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> /* check_region, 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 <linux/config.h> /* CONFIG_RADIO_TYPHOON_* */
41 #define BANNER "Typhoon Radio Card driver v0.1\n"
43 #ifndef CONFIG_RADIO_TYPHOON_PORT
44 #define CONFIG_RADIO_TYPHOON_PORT -1
47 #ifndef CONFIG_RADIO_TYPHOON_MUTEFREQ
48 #define CONFIG_RADIO_TYPHOON_MUTEFREQ 0
51 #ifndef CONFIG_PROC_FS
52 #undef CONFIG_RADIO_TYPHOON_PROC_FS
55 struct typhoon_device
{
60 unsigned long curfreq
;
61 unsigned long mutefreq
;
64 static void typhoon_setvol_generic(struct typhoon_device
*dev
, int vol
);
65 static int typhoon_setfreq_generic(struct typhoon_device
*dev
,
66 unsigned long frequency
);
67 static int typhoon_setfreq(struct typhoon_device
*dev
, unsigned long frequency
);
68 static void typhoon_mute(struct typhoon_device
*dev
);
69 static void typhoon_unmute(struct typhoon_device
*dev
);
70 static int typhoon_setvol(struct typhoon_device
*dev
, int vol
);
71 static int typhoon_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
);
72 static int typhoon_open(struct video_device
*dev
, int flags
);
73 static void typhoon_close(struct video_device
*dev
);
74 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
75 static int typhoon_read_proc(char *buf
, char **start
, off_t offset
, int len
,
79 int init_module(void);
80 void cleanup_module(void);
81 int typhoon_init(struct video_init
*v
);
83 int typhoon_init(struct video_init
*v
) __init
;
86 static void typhoon_setvol_generic(struct typhoon_device
*dev
, int vol
)
88 vol
>>= 14; /* Map 16 bit to 2 bit */
90 outb_p(vol
/ 2, dev
->iobase
); /* Set the volume, high bit. */
91 outb_p(vol
% 2, dev
->iobase
+ 2); /* Set the volume, low bit. */
94 static int typhoon_setfreq_generic(struct typhoon_device
*dev
,
95 unsigned long frequency
)
101 * The frequency transfer curve is not linear. The best fit I could
104 * outval = -155 + exp((f + 15.55) * 0.057))
106 * where frequency f is in MHz. Since we don't have exp in the kernel,
107 * I approximate this function by a third order polynomial.
112 outval
= (x
* x
+ 2500) / 5000;
113 outval
= (outval
* x
+ 5000) / 10000;
114 outval
-= (10 * x
* x
+ 10433) / 20866;
115 outval
+= 4 * x
- 11505;
117 outb_p((outval
>> 8) & 0x01, dev
->iobase
+ 4);
118 outb_p(outval
>> 9, dev
->iobase
+ 6);
119 outb_p(outval
& 0xff, dev
->iobase
+ 8);
124 static int typhoon_setfreq(struct typhoon_device
*dev
, unsigned long frequency
)
126 typhoon_setfreq_generic(dev
, frequency
);
127 dev
->curfreq
= frequency
;
131 static void typhoon_mute(struct typhoon_device
*dev
)
135 typhoon_setvol_generic(dev
, 0);
136 typhoon_setfreq_generic(dev
, dev
->mutefreq
);
140 static void typhoon_unmute(struct typhoon_device
*dev
)
144 typhoon_setfreq_generic(dev
, dev
->curfreq
);
145 typhoon_setvol_generic(dev
, dev
->curvol
);
149 static int typhoon_setvol(struct typhoon_device
*dev
, int vol
)
151 if (dev
->muted
&& vol
!= 0) { /* user is unmuting the card */
156 if (vol
== dev
->curvol
) /* requested volume == current */
159 if (vol
== 0) { /* volume == 0 means mute the card */
164 typhoon_setvol_generic(dev
, vol
);
170 static int typhoon_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
172 struct typhoon_device
*typhoon
= dev
->priv
;
177 struct video_capability v
;
178 v
.type
= VID_TYPE_TUNER
;
181 /* No we don't do pictures */
186 strcpy(v
.name
, "Typhoon Radio");
187 if (copy_to_user(arg
, &v
, sizeof(v
)))
193 struct video_tuner v
;
194 if (copy_from_user(&v
, arg
, sizeof(v
)) != 0)
196 if (v
.tuner
) /* Only 1 tuner */
198 v
.rangelow
= 875 * 1600;
199 v
.rangehigh
= 1080 * 1600;
200 v
.flags
= VIDEO_TUNER_LOW
;
201 v
.mode
= VIDEO_MODE_AUTO
;
202 v
.signal
= 0xFFFF; /* We can't get the signal strength */
203 strcpy(v
.name
, "FM");
204 if (copy_to_user(arg
, &v
, sizeof(v
)))
210 struct video_tuner v
;
211 if (copy_from_user(&v
, arg
, sizeof(v
)))
215 /* Only 1 tuner so no setting needed ! */
219 if (copy_to_user(arg
, &typhoon
->curfreq
,
220 sizeof(typhoon
->curfreq
)))
224 if (copy_from_user(&typhoon
->curfreq
, arg
,
225 sizeof(typhoon
->curfreq
)))
227 typhoon_setfreq(typhoon
, typhoon
->curfreq
);
231 struct video_audio v
;
232 memset(&v
, 0, sizeof(v
));
233 v
.flags
|= VIDEO_AUDIO_MUTABLE
| VIDEO_AUDIO_VOLUME
;
234 v
.mode
|= VIDEO_SOUND_MONO
;
235 v
.volume
= typhoon
->curvol
;
237 strcpy(v
.name
, "Typhoon Radio");
238 if (copy_to_user(arg
, &v
, sizeof(v
)))
244 struct video_audio v
;
245 if (copy_from_user(&v
, arg
, sizeof(v
)))
250 if (v
.flags
& VIDEO_AUDIO_MUTE
)
251 typhoon_mute(typhoon
);
253 typhoon_unmute(typhoon
);
255 if (v
.flags
& VIDEO_AUDIO_VOLUME
)
256 typhoon_setvol(typhoon
, v
.volume
);
265 static int typhoon_open(struct video_device
*dev
, int flags
)
267 struct typhoon_device
*typhoon
= dev
->priv
;
275 static void typhoon_close(struct video_device
*dev
)
277 struct typhoon_device
*typhoon
= dev
->priv
;
282 static struct typhoon_device typhoon_unit
=
285 CONFIG_RADIO_TYPHOON_PORT
, /* iobase */
288 CONFIG_RADIO_TYPHOON_MUTEFREQ
, /* curfreq */
289 CONFIG_RADIO_TYPHOON_MUTEFREQ
/* mutefreq */
292 static struct video_device typhoon_radio
=
296 VID_HARDWARE_TYPHOON
,
299 NULL
, /* Can't read (no capture ability) */
300 NULL
, /* Can't write */
301 NULL
, /* Can't poll */
307 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
309 static int typhoon_read_proc(char *buf
, char **start
, off_t offset
, int len
,
313 #define MODULEPROCSTRING "Driver loaded as a module"
315 #define MODULEPROCSTRING "Driver compiled into kernel"
318 #define LIMIT (PAGE_SIZE - 80)
321 len
+= sprintf(buf
+ len
, BANNER
);
322 if (len
> LIMIT
) return len
;
323 len
+= sprintf(buf
+ len
, "Load type: " MODULEPROCSTRING
"\n\n");
324 if (len
> LIMIT
) return len
;
325 len
+= sprintf(buf
+ len
, "frequency = %lu kHz\n",
326 typhoon_unit
.curfreq
>> 4);
327 if (len
> LIMIT
) return len
;
328 len
+= sprintf(buf
+ len
, "volume = %d\n", typhoon_unit
.curvol
);
329 if (len
> LIMIT
) return len
;
330 len
+= sprintf(buf
+ len
, "mute = %s\n", typhoon_unit
.muted
?
332 if (len
> LIMIT
) return len
;
333 len
+= sprintf(buf
+ len
, "iobase = 0x%x\n", typhoon_unit
.iobase
);
334 if (len
> LIMIT
) return len
;
335 len
+= sprintf(buf
+ len
, "mute frequency = %lu kHz\n",
336 typhoon_unit
.mutefreq
>> 4);
340 static struct proc_dir_entry typhoon_proc_entry
= {
341 0, /* low_ino: inode is dynamic */
342 13, "radio-typhoon", /* length of name and name */
343 S_IFREG
| S_IRUGO
, /* mode */
344 1, 0, 0, /* nlinks, owner, group */
345 0, /* size -- not used */
346 NULL
, /* operations -- use default */
347 &typhoon_read_proc
, /* function used to read data */
351 #endif /* CONFIG_RADIO_TYPHOON_PROC_FS */
353 int typhoon_init(struct video_init
*v
)
355 printk(KERN_INFO BANNER
);
356 if (check_region(typhoon_unit
.iobase
, 8)) {
357 printk(KERN_ERR
"radio-typhoon: port 0x%x already in use\n",
358 typhoon_unit
.iobase
);
362 typhoon_radio
.priv
= &typhoon_unit
;
363 if (video_register_device(&typhoon_radio
, VFL_TYPE_RADIO
) == -1)
366 request_region(typhoon_unit
.iobase
, 8, "typhoon");
367 printk(KERN_INFO
"radio-typhoon: port 0x%x.\n", typhoon_unit
.iobase
);
368 printk(KERN_INFO
"radio-typhoon: mute frequency is %lu kHz.\n",
369 typhoon_unit
.mutefreq
);
370 typhoon_unit
.mutefreq
<<= 4;
372 /* mute card - prevents noisy bootups */
373 typhoon_mute(&typhoon_unit
);
375 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
377 if (proc_register(&proc_root
, &typhoon_proc_entry
))
378 printk(KERN_ERR
"radio-typhoon: registering /proc/radio-typhoon failed\n");
387 MODULE_AUTHOR("Dr. Henrik Seidel");
388 MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio).");
389 MODULE_PARM(io
, "i");
390 MODULE_PARM_DESC(io
, "I/O address of the Typhoon card (0x316 or 0x336)");
391 MODULE_PARM(mutefreq
, "i");
392 MODULE_PARM_DESC(mutefreq
, "Frequency used when muting the card (in kHz)");
397 static unsigned long mutefreq
= 0;
399 int init_module(void)
402 printk(KERN_ERR
"radio-typhoon: You must set an I/O address with io=0x316 or io=0x336\n");
405 typhoon_unit
.iobase
= io
;
407 if (mutefreq
< 87000 || mutefreq
> 108500) {
408 printk(KERN_ERR
"radio-typhoon: You must set a frequency (in kHz) used when muting the card,\n");
409 printk(KERN_ERR
"radio-typhoon: e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n");
412 typhoon_unit
.mutefreq
= mutefreq
;
414 return typhoon_init(NULL
);
417 void cleanup_module(void)
420 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
422 if (proc_unregister(&proc_root
, typhoon_proc_entry
.low_ino
))
423 printk(KERN_ERR
"radio-typhoon: unregistering /proc/radio-typhoon failed\n");
427 video_unregister_device(&typhoon_radio
);
428 release_region(io
, 8);