2 * for the TEA6420 chip (only found on 3DFX (STB) TV/FM cards to the best
4 * Copyright (C) 2000 Dave Stuart <justdave@ynn.com>
5 * This code is placed under the terms of the GNU General Public License
6 * Code liberally copied from tea6300 by . . .
8 * Copyright (c) 1998 Greg Alexander <galexand@acm.org>
9 * This code is placed under the terms of the GNU General Public License
10 * Code liberally copied from msp3400.c, which is by Gerd Knorr
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/string.h>
18 #include <linux/timer.h>
19 #include <linux/delay.h>
20 #include <linux/errno.h>
21 #include <linux/malloc.h>
22 #include <linux/videodev.h>
23 #include <linux/i2c.h>
24 #include <linux/i2c-algo-bit.h>
27 #include "audiochip.h"
30 /* Addresses to scan */
31 #define I2C_TEA6420 0x98
32 static unsigned short normal_i2c
[] = {
35 static unsigned short normal_i2c_range
[] = {I2C_CLIENT_END
};
36 static unsigned short probe
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
37 static unsigned short probe_range
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
38 static unsigned short ignore
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
39 static unsigned short ignore_range
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
40 static unsigned short force
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
41 static struct i2c_client_address_data addr_data
= {
42 normal_i2c
, normal_i2c_range
,
49 MODULE_PARM(debug
,"i");
50 static int debug
= 0; /* insmod parameter */
52 #define dprintk if (debug) printk
56 int mode
; /* set to AUDIO_{OFF,TUNER,RADIO,EXTERN} */
60 static struct i2c_driver driver
;
61 static struct i2c_client client_template
;
63 #define TEA6420_S_SA 0x00 /* stereo A input */
64 #define TEA6420_S_SB 0x01 /* stereo B */
65 #define TEA6420_S_SC 0x02 /* stereo C */
66 #define TEA6420_S_SD 0x03 /* stereo D */
67 #define TEA6420_S_SE 0x04 /* stereo E */
68 #define TEA6420_S_GMU 0x05 /* general mute */
71 /* ******************************** *
72 * functions for talking to TEA6420 *
73 * ******************************** */
75 static int tea6420_write(struct i2c_client
*client
, int val
)
77 unsigned char buffer
[2];
80 /* buffer[0] = addr; */
82 result
= i2c_master_send(client
,buffer
,1);
84 printk(KERN_WARNING
"tea6420: I/O error, trying (write
85 0x%x) result = %d\n", val
, result
);
92 static void do_tea6420_init(struct i2c_client
*client
)
94 struct tea6420
*tea
= client
->data
;
98 tea6420_write(client
, TEA6420_S_GMU
); /* mute */
101 static void tea6420_audio(struct i2c_client
*client
, int mode
)
103 struct tea6420
*tea
= client
->data
;
105 /* valid for AUDIO_TUNER, RADIO, EXTERN, OFF */
106 dprintk(KERN_DEBUG
"tea6420_audio:%d (T,R,E,I,O)\n",mode
);
108 if (mode
==AUDIO_OFF
) { /* just mute it */
109 tea6420_write(client
, TEA6420_S_GMU
);
114 tea6420_write(client
, TEA6420_S_SA
);
117 tea6420_write(client
, TEA6420_S_SB
);
120 tea6420_write(client
, TEA6420_S_SC
);
126 /* *********************** *
127 * i2c interface functions *
128 * *********************** */
130 static int tea6420_attach(struct i2c_adapter
*adap
, int addr
,
131 unsigned short flags
, int kind
)
134 struct i2c_client
*client
;
136 client
= kmalloc(sizeof *client
,GFP_KERNEL
);
139 memcpy(client
,&client_template
,sizeof(struct i2c_client
));
140 client
->adapter
= adap
;
143 client
->data
= tea
= kmalloc(sizeof *tea
,GFP_KERNEL
);
146 memset(tea
,0,sizeof *tea
);
147 do_tea6420_init(client
);
150 strcpy(client
->name
,"TEA6420");
151 printk(KERN_INFO
"tea6420: initialized\n");
153 i2c_attach_client(client
);
157 static int tea6420_probe(struct i2c_adapter
*adap
)
159 if (adap
->id
== (I2C_ALGO_BIT
| I2C_HW_B_BT848
))
160 return i2c_probe(adap
, &addr_data
, tea6420_attach
);
164 static int tea6420_detach(struct i2c_client
*client
)
166 struct tea6420
*tea
= client
->data
;
168 do_tea6420_init(client
);
169 i2c_detach_client(client
);
178 tea6420_command(struct i2c_client
*client
, unsigned int cmd
, void *arg
)
184 tea6420_audio(client
,AUDIO_RADIO
);
187 tea6420_audio(client
,*sarg
);
190 /* --- v4l ioctls --- */
191 /* take care: bttv does userspace copying, we'll get a
192 kernel pointer here... */
195 struct video_audio
*va
= arg
;
197 va
->flags
|= VIDEO_AUDIO_VOLUME
|
200 /* va->volume=MAX(tea->left,tea->right);
201 va->balance=(32768*MIN(tea->left,tea->right))/
202 (va->volume ? va->volume : 1);
203 va->balance=(tea->left<tea->right)?
204 (65535-va->balance) : va->balance;
205 va->bass = tea->bass;
206 va->treble = tea->treble;
212 /* tea->left = (MIN(65536 - va->balance,32768) *
214 tea->right = (MIN(va->balance,32768) *
216 tea->bass = va->bass;
217 tea->treble = va->treble;
228 static struct i2c_driver driver
= {
229 "i2c tea6420 driver",
230 I2C_DRIVERID_TEA6420
,
237 static struct i2c_client client_template
=
239 "(unset)", /* name */
248 int init_module(void)
250 int tea6420_init(void)
253 i2c_add_driver(&driver
);
258 void cleanup_module(void)
260 i2c_del_driver(&driver
);