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 @@
#ifndef I2C_DRIVERID_TDA7432
# define I2C_DRIVERID_TDA7432 I2C_DRIVERID_EXP0+6
#endif
#ifndef I2C_DRIVERID_TDA9874A
# define I2C_DRIVERID_TDA9874A I2C_DRIVERID_EXP0+7
#ifndef I2C_DRIVERID_TDA9874
# define I2C_DRIVERID_TDA9874 I2C_DRIVERID_EXP0+7
#endif
/* algorithms */
#ifndef I2C_ALGO_SAA7134
# define I2C_ALGO_SAA7134 0x090000
#endif
......@@ -97,6 +97,7 @@ struct msp3400c {
int nicam_on;
int acb;
int main, second; /* sound carrier */
int input;
int muted;
int left, right; /* volume */
......@@ -462,6 +463,8 @@ static void msp3400c_setmode(struct i2c_client *client, int type)
/* turn on/off nicam + stereo */
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;
int nicam=0; /* channel source: FM/AM or nicam */
int src=0;
......@@ -469,7 +472,7 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode)
/* switch demodulator */
switch (msp->mode) {
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);
switch (mode) {
case VIDEO_SOUND_STEREO:
......@@ -483,7 +486,7 @@ static void msp3400c_setstereo(struct i2c_client *client, int mode)
}
break;
case MSP_MODE_FM_SAT:
dprintk("msp3400: SAT setstereo: %d\n",mode);
dprintk("msp3400: SAT setstereo: %s\n",strmode[mode]);
switch (mode) {
case VIDEO_SOUND_MONO:
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)
case MSP_MODE_FM_NICAM1:
case MSP_MODE_FM_NICAM2:
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);
if (msp->nicam_on)
nicam=0x0100;
break;
case MSP_MODE_BTSC:
dprintk("msp3400: BTSC setstereo: %d\n",mode);
dprintk("msp3400: BTSC setstereo: %s\n",strmode[mode]);
nicam=0x0300;
break;
case MSP_MODE_EXTERN:
dprintk("msp3400: extern setstereo: %d\n", mode);
dprintk("msp3400: extern setstereo: %s\n",strmode[mode]);
nicam = 0x0200;
break;
case MSP_MODE_FM_RADIO:
dprintk("msp3400: FM-Radio setstereo: %d\n", mode);
dprintk("msp3400: FM-Radio setstereo: %s\n",strmode[mode]);
break;
default:
dprintk("msp3400: mono setstereo\n");
......@@ -627,7 +630,7 @@ autodetect_stereo(struct i2c_client *client)
switch (msp->mode) {
case MSP_MODE_FM_TERRA:
val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x18);
if (val > 32768)
if (val > 32767)
val -= 65536;
dprintk("msp34xx: stereo detect register: %d\n",val);
......@@ -822,7 +825,7 @@ static int msp3400c_thread(void *data)
msp->restart = 0;
val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
if (val > 32768)
if (val > 32767)
val -= 65536;
if (val1 < val)
val1 = val, max1 = this;
......@@ -859,7 +862,7 @@ static int msp3400c_thread(void *data)
goto restart;
val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
if (val > 32768)
if (val > 32767)
val -= 65536;
if (val2 < val)
val2 = val, max2 = this;
......@@ -1221,6 +1224,7 @@ static struct i2c_driver driver = {
static struct i2c_client client_template =
{
name: "(unset)",
flags: I2C_CLIENT_ALLOW_USE,
driver: &driver,
};
......@@ -1253,6 +1257,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr,
msp->right = 65535;
msp->bass = 32768;
msp->treble = 32768;
msp->input = -1;
for (i = 0; i < DFP_COUNT; i++)
msp->dfp_regs[i] = -1;
......@@ -1391,6 +1396,9 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
- IN1 is often used for external input
- Hauppauge uses IN2 for the radio */
dprintk(KERN_DEBUG "msp34xx: AUDC_SET_INPUT(%d)\n",*sarg);
if (*sarg == msp->input)
break;
msp->input = *sarg;
switch (*sarg) {
case AUDIO_RADIO:
msp->mode = MSP_MODE_FM_RADIO;
......@@ -1420,6 +1428,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
break;
case AUDC_SET_RADIO:
dprintk(KERN_DEBUG "msp34xx: AUDC_SET_RADIO\n");
msp->norm = VIDEO_MODE_RADIO;
msp->watch_stereo=0;
del_timer(&msp->wake_stereo);
......@@ -1471,6 +1480,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
{
struct video_audio *va = arg;
dprintk(KERN_DEBUG "msp34xx: VIDIOCGAUDIO\n");
va->flags |= VIDEO_AUDIO_VOLUME |
VIDEO_AUDIO_BASS |
VIDEO_AUDIO_TREBLE |
......@@ -1497,6 +1507,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
{
struct video_audio *va = arg;
dprintk(KERN_DEBUG "msp34xx: VIDIOCSAUDIO\n");
msp->muted = (va->flags & VIDEO_AUDIO_MUTE);
msp->left = (MIN(65536 - va->balance,32768) *
va->volume) / 32768;
......@@ -1520,6 +1531,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
{
struct video_channel *vc = arg;
dprintk(KERN_DEBUG "msp34xx: VIDIOCSCHAN\n");
dprintk("msp34xx: switching to TV mode\n");
msp->norm = vc->norm;
break;
......@@ -1527,6 +1539,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
case VIDIOCSFREQ:
{
/* new channel -- kick audio carrier scan */
dprintk(KERN_DEBUG "msp34xx: VIDIOCSFREQ\n");
msp_wake_thread(client);
break;
}
......@@ -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);
return 0;
}
void msp3400_cleanup_module(void)
static void msp3400_cleanup_module(void)
{
i2c_del_driver(&driver);
}
......
......@@ -518,7 +518,7 @@ static struct i2c_client client_template =
&driver
};
int tda7432_init(void)
static int tda7432_init(void)
{
if ( (loudness < 0) || (loudness > 15) )
......@@ -531,7 +531,7 @@ int tda7432_init(void)
return 0;
}
void tda7432_fini(void)
static void tda7432_fini(void)
{
i2c_del_driver(&driver);
}
......
......@@ -147,6 +147,24 @@ static int tda9875_read(struct i2c_client *client)
}
#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)
{
struct tda9875 *tda = client->data;
......@@ -215,6 +233,22 @@ static void do_tda9875_init(struct i2c_client *client)
* 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,
unsigned short flags, int kind)
{
......@@ -232,6 +266,11 @@ static int tda9875_attach(struct i2c_adapter *adap, int addr,
client->adapter = adap;
client->addr = addr;
client->data = t;
if(!tda9875_checkit(adap,addr)) {
kfree(t);
return 1;
}
do_tda9875_init(client);
MOD_INC_USE_COUNT;
......@@ -375,22 +414,19 @@ static struct i2c_client client_template =
&driver
};
#ifdef MODULE
int init_module(void)
#else
int tda9875_init(void)
#endif
static int tda9875_init(void)
{
i2c_add_driver(&driver);
return 0;
}
#ifdef MODULE
void cleanup_module(void)
static void tda9875_fini(void)
{
i2c_del_driver(&driver);
}
#endif
module_init(tda9875_init);
module_exit(tda9875_fini);
/*
* Local variables:
......
This diff is collapsed.
......@@ -6,7 +6,7 @@
#define I2C_TDA9840 0x84
#define I2C_TDA985x_L 0xb4 /* also used by 9873 */
#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_TEA6420 0x98
......
......@@ -8,8 +8,9 @@
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/videodev.h>
#include <asm/semaphore.h>
#include <linux/init.h>
#include <linux/kdev_t.h>
#include <asm/semaphore.h>
#include <linux/sound.h>
#include <linux/soundcard.h>
......@@ -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;
......@@ -330,7 +331,7 @@ int tvmixer_init_module(void)
return 0;
}
void tvmixer_cleanup_module(void)
static void tvmixer_cleanup_module(void)
{
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