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> /* check_region, 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
;
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 handel 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 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_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
190 struct tt_device
*tt
=dev
->priv
;
196 struct video_capability v
;
197 v
.type
=VID_TYPE_TUNER
;
200 /* No we don't do pictures */
205 strcpy(v
.name
, "ActiveRadio");
206 if(copy_to_user(arg
,&v
,sizeof(v
)))
212 struct video_tuner v
;
213 if(copy_from_user(&v
, arg
,sizeof(v
))!=0)
215 if(v
.tuner
) /* Only 1 tuner */
217 v
.rangelow
=(87*16000);
218 v
.rangehigh
=(108*16000);
219 v
.flags
=VIDEO_TUNER_LOW
;
220 v
.mode
=VIDEO_MODE_AUTO
;
221 strcpy(v
.name
, "FM");
222 v
.signal
=0xFFFF*tt_getsigstr(tt
);
223 if(copy_to_user(arg
,&v
, sizeof(v
)))
229 struct video_tuner v
;
230 if(copy_from_user(&v
, arg
, sizeof(v
)))
234 /* Only 1 tuner so no setting needed ! */
238 if(copy_to_user(arg
, &tt
->curfreq
, sizeof(tt
->curfreq
)))
242 if(copy_from_user(&tt
->curfreq
, arg
,sizeof(tt
->curfreq
)))
244 tt_setfreq(tt
, tt
->curfreq
);
248 struct video_audio v
;
249 memset(&v
,0, sizeof(v
));
250 v
.flags
|=VIDEO_AUDIO_MUTABLE
|VIDEO_AUDIO_VOLUME
;
251 v
.volume
=tt
->curvol
* 6554;
253 strcpy(v
.name
, "Radio");
254 if(copy_to_user(arg
,&v
, sizeof(v
)))
260 struct video_audio v
;
261 if(copy_from_user(&v
, arg
, sizeof(v
)))
266 if(v
.flags
&VIDEO_AUDIO_MUTE
)
269 tt_setvol(tt
,v
.volume
/6554);
278 static int tt_open(struct video_device
*dev
, int flags
)
287 static void tt_close(struct video_device
*dev
)
293 static struct tt_device terratec_unit
;
295 static struct video_device terratec_radio
=
297 "TerraTec ActiveRadio",
299 VID_HARDWARE_TERRATEC
,
302 NULL
, /* Can't read (no capture ability) */
303 NULL
, /* Can't write */
310 static int __init
terratec_init(void)
314 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
317 if (check_region(io
, 2))
319 printk(KERN_ERR
"TerraTec: port 0x%x already in use\n", io
);
323 terratec_radio
.priv
=&terratec_unit
;
325 spin_lock_init(&lock
);
327 if(video_register_device(&terratec_radio
, VFL_TYPE_RADIO
)==-1)
330 request_region(io
, 2, "terratec");
331 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver.\n");
333 /* mute card - prevents noisy bootups */
335 /* this ensures that the volume is all the way down */
337 terratec_unit
.curvol
= 0;
342 MODULE_AUTHOR("R.OFFERMANNS & others");
343 MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
344 MODULE_PARM(io
, "i");
345 MODULE_PARM_DESC(io
, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)");
349 static void __exit
terratec_cleanup_module(void)
351 video_unregister_device(&terratec_radio
);
352 release_region(io
,2);
353 printk(KERN_INFO
"TERRATEC ActivRadio Standalone card driver unloaded.\n");
356 module_init(terratec_init
);
357 module_exit(terratec_cleanup_module
);