V4L/DVB (7753): saa7134: fix tuner setup
[safe/jmp/linux-2.6] / drivers / media / video / saa7134 / saa7134-i2c.c
index 1792d03..d8af386 100644 (file)
 #include <linux/init.h>
 #include <linux/list.h>
 #include <linux/module.h>
-#include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 
 #include "saa7134-reg.h"
 #include "saa7134.h"
+#include <media/v4l2-common.h>
 
 /* ----------------------------------------------------------- */
 
-static unsigned int i2c_debug = 0;
+static unsigned int i2c_debug;
 module_param(i2c_debug, int, 0644);
 MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]");
 
-static unsigned int i2c_scan = 0;
+static unsigned int i2c_scan;
 module_param(i2c_scan, int, 0444);
 MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
 
@@ -119,9 +119,9 @@ static inline int i2c_is_error(enum i2c_status status)
        case ARB_LOST:
        case SEQ_ERR:
        case ST_ERR:
-               return TRUE;
+               return true;
        default:
-               return FALSE;
+               return false;
        }
 }
 
@@ -130,9 +130,9 @@ static inline int i2c_is_idle(enum i2c_status status)
        switch (status) {
        case IDLE:
        case DONE_STOP:
-               return TRUE;
+               return true;
        default:
-               return FALSE;
+               return false;
        }
 }
 
@@ -140,9 +140,11 @@ static inline int i2c_is_busy(enum i2c_status status)
 {
        switch (status) {
        case BUSY:
-               return TRUE;
+       case TO_SCL:
+       case TO_ARB:
+               return true;
        default:
-               return FALSE;
+               return false;
        }
 }
 
@@ -158,8 +160,8 @@ static int i2c_is_busy_wait(struct saa7134_dev *dev)
                saa_wait(I2C_WAIT_DELAY);
        }
        if (I2C_WAIT_RETRY == count)
-               return FALSE;
-       return TRUE;
+               return false;
+       return true;
 }
 
 static int i2c_reset(struct saa7134_dev *dev)
@@ -170,7 +172,7 @@ static int i2c_reset(struct saa7134_dev *dev)
        d2printk(KERN_DEBUG "%s: i2c reset\n",dev->name);
        status = i2c_get_status(dev);
        if (!i2c_is_error(status))
-               return TRUE;
+               return true;
        i2c_set_status(dev,status);
 
        for (count = 0; count < I2C_WAIT_RETRY; count++) {
@@ -180,13 +182,13 @@ static int i2c_reset(struct saa7134_dev *dev)
                udelay(I2C_WAIT_DELAY);
        }
        if (I2C_WAIT_RETRY == count)
-               return FALSE;
+               return false;
 
        if (!i2c_is_idle(status))
-               return FALSE;
+               return false;
 
        i2c_set_attr(dev,NOP);
-       return TRUE;
+       return true;
 }
 
 static inline int i2c_send_byte(struct saa7134_dev *dev,
@@ -314,12 +316,6 @@ static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
 
 /* ----------------------------------------------------------- */
 
-static int algo_control(struct i2c_adapter *adapter,
-                       unsigned int cmd, unsigned long arg)
-{
-       return 0;
-}
-
 static u32 functionality(struct i2c_adapter *adap)
 {
        return I2C_FUNC_SMBUS_EMUL;
@@ -328,9 +324,6 @@ static u32 functionality(struct i2c_adapter *adap)
 static int attach_inform(struct i2c_client *client)
 {
        struct saa7134_dev *dev = client->adapter->algo_data;
-       int tuner = dev->tuner_type;
-       int conf  = dev->tda9887_conf;
-       struct tuner_setup tun_setup;
 
        d1printk( "%s i2c attach [addr=0x%x,client=%s]\n",
                client->driver->driver.name, client->addr, client->name);
@@ -340,6 +333,8 @@ static int attach_inform(struct i2c_client *client)
        switch (client->addr) {
                case 0x7a:
                case 0x47:
+               case 0x71:
+               case 0x2d:
                {
                        struct IR_i2c *ir = i2c_get_clientdata(client);
                        d1printk("%s i2c IR detected (%s).\n",
@@ -349,50 +344,17 @@ static int attach_inform(struct i2c_client *client)
                }
        }
 
-       if (!client->driver->command)
-               return 0;
-
-       if (saa7134_boards[dev->board].radio_type != UNSET) {
-
-               tun_setup.type = saa7134_boards[dev->board].radio_type;
-               tun_setup.addr = saa7134_boards[dev->board].radio_addr;
-
-               if ((tun_setup.addr == ADDR_UNSET) || (tun_setup.addr == client->addr)) {
-                       tun_setup.mode_mask = T_RADIO;
-
-                       client->driver->command(client, TUNER_SET_TYPE_ADDR, &tun_setup);
-               }
-       }
-
-       if (tuner != UNSET) {
-
-               tun_setup.type = tuner;
-               tun_setup.addr = saa7134_boards[dev->board].tuner_addr;
-
-               if ((tun_setup.addr == ADDR_UNSET)||(tun_setup.addr == client->addr)) {
-
-                       tun_setup.mode_mask = T_ANALOG_TV;
-
-                       client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_setup);
-               }
-       }
-
-       client->driver->command(client, TDA9887_SET_CONFIG, &conf);
-
        return 0;
 }
 
 static struct i2c_algorithm saa7134_algo = {
        .master_xfer   = saa7134_i2c_xfer,
-       .algo_control  = algo_control,
        .functionality = functionality,
 };
 
 static struct i2c_adapter saa7134_adap_template = {
        .owner         = THIS_MODULE,
-#ifdef I2C_CLASS_TV_ANALOG
        .class         = I2C_CLASS_TV_ANALOG,
-#endif
        .name          = "saa7134",
        .id            = I2C_HW_SAA7134,
        .algo          = &saa7134_algo,
@@ -438,6 +400,7 @@ static char *i2c_devs[128] = {
        [ 0xa0 >> 1 ] = "eeprom",
        [ 0xc0 >> 1 ] = "tuner (analog)",
        [ 0x86 >> 1 ] = "tda9887",
+       [ 0x5a >> 1 ] = "remote control",
 };
 
 static void do_i2c_scan(char *name, struct i2c_client *c)
@@ -445,7 +408,7 @@ static void do_i2c_scan(char *name, struct i2c_client *c)
        unsigned char buf;
        int i,rc;
 
-       for (i = 0; i < 128; i++) {
+       for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
                c->addr = i;
                rc = i2c_master_recv(c,&buf,0);
                if (rc < 0)