1 /* GemTek radio card driver for Linux (C) 1998 Jonas Munsin <jmunsin@iki.fi>
3 * GemTek hasn't released any specs on the card, so the protocol had to
4 * be reverse engineered with dosemu.
6 * Besides the protocol changes, this is mostly a copy of:
8 * RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
10 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
11 * Converted to new API by Alan Cox <Alan.Cox@linux.org>
12 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
14 * TODO: Allow for more than one of these foolish entities :-)
18 #include <linux/module.h> /* Modules */
19 #include <linux/init.h> /* Initdata */
20 #include <linux/ioport.h> /* request_region */
21 #include <linux/delay.h> /* udelay */
22 #include <asm/io.h> /* outb, outb_p */
23 #include <asm/uaccess.h> /* copy to/from user */
24 #include <linux/videodev.h> /* kernel radio structs */
25 #include <media/v4l2-common.h>
26 #include <linux/config.h> /* CONFIG_RADIO_GEMTEK_PORT */
27 #include <linux/spinlock.h>
29 #ifndef CONFIG_RADIO_GEMTEK_PORT
30 #define CONFIG_RADIO_GEMTEK_PORT -1
33 static int io = CONFIG_RADIO_GEMTEK_PORT;
34 static int radio_nr = -1;
35 static spinlock_t lock;
40 unsigned long curfreq;
47 /* the correct way to mute the gemtek may be to write the last written
48 * frequency || 0x10, but just writing 0x10 once seems to do it as well
50 static void gemtek_mute(struct gemtek_device *dev)
60 static void gemtek_unmute(struct gemtek_device *dev)
70 static void zero(void)
86 static int gemtek_setfreq(struct gemtek_device *dev, unsigned long freq)
90 /* freq = 78.25*((float)freq/16000.0 + 10.52); */
105 /* 28 frequency bits (lsb first) */
106 for (i = 0; i < 14; i++)
111 /* 36 unknown bits */
112 for (i = 0; i < 11; i++)
115 for (i = 0; i < 4; i++)
131 static int gemtek_getsigstr(struct gemtek_device *dev)
137 if (inb(io) & 8) /* bit set = no signal present */
139 return 1; /* signal present */
142 static int gemtek_do_ioctl(struct inode *inode, struct file *file,
143 unsigned int cmd, void *arg)
145 struct video_device *dev = video_devdata(file);
146 struct gemtek_device *rt=dev->priv;
152 struct video_capability *v = arg;
153 memset(v,0,sizeof(*v));
154 v->type=VID_TYPE_TUNER;
157 strcpy(v->name, "GemTek");
162 struct video_tuner *v = arg;
163 if(v->tuner) /* Only 1 tuner */
165 v->rangelow=87*16000;
166 v->rangehigh=108*16000;
167 v->flags=VIDEO_TUNER_LOW;
168 v->mode=VIDEO_MODE_AUTO;
169 v->signal=0xFFFF*gemtek_getsigstr(rt);
170 strcpy(v->name, "FM");
175 struct video_tuner *v = arg;
178 /* Only 1 tuner so no setting needed ! */
183 unsigned long *freq = arg;
189 unsigned long *freq = arg;
191 /* needs to be called twice in order for getsigstr to work */
192 gemtek_setfreq(rt, rt->curfreq);
193 gemtek_setfreq(rt, rt->curfreq);
198 struct video_audio *v = arg;
199 memset(v,0, sizeof(*v));
200 v->flags|=VIDEO_AUDIO_MUTABLE;
203 strcpy(v->name, "Radio");
208 struct video_audio *v = arg;
212 if(v->flags&VIDEO_AUDIO_MUTE)
224 static int gemtek_ioctl(struct inode *inode, struct file *file,
225 unsigned int cmd, unsigned long arg)
227 return video_usercopy(inode, file, cmd, arg, gemtek_do_ioctl);
230 static struct gemtek_device gemtek_unit;
232 static struct file_operations gemtek_fops = {
233 .owner = THIS_MODULE,
234 .open = video_exclusive_open,
235 .release = video_exclusive_release,
236 .ioctl = gemtek_ioctl,
237 .compat_ioctl = v4l_compat_ioctl32,
241 static struct video_device gemtek_radio=
243 .owner = THIS_MODULE,
244 .name = "GemTek radio",
245 .type = VID_TYPE_TUNER,
246 .hardware = VID_HARDWARE_GEMTEK,
247 .fops = &gemtek_fops,
250 static int __init gemtek_init(void)
254 printk(KERN_ERR "You must set an I/O address with io=0x20c, io=0x30c, io=0x24c or io=0x34c (io=0x020c or io=0x248 for the combined sound/radiocard)\n");
258 if (!request_region(io, 4, "gemtek"))
260 printk(KERN_ERR "gemtek: port 0x%x already in use\n", io);
264 gemtek_radio.priv=&gemtek_unit;
266 if(video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr)==-1)
268 release_region(io, 4);
271 printk(KERN_INFO "GemTek Radio Card driver.\n");
273 spin_lock_init(&lock);
275 /* this is _maybe_ unnecessary */
278 /* mute card - prevents noisy bootups */
279 gemtek_unit.muted = 0;
280 gemtek_mute(&gemtek_unit);
285 MODULE_AUTHOR("Jonas Munsin");
286 MODULE_DESCRIPTION("A driver for the GemTek Radio Card");
287 MODULE_LICENSE("GPL");
289 module_param(io, int, 0);
290 MODULE_PARM_DESC(io, "I/O address of the GemTek card (0x20c, 0x30c, 0x24c or 0x34c (0x20c or 0x248 have been reported to work for the combined sound/radiocard)).");
291 module_param(radio_nr, int, 0);
293 static void __exit gemtek_cleanup(void)
295 video_unregister_device(&gemtek_radio);
296 release_region(io,4);
299 module_init(gemtek_init);
300 module_exit(gemtek_cleanup);
304 compile-command: "gcc -c -DMODVERSIONS -D__KERNEL__ -DMODULE -O6 -Wall -Wstrict-prototypes -I /home/blp/tmp/linux-2.1.111-rtrack/include radio-rtrack2.c"