1 /* radio-trust.c - Trust FM Radio card driver for Linux 2.2
2 * by Eric Lammerts <eric@scintilla.utwente.nl>
4 * Based on radio-aztech.c. Original notes:
6 * Adapted to support the Video for Linux API by
7 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
11 * Jason Lewis (jlewis@twilight.vtc.vsc.edu)
12 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
15 * The basis for this code may be found at http://bigbang.vtc.vsc.edu/fmradio/
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/ioport.h>
23 #include <asm/uaccess.h>
24 #include <linux/videodev.h>
25 #include <media/v4l2-common.h>
26 #include <linux/config.h> /* CONFIG_RADIO_TRUST_PORT */
28 /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
30 #ifndef CONFIG_RADIO_TRUST_PORT
31 #define CONFIG_RADIO_TRUST_PORT -1
34 static int io
= CONFIG_RADIO_TRUST_PORT
;
35 static int radio_nr
= -1;
36 static int ioval
= 0xf;
39 static __u16 curtreble
;
40 static unsigned long curfreq
;
45 #define TDA7318_ADDR 0x88
46 #define TSA6060T_ADDR 0xc4
48 #define TR_DELAY do { inb(io); inb(io); inb(io); } while(0)
49 #define TR_SET_SCL outb(ioval |= 2, io)
50 #define TR_CLR_SCL outb(ioval &= 0xfd, io)
51 #define TR_SET_SDA outb(ioval |= 1, io)
52 #define TR_CLR_SDA outb(ioval &= 0xfe, io)
54 static void write_i2c(int n
, ...)
56 unsigned char val
, mask
;
70 val
= va_arg(args
, unsigned);
71 for(mask
= 0x80; mask
; mask
>>= 1) {
100 static void tr_setvol(__u16 vol
)
103 write_i2c(2, TDA7318_ADDR
, curvol
^ 0x1f);
106 static int basstreble2chip
[15] = {
107 0, 1, 2, 3, 4, 5, 6, 7, 14, 13, 12, 11, 10, 9, 8
110 static void tr_setbass(__u16 bass
)
112 curbass
= bass
/ 4370;
113 write_i2c(2, TDA7318_ADDR
, 0x60 | basstreble2chip
[curbass
]);
116 static void tr_settreble(__u16 treble
)
118 curtreble
= treble
/ 4370;
119 write_i2c(2, TDA7318_ADDR
, 0x70 | basstreble2chip
[curtreble
]);
122 static void tr_setstereo(int stereo
)
124 curstereo
= !!stereo
;
125 ioval
= (ioval
& 0xfb) | (!curstereo
<< 2);
129 static void tr_setmute(int mute
)
132 ioval
= (ioval
& 0xf7) | (curmute
<< 3);
136 static int tr_getsigstr(void)
140 for(i
= 0, v
= 0; i
< 100; i
++) v
|= inb(io
);
141 return (v
& 1)? 0 : 0xffff;
144 static int tr_getstereo(void)
146 /* don't know how to determine it, just return the setting */
150 static void tr_setfreq(unsigned long f
)
152 f
/= 160; /* Convert to 10 kHz units */
153 f
+= 1070; /* Add 10.7 MHz IF */
155 write_i2c(5, TSA6060T_ADDR
, (f
<< 1) | 1, f
>> 7, 0x60 | ((f
>> 15) & 1), 0);
158 static int tr_do_ioctl(struct inode
*inode
, struct file
*file
,
159 unsigned int cmd
, void *arg
)
165 struct video_capability
*v
= arg
;
167 memset(v
,0,sizeof(*v
));
168 v
->type
=VID_TYPE_TUNER
;
171 strcpy(v
->name
, "Trust FM Radio");
177 struct video_tuner
*v
= arg
;
179 if(v
->tuner
) /* Only 1 tuner */
182 v
->rangelow
= 87500 * 16;
183 v
->rangehigh
= 108000 * 16;
184 v
->flags
= VIDEO_TUNER_LOW
;
185 v
->mode
= VIDEO_MODE_AUTO
;
187 v
->signal
= tr_getsigstr();
189 v
->flags
|= VIDEO_TUNER_STEREO_ON
;
191 strcpy(v
->name
, "FM");
197 struct video_tuner
*v
= arg
;
204 unsigned long *freq
= arg
;
210 unsigned long *freq
= arg
;
216 struct video_audio
*v
= arg
;
218 memset(v
,0, sizeof(*v
));
219 v
->flags
= VIDEO_AUDIO_MUTABLE
| VIDEO_AUDIO_VOLUME
|
220 VIDEO_AUDIO_BASS
| VIDEO_AUDIO_TREBLE
;
221 v
->mode
= curstereo
? VIDEO_SOUND_STEREO
: VIDEO_SOUND_MONO
;
222 v
->volume
= curvol
* 2048;
224 v
->bass
= curbass
* 4370;
225 v
->treble
= curtreble
* 4370;
227 strcpy(v
->name
, "Trust FM Radio");
232 struct video_audio
*v
= arg
;
236 tr_setvol(v
->volume
);
238 tr_settreble(v
->treble
);
239 tr_setstereo(v
->mode
& VIDEO_SOUND_STEREO
);
240 tr_setmute(v
->flags
& VIDEO_AUDIO_MUTE
);
248 static int tr_ioctl(struct inode
*inode
, struct file
*file
,
249 unsigned int cmd
, unsigned long arg
)
251 return video_usercopy(inode
, file
, cmd
, arg
, tr_do_ioctl
);
254 static struct file_operations trust_fops
= {
255 .owner
= THIS_MODULE
,
256 .open
= video_exclusive_open
,
257 .release
= video_exclusive_release
,
259 .compat_ioctl
= v4l_compat_ioctl32
,
263 static struct video_device trust_radio
=
265 .owner
= THIS_MODULE
,
266 .name
= "Trust FM Radio",
267 .type
= VID_TYPE_TUNER
,
268 .hardware
= VID_HARDWARE_TRUST
,
272 static int __init
trust_init(void)
275 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
278 if(!request_region(io
, 2, "Trust FM Radio")) {
279 printk(KERN_ERR
"trust: port 0x%x already in use\n", io
);
282 if(video_register_device(&trust_radio
, VFL_TYPE_RADIO
, radio_nr
)==-1)
284 release_region(io
, 2);
288 printk(KERN_INFO
"Trust FM Radio card driver v1.0.\n");
290 write_i2c(2, TDA7318_ADDR
, 0x80); /* speaker att. LF = 0 dB */
291 write_i2c(2, TDA7318_ADDR
, 0xa0); /* speaker att. RF = 0 dB */
292 write_i2c(2, TDA7318_ADDR
, 0xc0); /* speaker att. LR = 0 dB */
293 write_i2c(2, TDA7318_ADDR
, 0xe0); /* speaker att. RR = 0 dB */
294 write_i2c(2, TDA7318_ADDR
, 0x40); /* stereo 1 input, gain = 18.75 dB */
298 tr_settreble(0x8000);
301 /* mute card - prevents noisy bootups */
307 MODULE_AUTHOR("Eric Lammerts, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
308 MODULE_DESCRIPTION("A driver for the Trust FM Radio card.");
309 MODULE_LICENSE("GPL");
311 module_param(io
, int, 0);
312 MODULE_PARM_DESC(io
, "I/O address of the Trust FM Radio card (0x350 or 0x358)");
313 module_param(radio_nr
, int, 0);
315 static void __exit
cleanup_trust_module(void)
317 video_unregister_device(&trust_radio
);
318 release_region(io
, 2);
321 module_init(trust_init
);
322 module_exit(cleanup_trust_module
);