]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/video/bttv-i2c.c
V4L/DVB (3376): Add cpia2 camera support
[linux-2.6-omap-h63xx.git] / drivers / media / video / bttv-i2c.c
index e684df37eb0e249c982b8255ffeb84c814c000d0..614c12018557a0e75d813c66afe1816201d00b33 100644 (file)
@@ -5,7 +5,7 @@
     bttv - Bt848 frame grabber driver
 
     Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
-                           & Marcus Metzler (mocm@thp.uni-koeln.de)
+                          & Marcus Metzler (mocm@thp.uni-koeln.de)
     (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
 
     This program is free software; you can redistribute it and/or modify
 #include <linux/moduleparam.h>
 #include <linux/init.h>
 #include <linux/delay.h>
-#include <linux/jiffies.h>
-#include <asm/io.h>
 
 #include "bttvp.h"
+#include <media/v4l2-common.h>
+#include <linux/jiffies.h>
+#include <asm/io.h>
 
 static struct i2c_algo_bit_data bttv_i2c_algo_bit_template;
 static struct i2c_adapter bttv_i2c_adap_sw_template;
@@ -40,9 +41,9 @@ static struct i2c_client bttv_i2c_client_template;
 
 static int attach_inform(struct i2c_client *client);
 
-static int i2c_debug = 0;
-static int i2c_hw = 0;
-static int i2c_scan = 0;
+static int i2c_debug;
+static int i2c_hw;
+static int i2c_scan;
 module_param(i2c_debug, int, 0644);
 module_param(i2c_hw,    int, 0444);
 module_param(i2c_scan,  int, 0444);
@@ -105,10 +106,8 @@ static struct i2c_algo_bit_data bttv_i2c_algo_bit_template = {
 
 static struct i2c_adapter bttv_i2c_adap_sw_template = {
        .owner             = THIS_MODULE,
-#ifdef I2C_CLASS_TV_ANALOG
        .class             = I2C_CLASS_TV_ANALOG,
-#endif
-       .name              = "bt848",
+       .name              = "bttv",
        .id                = I2C_HW_B_BT848,
        .client_register   = attach_inform,
 };
@@ -237,7 +236,7 @@ bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
  err:
        if (i2c_debug)
                printk(" ERR: %d\n",retval);
-               return retval;
+       return retval;
 }
 
 static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
@@ -275,10 +274,8 @@ static struct i2c_algorithm bttv_algo = {
 };
 
 static struct i2c_adapter bttv_i2c_adap_hw_template = {
-       .owner         = THIS_MODULE,
-#ifdef I2C_CLASS_TV_ANALOG
+       .owner             = THIS_MODULE,
        .class         = I2C_CLASS_TV_ANALOG,
-#endif
        .name          = "bt878",
        .id            = I2C_HW_B_BT848 /* FIXME */,
        .algo          = &bttv_algo,
@@ -290,29 +287,36 @@ static struct i2c_adapter bttv_i2c_adap_hw_template = {
 
 static int attach_inform(struct i2c_client *client)
 {
-        struct bttv *btv = i2c_get_adapdata(client->adapter);
+       struct bttv *btv = i2c_get_adapdata(client->adapter);
+       int addr=ADDR_UNSET;
+
+
+       if (ADDR_UNSET != bttv_tvcards[btv->c.type].tuner_addr)
+               addr = bttv_tvcards[btv->c.type].tuner_addr;
+
 
        if (bttv_debug)
                printk(KERN_DEBUG "bttv%d: %s i2c attach [addr=0x%x,client=%s]\n",
-                       btv->c.nr,client->driver->name,client->addr,
+                       btv->c.nr, client->driver->driver.name, client->addr,
                        client->name);
        if (!client->driver->command)
                return 0;
 
        if (btv->tuner_type != UNSET) {
-               struct tuner_setup tun_setup;
+               struct tuner_setup tun_setup;
+
+               if ((addr==ADDR_UNSET) ||
+                               (addr==client->addr)) {
 
-               tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
-               tun_setup.type = btv->tuner_type;
-               tun_setup.addr = ADDR_UNSET;
+                       tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV | T_RADIO;
+                       tun_setup.type = btv->tuner_type;
+                       tun_setup.addr = addr;
+                       bttv_call_i2c_clients(btv, TUNER_SET_TYPE_ADDR, &tun_setup);
+               }
 
-               client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
        }
 
-       if (btv->pinnacle_id != UNSET)
-               client->driver->command(client,AUDC_CONFIG_PINNACLE,
-                                     &btv->pinnacle_id);
-        return 0;
+       return 0;
 }
 
 void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg)
@@ -330,43 +334,43 @@ static struct i2c_client bttv_i2c_client_template = {
 /* read I2C */
 int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for)
 {
-        unsigned char buffer = 0;
+       unsigned char buffer = 0;
 
        if (0 != btv->i2c_rc)
                return -1;
        if (bttv_verbose && NULL != probe_for)
                printk(KERN_INFO "bttv%d: i2c: checking for %s @ 0x%02x... ",
                       btv->c.nr,probe_for,addr);
-        btv->i2c_client.addr = addr >> 1;
-        if (1 != i2c_master_recv(&btv->i2c_client, &buffer, 1)) {
+       btv->i2c_client.addr = addr >> 1;
+       if (1 != i2c_master_recv(&btv->i2c_client, &buffer, 1)) {
                if (NULL != probe_for) {
                        if (bttv_verbose)
                                printk("not found\n");
                } else
                        printk(KERN_WARNING "bttv%d: i2c read 0x%x: error\n",
                               btv->c.nr,addr);
-                return -1;
+               return -1;
        }
        if (bttv_verbose && NULL != probe_for)
                printk("found\n");
-        return buffer;
+       return buffer;
 }
 
 /* write I2C */
 int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
-                    unsigned char b2, int both)
+                   unsigned char b2, int both)
 {
-        unsigned char buffer[2];
-        int bytes = both ? 2 : 1;
+       unsigned char buffer[2];
+       int bytes = both ? 2 : 1;
 
        if (0 != btv->i2c_rc)
                return -1;
-        btv->i2c_client.addr = addr >> 1;
-        buffer[0] = b1;
-        buffer[1] = b2;
-        if (bytes != i2c_master_send(&btv->i2c_client, buffer, bytes))
+       btv->i2c_client.addr = addr >> 1;
+       buffer[0] = b1;
+       buffer[1] = b2;
+       if (bytes != i2c_master_send(&btv->i2c_client, buffer, bytes))
                return -1;
-        return 0;
+       return 0;
 }
 
 /* read EEPROM content */
@@ -431,15 +435,13 @@ int __devinit init_bttv_i2c(struct bttv *btv)
                 "bt%d #%d [%s]", btv->id, btv->c.nr,
                 btv->use_i2c_hw ? "hw" : "sw");
 
-        i2c_set_adapdata(&btv->c.i2c_adap, btv);
-        btv->i2c_client.adapter = &btv->c.i2c_adap;
+       i2c_set_adapdata(&btv->c.i2c_adap, btv);
+       btv->i2c_client.adapter = &btv->c.i2c_adap;
 
-#ifdef I2C_CLASS_TV_ANALOG
        if (bttv_tvcards[btv->c.type].no_video)
                btv->c.i2c_adap.class &= ~I2C_CLASS_TV_ANALOG;
        if (bttv_tvcards[btv->c.type].has_dvb)
                btv->c.i2c_adap.class |= I2C_CLASS_TV_DIGITAL;
-#endif
 
        if (btv->use_i2c_hw) {
                btv->i2c_rc = i2c_add_adapter(&btv->c.i2c_adap);