V4L/DVB (8571): gspca: Don't use CONFIG_VIDEO_ADV_DEBUG as a compile option.
[safe/jmp/linux-2.6] / drivers / media / video / tvp5150.c
index b167ffa..28af5ce 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include <linux/i2c.h>
-#include <linux/videodev.h>
+#include <linux/videodev2.h>
 #include <linux/delay.h>
 #include <linux/video_decoder.h>
 #include <media/v4l2-common.h>
@@ -27,7 +27,7 @@ static unsigned short normal_i2c[] = {
 
 I2C_CLIENT_INSMOD;
 
-static int debug = 0;
+static int debug;
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "Debug level (0-1)");
 
@@ -290,11 +290,12 @@ static inline void tvp5150_selmux(struct i2c_client *c)
        int opmode=0;
        struct tvp5150 *decoder = i2c_get_clientdata(c);
        int input = 0;
+       unsigned char val;
 
        if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable)
                input = 8;
 
-       switch (input) {
+       switch (decoder->route.input) {
        case TVP5150_COMPOSITE1:
                input |= 2;
                /* fall through */
@@ -308,8 +309,23 @@ static inline void tvp5150_selmux(struct i2c_client *c)
                break;
        }
 
+       tvp5150_dbg( 1, "Selecting video route: route input=%i, output=%i "
+                       "=> tvp5150 input=%i, opmode=%i\n",
+                       decoder->route.input,decoder->route.output,
+                       input, opmode );
+
        tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode);
        tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
+
+       /* Svideo should enable YCrCb output and disable GPCL output
+        * For Composite and TV, it should be the reverse
+        */
+       val = tvp5150_read(c, TVP5150_MISC_CTL);
+       if (decoder->route.input == TVP5150_SVIDEO)
+               val = (val & ~0x40) | 0x10;
+       else
+               val = (val & ~0x10) | 0x40;
+       tvp5150_write(c, TVP5150_MISC_CTL, val);
 };
 
 struct i2c_reg_value {
@@ -656,7 +672,7 @@ static int tvp5150_set_vbi(struct i2c_client *c,
        if (std == V4L2_STD_ALL) {
                tvp5150_err("VBI can't be configured without knowing number of lines\n");
                return 0;
-       } else if (std && V4L2_STD_625_50) {
+       } else if (std & V4L2_STD_625_50) {
                /* Don't follow NTSC Line number convension */
                line += 3;
        }
@@ -703,7 +719,7 @@ static int tvp5150_get_vbi(struct i2c_client *c,
        if (std == V4L2_STD_ALL) {
                tvp5150_err("VBI can't be configured without knowing number of lines\n");
                return 0;
-       } else if (std && V4L2_STD_625_50) {
+       } else if (std & V4L2_STD_625_50) {
                /* Don't follow NTSC Line number convension */
                line += 3;
        }
@@ -794,10 +810,10 @@ static inline void tvp5150_reset(struct i2c_client *c)
        tvp5150_write_inittab(c, tvp5150_init_enable);
 
        /* Initialize image preferences */
-       tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8);
-       tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8);
-       tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8);
-       tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8);
+       tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright);
+       tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast);
+       tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast);
+       tvp5150_write(c, TVP5150_HUE_CTL, decoder->hue);
 
        tvp5150_set_std(c, decoder->norm);
 };
@@ -945,25 +961,19 @@ static int tvp5150_command(struct i2c_client *c,
        }
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       case VIDIOC_INT_G_REGISTER:
-       {
-               struct v4l2_register *reg = arg;
-
-               if (reg->i2c_id != I2C_DRIVERID_TVP5150)
-                       return -EINVAL;
-               reg->val = tvp5150_read(c, reg->reg & 0xff);
-               break;
-       }
-
-       case VIDIOC_INT_S_REGISTER:
+       case VIDIOC_DBG_G_REGISTER:
+       case VIDIOC_DBG_S_REGISTER:
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_TVP5150)
+               if (!v4l2_chip_match_i2c_client(c, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
-               tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
+               if (cmd == VIDIOC_DBG_G_REGISTER)
+                       reg->val = tvp5150_read(c, reg->reg & 0xff);
+               else
+                       tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
                break;
        }
 #endif
@@ -1007,7 +1017,7 @@ static int tvp5150_command(struct i2c_client *c,
                {
                        struct v4l2_control *ctrl = arg;
                        u8 i, n;
-                       n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
+                       n = ARRAY_SIZE(tvp5150_qctrl);
                        for (i = 0; i < n; i++)
                                if (ctrl->id == tvp5150_qctrl[i].id) {
                                        if (ctrl->value <
@@ -1062,12 +1072,12 @@ static int tvp5150_detect_client(struct i2c_adapter *adapter,
                return 0;
 
        c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
-       if (c == 0)
+       if (!c)
                return -ENOMEM;
        memcpy(c, &client_template, sizeof(struct i2c_client));
 
        core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
-       if (core == 0) {
+       if (!core) {
                kfree(c);
                return -ENOMEM;
        }
@@ -1078,10 +1088,10 @@ static int tvp5150_detect_client(struct i2c_adapter *adapter,
        core->norm = V4L2_STD_ALL;      /* Default is autodetect */
        core->route.input = TVP5150_COMPOSITE1;
        core->enable = 1;
-       core->bright = 32768;
-       core->contrast = 32768;
-       core->hue = 32768;
-       core->sat = 32768;
+       core->bright = 128;
+       core->contrast = 128;
+       core->hue = 0;
+       core->sat = 128;
 
        if (rv) {
                kfree(c);