2 * Zoran zr36057/zr36067 PCI controller driver, for the
3 * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
4 * Media Labs LML33/LML33R10.
6 * This part handles device access (PCI/I2C/codec/...)
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
10 * Currently maintained by:
11 * Ronald Bultje <rbultje@ronald.bitfreak.net>
12 * Laurent Pinchart <laurent.pinchart@skynet.be>
13 * Mailinglist <mjpeg-users@lists.sf.net>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/config.h>
31 #include <linux/types.h>
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/vmalloc.h>
36 #include <linux/interrupt.h>
37 #include <linux/proc_fs.h>
38 #include <linux/i2c.h>
39 #include <linux/i2c-algo-bit.h>
40 #include <linux/videodev.h>
41 #include <linux/spinlock.h>
42 #include <linux/sem.h>
44 #include <linux/pci.h>
45 #include <linux/video_decoder.h>
46 #include <linux/video_encoder.h>
47 #include <linux/delay.h>
51 #include "videocodec.h"
53 #include "zoran_device.h"
55 #define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
57 ZR36057_ISR_JPEGRepIRQ )
59 extern const struct zoran_format zoran_formats[];
60 extern const int zoran_num_formats;
64 #define dprintk(num, format, args...) \
66 if (*zr_debug >= num) \
67 printk(format, ##args); \
70 static int lml33dpath = 0; /* 1 will use digital path in capture
71 * mode instead of analog. It can be
72 * used for picture adjustments using
73 * tool like xawtv while watching image
74 * on TV monitor connected to the output.
75 * However, due to absence of 75 Ohm
76 * load on Bt819 input, there will be
77 * some image imperfections */
79 MODULE_PARM(lml33dpath, "i");
80 MODULE_PARM_DESC(lml33dpath,
81 "Use digital path capture mode (on LML33 cards)");
84 * General Purpose I/O and Guest bus access
88 * This is a bit tricky. When a board lacks a GPIO function, the corresponding
89 * GPIO bit number in the card_info structure is set to 0.
93 GPIO (struct zoran *zr,
100 /* Make sure the bit number is legal
101 * A bit number of -1 (lacking) gives a mask of 0,
102 * making it harmless */
103 mask = (1 << (24 + bit)) & 0xff000000;
104 reg = btread(ZR36057_GPPGCR1) & ~mask;
108 btwrite(reg, ZR36057_GPPGCR1);
113 * Wait til post office is no longer busy
117 post_office_wait (struct zoran *zr)
121 // while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
122 while ((por = btread(ZR36057_POR)) & ZR36057_POR_POPen) {
123 /* wait for something to happen */
125 if ((por & ZR36057_POR_POTime) && !zr->card.gws_not_connected) {
126 /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
127 dprintk(1, KERN_INFO "%s: pop timeout %08x\n", ZR_DEVNAME(zr),
136 post_office_write (struct zoran *zr,
144 ZR36057_POR_PODir | ZR36057_POR_POTime | ((guest & 7) << 20) |
145 ((reg & 7) << 16) | (value & 0xFF);
146 btwrite(por, ZR36057_POR);
148 return post_office_wait(zr);
152 post_office_read (struct zoran *zr,
158 por = ZR36057_POR_POTime | ((guest & 7) << 20) | ((reg & 7) << 16);
159 btwrite(por, ZR36057_POR);
160 if (post_office_wait(zr) < 0) {
164 return btread(ZR36057_POR) & 0xFF;
172 dump_guests (struct zoran *zr)
177 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
178 guest[i] = post_office_read(zr, i, 0);
181 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
183 for (i = 1; i < 8; i++) {
184 printk(" 0x%02x", guest[i]);
190 static inline unsigned long
195 do_gettimeofday(&tv);
196 return (1000000 * tv.tv_sec + tv.tv_usec);
200 detect_guest_activity (struct zoran *zr)
202 int timeout, i, j, res, guest[8], guest0[8], change[8][3];
203 unsigned long t0, t1;
206 printk(KERN_INFO "%s: Detecting guests activity, please wait...\n",
208 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
209 guest0[i] = guest[i] = post_office_read(zr, i, 0);
215 while (timeout < 10000) {
218 for (i = 1; (i < 8) && (j < 8); i++) {
219 res = post_office_read(zr, i, 0);
220 if (res != guest[i]) {
222 change[j][0] = (t1 - t0);
233 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
235 for (i = 1; i < 8; i++) {
236 printk(" 0x%02x", guest0[i]);
240 printk(KERN_INFO "%s: No activity detected.\n", ZR_DEVNAME(zr));
243 for (i = 0; i < j; i++) {
244 printk(KERN_INFO "%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr),
245 change[i][0], change[i][1], change[i][2]);
254 jpeg_codec_sleep (struct zoran *zr,
257 GPIO(zr, zr->card.gpio[GPIO_JPEG_SLEEP], !sleep);
261 "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
262 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
267 "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
268 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
274 jpeg_codec_reset (struct zoran *zr)
276 /* Take the codec out of sleep */
277 jpeg_codec_sleep(zr, 0);
279 if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) {
280 post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0,
284 GPIO(zr, zr->card.gpio[GPIO_JPEG_RESET], 0);
286 GPIO(zr, zr->card.gpio[GPIO_JPEG_RESET], 1);
294 * Set the registers for the size we have specified. Don't bother
295 * trying to understand this without the ZR36057 manual in front of
298 * PS: The manual is free for download in .pdf format from
299 * www.zoran.com - nicely done those folks.
303 zr36057_adjust_vfe (struct zoran *zr,
304 enum zoran_codec_mode mode)
309 case BUZ_MODE_MOTION_DECOMPRESS:
310 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
311 reg = btread(ZR36057_VFEHCR);
312 if ((reg & (1 << 10)) && zr->card.type != LML33R10) {
313 reg += ((1 << 10) | 1);
315 btwrite(reg, ZR36057_VFEHCR);
317 case BUZ_MODE_MOTION_COMPRESS:
320 if (zr->norm == VIDEO_MODE_NTSC ||
321 (zr->card.type == LML33R10 &&
322 zr->norm == VIDEO_MODE_PAL))
323 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
325 btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
326 reg = btread(ZR36057_VFEHCR);
327 if (!(reg & (1 << 10)) && zr->card.type != LML33R10) {
328 reg -= ((1 << 10) | 1);
330 btwrite(reg, ZR36057_VFEHCR);
340 zr36057_set_vfe (struct zoran *zr,
343 const struct zoran_format *format)
346 unsigned HStart, HEnd, VStart, VEnd;
348 unsigned VidWinWid, VidWinHt;
349 unsigned hcrop1, hcrop2, vcrop1, vcrop2;
350 unsigned Wa, We, Ha, He;
351 unsigned X, Y, HorDcm, VerDcm;
353 unsigned mask_line_size;
360 dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
361 ZR_DEVNAME(zr), video_width, video_height);
363 if (zr->norm != VIDEO_MODE_PAL &&
364 zr->norm != VIDEO_MODE_NTSC &&
365 zr->norm != VIDEO_MODE_SECAM) {
367 KERN_ERR "%s: set_vfe() - norm = %d not valid\n",
368 ZR_DEVNAME(zr), zr->norm);
371 if (video_width < BUZ_MIN_WIDTH ||
372 video_height < BUZ_MIN_HEIGHT ||
373 video_width > Wa || video_height > Ha) {
374 dprintk(1, KERN_ERR "%s: set_vfe: w=%d h=%d not valid\n",
375 ZR_DEVNAME(zr), video_width, video_height);
382 VidWinWid = video_width;
383 X = (VidWinWid * 64 + tvn->Wa - 1) / tvn->Wa;
384 We = (VidWinWid * 64) / X;
386 hcrop1 = 2 * ((tvn->Wa - We) / 4);
387 hcrop2 = tvn->Wa - We - hcrop1;
388 HStart = tvn->HStart ? tvn->HStart : 1;
389 /* (Ronald) Original comment:
390 * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
391 * this is false. It inverses chroma values on the LML33R10 (so Cr
392 * suddenly is shown as Cb and reverse, really cool effect if you
393 * want to see blue faces, not useful otherwise). So don't use |1.
394 * However, the DC10 has '0' as HStart, but does need |1, so we
395 * use a dirty check...
397 HEnd = HStart + tvn->Wa - 1;
400 reg = ((HStart & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HStart)
401 | ((HEnd & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HEnd);
402 if (zr->card.vfe_pol.hsync_pol)
403 reg |= ZR36057_VFEHCR_HSPol;
404 btwrite(reg, ZR36057_VFEHCR);
407 DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
408 VidWinHt = DispMode ? video_height : video_height / 2;
409 Y = (VidWinHt * 64 * 2 + tvn->Ha - 1) / tvn->Ha;
410 He = (VidWinHt * 64) / Y;
412 vcrop1 = (tvn->Ha / 2 - He) / 2;
413 vcrop2 = tvn->Ha / 2 - He - vcrop1;
414 VStart = tvn->VStart;
415 VEnd = VStart + tvn->Ha / 2; // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
418 reg = ((VStart & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VStart)
419 | ((VEnd & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VEnd);
420 if (zr->card.vfe_pol.vsync_pol)
421 reg |= ZR36057_VFEVCR_VSPol;
422 btwrite(reg, ZR36057_VFEVCR);
424 /* scaler and pixel format */
426 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
427 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
428 reg |= (DispMode << ZR36057_VFESPFR_DispMode);
429 if (format->palette != VIDEO_PALETTE_YUV422)
430 reg |= ZR36057_VFESPFR_LittleEndian;
431 /* RJ: I don't know, why the following has to be the opposite
432 * of the corresponding ZR36060 setting, but only this way
433 * we get the correct colors when uncompressing to the screen */
434 //reg |= ZR36057_VFESPFR_VCLKPol; /**/
435 /* RJ: Don't know if that is needed for NTSC also */
436 if (zr->norm != VIDEO_MODE_NTSC)
437 reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang
438 reg |= ZR36057_VFESPFR_TopField;
439 switch (format->palette) {
441 case VIDEO_PALETTE_YUV422:
442 reg |= ZR36057_VFESPFR_YUV422;
445 case VIDEO_PALETTE_RGB555:
446 reg |= ZR36057_VFESPFR_RGB555 | ZR36057_VFESPFR_ErrDif;
449 case VIDEO_PALETTE_RGB565:
450 reg |= ZR36057_VFESPFR_RGB565 | ZR36057_VFESPFR_ErrDif;
453 case VIDEO_PALETTE_RGB24:
454 reg |= ZR36057_VFESPFR_RGB888 | ZR36057_VFESPFR_Pack24;
457 case VIDEO_PALETTE_RGB32:
458 reg |= ZR36057_VFESPFR_RGB888;
463 KERN_INFO "%s: set_vfe() - unknown color_fmt=%x\n",
464 ZR_DEVNAME(zr), format->palette);
469 reg |= 3 << ZR36057_VFESPFR_HFilter; /* 5 tap filter */
470 } else if (HorDcm >= 32) {
471 reg |= 2 << ZR36057_VFESPFR_HFilter; /* 4 tap filter */
472 } else if (HorDcm >= 16) {
473 reg |= 1 << ZR36057_VFESPFR_HFilter; /* 3 tap filter */
475 btwrite(reg, ZR36057_VFESPFR);
477 /* display configuration */
478 reg = (16 << ZR36057_VDCR_MinPix)
479 | (VidWinHt << ZR36057_VDCR_VidWinHt)
480 | (VidWinWid << ZR36057_VDCR_VidWinWid);
481 if (pci_pci_problems & PCIPCI_TRITON)
482 // || zr->revision < 1) // Revision 1 has also Triton support
483 reg &= ~ZR36057_VDCR_Triton;
485 reg |= ZR36057_VDCR_Triton;
486 btwrite(reg, ZR36057_VDCR);
488 /* (Ronald) don't write this if overlay_mask = NULL */
489 if (zr->overlay_mask) {
490 /* Write overlay clipping mask data, but don't enable overlay clipping */
491 /* RJ: since this makes only sense on the screen, we use
492 * zr->overlay_settings.width instead of video_width */
494 mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
495 reg = virt_to_bus(zr->overlay_mask);
496 btwrite(reg, ZR36057_MMTR);
497 reg = virt_to_bus(zr->overlay_mask + mask_line_size);
498 btwrite(reg, ZR36057_MMBR);
500 mask_line_size - (zr->overlay_settings.width +
503 reg += mask_line_size;
504 reg <<= ZR36057_OCR_MaskStride;
505 btwrite(reg, ZR36057_OCR);
508 zr36057_adjust_vfe(zr, zr->codec_mode);
512 * Switch overlay on or off
516 zr36057_overlay (struct zoran *zr,
522 /* do the necessary settings ... */
523 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR); /* switch it off first */
526 zr->overlay_settings.width,
527 zr->overlay_settings.height,
528 zr->overlay_settings.format);
530 /* Start and length of each line MUST be 4-byte aligned.
531 * This should be allready checked before the call to this routine.
532 * All error messages are internal driver checking only! */
534 /* video display top and bottom registers */
535 reg = (u32) zr->buffer.base +
536 zr->overlay_settings.x *
537 ((zr->overlay_settings.format->depth + 7) / 8) +
538 zr->overlay_settings.y *
539 zr->buffer.bytesperline;
540 btwrite(reg, ZR36057_VDTR);
544 "%s: zr36057_overlay() - video_address not aligned\n",
546 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
547 reg += zr->buffer.bytesperline;
548 btwrite(reg, ZR36057_VDBR);
550 /* video stride, status, and frame grab register */
551 reg = zr->buffer.bytesperline -
552 zr->overlay_settings.width *
553 ((zr->overlay_settings.format->depth + 7) / 8);
554 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
555 reg += zr->buffer.bytesperline;
559 "%s: zr36057_overlay() - video_stride not aligned\n",
561 reg = (reg << ZR36057_VSSFGR_DispStride);
562 reg |= ZR36057_VSSFGR_VidOvf; /* clear overflow status */
563 btwrite(reg, ZR36057_VSSFGR);
565 /* Set overlay clipping */
566 if (zr->overlay_settings.clipcount > 0)
567 btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
569 /* ... and switch it on */
570 btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
573 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
578 * The overlay mask has one bit for each pixel on a scan line,
579 * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
583 write_overlay_mask (struct file *file,
584 struct video_clip *vp,
587 struct zoran_fh *fh = file->private_data;
588 struct zoran *zr = fh->zr;
589 unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
591 int x, y, width, height;
595 /* fill mask with one bits */
596 memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
599 for (i = 0; i < count; ++i) {
600 /* pick up local copy of clip */
604 height = vp[i].height;
606 /* trim clips that extend beyond the window */
615 if (x + width > fh->overlay_settings.width) {
616 width = fh->overlay_settings.width - x;
618 if (y + height > fh->overlay_settings.height) {
619 height = fh->overlay_settings.height - y;
622 /* ignore degenerate clips */
630 /* apply clip for each scan line */
631 for (j = 0; j < height; ++j) {
632 /* reset bit for each pixel */
633 /* this can be optimized later if need be */
634 mask = fh->overlay_mask + (y + j) * mask_line_size;
635 for (k = 0; k < width; ++k) {
636 mask[(x + k) / 32] &=
637 ~((u32) 1 << (x + k) % 32);
643 /* Enable/Disable uncompressed memory grabbing of the 36057 */
646 zr36057_set_memgrab (struct zoran *zr,
650 if (btread(ZR36057_VSSFGR) &
651 (ZR36057_VSSFGR_SnapShot | ZR36057_VSSFGR_FrameGrab))
654 "%s: zr36057_set_memgrab(1) with SnapShot or FrameGrab on!?\n",
657 /* switch on VSync interrupts */
658 btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
659 btor(zr->card.vsync_int, ZR36057_ICR); // SW
661 /* enable SnapShot */
662 btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
664 /* Set zr36057 video front end and enable video */
665 zr36057_set_vfe(zr, zr->v4l_settings.width,
666 zr->v4l_settings.height,
667 zr->v4l_settings.format);
669 zr->v4l_memgrab_active = 1;
671 zr->v4l_memgrab_active = 0;
673 /* switch off VSync interrupts */
674 btand(~zr->card.vsync_int, ZR36057_ICR); // SW
676 /* reenable grabbing to screen if it was running */
677 if (zr->v4l_overlay_active) {
678 zr36057_overlay(zr, 1);
680 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
681 btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
687 wait_grab_pending (struct zoran *zr)
691 /* wait until all pending grabs are finished */
693 if (!zr->v4l_memgrab_active)
696 while (zr->v4l_pend_tail != zr->v4l_pend_head) {
697 interruptible_sleep_on(&zr->v4l_capq);
698 if (signal_pending(current))
702 spin_lock_irqsave(&zr->spinlock, flags);
703 zr36057_set_memgrab(zr, 0);
704 spin_unlock_irqrestore(&zr->spinlock, flags);
709 /*****************************************************************************
711 * Set up the Buz-specific MJPEG part *
713 *****************************************************************************/
716 set_frame (struct zoran *zr,
719 GPIO(zr, zr->card.gpio[GPIO_JPEG_FRAME], val);
723 set_videobus_dir (struct zoran *zr,
726 switch (zr->card.type) {
735 GPIO(zr, zr->card.gpio[GPIO_VID_DIR],
736 zr->card.gpio_pol[GPIO_VID_DIR] ? !val : val);
742 init_jpeg_queue (struct zoran *zr)
746 /* re-initialize DMA ring stuff */
747 zr->jpg_que_head = 0;
748 zr->jpg_dma_head = 0;
749 zr->jpg_dma_tail = 0;
750 zr->jpg_que_tail = 0;
755 zr->jpg_err_shift = 0;
756 zr->jpg_queued_num = 0;
757 for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
758 zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
760 for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
761 zr->stat_com[i] = 1; /* mark as unavailable to zr36057 */
766 zr36057_set_jpg (struct zoran *zr,
767 enum zoran_codec_mode mode)
774 /* assert P_Reset, disable code transfer, deassert Active */
775 btwrite(0, ZR36057_JPC);
777 /* MJPEG compression mode */
780 case BUZ_MODE_MOTION_COMPRESS:
782 reg = ZR36057_JMC_MJPGCmpMode;
785 case BUZ_MODE_MOTION_DECOMPRESS:
786 reg = ZR36057_JMC_MJPGExpMode;
787 reg |= ZR36057_JMC_SyncMstr;
788 /* RJ: The following is experimental - improves the output to screen */
789 //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
792 case BUZ_MODE_STILL_COMPRESS:
793 reg = ZR36057_JMC_JPGCmpMode;
796 case BUZ_MODE_STILL_DECOMPRESS:
797 reg = ZR36057_JMC_JPGExpMode;
801 reg |= ZR36057_JMC_JPG;
802 if (zr->jpg_settings.field_per_buff == 1)
803 reg |= ZR36057_JMC_Fld_per_buff;
804 btwrite(reg, ZR36057_JMC);
807 btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
808 reg = (6 << ZR36057_VSP_VsyncSize) |
809 (tvn->Ht << ZR36057_VSP_FrmTot);
810 btwrite(reg, ZR36057_VSP);
811 reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
812 (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
813 btwrite(reg, ZR36057_FVAP);
816 if (zr->card.vfe_pol.hsync_pol)
817 btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
819 btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
820 reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
821 (tvn->Wt << ZR36057_HSP_LineTot);
822 btwrite(reg, ZR36057_HSP);
823 reg = ((zr->jpg_settings.img_x +
824 tvn->HStart + 4) << ZR36057_FHAP_NAX) |
825 (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
826 btwrite(reg, ZR36057_FHAP);
828 /* field process parameters */
829 if (zr->jpg_settings.odd_even)
830 reg = ZR36057_FPP_Odd_Even;
834 btwrite(reg, ZR36057_FPP);
836 /* Set proper VCLK Polarity, else colors will be wrong during playback */
837 //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
839 /* code base address */
840 reg = virt_to_bus(zr->stat_com);
841 btwrite(reg, ZR36057_JCBA);
843 /* FIFO threshold (FIFO is 160. double words) */
844 /* NOTE: decimal values here */
847 case BUZ_MODE_STILL_COMPRESS:
848 case BUZ_MODE_MOTION_COMPRESS:
849 if (zr->card.type != BUZ)
855 case BUZ_MODE_STILL_DECOMPRESS:
856 case BUZ_MODE_MOTION_DECOMPRESS:
865 btwrite(reg, ZR36057_JCFT);
866 zr36057_adjust_vfe(zr, mode);
871 print_interrupts (struct zoran *zr)
875 printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
876 if ((res = zr->field_counter) < -1 || res > 1) {
877 printk(" FD:%d", res);
879 if ((res = zr->intr_counter_GIRQ1) != 0) {
880 printk(" GIRQ1:%d", res);
883 if ((res = zr->intr_counter_GIRQ0) != 0) {
884 printk(" GIRQ0:%d", res);
887 if ((res = zr->intr_counter_CodRepIRQ) != 0) {
888 printk(" CodRepIRQ:%d", res);
891 if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
892 printk(" JPEGRepIRQ:%d", res);
895 if (zr->JPEG_max_missed) {
896 printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
897 zr->JPEG_min_missed);
899 if (zr->END_event_missed) {
900 printk(" ENDs missed: %d", zr->END_event_missed);
902 //if (zr->jpg_queued_num) {
903 printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
904 zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
907 printk(": no interrupts detected.");
913 clear_interrupt_counters (struct zoran *zr)
915 zr->intr_counter_GIRQ1 = 0;
916 zr->intr_counter_GIRQ0 = 0;
917 zr->intr_counter_CodRepIRQ = 0;
918 zr->intr_counter_JPEGRepIRQ = 0;
919 zr->field_counter = 0;
926 zr->END_event_missed = 0;
928 zr->JPEG_max_missed = 0;
929 zr->JPEG_min_missed = 0x7fffffff;
933 count_reset_interrupt (struct zoran *zr)
937 if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
938 if (isr & ZR36057_ISR_GIRQ1) {
939 btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
940 zr->intr_counter_GIRQ1++;
942 if (isr & ZR36057_ISR_GIRQ0) {
943 btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
944 zr->intr_counter_GIRQ0++;
946 if (isr & ZR36057_ISR_CodRepIRQ) {
947 btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
948 zr->intr_counter_CodRepIRQ++;
950 if (isr & ZR36057_ISR_JPEGRepIRQ) {
951 btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
952 zr->intr_counter_JPEGRepIRQ++;
959 extern void zr36016_write (struct videocodec *codec,
964 jpeg_start (struct zoran *zr)
970 /* deassert P_reset, disable code transfer, deassert Active */
971 btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
972 /* stop flushing the internal code buffer */
973 btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
974 /* enable code transfer */
975 btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
978 btwrite(IRQ_MASK, ZR36057_ISR);
979 /* enable the JPEG IRQs */
980 btwrite(zr->card.jpeg_int |
981 ZR36057_ICR_JPEGRepIRQ |
982 ZR36057_ICR_IntPinEn,
985 set_frame(zr, 0); // \FRAME
987 /* set the JPEG codec guest ID */
988 reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
989 (0 << ZR36057_JCGI_JPEGuestReg);
990 btwrite(reg, ZR36057_JCGI);
992 if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
993 zr->card.video_codec == CODEC_TYPE_ZR36050) {
994 /* Enable processing on the ZR36016 */
996 zr36016_write(zr->vfe, 0, 1);
998 /* load the address of the GO register in the ZR36050 latch */
999 post_office_write(zr, 0, 0, 0);
1003 btor(ZR36057_JPC_Active, ZR36057_JPC);
1005 /* enable the Go generation */
1006 btor(ZR36057_JMC_Go_en, ZR36057_JMC);
1009 set_frame(zr, 1); // /FRAME
1011 dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
1015 zr36057_enable_jpg (struct zoran *zr,
1016 enum zoran_codec_mode mode)
1018 static int zero = 0;
1020 struct vfe_settings cap;
1022 zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
1024 zr->codec_mode = mode;
1026 cap.x = zr->jpg_settings.img_x;
1027 cap.y = zr->jpg_settings.img_y;
1028 cap.width = zr->jpg_settings.img_width;
1029 cap.height = zr->jpg_settings.img_height;
1031 zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
1032 cap.quality = zr->jpg_settings.jpg_comp.quality;
1036 case BUZ_MODE_MOTION_COMPRESS:
1037 /* In motion compress mode, the decoder output must be enabled, and
1038 * the video bus direction set to input.
1040 set_videobus_dir(zr, 0);
1041 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
1042 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1044 /* Take the JPEG codec and the VFE out of sleep */
1045 jpeg_codec_sleep(zr, 0);
1046 /* Setup the JPEG codec */
1047 zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
1048 sizeof(int), &field_size);
1049 zr->codec->set_video(zr->codec, zr->timing, &cap,
1051 zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
1055 zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
1056 sizeof(int), &field_size);
1057 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1059 zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
1062 init_jpeg_queue(zr);
1063 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1065 clear_interrupt_counters(zr);
1066 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
1070 case BUZ_MODE_MOTION_DECOMPRESS:
1071 /* In motion decompression mode, the decoder output must be disabled, and
1072 * the video bus direction set to output.
1074 decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
1075 set_videobus_dir(zr, 1);
1076 encoder_command(zr, ENCODER_SET_INPUT, &one);
1078 /* Take the JPEG codec and the VFE out of sleep */
1079 jpeg_codec_sleep(zr, 0);
1082 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1084 zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
1086 /* Setup the JPEG codec */
1087 zr->codec->set_video(zr->codec, zr->timing, &cap,
1089 zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
1091 init_jpeg_queue(zr);
1092 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1094 clear_interrupt_counters(zr);
1095 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
1101 /* shut down processing */
1102 btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
1104 btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
1106 btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
1110 set_videobus_dir(zr, 0);
1111 set_frame(zr, 1); // /FRAME
1112 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); // /CFlush
1113 btwrite(0, ZR36057_JPC); // \P_Reset,\CodTrnsEn,\Active
1114 btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
1115 btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
1116 jpeg_codec_reset(zr);
1117 jpeg_codec_sleep(zr, 1);
1118 zr36057_adjust_vfe(zr, mode);
1120 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
1121 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1123 dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
1129 /* when this is called the spinlock must be held */
1131 zoran_feed_stat_com (struct zoran *zr)
1133 /* move frames from pending queue to DMA */
1135 int frame, i, max_stat_com;
1138 (zr->jpg_settings.TmpDcm ==
1139 1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
1141 while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
1142 zr->jpg_dma_head < zr->jpg_que_head) {
1144 frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
1145 if (zr->jpg_settings.TmpDcm == 1) {
1146 /* fill 1 stat_com entry */
1147 i = (zr->jpg_dma_head -
1148 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1149 if (!(zr->stat_com[i] & 1))
1152 zr->jpg_buffers.buffer[frame].frag_tab_bus;
1154 /* fill 2 stat_com entries */
1155 i = ((zr->jpg_dma_head -
1156 zr->jpg_err_shift) & 1) * 2;
1157 if (!(zr->stat_com[i] & 1))
1160 zr->jpg_buffers.buffer[frame].frag_tab_bus;
1161 zr->stat_com[i + 1] =
1162 zr->jpg_buffers.buffer[frame].frag_tab_bus;
1164 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
1168 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
1169 zr->jpg_queued_num++;
1172 /* when this is called the spinlock must be held */
1174 zoran_reap_stat_com (struct zoran *zr)
1176 /* move frames from DMA queue to done queue */
1182 struct zoran_jpg_buffer *buffer;
1185 /* In motion decompress we don't have a hardware frame counter,
1186 * we just count the interrupts here */
1188 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1191 while (zr->jpg_dma_tail < zr->jpg_dma_head) {
1192 if (zr->jpg_settings.TmpDcm == 1)
1193 i = (zr->jpg_dma_tail -
1194 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1196 i = ((zr->jpg_dma_tail -
1197 zr->jpg_err_shift) & 1) * 2 + 1;
1199 stat_com = zr->stat_com[i];
1201 if ((stat_com & 1) == 0) {
1204 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1205 buffer = &zr->jpg_buffers.buffer[frame];
1206 do_gettimeofday(&buffer->bs.timestamp);
1208 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1209 buffer->bs.length = (stat_com & 0x7fffff) >> 1;
1211 /* update sequence number with the help of the counter in stat_com */
1213 seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
1214 dif = (seq - zr->jpg_seq_num) & 0xff;
1215 zr->jpg_seq_num += dif;
1217 buffer->bs.length = 0;
1220 zr->jpg_settings.TmpDcm ==
1221 2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
1222 buffer->state = BUZ_STATE_DONE;
1229 error_handler (struct zoran *zr,
1233 /* This is JPEG error handling part */
1234 if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) &&
1235 (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) {
1236 //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
1240 if ((stat & 1) == 0 &&
1241 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
1242 zr->jpg_dma_tail - zr->jpg_que_tail >=
1243 zr->jpg_buffers.num_buffers) {
1244 /* No free buffers... */
1245 zoran_reap_stat_com(zr);
1246 zoran_feed_stat_com(zr);
1247 wake_up_interruptible(&zr->jpg_capq);
1248 zr->JPEG_missed = 0;
1252 if (zr->JPEG_error != 1) {
1254 * First entry: error just happened during normal operation
1256 * In BUZ_MODE_MOTION_COMPRESS:
1258 * Possible glitch in TV signal. In this case we should
1259 * stop the codec and wait for good quality signal before
1260 * restarting it to avoid further problems
1262 * In BUZ_MODE_MOTION_DECOMPRESS:
1264 * Bad JPEG frame: we have to mark it as processed (codec crashed
1265 * and was not able to do it itself), and to remove it from queue.
1267 btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
1269 stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
1270 btwrite(0, ZR36057_JPC);
1271 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
1272 jpeg_codec_reset(zr);
1273 jpeg_codec_sleep(zr, 1);
1278 if (*zr_debug > 1 && zr->num_errors <= 8) {
1281 zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1283 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1284 ZR_DEVNAME(zr), stat, zr->last_isr,
1285 zr->jpg_que_tail, zr->jpg_dma_tail,
1286 zr->jpg_dma_head, zr->jpg_que_head,
1287 zr->jpg_seq_num, frame);
1288 printk("stat_com frames:");
1291 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1293 i < zr->jpg_buffers.num_buffers;
1295 if (zr->stat_com[j] ==
1308 /* Find an entry in stat_com and rotate contents */
1312 if (zr->jpg_settings.TmpDcm == 1)
1313 i = (zr->jpg_dma_tail -
1314 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1316 i = ((zr->jpg_dma_tail -
1317 zr->jpg_err_shift) & 1) * 2;
1318 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1319 /* Mimic zr36067 operation */
1320 zr->stat_com[i] |= 1;
1321 if (zr->jpg_settings.TmpDcm != 1)
1322 zr->stat_com[i + 1] |= 1;
1324 zoran_reap_stat_com(zr);
1325 zoran_feed_stat_com(zr);
1326 wake_up_interruptible(&zr->jpg_capq);
1327 /* Find an entry in stat_com again after refill */
1328 if (zr->jpg_settings.TmpDcm == 1)
1329 i = (zr->jpg_dma_tail -
1330 zr->jpg_err_shift) &
1333 i = ((zr->jpg_dma_tail -
1334 zr->jpg_err_shift) & 1) * 2;
1337 /* Rotate stat_comm entries to make current entry first */
1339 u32 bus_addr[BUZ_NUM_STAT_COM];
1341 memcpy(bus_addr, zr->stat_com,
1343 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1348 zr->jpg_err_shift += i;
1349 zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
1351 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
1352 zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
1356 /* Now the stat_comm buffer is ready for restart */
1360 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1361 decoder_command(zr, DECODER_GET_STATUS, &status);
1362 mode = CODEC_DO_COMPRESSION;
1365 mode = CODEC_DO_EXPANSION;
1367 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1368 (status & DECODER_STATUS_GOOD)) {
1369 /********** RESTART code *************/
1370 jpeg_codec_reset(zr);
1371 zr->codec->set_mode(zr->codec, mode);
1372 zr36057_set_jpg(zr, zr->codec_mode);
1375 if (zr->num_errors <= 8)
1376 dprintk(2, KERN_INFO "%s: Restart\n",
1379 zr->JPEG_missed = 0;
1381 /********** End RESTART code ***********/
1389 struct pt_regs *regs)
1394 unsigned long flags;
1396 zr = (struct zoran *) dev_id;
1400 /* Testing interrupts */
1401 spin_lock_irqsave(&zr->spinlock, flags);
1402 while ((stat = count_reset_interrupt(zr))) {
1403 if (count++ > 100) {
1404 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1407 "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
1408 ZR_DEVNAME(zr), stat);
1409 wake_up_interruptible(&zr->test_q);
1412 zr->last_isr = stat;
1413 spin_unlock_irqrestore(&zr->spinlock, flags);
1417 spin_lock_irqsave(&zr->spinlock, flags);
1419 /* get/clear interrupt status bits */
1420 stat = count_reset_interrupt(zr);
1421 astat = stat & IRQ_MASK;
1427 "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
1428 astat, btread(ZR36057_ICR));
1429 if (astat & zr->card.vsync_int) { // SW
1431 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1432 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1433 /* count missed interrupts */
1436 //post_office_read(zr,1,0);
1437 /* Interrupts may still happen when
1438 * zr->v4l_memgrab_active is switched off.
1439 * We simply ignore them */
1441 if (zr->v4l_memgrab_active) {
1443 /* A lot more checks should be here ... */
1444 if ((btread(ZR36057_VSSFGR) &
1445 ZR36057_VSSFGR_SnapShot) == 0)
1448 "%s: BuzIRQ with SnapShot off ???\n",
1451 if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
1452 /* There is a grab on a frame going on, check if it has finished */
1454 if ((btread(ZR36057_VSSFGR) &
1455 ZR36057_VSSFGR_FrameGrab) ==
1457 /* it is finished, notify the user */
1459 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
1460 zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
1461 do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
1462 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
1463 zr->v4l_pend_tail++;
1467 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
1468 wake_up_interruptible(&zr->v4l_capq);
1470 /* Check if there is another grab queued */
1472 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
1473 zr->v4l_pend_tail != zr->v4l_pend_head) {
1475 int frame = zr->v4l_pend[zr->v4l_pend_tail &
1479 zr->v4l_grab_frame = frame;
1481 /* Set zr36057 video front end and enable video */
1483 /* Buffer address */
1486 zr->v4l_buffers.buffer[frame].
1488 btwrite(reg, ZR36057_VDTR);
1489 if (zr->v4l_settings.height >
1494 btwrite(reg, ZR36057_VDBR);
1496 /* video stride, status, and frame grab register */
1498 if (zr->v4l_settings.height >
1505 ZR36057_VSSFGR_DispStride);
1506 reg |= ZR36057_VSSFGR_VidOvf;
1507 reg |= ZR36057_VSSFGR_SnapShot;
1508 reg |= ZR36057_VSSFGR_FrameGrab;
1509 btwrite(reg, ZR36057_VSSFGR);
1511 btor(ZR36057_VDCR_VidEn,
1516 /* even if we don't grab, we do want to increment
1517 * the sequence counter to see lost frames */
1520 #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1521 if (astat & ZR36057_ISR_CodRepIRQ) {
1522 zr->intr_counter_CodRepIRQ++;
1524 (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
1526 btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
1528 #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
1530 #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1531 if (astat & ZR36057_ISR_JPEGRepIRQ) {
1533 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1534 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1535 if (*zr_debug > 1 &&
1536 (!zr->frame_num || zr->JPEG_error)) {
1538 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1539 ZR_DEVNAME(zr), stat,
1540 zr->jpg_settings.odd_even,
1549 for (i = 0; i < 4; i++) {
1550 if (zr->stat_com[i] & 1)
1555 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1563 if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics
1564 zr->JPEG_max_missed =
1566 if (zr->JPEG_missed <
1567 zr->JPEG_min_missed)
1568 zr->JPEG_min_missed =
1572 if (*zr_debug > 2 && zr->frame_num < 6) {
1574 printk("%s: seq=%ld stat_com:",
1575 ZR_DEVNAME(zr), zr->jpg_seq_num);
1576 for (i = 0; i < 4; i++) {
1583 zr->JPEG_missed = 0;
1585 zoran_reap_stat_com(zr);
1586 zoran_feed_stat_com(zr);
1587 wake_up_interruptible(&zr->jpg_capq);
1591 "%s: JPEG interrupt while not in motion (de)compress mode!\n",
1595 #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
1597 /* DATERR, too many fields missed, error processing */
1598 if ((astat & zr->card.jpeg_int) ||
1599 zr->JPEG_missed > 25 ||
1600 zr->JPEG_error == 1 ||
1601 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
1602 (zr->frame_num & (zr->JPEG_missed >
1603 zr->jpg_settings.field_per_buff)))) {
1604 error_handler(zr, astat, stat);
1609 dprintk(2, KERN_WARNING "%s: irq loop %d\n",
1610 ZR_DEVNAME(zr), count);
1612 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1615 "%s: IRQ lockup, cleared int mask\n",
1620 zr->last_isr = stat;
1622 spin_unlock_irqrestore(&zr->spinlock, flags);
1628 zoran_set_pci_master (struct zoran *zr,
1632 pci_set_master(zr->pci_dev);
1636 pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
1637 command &= ~PCI_COMMAND_MASTER;
1638 pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
1643 zoran_init_hardware (struct zoran *zr)
1647 /* Enable bus-mastering */
1648 zoran_set_pci_master(zr, 1);
1650 /* Initialize the board */
1651 if (zr->card.init) {
1655 j = zr->card.input[zr->input].muxsel;
1657 decoder_command(zr, 0, NULL);
1658 decoder_command(zr, DECODER_SET_NORM, &zr->norm);
1659 decoder_command(zr, DECODER_SET_INPUT, &j);
1661 encoder_command(zr, 0, NULL);
1662 encoder_command(zr, ENCODER_SET_NORM, &zr->norm);
1663 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1665 /* toggle JPEG codec sleep to sync PLL */
1666 jpeg_codec_sleep(zr, 1);
1667 jpeg_codec_sleep(zr, 0);
1669 /* set individual interrupt enables (without GIRQ1)
1670 * but don't global enable until zoran_open() */
1672 //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW
1673 // It looks like using only JPEGRepIRQEn is not always reliable,
1674 // may be when JPEG codec crashes it won't generate IRQ? So,
1675 /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
1676 zr36057_init_vfe(zr);
1678 zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
1680 btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
1684 zr36057_restart (struct zoran *zr)
1686 btwrite(0, ZR36057_SPGPPCR);
1688 btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
1691 /* assert P_Reset */
1692 btwrite(0, ZR36057_JPC);
1693 /* set up GPIO direction - all output */
1694 btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
1696 /* set up GPIO pins and guest bus timing */
1697 btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
1701 * initialize video front end
1705 zr36057_init_vfe (struct zoran *zr)
1709 reg = btread(ZR36057_VFESPFR);
1710 reg |= ZR36057_VFESPFR_LittleEndian;
1711 reg &= ~ZR36057_VFESPFR_VCLKPol;
1712 reg |= ZR36057_VFESPFR_ExtFl;
1713 reg |= ZR36057_VFESPFR_TopField;
1714 btwrite(reg, ZR36057_VFESPFR);
1715 reg = btread(ZR36057_VDCR);
1716 if (pci_pci_problems & PCIPCI_TRITON)
1717 // || zr->revision < 1) // Revision 1 has also Triton support
1718 reg &= ~ZR36057_VDCR_Triton;
1720 reg |= ZR36057_VDCR_Triton;
1721 btwrite(reg, ZR36057_VDCR);
1725 * Interface to decoder and encoder chips using i2c bus
1729 decoder_command (struct zoran *zr,
1733 if (zr->decoder == NULL)
1736 if (zr->card.type == LML33 &&
1737 (cmd == DECODER_SET_NORM || DECODER_SET_INPUT)) {
1740 // Bt819 needs to reset its FIFO buffer using #FRST pin and
1741 // LML33 card uses GPIO(7) for that.
1743 res = zr->decoder->driver->command(zr->decoder, cmd, data);
1748 return zr->decoder->driver->command(zr->decoder, cmd,
1753 encoder_command (struct zoran *zr,
1757 if (zr->encoder == NULL)
1760 return zr->encoder->driver->command(zr->encoder, cmd, data);