1 /* Terratec ActiveRadio ISA Standalone card driver for Linux radio support
2 * (c) 1999 R. Offermanns (rolf@offermanns.de)
3 * based on the aimslab radio driver from M. Kirkwood
4 * many thanks to Michael Becker and Friedhelm Birth (from TerraTec)
8 * 1999-05-21 First preview release
10 * Notes on the hardware:
11 * There are two "main" chips on the card:
12 * - Philips OM5610 (http://www-us.semiconductors.philips.com/acrobat/datasheets/OM5610_2.pdf)
13 * - Philips SAA6588 (http://www-us.semiconductors.philips.com/acrobat/datasheets/SAA6588_1.pdf)
14 * (you can get the datasheet at the above links)
16 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
17 * Volume Control is done digitally
19 * there is a I2C controlled RDS decoder (SAA6588) onboard, which i would like to support someday
20 * (as soon i have understand how to get started :)
21 * If you can help me out with that, please contact me!!
26 #include <linux/module.h> /* Modules */
27 #include <linux/init.h> /* Initdata */
28 #include <linux/ioport.h> /* request_region */
29 #include <linux/delay.h> /* udelay */
30 #include <asm/io.h> /* outb, outb_p */
31 #include <asm/uaccess.h> /* copy to/from user */
32 #include <linux/videodev.h> /* kernel radio structs */
33 #include <media/v4l2-common.h>
34 #include <linux/config.h> /* CONFIG_RADIO_TERRATEC_PORT */
35 #include <linux/spinlock.h>
37 #ifndef CONFIG_RADIO_TERRATEC_PORT
38 #define CONFIG_RADIO_TERRATEC_PORT 0x590
41 /**************** this ones are for the terratec *******************/
42 #define BASEPORT 0x590
51 /*******************************************************************/
53 static int io = CONFIG_RADIO_TERRATEC_PORT;
54 static int radio_nr = -1;
55 static spinlock_t lock;
61 unsigned long curfreq;
68 static void cardWriteVol(int volume)
71 volume = volume+(volume * 32); // change both channels
75 if (volume & (0x80>>i))
77 else outb(0x00, VOLPORT);
84 static void tt_mute(struct tt_device *dev)
90 static int tt_setvol(struct tt_device *dev, int vol)
93 // printk(KERN_ERR "setvol called, vol = %d\n", vol);
95 if(vol == dev->curvol) { /* requested volume = current */
96 if (dev->muted) { /* user is unmuting the card */
98 cardWriteVol(vol); /* enable card */
104 if(vol == 0) { /* volume = 0 means mute the card */
105 cardWriteVol(0); /* "turn off card" by setting vol to 0 */
106 dev->curvol = vol; /* track the volume state! */
121 /* this is the worst part in this driver */
122 /* many more or less strange things are going on here, but hey, it works :) */
124 static int tt_setfreq(struct tt_device *dev, unsigned long freq1)
132 unsigned char buffer[25]; /* we have to bit shift 25 registers */
133 freq = freq1/160; /* convert the freq. to a nice to handle value */
137 rest = freq*10+10700; /* i once had understood what is going on here */
138 /* maybe some wise guy (friedhelm?) can comment this stuff */
144 if (rest%temp == rest)
158 for (i=24;i>-1;i--) /* bit shift the values to the radiocard */
162 outb(WRT_EN|DATA, BASEPORT);
163 outb(WRT_EN|DATA|CLK_ON , BASEPORT);
164 outb(WRT_EN|DATA, BASEPORT);
168 outb(WRT_EN|0x00, BASEPORT);
169 outb(WRT_EN|0x00|CLK_ON , BASEPORT);
172 outb(0x00, BASEPORT);
179 static int tt_getsigstr(struct tt_device *dev) /* TODO */
181 if (inb(io) & 2) /* bit set = no signal present */
183 return 1; /* signal present */
187 /* implement the video4linux api */
189 static int tt_do_ioctl(struct inode *inode, struct file *file,
190 unsigned int cmd, void *arg)
192 struct video_device *dev = video_devdata(file);
193 struct tt_device *tt=dev->priv;
199 struct video_capability *v = arg;
200 memset(v,0,sizeof(*v));
201 v->type=VID_TYPE_TUNER;
204 strcpy(v->name, "ActiveRadio");
209 struct video_tuner *v = arg;
210 if(v->tuner) /* Only 1 tuner */
212 v->rangelow=(87*16000);
213 v->rangehigh=(108*16000);
214 v->flags=VIDEO_TUNER_LOW;
215 v->mode=VIDEO_MODE_AUTO;
216 strcpy(v->name, "FM");
217 v->signal=0xFFFF*tt_getsigstr(tt);
222 struct video_tuner *v = arg;
225 /* Only 1 tuner so no setting needed ! */
230 unsigned long *freq = arg;
236 unsigned long *freq = arg;
238 tt_setfreq(tt, tt->curfreq);
243 struct video_audio *v = arg;
244 memset(v,0, sizeof(*v));
245 v->flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME;
246 v->volume=tt->curvol * 6554;
248 strcpy(v->name, "Radio");
253 struct video_audio *v = arg;
256 if(v->flags&VIDEO_AUDIO_MUTE)
259 tt_setvol(tt,v->volume/6554);
267 static int tt_ioctl(struct inode *inode, struct file *file,
268 unsigned int cmd, unsigned long arg)
270 return video_usercopy(inode, file, cmd, arg, tt_do_ioctl);
273 static struct tt_device terratec_unit;
275 static struct file_operations terratec_fops = {
276 .owner = THIS_MODULE,
277 .open = video_exclusive_open,
278 .release = video_exclusive_release,
280 .compat_ioctl = v4l_compat_ioctl32,
284 static struct video_device terratec_radio=
286 .owner = THIS_MODULE,
287 .name = "TerraTec ActiveRadio",
288 .type = VID_TYPE_TUNER,
289 .hardware = VID_HARDWARE_TERRATEC,
290 .fops = &terratec_fops,
293 static int __init terratec_init(void)
297 printk(KERN_ERR "You must set an I/O address with io=0x???\n");
300 if (!request_region(io, 2, "terratec"))
302 printk(KERN_ERR "TerraTec: port 0x%x already in use\n", io);
306 terratec_radio.priv=&terratec_unit;
308 spin_lock_init(&lock);
310 if(video_register_device(&terratec_radio, VFL_TYPE_RADIO, radio_nr)==-1)
312 release_region(io,2);
316 printk(KERN_INFO "TERRATEC ActivRadio Standalone card driver.\n");
318 /* mute card - prevents noisy bootups */
320 /* this ensures that the volume is all the way down */
322 terratec_unit.curvol = 0;
327 MODULE_AUTHOR("R.OFFERMANNS & others");
328 MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
329 MODULE_LICENSE("GPL");
330 module_param(io, int, 0);
331 MODULE_PARM_DESC(io, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)");
332 module_param(radio_nr, int, 0);
334 static void __exit terratec_cleanup_module(void)
336 video_unregister_device(&terratec_radio);
337 release_region(io,2);
338 printk(KERN_INFO "TERRATEC ActivRadio Standalone card driver unloaded.\n");
341 module_init(terratec_init);
342 module_exit(terratec_cleanup_module);