fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / media / video / zoran_driver.c
index 8af43a6..862a984 100644 (file)
@@ -44,7 +44,6 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/config.h>
 #include <linux/version.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -52,6 +51,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/vmalloc.h>
+#include <linux/wait.h>
 #include <linux/byteorder/generic.h>
 
 #include <linux/interrupt.h>
@@ -72,6 +72,7 @@
                             )
 
 #include <linux/videodev.h>
+#include <media/v4l2-common.h>
 #include "videocodec.h"
 
 #include <asm/io.h>
 
 #include <linux/video_decoder.h>
 #include <linux/video_encoder.h>
+#include <linux/mutex.h>
 #include "zoran.h"
 #include "zoran_device.h"
 #include "zoran_card.h"
 
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
        /* we declare some card type definitions here, they mean
         * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
 #define ZORAN_V4L2_VID_FLAGS ( \
@@ -92,7 +94,7 @@
                                V4L2_CAP_VIDEO_CAPTURE |\
                                V4L2_CAP_VIDEO_OUTPUT |\
                                V4L2_CAP_VIDEO_OVERLAY \
-                              )
+                             )
 #endif
 
 #include <asm/byteorder.h>
@@ -101,7 +103,7 @@ const struct zoran_format zoran_formats[] = {
        {
                .name = "15-bit RGB",
                .palette = VIDEO_PALETTE_RGB555,
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
 #ifdef __LITTLE_ENDIAN
                .fourcc = V4L2_PIX_FMT_RGB555,
 #else
@@ -115,7 +117,7 @@ const struct zoran_format zoran_formats[] = {
        }, {
                .name = "16-bit RGB",
                .palette = VIDEO_PALETTE_RGB565,
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
 #ifdef __LITTLE_ENDIAN
                .fourcc = V4L2_PIX_FMT_RGB565,
 #else
@@ -129,7 +131,7 @@ const struct zoran_format zoran_formats[] = {
        }, {
                .name = "24-bit RGB",
                .palette = VIDEO_PALETTE_RGB24,
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
 #ifdef __LITTLE_ENDIAN
                .fourcc = V4L2_PIX_FMT_BGR24,
 #else
@@ -143,7 +145,7 @@ const struct zoran_format zoran_formats[] = {
        }, {
                .name = "32-bit RGB",
                .palette = VIDEO_PALETTE_RGB32,
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
 #ifdef __LITTLE_ENDIAN
                .fourcc = V4L2_PIX_FMT_BGR32,
 #else
@@ -157,17 +159,17 @@ const struct zoran_format zoran_formats[] = {
        }, {
                .name = "4:2:2, packed, YUYV",
                .palette = VIDEO_PALETTE_YUV422,
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
                .fourcc = V4L2_PIX_FMT_YUYV,
                .colorspace = V4L2_COLORSPACE_SMPTE170M,
 #endif
                .depth = 16,
                .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
+                        ZORAN_FORMAT_OVERLAY,
        }, {
                .name = "Hardware-encoded Motion-JPEG",
                .palette = -1,
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
                .fourcc = V4L2_PIX_FMT_MJPEG,
                .colorspace = V4L2_COLORSPACE_SMPTE170M,
 #endif
@@ -208,7 +210,7 @@ static int lock_norm = 0;   /* 1=Don't change TV standard (norm) */
 module_param(lock_norm, int, 0);
 MODULE_PARM_DESC(lock_norm, "Users can't change norm");
 
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
        /* small helper function for calculating buffersizes for v4l2
         * we calculate the nearest higher power-of-two, which
         * will be the recommended buffersize */
@@ -649,7 +651,7 @@ jpg_fbuffer_free (struct file *file)
                                     off += PAGE_SIZE)
                                        ClearPageReserved(MAP_NR
                                                          (mem + off));
-                               kfree((void *) mem);
+                               kfree(mem);
                                fh->jpg_buffers.buffer[i].frag_tab[0] = 0;
                                fh->jpg_buffers.buffer[i].frag_tab[1] = 0;
                        }
@@ -668,7 +670,7 @@ jpg_fbuffer_free (struct file *file)
                                                                       j]))));
                                free_page((unsigned long)
                                          bus_to_virt
-                                                 (le32_to_cpu
+                                                 (le32_to_cpu
                                                   (fh->jpg_buffers.
                                                      buffer[i].
                                                      frag_tab[2 * j])));
@@ -918,12 +920,12 @@ v4l_sync (struct file *file,
        }
 
        /* wait on this buffer to get ready */
-       while (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_PEND) {
-               if (!interruptible_sleep_on_timeout(&zr->v4l_capq, 10 * HZ))
-                       return -ETIME;
-               else if (signal_pending(current))
-                       return -ERESTARTSYS;
-       }
+       if (!wait_event_interruptible_timeout(zr->v4l_capq,
+                               (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND),
+                               10*HZ))
+               return -ETIME;
+       if (signal_pending(current))
+               return -ERESTARTSYS;
 
        /* buffer should now be in BUZ_STATE_DONE */
        if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE)
@@ -995,8 +997,6 @@ zoran_jpg_queue_frame (struct file          *file,
                return -EINVAL;
        }
 
-       spin_lock_irqsave(&zr->spinlock, flags);
-
        if (fh->jpg_buffers.active == ZORAN_FREE) {
                if (zr->jpg_buffers.active == ZORAN_FREE) {
                        zr->jpg_buffers = fh->jpg_buffers;
@@ -1015,6 +1015,8 @@ zoran_jpg_queue_frame (struct file          *file,
                zr36057_enable_jpg(zr, mode);
        }
 
+       spin_lock_irqsave(&zr->spinlock, flags);
+
        if (!res) {
                switch (zr->jpg_buffers.buffer[num].state) {
                case BUZ_STATE_DONE:
@@ -1107,7 +1109,7 @@ jpg_sync (struct file       *file,
        struct zoran_fh *fh = file->private_data;
        struct zoran *zr = fh->zr;
        unsigned long flags;
-       int frame, timeout;
+       int frame;
 
        if (fh->jpg_buffers.active == ZORAN_FREE) {
                dprintk(1,
@@ -1124,29 +1126,26 @@ jpg_sync (struct file       *file,
                        ZR_DEVNAME(zr));
                return -EINVAL;
        }
-       while (zr->jpg_que_tail == zr->jpg_dma_tail) {
-               if (zr->jpg_dma_tail == zr->jpg_dma_head)
-                       break;
+       if (!wait_event_interruptible_timeout(zr->jpg_capq,
+                       (zr->jpg_que_tail != zr->jpg_dma_tail ||
+                        zr->jpg_dma_tail == zr->jpg_dma_head),
+                       10*HZ)) {
+               int isr;
 
-               timeout =
-                   interruptible_sleep_on_timeout(&zr->jpg_capq, 10 * HZ);
-               if (!timeout) {
-                       int isr;
-
-                       btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
-                       udelay(1);
-                       zr->codec->control(zr->codec, CODEC_G_STATUS,
+               btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
+               udelay(1);
+               zr->codec->control(zr->codec, CODEC_G_STATUS,
                                           sizeof(isr), &isr);
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: jpg_sync() - timeout: codec isr=0x%02x\n",
-                               ZR_DEVNAME(zr), isr);
+               dprintk(1,
+                       KERN_ERR
+                       "%s: jpg_sync() - timeout: codec isr=0x%02x\n",
+                       ZR_DEVNAME(zr), isr);
 
-                       return -ETIME;
+               return -ETIME;
 
-               } else if (signal_pending(current))
-                       return -ERESTARTSYS;
        }
+       if (signal_pending(current))
+               return -ERESTARTSYS;
 
        spin_lock_irqsave(&zr->spinlock, flags);
 
@@ -1294,7 +1293,7 @@ zoran_open (struct inode *inode,
 
        /* see fs/device.c - the kernel already locks during open(),
         * so locking ourselves only causes deadlocks */
-       /*down(&zr->resource_lock);*/
+       /*mutex_lock(&zr->resource_lock);*/
 
        if (!zr->decoder) {
                dprintk(1,
@@ -1313,7 +1312,7 @@ zoran_open (struct inode *inode,
                res = -ENODEV;
                goto open_unlock_and_return;
        }
-       if (!try_module_get(zr->decoder->driver->owner)) {
+       if (!try_module_get(zr->decoder->driver->driver.owner)) {
                dprintk(1,
                        KERN_ERR
                        "%s: failed to grab ownership of i2c decoder\n",
@@ -1323,13 +1322,13 @@ zoran_open (struct inode *inode,
                goto open_unlock_and_return;
        }
        if (zr->encoder &&
-           !try_module_get(zr->encoder->driver->owner)) {
+           !try_module_get(zr->encoder->driver->driver.owner)) {
                dprintk(1,
                        KERN_ERR
                        "%s: failed to grab ownership of i2c encoder\n",
                        ZR_DEVNAME(zr));
                res = -EIO;
-               module_put(zr->decoder->driver->owner);
+               module_put(zr->decoder->driver->driver.owner);
                module_put(THIS_MODULE);
                goto open_unlock_and_return;
        }
@@ -1347,7 +1346,7 @@ zoran_open (struct inode *inode,
                ZR_DEVNAME(zr), current->comm, current->pid, zr->user);
 
        /* now, create the open()-specific file_ops struct */
-       fh = kmalloc(sizeof(struct zoran_fh), GFP_KERNEL);
+       fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
        if (!fh) {
                dprintk(1,
                        KERN_ERR
@@ -1356,7 +1355,6 @@ zoran_open (struct inode *inode,
                res = -ENOMEM;
                goto open_unlock_and_return;
        }
-       memset(fh, 0, sizeof(struct zoran_fh));
        /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
         * on norm-change! */
        fh->overlay_mask =
@@ -1374,7 +1372,7 @@ zoran_open (struct inode *inode,
        if (zr->user++ == 0)
                first_open = 1;
 
-       /*up(&zr->resource_lock);*/
+       /*mutex_unlock(&zr->resource_lock);*/
 
        /* default setup - TODO: look at flags */
        if (first_open) {       /* First device open */
@@ -1395,16 +1393,16 @@ zoran_open (struct inode *inode,
 open_unlock_and_return:
        /* if we grabbed locks, release them accordingly */
        if (have_module_locks) {
-               module_put(zr->decoder->driver->owner);
+               module_put(zr->decoder->driver->driver.owner);
                if (zr->encoder) {
-                       module_put(zr->encoder->driver->owner);
+                       module_put(zr->encoder->driver->driver.owner);
                }
                module_put(THIS_MODULE);
        }
 
        /* if there's no device found, we didn't obtain the lock either */
        if (zr) {
-               /*up(&zr->resource_lock);*/
+               /*mutex_unlock(&zr->resource_lock);*/
        }
 
        return res;
@@ -1422,7 +1420,7 @@ zoran_close (struct inode *inode,
 
        /* kernel locks (fs/device.c), so don't do that ourselves
         * (prevents deadlocks) */
-       /*down(&zr->resource_lock);*/
+       /*mutex_lock(&zr->resource_lock);*/
 
        zoran_close_end_session(file);
 
@@ -1463,13 +1461,13 @@ zoran_close (struct inode *inode,
        kfree(fh);
 
        /* release locks on the i2c modules */
-       module_put(zr->decoder->driver->owner);
+       module_put(zr->decoder->driver->driver.owner);
        if (zr->encoder) {
-                module_put(zr->encoder->driver->owner);
+                module_put(zr->encoder->driver->driver.owner);
        }
        module_put(THIS_MODULE);
 
-       /*up(&zr->resource_lock);*/
+       /*mutex_unlock(&zr->resource_lock);*/
 
        dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr));
 
@@ -1514,6 +1512,13 @@ setup_fbuffer (struct file               *file,
        if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
                return -EPERM;
 
+       /* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
+          ALi Magik (that needs very low latency while the card needs a
+          higher value always) */
+
+       if (pci_pci_problems & (PCIPCI_FAIL | PCIAGP_FAIL | PCIPCI_ALIMAGIK))
+               return -ENXIO;
+
        /* we need a bytesperline value, even if not given */
        if (!bytesperline)
                bytesperline = width * ((fmt->depth + 7) & ~7) / 8;
@@ -1763,7 +1768,7 @@ setup_overlay (struct file *file,
        return wait_grab_pending(zr);
 }
 
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
        /* get the status of a buffer in the clients buffer queue */
 static int
 zoran_v4l2_buffer_status (struct file        *file,
@@ -1873,7 +1878,7 @@ zoran_v4l2_buffer_status (struct file        *file,
 
 static int
 zoran_set_norm (struct zoran *zr,
-               int           norm) /* VIDEO_MODE_* */
+               int           norm) /* VIDEO_MODE_* */
 {
        int norm_encoder, on;
 
@@ -2008,9 +2013,9 @@ zoran_set_input (struct zoran *zr,
 
 static int
 zoran_do_ioctl (struct inode *inode,
-               struct file  *file,
-               unsigned int  cmd,
-               void         *arg)
+               struct file  *file,
+               unsigned int  cmd,
+               void         *arg)
 {
        struct zoran_fh *fh = file->private_data;
        struct zoran *zr = fh->zr;
@@ -2030,14 +2035,14 @@ zoran_do_ioctl (struct inode *inode,
         * but moving the free code outside the munmap() handler fixes
         * all this... If someone knows why, please explain me (Ronald)
         */
-       if (!down_trylock(&zr->resource_lock)) {
+       if (!!mutex_trylock(&zr->resource_lock)) {
                /* we obtained it! Let's try to free some things */
                if (fh->jpg_buffers.ready_to_be_freed)
                        jpg_fbuffer_free(file);
                if (fh->v4l_buffers.ready_to_be_freed)
                        v4l_fbuffer_free(file);
 
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
        }
 
        switch (cmd) {
@@ -2049,17 +2054,17 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOCGCAP\n", ZR_DEVNAME(zr));
 
                memset(vcap, 0, sizeof(struct video_capability));
-               strncpy(vcap->name, ZR_DEVNAME(zr), sizeof(vcap->name));
+               strncpy(vcap->name, ZR_DEVNAME(zr), sizeof(vcap->name)-1);
                vcap->type = ZORAN_VID_TYPE;
 
                vcap->channels = zr->card.inputs;
                vcap->audios = 0;
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                vcap->maxwidth = BUZ_MAX_WIDTH;
                vcap->maxheight = BUZ_MAX_HEIGHT;
                vcap->minwidth = BUZ_MIN_WIDTH;
                vcap->minheight = BUZ_MIN_HEIGHT;
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -2087,9 +2092,9 @@ zoran_do_ioctl (struct inode *inode,
                vchan->tuners = 0;
                vchan->flags = 0;
                vchan->type = VIDEO_TYPE_CAMERA;
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                vchan->norm = zr->norm;
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                vchan->channel = channel;
 
                return 0;
@@ -2097,7 +2102,7 @@ zoran_do_ioctl (struct inode *inode,
                break;
 
                /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
-                * 
+                *
                 * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
                 * *                                 ^^^^^^^
                 * * The famos BTTV driver has it implemented with a struct video_channel argument
@@ -2116,7 +2121,7 @@ zoran_do_ioctl (struct inode *inode,
                        "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
                        ZR_DEVNAME(zr), vchan->channel, vchan->norm);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                if ((res = zoran_set_input(zr, vchan->channel)))
                        goto schan_unlock_and_return;
                if ((res = zoran_set_norm(zr, vchan->norm)))
@@ -2125,7 +2130,7 @@ zoran_do_ioctl (struct inode *inode,
                /* Make sure the changes come into effect */
                res = wait_grab_pending(zr);
        schan_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                return res;
        }
                break;
@@ -2137,7 +2142,7 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOCGPICT\n", ZR_DEVNAME(zr));
 
                memset(vpict, 0, sizeof(struct video_picture));
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                vpict->hue = zr->hue;
                vpict->brightness = zr->brightness;
                vpict->contrast = zr->contrast;
@@ -2148,7 +2153,7 @@ zoran_do_ioctl (struct inode *inode,
                } else {
                        vpict->depth = 0;
                }
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -2183,7 +2188,7 @@ zoran_do_ioctl (struct inode *inode,
                        return -EINVAL;
                }
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                decoder_command(zr, DECODER_SET_PICTURE, vpict);
 
@@ -2194,7 +2199,7 @@ zoran_do_ioctl (struct inode *inode,
 
                fh->overlay_settings.format = &zoran_formats[i];
 
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -2207,9 +2212,9 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOCCAPTURE - on=%d\n",
                        ZR_DEVNAME(zr), *on);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = setup_overlay(file, *on);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2222,12 +2227,12 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOCGWIN\n", ZR_DEVNAME(zr));
 
                memset(vwin, 0, sizeof(struct video_window));
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                vwin->x = fh->overlay_settings.x;
                vwin->y = fh->overlay_settings.y;
                vwin->width = fh->overlay_settings.width;
                vwin->height = fh->overlay_settings.height;
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                vwin->clipcount = 0;
                return 0;
        }
@@ -2244,12 +2249,12 @@ zoran_do_ioctl (struct inode *inode,
                        ZR_DEVNAME(zr), vwin->x, vwin->y, vwin->width,
                        vwin->height, vwin->clipcount);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res =
                    setup_window(file, vwin->x, vwin->y, vwin->width,
                                 vwin->height, vwin->clips,
                                 vwin->clipcount, NULL);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2261,9 +2266,9 @@ zoran_do_ioctl (struct inode *inode,
 
                dprintk(3, KERN_DEBUG "%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr));
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                *vbuf = zr->buffer;
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                return 0;
        }
                break;
@@ -2290,12 +2295,12 @@ zoran_do_ioctl (struct inode *inode,
                        return -EINVAL;
                }
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res =
                    setup_fbuffer(file, vbuf->base, &zoran_formats[i],
                                  vbuf->width, vbuf->height,
                                  vbuf->bytesperline);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2308,9 +2313,9 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOCSYNC - frame=%d\n",
                        ZR_DEVNAME(zr), *frame);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = v4l_sync(file, *frame);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                if (!res)
                        zr->v4l_sync_tail++;
                return res;
@@ -2328,9 +2333,9 @@ zoran_do_ioctl (struct inode *inode,
                        ZR_DEVNAME(zr), vmap->frame, vmap->width, vmap->height,
                        vmap->format);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = v4l_grab(file, vmap);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                return res;
        }
                break;
@@ -2351,7 +2356,7 @@ zoran_do_ioctl (struct inode *inode,
                            i * fh->v4l_buffers.buffer_size;
                }
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
                        dprintk(1,
@@ -2370,7 +2375,7 @@ zoran_do_ioctl (struct inode *inode,
                /* The next mmap will map the V4L buffers */
                fh->map_mode = ZORAN_MAP_MODE_RAW;
        v4l1reqbuf_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2424,7 +2429,7 @@ zoran_do_ioctl (struct inode *inode,
                bparams->major_version = MAJOR_VERSION;
                bparams->minor_version = MINOR_VERSION;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                bparams->norm = zr->norm;
                bparams->input = zr->input;
@@ -2453,7 +2458,7 @@ zoran_do_ioctl (struct inode *inode,
                bparams->jpeg_markers =
                    fh->jpg_settings.jpg_comp.jpeg_markers;
 
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                bparams->VFIFO_FB = 0;
 
@@ -2489,7 +2494,7 @@ zoran_do_ioctl (struct inode *inode,
                       sizeof(bparams->COM_data));
                settings.jpg_comp.jpeg_markers = bparams->jpeg_markers;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (zr->codec_mode != BUZ_MODE_IDLE) {
                        dprintk(1,
@@ -2509,7 +2514,7 @@ zoran_do_ioctl (struct inode *inode,
 
                fh->jpg_settings = settings;
        sparams_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2541,7 +2546,7 @@ zoran_do_ioctl (struct inode *inode,
                    breq->size > MAX_KMALLOC_MEM)
                        breq->size = MAX_KMALLOC_MEM;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
                        dprintk(1,
@@ -2564,7 +2569,7 @@ zoran_do_ioctl (struct inode *inode,
                 * also be *_PLAY, but it doesn't matter here */
                fh->map_mode = ZORAN_MAP_MODE_JPG_REC;
        jpgreqbuf_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2577,9 +2582,9 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_CAPT - frame=%d\n",
                        ZR_DEVNAME(zr), *frame);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2592,9 +2597,9 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_PLAY - frame=%d\n",
                        ZR_DEVNAME(zr), *frame);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2607,9 +2612,9 @@ zoran_do_ioctl (struct inode *inode,
 
                dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr));
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = jpg_sync(file, bsync);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -2633,7 +2638,7 @@ zoran_do_ioctl (struct inode *inode,
                input = zr->card.input[bstat->input].muxsel;
                norm = VIDEO_MODE_AUTO;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (zr->codec_mode != BUZ_MODE_IDLE) {
                        dprintk(1,
@@ -2658,7 +2663,7 @@ zoran_do_ioctl (struct inode *inode,
                decoder_command(zr, DECODER_SET_INPUT, &input);
                decoder_command(zr, DECODER_SET_NORM, &zr->norm);
        gstat_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                if (!res) {
                        bstat->signal =
@@ -2678,7 +2683,7 @@ zoran_do_ioctl (struct inode *inode,
        }
                break;
 
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
 
                /* The new video4linux2 capture interface - much nicer than video4linux1, since
                 * it allows for integrating the JPEG capturing calls inside standard v4l2
@@ -2691,10 +2696,10 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr));
 
                memset(cap, 0, sizeof(*cap));
-               strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card));
-               strncpy(cap->driver, "zoran", sizeof(cap->driver));
+               strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1);
+               strncpy(cap->driver, "zoran", sizeof(cap->driver)-1);
                snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
-                        zr->pci_dev->slot_name);
+                        pci_name(zr->pci_dev));
                cap->version =
                    KERNEL_VERSION(MAJOR_VERSION, MINOR_VERSION,
                                   RELEASE_VERSION);
@@ -2744,7 +2749,7 @@ zoran_do_ioctl (struct inode *inode,
                memset(fmt, 0, sizeof(*fmt));
                fmt->index = index;
                fmt->type = type;
-               strncpy(fmt->description, zoran_formats[i].name, 31);
+               strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1);
                fmt->pixelformat = zoran_formats[i].fourcc;
                if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED)
                        fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
@@ -2766,7 +2771,7 @@ zoran_do_ioctl (struct inode *inode,
                switch (fmt->type) {
                case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 
-                       down(&zr->resource_lock);
+                       mutex_lock(&zr->resource_lock);
 
                        fmt->fmt.win.w.left = fh->overlay_settings.x;
                        fmt->fmt.win.w.top = fh->overlay_settings.y;
@@ -2779,14 +2784,14 @@ zoran_do_ioctl (struct inode *inode,
                        else
                                fmt->fmt.win.field = V4L2_FIELD_TOP;
 
-                       up(&zr->resource_lock);
+                       mutex_unlock(&zr->resource_lock);
 
                        break;
 
                case V4L2_BUF_TYPE_VIDEO_CAPTURE:
                case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 
-                       down(&zr->resource_lock);
+                       mutex_lock(&zr->resource_lock);
 
                        if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
                            fh->map_mode == ZORAN_MAP_MODE_RAW) {
@@ -2840,7 +2845,7 @@ zoran_do_ioctl (struct inode *inode,
                                    V4L2_COLORSPACE_SMPTE170M;
                        }
 
-                       up(&zr->resource_lock);
+                       mutex_unlock(&zr->resource_lock);
 
                        break;
 
@@ -2873,7 +2878,7 @@ zoran_do_ioctl (struct inode *inode,
                                fmt->fmt.win.w.height,
                                fmt->fmt.win.clipcount,
                                fmt->fmt.win.bitmap);
-                       down(&zr->resource_lock);
+                       mutex_lock(&zr->resource_lock);
                        res =
                            setup_window(file, fmt->fmt.win.w.left,
                                         fmt->fmt.win.w.top,
@@ -2883,7 +2888,7 @@ zoran_do_ioctl (struct inode *inode,
                                           fmt->fmt.win.clips,
                                         fmt->fmt.win.clipcount,
                                         fmt->fmt.win.bitmap);
-                       up(&zr->resource_lock);
+                       mutex_unlock(&zr->resource_lock);
                        return res;
                        break;
 
@@ -2920,7 +2925,7 @@ zoran_do_ioctl (struct inode *inode,
                        }
 
                        if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
-                               down(&zr->resource_lock);
+                               mutex_lock(&zr->resource_lock);
 
                                settings = fh->jpg_settings;
 
@@ -2998,7 +3003,7 @@ zoran_do_ioctl (struct inode *inode,
                                    ZORAN_MAP_MODE_JPG_REC :
                                    ZORAN_MAP_MODE_JPG_PLAY;
                        sfmtjpg_unlock_and_return:
-                               up(&zr->resource_lock);
+                               mutex_unlock(&zr->resource_lock);
                        } else {
                                for (i = 0; i < zoran_num_formats; i++)
                                        if (fmt->fmt.pix.pixelformat ==
@@ -3013,7 +3018,7 @@ zoran_do_ioctl (struct inode *inode,
                                                (char *) &printformat);
                                        return -EINVAL;
                                }
-                               down(&zr->resource_lock);
+                               mutex_lock(&zr->resource_lock);
                                if (fh->jpg_buffers.allocated ||
                                    (fh->v4l_buffers.allocated &&
                                     fh->v4l_buffers.active !=
@@ -3055,7 +3060,7 @@ zoran_do_ioctl (struct inode *inode,
 
                                fh->map_mode = ZORAN_MAP_MODE_RAW;
                        sfmtv4l_unlock_and_return:
-                               up(&zr->resource_lock);
+                               mutex_unlock(&zr->resource_lock);
                        }
 
                        break;
@@ -3080,7 +3085,7 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr));
 
                memset(fb, 0, sizeof(*fb));
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                fb->base = zr->buffer.base;
                fb->fmt.width = zr->buffer.width;
                fb->fmt.height = zr->buffer.height;
@@ -3089,7 +3094,7 @@ zoran_do_ioctl (struct inode *inode,
                                fh->overlay_settings.format->fourcc;
                }
                fb->fmt.bytesperline = zr->buffer.bytesperline;
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                fb->fmt.colorspace = V4L2_COLORSPACE_SRGB;
                fb->fmt.field = V4L2_FIELD_INTERLACED;
                fb->flags = V4L2_FBUF_FLAG_OVERLAY;
@@ -3124,12 +3129,12 @@ zoran_do_ioctl (struct inode *inode,
                        return -EINVAL;
                }
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res =
                    setup_fbuffer(file, fb->base, &zoran_formats[i],
                                  fb->fmt.width, fb->fmt.height,
                                  fb->fmt.bytesperline);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3142,9 +3147,9 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOC_PREVIEW - on=%d\n",
                        ZR_DEVNAME(zr), *on);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = setup_overlay(file, *on);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3166,7 +3171,7 @@ zoran_do_ioctl (struct inode *inode,
                        return -EINVAL;
                }
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) {
                        dprintk(1,
@@ -3227,7 +3232,7 @@ zoran_do_ioctl (struct inode *inode,
                        goto v4l2reqbuf_unlock_and_return;
                }
        v4l2reqbuf_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -3248,9 +3253,9 @@ zoran_do_ioctl (struct inode *inode,
                buf->type = type;
                buf->index = index;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                res = zoran_v4l2_buffer_status(file, buf, buf->index);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3265,7 +3270,7 @@ zoran_do_ioctl (struct inode *inode,
                        KERN_DEBUG "%s: VIDIOC_QBUF - type=%d, index=%d\n",
                        ZR_DEVNAME(zr), buf->type, buf->index);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                switch (fh->map_mode) {
                case ZORAN_MAP_MODE_RAW:
@@ -3325,7 +3330,7 @@ zoran_do_ioctl (struct inode *inode,
                        goto qbuf_unlock_and_return;
                }
        qbuf_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3339,7 +3344,7 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOC_DQBUF - type=%d\n",
                        ZR_DEVNAME(zr), buf->type);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                switch (fh->map_mode) {
                case ZORAN_MAP_MODE_RAW:
@@ -3413,7 +3418,7 @@ zoran_do_ioctl (struct inode *inode,
                        goto dqbuf_unlock_and_return;
                }
        dqbuf_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3425,7 +3430,7 @@ zoran_do_ioctl (struct inode *inode,
 
                dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr));
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                switch (fh->map_mode) {
                case ZORAN_MAP_MODE_RAW:        /* raw capture */
@@ -3473,7 +3478,7 @@ zoran_do_ioctl (struct inode *inode,
                        goto strmon_unlock_and_return;
                }
        strmon_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3485,7 +3490,7 @@ zoran_do_ioctl (struct inode *inode,
 
                dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr));
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                switch (fh->map_mode) {
                case ZORAN_MAP_MODE_RAW:        /* raw capture */
@@ -3543,7 +3548,7 @@ zoran_do_ioctl (struct inode *inode,
                        goto strmoff_unlock_and_return;
                }
        strmoff_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3568,16 +3573,16 @@ zoran_do_ioctl (struct inode *inode,
 
                switch (ctrl->id) {
                case V4L2_CID_BRIGHTNESS:
-                       strncpy(ctrl->name, "Brightness", 31);
+                       strncpy(ctrl->name, "Brightness", sizeof(ctrl->name)-1);
                        break;
                case V4L2_CID_CONTRAST:
-                       strncpy(ctrl->name, "Contrast", 31);
+                       strncpy(ctrl->name, "Contrast", sizeof(ctrl->name)-1);
                        break;
                case V4L2_CID_SATURATION:
-                       strncpy(ctrl->name, "Saturation", 31);
+                       strncpy(ctrl->name, "Saturation", sizeof(ctrl->name)-1);
                        break;
                case V4L2_CID_HUE:
-                       strncpy(ctrl->name, "Hue", 31);
+                       strncpy(ctrl->name, "Hue", sizeof(ctrl->name)-1);
                        break;
                }
 
@@ -3603,7 +3608,7 @@ zoran_do_ioctl (struct inode *inode,
                    ctrl->id > V4L2_CID_HUE)
                        return -EINVAL;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                switch (ctrl->id) {
                case V4L2_CID_BRIGHTNESS:
                        ctrl->value = zr->brightness;
@@ -3618,7 +3623,7 @@ zoran_do_ioctl (struct inode *inode,
                        ctrl->value = zr->hue;
                        break;
                }
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -3645,7 +3650,7 @@ zoran_do_ioctl (struct inode *inode,
                        return -EINVAL;
                }
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                switch (ctrl->id) {
                case V4L2_CID_BRIGHTNESS:
                        zr->brightness = ctrl->value;
@@ -3667,7 +3672,7 @@ zoran_do_ioctl (struct inode *inode,
 
                decoder_command(zr, DECODER_SET_PICTURE, &pict);
 
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -3695,7 +3700,7 @@ zoran_do_ioctl (struct inode *inode,
                                        &caps);
                        if (caps.flags & VIDEO_DECODER_AUTO) {
                                std->id = V4L2_STD_ALL;
-                               strncpy(std->name, "Autodetect", 31);
+                               strncpy(std->name, "Autodetect", sizeof(std->name)-1);
                                return 0;
                        } else
                                return -EINVAL;
@@ -3703,21 +3708,21 @@ zoran_do_ioctl (struct inode *inode,
                switch (std->index) {
                case 0:
                        std->id = V4L2_STD_PAL;
-                       strncpy(std->name, "PAL", 31);
+                       strncpy(std->name, "PAL", sizeof(std->name)-1);
                        std->frameperiod.numerator = 1;
                        std->frameperiod.denominator = 25;
                        std->framelines = zr->card.tvn[0]->Ht;
                        break;
                case 1:
                        std->id = V4L2_STD_NTSC;
-                       strncpy(std->name, "NTSC", 31);
+                       strncpy(std->name, "NTSC", sizeof(std->name)-1);
                        std->frameperiod.numerator = 1001;
                        std->frameperiod.denominator = 30000;
                        std->framelines = zr->card.tvn[1]->Ht;
                        break;
                case 2:
                        std->id = V4L2_STD_SECAM;
-                       strncpy(std->name, "SECAM", 31);
+                       strncpy(std->name, "SECAM", sizeof(std->name)-1);
                        std->frameperiod.numerator = 1;
                        std->frameperiod.denominator = 25;
                        std->framelines = zr->card.tvn[2]->Ht;
@@ -3735,9 +3740,9 @@ zoran_do_ioctl (struct inode *inode,
 
                dprintk(3, KERN_DEBUG "%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr));
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                norm = zr->norm;
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                switch (norm) {
                case VIDEO_MODE_PAL:
@@ -3761,7 +3766,7 @@ zoran_do_ioctl (struct inode *inode,
                v4l2_std_id *std = arg;
 
                dprintk(3, KERN_DEBUG "%s: VIDIOC_S_STD - norm=0x%llx\n",
-                       ZR_DEVNAME(zr), *std);
+                       ZR_DEVNAME(zr), (unsigned long long)*std);
 
                if (*std == V4L2_STD_PAL)
                        norm = VIDEO_MODE_PAL;
@@ -3775,17 +3780,17 @@ zoran_do_ioctl (struct inode *inode,
                        dprintk(1,
                                KERN_ERR
                                "%s: VIDIOC_S_STD - invalid norm 0x%llx\n",
-                               ZR_DEVNAME(zr), *std);
+                               ZR_DEVNAME(zr), (unsigned long long)*std);
                        return -EINVAL;
                }
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                if ((res = zoran_set_norm(zr, norm)))
                        goto sstd_unlock_and_return;
 
                res = wait_grab_pending(zr);
        sstd_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                return res;
        }
                break;
@@ -3812,9 +3817,9 @@ zoran_do_ioctl (struct inode *inode,
                inp->std = V4L2_STD_ALL;
 
                /* Get status of video decoder */
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                decoder_command(zr, DECODER_GET_STATUS, &status);
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                if (!(status & DECODER_STATUS_GOOD)) {
                        inp->status |= V4L2_IN_ST_NO_POWER;
@@ -3833,9 +3838,9 @@ zoran_do_ioctl (struct inode *inode,
 
                dprintk(3, KERN_DEBUG "%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr));
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                *input = zr->input;
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -3848,14 +3853,14 @@ zoran_do_ioctl (struct inode *inode,
                dprintk(3, KERN_DEBUG "%s: VIDIOC_S_INPUT - input=%d\n",
                        ZR_DEVNAME(zr), *input);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
                if ((res = zoran_set_input(zr, *input)))
                        goto sinput_unlock_and_return;
 
                /* Make sure the changes come into effect */
                res = wait_grab_pending(zr);
        sinput_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                return res;
        }
                break;
@@ -3873,7 +3878,7 @@ zoran_do_ioctl (struct inode *inode,
                memset(outp, 0, sizeof(*outp));
                outp->index = 0;
                outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY;
-               strncpy(outp->name, "Autodetect", 31);
+               strncpy(outp->name, "Autodetect", sizeof(outp->name)-1);
 
                return 0;
        }
@@ -3917,7 +3922,7 @@ zoran_do_ioctl (struct inode *inode,
                memset(cropcap, 0, sizeof(*cropcap));
                cropcap->type = type;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
                    (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
@@ -3937,7 +3942,7 @@ zoran_do_ioctl (struct inode *inode,
                cropcap->defrect.width = BUZ_MIN_WIDTH;
                cropcap->defrect.height = BUZ_MIN_HEIGHT;
        cropcap_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                return res;
        }
                break;
@@ -3953,7 +3958,7 @@ zoran_do_ioctl (struct inode *inode,
                memset(crop, 0, sizeof(*crop));
                crop->type = type;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
                    (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
@@ -3972,7 +3977,7 @@ zoran_do_ioctl (struct inode *inode,
                crop->c.height = fh->jpg_settings.img_height;
 
        gcrop_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return res;
        }
@@ -3991,7 +3996,7 @@ zoran_do_ioctl (struct inode *inode,
                        ZR_DEVNAME(zr), crop->type, crop->c.left, crop->c.top,
                        crop->c.width, crop->c.height);
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
                        dprintk(1,
@@ -4027,7 +4032,7 @@ zoran_do_ioctl (struct inode *inode,
                fh->jpg_settings = settings;
 
        scrop_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
                return res;
        }
                break;
@@ -4041,7 +4046,7 @@ zoran_do_ioctl (struct inode *inode,
 
                memset(params, 0, sizeof(*params));
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                params->quality = fh->jpg_settings.jpg_comp.quality;
                params->APPn = fh->jpg_settings.jpg_comp.APPn;
@@ -4056,7 +4061,7 @@ zoran_do_ioctl (struct inode *inode,
                params->jpeg_markers =
                    fh->jpg_settings.jpg_comp.jpeg_markers;
 
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -4077,7 +4082,7 @@ zoran_do_ioctl (struct inode *inode,
 
                settings.jpg_comp = *params;
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                if (fh->v4l_buffers.active != ZORAN_FREE ||
                    fh->jpg_buffers.active != ZORAN_FREE) {
@@ -4096,7 +4101,7 @@ zoran_do_ioctl (struct inode *inode,
                            zoran_v4l2_calc_bufsize(&fh->jpg_settings);
                fh->jpg_settings.jpg_comp = *params = settings.jpg_comp;
        sjpegc_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                return 0;
        }
@@ -4108,7 +4113,7 @@ zoran_do_ioctl (struct inode *inode,
 
                dprintk(3,
                        KERN_DEBUG "%s: VIDIOC_QUERY_STD - std=0x%llx\n",
-                       ZR_DEVNAME(zr), *std);
+                       ZR_DEVNAME(zr), (unsigned long long)*std);
 
                if (*std == V4L2_STD_ALL || *std == V4L2_STD_NTSC ||
                    *std == V4L2_STD_PAL || (*std == V4L2_STD_SECAM &&
@@ -4130,7 +4135,7 @@ zoran_do_ioctl (struct inode *inode,
 
                switch (fmt->type) {
                case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       down(&zr->resource_lock);
+                       mutex_lock(&zr->resource_lock);
 
                        if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH)
                                fmt->fmt.win.w.width = BUZ_MAX_WIDTH;
@@ -4141,7 +4146,7 @@ zoran_do_ioctl (struct inode *inode,
                        if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT)
                                fmt->fmt.win.w.height = BUZ_MIN_HEIGHT;
 
-                       up(&zr->resource_lock);
+                       mutex_unlock(&zr->resource_lock);
                        break;
 
                case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -4149,7 +4154,7 @@ zoran_do_ioctl (struct inode *inode,
                        if (fmt->fmt.pix.bytesperline > 0)
                                return -EINVAL;
 
-                       down(&zr->resource_lock);
+                       mutex_lock(&zr->resource_lock);
 
                        if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
                                settings = fh->jpg_settings;
@@ -4232,7 +4237,7 @@ zoran_do_ioctl (struct inode *inode,
                                goto tryfmt_unlock_and_return;
                        }
                tryfmt_unlock_and_return:
-                       up(&zr->resource_lock);
+                       mutex_unlock(&zr->resource_lock);
 
                        return res;
                        break;
@@ -4283,7 +4288,7 @@ zoran_poll (struct file *file,
         * if no buffers queued or so, return POLLNVAL
         */
 
-       down(&zr->resource_lock);
+       mutex_lock(&zr->resource_lock);
 
        switch (fh->map_mode) {
        case ZORAN_MAP_MODE_RAW:
@@ -4332,7 +4337,7 @@ zoran_poll (struct file *file,
        }
 
 poll_unlock_and_return:
-       up(&zr->resource_lock);
+       mutex_unlock(&zr->resource_lock);
 
        return res;
 }
@@ -4388,7 +4393,7 @@ zoran_vm_close (struct vm_area_struct *vma)
                                if (fh->jpg_buffers.buffer[i].map)
                                        break;
                        if (i == fh->jpg_buffers.num_buffers) {
-                               down(&zr->resource_lock);
+                               mutex_lock(&zr->resource_lock);
 
                                if (fh->jpg_buffers.active != ZORAN_FREE) {
                                        jpg_qbuf(file, -1, zr->codec_mode);
@@ -4401,7 +4406,7 @@ zoran_vm_close (struct vm_area_struct *vma)
                                fh->jpg_buffers.allocated = 0;
                                fh->jpg_buffers.ready_to_be_freed = 1;
 
-                               up(&zr->resource_lock);
+                               mutex_unlock(&zr->resource_lock);
                        }
 
                        break;
@@ -4424,7 +4429,7 @@ zoran_vm_close (struct vm_area_struct *vma)
                                if (fh->v4l_buffers.buffer[i].map)
                                        break;
                        if (i == fh->v4l_buffers.num_buffers) {
-                               down(&zr->resource_lock);
+                               mutex_lock(&zr->resource_lock);
 
                                if (fh->v4l_buffers.active != ZORAN_FREE) {
                                        zr36057_set_memgrab(zr, 0);
@@ -4437,7 +4442,7 @@ zoran_vm_close (struct vm_area_struct *vma)
                                fh->v4l_buffers.allocated = 0;
                                fh->v4l_buffers.ready_to_be_freed = 1;
 
-                               up(&zr->resource_lock);
+                               mutex_unlock(&zr->resource_lock);
                        }
 
                        break;
@@ -4492,7 +4497,7 @@ zoran_mmap (struct file           *file,
        case ZORAN_MAP_MODE_JPG_PLAY:
 
                /* lock */
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                /* Map the MJPEG buffers */
                if (!fh->jpg_buffers.allocated) {
@@ -4582,13 +4587,13 @@ zoran_mmap (struct file           *file,
 
                }
        jpg_mmap_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                break;
 
        case ZORAN_MAP_MODE_RAW:
 
-               down(&zr->resource_lock);
+               mutex_lock(&zr->resource_lock);
 
                /* Map the V4L buffers */
                if (!fh->v4l_buffers.allocated) {
@@ -4660,7 +4665,7 @@ zoran_mmap (struct file           *file,
                                break;
                }
        v4l_mmap_unlock_and_return:
-               up(&zr->resource_lock);
+               mutex_unlock(&zr->resource_lock);
 
                break;
 
@@ -4680,6 +4685,7 @@ static struct file_operations zoran_fops = {
        .open = zoran_open,
        .release = zoran_close,
        .ioctl = zoran_ioctl,
+       .compat_ioctl   = v4l_compat_ioctl32,
        .llseek = no_llseek,
        .read = zoran_read,
        .write = zoran_write,
@@ -4690,7 +4696,7 @@ static struct file_operations zoran_fops = {
 struct video_device zoran_template __devinitdata = {
        .name = ZORAN_NAME,
        .type = ZORAN_VID_TYPE,
-#ifdef HAVE_V4L2
+#ifdef CONFIG_VIDEO_V4L2
        .type2 = ZORAN_V4L2_VID_FLAGS,
 #endif
        .hardware = ZORAN_HARDWARE,