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_card.c
index 807c96e..0a85c9e 100644 (file)
@@ -4,7 +4,7 @@
  * Media Labs LML33/LML33R10.
  *
  * This part handles card-specific data and detection
- * 
+ *
  * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
  *
  * Currently maintained by:
 #include <linux/spinlock.h>
 #include <linux/sem.h>
 #include <linux/kmod.h>
+#include <linux/wait.h>
 
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/video_decoder.h>
 #include <linux/video_encoder.h>
+#include <linux/mutex.h>
 
 #include <asm/io.h>
 
 #define I2C_NAME(x) (x)->name
 
 extern const struct zoran_format zoran_formats[];
-extern const int zoran_num_formats;
 
 static int card[BUZ_MAX] = { -1, -1, -1, -1 };
-MODULE_PARM(card, "1-" __stringify(BUZ_MAX) "i");
+module_param_array(card, int, NULL, 0);
 MODULE_PARM_DESC(card, "The type of card");
 
 static int encoder[BUZ_MAX] = { -1, -1, -1, -1 };
-MODULE_PARM(encoder, "1-" __stringify(BUZ_MAX) "i");
+module_param_array(encoder, int, NULL, 0);
 MODULE_PARM_DESC(encoder, "i2c TV encoder");
 
 static int decoder[BUZ_MAX] = { -1, -1, -1, -1 };
-MODULE_PARM(decoder, "1-" __stringify(BUZ_MAX) "i");
+module_param_array(decoder, int, NULL, 0);
 MODULE_PARM_DESC(decoder, "i2c TV decoder");
 
 /*
@@ -81,23 +82,23 @@ MODULE_PARM_DESC(decoder, "i2c TV decoder");
  */
 
 static unsigned long vidmem = 0;       /* Video memory base address */
-MODULE_PARM(vidmem, "i");
+module_param(vidmem, ulong, 0);
 
 /*
    Default input and video norm at startup of the driver.
 */
 
 static int default_input = 0;  /* 0=Composite, 1=S-Video */
-MODULE_PARM(default_input, "i");
+module_param(default_input, int, 0);
 MODULE_PARM_DESC(default_input,
                 "Default input (0=Composite, 1=S-Video, 2=Internal)");
 
 static int default_norm = 0;   /* 0=PAL, 1=NTSC 2=SECAM */
-MODULE_PARM(default_norm, "i");
+module_param(default_norm, int, 0);
 MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
 
 static int video_nr = -1;      /* /dev/videoN, -1 for autodetect */
-MODULE_PARM(video_nr, "i");
+module_param(video_nr, int, 0);
 MODULE_PARM_DESC(video_nr, "video device number");
 
 /*
@@ -119,27 +120,27 @@ MODULE_PARM_DESC(video_nr, "video device number");
 
 int v4l_nbufs = 2;
 int v4l_bufsize = 128;         /* Everybody should be able to work with this setting */
-MODULE_PARM(v4l_nbufs, "i");
+module_param(v4l_nbufs, int, 0);
 MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
-MODULE_PARM(v4l_bufsize, "i");
+module_param(v4l_bufsize, int, 0);
 MODULE_PARM_DESC(v4l_bufsize, "Maximum size per V4L buffer (in kB)");
 
 int jpg_nbufs = 32;
 int jpg_bufsize = 512;         /* max size for 100% quality full-PAL frame */
-MODULE_PARM(jpg_nbufs, "i");
+module_param(jpg_nbufs, int, 0);
 MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use");
-MODULE_PARM(jpg_bufsize, "i");
+module_param(jpg_bufsize, int, 0);
 MODULE_PARM_DESC(jpg_bufsize, "Maximum size per JPG buffer (in kB)");
 
 int pass_through = 0;          /* 1=Pass through TV signal when device is not used */
                                /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
-MODULE_PARM(pass_through, "i");
+module_param(pass_through, int, 0);
 MODULE_PARM_DESC(pass_through,
                 "Pass TV signal through to TV-out when idling");
 
 static int debug = 1;
 int *zr_debug = &debug;
-MODULE_PARM(debug, "i");
+module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "Debug level (0-4)");
 
 MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
@@ -673,7 +674,7 @@ zoran_i2c_client_register (struct i2c_client *client)
                KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n",
                ZR_DEVNAME(zr), client->driver->id);
 
-       down(&zr->resource_lock);
+       mutex_lock(&zr->resource_lock);
 
        if (zr->user > 0) {
                /* we're already busy, so we keep a reference to
@@ -694,7 +695,7 @@ zoran_i2c_client_register (struct i2c_client *client)
        }
 
 clientreg_unlock_and_return:
-       up(&zr->resource_lock);
+       mutex_unlock(&zr->resource_lock);
 
        return res;
 }
@@ -707,7 +708,7 @@ zoran_i2c_client_unregister (struct i2c_client *client)
 
        dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr));
 
-       down(&zr->resource_lock);
+       mutex_lock(&zr->resource_lock);
 
        if (zr->user > 0) {
                res = -EBUSY;
@@ -722,7 +723,7 @@ zoran_i2c_client_unregister (struct i2c_client *client)
                snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id);
        }
 clientunreg_unlock_and_return:
-       up(&zr->resource_lock);
+       mutex_unlock(&zr->resource_lock);
        return res;
 }
 
@@ -737,7 +738,7 @@ static struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
 };
 
 static struct i2c_adapter zoran_i2c_adapter_template = {
-       I2C_DEVNAME("zr36057"),
+       .name = "zr36057",
        .id = I2C_HW_B_ZR36067,
        .algo = NULL,
        .client_register = zoran_i2c_client_register,
@@ -969,6 +970,7 @@ zoran_open_init_params (struct zoran *zr)
 static void __devinit
 test_interrupts (struct zoran *zr)
 {
+       DEFINE_WAIT(wait);
        int timeout, icr;
 
        clear_interrupt_counters(zr);
@@ -976,7 +978,9 @@ test_interrupts (struct zoran *zr)
        zr->testing = 1;
        icr = btread(ZR36057_ICR);
        btwrite(0x78000000 | ZR36057_ICR_IntPinEn, ZR36057_ICR);
-       timeout = interruptible_sleep_on_timeout(&zr->test_q, 1 * HZ);
+       prepare_to_wait(&zr->test_q, &wait, TASK_INTERRUPTIBLE);
+       timeout = schedule_timeout(HZ);
+       finish_wait(&zr->test_q, &wait);
        btwrite(0, ZR36057_ICR);
        btwrite(0x78000000, ZR36057_ISR);
        zr->testing = 0;
@@ -992,10 +996,7 @@ test_interrupts (struct zoran *zr)
 static int __devinit
 zr36057_init (struct zoran *zr)
 {
-       unsigned long mem;
-       void *vdev;
-       unsigned mem_needed;
-       int j;
+       int j, err;
        int two = 2;
        int zero = 0;
 
@@ -1046,22 +1047,16 @@ zr36057_init (struct zoran *zr)
 
        /* allocate memory *before* doing anything to the hardware
         * in case allocation fails */
-       mem_needed = BUZ_NUM_STAT_COM * 4;
-       mem = (unsigned long) kmalloc(mem_needed, GFP_KERNEL);
-       vdev = (void *) kmalloc(sizeof(struct video_device), GFP_KERNEL);
-       if (!mem || !vdev) {
+       zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL);
+       zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL);
+       if (!zr->stat_com || !zr->video_dev) {
                dprintk(1,
                        KERN_ERR
                        "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
                        ZR_DEVNAME(zr));
-               if (vdev)
-                       kfree(vdev);
-               if (mem)
-                       kfree((void *)mem);
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto exit_free;
        }
-       memset((void *) mem, 0, mem_needed);
-       zr->stat_com = (u32 *) mem;
        for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
                zr->stat_com[j] = 1;    /* mark as unavailable to zr36057 */
        }
@@ -1069,16 +1064,11 @@ zr36057_init (struct zoran *zr)
        /*
         *   Now add the template and register the device unit.
         */
-       zr->video_dev = vdev;
        memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
        strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
-       if (video_register_device(zr->video_dev, VFL_TYPE_GRABBER,
-                                 video_nr) < 0) {
-               zoran_unregister_i2c(zr);
-               kfree((void *) zr->stat_com);
-               kfree(vdev);
-               return -1;
-       }
+       err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr);
+       if (err < 0)
+               goto exit_unregister;
 
        zoran_init_hardware(zr);
        if (*zr_debug > 2)
@@ -1092,6 +1082,13 @@ zr36057_init (struct zoran *zr)
        zr->zoran_proc = NULL;
        zr->initialized = 1;
        return 0;
+
+exit_unregister:
+       zoran_unregister_i2c(zr);
+exit_free:
+       kfree(zr->stat_com);
+       kfree(zr->video_dev);
+       return err;
 }
 
 static void
@@ -1102,15 +1099,15 @@ zoran_release (struct zoran *zr)
        /* unregister videocodec bus */
        if (zr->codec) {
                struct videocodec_master *master = zr->codec->master_data;
+
                videocodec_detach(zr->codec);
-               if (master)
-                       kfree(master);
+               kfree(master);
        }
        if (zr->vfe) {
                struct videocodec_master *master = zr->vfe->master_data;
+
                videocodec_detach(zr->vfe);
-               if (master)
-                       kfree(master);
+               kfree(master);
        }
 
        /* unregister i2c bus */
@@ -1121,7 +1118,7 @@ zoran_release (struct zoran *zr)
        btwrite(0, ZR36057_SPGPPCR);
        free_irq(zr->pci_dev->irq, zr);
        /* unmap and free memory */
-       kfree((void *) zr->stat_com);
+       kfree(zr->stat_com);
        zoran_proc_cleanup(zr);
        iounmap(zr->zr36057_mem);
        pci_disable_device(zr->pci_dev);
@@ -1206,7 +1203,7 @@ find_zr36057 (void)
                zr->id = zoran_num;
                snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
                spin_lock_init(&zr->spinlock);
-               init_MUTEX(&zr->resource_lock);
+               mutex_init(&zr->resource_lock);
                if (pci_enable_device(dev))
                        continue;
                zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);