30 #include <linux/types.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
37 #include <linux/i2c.h>
39 #include <linux/videodev2.h>
42 #include <linux/sem.h>
44 #include <linux/pci.h>
46 #include <linux/wait.h>
48 #include <asm/byteorder.h>
56 #define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
58 ZR36057_ISR_JPEGRepIRQ )
60 static bool lml33dpath;
72 "Use digital path capture mode (on LML33 cards)");
75 zr36057_init_vfe (
struct zoran *zr);
97 mask = (1 << (24 +
bit)) & 0xff000000;
139 ((reg & 7) << 16) | (value & 0xFF);
166 dump_guests (
struct zoran *zr)
171 for (i = 1; i < 8; i++) {
177 for (i = 1; i < 8; i++) {
178 printk(
" 0x%02x", guest[i]);
184 static inline unsigned long
190 return (1000000 * tv.tv_sec + tv.tv_usec);
196 int timeout,
i,
j,
res, guest[8], guest0[8], change[8][3];
197 unsigned long t0,
t1;
202 for (i = 1; i < 8; i++) {
209 while (timeout < 10000) {
212 for (i = 1; (i < 8) && (j < 8); i++) {
214 if (res != guest[i]) {
216 change[
j][0] = (t1 -
t0);
229 for (i = 1; i < 8; i++) {
230 printk(
" 0x%02x", guest0[i]);
237 for (i = 0; i <
j; i++) {
239 change[i][0], change[i][1], change[i][2]);
255 "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
261 "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
297 zr36057_adjust_vfe (
struct zoran *zr,
307 reg += ((1 << 10) | 1);
322 reg -= ((1 << 10) | 1);
334 zr36057_set_vfe (
struct zoran *zr,
342 unsigned VidWinWid, VidWinHt;
343 unsigned hcrop1, hcrop2, vcrop1, vcrop2;
344 unsigned Wa, We,
Ha, He;
345 unsigned X, Y, HorDcm, VerDcm;
347 unsigned mask_line_size;
359 video_width > Wa || video_height > Ha) {
368 VidWinWid = video_width;
370 We = (VidWinWid * 64) / X;
372 hcrop1 = 2 * ((tvn->
Wa - We) / 4);
373 hcrop2 = tvn->
Wa - We - hcrop1;
383 HEnd = HStart + tvn->
Wa - 1;
388 if (zr->
card.vfe_pol.hsync_pol)
394 VidWinHt = DispMode ? video_height : video_height / 2;
396 He = (VidWinHt * 64) / Y;
398 vcrop1 = (tvn->
Ha / 2 - He) / 2;
399 vcrop2 = tvn->
Ha / 2 - He - vcrop1;
401 VEnd = VStart + tvn->
Ha / 2;
406 if (zr->
card.vfe_pol.vsync_pol)
425 }
else if (HorDcm >= 32) {
427 }
else if (HorDcm >= 16) {
459 reg += mask_line_size;
500 "%s: zr36057_overlay() - video_address not aligned\n",
515 "%s: zr36057_overlay() - video_stride not aligned\n",
549 for (i = 0; i <
count; ++
i) {
553 width = vp[
i].
c.width;
554 height = vp[
i].
c.height;
585 for (k = 0; k <
width; ++
k) {
586 mask[(x +
k) / 32] &=
587 ~((
u32) 1 << (x +
k) % 32);
610 "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
660 spin_unlock_irqrestore(&zr->
spinlock, flags);
672 set_frame (
struct zoran *zr,
679 set_videobus_dir (
struct zoran *zr,
682 switch (zr->
card.type) {
698 init_jpeg_queue (
struct zoran *zr)
713 for (i = 0; i < zr->
jpg_buffers.num_buffers; i++) {
722 zr36057_set_jpg (
struct zoran *zr,
772 if (zr->
card.vfe_pol.hsync_pol)
822 zr36057_adjust_vfe(zr, mode);
844 printk(
" CodRepIRQ:%d", res);
848 printk(
" JPEGRepIRQ:%d", res);
863 printk(
": no interrupts detected.");
889 count_reset_interrupt (
struct zoran *zr)
992 set_videobus_dir(zr, 0);
1013 sizeof(
int), &field_size);
1021 sizeof(
int), &field_size);
1027 init_jpeg_queue(zr);
1028 zr36057_set_jpg(zr, mode);
1041 set_videobus_dir(zr, 1);
1057 init_jpeg_queue(zr);
1058 zr36057_set_jpg(zr, mode);
1076 set_videobus_dir(zr, 0);
1084 zr36057_adjust_vfe(zr, mode);
1101 int frame,
i, max_stat_com;
1140 zoran_reap_stat_com (
struct zoran *zr)
1167 if ((stat_com & 1) == 0) {
1175 buffer->
bs.length = (stat_com & 0x7fffff) >> 1;
1179 seq = ((stat_com >> 24) + zr->
jpg_err_seq) & 0xff;
1183 buffer->
bs.length = 0;
1194 static void zoran_restart(
struct zoran *zr)
1226 error_handler (
struct zoran *zr,
1238 if ((stat & 1) == 0 &&
1242 zoran_reap_stat_com(zr);
1285 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1292 for (i = 0; i < zr->
jpg_buffers.num_buffers; i++) {
1310 zoran_reap_stat_com(zr);
1348 unsigned long flags;
1356 while ((stat = count_reset_interrupt(zr))) {
1357 if (count++ > 100) {
1361 "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
1367 spin_unlock_irqrestore(&zr->
spinlock, flags);
1374 stat = count_reset_interrupt(zr);
1381 "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
1383 if (astat & zr->
card.vsync_int) {
1400 "%s: BuzIRQ with SnapShot off ???\n",
1457 #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1466 #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1471 char sv[BUZ_NUM_STAT_COM + 1];
1475 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1485 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1504 for (i = 0; i < 4; i++) {
1513 zoran_reap_stat_com(zr);
1520 if ((astat & zr->
card.jpeg_int) ||
1525 error_handler(zr, astat, stat);
1536 "%s: IRQ lockup, cleared int mask\n",
1543 spin_unlock_irqrestore(&zr->
spinlock, flags);
1570 if (zr->
card.init) {
1577 zr->
card.input[zr->
input].muxsel, 0, 0);
1594 zr36057_init_vfe(zr);
1623 zr36057_init_vfe (
struct zoran *zr)