Commit a7856647 authored by Gerd Knorr's avatar Gerd Knorr Committed by Linus Torvalds

[PATCH] v4l: bttv i2c audio update

This patch updates the i2c audio chip modules.  It improves the support
for tda9874x chips.  There are some bugfixes.  It also has alot of small
cleanups: switch some modules to new initialization, declare lots of
functions static, ...  which make the patch a bit large.
parent 713194bd
...@@ -24,6 +24,12 @@ ...@@ -24,6 +24,12 @@
#ifndef I2C_DRIVERID_TDA7432 #ifndef I2C_DRIVERID_TDA7432
# define I2C_DRIVERID_TDA7432 I2C_DRIVERID_EXP0+6 # define I2C_DRIVERID_TDA7432 I2C_DRIVERID_EXP0+6
#endif #endif
#ifndef I2C_DRIVERID_TDA9874A #ifndef I2C_DRIVERID_TDA9874
# define I2C_DRIVERID_TDA9874A I2C_DRIVERID_EXP0+7 # define I2C_DRIVERID_TDA9874 I2C_DRIVERID_EXP0+7
#endif #endif
/* algorithms */
#ifndef I2C_ALGO_SAA7134
# define I2C_ALGO_SAA7134 0x090000
#endif
...@@ -97,6 +97,7 @@ struct msp3400c { ...@@ -97,6 +97,7 @@ struct msp3400c {
int nicam_on; int nicam_on;
int acb; int acb;
int main, second; /* sound carrier */ int main, second; /* sound carrier */
int input;
int muted; int muted;
int left, right; /* volume */ int left, right; /* volume */
...@@ -462,6 +463,8 @@ static void msp3400c_setmode(struct i2c_client *client, int type) ...@@ -462,6 +463,8 @@ static void msp3400c_setmode(struct i2c_client *client, int type)
/* turn on/off nicam + stereo */ /* turn on/off nicam + stereo */
static void msp3400c_setstereo(struct i2c_client *client, int mode) static void msp3400c_setstereo(struct i2c_client *client, int mode)
{ {
static char *strmode[] = { "0", "mono", "stereo", "3",
"lang1", "5", "6", "7", "lang2" };
struct msp3400c *msp = client->data; struct msp3400c *msp = client->data;
int nicam=0; /* channel source: FM/AM or nicam */ int nicam=0; /* channel source: FM/AM or nicam */
int src=0; int src=0;
...@@ -469,7 +472,7 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode) ...@@ -469,7 +472,7 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode)
/* switch demodulator */ /* switch demodulator */
switch (msp->mode) { switch (msp->mode) {
case MSP_MODE_FM_TERRA: case MSP_MODE_FM_TERRA:
dprintk("msp3400: FM setstereo: %d\n",mode); dprintk("msp3400: FM setstereo: %s\n",strmode[mode]);
msp3400c_setcarrier(client,msp->second,msp->main); msp3400c_setcarrier(client,msp->second,msp->main);
switch (mode) { switch (mode) {
case VIDEO_SOUND_STEREO: case VIDEO_SOUND_STEREO:
...@@ -483,7 +486,7 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode) ...@@ -483,7 +486,7 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode)
} }
break; break;
case MSP_MODE_FM_SAT: case MSP_MODE_FM_SAT:
dprintk("msp3400: SAT setstereo: %d\n",mode); dprintk("msp3400: SAT setstereo: %s\n",strmode[mode]);
switch (mode) { switch (mode) {
case VIDEO_SOUND_MONO: case VIDEO_SOUND_MONO:
msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5)); msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
...@@ -502,21 +505,21 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode) ...@@ -502,21 +505,21 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode)
case MSP_MODE_FM_NICAM1: case MSP_MODE_FM_NICAM1:
case MSP_MODE_FM_NICAM2: case MSP_MODE_FM_NICAM2:
case MSP_MODE_AM_NICAM: case MSP_MODE_AM_NICAM:
dprintk("msp3400: NICAM setstereo: %d\n",mode); dprintk("msp3400: NICAM setstereo: %s\n",strmode[mode]);
msp3400c_setcarrier(client,msp->second,msp->main); msp3400c_setcarrier(client,msp->second,msp->main);
if (msp->nicam_on) if (msp->nicam_on)
nicam=0x0100; nicam=0x0100;
break; break;
case MSP_MODE_BTSC: case MSP_MODE_BTSC:
dprintk("msp3400: BTSC setstereo: %d\n",mode); dprintk("msp3400: BTSC setstereo: %s\n",strmode[mode]);
nicam=0x0300; nicam=0x0300;
break; break;
case MSP_MODE_EXTERN: case MSP_MODE_EXTERN:
dprintk("msp3400: extern setstereo: %d\n", mode); dprintk("msp3400: extern setstereo: %s\n",strmode[mode]);
nicam = 0x0200; nicam = 0x0200;
break; break;
case MSP_MODE_FM_RADIO: case MSP_MODE_FM_RADIO:
dprintk("msp3400: FM-Radio setstereo: %d\n", mode); dprintk("msp3400: FM-Radio setstereo: %s\n",strmode[mode]);
break; break;
default: default:
dprintk("msp3400: mono setstereo\n"); dprintk("msp3400: mono setstereo\n");
...@@ -627,7 +630,7 @@ autodetect_stereo(struct i2c_client *client) ...@@ -627,7 +630,7 @@ autodetect_stereo(struct i2c_client *client)
switch (msp->mode) { switch (msp->mode) {
case MSP_MODE_FM_TERRA: case MSP_MODE_FM_TERRA:
val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x18); val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x18);
if (val > 32768) if (val > 32767)
val -= 65536; val -= 65536;
dprintk("msp34xx: stereo detect register: %d\n",val); dprintk("msp34xx: stereo detect register: %d\n",val);
...@@ -822,7 +825,7 @@ static int msp3400c_thread(void *data) ...@@ -822,7 +825,7 @@ static int msp3400c_thread(void *data)
msp->restart = 0; msp->restart = 0;
val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b); val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
if (val > 32768) if (val > 32767)
val -= 65536; val -= 65536;
if (val1 < val) if (val1 < val)
val1 = val, max1 = this; val1 = val, max1 = this;
...@@ -859,7 +862,7 @@ static int msp3400c_thread(void *data) ...@@ -859,7 +862,7 @@ static int msp3400c_thread(void *data)
goto restart; goto restart;
val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b); val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
if (val > 32768) if (val > 32767)
val -= 65536; val -= 65536;
if (val2 < val) if (val2 < val)
val2 = val, max2 = this; val2 = val, max2 = this;
...@@ -1221,6 +1224,7 @@ static struct i2c_driver driver = { ...@@ -1221,6 +1224,7 @@ static struct i2c_driver driver = {
static struct i2c_client client_template = static struct i2c_client client_template =
{ {
name: "(unset)", name: "(unset)",
flags: I2C_CLIENT_ALLOW_USE,
driver: &driver, driver: &driver,
}; };
...@@ -1253,6 +1257,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr, ...@@ -1253,6 +1257,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr,
msp->right = 65535; msp->right = 65535;
msp->bass = 32768; msp->bass = 32768;
msp->treble = 32768; msp->treble = 32768;
msp->input = -1;
for (i = 0; i < DFP_COUNT; i++) for (i = 0; i < DFP_COUNT; i++)
msp->dfp_regs[i] = -1; msp->dfp_regs[i] = -1;
...@@ -1391,6 +1396,9 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -1391,6 +1396,9 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
- IN1 is often used for external input - IN1 is often used for external input
- Hauppauge uses IN2 for the radio */ - Hauppauge uses IN2 for the radio */
dprintk(KERN_DEBUG "msp34xx: AUDC_SET_INPUT(%d)\n",*sarg); dprintk(KERN_DEBUG "msp34xx: AUDC_SET_INPUT(%d)\n",*sarg);
if (*sarg == msp->input)
break;
msp->input = *sarg;
switch (*sarg) { switch (*sarg) {
case AUDIO_RADIO: case AUDIO_RADIO:
msp->mode = MSP_MODE_FM_RADIO; msp->mode = MSP_MODE_FM_RADIO;
...@@ -1420,6 +1428,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -1420,6 +1428,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
break; break;
case AUDC_SET_RADIO: case AUDC_SET_RADIO:
dprintk(KERN_DEBUG "msp34xx: AUDC_SET_RADIO\n");
msp->norm = VIDEO_MODE_RADIO; msp->norm = VIDEO_MODE_RADIO;
msp->watch_stereo=0; msp->watch_stereo=0;
del_timer(&msp->wake_stereo); del_timer(&msp->wake_stereo);
...@@ -1471,6 +1480,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -1471,6 +1480,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
{ {
struct video_audio *va = arg; struct video_audio *va = arg;
dprintk(KERN_DEBUG "msp34xx: VIDIOCGAUDIO\n");
va->flags |= VIDEO_AUDIO_VOLUME | va->flags |= VIDEO_AUDIO_VOLUME |
VIDEO_AUDIO_BASS | VIDEO_AUDIO_BASS |
VIDEO_AUDIO_TREBLE | VIDEO_AUDIO_TREBLE |
...@@ -1497,6 +1507,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -1497,6 +1507,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
{ {
struct video_audio *va = arg; struct video_audio *va = arg;
dprintk(KERN_DEBUG "msp34xx: VIDIOCSAUDIO\n");
msp->muted = (va->flags & VIDEO_AUDIO_MUTE); msp->muted = (va->flags & VIDEO_AUDIO_MUTE);
msp->left = (MIN(65536 - va->balance,32768) * msp->left = (MIN(65536 - va->balance,32768) *
va->volume) / 32768; va->volume) / 32768;
...@@ -1520,6 +1531,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -1520,6 +1531,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
{ {
struct video_channel *vc = arg; struct video_channel *vc = arg;
dprintk(KERN_DEBUG "msp34xx: VIDIOCSCHAN\n");
dprintk("msp34xx: switching to TV mode\n"); dprintk("msp34xx: switching to TV mode\n");
msp->norm = vc->norm; msp->norm = vc->norm;
break; break;
...@@ -1527,6 +1539,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -1527,6 +1539,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
case VIDIOCSFREQ: case VIDIOCSFREQ:
{ {
/* new channel -- kick audio carrier scan */ /* new channel -- kick audio carrier scan */
dprintk(KERN_DEBUG "msp34xx: VIDIOCSFREQ\n");
msp_wake_thread(client); msp_wake_thread(client);
break; break;
} }
...@@ -1540,13 +1553,13 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -1540,13 +1553,13 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int msp3400_init_module(void) static int msp3400_init_module(void)
{ {
i2c_add_driver(&driver); i2c_add_driver(&driver);
return 0; return 0;
} }
void msp3400_cleanup_module(void) static void msp3400_cleanup_module(void)
{ {
i2c_del_driver(&driver); i2c_del_driver(&driver);
} }
......
...@@ -518,7 +518,7 @@ static struct i2c_client client_template = ...@@ -518,7 +518,7 @@ static struct i2c_client client_template =
&driver &driver
}; };
int tda7432_init(void) static int tda7432_init(void)
{ {
if ( (loudness < 0) || (loudness > 15) ) if ( (loudness < 0) || (loudness > 15) )
...@@ -531,7 +531,7 @@ int tda7432_init(void) ...@@ -531,7 +531,7 @@ int tda7432_init(void)
return 0; return 0;
} }
void tda7432_fini(void) static void tda7432_fini(void)
{ {
i2c_del_driver(&driver); i2c_del_driver(&driver);
} }
......
...@@ -147,6 +147,24 @@ static int tda9875_read(struct i2c_client *client) ...@@ -147,6 +147,24 @@ static int tda9875_read(struct i2c_client *client)
} }
#endif #endif
static int i2c_read_register(struct i2c_adapter *adap, int addr, int reg)
{
unsigned char write[1];
unsigned char read[1];
struct i2c_msg msgs[2] = {
{ addr, 0, 1, write },
{ addr, I2C_M_RD, 1, read }
};
write[0] = reg;
if (2 != i2c_transfer(adap,msgs,2)) {
printk(KERN_WARNING "tda9875: I/O error (read2)\n");
return -1;
}
dprintk("tda9875: chip_read2: reg%d=0x%x\n",reg,read[0]);
return read[0];
}
static void tda9875_set(struct i2c_client *client) static void tda9875_set(struct i2c_client *client)
{ {
struct tda9875 *tda = client->data; struct tda9875 *tda = client->data;
...@@ -215,6 +233,22 @@ static void do_tda9875_init(struct i2c_client *client) ...@@ -215,6 +233,22 @@ static void do_tda9875_init(struct i2c_client *client)
* i2c interface functions * * i2c interface functions *
* *********************** */ * *********************** */
static int tda9875_checkit(struct i2c_adapter *adap, int addr)
{
int dic,rev;
dic=i2c_read_register(adap,addr,254);
rev=i2c_read_register(adap,addr,255);
if(dic==0 || dic==2) { // tda9875 and tda9875A
printk("tda9875: TDA9875%s Rev.%d detected at 0x%x\n",
dic==0?"":"A", rev,addr<<1);
return 1;
}
printk("tda9875: no such chip at 0x%x (dic=0x%x rev=0x%x)\n",addr<<1,dic,rev);
return(0);
}
static int tda9875_attach(struct i2c_adapter *adap, int addr, static int tda9875_attach(struct i2c_adapter *adap, int addr,
unsigned short flags, int kind) unsigned short flags, int kind)
{ {
...@@ -233,6 +267,11 @@ static int tda9875_attach(struct i2c_adapter *adap, int addr, ...@@ -233,6 +267,11 @@ static int tda9875_attach(struct i2c_adapter *adap, int addr,
client->addr = addr; client->addr = addr;
client->data = t; client->data = t;
if(!tda9875_checkit(adap,addr)) {
kfree(t);
return 1;
}
do_tda9875_init(client); do_tda9875_init(client);
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
strcpy(client->name,"TDA9875"); strcpy(client->name,"TDA9875");
...@@ -375,22 +414,19 @@ static struct i2c_client client_template = ...@@ -375,22 +414,19 @@ static struct i2c_client client_template =
&driver &driver
}; };
#ifdef MODULE static int tda9875_init(void)
int init_module(void)
#else
int tda9875_init(void)
#endif
{ {
i2c_add_driver(&driver); i2c_add_driver(&driver);
return 0; return 0;
} }
#ifdef MODULE static void tda9875_fini(void)
void cleanup_module(void)
{ {
i2c_del_driver(&driver); i2c_del_driver(&driver);
} }
#endif
module_init(tda9875_init);
module_exit(tda9875_fini);
/* /*
* Local variables: * Local variables:
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define I2C_TDA9840 0x84 #define I2C_TDA9840 0x84
#define I2C_TDA985x_L 0xb4 /* also used by 9873 */ #define I2C_TDA985x_L 0xb4 /* also used by 9873 */
#define I2C_TDA985x_H 0xb6 #define I2C_TDA985x_H 0xb6
#define I2C_TDA9874A 0xb0 /* also used by 9875 */ #define I2C_TDA9874 0xb0 /* also used by 9875 */
#define I2C_TEA6300 0x80 #define I2C_TEA6300 0x80
#define I2C_TEA6420 0x98 #define I2C_TEA6420 0x98
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/videodev.h> #include <linux/videodev.h>
#include <asm/semaphore.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/kdev_t.h>
#include <asm/semaphore.h>
#include <linux/sound.h> #include <linux/sound.h>
#include <linux/soundcard.h> #include <linux/soundcard.h>
...@@ -320,7 +321,7 @@ static int tvmixer_clients(struct i2c_client *client) ...@@ -320,7 +321,7 @@ static int tvmixer_clients(struct i2c_client *client)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int tvmixer_init_module(void) static int tvmixer_init_module(void)
{ {
int i; int i;
...@@ -330,7 +331,7 @@ int tvmixer_init_module(void) ...@@ -330,7 +331,7 @@ int tvmixer_init_module(void)
return 0; return 0;
} }
void tvmixer_cleanup_module(void) static void tvmixer_cleanup_module(void)
{ {
int i; int i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment