Lines Matching refs:zr

56 static void zr36057_init_vfe(struct zoran *zr)  in zr36057_init_vfe()  argument
84 void GPIO(struct zoran *zr, int bit, unsigned int value) in GPIO() argument
106 int post_office_wait(struct zoran *zr) in post_office_wait() argument
114 if ((por & ZR36057_POR_PO_TIME) && !zr->card.gws_not_connected) { in post_office_wait()
116 pci_info(zr->pci_dev, "pop timeout %08x\n", por); in post_office_wait()
123 int post_office_write(struct zoran *zr, unsigned int guest, in post_office_write() argument
133 return post_office_wait(zr); in post_office_write()
136 int post_office_read(struct zoran *zr, unsigned int guest, unsigned int reg) in post_office_read() argument
142 if (post_office_wait(zr) < 0) in post_office_read()
152 void jpeg_codec_sleep(struct zoran *zr, int sleep) in jpeg_codec_sleep() argument
154 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_SLEEP], !sleep); in jpeg_codec_sleep()
156 pci_dbg(zr->pci_dev, "%s() - wake GPIO=0x%08x\n", in jpeg_codec_sleep()
160 pci_dbg(zr->pci_dev, "%s() - sleep GPIO=0x%08x\n", in jpeg_codec_sleep()
166 int jpeg_codec_reset(struct zoran *zr) in jpeg_codec_reset() argument
169 jpeg_codec_sleep(zr, 0); in jpeg_codec_reset()
171 if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) { in jpeg_codec_reset()
172 post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0, in jpeg_codec_reset()
176 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 0); in jpeg_codec_reset()
178 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 1); in jpeg_codec_reset()
190 static void zr36057_adjust_vfe(struct zoran *zr, enum zoran_codec_mode mode) in zr36057_adjust_vfe() argument
198 if ((reg & (1 << 10)) && zr->card.type != LML33R10) in zr36057_adjust_vfe()
206 if ((zr->norm & V4L2_STD_NTSC) || in zr36057_adjust_vfe()
207 (zr->card.type == LML33R10 && in zr36057_adjust_vfe()
208 (zr->norm & V4L2_STD_PAL))) in zr36057_adjust_vfe()
213 if (!(reg & (1 << 10)) && zr->card.type != LML33R10) in zr36057_adjust_vfe()
225 static void zr36057_set_vfe(struct zoran *zr, int video_width, int video_height, in zr36057_set_vfe() argument
237 tvn = zr->timing; in zr36057_set_vfe()
242 pci_dbg(zr->pci_dev, "set_vfe() - width = %d, height = %d\n", video_width, video_height); in zr36057_set_vfe()
247 pci_err(zr->pci_dev, "set_vfe: w=%d h=%d not valid\n", video_width, video_height); in zr36057_set_vfe()
274 if (zr->card.vfe_pol.hsync_pol) in zr36057_set_vfe()
293 if (zr->card.vfe_pol.vsync_pol) in zr36057_set_vfe()
309 if (!(zr->norm & V4L2_STD_NTSC)) in zr36057_set_vfe()
333 zr36057_adjust_vfe(zr, zr->codec_mode); in zr36057_set_vfe()
337 void zr36057_set_memgrab(struct zoran *zr, int mode) in zr36057_set_memgrab() argument
348 pci_warn(zr->pci_dev, "%s(1) with SnapShot on!?\n", __func__); in zr36057_set_memgrab()
352 btor(zr->card.vsync_int, ZR36057_ICR); // SW in zr36057_set_memgrab()
358 zr36057_set_vfe(zr, zr->v4l_settings.width, in zr36057_set_memgrab()
359 zr->v4l_settings.height, in zr36057_set_memgrab()
360 zr->v4l_settings.format); in zr36057_set_memgrab()
363 btand(~zr->card.vsync_int, ZR36057_ICR); // SW in zr36057_set_memgrab()
377 static inline void set_frame(struct zoran *zr, int val) in set_frame() argument
379 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_FRAME], val); in set_frame()
382 static void set_videobus_dir(struct zoran *zr, int val) in set_videobus_dir() argument
384 switch (zr->card.type) { in set_videobus_dir()
388 GPIO(zr, 5, val); in set_videobus_dir()
390 GPIO(zr, 5, 1); in set_videobus_dir()
393 GPIO(zr, zr->card.gpio[ZR_GPIO_VID_DIR], in set_videobus_dir()
394 zr->card.gpio_pol[ZR_GPIO_VID_DIR] ? !val : val); in set_videobus_dir()
399 static void init_jpeg_queue(struct zoran *zr) in init_jpeg_queue() argument
404 zr->jpg_que_head = 0; in init_jpeg_queue()
405 zr->jpg_dma_head = 0; in init_jpeg_queue()
406 zr->jpg_dma_tail = 0; in init_jpeg_queue()
407 zr->jpg_que_tail = 0; in init_jpeg_queue()
408 zr->jpg_seq_num = 0; in init_jpeg_queue()
409 zr->jpeg_error = 0; in init_jpeg_queue()
410 zr->num_errors = 0; in init_jpeg_queue()
411 zr->jpg_err_seq = 0; in init_jpeg_queue()
412 zr->jpg_err_shift = 0; in init_jpeg_queue()
413 zr->jpg_queued_num = 0; in init_jpeg_queue()
415 zr->stat_com[i] = cpu_to_le32(1); /* mark as unavailable to zr36057 */ in init_jpeg_queue()
418 static void zr36057_set_jpg(struct zoran *zr, enum zoran_codec_mode mode) in zr36057_set_jpg() argument
423 tvn = zr->timing; in zr36057_set_jpg()
451 if (zr->jpg_settings.field_per_buff == 1) in zr36057_set_jpg()
460 reg = ((zr->jpg_settings.img_y + tvn->v_start) << ZR36057_FVAP_NAY) | in zr36057_set_jpg()
461 (zr->jpg_settings.img_height << ZR36057_FVAP_PAY); in zr36057_set_jpg()
465 if (zr->card.vfe_pol.hsync_pol) in zr36057_set_jpg()
472 reg = ((zr->jpg_settings.img_x + in zr36057_set_jpg()
474 (zr->jpg_settings.img_width << ZR36057_FHAP_PAX); in zr36057_set_jpg()
478 if (zr->jpg_settings.odd_even) in zr36057_set_jpg()
489 btwrite(zr->p_sc, ZR36057_JCBA); in zr36057_set_jpg()
496 if (zr->card.type != BUZ) in zr36057_set_jpg()
512 zr36057_adjust_vfe(zr, mode); in zr36057_set_jpg()
515 void clear_interrupt_counters(struct zoran *zr) in clear_interrupt_counters() argument
517 zr->intr_counter_GIRQ1 = 0; in clear_interrupt_counters()
518 zr->intr_counter_GIRQ0 = 0; in clear_interrupt_counters()
519 zr->intr_counter_cod_rep_irq = 0; in clear_interrupt_counters()
520 zr->intr_counter_jpeg_rep_irq = 0; in clear_interrupt_counters()
521 zr->field_counter = 0; in clear_interrupt_counters()
522 zr->irq1_in = 0; in clear_interrupt_counters()
523 zr->irq1_out = 0; in clear_interrupt_counters()
524 zr->jpeg_in = 0; in clear_interrupt_counters()
525 zr->jpeg_out = 0; in clear_interrupt_counters()
526 zr->JPEG_0 = 0; in clear_interrupt_counters()
527 zr->JPEG_1 = 0; in clear_interrupt_counters()
528 zr->end_event_missed = 0; in clear_interrupt_counters()
529 zr->jpeg_missed = 0; in clear_interrupt_counters()
530 zr->jpeg_max_missed = 0; in clear_interrupt_counters()
531 zr->jpeg_min_missed = 0x7fffffff; in clear_interrupt_counters()
534 static u32 count_reset_interrupt(struct zoran *zr) in count_reset_interrupt() argument
542 zr->intr_counter_GIRQ1++; in count_reset_interrupt()
546 zr->intr_counter_GIRQ0++; in count_reset_interrupt()
550 zr->intr_counter_cod_rep_irq++; in count_reset_interrupt()
554 zr->intr_counter_jpeg_rep_irq++; in count_reset_interrupt()
560 void jpeg_start(struct zoran *zr) in jpeg_start() argument
564 zr->frame_num = 0; in jpeg_start()
576 btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEG_REP_IRQ | ZR36057_ICR_INT_PIN_EN, in jpeg_start()
579 set_frame(zr, 0); // \FRAME in jpeg_start()
582 reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPE_GUEST_ID) | in jpeg_start()
586 if (zr->card.video_vfe == CODEC_TYPE_ZR36016 && in jpeg_start()
587 zr->card.video_codec == CODEC_TYPE_ZR36050) { in jpeg_start()
589 if (zr->vfe) in jpeg_start()
590 zr36016_write(zr->vfe, 0, 1); in jpeg_start()
593 post_office_write(zr, 0, 0, 0); in jpeg_start()
603 set_frame(zr, 1); // /FRAME in jpeg_start()
606 void zr36057_enable_jpg(struct zoran *zr, enum zoran_codec_mode mode) in zr36057_enable_jpg() argument
609 int field_size = zr->buffer_size / zr->jpg_settings.field_per_buff; in zr36057_enable_jpg()
611 zr->codec_mode = mode; in zr36057_enable_jpg()
613 cap.x = zr->jpg_settings.img_x; in zr36057_enable_jpg()
614 cap.y = zr->jpg_settings.img_y; in zr36057_enable_jpg()
615 cap.width = zr->jpg_settings.img_width; in zr36057_enable_jpg()
616 cap.height = zr->jpg_settings.img_height; in zr36057_enable_jpg()
618 zr->jpg_settings.hor_dcm | (zr->jpg_settings.ver_dcm << 8); in zr36057_enable_jpg()
619 cap.quality = zr->jpg_settings.jpg_comp.quality; in zr36057_enable_jpg()
629 set_videobus_dir(zr, 0); in zr36057_enable_jpg()
630 decoder_call(zr, video, s_stream, 1); in zr36057_enable_jpg()
631 encoder_call(zr, video, s_routing, 0, 0, 0); in zr36057_enable_jpg()
634 jpeg_codec_sleep(zr, 0); in zr36057_enable_jpg()
637 app.appn = zr->jpg_settings.jpg_comp.APPn; in zr36057_enable_jpg()
638 app.len = zr->jpg_settings.jpg_comp.APP_len; in zr36057_enable_jpg()
639 memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60); in zr36057_enable_jpg()
640 zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA, in zr36057_enable_jpg()
643 com.len = zr->jpg_settings.jpg_comp.COM_len; in zr36057_enable_jpg()
644 memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60); in zr36057_enable_jpg()
645 zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA, in zr36057_enable_jpg()
649 zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE, in zr36057_enable_jpg()
651 zr->codec->set_video(zr->codec, zr->timing, &cap, in zr36057_enable_jpg()
652 &zr->card.vfe_pol); in zr36057_enable_jpg()
653 zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION); in zr36057_enable_jpg()
656 if (zr->vfe) { in zr36057_enable_jpg()
657 zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE, in zr36057_enable_jpg()
659 zr->vfe->set_video(zr->vfe, zr->timing, &cap, in zr36057_enable_jpg()
660 &zr->card.vfe_pol); in zr36057_enable_jpg()
661 zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION); in zr36057_enable_jpg()
664 init_jpeg_queue(zr); in zr36057_enable_jpg()
665 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO in zr36057_enable_jpg()
667 clear_interrupt_counters(zr); in zr36057_enable_jpg()
668 pci_dbg(zr->pci_dev, "enable_jpg(MOTION_COMPRESS)\n"); in zr36057_enable_jpg()
676 decoder_call(zr, video, s_stream, 0); in zr36057_enable_jpg()
677 set_videobus_dir(zr, 1); in zr36057_enable_jpg()
678 encoder_call(zr, video, s_routing, 1, 0, 0); in zr36057_enable_jpg()
681 jpeg_codec_sleep(zr, 0); in zr36057_enable_jpg()
683 if (zr->vfe) { in zr36057_enable_jpg()
684 zr->vfe->set_video(zr->vfe, zr->timing, &cap, in zr36057_enable_jpg()
685 &zr->card.vfe_pol); in zr36057_enable_jpg()
686 zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION); in zr36057_enable_jpg()
689 zr->codec->set_video(zr->codec, zr->timing, &cap, in zr36057_enable_jpg()
690 &zr->card.vfe_pol); in zr36057_enable_jpg()
691 zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION); in zr36057_enable_jpg()
693 init_jpeg_queue(zr); in zr36057_enable_jpg()
694 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO in zr36057_enable_jpg()
696 clear_interrupt_counters(zr); in zr36057_enable_jpg()
697 pci_dbg(zr->pci_dev, "enable_jpg(MOTION_DECOMPRESS)\n"); in zr36057_enable_jpg()
703 btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEG_REP_IRQ), in zr36057_enable_jpg()
705 btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEG_REP_IRQ, in zr36057_enable_jpg()
711 set_videobus_dir(zr, 0); in zr36057_enable_jpg()
712 set_frame(zr, 1); // /FRAME in zr36057_enable_jpg()
717 jpeg_codec_reset(zr); in zr36057_enable_jpg()
718 jpeg_codec_sleep(zr, 1); in zr36057_enable_jpg()
719 zr36057_adjust_vfe(zr, mode); in zr36057_enable_jpg()
721 decoder_call(zr, video, s_stream, 1); in zr36057_enable_jpg()
722 encoder_call(zr, video, s_routing, 0, 0, 0); in zr36057_enable_jpg()
724 pci_dbg(zr->pci_dev, "enable_jpg(IDLE)\n"); in zr36057_enable_jpg()
730 void zoran_feed_stat_com(struct zoran *zr) in zoran_feed_stat_com() argument
742 (zr->jpg_settings.tmp_dcm == in zoran_feed_stat_com()
745 spin_lock_irqsave(&zr->queued_bufs_lock, flags); in zoran_feed_stat_com()
746 while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com) { in zoran_feed_stat_com()
747 buf = list_first_entry_or_null(&zr->queued_bufs, struct zr_buffer, queue); in zoran_feed_stat_com()
749 pci_err(zr->pci_dev, "No buffer available to queue\n"); in zoran_feed_stat_com()
750 spin_unlock_irqrestore(&zr->queued_bufs_lock, flags); in zoran_feed_stat_com()
754 zr->buf_in_reserve--; in zoran_feed_stat_com()
760 payload = zr->buffer_size; in zoran_feed_stat_com()
761 if (zr->jpg_settings.tmp_dcm == 1) { in zoran_feed_stat_com()
763 i = (zr->jpg_dma_head - in zoran_feed_stat_com()
764 zr->jpg_err_shift) & BUZ_MASK_STAT_COM; in zoran_feed_stat_com()
765 if (!(zr->stat_com[i] & cpu_to_le32(1))) in zoran_feed_stat_com()
767 zr->stat_comb[i * 2] = cpu_to_le32(phys_addr); in zoran_feed_stat_com()
768 zr->stat_comb[i * 2 + 1] = cpu_to_le32((payload >> 1) | 1); in zoran_feed_stat_com()
769 zr->inuse[i] = buf; in zoran_feed_stat_com()
770 zr->stat_com[i] = cpu_to_le32(zr->p_scb + i * 2 * 4); in zoran_feed_stat_com()
773 i = ((zr->jpg_dma_head - in zoran_feed_stat_com()
774 zr->jpg_err_shift) & 1) * 2; in zoran_feed_stat_com()
775 if (!(zr->stat_com[i] & cpu_to_le32(1))) in zoran_feed_stat_com()
777 zr->stat_com[i] = cpu_to_le32(zr->p_scb + i * 2 * 4); in zoran_feed_stat_com()
778 zr->stat_com[i + 1] = cpu_to_le32(zr->p_scb + i * 2 * 4); in zoran_feed_stat_com()
780 zr->stat_comb[i * 2] = cpu_to_le32(phys_addr); in zoran_feed_stat_com()
781 zr->stat_comb[i * 2 + 1] = cpu_to_le32((payload >> 1) | 1); in zoran_feed_stat_com()
783 zr->inuse[i] = buf; in zoran_feed_stat_com()
784 zr->inuse[i + 1] = NULL; in zoran_feed_stat_com()
786 zr->jpg_dma_head++; in zoran_feed_stat_com()
788 spin_unlock_irqrestore(&zr->queued_bufs_lock, flags); in zoran_feed_stat_com()
789 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) in zoran_feed_stat_com()
790 zr->jpg_queued_num++; in zoran_feed_stat_com()
794 static void zoran_reap_stat_com(struct zoran *zr) in zoran_reap_stat_com() argument
812 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) in zoran_reap_stat_com()
813 zr->jpg_seq_num++; in zoran_reap_stat_com()
815 spin_lock_irqsave(&zr->queued_bufs_lock, flags); in zoran_reap_stat_com()
816 while (zr->jpg_dma_tail < zr->jpg_dma_head) { in zoran_reap_stat_com()
817 if (zr->jpg_settings.tmp_dcm == 1) in zoran_reap_stat_com()
818 i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM; in zoran_reap_stat_com()
820 i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2; in zoran_reap_stat_com()
822 stat_com = le32_to_cpu(zr->stat_com[i]); in zoran_reap_stat_com()
824 spin_unlock_irqrestore(&zr->queued_bufs_lock, flags); in zoran_reap_stat_com()
831 buf = zr->inuse[i]; in zoran_reap_stat_com()
833 spin_unlock_irqrestore(&zr->queued_bufs_lock, flags); in zoran_reap_stat_com()
834 pci_err(zr->pci_dev, "No buffer at slot %d\n", i); in zoran_reap_stat_com()
839 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { in zoran_reap_stat_com()
843 seq = (fcnt + zr->jpg_err_seq) & 0xff; in zoran_reap_stat_com()
844 dif = (seq - zr->jpg_seq_num) & 0xff; in zoran_reap_stat_com()
845 zr->jpg_seq_num += dif; in zoran_reap_stat_com()
847 buf->vbuf.sequence = zr->jpg_settings.tmp_dcm == in zoran_reap_stat_com()
848 2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num; in zoran_reap_stat_com()
849 zr->inuse[i] = NULL; in zoran_reap_stat_com()
850 if (zr->jpg_settings.tmp_dcm != 1) in zoran_reap_stat_com()
851 buf->vbuf.field = zr->jpg_settings.odd_even ? in zoran_reap_stat_com()
854 buf->vbuf.field = zr->jpg_settings.odd_even ? in zoran_reap_stat_com()
858 zr->jpg_dma_tail++; in zoran_reap_stat_com()
860 spin_unlock_irqrestore(&zr->queued_bufs_lock, flags); in zoran_reap_stat_com()
865 struct zoran *zr = dev_id; in zoran_irq() local
868 stat = count_reset_interrupt(zr); in zoran_irq()
870 if (astat & zr->card.vsync_int) { in zoran_irq()
871 if (zr->running == ZORAN_MAP_MODE_RAW) { in zoran_irq()
873 pci_warn(zr->pci_dev, "BuzIRQ with SnapShot off ???\n"); in zoran_irq()
875 zr_set_buf(zr); in zoran_irq()
879 if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS && in zoran_irq()
880 zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) { in zoran_irq()
881 pci_err(zr->pci_dev, "JPG IRQ when not in good mode\n"); in zoran_irq()
884 zr->frame_num++; in zoran_irq()
885 zoran_reap_stat_com(zr); in zoran_irq()
886 zoran_feed_stat_com(zr); in zoran_irq()
891 zr->ghost_int++; in zoran_irq()
895 void zoran_set_pci_master(struct zoran *zr, int set_master) in zoran_set_pci_master() argument
898 pci_set_master(zr->pci_dev); in zoran_set_pci_master()
902 pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command); in zoran_set_pci_master()
904 pci_write_config_word(zr->pci_dev, PCI_COMMAND, command); in zoran_set_pci_master()
908 void zoran_init_hardware(struct zoran *zr) in zoran_init_hardware() argument
911 zoran_set_pci_master(zr, 1); in zoran_init_hardware()
914 if (zr->card.init) in zoran_init_hardware()
915 zr->card.init(zr); in zoran_init_hardware()
917 decoder_call(zr, core, init, 0); in zoran_init_hardware()
918 decoder_call(zr, video, s_std, zr->norm); in zoran_init_hardware()
919 decoder_call(zr, video, s_routing, in zoran_init_hardware()
920 zr->card.input[zr->input].muxsel, 0, 0); in zoran_init_hardware()
922 encoder_call(zr, core, init, 0); in zoran_init_hardware()
923 encoder_call(zr, video, s_std_output, zr->norm); in zoran_init_hardware()
924 encoder_call(zr, video, s_routing, 0, 0, 0); in zoran_init_hardware()
927 jpeg_codec_sleep(zr, 1); in zoran_init_hardware()
928 jpeg_codec_sleep(zr, 0); in zoran_init_hardware()
934 zr36057_init_vfe(zr); in zoran_init_hardware()
936 zr36057_enable_jpg(zr, BUZ_MODE_IDLE); in zoran_init_hardware()
941 void zr36057_restart(struct zoran *zr) in zr36057_restart() argument