Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / media / video / zoran_device.c
index a35d518..c690b2e 100644 (file)
@@ -4,7 +4,7 @@
  * Media Labs LML33/LML33R10.
  *
  * This part handles device access (PCI/I2C/codec/...)
- * 
+ *
  * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
  *
  * Currently maintained by:
@@ -32,6 +32,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/vmalloc.h>
+#include <linux/byteorder/generic.h>
 
 #include <linux/interrupt.h>
 #include <linux/proc_fs.h>
@@ -45,6 +46,7 @@
 #include <linux/video_decoder.h>
 #include <linux/video_encoder.h>
 #include <linux/delay.h>
+#include <linux/wait.h>
 
 #include <asm/io.h>
 
@@ -57,7 +59,6 @@
                   ZR36057_ISR_JPEGRepIRQ )
 
 extern const struct zoran_format zoran_formats[];
-extern const int zoran_num_formats;
 
 extern int *zr_debug;
 
@@ -76,10 +77,13 @@ static int lml33dpath = 0;  /* 1 will use digital path in capture
                                 * load on Bt819 input, there will be
                                 * some image imperfections */
 
-MODULE_PARM(lml33dpath, "i");
+module_param(lml33dpath, bool, 0);
 MODULE_PARM_DESC(lml33dpath,
                 "Use digital path capture mode (on LML33 cards)");
 
+static void
+zr36057_init_vfe (struct zoran *zr);
+
 /*
  * General Purpose I/O and Guest bus access
  */
@@ -488,7 +492,7 @@ zr36057_set_vfe (struct zoran              *zr,
        /* (Ronald) don't write this if overlay_mask = NULL */
        if (zr->overlay_mask) {
                /* Write overlay clipping mask data, but don't enable overlay clipping */
-               /* RJ: since this makes only sense on the screen, we use 
+               /* RJ: since this makes only sense on the screen, we use
                 * zr->overlay_settings.width instead of video_width */
 
                mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
@@ -693,11 +697,10 @@ wait_grab_pending (struct zoran *zr)
        if (!zr->v4l_memgrab_active)
                return 0;
 
-       while (zr->v4l_pend_tail != zr->v4l_pend_head) {
-               interruptible_sleep_on(&zr->v4l_capq);
-               if (signal_pending(current))
-                       return -ERESTARTSYS;
-       }
+       wait_event_interruptible(zr->v4l_capq,
+                       (zr->v4l_pend_tail == zr->v4l_pend_head));
+       if (signal_pending(current))
+               return -ERESTARTSYS;
 
        spin_lock_irqsave(&zr->spinlock, flags);
        zr36057_set_memgrab(zr, 0);
@@ -758,7 +761,7 @@ init_jpeg_queue (struct zoran *zr)
                zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
        }
        for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
-               zr->stat_com[i] = 1;    /* mark as unavailable to zr36057 */
+               zr->stat_com[i] = cpu_to_le32(1);       /* mark as unavailable to zr36057 */
        }
 }
 
@@ -816,12 +819,12 @@ zr36057_set_jpg (struct zoran          *zr,
        if (zr->card.vfe_pol.hsync_pol)
                btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
        else
-               btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);           
+               btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
        reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
              (tvn->Wt << ZR36057_HSP_LineTot);
        btwrite(reg, ZR36057_HSP);
        reg = ((zr->jpg_settings.img_x +
-               tvn->HStart + 4) << ZR36057_FHAP_NAX) |
+               tvn->HStart + 4) << ZR36057_FHAP_NAX) |
              (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
        btwrite(reg, ZR36057_FHAP);
 
@@ -1033,7 +1036,10 @@ zr36057_enable_jpg (struct zoran          *zr,
 
        switch (mode) {
 
-       case BUZ_MODE_MOTION_COMPRESS:
+       case BUZ_MODE_MOTION_COMPRESS: {
+               struct jpeg_app_marker app;
+               struct jpeg_com_marker com;
+
                /* In motion compress mode, the decoder output must be enabled, and
                 * the video bus direction set to input.
                 */
@@ -1043,6 +1049,19 @@ zr36057_enable_jpg (struct zoran          *zr,
 
                /* Take the JPEG codec and the VFE out of sleep */
                jpeg_codec_sleep(zr, 0);
+
+               /* set JPEG app/com marker */
+               app.appn = zr->jpg_settings.jpg_comp.APPn;
+               app.len = zr->jpg_settings.jpg_comp.APP_len;
+               memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
+               zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
+                                  sizeof(struct jpeg_app_marker), &app);
+
+               com.len = zr->jpg_settings.jpg_comp.COM_len;
+               memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
+               zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
+                                  sizeof(struct jpeg_com_marker), &com);
+
                /* Setup the JPEG codec */
                zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
                                   sizeof(int), &field_size);
@@ -1066,6 +1085,7 @@ zr36057_enable_jpg (struct zoran          *zr,
                dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
                        ZR_DEVNAME(zr));
                break;
+       }
 
        case BUZ_MODE_MOTION_DECOMPRESS:
                /* In motion decompression mode, the decoder output must be disabled, and
@@ -1146,20 +1166,20 @@ zoran_feed_stat_com (struct zoran *zr)
                        /* fill 1 stat_com entry */
                        i = (zr->jpg_dma_head -
                             zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
-                       if (!(zr->stat_com[i] & 1))
+                       if (!(zr->stat_com[i] & cpu_to_le32(1)))
                                break;
                        zr->stat_com[i] =
-                           zr->jpg_buffers.buffer[frame].frag_tab_bus;
+                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
                } else {
                        /* fill 2 stat_com entries */
                        i = ((zr->jpg_dma_head -
                              zr->jpg_err_shift) & 1) * 2;
-                       if (!(zr->stat_com[i] & 1))
+                       if (!(zr->stat_com[i] & cpu_to_le32(1)))
                                break;
                        zr->stat_com[i] =
-                           zr->jpg_buffers.buffer[frame].frag_tab_bus;
+                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
                        zr->stat_com[i + 1] =
-                           zr->jpg_buffers.buffer[frame].frag_tab_bus;
+                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
                }
                zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
                zr->jpg_dma_head++;
@@ -1196,7 +1216,7 @@ zoran_reap_stat_com (struct zoran *zr)
                        i = ((zr->jpg_dma_tail -
                              zr->jpg_err_shift) & 1) * 2 + 1;
 
-               stat_com = zr->stat_com[i];
+               stat_com = le32_to_cpu(zr->stat_com[i]);
 
                if ((stat_com & 1) == 0) {
                        return;
@@ -1252,15 +1272,15 @@ error_handler (struct zoran *zr,
        if (zr->JPEG_error != 1) {
                /*
                 * First entry: error just happened during normal operation
-                * 
+                *
                 * In BUZ_MODE_MOTION_COMPRESS:
-                * 
+                *
                 * Possible glitch in TV signal. In this case we should
                 * stop the codec and wait for good quality signal before
                 * restarting it to avoid further problems
-                * 
+                *
                 * In BUZ_MODE_MOTION_DECOMPRESS:
-                * 
+                *
                 * Bad JPEG frame: we have to mark it as processed (codec crashed
                 * and was not able to do it itself), and to remove it from queue.
                 */
@@ -1292,7 +1312,7 @@ error_handler (struct zoran *zr,
                                        for (i = 0;
                                             i < zr->jpg_buffers.num_buffers;
                                             i++) {
-                                               if (zr->stat_com[j] ==
+                                               if (le32_to_cpu(zr->stat_com[j]) ==
                                                    zr->jpg_buffers.
                                                    buffer[i].
                                                    frag_tab_bus) {
@@ -1304,7 +1324,6 @@ error_handler (struct zoran *zr,
                                printk("\n");
                        }
                }
-
                /* Find an entry in stat_com and rotate contents */
                {
                        int i;
@@ -1317,9 +1336,9 @@ error_handler (struct zoran *zr,
                                      zr->jpg_err_shift) & 1) * 2;
                        if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
                                /* Mimic zr36067 operation */
-                               zr->stat_com[i] |= 1;
+                               zr->stat_com[i] |= cpu_to_le32(1);
                                if (zr->jpg_settings.TmpDcm != 1)
-                                       zr->stat_com[i + 1] |= 1;
+                                       zr->stat_com[i + 1] |= cpu_to_le32(1);
                                /* Refill */
                                zoran_reap_stat_com(zr);
                                zoran_feed_stat_com(zr);
@@ -1338,12 +1357,17 @@ error_handler (struct zoran *zr,
                                int j;
                                u32 bus_addr[BUZ_NUM_STAT_COM];
 
+                               /* Here we are copying the stat_com array, which
+                                * is already in little endian format, so
+                                * no endian conversions here
+                                */
                                memcpy(bus_addr, zr->stat_com,
                                       sizeof(bus_addr));
                                for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
                                        zr->stat_com[j] =
                                            bus_addr[(i + j) &
                                                     BUZ_MASK_STAT_COM];
+
                                }
                                zr->jpg_err_shift += i;
                                zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
@@ -1547,7 +1571,7 @@ zoran_irq (int             irq,
                                                int i;
                                                strcpy(sv, sc);
                                                for (i = 0; i < 4; i++) {
-                                                       if (zr->stat_com[i] & 1)
+                                                       if (le32_to_cpu(zr->stat_com[i]) & 1)
                                                                sv[i] = '1';
                                                }
                                                sv[4] = 0;
@@ -1575,7 +1599,7 @@ zoran_irq (int             irq,
                                               ZR_DEVNAME(zr), zr->jpg_seq_num);
                                        for (i = 0; i < 4; i++) {
                                                printk(" %08x",
-                                                      zr->stat_com[i]);
+                                                      le32_to_cpu(zr->stat_com[i]));
                                        }
                                        printk("\n");
                                }
@@ -1701,7 +1725,7 @@ zr36057_restart (struct zoran *zr)
  * initialize video front end
  */
 
-void
+static void
 zr36057_init_vfe (struct zoran *zr)
 {
        u32 reg;