fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / media / video / zr36060.c
index 2d582a3..97c8f9b 100644 (file)
@@ -26,7 +26,6 @@
 
 #define ZR060_VERSION "v0.7"
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -35,7 +34,7 @@
 #include <linux/types.h>
 #include <linux/wait.h>
 
-/* includes for structures and defines regarding video 
+/* includes for structures and defines regarding video
    #include<linux/videodev.h> */
 
 /* I/O commands, error codes */
 static int zr36060_codecs = 0;
 
 static int low_bitrate = 0;
-MODULE_PARM(low_bitrate, "i");
+module_param(low_bitrate, bool, 0);
 MODULE_PARM_DESC(low_bitrate, "Buz compatibility option, halves bitrate");
 
 /* debugging is available via module parameter */
 static int debug = 0;
-MODULE_PARM(debug, "i");
+module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "Debug level (0-4)");
 
 #define dprintk(num, format, args...) \
@@ -162,7 +161,7 @@ zr36060_wait_end (struct zr36060 *ptr)
 
        while (zr36060_read_status(ptr) & ZR060_CFSR_Busy) {
                udelay(1);
-               if (i++ > 200000) {     // 200ms, there is for shure something wrong!!!
+               if (i++ > 200000) {     // 200ms, there is for sure something wrong!!!
                        dprintk(1,
                                "%s: timout at wait_end (last status: 0x%02x)\n",
                                ptr->name, ptr->status);
@@ -174,7 +173,7 @@ zr36060_wait_end (struct zr36060 *ptr)
 /* =========================================================================
    Local helper function:
 
-   basic test of "connectivity", writes/reads to/from memory the SOF marker 
+   basic test of "connectivity", writes/reads to/from memory the SOF marker
    ========================================================================= */
 
 static int
@@ -209,9 +208,9 @@ zr36060_basic_test (struct zr36060 *ptr)
 
 static int
 zr36060_pushit (struct zr36060 *ptr,
-               u16             startreg,
-               u16             len,
-               const char     *data)
+               u16             startreg,
+               u16             len,
+               const char     *data)
 {
        int i = 0;
 
@@ -315,32 +314,6 @@ static const char zr36060_dht[0x1a4] = {
        0xF9, 0xFA
 };
 
-static const char zr36060_app[0x40] = {
-       0xff, 0xe0,             //Marker: APP0
-       0x00, 0x07,             //Length: 7
-       ' ', 'A', 'V', 'I', '1', 0, 0, 0,       // 'AVI' field
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0
-};
-
-static const char zr36060_com[0x40] = {
-       0xff, 0xfe,             //Marker: COM
-       0x00, 0x06,             //Length: 6
-       ' ', 'C', 'O', 'M', 0, 0, 0, 0, // 'COM' field
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0
-};
-
 /* jpeg baseline setup, this is just fixed in this driver (YUV pictures) */
 #define NO_OF_COMPONENTS          0x3  //Y,U,V
 #define BASELINE_PRECISION        0x8  //MCU size (?)
@@ -362,7 +335,7 @@ static const char zr36060_decimation_v[8] = { 1, 1, 1, 0, 0, 0, 0, 0 };
 /* ------------------------------------------------------------------------- */
 
 /* SOF (start of frame) segment depends on width, height and sampling ratio
-                         of each color component */
+                        of each color component */
 
 static int
 zr36060_set_sof (struct zr36060 *ptr)
@@ -394,8 +367,8 @@ zr36060_set_sof (struct zr36060 *ptr)
 
 /* ------------------------------------------------------------------------- */
 
-/* SOS (start of scan) segment depends on the used scan components 
-                        of each color component */
+/* SOS (start of scan) segment depends on the used scan components
+                       of each color component */
 
 static int
 zr36060_set_sos (struct zr36060 *ptr)
@@ -412,7 +385,7 @@ zr36060_set_sos (struct zr36060 *ptr)
        for (i = 0; i < NO_OF_COMPONENTS; i++) {
                sos_data[5 + (i * 2)] = i;      // index
                sos_data[6 + (i * 2)] = (zr36060_td[i] << 4) |
-                                       zr36060_ta[i]; // AC/DC tbl.sel.
+                                       zr36060_ta[i]; // AC/DC tbl.sel.
        }
        sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 2] = 00;      // scan start
        sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 3] = 0x3f;
@@ -498,12 +471,18 @@ zr36060_init (struct zr36060 *ptr)
                sum +=
                    zr36060_pushit(ptr, ZR060_DHT_IDX, sizeof(zr36060_dht),
                                   zr36060_dht);
-               sum +=
-                   zr36060_pushit(ptr, ZR060_APP_IDX, sizeof(zr36060_app),
-                                  zr36060_app);
-               sum +=
-                   zr36060_pushit(ptr, ZR060_COM_IDX, sizeof(zr36060_com),
-                                  zr36060_com);
+               zr36060_write(ptr, ZR060_APP_IDX, 0xff);
+               zr36060_write(ptr, ZR060_APP_IDX + 1, 0xe0 + ptr->app.appn);
+               zr36060_write(ptr, ZR060_APP_IDX + 2, 0x00);
+               zr36060_write(ptr, ZR060_APP_IDX + 3, ptr->app.len + 2);
+               sum += zr36060_pushit(ptr, ZR060_APP_IDX + 4, 60,
+                                     ptr->app.data) + 4;
+               zr36060_write(ptr, ZR060_COM_IDX, 0xff);
+               zr36060_write(ptr, ZR060_COM_IDX + 1, 0xfe);
+               zr36060_write(ptr, ZR060_COM_IDX + 2, 0x00);
+               zr36060_write(ptr, ZR060_COM_IDX + 3, ptr->com.len + 2);
+               sum += zr36060_pushit(ptr, ZR060_COM_IDX + 4, 60,
+                                     ptr->com.data) + 4;
 
                /* setup misc. data for compression (target code sizes) */
 
@@ -535,8 +514,9 @@ zr36060_init (struct zr36060 *ptr)
 
                /* JPEG markers to be included in the compressed stream */
                zr36060_write(ptr, ZR060_MER,
-                             ZR060_MER_App | ZR060_MER_Com | ZR060_MER_DQT
-                             | ZR060_MER_DHT);
+                             ZR060_MER_DQT | ZR060_MER_DHT |
+                             ((ptr->com.len > 0) ? ZR060_MER_Com : 0) |
+                             ((ptr->app.len > 0) ? ZR060_MER_App : 0));
 
                /* Setup the Video Frontend */
                /* Limit pixel range to 16..235 as per CCIR-601 */
@@ -841,6 +821,47 @@ zr36060_control (struct videocodec *codec,
                        return -EFAULT;
                ptr->scalefact = *ival;
                break;
+
+       case CODEC_G_JPEG_APP_DATA: {   /* get appn marker data */
+               struct jpeg_app_marker *app = data;
+
+               if (size != sizeof(struct jpeg_app_marker))
+                       return -EFAULT;
+
+               *app = ptr->app;
+               break;
+       }
+
+       case CODEC_S_JPEG_APP_DATA: {   /* set appn marker data */
+               struct jpeg_app_marker *app = data;
+
+               if (size != sizeof(struct jpeg_app_marker))
+                       return -EFAULT;
+
+               ptr->app = *app;
+               break;
+       }
+
+       case CODEC_G_JPEG_COM_DATA: {   /* get comment marker data */
+               struct jpeg_com_marker *com = data;
+
+               if (size != sizeof(struct jpeg_com_marker))
+                       return -EFAULT;
+
+               *com = ptr->com;
+               break;
+       }
+
+       case CODEC_S_JPEG_COM_DATA: {   /* set comment marker data */
+               struct jpeg_com_marker *com = data;
+
+               if (size != sizeof(struct jpeg_com_marker))
+                       return -EFAULT;
+
+               ptr->com = *com;
+               break;
+       }
+
        default:
                return -EINVAL;
        }
@@ -898,12 +919,11 @@ zr36060_setup (struct videocodec *codec)
                return -ENOSPC;
        }
        //mem structure init
-       codec->data = ptr = kmalloc(sizeof(struct zr36060), GFP_KERNEL);
+       codec->data = ptr = kzalloc(sizeof(struct zr36060), GFP_KERNEL);
        if (NULL == ptr) {
                dprintk(1, KERN_ERR "zr36060: Can't get enough memory!\n");
                return -ENOMEM;
        }
-       memset(ptr, 0, sizeof(struct zr36060));
 
        snprintf(ptr->name, sizeof(ptr->name), "zr36060[%d]",
                 zr36060_codecs);
@@ -930,6 +950,12 @@ zr36060_setup (struct videocodec *codec)
        ptr->max_block_vol = 240;       /* CHECKME, was 120 is 240 */
        ptr->scalefact = 0x100;
        ptr->dri = 1;           /* CHECKME, was 8 is 1 */
+
+       /* by default, no COM or APP markers - app should set those */
+       ptr->com.len = 0;
+       ptr->app.appn = 0;
+       ptr->app.len = 0;
+
        zr36060_init(ptr);
 
        dprintk(1, KERN_INFO "%s: codec attached and running\n",
@@ -973,7 +999,7 @@ zr36060_cleanup_module (void)
                dprintk(1,
                        "zr36060: something's wrong - %d codecs left somehow.\n",
                        zr36060_codecs);
-       } 
+       }
 
        /* however, we can't just stay alive */
        videocodec_unregister(&zr36060_codec);