1 /* Typhoon Radio Card driver for radio support
2 * (c) 1999 Dr. Henrik Seidel <Henrik.Seidel@gmx.de>
5 * http://194.18.155.92/idc/prod2.idc?nr=50753&lang=e
7 * Notes on the hardware
9 * This card has two output sockets, one for speakers and one for line.
10 * The speaker output has volume control, but only in four discrete
11 * steps. The line output has neither volume control nor mute.
13 * The card has auto-stereo according to its manual, although it all
14 * sounds mono to me (even with the Win/DOS drivers). Maybe it's my
15 * antenna - I really don't know for sure.
17 * Frequency control is done digitally.
19 * Volume control is done digitally, but there are only four different
20 * possible values. So you should better always turn the volume up and
21 * use line control. I got the best results by connecting line output
22 * to the sound card microphone input. For such a configuration the
23 * volume control has no effect, since volume control only influences
26 * There is no explicit mute/unmute. So I set the radio frequency to a
27 * value where I do expect just noise and turn the speaker volume down.
28 * The frequency change is necessary since the card never seems to be
32 #include <linux/module.h> /* Modules */
33 #include <linux/init.h> /* Initdata */
34 #include <linux/ioport.h> /* request_region */
35 #include <linux/proc_fs.h> /* radio card status report */
36 #include <asm/io.h> /* outb, outb_p */
37 #include <asm/uaccess.h> /* copy to/from user */
38 #include <linux/videodev.h> /* kernel radio structs */
39 #include <media/v4l2-common.h>
40 #include <linux/config.h> /* CONFIG_RADIO_TYPHOON_* */
42 #define BANNER "Typhoon Radio Card driver v0.1\n"
44 #ifndef CONFIG_RADIO_TYPHOON_PORT
45 #define CONFIG_RADIO_TYPHOON_PORT -1
48 #ifndef CONFIG_RADIO_TYPHOON_MUTEFREQ
49 #define CONFIG_RADIO_TYPHOON_MUTEFREQ 0
52 #ifndef CONFIG_PROC_FS
53 #undef CONFIG_RADIO_TYPHOON_PROC_FS
56 struct typhoon_device {
61 unsigned long curfreq;
62 unsigned long mutefreq;
66 static void typhoon_setvol_generic(struct typhoon_device *dev, int vol);
67 static int typhoon_setfreq_generic(struct typhoon_device *dev,
68 unsigned long frequency);
69 static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency);
70 static void typhoon_mute(struct typhoon_device *dev);
71 static void typhoon_unmute(struct typhoon_device *dev);
72 static int typhoon_setvol(struct typhoon_device *dev, int vol);
73 static int typhoon_ioctl(struct inode *inode, struct file *file,
74 unsigned int cmd, unsigned long arg);
75 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
76 static int typhoon_get_info(char *buf, char **start, off_t offset, int len);
79 static void typhoon_setvol_generic(struct typhoon_device *dev, int vol)
81 mutex_lock(&dev->lock);
82 vol >>= 14; /* Map 16 bit to 2 bit */
84 outb_p(vol / 2, dev->iobase); /* Set the volume, high bit. */
85 outb_p(vol % 2, dev->iobase + 2); /* Set the volume, low bit. */
86 mutex_unlock(&dev->lock);
89 static int typhoon_setfreq_generic(struct typhoon_device *dev,
90 unsigned long frequency)
96 * The frequency transfer curve is not linear. The best fit I could
99 * outval = -155 + exp((f + 15.55) * 0.057))
101 * where frequency f is in MHz. Since we don't have exp in the kernel,
102 * I approximate this function by a third order polynomial.
106 mutex_lock(&dev->lock);
108 outval = (x * x + 2500) / 5000;
109 outval = (outval * x + 5000) / 10000;
110 outval -= (10 * x * x + 10433) / 20866;
111 outval += 4 * x - 11505;
113 outb_p((outval >> 8) & 0x01, dev->iobase + 4);
114 outb_p(outval >> 9, dev->iobase + 6);
115 outb_p(outval & 0xff, dev->iobase + 8);
116 mutex_unlock(&dev->lock);
121 static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency)
123 typhoon_setfreq_generic(dev, frequency);
124 dev->curfreq = frequency;
128 static void typhoon_mute(struct typhoon_device *dev)
132 typhoon_setvol_generic(dev, 0);
133 typhoon_setfreq_generic(dev, dev->mutefreq);
137 static void typhoon_unmute(struct typhoon_device *dev)
141 typhoon_setfreq_generic(dev, dev->curfreq);
142 typhoon_setvol_generic(dev, dev->curvol);
146 static int typhoon_setvol(struct typhoon_device *dev, int vol)
148 if (dev->muted && vol != 0) { /* user is unmuting the card */
153 if (vol == dev->curvol) /* requested volume == current */
156 if (vol == 0) { /* volume == 0 means mute the card */
161 typhoon_setvol_generic(dev, vol);
167 static int typhoon_do_ioctl(struct inode *inode, struct file *file,
168 unsigned int cmd, void *arg)
170 struct video_device *dev = video_devdata(file);
171 struct typhoon_device *typhoon = dev->priv;
176 struct video_capability *v = arg;
177 memset(v,0,sizeof(*v));
178 v->type = VID_TYPE_TUNER;
181 strcpy(v->name, "Typhoon Radio");
186 struct video_tuner *v = arg;
187 if (v->tuner) /* Only 1 tuner */
189 v->rangelow = 875 * 1600;
190 v->rangehigh = 1080 * 1600;
191 v->flags = VIDEO_TUNER_LOW;
192 v->mode = VIDEO_MODE_AUTO;
193 v->signal = 0xFFFF; /* We can't get the signal strength */
194 strcpy(v->name, "FM");
199 struct video_tuner *v = arg;
202 /* Only 1 tuner so no setting needed ! */
207 unsigned long *freq = arg;
208 *freq = typhoon->curfreq;
213 unsigned long *freq = arg;
214 typhoon->curfreq = *freq;
215 typhoon_setfreq(typhoon, typhoon->curfreq);
220 struct video_audio *v = arg;
221 memset(v, 0, sizeof(*v));
222 v->flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME;
223 v->mode |= VIDEO_SOUND_MONO;
224 v->volume = typhoon->curvol;
226 strcpy(v->name, "Typhoon Radio");
231 struct video_audio *v = arg;
234 if (v->flags & VIDEO_AUDIO_MUTE)
235 typhoon_mute(typhoon);
237 typhoon_unmute(typhoon);
238 if (v->flags & VIDEO_AUDIO_VOLUME)
239 typhoon_setvol(typhoon, v->volume);
247 static int typhoon_ioctl(struct inode *inode, struct file *file,
248 unsigned int cmd, unsigned long arg)
250 return video_usercopy(inode, file, cmd, arg, typhoon_do_ioctl);
253 static struct typhoon_device typhoon_unit =
255 .iobase = CONFIG_RADIO_TYPHOON_PORT,
256 .curfreq = CONFIG_RADIO_TYPHOON_MUTEFREQ,
257 .mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ,
260 static struct file_operations typhoon_fops = {
261 .owner = THIS_MODULE,
262 .open = video_exclusive_open,
263 .release = video_exclusive_release,
264 .ioctl = typhoon_ioctl,
265 .compat_ioctl = v4l_compat_ioctl32,
269 static struct video_device typhoon_radio =
271 .owner = THIS_MODULE,
272 .name = "Typhoon Radio",
273 .type = VID_TYPE_TUNER,
274 .hardware = VID_HARDWARE_TYPHOON,
275 .fops = &typhoon_fops,
278 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
280 static int typhoon_get_info(char *buf, char **start, off_t offset, int len)
285 #define MODULEPROCSTRING "Driver loaded as a module"
287 #define MODULEPROCSTRING "Driver compiled into kernel"
290 /* output must be kept under PAGE_SIZE */
291 out += sprintf(out, BANNER);
292 out += sprintf(out, "Load type: " MODULEPROCSTRING "\n\n");
293 out += sprintf(out, "frequency = %lu kHz\n",
294 typhoon_unit.curfreq >> 4);
295 out += sprintf(out, "volume = %d\n", typhoon_unit.curvol);
296 out += sprintf(out, "mute = %s\n", typhoon_unit.muted ?
298 out += sprintf(out, "iobase = 0x%x\n", typhoon_unit.iobase);
299 out += sprintf(out, "mute frequency = %lu kHz\n",
300 typhoon_unit.mutefreq >> 4);
304 #endif /* CONFIG_RADIO_TYPHOON_PROC_FS */
306 MODULE_AUTHOR("Dr. Henrik Seidel");
307 MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio).");
308 MODULE_LICENSE("GPL");
311 static int radio_nr = -1;
313 module_param(io, int, 0);
314 MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)");
315 module_param(radio_nr, int, 0);
318 static unsigned long mutefreq = 0;
319 module_param(mutefreq, ulong, 0);
320 MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)");
323 static int __init typhoon_init(void)
327 printk(KERN_ERR "radio-typhoon: You must set an I/O address with io=0x316 or io=0x336\n");
330 typhoon_unit.iobase = io;
332 if (mutefreq < 87000 || mutefreq > 108500) {
333 printk(KERN_ERR "radio-typhoon: You must set a frequency (in kHz) used when muting the card,\n");
334 printk(KERN_ERR "radio-typhoon: e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n");
337 typhoon_unit.mutefreq = mutefreq;
340 printk(KERN_INFO BANNER);
341 mutex_init(&typhoon_unit.lock);
342 io = typhoon_unit.iobase;
343 if (!request_region(io, 8, "typhoon")) {
344 printk(KERN_ERR "radio-typhoon: port 0x%x already in use\n",
345 typhoon_unit.iobase);
349 typhoon_radio.priv = &typhoon_unit;
350 if (video_register_device(&typhoon_radio, VFL_TYPE_RADIO, radio_nr) == -1)
352 release_region(io, 8);
355 printk(KERN_INFO "radio-typhoon: port 0x%x.\n", typhoon_unit.iobase);
356 printk(KERN_INFO "radio-typhoon: mute frequency is %lu kHz.\n",
357 typhoon_unit.mutefreq);
358 typhoon_unit.mutefreq <<= 4;
360 /* mute card - prevents noisy bootups */
361 typhoon_mute(&typhoon_unit);
363 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
364 if (!create_proc_info_entry("driver/radio-typhoon", 0, NULL,
366 printk(KERN_ERR "radio-typhoon: registering /proc/driver/radio-typhoon failed\n");
372 static void __exit typhoon_cleanup_module(void)
375 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
376 remove_proc_entry("driver/radio-typhoon", NULL);
379 video_unregister_device(&typhoon_radio);
380 release_region(io, 8);
383 module_init(typhoon_init);
384 module_exit(typhoon_cleanup_module);