Lines Matching +full:jpeg +full:- +full:codec
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * This part handles device access (PCI/I2C/codec/...)
18 #include <linux/i2c-algo-bit.h>
20 #include <media/v4l2-common.h>
26 #include <linux/dma-mapping.h>
68 // || zr->revision < 1) // Revision 1 has also Triton support in zr36057_init_vfe()
90 * A bit number of -1 (lacking) gives a mask of 0, in GPIO()
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()
117 return -1; in post_office_wait()
143 return -1; in post_office_read()
149 * JPEG Codec access
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()
168 /* Take the codec out of sleep */ 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()
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()
214 reg -= ((1 << 10) | 1); in zr36057_adjust_vfe()
237 tvn = zr->timing; in zr36057_set_vfe()
239 wa = tvn->wa; in zr36057_set_vfe()
240 ha = tvn->ha; 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()
255 X = DIV_ROUND_UP(vid_win_wid * 64, tvn->wa); in zr36057_set_vfe()
257 hor_dcm = 64 - X; in zr36057_set_vfe()
258 hcrop1 = 2 * ((tvn->wa - we) / 4); in zr36057_set_vfe()
259 hcrop2 = tvn->wa - we - hcrop1; in zr36057_set_vfe()
260 h_start = tvn->h_start ? tvn->h_start : 1; in zr36057_set_vfe()
269 h_end = h_start + tvn->wa - 1; in zr36057_set_vfe()
271 h_end -= hcrop2; in zr36057_set_vfe()
274 if (zr->card.vfe_pol.hsync_pol) in zr36057_set_vfe()
281 Y = DIV_ROUND_UP(vid_win_ht * 64 * 2, tvn->ha); in zr36057_set_vfe()
283 ver_dcm = 64 - Y; in zr36057_set_vfe()
284 vcrop1 = (tvn->ha / 2 - he) / 2; in zr36057_set_vfe()
285 vcrop2 = tvn->ha / 2 - he - vcrop1; in zr36057_set_vfe()
286 v_start = tvn->v_start; in zr36057_set_vfe()
287 // FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP in zr36057_set_vfe()
288 v_end = v_start + tvn->ha / 2; // - 1; in zr36057_set_vfe()
290 v_end -= vcrop2; 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()
319 reg |= format->vfespfr; in zr36057_set_vfe()
327 // || zr->revision < 1) // Revision 1 has also Triton support in zr36057_set_vfe()
333 zr36057_adjust_vfe(zr, zr->codec_mode); in zr36057_set_vfe()
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()
365 /* re-enable grabbing to screen if it was running */ in zr36057_set_memgrab()
373 * Set up the Buz-specific MJPEG part *
379 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_FRAME], val); in set_frame()
384 switch (zr->card.type) { 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()
403 /* re-initialize DMA ring stuff */ in init_jpeg_queue()
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()
423 tvn = zr->timing; in zr36057_set_jpg()
438 /* RJ: The following is experimental - improves the output to screen */ in zr36057_set_jpg()
439 //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM in zr36057_set_jpg()
451 if (zr->jpg_settings.field_per_buff == 1) in zr36057_set_jpg()
458 (tvn->ht << ZR36057_VSP_FRM_TOT); 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()
469 reg = ((tvn->h_sync_start) << ZR36057_HSP_HSYNC_START) | in zr36057_set_jpg()
470 (tvn->wt << ZR36057_HSP_LINE_TOT); in zr36057_set_jpg()
472 reg = ((zr->jpg_settings.img_x + in zr36057_set_jpg()
473 tvn->h_start + 4) << ZR36057_FHAP_NAX) | 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()
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()
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()
564 zr->frame_num = 0; in jpeg_start()
575 /* enable the JPEG IRQs */ in jpeg_start()
576 btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEG_REP_IRQ | ZR36057_ICR_INT_PIN_EN, in jpeg_start()
581 /* set the JPEG codec guest ID */ 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()
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()
633 /* Take the JPEG codec and the VFE out of sleep */ in zr36057_enable_jpg()
636 /* set JPEG app/com marker */ 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()
648 /* Setup the JPEG codec */ 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()
668 pci_dbg(zr->pci_dev, "enable_jpg(MOTION_COMPRESS)\n"); in zr36057_enable_jpg()
680 /* Take the JPEG codec and the VFE out of sleep */ 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()
688 /* Setup the JPEG codec */ 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()
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()
724 pci_dbg(zr->pci_dev, "enable_jpg(IDLE)\n"); in zr36057_enable_jpg()
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()
753 list_del(&buf->queue); in zoran_feed_stat_com()
754 zr->buf_in_reserve--; in zoran_feed_stat_com()
755 vbuf = &buf->vbuf; in zoran_feed_stat_com()
756 vbuf->vb2_buf.state = VB2_BUF_STATE_ACTIVE; in zoran_feed_stat_com()
757 phys_addr = vb2_dma_contig_plane_dma_addr(&vbuf->vb2_buf, 0); in zoran_feed_stat_com()
758 payload = vb2_get_plane_payload(&vbuf->vb2_buf, 0); 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()
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()
837 buf->vbuf.vb2_buf.timestamp = ktime_get_ns(); in zoran_reap_stat_com()
839 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { in zoran_reap_stat_com()
840 vb2_set_plane_payload(&buf->vbuf.vb2_buf, 0, size); 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()
856 vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_DONE); 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()
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()
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()
891 zr->ghost_int++; in zoran_irq()
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()
910 /* Enable bus-mastering */ in zoran_init_hardware()
914 if (zr->card.init) in zoran_init_hardware()
915 zr->card.init(zr); in zoran_init_hardware()
918 decoder_call(zr, video, s_std, zr->norm); in zoran_init_hardware()
920 zr->card.input[zr->input].muxsel, 0, 0); in zoran_init_hardware()
923 encoder_call(zr, video, s_std_output, zr->norm); in zoran_init_hardware()
926 /* toggle JPEG codec sleep to sync PLL */ in zoran_init_hardware()
950 /* set up GPIO direction - all output */ in zr36057_restart()