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 <linux/config.h> /* CONFIG_RADIO_TERRATEC_PORT */
34 #include <linux/spinlock.h>
36 #ifndef CONFIG_RADIO_TERRATEC_PORT
37 #define CONFIG_RADIO_TERRATEC_PORT 0x590
40 /**************** this ones are for the terratec *******************/
41 #define BASEPORT 0x590
50 /*******************************************************************/
52 static int io
= CONFIG_RADIO_TERRATEC_PORT
;
53 static int radio_nr
= -1;
54 static spinlock_t lock
;
60 unsigned long curfreq
;
67 static void cardWriteVol(int volume
)
70 volume
= volume
+(volume
* 32); // change both channels
74 if (volume
& (0x80>>i
))
76 else outb(0x00, VOLPORT
);
83 static void tt_mute(struct tt_device
*dev
)
89 static int tt_setvol(struct tt_device
*dev
, int vol
)
92 // printk(KERN_ERR "setvol called, vol = %d\n", vol);
94 if(vol
== dev
->curvol
) { /* requested volume = current */
95 if (dev
->muted
) { /* user is unmuting the card */
97 cardWriteVol(vol
); /* enable card */
103 if(vol
== 0) { /* volume = 0 means mute the card */
104 cardWriteVol(0); /* "turn off card" by setting vol to 0 */
105 dev
->curvol
= vol
; /* track the volume state! */
120 /* this is the worst part in this driver */
121 /* many more or less strange things are going on here, but hey, it works :) */
123 static int tt_setfreq(struct tt_device
*dev
, unsigned long freq1
)
131 unsigned char buffer
[25]; /* we have to bit shift 25 registers */
132 freq
= freq1
/160; /* convert the freq. to a nice to handle value */
136 rest
= freq
*10+10700; /* i once had understood what is going on here */
137 /* maybe some wise guy (friedhelm?) can comment this stuff */
143 if (rest
%temp
== rest
)
157 for (i
=24;i
>-1;i
--) /* bit shift the values to the radiocard */
161 outb(WRT_EN
|DATA
, BASEPORT
);
162 outb(WRT_EN
|DATA
|CLK_ON
, BASEPORT
);
163 outb(WRT_EN
|DATA
, BASEPORT
);
167 outb(WRT_EN
|0x00, BASEPORT
);
168 outb(WRT_EN
|0x00|CLK_ON
, BASEPORT
);
171 outb(0x00, BASEPORT
);
178 static int tt_getsigstr(struct tt_device
*dev
) /* TODO */
180 if (inb(io
) & 2) /* bit set = no signal present */
182 return 1; /* signal present */
186 /* implement the video4linux api */
188 static int tt_do_ioctl(struct inode
*inode
, struct file
*file
,
189 unsigned int cmd
, void *arg
)
191 struct video_device
*dev
= video_devdata(file
);
192 struct tt_device
*tt
=dev
->priv
;
198 struct video_capability
*v
= arg
;
199 memset(v
,0,sizeof(*v
));
200 v
->type
=VID_TYPE_TUNER
;
203 strcpy(v
->name
, "ActiveRadio");
208 struct video_tuner
*v
= arg
;
209 if(v
->tuner
) /* Only 1 tuner */
211 v
->rangelow
=(87*16000);
212 v
->rangehigh
=(108*16000);
213 v
->flags
=VIDEO_TUNER_LOW
;
214 v
->mode
=VIDEO_MODE_AUTO
;
215 strcpy(v
->name
, "FM");
216 v
->signal
=0xFFFF*tt_getsigstr(tt
);
221 struct video_tuner
*v
= arg
;
224 /* Only 1 tuner so no setting needed ! */
229 unsigned long *freq
= arg
;
235 unsigned long *freq
= arg
;
237 tt_setfreq(tt
, tt
->curfreq
);
242 struct video_audio
*v
= arg
;
243 memset(v
,0, sizeof(*v
));
244 v
->flags
|=VIDEO_AUDIO_MUTABLE
|VIDEO_AUDIO_VOLUME
;
245 v
->volume
=tt
->curvol
* 6554;
247 strcpy(v
->name
, "Radio");
252 struct video_audio
*v
= arg
;
255 if(v
->flags
&VIDEO_AUDIO_MUTE
)
258 tt_setvol(tt
,v
->volume
/6554);
266 static int tt_ioctl(struct inode
*inode
, struct file
*file
,
267 unsigned int cmd
, unsigned long arg
)
269 return video_usercopy(inode
, file
, cmd
, arg
, tt_do_ioctl
);
272 static struct tt_device terratec_unit
;
274 static struct file_operations terratec_fops
= {
275 .owner
= THIS_MODULE
,
276 .open
= video_exclusive_open
,
277 .release
= video_exclusive_release
,
279 .compat_ioctl
= v4l_compat_ioctl32
,
283 static struct video_device terratec_radio
=
285 .owner
= THIS_MODULE
,
286 .name
= "TerraTec ActiveRadio",
287 .type
= VID_TYPE_TUNER
,
288 .hardware
= VID_HARDWARE_TERRATEC
,
289 .fops
= &terratec_fops
,
292 static int __init
terratec_init(void)
296 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
299 if (!request_region(io
, 2, "terratec"))
301 printk(KERN_ERR
"TerraTec: port 0x%x already in use\n", io
);
305 terratec_radio
.priv
=&terratec_unit
;
307 spin_lock_init(&lock
);
309 if(video_register_device(&terratec_radio
, VFL_TYPE_RADIO
, radio_nr
)==-1)
311 release_region(io
,2);
315 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver.\n");
317 /* mute card - prevents noisy bootups */
319 /* this ensures that the volume is all the way down */
321 terratec_unit
.curvol
= 0;
326 MODULE_AUTHOR("R.OFFERMANNS & others");
327 MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
328 MODULE_LICENSE("GPL");
329 module_param(io
, int, 0);
330 MODULE_PARM_DESC(io
, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)");
331 module_param(radio_nr
, int, 0);
333 static void __exit
terratec_cleanup_module(void)
335 video_unregister_device(&terratec_radio
);
336 release_region(io
,2);
337 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver unloaded.\n");
340 module_init(terratec_init
);
341 module_exit(terratec_cleanup_module
);