2 * for the TDA8425 chip (I don't know which cards have this)
3 * WARNING: THIS DRIVER WILL LOAD WITHOUT COMPLAINTS EVEN IF A DIFFERENT
4 * CHIP IS AT ADDRESS 0x82 (it relies on i2c to make sure that there is a
5 * device acknowledging that address)
7 * Copyright (c) 1998 Greg Alexander <galexand@acm.org>
8 * This code is placed under the terms of the GNU General Public License
9 * Code liberally copied from msp3400.c, which is by Gerd Knorr
11 * All of this should work, though it would be nice to eventually support
12 * balance (different left,right values). Also, the chip seems (?) to have
13 * two stereo inputs, so if someone has this card, could they tell me if the
14 * second one can be used for anything (i.e., does it have an external input
15 * that you can't hear even if you set input to composite?)
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/string.h>
22 #include <linux/timer.h>
23 #include <linux/delay.h>
24 #include <linux/errno.h>
25 #include <linux/malloc.h>
26 #include <linux/videodev.h>
27 #include <linux/i2c.h>
28 #include <linux/i2c-algo-bit.h>
31 #include "audiochip.h"
33 /* Addresses to scan */
34 static unsigned short normal_i2c
[] = {
37 static unsigned short normal_i2c_range
[] = {I2C_CLIENT_END
};
38 static unsigned short probe
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
39 static unsigned short probe_range
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
40 static unsigned short ignore
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
41 static unsigned short ignore_range
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
42 static unsigned short force
[2] = { I2C_CLIENT_END
, I2C_CLIENT_END
};
43 static struct i2c_client_address_data addr_data
= {
44 normal_i2c
, normal_i2c_range
,
50 MODULE_PARM(debug
,"i");
51 static int debug
= 0; /* insmod parameter */
52 #define dprintk if (debug) printk
56 int mode
; /* set to AUDIO_{OFF,TUNER,RADIO,EXTERN} */
62 static struct i2c_driver driver
;
63 static struct i2c_client client_template
;
66 #define TDA8425_VL 0x00 /* volume left */
67 #define TDA8425_VR 0x01 /* volume right */
68 #define TDA8425_BA 0x02 /* bass */
69 #define TDA8425_TR 0x03 /* treble */
70 #define TDA8425_S1 0x08 /* switch functions */
71 /* values for those registers: */
72 #define TDA8425_S1_OFF 0xEE /* audio off (mute on) */
73 #define TDA8425_S1_ON 0xCE /* audio on (mute off) - "linear stereo" mode */
76 /* ******************************** *
77 * functions for talking to TDA8425 *
78 * ******************************** */
80 static int tda8425_write(struct i2c_client
*client
, int addr
, int val
)
82 unsigned char buffer
[2];
86 if (2 != i2c_master_send(client
,buffer
,2)) {
87 printk(KERN_WARNING
"tda8425: I/O error, trying (write %d 0x%x)\n",
94 static void tda8425_set(struct i2c_client
*client
)
96 struct tda8425
*tda
= client
->data
;
98 /* mode is ignored today */
99 dprintk(KERN_DEBUG
"tda8425_set(%04x,%04x,%04x,%04x)\n",tda
->left
>>10,tda
->right
>>10,tda
->bass
>>12,tda
->treble
>>12);
100 tda8425_write(client
, TDA8425_VL
, tda
->left
>>10 |0xC0);
101 tda8425_write(client
, TDA8425_VR
, tda
->right
>>10 |0xC0);
102 tda8425_write(client
, TDA8425_BA
, tda
->bass
>>12 |0xF0);
103 tda8425_write(client
, TDA8425_TR
, tda
->treble
>>12|0xF0);
106 static void do_tda8425_init(struct i2c_client
*client
)
108 struct tda8425
*tda
= client
->data
;
110 tda
->left
=tda
->right
=61440; /* 0dB */
111 tda
->bass
=tda
->treble
=24576; /* 0dB */
114 /* left=right=0x27<<10, bass=treble=0x07<<12 */
115 tda8425_write(client
, TDA8425_S1
, TDA8425_S1_OFF
); /* mute */
119 static void tda8425_audio(struct i2c_client
*client
, int mode
)
121 struct tda8425
*tda
= client
->data
;
123 /* valid for AUDIO_TUNER, RADIO, EXTERN, OFF */
124 dprintk(KERN_DEBUG
"tda8425_audio:%d (T,R,E,I,O)\n",mode
);
126 tda8425_write(client
, TDA8425_S1
,
127 (mode
==AUDIO_OFF
)?TDA8425_S1_OFF
:TDA8425_S1_ON
);
128 /* this is the function we'll need to change if it turns out the
129 * input-selecting capabilities should be used. */
133 /* *********************** *
134 * i2c interface functions *
135 * *********************** */
137 static int tda8425_attach(struct i2c_adapter
*adap
, int addr
,
138 unsigned short flags
, int kind
)
141 struct i2c_client
*client
;
143 client
= kmalloc(sizeof *client
,GFP_KERNEL
);
146 memcpy(client
,&client_template
,sizeof(struct i2c_client
));
147 client
->adapter
= adap
;
150 client
->data
= tda
= kmalloc(sizeof *tda
,GFP_KERNEL
);
153 memset(tda
,0,sizeof *tda
);
154 do_tda8425_init(client
);
156 strcpy(client
->name
,"TDA8425");
157 printk(KERN_INFO
"tda8425: init\n");
159 i2c_attach_client(client
);
163 static int tda8425_probe(struct i2c_adapter
*adap
)
165 if (adap
->id
== (I2C_ALGO_BIT
| I2C_HW_B_BT848
))
166 return i2c_probe(adap
, &addr_data
, tda8425_attach
);
171 static int tda8425_detach(struct i2c_client
*client
)
173 struct tda8425
*tda
= client
->data
;
175 do_tda8425_init(client
);
176 i2c_detach_client(client
);
184 static int tda8425_command(struct i2c_client
*client
,
185 unsigned int cmd
, void *arg
)
187 struct tda8425
*tda
= client
->data
;
192 tda8425_audio(client
,AUDIO_RADIO
);
195 tda8425_audio(client
,*sarg
);
198 /* --- v4l ioctls --- */
199 /* take care: bttv does userspace copying, we'll get a
200 kernel pointer here... */
203 struct video_audio
*va
= arg
;
205 va
->flags
|= VIDEO_AUDIO_VOLUME
|
208 va
->volume
=MAX(tda
->left
,tda
->right
);
209 va
->balance
=(32768*MIN(tda
->left
,tda
->right
))/
210 (va
->volume
? va
->volume
: 1);
211 va
->balance
=(tda
->left
<tda
->right
)?
212 (65535-va
->balance
) : va
->balance
;
213 va
->bass
= tda
->bass
;
214 va
->treble
= tda
->treble
;
219 struct video_audio
*va
= arg
;
221 tda
->left
= (MIN(65536 - va
->balance
,32768) *
223 tda
->right
= (MIN(va
->balance
,32768) *
225 tda
->bass
= va
->bass
;
226 tda
->treble
= va
->treble
;
232 /* --- old, obsolete interface --- */
233 case AUDC_GET_VOLUME_LEFT
:
236 case AUDC_GET_VOLUME_RIGHT
:
239 case AUDC_SET_VOLUME_LEFT
:
243 case AUDC_SET_VOLUME_RIGHT
:
256 case AUDC_GET_TREBLE
:
259 case AUDC_SET_TREBLE
:
264 case AUDC_GET_STEREO
:
265 *sarg
= tda
->stereo
?VIDEO_SOUND_STEREO
:VIDEO_SOUND_MONO
;
267 case AUDC_SET_STEREO
:
268 tda
->stereo
=(*sarg
==VIDEO_SOUND_MONO
)?0:1;
269 /* TODO: make this write to the TDA9850? */
272 /* case AUDC_SWITCH_MUTE: someday, maybe -- not a lot of point to
273 case AUDC_NEWCHANNEL: it and it would require preserving state
274 case AUDC_GET_DC: huh?? (not used by bttv.c)
284 static struct i2c_driver driver
= {
285 "i2c tda8424 driver",
286 I2C_DRIVERID_TDA8425
,
293 static struct i2c_client client_template
=
295 "(unset)", /* name */
304 int init_module(void)
306 int tda8425_init(void)
309 i2c_add_driver(&driver
);
314 void cleanup_module(void)
316 i2c_del_driver(&driver
);