diff -urN video4linux-20031218/doc/CARDLIST.tuner video4linux-20031218.monstertv.1/doc/CARDLIST.tuner
--- video4linux-20031218/doc/CARDLIST.tuner	2003-11-13 17:08:06.000000000 +0900
+++ video4linux-20031218.monstertv.1/doc/CARDLIST.tuner	2003-12-20 02:46:15.000000000 +0900
@@ -41,3 +41,4 @@
 tuner=40 - HITACHI V7-J180AT
 tuner=41 - Philips PAL_MK (FI1216 MK)
 tuner=42 - Philips 1236D ATSC/NTSC daul in
+tuner=43 - Philips FM1236 MK3
diff -urN video4linux-20031218/doc/insmod-options video4linux-20031218.monstertv.1/doc/insmod-options
--- video4linux-20031218/doc/insmod-options	2003-11-13 17:20:56.000000000 +0900
+++ video4linux-20031218.monstertv.1/doc/insmod-options	2003-12-20 02:46:15.000000000 +0900
@@ -130,6 +130,14 @@
 	  card=65 (FlyVideo 2000S) - set AMSEL=1 or AMSEL=0
 	  card=72 (Prolink PV-BT878P rev.9B) - set AMSEL=0 only
 
+        insmod args for MSP3445G:
+                msp3445 = n   Select TV Standard for SKNet MONSTER TV[1|2].
+		              n = 1 : EIA-J Two Carrier FM (Japan Only)
+			          x : Not implement yet. Please Help!
+				  
+		
+		debug = 1	print debug messages
+
 msp3400.o
 	The driver for the msp34xx sound processor chips. If you have a
 	stereo card, you probably want to insmod this one.
diff -urN video4linux-20031218/msp34x5.h video4linux-20031218.monstertv.1/msp34x5.h
--- video4linux-20031218/msp34x5.h	1970-01-01 09:00:00.000000000 +0900
+++ video4linux-20031218.monstertv.1/msp34x5.h	2003-12-20 02:46:15.000000000 +0900
@@ -0,0 +1,37 @@
+/*
+ * Header for MICRONAS MSP34x5
+ * Modify FROM msp3400 driver @ v2.4.20pre6 
+ * 2002-09-15 K.Ohta
+ */
+#ifndef MSP34x5_H
+#define MSP34x5_H
+
+/* ---------------------------------------------------------------------- */
+
+struct msp_dfpreg {
+    int reg;
+    int value;
+};
+
+#define MSP_SET_DFPREG     _IOW('m',15,struct msp_dfpreg)
+#define MSP_GET_DFPREG     _IOW('m',16,struct msp_dfpreg)
+#define MSP_AUDC_SET_INPUT -1 /* Temporally value 20030325 K.O */
+#define MSP_AUDC_SET_RADIO -2 /* Temporally value 20030325 K.O */
+
+#define MSP_FLAG_NORM      0
+#define MSP_FLAG_EIAJ      1
+#define MSP_FLAG_KOREA     2
+/* After 0.2.7+2.4.21pre6 */
+static inline int MAX(int a,int b)
+{
+   if(a>b) return a;
+   return b;
+}
+
+static inline int MIN(int a,int b)
+{
+   if(a<b) return a;
+   return b;
+}
+
+#endif /* MSP34x5_H */
diff -urN video4linux-20031218/saa7134-cards.c video4linux-20031218.monstertv.1/saa7134-cards.c
--- video4linux-20031218/saa7134-cards.c	2003-12-17 19:32:01.000000000 +0900
+++ video4linux-20031218.monstertv.1/saa7134-cards.c	2003-12-20 02:46:15.000000000 +0900
@@ -185,11 +185,12 @@
                /* "K.Ohta" <alpha292@bremen.or.jp> */
                .name           = "SKNet Monster TV",
                .audio_clock    = 0x00187de7,
-               .tuner_type     = TUNER_PHILIPS_NTSC_M,
+               .tuner_type     = TUNER_PHILIPS_FM1236_MK3,
+	       .need_tda9887   = 0,
                .inputs         = {{
                        .name = name_tv,
                        .vmux = 1,
-                       .amux = TV,
+                       .amux = LINE2,
                        .tv   = 1,
                },{
                        .name = name_comp1,
diff -urN video4linux-20031218/saa7134-tvaudio.c video4linux-20031218.monstertv.1/saa7134-tvaudio.c
--- video4linux-20031218/saa7134-tvaudio.c	2003-12-15 19:18:39.000000000 +0900
+++ video4linux-20031218.monstertv.1/saa7134-tvaudio.c	2003-12-20 02:46:15.000000000 +0900
@@ -185,10 +185,11 @@
 		if (mute)
 			in = &card(dev).mute;
 	}
+#if 1
 	if (dev->hw_mute  == mute &&
 	    dev->hw_input == in)
 		return;
-
+#endif
 	dprintk("ctl_mute=%d automute=%d input=%s  =>  mute=%d input=%s\n",
 		dev->ctl_mute,dev->automute,dev->input->name,mute,in->name);
 	dev->hw_mute  = mute;
diff -urN video4linux-20031218/saa7134-video.c video4linux-20031218.monstertv.1/saa7134-video.c
--- video4linux-20031218/saa7134-video.c	2003-12-16 19:06:20.000000000 +0900
+++ video4linux-20031218.monstertv.1/saa7134-video.c	2003-12-20 02:46:15.000000000 +0900
@@ -1732,13 +1732,21 @@
 	case VIDIOC_G_AUDIO:
 	{
 		struct v4l2_audio *a = arg;
-
+	        struct video_audio t;
+	        saa7134_i2c_call_clients(dev,VIDIOCGAUDIO,&t);
 		memset(a,0,sizeof(*a));
 		strcpy(a->name,"audio");
+	        a->mode=(__u32)(t.mode);
 		return 0;
 	}
 	case VIDIOC_S_AUDIO:
-		return 0;
+	{
+	       struct video_audio a;
+	       memset(&a,0,sizeof(a));
+	       a.mode=(__u16)((((struct v4l2_audio *) arg)->mode)%65536);
+	       saa7134_i2c_call_clients(dev,VIDIOCSAUDIO,&a);
+	       return 0;
+	}
         case VIDIOC_G_PARM:
         {
                 struct v4l2_captureparm *parm = arg;
diff -urN video4linux-20031218/saa7134-video.c.orig video4linux-20031218.monstertv.1/saa7134-video.c.orig
--- video4linux-20031218/saa7134-video.c.orig	1970-01-01 09:00:00.000000000 +0900
+++ video4linux-20031218.monstertv.1/saa7134-video.c.orig	2003-12-16 19:06:20.000000000 +0900
@@ -0,0 +1,2201 @@
+/*
+ * device driver for philips saa7134 based TV cards
+ * video4linux video interface
+ *
+ * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+
+#include "saa7134-reg.h"
+#include "saa7134.h"
+
+/* ------------------------------------------------------------------ */
+
+static unsigned int video_debug  = 0;
+static unsigned int gbuffers     = 8;
+static unsigned int gbufsize     = 768*576*4;
+static unsigned int gbufsize_max = 768*576*4;
+MODULE_PARM(video_debug,"i");
+MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
+MODULE_PARM(gbuffers,"i");
+MODULE_PARM_DESC(gbuffers,"number of capture buffers, range 2-32");
+
+#define dprintk(fmt, arg...)	if (video_debug) \
+	printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg)
+
+/* ------------------------------------------------------------------ */
+/* data structs for video                                             */
+
+static int video_out[][9] = {
+	[CCIR656] = { 0x00, 0xb1, 0x00, 0xa1, 0x00, 0x04, 0x06, 0x00, 0x00 },
+};
+		
+static struct saa7134_format formats[] = {
+	{
+		.name     = "8 bpp gray",
+		.fourcc   = V4L2_PIX_FMT_GREY,
+		.depth    = 8,
+		.pm       = 0x06,
+	},{
+		.name     = "15 bpp RGB, le",
+		.fourcc   = V4L2_PIX_FMT_RGB555,
+		.depth    = 16,
+		.pm       = 0x13 | 0x80,
+	},{
+		.name     = "15 bpp RGB, be",
+		.fourcc   = V4L2_PIX_FMT_RGB555X,
+		.depth    = 16,
+		.pm       = 0x13 | 0x80,
+		.bswap    = 1,
+	},{
+		.name     = "16 bpp RGB, le",
+		.fourcc   = V4L2_PIX_FMT_RGB565,
+		.depth    = 16,
+		.pm       = 0x10 | 0x80,
+	},{
+		.name     = "16 bpp RGB, be",
+		.fourcc   = V4L2_PIX_FMT_RGB565X,
+		.depth    = 16,
+		.pm       = 0x10 | 0x80,
+		.bswap    = 1,
+	},{
+		.name     = "24 bpp RGB, le",
+		.fourcc   = V4L2_PIX_FMT_BGR24,
+		.depth    = 24,
+		.pm       = 0x11,
+	},{
+		.name     = "24 bpp RGB, be",
+		.fourcc   = V4L2_PIX_FMT_RGB24,
+		.depth    = 24,
+		.pm       = 0x11,
+		.bswap    = 1,
+	},{
+		.name     = "32 bpp RGB, le",
+		.fourcc   = V4L2_PIX_FMT_BGR32,
+		.depth    = 32,
+		.pm       = 0x12,
+	},{
+		.name     = "32 bpp RGB, be",
+		.fourcc   = V4L2_PIX_FMT_RGB32,
+		.depth    = 32,
+		.pm       = 0x12,
+		.bswap    = 1,
+		.wswap    = 1,
+	},{
+		.name     = "4:2:2 packed, YUYV",
+		.fourcc   = V4L2_PIX_FMT_YUYV,
+		.depth    = 16,
+		.pm       = 0x00,
+		.bswap    = 1,
+		.yuv      = 1,
+	},{
+		.name     = "4:2:2 packed, UYVY",
+		.fourcc   = V4L2_PIX_FMT_UYVY,
+		.depth    = 16,
+		.pm       = 0x00,
+		.yuv      = 1,
+	},{
+		.name     = "4:2:2 planar, Y-Cb-Cr",
+		.fourcc   = V4L2_PIX_FMT_YUV422P,
+		.depth    = 16,
+		.pm       = 0x09,
+		.yuv      = 1,
+		.planar   = 1,
+		.hshift   = 1,
+		.vshift   = 0,
+	},{
+		.name     = "4:2:0 planar, Y-Cb-Cr",
+		.fourcc   = V4L2_PIX_FMT_YUV420,
+		.depth    = 12,
+		.pm       = 0x0a,
+		.yuv      = 1,
+		.planar   = 1,
+		.hshift   = 1,
+		.vshift   = 1,
+	},{
+		.name     = "4:2:0 planar, Y-Cb-Cr",
+		.fourcc   = V4L2_PIX_FMT_YVU420,
+		.depth    = 12,
+		.pm       = 0x0a,
+		.yuv      = 1,
+		.planar   = 1,
+		.uvswap   = 1,
+		.hshift   = 1,
+		.vshift   = 1,
+	}
+};
+#define FORMATS ARRAY_SIZE(formats)
+
+static struct saa7134_tvnorm tvnorms[] = {
+	{
+		.name          = "PAL",
+		.id            = V4L2_STD_PAL,
+		.width         = 720,
+		.height        = 576,
+
+		.sync_control  = 0x18,
+		.luma_control  = 0x40,
+		.chroma_ctrl1  = 0x81,
+		.chroma_gain   = 0x2a,
+		.chroma_ctrl2  = 0x06,
+		.vgate_misc    = 0x1c,
+
+		.h_start       = 0,
+		.h_stop        = 719,
+		.video_v_start = 24,
+		.video_v_stop  = 311,
+		.vbi_v_start   = 7,
+		.vbi_v_stop    = 22,
+		.src_timing    = 4,
+	},{
+		.name          = "NTSC",
+		.id            = V4L2_STD_NTSC,
+		.width         = 720,
+		.height        = 480,
+
+		.sync_control  = 0x59,
+		.luma_control  = 0x40,
+		.chroma_ctrl1  = 0x89,
+		.chroma_gain   = 0x2a,
+		.chroma_ctrl2  = 0x0e,
+		.vgate_misc    = 0x18,
+
+		.h_start       = 0,
+		.h_stop        = 719,
+		.video_v_start = 22,
+		.video_v_stop  = 22+240,
+		.vbi_v_start   = 10, /* FIXME */
+		.vbi_v_stop    = 21, /* FIXME */
+		.src_timing    = 1,
+	},{
+		.name          = "SECAM",
+		.id            = V4L2_STD_SECAM,
+		.width         = 720,
+		.height        = 576,
+
+		.sync_control  = 0x18, /* old: 0x58, */
+		.luma_control  = 0x1b,
+		.chroma_ctrl1  = 0xd1,
+		.chroma_gain   = 0x80,
+		.chroma_ctrl2  = 0x00,
+		.vgate_misc    = 0x1c,
+
+		.h_start       = 0,
+		.h_stop        = 719,
+		.video_v_start = 24,
+		.video_v_stop  = 311,
+		.vbi_v_start   = 7,
+		.vbi_v_stop    = 22,
+		.src_timing    = 4,
+	},{
+		.name          = "PAL-M",
+		.id            = V4L2_STD_PAL_M,
+		.width         = 720,
+		.height        = 480,
+
+		.sync_control  = 0x59,
+		.luma_control  = 0x40,
+		.chroma_ctrl1  = 0xb9,
+		.chroma_gain   = 0x2a,
+		.chroma_ctrl2  = 0x0e,
+		.vgate_misc    = 0x18,
+
+		.h_start       = 0,
+		.h_stop        = 719,
+		.video_v_start = 22,
+		.video_v_stop  = 22+240,
+		.vbi_v_start   = 10, /* FIXME */
+		.vbi_v_stop    = 21, /* FIXME */
+		.src_timing    = 1,
+	},{
+		.name          = "PAL-Nc",
+		.id            = V4L2_STD_PAL_Nc,
+		.width         = 720,
+		.height        = 576,
+
+		.sync_control  = 0x18,
+		.luma_control  = 0x40,
+		.chroma_ctrl1  = 0xa1,
+		.chroma_gain   = 0x2a,
+		.chroma_ctrl2  = 0x06,
+		.vgate_misc    = 0x1c,
+
+		.h_start       = 0,
+		.h_stop        = 719,
+		.video_v_start = 24,
+		.video_v_stop  = 311,
+		.vbi_v_start   = 7,
+		.vbi_v_stop    = 22,
+		.src_timing    = 4,
+#if 0
+	},{
+		.name          = "AUTO",
+		.id            = V4L2_STD_PAL|V4L2_STD_NTSC|V4L2_STD_SECAM,
+		.width         = 768,
+		.height        = 576,
+
+		.sync_control  = 0x98,
+		.luma_control  = 0x40,
+		.chroma_ctrl1  = 0x8b,
+		.chroma_gain   = 0x00,
+		.chroma_ctrl2  = 0x00,
+		.vgate_misc    = 0x18,
+
+		.h_start       = 0,
+		.h_stop        = 719,
+		.video_v_start = 24,
+		.video_v_stop  = 311,
+		.vbi_v_start   = 7,
+		.vbi_v_stop    = 22,
+		.src_timing    = 4,
+#endif
+	}
+};
+#define TVNORMS ARRAY_SIZE(tvnorms)
+
+#define V4L2_CID_PRIVATE_INVERT      (V4L2_CID_PRIVATE_BASE + 0)
+#define V4L2_CID_PRIVATE_Y_ODD       (V4L2_CID_PRIVATE_BASE + 1)
+#define V4L2_CID_PRIVATE_Y_EVEN      (V4L2_CID_PRIVATE_BASE + 2)
+#define V4L2_CID_PRIVATE_LASTP1      (V4L2_CID_PRIVATE_BASE + 3)
+
+static const struct v4l2_queryctrl no_ctrl = {
+	.name  = "42",
+	.flags = V4L2_CTRL_FLAG_DISABLED,
+};
+static const struct v4l2_queryctrl video_ctrls[] = {
+	/* --- video --- */
+	{
+		.id            = V4L2_CID_BRIGHTNESS,
+		.name          = "Brightness",
+		.minimum       = 0,
+		.maximum       = 255,
+		.step          = 1,
+		.default_value = 128,
+		.type          = V4L2_CTRL_TYPE_INTEGER,
+	},{
+		.id            = V4L2_CID_CONTRAST,
+		.name          = "Contrast",
+		.minimum       = 0,
+		.maximum       = 127,
+		.step          = 1,
+		.default_value = 68,
+		.type          = V4L2_CTRL_TYPE_INTEGER,
+	},{
+		.id            = V4L2_CID_SATURATION,
+		.name          = "Saturation",
+		.minimum       = 0,
+		.maximum       = 127,
+		.step          = 1,
+		.default_value = 64,
+		.type          = V4L2_CTRL_TYPE_INTEGER,
+	},{
+		.id            = V4L2_CID_HUE,
+		.name          = "Hue",
+		.minimum       = -128,
+		.maximum       = 127,
+		.step          = 1,
+		.default_value = 0,
+		.type          = V4L2_CTRL_TYPE_INTEGER,
+	},{
+		.id            = V4L2_CID_VFLIP,
+		.name          = "vertical flip",
+		.minimum       = 0,
+		.maximum       = 1,
+		.type          = V4L2_CTRL_TYPE_BOOLEAN,
+	},
+	/* --- audio --- */
+	{
+		.id            = V4L2_CID_AUDIO_MUTE,
+		.name          = "Mute",
+		.minimum       = 0,
+		.maximum       = 1,
+		.type          = V4L2_CTRL_TYPE_BOOLEAN,
+	},{
+		.id            = V4L2_CID_AUDIO_VOLUME,
+		.name          = "Volume",
+		.minimum       = -15,
+		.maximum       = 15,
+		.step          = 1,
+		.default_value = 0,
+		.type          = V4L2_CTRL_TYPE_INTEGER,
+	},
+	/* --- private --- */
+	{
+		.id            = V4L2_CID_PRIVATE_INVERT,
+		.name          = "Invert",
+		.minimum       = 0,
+		.maximum       = 1,
+		.type          = V4L2_CTRL_TYPE_BOOLEAN,
+	},{
+		.id            = V4L2_CID_PRIVATE_Y_ODD,
+		.name          = "y offset odd field",
+		.minimum       = 0,
+		.maximum       = 128,
+		.default_value = 0,
+		.type          = V4L2_CTRL_TYPE_INTEGER,
+	},{
+		.id            = V4L2_CID_PRIVATE_Y_EVEN,
+		.name          = "y offset even field",
+		.minimum       = 0,
+		.maximum       = 128,
+		.default_value = 0,
+		.type          = V4L2_CTRL_TYPE_INTEGER,
+	}
+};
+static const unsigned int CTRLS = ARRAY_SIZE(video_ctrls);
+
+static const struct v4l2_queryctrl* ctrl_by_id(unsigned int id)
+{
+	unsigned int i;
+	
+	for (i = 0; i < CTRLS; i++)
+		if (video_ctrls[i].id == id)
+			return video_ctrls+i;
+	return NULL;
+}
+
+static struct saa7134_format* format_by_fourcc(unsigned int fourcc)
+{
+	unsigned int i;
+
+	for (i = 0; i < FORMATS; i++)
+		if (formats[i].fourcc == fourcc)
+			return formats+i;
+	return NULL;
+}
+
+/* ----------------------------------------------------------------------- */
+/* resource management                                                     */
+
+static int res_get(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bit)
+{
+	if (fh->resources & bit)
+		/* have it already allocated */
+		return 1;
+
+	/* is it free? */
+	down(&dev->lock);
+	if (dev->resources & bit) {
+		/* no, someone else uses it */
+		up(&dev->lock);
+		return 0;
+	}
+	/* it's free, grab it */
+	fh->resources  |= bit;
+	dev->resources |= bit;
+	dprintk("res: get %d\n",bit);
+	up(&dev->lock);
+	return 1;
+}
+
+static
+int res_check(struct saa7134_fh *fh, unsigned int bit)
+{
+	return (fh->resources & bit);
+}
+
+static
+int res_locked(struct saa7134_dev *dev, unsigned int bit)
+{
+	return (dev->resources & bit);
+}
+
+static
+void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits)
+{
+	if ((fh->resources & bits) != bits)
+		BUG();
+
+	down(&dev->lock);
+	fh->resources  &= ~bits;
+	dev->resources &= ~bits;
+	dprintk("res: put %d\n",bits);
+	up(&dev->lock);
+}
+
+/* ------------------------------------------------------------------ */
+
+static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
+{
+	struct video_channel c;
+	int luma_control,mux;
+
+	dprintk("set tv norm = %s\n",norm->name);
+	dev->tvnorm = norm;
+
+	mux = card_in(dev,dev->ctl_input).vmux;
+	luma_control = norm->luma_control;
+	if (mux > 5)
+		luma_control |= 0x80; /* svideo */
+
+	/* setup video decoder */
+	saa_writeb(SAA7134_INCR_DELAY,            0x08);
+	saa_writeb(SAA7134_ANALOG_IN_CTRL1,       0xc0 | mux);
+	saa_writeb(SAA7134_ANALOG_IN_CTRL2,       0x00);
+
+	saa_writeb(SAA7134_ANALOG_IN_CTRL3,       0x90);
+	saa_writeb(SAA7134_ANALOG_IN_CTRL4,       0x90);
+	saa_writeb(SAA7134_HSYNC_START,           0xeb);
+	saa_writeb(SAA7134_HSYNC_STOP,            0xe0);
+	saa_writeb(SAA7134_SOURCE_TIMING1,        norm->src_timing);
+	
+	saa_writeb(SAA7134_SYNC_CTRL,             norm->sync_control);
+	saa_writeb(SAA7134_LUMA_CTRL,             luma_control);
+	saa_writeb(SAA7134_DEC_LUMA_BRIGHT,       dev->ctl_bright);
+	saa_writeb(SAA7134_DEC_LUMA_CONTRAST,     dev->ctl_contrast);
+ 
+	saa_writeb(SAA7134_DEC_CHROMA_SATURATION, dev->ctl_saturation);
+	saa_writeb(SAA7134_DEC_CHROMA_HUE,        dev->ctl_hue);
+	saa_writeb(SAA7134_CHROMA_CTRL1,          norm->chroma_ctrl1);
+	saa_writeb(SAA7134_CHROMA_GAIN,           norm->chroma_gain);
+
+	saa_writeb(SAA7134_CHROMA_CTRL2,          norm->chroma_ctrl2);
+	saa_writeb(SAA7134_MODE_DELAY_CTRL,       0x00);
+
+	saa_writeb(SAA7134_ANALOG_ADC,            0x01);
+	saa_writeb(SAA7134_VGATE_START,           0x11);
+	saa_writeb(SAA7134_VGATE_STOP,            0xfe);
+	saa_writeb(SAA7134_MISC_VGATE_MSB,        norm->vgate_misc);
+	saa_writeb(SAA7134_RAW_DATA_GAIN,         0x40);
+	saa_writeb(SAA7134_RAW_DATA_OFFSET,       0x80);
+
+	/* pass down info to the i2c chips (v4l1) */
+	memset(&c,0,sizeof(c));
+	c.channel = dev->ctl_input;
+	c.norm = VIDEO_MODE_PAL;
+	if (norm->id & V4L2_STD_NTSC)
+		c.norm = VIDEO_MODE_NTSC;
+	if (norm->id & V4L2_STD_SECAM)
+		c.norm = VIDEO_MODE_SECAM;
+	saa7134_i2c_call_clients(dev,VIDIOCSCHAN,&c);
+}
+
+static void video_mux(struct saa7134_dev *dev, int input)
+{
+	dprintk("video input = %d [%s]\n",input,card_in(dev,input).name);
+	dev->ctl_input = input;
+	set_tvnorm(dev,dev->tvnorm);
+	saa7134_tvaudio_setinput(dev,&card_in(dev,input));
+}
+
+static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
+{
+	static const struct {
+		int xpsc;
+		int xacl;
+		int xc2_1;
+		int xdcg;
+		int vpfy;
+	} vals[] = {
+		/* XPSC XACL XC2_1 XDCG VPFY */
+		{    1,   0,    0,    0,   0 },
+		{    2,   2,    1,    2,   2 },
+		{    3,   4,    1,    3,   2 },
+		{    4,   8,    1,    4,   2 },
+		{    5,   8,    1,    4,   2 },
+		{    6,   8,    1,    4,   3 },
+		{    7,   8,    1,    4,   3 },
+		{    8,  15,    0,    4,   3 },
+		{    9,  15,    0,    4,   3 },
+		{   10,  16,    1,    5,   3 },
+	};
+	static const int count = ARRAY_SIZE(vals);
+	int i;
+
+	for (i = 0; i < count; i++)
+		if (vals[i].xpsc == prescale)
+			break;
+	if (i == count)
+		return;
+
+	saa_writeb(SAA7134_H_PRESCALE(task), vals[i].xpsc);
+	saa_writeb(SAA7134_ACC_LENGTH(task), vals[i].xacl);
+	saa_writeb(SAA7134_LEVEL_CTRL(task),
+		   (vals[i].xc2_1 << 3) | (vals[i].xdcg));
+	saa_andorb(SAA7134_FIR_PREFILTER_CTRL(task), 0x0f,
+		   (vals[i].vpfy << 2) | vals[i].vpfy);
+}
+
+static void set_v_scale(struct saa7134_dev *dev, int task, int yscale)
+{
+	int val,mirror;
+	
+	saa_writeb(SAA7134_V_SCALE_RATIO1(task), yscale &  0xff);
+	saa_writeb(SAA7134_V_SCALE_RATIO2(task), yscale >> 8);
+
+	mirror = (dev->ctl_mirror) ? 0x02 : 0x00;
+	if (yscale < 2048) {
+		/* LPI */
+		dprintk("yscale LPI yscale=%d\n",yscale);
+		saa_writeb(SAA7134_V_FILTER(task), 0x00 | mirror);
+		saa_writeb(SAA7134_LUMA_CONTRAST(task), 0x40);
+		saa_writeb(SAA7134_CHROMA_SATURATION(task), 0x40);
+	} else {
+		/* ACM */
+		val = 0x40 * 1024 / yscale;
+		dprintk("yscale ACM yscale=%d val=0x%x\n",yscale,val);
+		saa_writeb(SAA7134_V_FILTER(task), 0x01 | mirror);
+		saa_writeb(SAA7134_LUMA_CONTRAST(task), val);
+		saa_writeb(SAA7134_CHROMA_SATURATION(task), val);
+	}
+	saa_writeb(SAA7134_LUMA_BRIGHT(task),       0x80);
+}
+
+static void set_size(struct saa7134_dev *dev, int task,
+		     int width, int height, int interlace)
+{
+	struct saa7134_tvnorm *norm = dev->tvnorm;
+	int prescale,xscale,yscale,y_even,y_odd;
+	int div = interlace ? 2 : 1;
+
+	/* setup video scaler */
+	saa_writeb(SAA7134_VIDEO_H_START1(task), norm->h_start       &  0xff);
+	saa_writeb(SAA7134_VIDEO_H_START2(task), norm->h_start       >> 8);
+	saa_writeb(SAA7134_VIDEO_H_STOP1(task),  norm->h_stop        &  0xff);
+	saa_writeb(SAA7134_VIDEO_H_STOP2(task),  norm->h_stop        >> 8);
+	saa_writeb(SAA7134_VIDEO_V_START1(task), norm->video_v_start &  0xff);
+	saa_writeb(SAA7134_VIDEO_V_START2(task), norm->video_v_start >> 8);
+	saa_writeb(SAA7134_VIDEO_V_STOP1(task),  norm->video_v_stop  &  0xff);
+	saa_writeb(SAA7134_VIDEO_V_STOP2(task),  norm->video_v_stop  >> 8);
+
+	prescale = norm->width / width;
+	if (0 == prescale)
+		prescale = 1;
+	xscale = 1024 * norm->width / prescale / width;
+	yscale = 512 * div * norm->height / height;
+       	dprintk("prescale=%d xscale=%d yscale=%d\n",prescale,xscale,yscale);
+	set_h_prescale(dev,task,prescale);
+	saa_writeb(SAA7134_H_SCALE_INC1(task),      xscale &  0xff);
+	saa_writeb(SAA7134_H_SCALE_INC2(task),      xscale >> 8);
+	set_v_scale(dev,task,yscale);
+	
+	saa_writeb(SAA7134_VIDEO_PIXELS1(task),     width  & 0xff);
+	saa_writeb(SAA7134_VIDEO_PIXELS2(task),     width  >> 8);
+	saa_writeb(SAA7134_VIDEO_LINES1(task),      height/div & 0xff);
+	saa_writeb(SAA7134_VIDEO_LINES2(task),      height/div >> 8);
+
+	/* deinterlace y offsets */
+	y_odd  = dev->ctl_y_odd;
+	y_even = dev->ctl_y_even;
+	saa_writeb(SAA7134_V_PHASE_OFFSET0(task), y_odd);
+	saa_writeb(SAA7134_V_PHASE_OFFSET1(task), y_even);
+	saa_writeb(SAA7134_V_PHASE_OFFSET2(task), y_odd);
+	saa_writeb(SAA7134_V_PHASE_OFFSET3(task), y_even);
+}
+
+/* ------------------------------------------------------------------ */
+
+struct cliplist {
+	__u16 position;
+	__u8  enable;
+	__u8  disable;
+};
+
+static void sort_cliplist(struct cliplist *cl, int entries)
+{
+	struct cliplist swap;
+	int i,j,n;
+	
+	for (i = entries-2; i >= 0; i--) {
+		for (n = 0, j = 0; j <= i; j++) {
+			if (cl[j].position > cl[j+1].position) {
+				swap = cl[j];
+				cl[j] = cl[j+1];
+				cl[j+1] = swap;
+				n++;
+			}
+		}
+		if (0 == n)
+			break;
+	}
+}
+
+static void set_cliplist(struct saa7134_dev *dev, int reg,
+			struct cliplist *cl, int entries, char *name)
+{
+	__u8 winbits = 0;
+	int i;
+
+	for (i = 0; i < entries; i++) {
+		winbits |= cl[i].enable;
+		winbits &= ~cl[i].disable;
+		if (i < 15 && cl[i].position == cl[i+1].position)
+			continue;
+		saa_writeb(reg + 0, winbits);
+		saa_writeb(reg + 2, cl[i].position & 0xff);
+		saa_writeb(reg + 3, cl[i].position >> 8);
+		dprintk("clip: %s winbits=%02x pos=%d\n",
+			name,winbits,cl[i].position);
+		reg += 8;
+	}
+	for (; reg < 0x400; reg += 8) {
+		saa_writeb(reg+ 0, 0);
+		saa_writeb(reg + 1, 0);
+		saa_writeb(reg + 2, 0);
+		saa_writeb(reg + 3, 0);
+	}
+}
+
+static int clip_range(int val)
+{
+	if (val < 0)
+		val = 0;
+	return val;
+}
+
+static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips,
+			  int nclips, int interlace)
+{
+	struct cliplist col[16], row[16];
+	int cols, rows, i;
+	int div = interlace ? 2 : 1;
+
+	memset(col,0,sizeof(col)); cols = 0;
+	memset(row,0,sizeof(row)); rows = 0;
+	for (i = 0; i < nclips && i < 8; i++) {
+		col[cols].position = clip_range(clips[i].c.left);
+		col[cols].enable   = (1 << i);
+		cols++;
+		col[cols].position = clip_range(clips[i].c.left+clips[i].c.width);
+		col[cols].disable  = (1 << i);
+		cols++;
+		row[rows].position = clip_range(clips[i].c.top / div);
+		row[rows].enable   = (1 << i);
+		rows++;
+		row[rows].position = clip_range((clips[i].c.top + clips[i].c.height)
+						/ div);
+		row[rows].disable  = (1 << i);
+		rows++;
+	}
+	sort_cliplist(col,cols);
+	sort_cliplist(row,rows);
+	set_cliplist(dev,0x380,col,cols,"cols");
+	set_cliplist(dev,0x384,row,rows,"rows");
+	return 0;
+}
+
+static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win)
+{
+	enum v4l2_field field;
+	int maxw, maxh;
+
+	if (NULL == dev->ovbuf.base)
+		return -EINVAL;
+	if (NULL == dev->ovfmt)
+		return -EINVAL;
+	if (win->w.width < 48 || win->w.height <  32)
+		return -EINVAL;
+	if (win->clipcount > 2048)
+		return -EINVAL;
+
+	field = win->field;
+	maxw  = dev->tvnorm->width;
+	maxh  = dev->tvnorm->height;
+
+	if (V4L2_FIELD_ANY == field) {
+                field = (win->w.height > maxh/2)
+                        ? V4L2_FIELD_INTERLACED
+                        : V4L2_FIELD_TOP;
+        }
+        switch (field) {
+        case V4L2_FIELD_TOP:
+        case V4L2_FIELD_BOTTOM:
+                maxh = maxh / 2;
+                break;
+        case V4L2_FIELD_INTERLACED:
+                break;
+        default:
+                return -EINVAL;
+        }
+
+	win->field = field;
+	if (win->w.width > maxw)
+		win->w.width = maxw;
+	if (win->w.height > maxh)
+		win->w.height = maxh;
+	return 0;
+}
+
+static int start_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
+{
+	unsigned long base,control,bpl;
+	int err;
+
+	err = verify_preview(dev,&fh->win);
+	if (0 != err)
+		return err;
+
+	dev->ovfield = fh->win.field;
+	dprintk("start_preview %dx%d+%d+%d %s field=%s\n",
+		fh->win.w.width,fh->win.w.height,
+		fh->win.w.left,fh->win.w.top,
+		dev->ovfmt->name,v4l2_field_names[dev->ovfield]);
+
+	/* setup window + clipping */
+	set_size(dev,TASK_B,fh->win.w.width,fh->win.w.height,
+		 V4L2_FIELD_HAS_BOTH(dev->ovfield));
+	setup_clipping(dev,fh->clips,fh->nclips,
+		       V4L2_FIELD_HAS_BOTH(dev->ovfield));
+	if (dev->ovfmt->yuv)
+		saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x03);
+	else
+		saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x01);
+	saa_writeb(SAA7134_OFMT_VIDEO_B, dev->ovfmt->pm | 0x20);
+
+	/* dma: setup channel 1 (= Video Task B) */
+	base  = (unsigned long)dev->ovbuf.base;
+	base += dev->ovbuf.fmt.bytesperline * fh->win.w.top;
+	base += dev->ovfmt->depth/8         * fh->win.w.left;
+	bpl   = dev->ovbuf.fmt.bytesperline;
+	control = SAA7134_RS_CONTROL_BURST_16;
+	if (dev->ovfmt->bswap)
+		control |= SAA7134_RS_CONTROL_BSWAP;
+	if (dev->ovfmt->wswap)
+		control |= SAA7134_RS_CONTROL_WSWAP;
+	if (V4L2_FIELD_HAS_BOTH(dev->ovfield)) {
+		saa_writel(SAA7134_RS_BA1(1),base);
+		saa_writel(SAA7134_RS_BA2(1),base+bpl);
+		saa_writel(SAA7134_RS_PITCH(1),bpl*2);
+		saa_writel(SAA7134_RS_CONTROL(1),control);
+	} else {
+		saa_writel(SAA7134_RS_BA1(1),base);
+		saa_writel(SAA7134_RS_BA2(1),base);
+		saa_writel(SAA7134_RS_PITCH(1),bpl);
+		saa_writel(SAA7134_RS_CONTROL(1),control);
+	}
+
+	/* start dma */
+	dev->ovenable = 1;
+	saa7134_set_dmabits(dev);
+
+	return 0;
+}
+
+static int stop_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
+{
+	dev->ovenable = 0;
+	saa7134_set_dmabits(dev);
+	return 0;
+}
+
+/* ------------------------------------------------------------------ */
+
+static int buffer_activate(struct saa7134_dev *dev,
+			   struct saa7134_buf *buf,
+			   struct saa7134_buf *next)
+{
+	unsigned long base,control,bpl;
+	unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
+
+	dprintk("buffer_activate buf=%p\n",buf);
+	buf->vb.state = STATE_ACTIVE;
+	buf->top_seen = 0;
+	
+	set_size(dev,TASK_A,buf->vb.width,buf->vb.height,
+		 V4L2_FIELD_HAS_BOTH(buf->vb.field));
+	if (buf->fmt->yuv)
+		saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x03);
+	else
+		saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x01);
+	saa_writeb(SAA7134_OFMT_VIDEO_A, buf->fmt->pm);
+
+	/* DMA: setup channel 0 (= Video Task A0) */
+	base  = saa7134_buffer_base(buf);
+	if (buf->fmt->planar)
+		bpl = buf->vb.width;
+	else
+		bpl = (buf->vb.width * buf->fmt->depth) / 8;
+	control = SAA7134_RS_CONTROL_BURST_16 |
+		SAA7134_RS_CONTROL_ME |
+		(buf->pt->dma >> 12);
+	if (buf->fmt->bswap)
+		control |= SAA7134_RS_CONTROL_BSWAP;
+	if (buf->fmt->wswap)
+		control |= SAA7134_RS_CONTROL_WSWAP;
+	if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
+		/* interlaced */
+		saa_writel(SAA7134_RS_BA1(0),base);
+		saa_writel(SAA7134_RS_BA2(0),base+bpl);
+		saa_writel(SAA7134_RS_PITCH(0),bpl*2);
+	} else {
+		/* non-interlaced */
+		saa_writel(SAA7134_RS_BA1(0),base);
+		saa_writel(SAA7134_RS_BA2(0),base);
+		saa_writel(SAA7134_RS_PITCH(0),bpl);
+	}
+	saa_writel(SAA7134_RS_CONTROL(0),control);
+
+	if (buf->fmt->planar) {
+		/* DMA: setup channel 4+5 (= planar task A) */
+		bpl_uv   = bpl >> buf->fmt->hshift;
+		lines_uv = buf->vb.height >> buf->fmt->vshift;
+		base2    = base + bpl * buf->vb.height;
+		base3    = base2 + bpl_uv * lines_uv;
+		if (buf->fmt->uvswap)
+			tmp = base2, base2 = base3, base3 = tmp;
+		dprintk("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
+			bpl_uv,lines_uv,base2,base3);
+		if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
+			/* interlaced */
+			saa_writel(SAA7134_RS_BA1(4),base2);
+			saa_writel(SAA7134_RS_BA2(4),base2+bpl_uv);
+			saa_writel(SAA7134_RS_PITCH(4),bpl_uv*2);
+			saa_writel(SAA7134_RS_BA1(5),base3);
+			saa_writel(SAA7134_RS_BA2(5),base3+bpl_uv);
+			saa_writel(SAA7134_RS_PITCH(5),bpl_uv*2);
+		} else {
+			/* non-interlaced */
+			saa_writel(SAA7134_RS_BA1(4),base2);
+			saa_writel(SAA7134_RS_BA2(4),base2);
+			saa_writel(SAA7134_RS_PITCH(4),bpl_uv);
+			saa_writel(SAA7134_RS_BA1(5),base3);
+			saa_writel(SAA7134_RS_BA2(5),base3);
+			saa_writel(SAA7134_RS_PITCH(5),bpl_uv);
+		}
+		saa_writel(SAA7134_RS_CONTROL(4),control);
+		saa_writel(SAA7134_RS_CONTROL(5),control);
+	}
+
+	/* start DMA */
+	saa7134_set_dmabits(dev);
+	mod_timer(&dev->video_q.timeout, jiffies+BUFFER_TIMEOUT);
+	return 0;
+}
+
+static int buffer_prepare(struct file *file, struct videobuf_buffer *vb,
+			  enum v4l2_field field)
+{
+	struct saa7134_fh *fh = file->private_data;
+	struct saa7134_dev *dev = fh->dev;
+	struct saa7134_buf *buf = (struct saa7134_buf *)vb;
+	unsigned int size;
+	int err;
+	
+	/* sanity checks */
+	if (NULL == fh->fmt)
+		return -EINVAL;
+	if (fh->width  < 48 ||
+	    fh->height < 32 ||
+	    fh->width  > dev->tvnorm->width ||
+	    fh->height > dev->tvnorm->height)
+		return -EINVAL;
+	size = (fh->width * fh->height * fh->fmt->depth) >> 3;
+	if (0 != buf->vb.baddr  &&  buf->vb.bsize < size)
+		return -EINVAL;
+
+	dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n",
+		vb->i,fh->width,fh->height,size,v4l2_field_names[field],
+		fh->fmt->name);
+	if (buf->vb.width  != fh->width  ||
+	    buf->vb.height != fh->height ||
+	    buf->vb.size   != size       ||
+	    buf->vb.field  != field      ||
+	    buf->fmt       != fh->fmt) {
+		saa7134_dma_free(dev,buf);
+	}
+
+	if (STATE_NEEDS_INIT == buf->vb.state) {
+		buf->vb.width  = fh->width;
+		buf->vb.height = fh->height;
+		buf->vb.size   = size;
+		buf->vb.field  = field;
+		buf->fmt       = fh->fmt;
+		buf->pt        = &fh->pt_cap;
+
+		err = videobuf_iolock(dev->pci,&buf->vb,&dev->ovbuf);
+		if (err)
+			goto oops;
+		err = saa7134_pgtable_build(dev->pci,buf->pt,
+					    buf->vb.dma.sglist,
+					    buf->vb.dma.sglen,
+					    saa7134_buffer_startpage(buf));
+		if (err)
+			goto oops;
+	}
+	buf->vb.state = STATE_PREPARED;
+	buf->activate = buffer_activate;
+	return 0;
+
+ oops:
+	saa7134_dma_free(dev,buf);
+	return err;
+}
+
+static int
+buffer_setup(struct file *file, unsigned int *count, unsigned int *size)
+{
+	struct saa7134_fh *fh = file->private_data;
+
+	*size = fh->fmt->depth * fh->width * fh->height >> 3;
+	if (0 == *count)
+		*count = gbuffers;
+	*count = saa7134_buffer_count(*size,*count);
+	return 0;
+}
+
+static void buffer_queue(struct file *file, struct videobuf_buffer *vb)
+{
+	struct saa7134_fh *fh = file->private_data;
+	struct saa7134_buf *buf = (struct saa7134_buf *)vb;
+	
+	saa7134_buffer_queue(fh->dev,&fh->dev->video_q,buf);
+}
+
+static void buffer_release(struct file *file, struct videobuf_buffer *vb)
+{
+	struct saa7134_fh *fh = file->private_data;
+	struct saa7134_buf *buf = (struct saa7134_buf *)vb;
+	
+	saa7134_dma_free(fh->dev,buf);
+}
+
+static struct videobuf_queue_ops video_qops = {
+	.buf_setup    = buffer_setup,
+	.buf_prepare  = buffer_prepare,
+	.buf_queue    = buffer_queue,
+	.buf_release  = buffer_release,
+};
+
+/* ------------------------------------------------------------------ */
+
+static int get_control(struct saa7134_dev *dev, struct v4l2_control *c)
+{
+	const struct v4l2_queryctrl* ctrl;
+
+	ctrl = ctrl_by_id(c->id);
+	if (NULL == ctrl)
+		return -EINVAL;
+	switch (c->id) {
+	case V4L2_CID_BRIGHTNESS:
+		c->value = dev->ctl_bright;
+		break;
+	case V4L2_CID_HUE:
+		c->value = dev->ctl_hue;
+		break;
+	case V4L2_CID_CONTRAST:
+		c->value = dev->ctl_contrast;
+		break;
+	case V4L2_CID_SATURATION:
+		c->value = dev->ctl_saturation;
+		break;
+	case V4L2_CID_AUDIO_MUTE:
+		c->value = dev->ctl_mute;
+		break;
+	case V4L2_CID_AUDIO_VOLUME:
+		c->value = dev->ctl_volume;
+		break;
+	case V4L2_CID_PRIVATE_INVERT:
+		c->value = dev->ctl_invert;
+		break;
+	case V4L2_CID_VFLIP:
+		c->value = dev->ctl_mirror;
+		break;
+	case V4L2_CID_PRIVATE_Y_EVEN:
+		c->value = dev->ctl_y_even;
+		break;
+	case V4L2_CID_PRIVATE_Y_ODD:
+		c->value = dev->ctl_y_odd;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int set_control(struct saa7134_dev *dev, struct saa7134_fh *fh,
+		       struct v4l2_control *c)
+{
+	const struct v4l2_queryctrl* ctrl;
+	unsigned long flags;
+	int restart_overlay = 0;
+
+	ctrl = ctrl_by_id(c->id);
+	if (NULL == ctrl)
+		return -EINVAL;
+	dprintk("set_control name=%s val=%d\n",ctrl->name,c->value);
+	switch (ctrl->type) {
+	case V4L2_CTRL_TYPE_BOOLEAN:
+	case V4L2_CTRL_TYPE_MENU:
+	case V4L2_CTRL_TYPE_INTEGER:
+		if (c->value < ctrl->minimum)
+			c->value = ctrl->minimum;
+		if (c->value > ctrl->maximum)
+			c->value = ctrl->maximum;
+		break;
+	default:
+		/* nothing */;
+	};
+	switch (c->id) {
+	case V4L2_CID_BRIGHTNESS:
+		dev->ctl_bright = c->value;
+		saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright);
+		break;
+	case V4L2_CID_HUE:
+		dev->ctl_hue = c->value;
+		saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue);
+		break;
+	case V4L2_CID_CONTRAST:
+		dev->ctl_contrast = c->value;
+		saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
+			   dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
+		break;
+	case V4L2_CID_SATURATION:
+		dev->ctl_saturation = c->value;
+		saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
+			   dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
+		break;
+	case V4L2_CID_AUDIO_MUTE:
+		dev->ctl_mute = c->value;
+		saa7134_tvaudio_setmute(dev);
+		break;
+	case V4L2_CID_AUDIO_VOLUME:
+		dev->ctl_volume = c->value;
+		saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
+		break;
+	case V4L2_CID_PRIVATE_INVERT:
+		dev->ctl_invert = c->value;
+		saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
+			   dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
+		saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
+			   dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
+		break;
+	case V4L2_CID_VFLIP:
+		dev->ctl_mirror = c->value;
+		restart_overlay = 1;
+		break;
+	case V4L2_CID_PRIVATE_Y_EVEN:
+		dev->ctl_y_even = c->value;
+		restart_overlay = 1;
+		break;
+	case V4L2_CID_PRIVATE_Y_ODD:
+		dev->ctl_y_odd = c->value;
+		restart_overlay = 1;
+		break;
+	default:
+		return -EINVAL;
+	}
+	if (restart_overlay && fh && res_check(fh, RESOURCE_OVERLAY)) {
+		spin_lock_irqsave(&dev->slock,flags);
+		stop_preview(dev,fh);
+		start_preview(dev,fh);
+		spin_unlock_irqrestore(&dev->slock,flags);
+	}
+	return 0;
+}
+
+/* ------------------------------------------------------------------ */
+
+static struct videobuf_queue* saa7134_queue(struct saa7134_fh *fh)
+{
+	struct videobuf_queue* q = NULL;
+	
+	switch (fh->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		q = &fh->cap;
+		break;
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		q = &fh->vbi;
+		break;
+	default:
+		BUG();
+	}
+	return q;
+}
+
+static int saa7134_resource(struct saa7134_fh *fh)
+{
+	int res = 0;
+	
+	switch (fh->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		res = RESOURCE_VIDEO;
+		break;
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		res = RESOURCE_VBI;
+		break;
+	default:
+		BUG();
+	}
+	return res;
+}
+
+static int video_open(struct inode *inode, struct file *file)
+{
+	int minor = iminor(inode);
+	struct saa7134_dev *h,*dev = NULL;
+	struct saa7134_fh *fh;
+	struct list_head *list;
+	enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	int radio = 0;
+	
+	list_for_each(list,&saa7134_devlist) {
+		h = list_entry(list, struct saa7134_dev, devlist);
+		if (h->video_dev && (h->video_dev->minor == minor))
+			dev = h;
+		if (h->radio_dev && (h->radio_dev->minor == minor)) {
+			radio = 1;
+			dev = h;
+		}
+		if (h->vbi_dev && (h->vbi_dev->minor == minor)) {
+			type = V4L2_BUF_TYPE_VBI_CAPTURE;
+			dev = h;
+		}
+	}
+	if (NULL == dev)
+		return -ENODEV;
+
+	dprintk("open minor=%d radio=%d type=%s\n",minor,radio,
+		v4l2_type_names[type]);
+
+	/* allocate + initialize per filehandle data */
+	fh = kmalloc(sizeof(*fh),GFP_KERNEL);
+	if (NULL == fh)
+		return -ENOMEM;
+	memset(fh,0,sizeof(*fh));
+	file->private_data = fh;
+	fh->dev      = dev;
+	fh->radio    = radio;
+	fh->type     = type;
+	fh->fmt      = format_by_fourcc(V4L2_PIX_FMT_BGR24);
+	fh->width    = 768;
+	fh->height   = 576;
+
+	videobuf_queue_init(&fh->cap, &video_qops,
+			    dev->pci, &dev->slock,
+			    V4L2_BUF_TYPE_VIDEO_CAPTURE,
+			    V4L2_FIELD_INTERLACED,
+			    sizeof(struct saa7134_buf));
+	init_MUTEX(&fh->cap.lock);
+	saa7134_pgtable_alloc(dev->pci,&fh->pt_cap);
+
+	videobuf_queue_init(&fh->vbi, &saa7134_vbi_qops,
+			    dev->pci, &dev->slock,
+			    V4L2_BUF_TYPE_VBI_CAPTURE,
+			    V4L2_FIELD_SEQ_TB,
+			    sizeof(struct saa7134_buf));
+        init_MUTEX(&fh->vbi.lock);
+	saa7134_pgtable_alloc(dev->pci,&fh->pt_vbi);
+
+	if (fh->radio) {
+		/* switch to radio mode */
+		saa7134_tvaudio_setinput(dev,&card(dev).radio);
+		saa7134_i2c_call_clients(dev,AUDC_SET_RADIO,NULL);
+	} else {
+		/* switch to video/vbi mode */
+		video_mux(dev,dev->ctl_input);
+	}
+        return 0;
+}
+
+static ssize_t
+video_read(struct file *file, char *data, size_t count, loff_t *ppos)
+{
+	struct saa7134_fh *fh = file->private_data;
+
+	switch (fh->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		if (res_locked(fh->dev,RESOURCE_VIDEO))
+			return -EBUSY;
+		return videobuf_read_one(file, saa7134_queue(fh),
+					 data, count, ppos);
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		if (!res_get(fh->dev,fh,RESOURCE_VBI))
+			return -EBUSY;
+		return videobuf_read_stream(file, saa7134_queue(fh),
+					    data, count, ppos, 1);
+		break;
+	default:
+		BUG();
+		return 0;
+	}
+}
+
+static unsigned int
+video_poll(struct file *file, struct poll_table_struct *wait)
+{
+	struct saa7134_fh *fh = file->private_data;
+	struct videobuf_buffer *buf = NULL;
+
+	if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)
+		return videobuf_poll_stream(file, &fh->vbi, wait);
+
+	if (res_check(fh,RESOURCE_VIDEO)) {
+		if (!list_empty(&fh->cap.stream))
+			buf = list_entry(fh->cap.stream.next, struct videobuf_buffer, stream);
+	} else {
+		down(&fh->cap.lock);
+		if (UNSET == fh->cap.read_off) {
+                        /* need to capture a new frame */
+			if (res_locked(fh->dev,RESOURCE_VIDEO)) {
+                                up(&fh->cap.lock);
+                                return POLLERR;
+                        }
+                        if (0 != fh->cap.ops->buf_prepare(file,fh->cap.read_buf,fh->cap.field)) {
+                                up(&fh->cap.lock);
+                                return POLLERR;
+                        }
+                        fh->cap.ops->buf_queue(file,fh->cap.read_buf);
+                        fh->cap.read_off = 0;
+		}
+		up(&fh->cap.lock);
+		buf = fh->cap.read_buf;
+	}
+
+	if (!buf)
+		return POLLERR;
+
+	poll_wait(file, &buf->done, wait);
+	if (buf->state == STATE_DONE ||
+	    buf->state == STATE_ERROR)
+		return POLLIN|POLLRDNORM;
+	return 0;
+}
+
+static int video_release(struct inode *inode, struct file *file)
+{
+	struct saa7134_fh  *fh  = file->private_data;
+	struct saa7134_dev *dev = fh->dev;
+	unsigned long flags;
+
+	/* turn off overlay */
+	if (res_check(fh, RESOURCE_OVERLAY)) {
+		spin_lock_irqsave(&dev->slock,flags);
+		stop_preview(dev,fh);
+		spin_unlock_irqrestore(&dev->slock,flags);
+		res_free(dev,fh,RESOURCE_OVERLAY);
+	}
+
+	/* stop video capture */
+	if (res_check(fh, RESOURCE_VIDEO)) {
+		videobuf_streamoff(file,&fh->cap);
+		res_free(dev,fh,RESOURCE_VIDEO);
+	}
+	if (fh->cap.read_buf) {
+		buffer_release(file,fh->cap.read_buf);
+		kfree(fh->cap.read_buf);
+	}
+
+	/* stop vbi capture */
+	if (res_check(fh, RESOURCE_VBI)) {
+		if (fh->vbi.streaming)
+			videobuf_streamoff(file,&fh->vbi);
+		if (fh->vbi.reading)
+			videobuf_read_stop(file,&fh->vbi);
+		res_free(dev,fh,RESOURCE_VBI);
+	}
+
+	saa7134_pgtable_free(dev->pci,&fh->pt_cap);
+	saa7134_pgtable_free(dev->pci,&fh->pt_vbi);
+	
+	file->private_data = NULL;
+	kfree(fh);
+	return 0;
+}
+
+static int
+video_mmap(struct file *file, struct vm_area_struct * vma)
+{
+	struct saa7134_fh *fh = file->private_data;
+	
+	return videobuf_mmap_mapper(vma,saa7134_queue(fh));
+}
+
+/* ------------------------------------------------------------------ */
+
+void saa7134_vbi_fmt(struct saa7134_dev *dev, struct v4l2_format *f)
+{
+	struct saa7134_tvnorm *norm = dev->tvnorm;
+
+	f->fmt.vbi.sampling_rate = 6750000 * 4;
+	f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */;
+	f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
+	f->fmt.vbi.offset = 64 * 4;
+	f->fmt.vbi.start[0] = norm->vbi_v_start;
+	f->fmt.vbi.count[0] = norm->vbi_v_stop - norm->vbi_v_start +1;
+	f->fmt.vbi.start[1] = norm->video_v_stop + norm->vbi_v_start +1;
+	f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
+	f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
+
+#if 0
+	if (V4L2_STD_PAL == norm->id) {
+		/* FIXME */
+		f->fmt.vbi.start[0] += 3;
+		f->fmt.vbi.start[1] += 3*2;
+	}
+#endif
+}
+
+int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
+		  struct v4l2_format *f)
+{
+	switch (f->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
+		f->fmt.pix.width        = fh->width;
+		f->fmt.pix.height       = fh->height;
+		f->fmt.pix.field        = fh->cap.field;
+		f->fmt.pix.pixelformat  = fh->fmt->fourcc;
+		f->fmt.pix.bytesperline =
+			(f->fmt.pix.width * fh->fmt->depth) >> 3;
+		f->fmt.pix.sizeimage =
+			f->fmt.pix.height * f->fmt.pix.bytesperline;
+		return 0;
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+		f->fmt.win = fh->win;
+		return 0;
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		saa7134_vbi_fmt(dev,f);
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+int saa7134_try_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
+		    struct v4l2_format *f)
+{
+	int err;
+	
+	switch (f->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+	{
+		struct saa7134_format *fmt;
+		enum v4l2_field field;
+		unsigned int maxw, maxh;
+
+		fmt = format_by_fourcc(f->fmt.pix.pixelformat);
+		if (NULL == fmt)
+			return -EINVAL;
+
+		field = f->fmt.pix.field;
+		maxw  = dev->tvnorm->width;
+		maxh  = dev->tvnorm->height;
+		
+		if (V4L2_FIELD_ANY == field) {
+			field = (f->fmt.pix.height > maxh/2)
+				? V4L2_FIELD_INTERLACED
+				: V4L2_FIELD_BOTTOM;
+		}
+		switch (field) {
+		case V4L2_FIELD_TOP:
+		case V4L2_FIELD_BOTTOM:
+			maxh = maxh / 2;
+			break;
+		case V4L2_FIELD_INTERLACED:
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		f->fmt.pix.field = field;
+		if (f->fmt.pix.width  < 48)
+			f->fmt.pix.width  = 48;
+		if (f->fmt.pix.height < 32)
+			f->fmt.pix.height = 32;
+		if (f->fmt.pix.width > maxw)
+			f->fmt.pix.width = maxw;
+		if (f->fmt.pix.height > maxh)
+			f->fmt.pix.height = maxh;
+		f->fmt.pix.bytesperline =
+			(f->fmt.pix.width * fmt->depth) >> 3;
+		f->fmt.pix.sizeimage =
+			f->fmt.pix.height * f->fmt.pix.bytesperline;
+		
+		return 0;
+	}
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+		err = verify_preview(dev,&f->fmt.win);
+		if (0 != err)
+			return err;
+		return 0;
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		saa7134_vbi_fmt(dev,f);
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+int saa7134_s_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
+		  struct v4l2_format *f)
+{
+	unsigned long flags;
+	int err;
+	
+	switch (f->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		err = saa7134_try_fmt(dev,fh,f);
+		if (0 != err)
+			return err;
+			
+		fh->fmt       = format_by_fourcc(f->fmt.pix.pixelformat);
+		fh->width     = f->fmt.pix.width;
+		fh->height    = f->fmt.pix.height;
+		fh->cap.field = f->fmt.pix.field;
+		return 0;
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+		err = verify_preview(dev,&f->fmt.win);
+		if (0 != err)
+			return err;
+
+		down(&dev->lock);
+		fh->win    = f->fmt.win;
+		fh->nclips = f->fmt.win.clipcount;
+		if (fh->nclips > 8)
+			fh->nclips = 8;
+		if (copy_from_user(fh->clips,f->fmt.win.clips,
+				   sizeof(struct v4l2_clip)*fh->nclips)) {
+			up(&dev->lock);
+			return -EFAULT;
+		}
+
+		if (res_check(fh, RESOURCE_OVERLAY)) {
+			spin_lock_irqsave(&dev->slock,flags);
+			stop_preview(dev,fh);
+			start_preview(dev,fh);
+			spin_unlock_irqrestore(&dev->slock,flags);
+		}
+		up(&dev->lock);
+		return 0;
+		break;
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		saa7134_vbi_fmt(dev,f);
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+int saa7134_common_ioctl(struct saa7134_dev *dev,
+			 unsigned int cmd, void *arg)
+{
+	int err;
+	
+	switch (cmd) {
+	case VIDIOC_QUERYCTRL:
+	{
+		const struct v4l2_queryctrl *ctrl;
+		struct v4l2_queryctrl *c = arg;
+
+		if ((c->id <  V4L2_CID_BASE ||
+		     c->id >= V4L2_CID_LASTP1) &&
+		    (c->id <  V4L2_CID_PRIVATE_BASE ||
+		     c->id >= V4L2_CID_PRIVATE_LASTP1))
+			return -EINVAL;
+		ctrl = ctrl_by_id(c->id);
+		*c = (NULL != ctrl) ? *ctrl : no_ctrl;
+		return 0;
+	}
+	case VIDIOC_G_CTRL:
+		return get_control(dev,arg);
+	case VIDIOC_S_CTRL:
+	{
+		down(&dev->lock);
+		err = set_control(dev,NULL,arg);
+		up(&dev->lock);
+		return err;
+	}
+	/* --- input switching --------------------------------------- */
+	case VIDIOC_ENUMINPUT:
+	{
+		struct v4l2_input *i = arg;
+		unsigned int n;
+
+		n = i->index;
+		if (n >= SAA7134_INPUT_MAX)
+			return -EINVAL;
+		if (NULL == card_in(dev,i->index).name)
+			return -EINVAL;
+		memset(i,0,sizeof(*i));
+		i->index = n;
+		i->type  = V4L2_INPUT_TYPE_CAMERA;
+		strcpy(i->name,card_in(dev,n).name);
+		if (card_in(dev,n).tv)
+			i->type = V4L2_INPUT_TYPE_TUNER;
+		i->audioset = 1;
+		if (n == dev->ctl_input) {
+			int v1 = saa_readb(SAA7134_STATUS_VIDEO1);
+			int v2 = saa_readb(SAA7134_STATUS_VIDEO2);
+
+			if (0 != (v1 & 0x40))
+				i->status |= V4L2_IN_ST_NO_H_LOCK;
+			if (0 != (v2 & 0x40))
+				i->status |= V4L2_IN_ST_NO_SYNC;
+			if (0 != (v2 & 0x0e))
+				i->status |= V4L2_IN_ST_MACROVISION;
+		}
+		for (n = 0; n < TVNORMS; n++)
+			i->std |= tvnorms[n].id;
+		return 0;
+	}
+	case VIDIOC_G_INPUT:
+	{
+		int *i = arg;
+		*i = dev->ctl_input;
+		return 0;
+	}
+	case VIDIOC_S_INPUT:
+	{
+		int *i = arg;
+		
+		if (*i < 0  ||  *i >= SAA7134_INPUT_MAX)
+			return -EINVAL;
+		if (NULL == card_in(dev,*i).name)
+			return -EINVAL;
+		down(&dev->lock);
+		video_mux(dev,*i);
+		up(&dev->lock);
+		return 0;
+	}
+
+	}
+	return 0;
+}
+
+/*
+ * This function is _not_ called directly, but from
+ * video_generic_ioctl (and maybe others).  userspace
+ * copying is done already, arg is a kernel pointer.
+ */
+static int video_do_ioctl(struct inode *inode, struct file *file,
+			  unsigned int cmd, void *arg)
+{
+	struct saa7134_fh *fh = file->private_data;
+	struct saa7134_dev *dev = fh->dev;
+	unsigned long flags;
+	int err;
+
+	if (video_debug > 1)
+		saa7134_print_ioctl(dev->name,cmd);
+	switch (cmd) {
+	case VIDIOC_QUERYCAP:
+	{
+		struct v4l2_capability *cap = arg;
+		
+		memset(cap,0,sizeof(*cap));
+                strcpy(cap->driver, "saa7134");
+		strlcpy(cap->card, saa7134_boards[dev->board].name,
+			sizeof(cap->card));
+		sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
+		cap->version = SAA7134_VERSION_CODE;
+		cap->capabilities =
+			V4L2_CAP_VIDEO_CAPTURE |
+			V4L2_CAP_VIDEO_OVERLAY |
+			V4L2_CAP_VBI_CAPTURE |
+			V4L2_CAP_TUNER |
+			V4L2_CAP_READWRITE | 
+			V4L2_CAP_STREAMING;
+		return 0;
+	}
+
+	/* --- tv standards ------------------------------------------ */
+	case VIDIOC_ENUMSTD:
+	{
+		struct v4l2_standard *e = arg;
+		unsigned int i;
+
+		i = e->index;
+		if (i >= TVNORMS)
+			return -EINVAL;
+		err = v4l2_video_std_construct(e, tvnorms[e->index].id,
+					       tvnorms[e->index].name);
+		e->index = i;
+		if (err < 0)
+			return err;
+		return 0;
+	}
+	case VIDIOC_G_STD:
+	{
+		v4l2_std_id *id = arg;
+
+		*id = dev->tvnorm->id;
+		return 0;
+	}
+	case VIDIOC_S_STD:
+	{
+		v4l2_std_id *id = arg;
+		unsigned int i;
+
+		for(i = 0; i < TVNORMS; i++)
+			if (*id & tvnorms[i].id)
+				break;
+		if (i == TVNORMS)
+			return -EINVAL;
+
+		down(&dev->lock);
+		if (res_check(fh, RESOURCE_OVERLAY)) {
+			spin_lock_irqsave(&dev->slock,flags);
+			stop_preview(dev,fh);
+			set_tvnorm(dev,&tvnorms[i]);
+			start_preview(dev,fh);
+			spin_unlock_irqrestore(&dev->slock,flags);
+		} else 
+			set_tvnorm(dev,&tvnorms[i]);
+		up(&dev->lock);
+		return 0;
+	}
+
+	/* --- tuner ioctls ------------------------------------------ */
+	case VIDIOC_G_TUNER:
+	{
+		struct v4l2_tuner *t = arg;
+		int n;
+
+		if (0 != t->index)
+			return -EINVAL;
+		memset(t,0,sizeof(*t));
+		for (n = 0; n < SAA7134_INPUT_MAX; n++)
+			if (card_in(dev,n).tv)
+				break;
+		if (NULL != card_in(dev,n).name) {
+			strcpy(t->name, "Television");
+			t->capability = V4L2_TUNER_CAP_NORM |
+				V4L2_TUNER_CAP_STEREO |
+				V4L2_TUNER_CAP_LANG1 |
+				V4L2_TUNER_CAP_LANG2;
+			t->rangehigh = 0xffffffffUL;
+			t->rxsubchans = saa7134_tvaudio_getstereo(dev);
+			t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans);
+		}
+		if (0 != (saa_readb(SAA7134_STATUS_VIDEO1) & 0x03))
+			t->signal = 0xffff;
+		return 0;
+	}
+	case VIDIOC_S_TUNER:
+	{
+		struct v4l2_tuner *t = arg;
+		int rx,mode;
+
+		mode = dev->thread.mode;
+		if (UNSET == mode) {
+			rx   = saa7134_tvaudio_getstereo(dev);
+			mode = saa7134_tvaudio_rx2mode(t->rxsubchans);
+		}
+		if (mode != t->audmode) {
+			dev->thread.mode = t->audmode;
+		}
+		return 0;
+	}
+	case VIDIOC_G_FREQUENCY:
+	{
+		struct v4l2_frequency *f = arg;
+
+		memset(f,0,sizeof(*f));
+		f->type = V4L2_TUNER_ANALOG_TV;
+		f->frequency = dev->ctl_freq;
+		return 0;
+	}
+	case VIDIOC_S_FREQUENCY:
+	{
+		struct v4l2_frequency *f = arg;
+
+		if (0 != f->tuner)
+			return -EINVAL;
+		if (V4L2_TUNER_ANALOG_TV != f->type)
+			return -EINVAL;
+		down(&dev->lock);
+		dev->ctl_freq = f->frequency;
+		saa7134_i2c_call_clients(dev,VIDIOCSFREQ,&dev->ctl_freq);
+		saa7134_tvaudio_do_scan(dev);
+		up(&dev->lock);
+		return 0;
+	}
+		
+	/* --- control ioctls ---------------------------------------- */
+	case VIDIOC_ENUMINPUT:
+	case VIDIOC_G_INPUT:
+	case VIDIOC_S_INPUT:
+	case VIDIOC_QUERYCTRL:
+	case VIDIOC_G_CTRL:
+	case VIDIOC_S_CTRL:
+		return saa7134_common_ioctl(dev, cmd, arg);
+
+	case VIDIOC_G_AUDIO:
+	{
+		struct v4l2_audio *a = arg;
+
+		memset(a,0,sizeof(*a));
+		strcpy(a->name,"audio");
+		return 0;
+	}
+	case VIDIOC_S_AUDIO:
+		return 0;
+        case VIDIOC_G_PARM:
+        {
+                struct v4l2_captureparm *parm = arg;
+                memset(parm,0,sizeof(*parm));
+                return 0;
+        }
+
+	/* --- preview ioctls ---------------------------------------- */
+	case VIDIOC_ENUM_FMT:
+	{
+		struct v4l2_fmtdesc *f = arg;
+		enum v4l2_buf_type type;
+		unsigned int index;
+
+		index = f->index;
+		type  = f->type;
+		switch (type) {
+		case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+			if (index >= FORMATS)
+				return -EINVAL;
+			if (f->type == V4L2_BUF_TYPE_VIDEO_OVERLAY &&
+			    formats[index].planar)
+				return -EINVAL;
+			memset(f,0,sizeof(*f));
+			f->index = index;
+			f->type  = type;
+			strlcpy(f->description,formats[index].name,sizeof(f->description));
+			f->pixelformat = formats[index].fourcc;
+			break;
+		case V4L2_BUF_TYPE_VBI_CAPTURE:
+			if (0 != index)
+				return -EINVAL;
+			memset(f,0,sizeof(*f));
+			f->index = index;
+			f->type  = type;
+			f->pixelformat = V4L2_PIX_FMT_GREY;
+			strcpy(f->description,"vbi data");
+			break;
+		default:
+			return -EINVAL;	
+		}
+		return 0;
+	}
+	case VIDIOC_G_FBUF:
+	{
+		struct v4l2_framebuffer *fb = arg;
+
+		*fb = dev->ovbuf;
+		fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
+		return 0;
+	}
+	case VIDIOC_S_FBUF:
+	{
+		struct v4l2_framebuffer *fb = arg;
+		struct saa7134_format *fmt;
+		
+		if(!capable(CAP_SYS_ADMIN) &&
+		   !capable(CAP_SYS_RAWIO))
+			return -EPERM;
+
+		/* check args */
+		fmt = format_by_fourcc(fb->fmt.pixelformat);
+		if (NULL == fmt)
+			return -EINVAL;
+
+		/* ok, accept it */
+		dev->ovbuf = *fb;
+		dev->ovfmt = fmt;
+		if (0 == dev->ovbuf.fmt.bytesperline)
+			dev->ovbuf.fmt.bytesperline =
+				dev->ovbuf.fmt.width*fmt->depth/8;
+		return 0;
+	}
+	case VIDIOC_OVERLAY:
+	{
+		int *on = arg;
+
+		if (*on) {
+			if (!res_get(dev,fh,RESOURCE_OVERLAY))
+				return -EBUSY;
+			spin_lock_irqsave(&dev->slock,flags);
+			start_preview(dev,fh);
+			spin_unlock_irqrestore(&dev->slock,flags);
+		}
+		if (!*on) {
+			if (!res_check(fh, RESOURCE_OVERLAY))
+				return -EINVAL;
+			spin_lock_irqsave(&dev->slock,flags);
+			stop_preview(dev,fh);
+			spin_unlock_irqrestore(&dev->slock,flags);
+			res_free(dev,fh,RESOURCE_OVERLAY);
+		}
+		return 0;
+	}
+
+	/* --- capture ioctls ---------------------------------------- */
+	case VIDIOC_G_FMT:
+	{
+		struct v4l2_format *f = arg;
+		return saa7134_g_fmt(dev,fh,f);
+	}
+	case VIDIOC_S_FMT:
+	{
+		struct v4l2_format *f = arg;
+		return saa7134_s_fmt(dev,fh,f);
+	}
+	case VIDIOC_TRY_FMT:
+	{
+		struct v4l2_format *f = arg;
+		return saa7134_try_fmt(dev,fh,f);
+	}
+	
+	case VIDIOCGMBUF:
+	{
+		struct video_mbuf *mbuf = arg;
+		struct videobuf_queue *q;
+		struct v4l2_requestbuffers req;
+		unsigned int i;
+
+		q = saa7134_queue(fh);
+		memset(&req,0,sizeof(req));
+		req.type   = q->type;
+		req.count  = gbuffers;
+		req.memory = V4L2_MEMORY_MMAP;
+		err = videobuf_reqbufs(file,q,&req);
+		if (err < 0)
+			return err;
+		memset(mbuf,0,sizeof(*mbuf));
+		mbuf->frames = req.count;
+		mbuf->size   = 0;
+		for (i = 0; i < mbuf->frames; i++) {
+			mbuf->offsets[i]  = q->bufs[i]->boff;
+			mbuf->size       += q->bufs[i]->bsize;
+		}
+		return 0;
+	}
+	case VIDIOC_REQBUFS:
+		return videobuf_reqbufs(file,saa7134_queue(fh),arg);
+
+	case VIDIOC_QUERYBUF:
+		return videobuf_querybuf(saa7134_queue(fh),arg);
+
+	case VIDIOC_QBUF:
+		return videobuf_qbuf(file,saa7134_queue(fh),arg);
+
+	case VIDIOC_DQBUF:
+		return videobuf_dqbuf(file,saa7134_queue(fh),arg);
+
+	case VIDIOC_STREAMON:
+	{
+		int res = saa7134_resource(fh);
+
+                if (!res_get(dev,fh,res))
+			return -EBUSY;
+		return videobuf_streamon(file,saa7134_queue(fh));
+	}
+	case VIDIOC_STREAMOFF:
+	{
+		int res = saa7134_resource(fh);
+
+		err = videobuf_streamoff(file,saa7134_queue(fh));
+		if (err < 0)
+			return err;
+		res_free(dev,fh,res);
+		return 0;
+	}
+
+	default:
+		return v4l_compat_translate_ioctl(inode,file,cmd,arg,
+						  video_do_ioctl);
+	}
+	return 0;
+}
+
+static int video_ioctl(struct inode *inode, struct file *file,
+		       unsigned int cmd, unsigned long arg)
+{
+	return video_usercopy(inode, file, cmd, arg, video_do_ioctl);
+}
+
+static int radio_do_ioctl(struct inode *inode, struct file *file,
+			  unsigned int cmd, void *arg)
+{
+	struct saa7134_fh *fh = file->private_data;
+	struct saa7134_dev *dev = fh->dev;
+	
+	if (video_debug > 1)
+		saa7134_print_ioctl(dev->name,cmd);
+	switch (cmd) {
+	case VIDIOC_QUERYCAP:
+	{
+		struct v4l2_capability *cap = arg;
+
+		memset(cap,0,sizeof(*cap));
+                strcpy(cap->driver, "saa7134");
+		strlcpy(cap->card, saa7134_boards[dev->board].name,
+			sizeof(cap->card));
+		sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
+		cap->version = SAA7134_VERSION_CODE;
+		cap->capabilities = V4L2_CAP_TUNER;
+		return 0;
+	}
+	case VIDIOC_G_TUNER:
+	{
+		struct v4l2_tuner *t = arg;
+		struct video_tuner vt;
+
+		if (0 != t->index)
+			return -EINVAL;
+
+		memset(t,0,sizeof(*t));
+		strcpy(t->name, "Radio");
+                t->rangelow  = (int)(65*16);
+                t->rangehigh = (int)(108*16);
+		
+		memset(&vt,0,sizeof(vt));
+		saa7134_i2c_call_clients(dev,VIDIOCGTUNER,&vt);
+		t->signal = vt.signal;
+		return 0;
+	}
+	case VIDIOC_ENUMINPUT:
+	{
+		struct v4l2_input *i = arg;
+		
+		if (i->index != 0)
+			return -EINVAL;
+		strcpy(i->name,"Radio");
+		i->type = V4L2_INPUT_TYPE_TUNER;
+		return 0;
+	}
+	case VIDIOC_G_INPUT:
+	{
+		int *i = arg;
+		*i = 0;
+		return 0;
+	}
+	case VIDIOC_G_AUDIO:
+	{
+		struct v4l2_audio *a = arg;
+
+		memset(a,0,sizeof(*a));
+		strcpy(a->name,"Radio");
+		return 0;
+	}
+	case VIDIOC_G_STD:
+	{
+		v4l2_std_id *id = arg;
+		*id = 0;
+		return 0;
+	}
+	case VIDIOC_S_AUDIO:
+	case VIDIOC_S_TUNER:
+	case VIDIOC_S_INPUT:
+	case VIDIOC_S_STD:
+		return 0;
+
+	case VIDIOC_QUERYCTRL:
+	{
+		const struct v4l2_queryctrl *ctrl;
+		struct v4l2_queryctrl *c = arg;
+
+		if (c->id <  V4L2_CID_BASE ||
+		    c->id >= V4L2_CID_LASTP1)
+			return -EINVAL;
+		if (c->id == V4L2_CID_AUDIO_MUTE) {
+			ctrl = ctrl_by_id(c->id);
+			*c = *ctrl;
+		} else
+			*c = no_ctrl;
+		return 0;
+	}
+
+	case VIDIOC_G_CTRL:
+	case VIDIOC_S_CTRL:
+	case VIDIOC_G_FREQUENCY:
+	case VIDIOC_S_FREQUENCY:
+		return video_do_ioctl(inode,file,cmd,arg);
+		
+	default:
+		return v4l_compat_translate_ioctl(inode,file,cmd,arg,
+						  radio_do_ioctl);
+	}
+	return 0;
+}
+
+static int radio_ioctl(struct inode *inode, struct file *file,
+		       unsigned int cmd, unsigned long arg)
+{
+	return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
+}
+
+static struct file_operations video_fops =
+{
+	.owner	  = THIS_MODULE,
+	.open	  = video_open,
+	.release  = video_release,
+	.read	  = video_read,
+	.poll     = video_poll,
+	.mmap	  = video_mmap,
+	.ioctl	  = video_ioctl,
+	.llseek   = no_llseek,
+};
+
+static struct file_operations radio_fops =
+{
+	.owner	  = THIS_MODULE,
+	.open	  = video_open,
+	.release  = video_release,
+	.ioctl	  = radio_ioctl,
+	.llseek   = no_llseek,
+};
+
+/* ----------------------------------------------------------- */
+/* exported stuff                                              */
+
+struct video_device saa7134_video_template =
+{
+	.name          = "saa7134-video",
+	.type          = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_OVERLAY|
+	                 VID_TYPE_CLIPPING|VID_TYPE_SCALES,
+	.hardware      = 0,
+	.fops          = &video_fops,
+	.minor         = -1,
+};
+
+struct video_device saa7134_vbi_template =
+{
+	.name          = "saa7134-vbi",
+	.type          = VID_TYPE_TUNER|VID_TYPE_TELETEXT,
+	.hardware      = 0,
+	.fops          = &video_fops,
+	.minor         = -1,
+};
+
+struct video_device saa7134_radio_template =
+{
+	.name          = "saa7134-radio",
+	.type          = VID_TYPE_TUNER,
+	.hardware      = 0,
+	.fops          = &radio_fops,
+	.minor         = -1,
+};
+
+int saa7134_video_init1(struct saa7134_dev *dev)
+{
+	/* sanitycheck insmod options */
+	if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME)
+		gbuffers = 2;
+	if (gbufsize < 0 || gbufsize > gbufsize_max)
+		gbufsize = gbufsize_max;
+	gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK;
+
+	/* put some sensible defaults into the data structures ... */
+	dev->ctl_bright     = ctrl_by_id(V4L2_CID_BRIGHTNESS)->default_value;
+	dev->ctl_contrast   = ctrl_by_id(V4L2_CID_CONTRAST)->default_value;
+	dev->ctl_hue        = ctrl_by_id(V4L2_CID_HUE)->default_value;
+	dev->ctl_saturation = ctrl_by_id(V4L2_CID_SATURATION)->default_value;
+	dev->ctl_volume     = ctrl_by_id(V4L2_CID_AUDIO_VOLUME)->default_value;
+
+	dev->ctl_invert     = 0;
+	dev->ctl_mute       = 1;
+	dev->automute       = 0;
+
+        INIT_LIST_HEAD(&dev->video_q.queue);
+	init_timer(&dev->video_q.timeout);
+	dev->video_q.timeout.function = saa7134_buffer_timeout;
+	dev->video_q.timeout.data     = (unsigned long)(&dev->video_q);
+	dev->video_q.dev              = dev;
+
+	if (saa7134_boards[dev->board].video_out) {
+		/* enable video output */
+		int vo = saa7134_boards[dev->board].video_out;
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL0, video_out[vo][0]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL1, video_out[vo][1]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL2, video_out[vo][2]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL3, video_out[vo][3]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL4, video_out[vo][4]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL5, video_out[vo][5]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL6, video_out[vo][6]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL7, video_out[vo][7]);
+		saa_writeb(SAA7134_VIDEO_PORT_CTRL8, video_out[vo][8]);
+	}
+ 
+	return 0;
+}
+
+int saa7134_video_init2(struct saa7134_dev *dev)
+{
+	/* init video hw */
+	set_tvnorm(dev,&tvnorms[0]);
+	video_mux(dev,0);
+	saa7134_tvaudio_setmute(dev);
+	saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
+	return 0;
+}
+
+int saa7134_video_fini(struct saa7134_dev *dev)
+{
+	/* nothing */
+	return 0;
+}
+
+void saa7134_irq_video_intl(struct saa7134_dev *dev)
+{
+	static const char *st[] = {
+		"no signal", "found NTSC", "found PAL", "found SECAM" };
+	int norm;
+
+	norm = saa_readb(SAA7134_STATUS_VIDEO1) & 0x03;
+	dprintk("DCSDT: %s\n",st[norm]);
+	
+	if (0 != norm) {
+		/* wake up tvaudio audio carrier scan thread */
+		saa7134_tvaudio_do_scan(dev);
+	} else {
+		/* no video signal -> mute audio */
+		dev->automute = 1;
+		saa7134_tvaudio_setmute(dev);
+	}
+}
+
+void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status)
+{
+	enum v4l2_field field;
+	
+	spin_lock(&dev->slock);
+	if (dev->video_q.curr) {
+		dev->video_fieldcount++;
+		field = dev->video_q.curr->vb.field;
+		if (V4L2_FIELD_HAS_BOTH(field)) {
+			/* make sure we have seen both fields */
+			if ((status & 0x10) == 0x00) {
+				dev->video_q.curr->top_seen = 1;
+				goto done;
+			}
+			if (!dev->video_q.curr->top_seen)
+				goto done;
+		} else if (field == V4L2_FIELD_TOP) {
+			if ((status & 0x10) != 0x10)
+				goto done;
+		} else if (field == V4L2_FIELD_BOTTOM) {
+			if ((status & 0x10) != 0x00)
+				goto done;
+		}
+		dev->video_q.curr->vb.field_count = dev->video_fieldcount;
+		saa7134_buffer_finish(dev,&dev->video_q,STATE_DONE);
+	}
+	saa7134_buffer_next(dev,&dev->video_q);
+
+ done:
+	spin_unlock(&dev->slock);
+}
+
+/* ----------------------------------------------------------- */
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff -urN video4linux-20031218/scripts/update video4linux-20031218.monstertv.1/scripts/update
--- video4linux-20031218/scripts/update	2003-12-18 20:34:34.000000000 +0900
+++ video4linux-20031218.monstertv.1/scripts/update	2003-12-20 03:01:33.000000000 +0900
@@ -16,6 +16,10 @@
 xrmmod ir-kbd-gpio
 xrmmod ir-kbd-i2c
 xrmmod bttv
+xrmmod tvaudio
+xrmmod saa7134
+xrmmod tuner
+
 
 # cx88
 xrmmod cx8800
@@ -32,16 +36,20 @@
 # common
 v4l2basic
 xinsmod video-buf debug=0
-xinsmod btcx-risc debug=0
+#xinsmod btcx-risc debug=0
 xinsmod ir-common debug=0 repeat=0
 xinsmod tuner     debug=0
 
 # bttv
-xinsmod bttv bttv_debug=0 vbi_debug=0 irq_debug=0 \
+#xinsmod bttv bttv_debug=0 vbi_debug=0 irq_debug=0 \
 	fdsr=0 chroma_agc=1 vbibufs=4 irq_iswitch=0 $btopt
 test -f ir-kbd-i2c.ko  && xinsmod ir-kbd-i2c  debug=0
-test -f ir-kbd-gpio.ko && xinsmod ir-kbd-gpio debug=0
+#test -f ir-kbd-gpio.ko && xinsmod ir-kbd-gpio debug=0
 
 # cx88
-xinsmod cx88xx
-xinsmod cx8800
+#xinsmod cx88xx
+#xinsmod cx8800
+
+#saa7134
+xinsmod saa7134
+xinsmod tvaudio
diff -urN video4linux-20031218/scripts/update~ video4linux-20031218.monstertv.1/scripts/update~
--- video4linux-20031218/scripts/update~	2003-12-18 20:26:41.000000000 +0900
+++ video4linux-20031218.monstertv.1/scripts/update~	2003-12-20 02:46:15.000000000 +0900
@@ -16,6 +16,10 @@
 xrmmod ir-kbd-gpio
 xrmmod ir-kbd-i2c
 xrmmod bttv
+xrmmod tvaudio
+xrmmod saa7134
+xrmmod tuner
+
 
 # cx88
 xrmmod cx8800
@@ -38,10 +42,14 @@
 
 # bttv
 #xinsmod bttv bttv_debug=0 vbi_debug=0 irq_debug=0 \
-#	fdsr=0 chroma_agc=1 vbibufs=4 irq_iswitch=0 $btopt
-#test -f ir-kbd-i2c.ko  && xinsmod ir-kbd-i2c  debug=0
+	fdsr=0 chroma_agc=1 vbibufs=4 irq_iswitch=0 $btopt
+test -f ir-kbd-i2c.ko  && xinsmod ir-kbd-i2c  debug=0
 #test -f ir-kbd-gpio.ko && xinsmod ir-kbd-gpio debug=0
 
 # cx88
-xinsmod cx88xx
-xinsmod cx8800
+#xinsmod cx88xx
+#xinsmod cx8800
+
+#saa7134
+xinsmod saa7134
+xinsmod tvaudio
diff -urN video4linux-20031218/tuner.c video4linux-20031218.monstertv.1/tuner.c
--- video4linux-20031218/tuner.c	2003-12-17 19:32:01.000000000 +0900
+++ video4linux-20031218.monstertv.1/tuner.c	2003-12-20 10:06:43.000000000 +0900
@@ -130,7 +130,7 @@
   
 	unsigned short thresh1;  /*  band switch VHF_LO <=> VHF_HI  */
 	unsigned short thresh2;  /*  band switch VHF_HI <=> UHF     */
-	unsigned char VHF_L;
+        unsigned char VHF_L;
 	unsigned char VHF_H;
 	unsigned char UHF;
 	unsigned char config; 
@@ -242,7 +242,7 @@
 	{ "Philips 1236D ATSC/NTSC daul in",Philips,ATSC,
 	  16*157.25,16*454.00,0xa0,0x90,0x30,0x8e,732},
         { "Philips NTSC MK3 (FM1236MK3 or FM1236/F)", Philips, NTSC,
-          16*160.00,16*442.00,0x01,0x02,0x04,0x8},
+          16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732},
 };
 #define TUNERS ARRAY_SIZE(tuners)
 
@@ -915,6 +915,9 @@
 	case TUNER_PHILIPS_FM1236_MK3:
 		buffer[3] = 0x19;
 		break;
+//	case TUNER_PHILIPS_FM1236_MK3:
+//		buffer[3] = 0xa5; /* If 0x19,Can't tune in Japan :-( */
+//		break;
 	default:
 		buffer[3] = 0xa4;
 		break;
diff -urN video4linux-20031218/tvaudio.c video4linux-20031218.monstertv.1/tvaudio.c
--- video4linux-20031218/tvaudio.c	2003-11-08 00:02:16.000000000 +0900
+++ video4linux-20031218.monstertv.1/tvaudio.c	2003-12-20 02:46:27.000000000 +0900
@@ -7,6 +7,8 @@
  *   Steve VanDeBogart (vandebo@uclink.berkeley.edu)
  *   Greg Alexander (galexand@acm.org)
  *
+ * Add: MSP34x5 20031025 K.Ohta (alpha292@bremen.or.jp)
+ * 
  * This code is placed under the terms of the GNU General Public License
  * 
  * OPTIONS:
@@ -39,15 +41,18 @@
 #endif
 
 #include "tvaudio.h"
+#include "msp34x5.h"
+#define I2C_MSP3445 0x80 
 
 /* ---------------------------------------------------------------------- */
 /* insmod args                                                            */
 
 MODULE_PARM(debug,"i");
+
 static int debug = 0;	/* insmod parameter */
 
 MODULE_DESCRIPTION("device driver for various i2c TV sound decoder / audiomux chips");
-MODULE_AUTHOR("Eric Sandeen, Steve VanDeBogart, Greg Alexander, Gerd Knorr");
+MODULE_AUTHOR("Eric Sandeen, Steve VanDeBogart, Greg Alexander, Gerd Knorr, Ohta Kyuma");
 MODULE_LICENSE("GPL");
 
 #define UNSET    (-1U)
@@ -151,6 +156,7 @@
 	I2C_TDA985x_H >> 1,
 	I2C_TDA9874   >> 1,
 	I2C_PIC16C54  >> 1,
+        I2C_MSP3445   >> 1, /* Okay? */
 	I2C_CLIENT_END };
 static unsigned short normal_i2c_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
 I2C_CLIENT_INSMOD;
@@ -167,8 +173,10 @@
 	unsigned char buffer[2];
 
 	if (-1 == subaddr) {
+#if 0
 		dprintk("%s: chip_write: 0x%x\n",
 			i2c_clientname(&chip->c), val);
+#endif
 		chip->shadow.bytes[1] = val;
 		buffer[0] = val;
 		if (1 != i2c_master_send(&chip->c,buffer,1)) {
@@ -177,8 +185,10 @@
 			return -1;
 		}
 	} else {
+#if 0
 		dprintk("%s: chip_write: reg%d=0x%x\n",
 			i2c_clientname(&chip->c), subaddr, val);
+#endif
 		chip->shadow.bytes[subaddr+1] = val;
 		buffer[0] = subaddr;
 		buffer[1] = val;
@@ -191,6 +201,7 @@
 	return 0;
 }
 
+
 static int chip_write_masked(struct CHIPSTATE *chip, int subaddr, int val, int mask)
 {
 	if (mask != 0) {
@@ -298,11 +309,11 @@
 		dprintk("%s: thread wakeup\n", i2c_clientname(&chip->c));
 		if (chip->done || signal_pending(current))
 			break;
-
+#if 0
 		/* don't do anything for radio or if mode != auto */
 		if (chip->norm == VIDEO_MODE_RADIO || chip->mode != 0)
 			continue;
-		
+#endif		
 		/* have a look what's going on */
 		desc->checkmode(chip);
 		
@@ -1216,6 +1227,313 @@
 	return ((rc & 0x1f) == 0x1f) ? 1 : 0;
 }
 
+/*-----------------------------------------------------------------------
+ * MSP3445G
+ * ----------------------------------------------------------------------*/
+/* MODULE OPTIONS */
+int msp3445  = 1;
+MODULE_PARM(msp3445, "i"); /* MPX MODE See "MSP3445 MPX TYPE" */
+
+/* EIA-J ONLY Now :-( */
+#define MSP3445_DEM 0x10
+#define MSP3445_DFP 0x12
+
+/* MSP3445 MPX TYPE */
+#define MSP3445_EIAJ 1
+
+
+static int msp3445_reset(struct CHIPSTATE *chip)
+{
+   unsigned char reset[3];
+   unsigned char unreset[3];
+   struct i2c_msg msgs[2] = {
+	{ chip->c.addr,0x1000,3,reset},
+        { chip->c.addr,0x1000,3,unreset},
+   };
+
+   reset[0]=0x00;reset[1]=0x80;reset[2]=0x00;
+   unreset[0]=0x00;unreset[1]=0x00;unreset[2]=0x00;
+
+   if(i2c_transfer(chip->c.adapter,&msgs[0],1)!=1) {
+         dprintk("msp34xx: reset failed\n");
+         return -1;
+   }
+   if(i2c_transfer(chip->c.adapter,&msgs[1],1)!=1) {
+         dprintk("msp34xx: unreset failed\n");
+         return -1;
+   }
+
+   dprintk("msp34xx: reset okay\n");
+   return 0;
+}
+
+static int msp3445_read(struct CHIPSTATE *chip,int subaddr,int reg,unsigned char *read)
+{
+   unsigned char write[3];
+   struct i2c_msg msgs[2] = {
+	{ chip->c.addr,0,3,write},
+        { chip->c.addr,I2C_M_RD,2,read},
+   };
+   /* send CMD */
+   write[0]=(unsigned char)((subaddr%256)+1);
+   write[1]=(unsigned char)((reg/256)%256);
+   write[2]=(unsigned char)(reg%256);
+	if (2 != i2c_transfer(chip->c.adapter,msgs,2)) {
+		printk(KERN_WARNING "%s: I/O error (read2)\n",
+		       i2c_clientname(&chip->c));
+		return -1;
+	}
+	dprintk("%s: read: subadr:reg %04x:%04x=0x%02x%02x\n",
+		i2c_clientname(&chip->c),subaddr+1,reg,read[0],read[1]); 
+
+   return 2;
+}
+
+static int msp3445_write(struct CHIPSTATE *chip,int subaddr,int reg,int cmd)
+{
+   unsigned char write[6];
+   int i;
+   /* send CMD */
+   write[0]=I2C_MSP3445>>1;
+   write[1]=(unsigned char)(subaddr%256);
+   write[2]=(unsigned char)((reg/256)%256);
+   write[3]=(unsigned char)(reg%256);
+   write[4]=(unsigned char)((cmd/256)%256);
+   write[5]=(unsigned char)(cmd%256);
+#if 0 /* No Good :-( */
+   if((i=chip_mwrite(chip,6,write))!=6) {
+      msp3445_reset(chip);
+      dprintk("msp34xx: writing : %02x-%02x-%02x%02x-%02x%02x Failed. bytes = %d\n",write[0],write[1],write[2],write[3],write[4],write[5],i);
+      return -1;
+   }
+#else /* Okay... :-( */
+   if((i=i2c_master_send(&chip->c,&(write[1]),5))!=5) {
+      msp3445_reset(chip);
+      dprintk("msp34xx: writing : %02x-%02x-%02x%02x-%02x%02x Failed. bytes = %d\n",write[0],write[1],write[2],write[3],write[4],write[5],i);
+      return -1;
+   }
+   i=i+1;
+#endif
+   dprintk("%s: write: subadr:reg %04x:%04x=%04x\n",
+		i2c_clientname(&chip->c),subaddr,reg,cmd); 
+  return i;
+}
+
+/* Set Volume : right,left <- 65536=0dB */
+static void msp3445_setvolume(struct CHIPSTATE *chip,int left,int right)
+{
+        int vol,val,balance;
+        balance = 0;
+        vol     = (left > right) ? left : right;
+	val     = ((vol * 0x73) / 65536) << 8;
+        if (vol > 0) {
+		balance = ((right-left) * 127) / vol;
+	}
+         
+   	msp3445_write(chip,MSP3445_DFP, 0x0000, val); /* loudspeaker */
+	msp3445_write(chip,MSP3445_DFP, 0x0006, val); /* headphones  */
+	/* scart - on/off only */
+	msp3445_write(chip,MSP3445_DFP, 0x0007, val ? 0x4000 : 0);
+	msp3445_write(chip,MSP3445_DFP, 0x0001, balance << 8);
+}
+static void msp3445_setmode(struct CHIPSTATE *chip,int mode)
+{
+	int src,matrix;
+        switch(msp3445) {
+        /* EIA-J Only :-( */
+	 case MSP3445_EIAJ:
+	   matrix=0x3002;
+	   break;
+	 default:
+	   matrix=0x3002;
+	   break;
+	}
+        /* End EIA-J */
+        msp3445_write(chip,MSP3445_DFP,0x000e,matrix);
+        switch(mode) {
+	 case VIDEO_SOUND_STEREO:
+	   src=0x0120;
+	   break;
+	 case VIDEO_SOUND_LANG1:
+	   src=0x0100;
+	   break;
+	 case VIDEO_SOUND_LANG2:
+	   src=0x0110;
+	   break;
+	 case VIDEO_SOUND_MONO:
+	   src=0x0030;
+	   break;
+	 default:
+	   src=0x0030;
+	   break;
+	}
+        chip->prevmode = mode;
+        dprintk(KERN_DEBUG
+	   "msp34xx: setstereo final source/matrix = 0x%04x\n", src);
+        msp3445_write(chip,MSP3445_DFP, 0x0008,src);
+        msp3445_write(chip,MSP3445_DFP, 0x0009,src);
+        msp3445_write(chip,MSP3445_DFP, 0x000c,src);
+        msp3445_write(chip,MSP3445_DFP, 0x000a,src);
+        msp3445_write(chip,MSP3445_DFP, 0x000b,src);
+        chip->prevmode = mode;
+}
+#define MSP_CARRIER(freq) ((int)((float)(freq/18.432)*(1<<24)))
+
+	        
+static void msp3445_setcarrier(struct CHIPSTATE *chip, int cdo1, int cdo2)
+{
+	msp3445_write(chip,MSP3445_DEM, 0x0093, cdo1 & 0xfff);
+	msp3445_write(chip,MSP3445_DEM, 0x009b, cdo1 >> 12);
+	msp3445_write(chip,MSP3445_DEM, 0x00a3, cdo2 & 0xfff);
+	msp3445_write(chip,MSP3445_DEM, 0x00ab, cdo2 >> 12);
+	msp3445_write(chip,MSP3445_DEM, 0x0056, 0); /*LOAD_REG_1/2*/
+}
+
+
+#define SCART_MASK    0
+#define SCART_IN1     1
+#define SCART_IN2     2
+#define SCART_IN1_DA  3
+#define SCART_IN2_DA  4
+#define SCART_IN3     5
+#define SCART_IN4     6
+#define SCART_MONO    7
+#define SCART_MUTE    8
+
+static int msp3445_scarts[3][9] = {
+  /* MASK    IN1     IN2     IN1_DA  IN2_DA  IN3     IN4     MONO    MUTE   */
+  {  0x0320, 0x0000, 0x0200, -1,     -1,     0x0300, 0x0020, 0x0100, 0x0320 },
+  {  0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },
+  {  0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 },
+};
+
+static void msp3445_setscart(struct CHIPSTATE *chip, int in, int out)
+{
+        int acb=0;
+	if (-1 == msp3445_scarts[out][in])
+		return;
+	acb |=  msp3445_scarts[out][in];
+	msp3445_write(chip,MSP3445_DFP, 0x0013, acb);
+}
+
+
+static void msp3445_setinput(struct CHIPSTATE *chip,int in)
+{
+   /* TUNER ONLY...Temporally :) */
+   switch(in){
+    case AUDIO_TUNER:
+      /* Monster TV */
+      msp3445_setscart(chip,SCART_IN1,0);
+      msp3445_write(chip,MSP3445_DFP,0x000d,0x1900);
+      /* End Monster TV */
+      break;
+    default:
+      msp3445_setscart(chip,SCART_IN1,0);
+      msp3445_write(chip,MSP3445_DFP,0x000d,0x1900);
+      break;
+   }
+}
+
+static int msp3445_initialize(struct CHIPSTATE *chip)
+{
+   int std,demvar,matrix;
+   int cf1,cf2 ; /* CARRIER */
+   unsigned char read[2];
+   int right,left;
+   msp3445_reset(chip);
+   /* EIA-J */
+   switch(msp3445) {
+    case MSP3445_EIAJ:
+      std = 0x0030;
+      demvar = 0x4003;
+      matrix = 0x3002;
+      cf1 = MSP_CARRIER(4.5);
+      cf2 = MSP_CARRIER(4.5);
+      break;
+    default:
+      std = 0x0030;
+      demvar = 0x4003;
+      matrix = 0x3002;
+      cf1 = MSP_CARRIER(4.5);
+      cf2 = MSP_CARRIER(4.5);
+      break;
+   }
+      /* End EIA-J */
+   /* Genelic */
+   right=65536;
+   left=65536;
+   /* End Genelic */
+   msp3445_write(chip,MSP3445_DEM,0x0030,demvar); /* WRITE DEM */
+   msp3445_read(chip,MSP3445_DEM,0x200,read);     /* Read status */
+   msp3445_write(chip,MSP3445_DEM,0x0020,std);    /* WRITE STD */
+   msp3445_write(chip,MSP3445_DFP,0x000e,matrix); /* Write MATRIX */
+   msp3445_setcarrier(chip, cf1, cf2);
+   msp3445_setinput(chip,AUDIO_TUNER);
+   msp3445_setmode(chip,VIDEO_SOUND_STEREO);
+   msp3445_setvolume(chip,right,left);
+
+   return 0;
+}
+
+static int msp3445_getmode(struct CHIPSTATE *chip)
+{
+	unsigned int val;
+        int mode;
+        unsigned char read[2];
+   
+        mode=VIDEO_SOUND_MONO;
+   
+        if(msp3445_read(chip,MSP3445_DEM,0x0200,read)<=0) return -1;
+        val=(unsigned int)(read[0]<<8)+(unsigned int)read[1];
+
+        if(((val & 0x0040)!=0)&&(chip->mode == VIDEO_SOUND_STEREO)) {
+	   mode = VIDEO_SOUND_STEREO;
+	} 
+        if((val & 0x0100)!=0){
+	   if(chip->mode == VIDEO_SOUND_LANG1) {
+	      mode = VIDEO_SOUND_LANG1;
+	   } else {
+	      mode = VIDEO_SOUND_LANG2;
+	   }
+	}
+        dprintk(KERN_DEBUG
+	   "msp34xx: getstereo mode = 0x%04x\n", mode);
+        return mode;
+}
+
+
+static int msp3445_checkit(struct CHIPSTATE *chip)
+{
+   unsigned char rev1[2],rev2[2];
+   char name[32];
+   if(msp3445_read(chip,MSP3445_DFP,0x1e,rev1)<0) return 0;
+   if(msp3445_read(chip,MSP3445_DFP,0x1f,rev2)<0) return 0;
+   sprintf(name,"MSP34%02d%c-%c%d",
+	   rev2[0], rev1[1]+'@', rev1[0]+'@', rev2[1]&0x1f);   
+   dprintk("msp34xx: detected as %s\n",name);
+   return 1;
+}
+
+static void msp3445_checkmode(struct CHIPSTATE *chip)
+{
+	int mode = msp3445_getmode(chip);
+
+	if (mode == chip->prevmode)
+	    return;
+
+	dprintk("%s: thread checkmode\n", i2c_clientname(&chip->c));
+	if ((mode & VIDEO_SOUND_STEREO)!=0)
+		msp3445_setmode(chip,VIDEO_SOUND_STEREO);
+	else if ((mode & VIDEO_SOUND_LANG2)!=0)
+		msp3445_setmode(chip,VIDEO_SOUND_LANG2);
+	else if ((mode & VIDEO_SOUND_LANG1)!=0)
+		msp3445_setmode(chip,VIDEO_SOUND_LANG1);
+	else
+		msp3445_setmode(chip,VIDEO_SOUND_MONO);
+                chip->mode = mode;
+}
+
+
 /* ---------------------------------------------------------------------- */
 /* audio chip descriptions - struct CHIPDESC                              */
 
@@ -1231,6 +1549,7 @@
 int pic16c54 = 1;
 int ta8874z  = 0;  // address clash with tda9840
 
+   
 MODULE_PARM(tda8425,"i");
 MODULE_PARM(tda9840,"i");
 MODULE_PARM(tda9850,"i");
@@ -1421,6 +1740,22 @@
 
 	        .init       = {2, { TA8874Z_MONO_SET, TA8874Z_SEPARATION_DEFAULT}},
 	},
+   	{
+		.name       = "msp3445",
+		.id         = -1,
+	        .insmodopt  = &msp3445,
+		//.id         = I2C_DRIVERID_TA8874Z,
+		.checkit    = msp3445_checkit,
+		.addr_lo    = I2C_MSP3445 >>1,
+		.addr_hi    = I2C_MSP3445 >>1,
+		.registers  = 5,
+                .flags      = 0,
+		.getmode    = msp3445_getmode,
+		.setmode    = msp3445_setmode,
+	        .initialize = msp3445_initialize,
+                .checkmode  = msp3445_checkmode,
+	},
+   
 	{ .name = NULL } /* EOF */
 };
 
@@ -1633,7 +1968,7 @@
 			chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass));
 			chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble));
 		}
-		if (desc->setmode && va->mode) {
+		if ((desc->setmode) != NULL) {
 			chip->watch_stereo = 0;
 			/* del_timer(&chip->wt); */
 			chip->mode = va->mode;
diff -urN video4linux-20031218/tvaudio.h video4linux-20031218.monstertv.1/tvaudio.h
--- video4linux-20031218/tvaudio.h	2003-11-08 00:02:17.000000000 +0900
+++ video4linux-20031218.monstertv.1/tvaudio.h	2003-12-20 02:46:27.000000000 +0900
@@ -12,3 +12,4 @@
 #define I2C_TEA6420	   0x98
 
 #define I2C_PIC16C54       0x96 /* PV951 */
+#define I2C_MSP3445G       0x80 /* Monster TV */       
diff -urN video4linux-20031218/u video4linux-20031218.monstertv.1/u
--- video4linux-20031218/u	2003-12-18 20:34:34.000000000 +0900
+++ video4linux-20031218.monstertv.1/u	2003-12-20 03:01:33.000000000 +0900
@@ -16,6 +16,10 @@
 xrmmod ir-kbd-gpio
 xrmmod ir-kbd-i2c
 xrmmod bttv
+xrmmod tvaudio
+xrmmod saa7134
+xrmmod tuner
+
 
 # cx88
 xrmmod cx8800
@@ -32,16 +36,20 @@
 # common
 v4l2basic
 xinsmod video-buf debug=0
-xinsmod btcx-risc debug=0
+#xinsmod btcx-risc debug=0
 xinsmod ir-common debug=0 repeat=0
 xinsmod tuner     debug=0
 
 # bttv
-xinsmod bttv bttv_debug=0 vbi_debug=0 irq_debug=0 \
+#xinsmod bttv bttv_debug=0 vbi_debug=0 irq_debug=0 \
 	fdsr=0 chroma_agc=1 vbibufs=4 irq_iswitch=0 $btopt
 test -f ir-kbd-i2c.ko  && xinsmod ir-kbd-i2c  debug=0
-test -f ir-kbd-gpio.ko && xinsmod ir-kbd-gpio debug=0
+#test -f ir-kbd-gpio.ko && xinsmod ir-kbd-gpio debug=0
 
 # cx88
-xinsmod cx88xx
-xinsmod cx8800
+#xinsmod cx88xx
+#xinsmod cx8800
+
+#saa7134
+xinsmod saa7134
+xinsmod tvaudio
