Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / media / video / tda7432.c
index 376a4a4..78e043a 100644 (file)
@@ -48,9 +48,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-algo-bit.h>
 
-#include "bttv.h"
-#include <media/audiochip.h>
-#include <media/id.h>
+#include <media/v4l2-common.h>
+#include <media/i2c-addr.h>
 
 #ifndef VIDEO_AUDIO_BALANCE
 # define VIDEO_AUDIO_BALANCE 32
@@ -71,10 +70,9 @@ module_param(maxvol, int, S_IRUGO | S_IWUSR);
 
 /* Address to scan (I2C address of this chip) */
 static unsigned short normal_i2c[] = {
-       I2C_TDA7432 >> 1,
+       I2C_ADDR_TDA7432 >> 1,
        I2C_CLIENT_END,
 };
-static unsigned short normal_i2c_range[] = { I2C_CLIENT_END, I2C_CLIENT_END };
 I2C_CLIENT_INSMOD;
 
 /* Structure of address and subaddresses for the tda7432 */
@@ -92,9 +90,6 @@ struct tda7432 {
 static struct i2c_driver driver;
 static struct i2c_client client_template;
 
-#define dprintk  if (debug) printk
-#define d2printk if (debug > 1) printk
-
 /* The TDA7432 is made by STS-Thompson
  * http://www.st.com
  * http://us.st.com/stonline/books/pdf/docs/4056.pdf
@@ -231,12 +226,12 @@ static struct i2c_client client_template;
 static int tda7432_write(struct i2c_client *client, int subaddr, int val)
 {
        unsigned char buffer[2];
-       d2printk("tda7432: In tda7432_write\n");
-       dprintk("tda7432: Writing %d 0x%x\n", subaddr, val);
+       v4l_dbg(2, debug,client,"In tda7432_write\n");
+       v4l_dbg(1, debug,client,"Writing %d 0x%x\n", subaddr, val);
        buffer[0] = subaddr;
        buffer[1] = val;
        if (2 != i2c_master_send(client,buffer,2)) {
-               printk(KERN_WARNING "tda7432: I/O error, trying (write %d 0x%x)\n",
+               v4l_err(client,"I/O error, trying (write %d 0x%x)\n",
                       subaddr, val);
                return -1;
        }
@@ -244,27 +239,14 @@ static int tda7432_write(struct i2c_client *client, int subaddr, int val)
 }
 
 /* I don't think we ever actually _read_ the chip... */
-#if 0
-static int tda7432_read(struct i2c_client *client)
-{
-       unsigned char buffer;
-       d2printk("tda7432: In tda7432_read\n");
-       if (1 != i2c_master_recv(client,&buffer,1)) {
-               printk(KERN_WARNING "tda7432: I/O error, trying (read)\n");
-               return -1;
-       }
-       dprintk("tda7432: Read 0x%02x\n", buffer);
-       return buffer;
-}
-#endif
 
 static int tda7432_set(struct i2c_client *client)
 {
        struct tda7432 *t = i2c_get_clientdata(client);
        unsigned char buf[16];
-       d2printk("tda7432: In tda7432_set\n");
+       v4l_dbg(2, debug,client,"In tda7432_set\n");
 
-       dprintk(KERN_INFO
+       v4l_dbg(1, debug,client,
                "tda7432: 7432_set(0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n",
                t->input,t->volume,t->bass,t->treble,t->lf,t->lr,t->rf,t->rr,t->loud);
        buf[0]  = TDA7432_IN;
@@ -278,7 +260,7 @@ static int tda7432_set(struct i2c_client *client)
        buf[8]  = t->rr;
        buf[9]  = t->loud;
        if (10 != i2c_master_send(client,buf,10)) {
-               printk(KERN_WARNING "tda7432: I/O error, trying tda7432_set\n");
+               v4l_err(client,"I/O error, trying tda7432_set\n");
                return -1;
        }
 
@@ -288,7 +270,7 @@ static int tda7432_set(struct i2c_client *client)
 static void do_tda7432_init(struct i2c_client *client)
 {
        struct tda7432 *t = i2c_get_clientdata(client);
-       d2printk("tda7432: In tda7432_init\n");
+       v4l_dbg(2, debug,client,"In tda7432_init\n");
 
        t->input  = TDA7432_STEREO_IN |  /* Main (stereo) input   */
                    TDA7432_BASS_SYM  |  /* Symmetric bass cut    */
@@ -316,35 +298,28 @@ static int tda7432_attach(struct i2c_adapter *adap, int addr, int kind)
 {
        struct tda7432 *t;
        struct i2c_client *client;
-       d2printk("tda7432: In tda7432_attach\n");
 
-       t = kmalloc(sizeof *t,GFP_KERNEL);
+       t = kzalloc(sizeof *t,GFP_KERNEL);
        if (!t)
                return -ENOMEM;
-       memset(t,0,sizeof *t);
 
        client = &t->c;
-        memcpy(client,&client_template,sizeof(struct i2c_client));
-        client->adapter = adap;
-        client->addr = addr;
+       memcpy(client,&client_template,sizeof(struct i2c_client));
+       client->adapter = adap;
+       client->addr = addr;
        i2c_set_clientdata(client, t);
 
        do_tda7432_init(client);
-       printk(KERN_INFO "tda7432: init\n");
-
        i2c_attach_client(client);
+
+       v4l_info(client, "chip found @ 0x%x (%s)\n", addr << 1, adap->name);
        return 0;
 }
 
 static int tda7432_probe(struct i2c_adapter *adap)
 {
-#ifdef I2C_CLASS_TV_ANALOG
        if (adap->class & I2C_CLASS_TV_ANALOG)
                return i2c_probe(adap, &addr_data, tda7432_attach);
-#else
-       if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848))
-               return i2c_probe(adap, &addr_data, tda7432_attach);
-#endif
        return 0;
 }
 
@@ -363,7 +338,9 @@ static int tda7432_command(struct i2c_client *client,
                           unsigned int cmd, void *arg)
 {
        struct tda7432 *t = i2c_get_clientdata(client);
-       d2printk("tda7432: In tda7432_command\n");
+       v4l_dbg(2, debug,client,"In tda7432_command\n");
+       if (debug>1)
+               v4l_i2c_print_ioctl(client,cmd);
 
        switch (cmd) {
        /* --- v4l ioctls --- */
@@ -374,7 +351,6 @@ static int tda7432_command(struct i2c_client *client,
        case VIDIOCGAUDIO:
        {
                struct video_audio *va = arg;
-               dprintk("tda7432: VIDIOCGAUDIO\n");
 
                va->flags |= VIDEO_AUDIO_VOLUME |
                        VIDEO_AUDIO_BASS |
@@ -429,7 +405,6 @@ static int tda7432_command(struct i2c_client *client,
        case VIDIOCSAUDIO:
        {
                struct video_audio *va = arg;
-               dprintk("tda7432: VIDEOCSAUDIO\n");
 
                if(va->flags & VIDEO_AUDIO_VOLUME){
                        if(!maxvol){ /* max +20db */
@@ -486,7 +461,7 @@ static int tda7432_command(struct i2c_client *client,
                }
                }
 
-               t->muted=(va->flags & VIDEO_AUDIO_MUTE);
+               t->muted=(va->flags & VIDEO_AUDIO_MUTE);
                if (t->muted)
                {
                        /* Mute & update balance*/
@@ -505,36 +480,31 @@ static int tda7432_command(struct i2c_client *client,
 
        } /* end of VIDEOCSAUDIO case */
 
-       default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */
-
-               /* nothing */
-               d2printk("tda7432: Default\n");
-
        } /* end of (cmd) switch */
 
        return 0;
 }
 
 static struct i2c_driver driver = {
-       .owner           = THIS_MODULE,
-        .name            = "i2c tda7432 driver",
+       .driver = {
+               .name    = "tda7432",
+       },
        .id              = I2C_DRIVERID_TDA7432,
-        .flags           = I2C_DF_NOTIFY,
        .attach_adapter  = tda7432_probe,
-        .detach_client   = tda7432_detach,
-        .command         = tda7432_command,
+       .detach_client   = tda7432_detach,
+       .command         = tda7432_command,
 };
 
 static struct i2c_client client_template =
 {
-       I2C_DEVNAME("tda7432"),
+       .name       = "tda7432",
        .driver     = &driver,
 };
 
 static int __init tda7432_init(void)
 {
        if ( (loudness < 0) || (loudness > 15) ) {
-               printk(KERN_ERR "tda7432: loudness parameter must be between 0 and 15\n");
+               printk(KERN_ERR "loudness parameter must be between 0 and 15\n");
                return -EINVAL;
        }