V4L/DVB (3916): AverMedia 6 Eyes AVS6EYES support
authorMartin Samuelsson <sam@home.se>
Thu, 27 Apr 2006 13:17:00 +0000 (10:17 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Sun, 25 Jun 2006 04:59:28 +0000 (01:59 -0300)
Add support for the AverMedia 6 Eyes MJPEG card.
- Updated drivers/media/video/Kconfig with AVS6EYES
  options.
- Added CONFIG_VIDEO_ZORAN_AVS6EYES to
  drivers/media/video/Makefile.
- Added I2C_DRIVERID_BT866 and I2C_DRIVERID_KS0127 to
  include/linux/i2c-id.h
- Added drivers/media/video/ks0127.c, imported and modified from
  the Marvel project.
- Added drivers/media/video/ks0127.h, imported and modified from
  the Marvel project.
- Added drivers/media/video/bt866.c, ported from a 2.4 version
  by Christer Weinigel.
- Added AVS6EYES to drivers/media/video/zoran_card.c
- Added input_mux to all cards in drivers/media/video/zoran_card.c
- Added input mux module parameter to drivers/media/video/zoran_card.c
- Added AVS6EYES to card_type in drivers/media/video/zoran.h
- Added input_mux to card_info in drivers/media/video/zoran.h
- Upped BUZ_MAX_INPUT in drivers/media/video/zoran.h from 8 to 16,
  as the AVS6EYES has 10.
- Updated Documentation/video4linux/Zoran with information about AVS6EYES.

Signed-off-by: Martin Samuelsson <sam@home.se>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Documentation/video4linux/Zoran
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/bt866.c [new file with mode: 0644]
drivers/media/video/ks0127.c [new file with mode: 0644]
drivers/media/video/ks0127.h [new file with mode: 0644]
drivers/media/video/zoran.h
drivers/media/video/zoran_card.c
include/linux/i2c-id.h

index be9f21b8455589b6c697b888c1132858bce043ce..040a2c841ae96352365d0048c07744661de7b631 100644 (file)
@@ -33,6 +33,21 @@ Inputs/outputs: Composite and S-video
 Norms: PAL, SECAM (720x576 @ 25 fps), NTSC (720x480 @ 29.97 fps)
 Card number: 7
 
+AverMedia 6 Eyes AVS6EYES:
+* Zoran zr36067 PCI controller
+* Zoran zr36060 MJPEG codec
+* Samsung ks0127 TV decoder
+* Conexant bt866  TV encoder
+Drivers to use: videodev, i2c-core, i2c-algo-bit,
+               videocodec, ks0127, bt866, zr36060, zr36067
+Inputs/outputs: Six physical inputs. 1-6 are composite,
+               1-2, 3-4, 5-6 doubles as S-video,
+               1-3 triples as component.
+               One composite output.
+Norms: PAL, SECAM (720x576 @ 25 fps), NTSC (720x480 @ 29.97 fps)
+Card number: 8
+Not autodetected, card=8 is necessary.
+
 Linux Media Labs LML33:
 * Zoran zr36067 PCI controller
 * Zoran zr36060 MJPEG codec
@@ -192,6 +207,10 @@ Micronas vpx3220a TV decoder
 was introduced in 1996, is used in the DC30 and DC30+ and
 can handle: PAL B/G/H/I, PAL N, PAL M, NTSC M, NTSC 44, PAL 60, SECAM,NTSC Comb
 
+Samsung ks0127 TV decoder
+is used in the AVS6EYES card and
+can handle: NTSC-M/N/44, PAL-M/N/B/G/H/I/D/K/L and SECAM
+
 ===========================
 
 1.2 What the TV encoder can do an what not
@@ -221,6 +240,10 @@ ITT mse3000 TV encoder
 was introduced in 1991, is used in the DC10 old
 can generate: PAL , NTSC , SECAM
 
+Conexant bt866 TV encoder
+is used in AVS6EYES, and
+can generate: NTSC/PAL, PAL­M, PAL­N
+
 The adv717x, should be able to produce PAL N. But you find nothing PAL N
 specific in the registers. Seem that you have to reuse a other standard
 to generate PAL N, maybe it would work if you use the PAL M settings.
index 6b41970185610780327355a0f4d4af6f5a852e8e..515e16acf0dd765fbc9e7aaa4bc483544d45dd83 100644 (file)
@@ -224,6 +224,12 @@ config VIDEO_ZORAN_LML33R10
          support for the Linux Media Labs LML33R10 MJPEG capture/playback
          card.
 
+config VIDEO_ZORAN_AVS6EYES
+       tristate "AverMedia 6 Eyes support (EXPERIMENTAL)"
+       depends on VIDEO_ZORAN && EXPERIMENTAL && VIDEO_V4L1
+       help
+         Support for the AverMedia 6 Eyes video surveillance card.
+
 config VIDEO_ZR36120
        tristate "Zoran ZR36120/36125 Video For Linux"
        depends on PCI && I2C && VIDEO_V4L1 && BROKEN
index e5bf2687b76de83f15508429f327ca0f3d4046df..97e899074436db64f29f67b2770e8db85ffe52a6 100644 (file)
@@ -33,6 +33,7 @@ obj-$(CONFIG_VIDEO_ZORAN_DC30) += adv7175.o vpx3220.o zr36050.o \
        zr36016.o
 obj-$(CONFIG_VIDEO_ZORAN_LML33) += bt819.o bt856.o zr36060.o
 obj-$(CONFIG_VIDEO_ZORAN_LML33R10) += saa7114.o adv7170.o zr36060.o
+obj-$(CONFIG_VIDEO_ZORAN_AVS6EYES) += bt866.o ks0127.o zr36060.o
 obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o
 obj-$(CONFIG_VIDEO_PMS) += pms.o
 obj-$(CONFIG_VIDEO_PLANB) += planb.o
diff --git a/drivers/media/video/bt866.c b/drivers/media/video/bt866.c
new file mode 100644 (file)
index 0000000..05e42bb
--- /dev/null
@@ -0,0 +1,377 @@
+/*
+    bt866 - BT866 Digital Video Encoder (Rockwell Part)
+
+    Copyright (C) 1999 Mike Bernson <mike@mlb.org>
+    Copyright (C) 1998 Dave Perks <dperks@ibm.net>
+
+    Modifications for LML33/DC10plus unified driver
+    Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+
+    This code was modify/ported from the saa7111 driver written
+    by Dave Perks.
+
+    This code was adapted for the bt866 by Christer Weinigel and ported
+    to 2.6 by Martin Samuelsson.
+
+    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/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/kernel.h>
+#include <linux/major.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+#include <linux/pci.h>
+#include <linux/signal.h>
+#include <asm/io.h>
+#include <asm/pgtable.h>
+#include <asm/page.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/i2c.h>
+
+#include <linux/videodev.h>
+#include <asm/uaccess.h>
+
+#include <linux/video_encoder.h>
+
+MODULE_LICENSE("GPL");
+
+#define        BT866_DEVNAME   "bt866"
+#define I2C_BT866      0x88
+
+MODULE_LICENSE("GPL");
+
+#define DEBUG(x)               /* Debug driver */
+
+/* ----------------------------------------------------------------------- */
+
+struct bt866 {
+       struct i2c_client *i2c;
+       int addr;
+       unsigned char reg[128];
+
+       int norm;
+       int enable;
+       int bright;
+       int contrast;
+       int hue;
+       int sat;
+};
+
+static int bt866_write(struct bt866 *dev,
+                       unsigned char subaddr, unsigned char data);
+
+static int bt866_do_command(struct bt866 *encoder,
+                       unsigned int cmd, void *arg)
+{
+       switch (cmd) {
+       case ENCODER_GET_CAPABILITIES:
+       {
+               struct video_encoder_capability *cap = arg;
+
+               DEBUG(printk
+                     (KERN_INFO "%s: get capabilities\n",
+                      encoder->i2c->name));
+
+               cap->flags
+                       = VIDEO_ENCODER_PAL
+                       | VIDEO_ENCODER_NTSC
+                       | VIDEO_ENCODER_CCIR;
+               cap->inputs = 2;
+               cap->outputs = 1;
+       }
+       break;
+
+       case ENCODER_SET_NORM:
+       {
+               int *iarg = arg;
+
+               DEBUG(printk(KERN_INFO "%s: set norm %d\n",
+                            encoder->i2c->name, *iarg));
+
+               switch (*iarg) {
+
+               case VIDEO_MODE_NTSC:
+                       break;
+
+               case VIDEO_MODE_PAL:
+                       break;
+
+               default:
+                       return -EINVAL;
+
+               }
+               encoder->norm = *iarg;
+       }
+       break;
+
+       case ENCODER_SET_INPUT:
+       {
+               int *iarg = arg;
+               static const __u8 init[] = {
+                       0xc8, 0xcc, /* CRSCALE */
+                       0xca, 0x91, /* CBSCALE */
+                       0xcc, 0x24, /* YC16 | OSDNUM */
+                       0xda, 0x00, /*  */
+                       0xdc, 0x24, /* SETMODE | PAL */
+                       0xde, 0x02, /* EACTIVE */
+
+                       /* overlay colors */
+                       0x70, 0xEB, 0x90, 0x80, 0xB0, 0x80, /* white */
+                       0x72, 0xA2, 0x92, 0x8E, 0xB2, 0x2C, /* yellow */
+                       0x74, 0x83, 0x94, 0x2C, 0xB4, 0x9C, /* cyan */
+                       0x76, 0x70, 0x96, 0x3A, 0xB6, 0x48, /* green */
+                       0x78, 0x54, 0x98, 0xC6, 0xB8, 0xB8, /* magenta */
+                       0x7A, 0x41, 0x9A, 0xD4, 0xBA, 0x64, /* red */
+                       0x7C, 0x23, 0x9C, 0x72, 0xBC, 0xD4, /* blue */
+                       0x7E, 0x10, 0x9E, 0x80, 0xBE, 0x80, /* black */
+
+                       0x60, 0xEB, 0x80, 0x80, 0xc0, 0x80, /* white */
+                       0x62, 0xA2, 0x82, 0x8E, 0xc2, 0x2C, /* yellow */
+                       0x64, 0x83, 0x84, 0x2C, 0xc4, 0x9C, /* cyan */
+                       0x66, 0x70, 0x86, 0x3A, 0xc6, 0x48, /* green */
+                       0x68, 0x54, 0x88, 0xC6, 0xc8, 0xB8, /* magenta */
+                       0x6A, 0x41, 0x8A, 0xD4, 0xcA, 0x64, /* red */
+                       0x6C, 0x23, 0x8C, 0x72, 0xcC, 0xD4, /* blue */
+                       0x6E, 0x10, 0x8E, 0x80, 0xcE, 0x80, /* black */
+               };
+               int i;
+               u8 val;
+
+               for (i = 0; i < ARRAY_SIZE(init) / 2; i += 2)
+                       bt866_write(encoder, init[i], init[i+1]);
+
+               val = encoder->reg[0xdc];
+
+               if (*iarg == 0)
+                       val |= 0x40; /* CBSWAP */
+               else
+                       val &= ~0x40; /* !CBSWAP */
+
+               bt866_write(encoder, 0xdc, val);
+
+               val = encoder->reg[0xcc];
+               if (*iarg == 2)
+                       val |= 0x01; /* OSDBAR */
+               else
+                       val &= ~0x01; /* !OSDBAR */
+               bt866_write(encoder, 0xcc, val);
+
+               DEBUG(printk(KERN_INFO "%s: set input %d\n",
+                            encoder->i2c->name, *iarg));
+
+               switch (*iarg) {
+               case 0:
+                       break;
+               case 1:
+                       break;
+               default:
+                       return -EINVAL;
+
+               }
+       }
+       break;
+
+       case ENCODER_SET_OUTPUT:
+       {
+               int *iarg = arg;
+
+               DEBUG(printk(KERN_INFO "%s: set output %d\n",
+                            encoder->i2c->name, *iarg));
+
+               /* not much choice of outputs */
+               if (*iarg != 0)
+                       return -EINVAL;
+       }
+       break;
+
+       case ENCODER_ENABLE_OUTPUT:
+       {
+               int *iarg = arg;
+               encoder->enable = !!*iarg;
+
+               DEBUG(printk
+                     (KERN_INFO "%s: enable output %d\n",
+                      encoder->i2c->name, encoder->enable));
+       }
+       break;
+
+       case 4711:
+       {
+               int *iarg = arg;
+               __u8 val;
+
+               printk("bt866: square = %d\n", *iarg);
+
+               val = encoder->reg[0xdc];
+               if (*iarg)
+                       val |= 1; /* SQUARE */
+               else
+                       val &= ~1; /* !SQUARE */
+               bt866_write(encoder, 0xdc, val);
+               break;
+       }
+
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int bt866_write(struct bt866 *encoder,
+                       unsigned char subaddr, unsigned char data)
+{
+       unsigned char buffer[2];
+       int err;
+
+       buffer[0] = subaddr;
+       buffer[1] = data;
+
+       encoder->reg[subaddr] = data;
+
+       DEBUG(printk
+             ("%s: write 0x%02X = 0x%02X\n",
+              encoder->i2c->name, subaddr, data));
+
+       for (err = 0; err < 3;) {
+               if (i2c_master_send(encoder->i2c, buffer, 2) == 2)
+                       break;
+               err++;
+               printk(KERN_WARNING "%s: I/O error #%d "
+                      "(write 0x%02x/0x%02x)\n",
+                      encoder->i2c->name, err, encoder->addr, subaddr);
+               schedule_timeout_interruptible(HZ/10);
+       }
+       if (err == 3) {
+               printk(KERN_WARNING "%s: giving up\n",
+                      encoder->i2c->name);
+               return -1;
+       }
+
+       return 0;
+}
+
+static int bt866_attach(struct i2c_adapter *adapter);
+static int bt866_detach(struct i2c_client *client);
+static int bt866_command(struct i2c_client *client,
+                        unsigned int cmd, void *arg);
+
+
+/* Addresses to scan */
+static unsigned short normal_i2c[]     = {I2C_BT866>>1, I2C_CLIENT_END};
+static unsigned short probe[2]         = {I2C_CLIENT_END, I2C_CLIENT_END};
+static unsigned short ignore[2]                = {I2C_CLIENT_END, I2C_CLIENT_END};
+
+static struct i2c_client_address_data addr_data = {
+       normal_i2c,
+       probe,
+       ignore,
+};
+
+static struct i2c_driver i2c_driver_bt866 = {
+       .driver.name = BT866_DEVNAME,
+       .id = I2C_DRIVERID_BT866,
+       .attach_adapter = bt866_attach,
+       .detach_client = bt866_detach,
+       .command = bt866_command
+};
+
+
+static struct i2c_client bt866_client_tmpl =
+{
+       .name = "(nil)",
+       .addr = 0,
+       .adapter = NULL,
+       .driver = &i2c_driver_bt866,
+       .usage_count = 0
+};
+
+static int bt866_found_proc(struct i2c_adapter *adapter,
+                           int addr, int kind)
+{
+       struct bt866 *encoder;
+       struct i2c_client *client;
+
+       client = kzalloc(sizeof(*client), GFP_KERNEL);
+       if (client == NULL)
+               return -ENOMEM;
+       memcpy(client, &bt866_client_tmpl, sizeof(*client));
+
+       encoder = kzalloc(sizeof(*encoder), GFP_KERNEL);
+       if (encoder == NULL) {
+               kfree(client);
+               return -ENOMEM;
+       }
+
+       i2c_set_clientdata(client, encoder);
+       client->adapter = adapter;
+       client->addr = addr;
+       sprintf(client->name, "%s-%02x", BT866_DEVNAME, adapter->id);
+
+       encoder->i2c = client;
+       encoder->addr = addr;
+       //encoder->encoder_type = ENCODER_TYPE_UNKNOWN;
+
+       /* initialize */
+
+       i2c_attach_client(client);
+
+       return 0;
+}
+
+static int bt866_attach(struct i2c_adapter *adapter)
+{
+       if (adapter->id == I2C_HW_B_ZR36067)
+               return i2c_probe(adapter, &addr_data, bt866_found_proc);
+       return 0;
+}
+
+static int bt866_detach(struct i2c_client *client)
+{
+       struct bt866 *encoder = i2c_get_clientdata(client);
+
+       i2c_detach_client(client);
+       kfree(encoder);
+       kfree(client);
+
+       return 0;
+}
+
+static int bt866_command(struct i2c_client *client,
+                        unsigned int cmd, void *arg)
+{
+       struct bt866 *encoder = i2c_get_clientdata(client);
+       return bt866_do_command(encoder, cmd, arg);
+}
+
+static int __devinit bt866_init(void)
+{
+       i2c_add_driver(&i2c_driver_bt866);
+       return 0;
+}
+
+static void __devexit bt866_exit(void)
+{
+       i2c_del_driver(&i2c_driver_bt866);
+}
+
+module_init(bt866_init);
+module_exit(bt866_exit);
diff --git a/drivers/media/video/ks0127.c b/drivers/media/video/ks0127.c
new file mode 100644 (file)
index 0000000..3bf7ac4
--- /dev/null
@@ -0,0 +1,846 @@
+/*
+ * Video Capture Driver (Video for Linux 1/2)
+ * for the Matrox Marvel G200,G400 and Rainbow Runner-G series
+ *
+ * This module is an interface to the KS0127 video decoder chip.
+ *
+ * Copyright (C) 1999  Ryan Drake <stiletto@mediaone.net>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ *****************************************************************************
+ *
+ * Modified and extended by
+ *     Mike Bernson <mike@mlb.org>
+ *     Gerard v.d. Horst
+ *     Leon van Stuivenberg <l.vanstuivenberg@chello.nl>
+ *     Gernot Ziegler <gz@lysator.liu.se>
+ *
+ * Version History:
+ * V1.0 Ryan Drake        Initial version by Ryan Drake
+ * V1.1 Gerard v.d. Horst  Added some debugoutput, reset the video-standard
+ */
+
+#ifndef __KERNEL__
+#define __KERNEL__
+#endif
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include "ks0127.h"
+
+#include <linux/i2c.h>
+#include <linux/video_decoder.h>
+
+#define dprintk     if (debug) printk
+
+/* i2c identification */
+#define I2C_KS0127_ADDON   0xD8
+#define I2C_KS0127_ONBOARD 0xDA
+
+#define KS_TYPE_UNKNOWN        0
+#define KS_TYPE_0122S  1
+#define KS_TYPE_0127   2
+#define KS_TYPE_0127B  3
+
+/* ks0127 control registers */
+#define KS_STAT     0x00
+#define KS_CMDA     0x01
+#define KS_CMDB     0x02
+#define KS_CMDC     0x03
+#define KS_CMDD     0x04
+#define KS_HAVB     0x05
+#define KS_HAVE     0x06
+#define KS_HS1B     0x07
+#define KS_HS1E     0x08
+#define KS_HS2B     0x09
+#define KS_HS2E     0x0a
+#define KS_AGC      0x0b
+#define KS_HXTRA    0x0c
+#define KS_CDEM     0x0d
+#define KS_PORTAB   0x0e
+#define KS_LUMA     0x0f
+#define KS_CON      0x10
+#define KS_BRT      0x11
+#define KS_CHROMA   0x12
+#define KS_CHROMB   0x13
+#define KS_DEMOD    0x14
+#define KS_SAT      0x15
+#define KS_HUE      0x16
+#define KS_VERTIA   0x17
+#define KS_VERTIB   0x18
+#define KS_VERTIC   0x19
+#define KS_HSCLL    0x1a
+#define KS_HSCLH    0x1b
+#define KS_VSCLL    0x1c
+#define KS_VSCLH    0x1d
+#define KS_OFMTA    0x1e
+#define KS_OFMTB    0x1f
+#define KS_VBICTL   0x20
+#define KS_CCDAT2   0x21
+#define KS_CCDAT1   0x22
+#define KS_VBIL30   0x23
+#define KS_VBIL74   0x24
+#define KS_VBIL118  0x25
+#define KS_VBIL1512 0x26
+#define KS_TTFRAM   0x27
+#define KS_TESTA    0x28
+#define KS_UVOFFH   0x29
+#define KS_UVOFFL   0x2a
+#define KS_UGAIN    0x2b
+#define KS_VGAIN    0x2c
+#define KS_VAVB     0x2d
+#define KS_VAVE     0x2e
+#define KS_CTRACK   0x2f
+#define KS_POLCTL   0x30
+#define KS_REFCOD   0x31
+#define KS_INVALY   0x32
+#define KS_INVALU   0x33
+#define KS_INVALV   0x34
+#define KS_UNUSEY   0x35
+#define KS_UNUSEU   0x36
+#define KS_UNUSEV   0x37
+#define KS_USRSAV   0x38
+#define KS_USREAV   0x39
+#define KS_SHS1A    0x3a
+#define KS_SHS1B    0x3b
+#define KS_SHS1C    0x3c
+#define KS_CMDE     0x3d
+#define KS_VSDEL    0x3e
+#define KS_CMDF     0x3f
+#define KS_GAMMA0   0x40
+#define KS_GAMMA1   0x41
+#define KS_GAMMA2   0x42
+#define KS_GAMMA3   0x43
+#define KS_GAMMA4   0x44
+#define KS_GAMMA5   0x45
+#define KS_GAMMA6   0x46
+#define KS_GAMMA7   0x47
+#define KS_GAMMA8   0x48
+#define KS_GAMMA9   0x49
+#define KS_GAMMA10  0x4a
+#define KS_GAMMA11  0x4b
+#define KS_GAMMA12  0x4c
+#define KS_GAMMA13  0x4d
+#define KS_GAMMA14  0x4e
+#define KS_GAMMA15  0x4f
+#define KS_GAMMA16  0x50
+#define KS_GAMMA17  0x51
+#define KS_GAMMA18  0x52
+#define KS_GAMMA19  0x53
+#define KS_GAMMA20  0x54
+#define KS_GAMMA21  0x55
+#define KS_GAMMA22  0x56
+#define KS_GAMMA23  0x57
+#define KS_GAMMA24  0x58
+#define KS_GAMMA25  0x59
+#define KS_GAMMA26  0x5a
+#define KS_GAMMA27  0x5b
+#define KS_GAMMA28  0x5c
+#define KS_GAMMA29  0x5d
+#define KS_GAMMA30  0x5e
+#define KS_GAMMA31  0x5f
+#define KS_GAMMAD0  0x60
+#define KS_GAMMAD1  0x61
+#define KS_GAMMAD2  0x62
+#define KS_GAMMAD3  0x63
+#define KS_GAMMAD4  0x64
+#define KS_GAMMAD5  0x65
+#define KS_GAMMAD6  0x66
+#define KS_GAMMAD7  0x67
+#define KS_GAMMAD8  0x68
+#define KS_GAMMAD9  0x69
+#define KS_GAMMAD10 0x6a
+#define KS_GAMMAD11 0x6b
+#define KS_GAMMAD12 0x6c
+#define KS_GAMMAD13 0x6d
+#define KS_GAMMAD14 0x6e
+#define KS_GAMMAD15 0x6f
+#define KS_GAMMAD16 0x70
+#define KS_GAMMAD17 0x71
+#define KS_GAMMAD18 0x72
+#define KS_GAMMAD19 0x73
+#define KS_GAMMAD20 0x74
+#define KS_GAMMAD21 0x75
+#define KS_GAMMAD22 0x76
+#define KS_GAMMAD23 0x77
+#define KS_GAMMAD24 0x78
+#define KS_GAMMAD25 0x79
+#define KS_GAMMAD26 0x7a
+#define KS_GAMMAD27 0x7b
+#define KS_GAMMAD28 0x7c
+#define KS_GAMMAD29 0x7d
+#define KS_GAMMAD30 0x7e
+#define KS_GAMMAD31 0x7f
+
+
+/****************************************************************************
+* mga_dev : represents one ks0127 chip.
+****************************************************************************/
+
+struct adjust {
+       int     contrast;
+       int     bright;
+       int     hue;
+       int     ugain;
+       int     vgain;
+};
+
+struct ks0127 {
+       struct i2c_client *client;
+       unsigned char   addr;
+       int             format_width;
+       int             format_height;
+       int             cap_width;
+       int             cap_height;
+       int             norm;
+       int             ks_type;
+       u8              regs[256];
+};
+
+
+static int debug; /* insmod parameter */
+
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "Debug output");
+MODULE_LICENSE("GPL");
+
+static u8 reg_defaults[64];
+
+
+
+static void init_reg_defaults(void)
+{
+       u8 *table = reg_defaults;
+
+       table[KS_CMDA]     = 0x2c;  /* VSE=0, CCIR 601, autodetect standard */
+       table[KS_CMDB]     = 0x12;  /* VALIGN=0, AGC control and input */
+       table[KS_CMDC]     = 0x00;  /* Test options */
+       /* clock & input select, write 1 to PORTA */
+       table[KS_CMDD]     = 0x01;
+       table[KS_HAVB]     = 0x00;  /* HAV Start Control */
+       table[KS_HAVE]     = 0x00;  /* HAV End Control */
+       table[KS_HS1B]     = 0x10;  /* HS1 Start Control */
+       table[KS_HS1E]     = 0x00;  /* HS1 End Control */
+       table[KS_HS2B]     = 0x00;  /* HS2 Start Control */
+       table[KS_HS2E]     = 0x00;  /* HS2 End Control */
+       table[KS_AGC]      = 0x53;  /* Manual setting for AGC */
+       table[KS_HXTRA]    = 0x00;  /* Extra Bits for HAV and HS1/2 */
+       table[KS_CDEM]     = 0x00;  /* Chroma Demodulation Control */
+       table[KS_PORTAB]   = 0x0f;  /* port B is input, port A output GPPORT */
+       table[KS_LUMA]     = 0x01;  /* Luma control */
+       table[KS_CON]      = 0x00;  /* Contrast Control */
+       table[KS_BRT]      = 0x00;  /* Brightness Control */
+       table[KS_CHROMA]   = 0x2a;  /* Chroma control A */
+       table[KS_CHROMB]   = 0x90;  /* Chroma control B */
+       table[KS_DEMOD]    = 0x00;  /* Chroma Demodulation Control & Status */
+       table[KS_SAT]      = 0x00;  /* Color Saturation Control*/
+       table[KS_HUE]      = 0x00;  /* Hue Control */
+       table[KS_VERTIA]   = 0x00;  /* Vertical Processing Control A */
+       /* Vertical Processing Control B, luma 1 line delayed */
+       table[KS_VERTIB]   = 0x12;
+       table[KS_VERTIC]   = 0x0b;  /* Vertical Processing Control C */
+       table[KS_HSCLL]    = 0x00;  /* Horizontal Scaling Ratio Low */
+       table[KS_HSCLH]    = 0x00;  /* Horizontal Scaling Ratio High */
+       table[KS_VSCLL]    = 0x00;  /* Vertical Scaling Ratio Low */
+       table[KS_VSCLH]    = 0x00;  /* Vertical Scaling Ratio High */
+       /* 16 bit YCbCr 4:2:2 output; I can't make the bt866 like 8 bit /Sam */
+       table[KS_OFMTA]    = 0x30;
+       table[KS_OFMTB]    = 0x00;  /* Output Control B */
+       /* VBI Decoder Control; 4bit fmt: avoid Y overflow */
+       table[KS_VBICTL]   = 0x5d;
+       table[KS_CCDAT2]   = 0x00;  /* Read Only register */
+       table[KS_CCDAT1]   = 0x00;  /* Read Only register */
+       table[KS_VBIL30]   = 0xa8;  /* VBI data decoding options */
+       table[KS_VBIL74]   = 0xaa;  /* VBI data decoding options */
+       table[KS_VBIL118]  = 0x2a;  /* VBI data decoding options */
+       table[KS_VBIL1512] = 0x00;  /* VBI data decoding options */
+       table[KS_TTFRAM]   = 0x00;  /* Teletext frame alignment pattern */
+       table[KS_TESTA]    = 0x00;  /* test register, shouldn't be written */
+       table[KS_UVOFFH]   = 0x00;  /* UV Offset Adjustment High */
+       table[KS_UVOFFL]   = 0x00;  /* UV Offset Adjustment Low */
+       table[KS_UGAIN]    = 0x00;  /* U Component Gain Adjustment */
+       table[KS_VGAIN]    = 0x00;  /* V Component Gain Adjustment */
+       table[KS_VAVB]     = 0x07;  /* VAV Begin */
+       table[KS_VAVE]     = 0x00;  /* VAV End */
+       table[KS_CTRACK]   = 0x00;  /* Chroma Tracking Control */
+       table[KS_POLCTL]   = 0x41;  /* Timing Signal Polarity Control */
+       table[KS_REFCOD]   = 0x80;  /* Reference Code Insertion Control */
+       table[KS_INVALY]   = 0x10;  /* Invalid Y Code */
+       table[KS_INVALU]   = 0x80;  /* Invalid U Code */
+       table[KS_INVALV]   = 0x80;  /* Invalid V Code */
+       table[KS_UNUSEY]   = 0x10;  /* Unused Y Code */
+       table[KS_UNUSEU]   = 0x80;  /* Unused U Code */
+       table[KS_UNUSEV]   = 0x80;  /* Unused V Code */
+       table[KS_USRSAV]   = 0x00;  /* reserved */
+       table[KS_USREAV]   = 0x00;  /* reserved */
+       table[KS_SHS1A]    = 0x00;  /* User Defined SHS1 A */
+       /* User Defined SHS1 B, ALT656=1 on 0127B */
+       table[KS_SHS1B]    = 0x80;
+       table[KS_SHS1C]    = 0x00;  /* User Defined SHS1 C */
+       table[KS_CMDE]     = 0x00;  /* Command Register E */
+       table[KS_VSDEL]    = 0x00;  /* VS Delay Control */
+       /* Command Register F, update -immediately- */
+       /* (there might come no vsync)*/
+       table[KS_CMDF]     = 0x02;
+}
+
+
+/* We need to manually read because of a bug in the KS0127 chip.
+ *
+ * An explanation from kayork@mail.utexas.edu:
+ *
+ * During I2C reads, the KS0127 only samples for a stop condition
+ * during the place where the acknoledge bit should be. Any standard
+ * I2C implementation (correctly) throws in another clock transition
+ * at the 9th bit, and the KS0127 will not recognize the stop condition
+ * and will continue to clock out data.
+ *
+ * So we have to do the read ourself.  Big deal.
+          workaround in i2c-algo-bit
+ */
+
+
+static u8 ks0127_read(struct ks0127 *ks, u8 reg)
+{
+       struct i2c_client *c = ks->client;
+       char val = 0;
+       struct i2c_msg msgs[] = {
+               {c->addr, 0, sizeof(reg), &reg},
+               {c->addr, I2C_M_RD | I2C_M_NO_RD_ACK, sizeof(val), &val}};
+       int ret;
+
+       ret = i2c_transfer(c->adapter, msgs, ARRAY_SIZE(msgs));
+       if (ret != ARRAY_SIZE(msgs))
+               dprintk("ks0127_write error\n");
+
+       return val;
+}
+
+
+static void ks0127_write(struct ks0127 *ks, u8 reg, u8 val)
+{
+       char msg[] = {reg, val};
+
+       if (i2c_master_send(ks->client, msg, sizeof(msg)) != sizeof(msg))
+               dprintk("ks0127_write error\n");
+
+       ks->regs[reg] = val;
+}
+
+
+/* generic bit-twiddling */
+static void ks0127_and_or(struct ks0127 *ks, u8 reg, u8 and_v, u8 or_v)
+{
+       u8 val = ks->regs[reg];
+       val = (val & and_v) | or_v;
+       ks0127_write(ks, reg, val);
+}
+
+
+
+/****************************************************************************
+* ks0127 private api
+****************************************************************************/
+static void ks0127_reset(struct ks0127* ks)
+{
+       int i;
+       u8 *table = reg_defaults;
+
+       ks->ks_type = KS_TYPE_UNKNOWN;
+
+       dprintk("ks0127: reset\n");
+       msleep(1);
+
+       /* initialize all registers to known values */
+       /* (except STAT, 0x21, 0x22, TEST and 0x38,0x39) */
+
+       for(i = 1; i < 33; i++)
+               ks0127_write(ks, i, table[i]);
+
+       for(i = 35; i < 40; i++)
+               ks0127_write(ks, i, table[i]);
+
+       for(i = 41; i < 56; i++)
+               ks0127_write(ks, i, table[i]);
+
+       for(i = 58; i < 64; i++)
+               ks0127_write(ks, i, table[i]);
+
+
+       if ((ks0127_read(ks, KS_STAT) & 0x80) == 0) {
+               ks->ks_type = KS_TYPE_0122S;
+               dprintk("ks0127: ks0122s Found\n");
+               return;
+       }
+
+       switch(ks0127_read(ks, KS_CMDE) & 0x0f) {
+
+       case 0:
+               ks->ks_type = KS_TYPE_0127;
+               dprintk("ks0127: ks0127 found\n");
+               break;
+
+       case 9:
+               ks->ks_type = KS_TYPE_0127B;
+               dprintk("ks0127: ks0127B Revision A found\n");
+               break;
+
+       default:
+               dprintk("ks0127: unknown revision\n");
+               break;
+       }
+}
+
+static int ks0127_command(struct i2c_client *client,
+                         unsigned int cmd, void *arg)
+{
+       struct ks0127 *ks = i2c_get_clientdata(client);
+
+       int             *iarg = (int*)arg;
+
+       int             status;
+
+       if (!ks)
+               return -ENODEV;
+
+       switch (cmd) {
+
+       case DECODER_INIT:
+               dprintk("ks0127: command DECODER_INIT\n");
+               ks0127_reset(ks);
+               break;
+
+       case DECODER_SET_INPUT:
+               switch(*iarg) {
+               case KS_INPUT_COMPOSITE_1:
+               case KS_INPUT_COMPOSITE_2:
+               case KS_INPUT_COMPOSITE_3:
+               case KS_INPUT_COMPOSITE_4:
+               case KS_INPUT_COMPOSITE_5:
+               case KS_INPUT_COMPOSITE_6:
+                       dprintk("ks0127: command DECODER_SET_INPUT %d: "
+                               "Composite\n", *iarg);
+                       /* autodetect 50/60 Hz */
+                       ks0127_and_or(ks, KS_CMDA,   0xfc, 0x00);
+                       /* VSE=0 */
+                       ks0127_and_or(ks, KS_CMDA,   ~0x40, 0x00);
+                       /* set input line */
+                       ks0127_and_or(ks, KS_CMDB,   0xb0, *iarg);
+                       /* non-freerunning mode */
+                       ks0127_and_or(ks, KS_CMDC,   0x70, 0x0a);
+                       /* analog input */
+                       ks0127_and_or(ks, KS_CMDD,   0x03, 0x00);
+                       /* enable chroma demodulation */
+                       ks0127_and_or(ks, KS_CTRACK, 0xcf, 0x00);
+                       /* chroma trap, HYBWR=1 */
+                       ks0127_and_or(ks, KS_LUMA,   0x00,
+                                      (reg_defaults[KS_LUMA])|0x0c);
+                       /* scaler fullbw, luma comb off */
+                       ks0127_and_or(ks, KS_VERTIA, 0x08, 0x81);
+                       /* manual chroma comb .25 .5 .25 */
+                       ks0127_and_or(ks, KS_VERTIC, 0x0f, 0x90);
+
+                       /* chroma path delay */
+                       ks0127_and_or(ks, KS_CHROMB, 0x0f, 0x90);
+
+                       ks0127_write(ks, KS_UGAIN, reg_defaults[KS_UGAIN]);
+                       ks0127_write(ks, KS_VGAIN, reg_defaults[KS_VGAIN]);
+                       ks0127_write(ks, KS_UVOFFH, reg_defaults[KS_UVOFFH]);
+                       ks0127_write(ks, KS_UVOFFL, reg_defaults[KS_UVOFFL]);
+                       break;
+
+               case KS_INPUT_SVIDEO_1:
+               case KS_INPUT_SVIDEO_2:
+               case KS_INPUT_SVIDEO_3:
+                       dprintk("ks0127: command DECODER_SET_INPUT %d: "
+                               "S-Video\n", *iarg);
+                       /* autodetect 50/60 Hz */
+                       ks0127_and_or(ks, KS_CMDA,   0xfc, 0x00);
+                       /* VSE=0 */
+                       ks0127_and_or(ks, KS_CMDA,   ~0x40, 0x00);
+                       /* set input line */
+                       ks0127_and_or(ks, KS_CMDB,   0xb0, *iarg);
+                       /* non-freerunning mode */
+                       ks0127_and_or(ks, KS_CMDC,   0x70, 0x0a);
+                       /* analog input */
+                       ks0127_and_or(ks, KS_CMDD,   0x03, 0x00);
+                       /* enable chroma demodulation */
+                       ks0127_and_or(ks, KS_CTRACK, 0xcf, 0x00);
+                       ks0127_and_or(ks, KS_LUMA, 0x00,
+                                      reg_defaults[KS_LUMA]);
+                       /* disable luma comb */
+                       ks0127_and_or(ks, KS_VERTIA, 0x08,
+                                      (reg_defaults[KS_VERTIA]&0xf0)|0x01);
+                       ks0127_and_or(ks, KS_VERTIC, 0x0f,
+                                      reg_defaults[KS_VERTIC]&0xf0);
+
+                       ks0127_and_or(ks, KS_CHROMB, 0x0f,
+                                      reg_defaults[KS_CHROMB]&0xf0);
+
+                       ks0127_write(ks, KS_UGAIN, reg_defaults[KS_UGAIN]);
+                       ks0127_write(ks, KS_VGAIN, reg_defaults[KS_VGAIN]);
+                       ks0127_write(ks, KS_UVOFFH, reg_defaults[KS_UVOFFH]);
+                       ks0127_write(ks, KS_UVOFFL, reg_defaults[KS_UVOFFL]);
+                       break;
+
+               case KS_INPUT_YUV656:
+                       dprintk("ks0127: command DECODER_SET_INPUT 15: "
+                               "YUV656\n");
+                       if (ks->norm == VIDEO_MODE_NTSC ||
+                           ks->norm == KS_STD_PAL_M)
+                               /* force 60 Hz */
+                               ks0127_and_or(ks, KS_CMDA,   0xfc, 0x03);
+                       else
+                               /* force 50 Hz */
+                               ks0127_and_or(ks, KS_CMDA,   0xfc, 0x02);
+
+                       ks0127_and_or(ks, KS_CMDA,   0xff, 0x40); /* VSE=1 */
+                       /* set input line and VALIGN */
+                       ks0127_and_or(ks, KS_CMDB,   0xb0, (*iarg | 0x40));
+                       /* freerunning mode, */
+                       /* TSTGEN = 1 TSTGFR=11 TSTGPH=0 TSTGPK=0  VMEM=1*/
+                       ks0127_and_or(ks, KS_CMDC,   0x70, 0x87);
+                       /* digital input, SYNDIR = 0 INPSL=01 CLKDIR=0 EAV=0 */
+                       ks0127_and_or(ks, KS_CMDD,   0x03, 0x08);
+                       /* disable chroma demodulation */
+                       ks0127_and_or(ks, KS_CTRACK, 0xcf, 0x30);
+                       /* HYPK =01 CTRAP = 0 HYBWR=0 PED=1 RGBH=1 UNIT=1 */
+                       ks0127_and_or(ks, KS_LUMA,   0x00, 0x71);
+                       ks0127_and_or(ks, KS_VERTIC, 0x0f,
+                                      reg_defaults[KS_VERTIC]&0xf0);
+
+                       /* scaler fullbw, luma comb off */
+                       ks0127_and_or(ks, KS_VERTIA, 0x08, 0x81);
+
+                       ks0127_and_or(ks, KS_CHROMB, 0x0f,
+                                      reg_defaults[KS_CHROMB]&0xf0);
+
+                       ks0127_and_or(ks, KS_CON, 0x00, 0x00);
+                       ks0127_and_or(ks, KS_BRT, 0x00, 32);    /* spec: 34 */
+                               /* spec: 229 (e5) */
+                       ks0127_and_or(ks, KS_SAT, 0x00, 0xe8);
+                       ks0127_and_or(ks, KS_HUE, 0x00, 0);
+
+                       ks0127_and_or(ks, KS_UGAIN, 0x00, 238);
+                       ks0127_and_or(ks, KS_VGAIN, 0x00, 0x00);
+
+                       /*UOFF:0x30, VOFF:0x30, TSTCGN=1 */
+                       ks0127_and_or(ks, KS_UVOFFH, 0x00, 0x4f);
+                       ks0127_and_or(ks, KS_UVOFFL, 0x00, 0x00);
+                       break;
+
+               default:
+                       dprintk("ks0127: command DECODER_SET_INPUT: "
+                               "Unknown input %d\n", *iarg);
+                       break;
+               }
+
+               /* hack: CDMLPF sometimes spontaneously switches on; */
+               /* force back off */
+               ks0127_write(ks, KS_DEMOD, reg_defaults[KS_DEMOD]);
+               break;
+
+       case DECODER_SET_OUTPUT:
+               switch(*iarg) {
+               case KS_OUTPUT_YUV656E:
+                       dprintk("ks0127: command DECODER_SET_OUTPUT: "
+                               "OUTPUT_YUV656E (Missing)\n");
+                       return -EINVAL;
+                       break;
+
+               case KS_OUTPUT_EXV:
+                       dprintk("ks0127: command DECODER_SET_OUTPUT: "
+                               "OUTPUT_EXV\n");
+                       ks0127_and_or(ks, KS_OFMTA, 0xf0, 0x09);
+                       break;
+               }
+               break;
+
+       case DECODER_SET_NORM: //sam This block mixes old and new norm names...
+               /* Set to automatic SECAM/Fsc mode */
+               ks0127_and_or(ks, KS_DEMOD, 0xf0, 0x00);
+
+               ks->norm = *iarg;
+               switch(*iarg)
+               {
+               /* this is untested !! */
+               /* It just detects PAL_N/NTSC_M (no special frequencies) */
+               /* And you have to set the standard a second time afterwards */
+               case VIDEO_MODE_AUTO:
+                       dprintk("ks0127: command DECODER_SET_NORM: AUTO\n");
+
+                       /* The chip determines the format */
+                       /* based on the current field rate */
+                       ks0127_and_or(ks, KS_CMDA,   0xfc, 0x00);
+                       ks0127_and_or(ks, KS_CHROMA, 0x9f, 0x20);
+                       /* This is wrong for PAL ! As I said, */
+                       /* you need to set the standard once again !! */
+                       ks->format_height = 240;
+                       ks->format_width = 704;
+                       break;
+
+               case VIDEO_MODE_NTSC:
+                       dprintk("ks0127: command DECODER_SET_NORM: NTSC_M\n");
+                       ks0127_and_or(ks, KS_CHROMA, 0x9f, 0x20);
+                       ks->format_height = 240;
+                       ks->format_width = 704;
+                       break;
+
+               case KS_STD_NTSC_N:
+                       dprintk("ks0127: command KS0127_SET_STANDARD: "
+                               "NTSC_N (fixme)\n");
+                       ks0127_and_or(ks, KS_CHROMA, 0x9f, 0x40);
+                       ks->format_height = 240;
+                       ks->format_width = 704;
+                       break;
+
+               case VIDEO_MODE_PAL:
+                       dprintk("ks0127: command DECODER_SET_NORM: PAL_N\n");
+                       ks0127_and_or(ks, KS_CHROMA, 0x9f, 0x20);
+                       ks->format_height = 290;
+                       ks->format_width = 704;
+                       break;
+
+               case KS_STD_PAL_M:
+                       dprintk("ks0127: command KS0127_SET_STANDARD: "
+                               "PAL_M (fixme)\n");
+                       ks0127_and_or(ks, KS_CHROMA, 0x9f, 0x40);
+                       ks->format_height = 290;
+                       ks->format_width = 704;
+                       break;
+
+               case VIDEO_MODE_SECAM:
+                       dprintk("ks0127: command KS0127_SET_STANDARD: "
+                               "SECAM\n");
+                       ks->format_height = 290;
+                       ks->format_width = 704;
+
+                       /* set to secam autodetection */
+                       ks0127_and_or(ks, KS_CHROMA, 0xdf, 0x20);
+                       ks0127_and_or(ks, KS_DEMOD, 0xf0, 0x00);
+                       schedule_timeout_interruptible(HZ/10+1);
+
+                       /* did it autodetect? */
+                       if (ks0127_read(ks, KS_DEMOD) & 0x40)
+                               break;
+
+                       /* force to secam mode */
+                       ks0127_and_or(ks, KS_DEMOD, 0xf0, 0x0f);
+                       break;
+
+               default:
+                       dprintk("ks0127: command DECODER_SET_NORM: "
+                               "Unknown norm %d\n", *iarg);
+                       break;
+               }
+               break;
+
+       case DECODER_SET_PICTURE:
+               dprintk("ks0127: command DECODER_SET_PICTURE "
+                       "not yet supported (fixme)\n");
+               return -EINVAL;
+
+       //sam todo: KS0127_SET_BRIGHTNESS: Merge into DECODER_SET_PICTURE
+       //sam todo: KS0127_SET_CONTRAST: Merge into DECODER_SET_PICTURE
+       //sam todo: KS0127_SET_HUE: Merge into DECODER_SET_PICTURE?
+       //sam todo: KS0127_SET_SATURATION: Merge into DECODER_SET_PICTURE
+       //sam todo: KS0127_SET_AGC_MODE:
+       //sam todo: KS0127_SET_AGC:
+       //sam todo: KS0127_SET_CHROMA_MODE:
+       //sam todo: KS0127_SET_PIXCLK_MODE:
+       //sam todo: KS0127_SET_GAMMA_MODE:
+       //sam todo: KS0127_SET_UGAIN:
+       //sam todo: KS0127_SET_VGAIN:
+       //sam todo: KS0127_SET_INVALY:
+       //sam todo: KS0127_SET_INVALU:
+       //sam todo: KS0127_SET_INVALV:
+       //sam todo: KS0127_SET_UNUSEY:
+       //sam todo: KS0127_SET_UNUSEU:
+       //sam todo: KS0127_SET_UNUSEV:
+       //sam todo: KS0127_SET_VSALIGN_MODE:
+
+       case DECODER_ENABLE_OUTPUT:
+       {
+
+               int *iarg = arg;
+               int enable = (*iarg != 0);
+                       if (enable) {
+                               dprintk("ks0127: command "
+                                       "DECODER_ENABLE_OUTPUT on "
+                                       "(%d)\n", enable);
+                               /* All output pins on */
+                               ks0127_and_or(ks, KS_OFMTA, 0xcf, 0x30);
+                               /* Obey the OEN pin */
+                               ks0127_and_or(ks, KS_CDEM, 0x7f, 0x00);
+                       } else {
+                               dprintk("ks0127: command "
+                                       "DECODER_ENABLE_OUTPUT off "
+                                       "(%d)\n", enable);
+                               /* Video output pins off */
+                               ks0127_and_or(ks, KS_OFMTA, 0xcf, 0x00);
+                               /* Ignore the OEN pin */
+                               ks0127_and_or(ks, KS_CDEM, 0x7f, 0x80);
+                       }
+       }
+               break;
+
+       //sam todo: KS0127_SET_OUTPUT_MODE:
+       //sam todo: KS0127_SET_WIDTH:
+       //sam todo: KS0127_SET_HEIGHT:
+       //sam todo: KS0127_SET_HSCALE:
+
+       case DECODER_GET_STATUS:
+               dprintk("ks0127: command DECODER_GET_STATUS\n");
+               *iarg = 0;
+               status = ks0127_read(ks, KS_STAT);
+               if (!(status & 0x20))            /* NOVID not set */
+                       *iarg = (*iarg & DECODER_STATUS_GOOD);
+               if ((status & 0x01))                  /* CLOCK set */
+                       *iarg = (*iarg & DECODER_STATUS_COLOR);
+               if ((status & 0x08))               /* PALDET set */
+                       *iarg = (*iarg & DECODER_STATUS_PAL);
+               else
+                       *iarg = (*iarg & DECODER_STATUS_NTSC);
+               break;
+
+       //Catch any unknown command
+       default:
+               dprintk("ks0127: command unknown: %04X\n", cmd);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+
+
+
+static int ks0127_probe(struct i2c_adapter *adapter);
+static int ks0127_detach(struct i2c_client *client);
+static int ks0127_command(struct i2c_client *client,
+                         unsigned int cmd, void *arg);
+
+
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = {I2C_KS0127_ADDON>>1,
+                                      I2C_KS0127_ONBOARD>>1, I2C_CLIENT_END};
+static unsigned short probe[2] =       {I2C_CLIENT_END, I2C_CLIENT_END};
+static unsigned short ignore[2] =      {I2C_CLIENT_END, I2C_CLIENT_END};
+static struct i2c_client_address_data addr_data = {
+       normal_i2c,
+       probe,
+       ignore,
+};
+
+static struct i2c_driver i2c_driver_ks0127 = {
+       .driver.name = "ks0127",
+       .id             = I2C_DRIVERID_KS0127,
+       .attach_adapter = ks0127_probe,
+       .detach_client  = ks0127_detach,
+       .command        = ks0127_command
+};
+
+static struct i2c_client ks0127_client_tmpl =
+{
+       .name = "(ks0127 unset)",
+       .addr = 0,
+       .adapter = NULL,
+       .driver = &i2c_driver_ks0127,
+       .usage_count = 0
+};
+
+static int ks0127_found_proc(struct i2c_adapter *adapter, int addr, int kind)
+{
+       struct ks0127 *ks;
+       struct i2c_client *client;
+
+       client = kzalloc(sizeof(*client), GFP_KERNEL);
+       if (client == NULL)
+               return -ENOMEM;
+       memcpy(client, &ks0127_client_tmpl, sizeof(*client));
+
+       ks = kzalloc(sizeof(*ks), GFP_KERNEL);
+       if (ks == NULL) {
+               kfree(client);
+               return -ENOMEM;
+       }
+
+       i2c_set_clientdata(client, ks);
+       client->adapter = adapter;
+       client->addr = addr;
+       sprintf(client->name, "ks0127-%02x", adapter->id);
+
+       ks->client = client;
+       ks->addr = addr;
+       ks->ks_type = KS_TYPE_UNKNOWN;
+
+       /* power up */
+       ks0127_write(ks, KS_CMDA, 0x2c);
+       mdelay(10);
+
+       /* reset the device */
+       ks0127_reset(ks);
+       printk(KERN_INFO "ks0127: attach: %s video decoder\n",
+              ks->addr==(I2C_KS0127_ADDON>>1) ? "addon" : "on-board");
+
+       i2c_attach_client(client);
+       return 0;
+}
+
+
+static int ks0127_probe(struct i2c_adapter *adapter)
+{
+       if (adapter->id == I2C_HW_B_ZR36067)
+               return i2c_probe(adapter, &addr_data, ks0127_found_proc);
+       return 0;
+}
+
+static int ks0127_detach(struct i2c_client *client)
+{
+       struct ks0127 *ks = i2c_get_clientdata(client);
+
+       ks0127_write(ks, KS_OFMTA, 0x20); /*tristate*/
+       ks0127_write(ks, KS_CMDA, 0x2c | 0x80); /* power down */
+
+       i2c_detach_client(client);
+       kfree(ks);
+       kfree(client);
+
+       dprintk("ks0127: detach\n");
+       return 0;
+}
+
+
+static int __devinit ks0127_init_module(void)
+{
+       init_reg_defaults();
+       i2c_add_driver(&i2c_driver_ks0127);
+       return 0;
+}
+
+static void __devexit ks0127_cleanup_module(void)
+{
+       i2c_del_driver(&i2c_driver_ks0127);
+}
+
+
+module_init(ks0127_init_module);
+module_exit(ks0127_cleanup_module);
diff --git a/drivers/media/video/ks0127.h b/drivers/media/video/ks0127.h
new file mode 100644 (file)
index 0000000..1ec5788
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Video Capture Driver ( Video for Linux 1/2 )
+ * for the Matrox Marvel G200,G400 and Rainbow Runner-G series
+ *
+ * This module is an interface to the KS0127 video decoder chip.
+ *
+ * Copyright (C) 1999  Ryan Drake <stiletto@mediaone.net>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef KS0127_H
+#define KS0127_H
+
+#include <linux/videodev.h>
+
+/* input channels */
+#define KS_INPUT_COMPOSITE_1    0
+#define KS_INPUT_COMPOSITE_2    1
+#define KS_INPUT_COMPOSITE_3    2
+#define KS_INPUT_COMPOSITE_4    4
+#define KS_INPUT_COMPOSITE_5    5
+#define KS_INPUT_COMPOSITE_6    6
+
+#define KS_INPUT_SVIDEO_1       8
+#define KS_INPUT_SVIDEO_2       9
+#define KS_INPUT_SVIDEO_3       10
+
+#define KS_INPUT_YUV656                15
+#define KS_INPUT_COUNT          10
+
+/* output channels */
+#define KS_OUTPUT_YUV656E       0
+#define KS_OUTPUT_EXV           1
+
+/* video standards */
+#define KS_STD_NTSC_N           112       /* 50 Hz NTSC */
+#define KS_STD_PAL_M            113       /* 60 Hz PAL  */
+
+#endif /* KS0127_H */
+
index 0166f555a5ca1b37c5399d85b95137dd0c1705ed..ffcda95ed9d4720eba3dcfb16f1e6a473cd29e86 100644 (file)
@@ -159,7 +159,7 @@ Private IOCTL to set up for displaying MJPEG
 #define BUZ_MAX_FRAME     256  /* Must be a power of 2 */
 #define BUZ_MASK_FRAME    255  /* Must be BUZ_MAX_FRAME-1 */
 
-#define BUZ_MAX_INPUT       8
+#define BUZ_MAX_INPUT       16
 
 #if VIDEO_MAX_FRAME <= 32
 #   define   V4L_MAX_FRAME   32
@@ -191,6 +191,9 @@ enum card_type {
        /* Iomega */
        BUZ,
 
+       /* AverMedia */
+       AVS6EYES,
+
        /* total number of cards */
        NUM_CARDS
 };
@@ -379,6 +382,9 @@ struct card_info {
        /* is the /GWS line conected? */
        u8 gws_not_connected;
 
+       /* avs6eyes mux setting */
+       u8 input_mux;
+
        void (*init) (struct zoran * zr);
 };
 
index 0a85c9e7fb4824803abdf0801268bfbb9ac695bd..798138599bec8964cc2b499fa05724fd06e50aac 100644 (file)
@@ -27,6 +27,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <linux/delay.h>
+
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -93,6 +95,11 @@ module_param(default_input, int, 0);
 MODULE_PARM_DESC(default_input,
                 "Default input (0=Composite, 1=S-Video, 2=Internal)");
 
+static int default_mux = 1;    /* 6 Eyes input selection */
+module_param(default_mux, int, 0);
+MODULE_PARM_DESC(default_mux,
+                "Default 6 Eyes mux setting (Input selection)");
+
 static int default_norm = 0;   /* 0=PAL, 1=NTSC 2=SECAM */
 module_param(default_norm, int, 0);
 MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
@@ -301,6 +308,30 @@ lml33_init (struct zoran *zr)
        GPIO(zr, 2, 1);         // Set Composite input/output
 }
 
+static void
+avs6eyes_init (struct zoran *zr)
+{
+       // AverMedia 6-Eyes original driver by Christer Weinigel
+
+       // Lifted straight from Christer's old driver and
+       // modified slightly by Martin Samuelsson.
+
+       int mux = default_mux; /* 1 = BT866, 7 = VID1 */
+
+       GPIO(zr, 4, 1); /* Bt866 SLEEP on */
+       udelay(2);
+
+       GPIO(zr, 0, 1); /* ZR36060 /RESET on */
+       GPIO(zr, 1, 0); /* ZR36060 /SLEEP on */
+       GPIO(zr, 2, mux & 1);   /* MUX S0 */
+       GPIO(zr, 3, 0); /* /FRAME on */
+       GPIO(zr, 4, 0); /* Bt866 SLEEP off */
+       GPIO(zr, 5, mux & 2);   /* MUX S1 */
+       GPIO(zr, 6, 0); /* ? */
+       GPIO(zr, 7, mux & 4);   /* MUX S2 */
+
+}
+
 static char *
 i2cid_to_modulename (u16 i2c_id)
 {
@@ -391,6 +422,14 @@ static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
 static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
 static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
 
+/* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
+ * copy Maxim's left shift hack for the 6 Eyes.
+ *
+ * Christer's driver used the unshifted norms, though...
+ * /Sam  */
+static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
+static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
+
 static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
        {
                .type = DC10_old,
@@ -419,6 +458,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 0 },
                .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10_init,
        }, {
                .type = DC10_new,
@@ -445,6 +485,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 1},
                .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10plus_init,
        }, {
                .type = DC10plus,
@@ -474,6 +515,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 1 },
                .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10plus_init,
        }, {
                .type = DC30,
@@ -502,6 +544,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 0 },
                .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10_init,
        }, {
                .type = DC30plus,
@@ -532,6 +575,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { -1, 0 },
                .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
                .gws_not_connected = 0,
+               .input_mux = 0,
                .init = &dc10_init,
        }, {
                .type = LML33,
@@ -558,6 +602,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { 3, 1 },
                .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
                .gws_not_connected = 1,
+               .input_mux = 0,
                .init = &lml33_init,
        }, {
                .type = LML33R10,
@@ -586,6 +631,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { 3, 1 },
                .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
                .gws_not_connected = 1,
+               .input_mux = 0,
                .init = &lml33_init,
        }, {
                .type = BUZ,
@@ -614,8 +660,49 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
                .gpcs = { 3, 1 },
                .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
                .gws_not_connected = 1,
+               .input_mux = 0,
                .init = &buz_init,
+       }, {
+               .type = AVS6EYES,
+               .name = "6-Eyes",
+               /* AverMedia chose not to brand the 6-Eyes. Thus it
+                  can't be autodetected, and requires card=x. */
+               .vendor_id = -1,
+               .device_id = -1,
+               .i2c_decoder = I2C_DRIVERID_KS0127,
+               .i2c_encoder = I2C_DRIVERID_BT866,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 10,
+               .input = {
+                       { 0, "Composite 1" },
+                       { 1, "Composite 2" },
+                       { 2, "Composite 3" },
+                       { 4, "Composite 4" },
+                       { 5, "Composite 5" },
+                       { 6, "Composite 6" },
+                       { 8, "S-Video 1" },
+                       { 9, "S-Video 2" },
+                       {10, "S-Video 3" },
+                       {15, "YCbCr" }
+               },
+               .norms = 2,
+               .tvn = {
+                       &f50ccir601_avs6eyes,
+                       &f60ccir601_avs6eyes,
+                       NULL
+               },
+               .jpeg_int = ZR36057_ISR_GIRQ1,
+               .vsync_int = ZR36057_ISR_GIRQ0,
+               .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
+               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
+               .gpcs = { 3, 1 },                       // Validity unknown /Sam
+               .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 },  // Validity unknown /Sam
+               .gws_not_connected = 1,
+               .input_mux = 1,
+               .init = &avs6eyes_init,
        }
+
 };
 
 /*
index c8b81f419fd8e49aa6f42d6994204ab96884c4c5..748bbf7c327c697d4a75ddedad5ad2a4a54867b3 100644 (file)
 #define I2C_DRIVERID_X1205     82      /* Xicor/Intersil X1205 RTC     */
 #define I2C_DRIVERID_PCF8563   83      /* Philips PCF8563 RTC          */
 #define I2C_DRIVERID_RS5C372   84      /* Ricoh RS5C372 RTC            */
+#define I2C_DRIVERID_BT866     85      /* Conexant bt866 video encoder */
+#define I2C_DRIVERID_KS0127    86      /* Samsung ks0127 video decoder */
 
 #define I2C_DRIVERID_I2CDEV    900
 #define I2C_DRIVERID_ARP        902    /* SMBus ARP Client              */