kbuild: move files that don't check __KERNEL__
[safe/jmp/linux-2.6] / drivers / media / video / zoran_card.c
index a2e528c..006d488 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:
@@ -27,7 +27,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/config.h>
+#include <linux/delay.h>
+
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -38,6 +39,7 @@
 #include <linux/i2c.h>
 #include <linux/i2c-algo-bit.h>
 #include <linux/videodev.h>
+#include <media/v4l2-common.h>
 #include <linux/spinlock.h>
 #include <linux/sem.h>
 #include <linux/kmod.h>
@@ -47,6 +49,7 @@
 #include <linux/interrupt.h>
 #include <linux/video_decoder.h>
 #include <linux/video_encoder.h>
+#include <linux/mutex.h>
 
 #include <asm/io.h>
 
 extern const struct zoran_format zoran_formats[];
 
 static int card[BUZ_MAX] = { -1, -1, -1, -1 };
-module_param_array(card, int, NULL, 0);
+module_param_array(card, int, NULL, 0444);
 MODULE_PARM_DESC(card, "The type of card");
 
 static int encoder[BUZ_MAX] = { -1, -1, -1, -1 };
-module_param_array(encoder, int, NULL, 0);
+module_param_array(encoder, int, NULL, 0444);
 MODULE_PARM_DESC(encoder, "i2c TV encoder");
 
 static int decoder[BUZ_MAX] = { -1, -1, -1, -1 };
-module_param_array(decoder, int, NULL, 0);
+module_param_array(decoder, int, NULL, 0444);
 MODULE_PARM_DESC(decoder, "i2c TV decoder");
 
 /*
@@ -80,25 +83,32 @@ MODULE_PARM_DESC(decoder, "i2c TV decoder");
    or set in in a VIDIOCSFBUF ioctl
  */
 
-static unsigned long vidmem = 0;       /* Video memory base address */
-module_param(vidmem, ulong, 0);
+static unsigned long vidmem;   /* default = 0 - Video memory base address */
+module_param(vidmem, ulong, 0444);
+MODULE_PARM_DESC(vidmem, "Default video memory base address");
 
 /*
    Default input and video norm at startup of the driver.
 */
 
-static int default_input = 0;  /* 0=Composite, 1=S-Video */
-module_param(default_input, int, 0);
+static unsigned int default_input;     /* default 0 = Composite, 1 = S-Video */
+module_param(default_input, uint, 0444);
 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_param(default_norm, int, 0);
+static int default_mux = 1;    /* 6 Eyes input selection */
+module_param(default_mux, int, 0644);
+MODULE_PARM_DESC(default_mux,
+                "Default 6 Eyes mux setting (Input selection)");
+
+static int default_norm;       /* default 0 = PAL, 1 = NTSC 2 = SECAM */
+module_param(default_norm, int, 0444);
 MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
 
-static int video_nr = -1;      /* /dev/videoN, -1 for autodetect */
-module_param(video_nr, int, 0);
-MODULE_PARM_DESC(video_nr, "video device number");
+/* /dev/videoN, -1 for autodetect */
+static int video_nr[BUZ_MAX] = {-1, -1, -1, -1};
+module_param_array(video_nr, int, NULL, 0444);
+MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)");
 
 /*
    Number and size of grab buffers for Video 4 Linux
@@ -119,28 +129,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_param(v4l_nbufs, int, 0);
+module_param(v4l_nbufs, int, 0644);
 MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
-module_param(v4l_bufsize, int, 0);
+module_param(v4l_bufsize, int, 0644);
 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_param(jpg_nbufs, int, 0);
+module_param(jpg_nbufs, int, 0644);
 MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use");
-module_param(jpg_bufsize, int, 0);
+module_param(jpg_bufsize, int, 0644);
 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_param(pass_through, int, 0);
+module_param(pass_through, int, 0644);
 MODULE_PARM_DESC(pass_through,
                 "Pass TV signal through to TV-out when idling");
 
-static int debug = 1;
-int *zr_debug = &debug;
-module_param(debug, int, 0);
-MODULE_PARM_DESC(debug, "Debug level (0-4)");
+int zr36067_debug = 1;
+module_param_named(debug, zr36067_debug, int, 0644);
+MODULE_PARM_DESC(debug, "Debug level (0-5)");
 
 MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
 MODULE_AUTHOR("Serguei Miridonov");
@@ -153,12 +162,6 @@ static struct pci_device_id zr36067_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
 
-#define dprintk(num, format, args...) \
-       do { \
-               if (*zr_debug >= num) \
-                       printk(format, ##args); \
-       } while (0)
-
 int zoran_num;                 /* number of Buzs in use */
 struct zoran zoran[BUZ_MAX];
 
@@ -300,6 +303,30 @@ lml33_init (struct zoran *zr)
        GPIO(zr, 2, 1);         // Set Composite input/output
 }
 
+static void
+avs6eyes_init (struct zoran *zr)
+{
+       // AverMedia 6-Eyes original driver by Christer Weinigel
+
+       // Lifted straight from Christer's old driver and
+       // modified slightly by Martin Samuelsson.
+
+       int mux = default_mux; /* 1 = BT866, 7 = VID1 */
+
+       GPIO(zr, 4, 1); /* Bt866 SLEEP on */
+       udelay(2);
+
+       GPIO(zr, 0, 1); /* ZR36060 /RESET on */
+       GPIO(zr, 1, 0); /* ZR36060 /SLEEP on */
+       GPIO(zr, 2, mux & 1);   /* MUX S0 */
+       GPIO(zr, 3, 0); /* /FRAME on */
+       GPIO(zr, 4, 0); /* Bt866 SLEEP off */
+       GPIO(zr, 5, mux & 2);   /* MUX S1 */
+       GPIO(zr, 6, 0); /* ? */
+       GPIO(zr, 7, mux & 4);   /* MUX S2 */
+
+}
+
 static char *
 i2cid_to_modulename (u16 i2c_id)
 {
@@ -390,6 +417,14 @@ static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
 static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
 static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
 
+/* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
+ * copy Maxim's left shift hack for the 6 Eyes.
+ *
+ * Christer's driver used the unshifted norms, though...
+ * /Sam  */
+static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
+static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
+
 static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
        {
                .type = DC10_old,
@@ -418,6 +453,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 0 },
                .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10_init,
        }, {
                .type = DC10_new,
@@ -444,6 +480,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 1},
                .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10plus_init,
        }, {
                .type = DC10plus,
@@ -473,6 +510,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 1 },
                .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10plus_init,
        }, {
                .type = DC30,
@@ -501,6 +539,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 0 },
                .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10_init,
        }, {
                .type = DC30plus,
@@ -531,6 +570,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 0 },
                .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10_init,
        }, {
                .type = LML33,
@@ -557,6 +597,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { 3, 1 },
                .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
                .gws_not_connected = 1,
+               .input_mux = 0,
                .init = &lml33_init,
        }, {
                .type = LML33R10,
@@ -585,6 +626,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { 3, 1 },
                .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
                .gws_not_connected = 1,
+               .input_mux = 0,
                .init = &lml33_init,
        }, {
                .type = BUZ,
@@ -613,8 +655,49 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { 3, 1 },
                .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
                .gws_not_connected = 1,
+               .input_mux = 0,
                .init = &buz_init,
+       }, {
+               .type = AVS6EYES,
+               .name = "6-Eyes",
+               /* AverMedia chose not to brand the 6-Eyes. Thus it
+                  can't be autodetected, and requires card=x. */
+               .vendor_id = -1,
+               .device_id = -1,
+               .i2c_decoder = I2C_DRIVERID_KS0127,
+               .i2c_encoder = I2C_DRIVERID_BT866,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 10,
+               .input = {
+                       { 0, "Composite 1" },
+                       { 1, "Composite 2" },
+                       { 2, "Composite 3" },
+                       { 4, "Composite 4" },
+                       { 5, "Composite 5" },
+                       { 6, "Composite 6" },
+                       { 8, "S-Video 1" },
+                       { 9, "S-Video 2" },
+                       {10, "S-Video 3" },
+                       {15, "YCbCr" }
+               },
+               .norms = 2,
+               .tvn = {
+                       &f50ccir601_avs6eyes,
+                       &f60ccir601_avs6eyes,
+                       NULL
+               },
+               .jpeg_int = ZR36057_ISR_GIRQ1,
+               .vsync_int = ZR36057_ISR_GIRQ0,
+               .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
+               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
+               .gpcs = { 3, 1 },                       // Validity unknown /Sam
+               .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 },  // Validity unknown /Sam
+               .gws_not_connected = 1,
+               .input_mux = 1,
+               .init = &avs6eyes_init,
        }
+
 };
 
 /*
@@ -673,7 +756,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 +777,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 +790,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 +805,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;
 }
 
@@ -732,7 +815,6 @@ static struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
        .getsda = zoran_i2c_getsda,
        .getscl = zoran_i2c_getscl,
        .udelay = 10,
-       .mdelay = 0,
        .timeout = 100,
 };
 
@@ -756,13 +838,14 @@ zoran_register_i2c (struct zoran *zr)
                sizeof(I2C_NAME(&zr->i2c_adapter)) - 1);
        i2c_set_adapdata(&zr->i2c_adapter, zr);
        zr->i2c_adapter.algo_data = &zr->i2c_algo;
+       zr->i2c_adapter.dev.parent = &zr->pci_dev->dev;
        return i2c_bit_add_bus(&zr->i2c_adapter);
 }
 
 static void
 zoran_unregister_i2c (struct zoran *zr)
 {
-       i2c_bit_del_bus((&zr->i2c_adapter));
+       i2c_del_adapter(&zr->i2c_adapter);
 }
 
 /* Check a zoran_params struct for correctness, insert default params */
@@ -987,7 +1070,7 @@ test_interrupts (struct zoran *zr)
        if (timeout) {
                dprintk(1, ": time spent: %d\n", 1 * HZ - timeout);
        }
-       if (*zr_debug > 1)
+       if (zr36067_debug > 1)
                print_interrupts(zr);
        btwrite(icr, ZR36057_ICR);
 }
@@ -1033,7 +1116,14 @@ zr36057_init (struct zoran *zr)
                zr->timing = zr->card.tvn[zr->norm];
        }
 
-       zr->input = default_input = (default_input ? 1 : 0);
+       if (default_input > zr->card.inputs-1) {
+               dprintk(1,
+                       KERN_WARNING
+                       "%s: default_input value %d out of range (0-%d)\n",
+                       ZR_DEVNAME(zr), default_input, zr->card.inputs-1);
+               default_input = 0;
+       }
+       zr->input = default_input;
 
        /* Should the following be reset at every open ? */
        zr->hue = 32768;
@@ -1065,12 +1155,12 @@ zr36057_init (struct zoran *zr)
         */
        memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
        strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
-       err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr);
+       err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
        if (err < 0)
                goto exit_unregister;
 
        zoran_init_hardware(zr);
-       if (*zr_debug > 2)
+       if (zr36067_debug > 2)
                detect_guest_activity(zr);
        test_interrupts(zr);
        if (!pass_through) {
@@ -1145,8 +1235,14 @@ zoran_setup_videocodec (struct zoran *zr,
                return m;
        }
 
-       m->magic = 0L; /* magic not used */
-       m->type = VID_HARDWARE_ZR36067;
+       /* magic and type are unused for master struct. Makes sense only at
+          codec structs.
+          In the past, .type were initialized to the old V4L1 .hardware
+          value, as VID_HARDWARE_ZR36067
+        */
+       m->magic = 0L;
+       m->type = 0;
+
        m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER;
        strncpy(m->name, ZR_DEVNAME(zr), sizeof(m->name));
        m->data = zr;
@@ -1174,7 +1270,7 @@ zoran_setup_videocodec (struct zoran *zr,
 }
 
 /*
- *   Scan for a Buz card (actually for the PCI contoler ZR36057),
+ *   Scan for a Buz card (actually for the PCI controller ZR36057),
  *   request the irq and map the io memory
  */
 static int __devinit
@@ -1191,9 +1287,7 @@ find_zr36057 (void)
 
        zoran_num = 0;
        while (zoran_num < BUZ_MAX &&
-              (dev =
-               pci_find_device(PCI_VENDOR_ID_ZORAN,
-                               PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
+              (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
                card_num = card[zoran_num];
                zr = &zoran[zoran_num];
                memset(zr, 0, sizeof(struct zoran));    // Just in case if previous cycle failed
@@ -1202,7 +1296,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);
@@ -1292,7 +1386,7 @@ find_zr36057 (void)
 
                result = request_irq(zr->pci_dev->irq,
                                     zoran_irq,
-                                    SA_SHIRQ | SA_INTERRUPT,
+                                    IRQF_SHARED | IRQF_DISABLED,
                                     ZR_DEVNAME(zr),
                                     (void *) zr);
                if (result < 0) {
@@ -1454,7 +1548,8 @@ find_zr36057 (void)
                                goto zr_detach_vfe;
                        }
                }
-
+               /* Success so keep the pci_dev referenced */
+               pci_dev_get(zr->pci_dev);
                zoran_num++;
                continue;
 
@@ -1476,6 +1571,9 @@ find_zr36057 (void)
                iounmap(zr->zr36057_mem);
                continue;
        }
+       if (dev)        /* Clean up ref count on early exit */
+               pci_dev_put(dev);
+
        if (zoran_num == 0) {
                dprintk(1, KERN_INFO "No known MJPEG cards found.\n");
        }
@@ -1530,13 +1628,13 @@ init_dc10_cards (void)
        }
 
        /* random nonsense */
-       dprintk(5, KERN_DEBUG "Jotti is een held!\n");
+       dprintk(6, KERN_DEBUG "Jotti is een held!\n");
 
        /* some mainboards might not do PCI-PCI data transfer well */
-       if (pci_pci_problems & PCIPCI_FAIL) {
+       if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
                dprintk(1,
                        KERN_WARNING
-                       "%s: chipset may not support reliable PCI-PCI DMA\n",
+                       "%s: chipset does not support reliable PCI-PCI DMA\n",
                        ZORAN_NAME);
        }
 
@@ -1544,7 +1642,7 @@ init_dc10_cards (void)
        for (i = 0; i < zoran_num; i++) {
                struct zoran *zr = &zoran[i];
 
-               if (pci_pci_problems & PCIPCI_NATOMA && zr->revision <= 1) {
+               if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
                        zr->jpg_buffers.need_contiguous = 1;
                        dprintk(1,
                                KERN_INFO