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 :-)
16 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
19 #include <linux/module.h> /* Modules */
20 #include <linux/init.h> /* Initdata */
21 #include <linux/ioport.h> /* request_region */
22 #include <linux/delay.h> /* udelay */
23 #include <asm/io.h> /* outb, outb_p */
24 #include <asm/uaccess.h> /* copy to/from user */
25 #include <linux/videodev2.h> /* kernel radio structs */
26 #include <media/v4l2-common.h>
27 #include <linux/spinlock.h>
29 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
30 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
32 static struct v4l2_queryctrl radio_qctrl[] = {
34 .id = V4L2_CID_AUDIO_MUTE,
39 .type = V4L2_CTRL_TYPE_BOOLEAN,
41 .id = V4L2_CID_AUDIO_VOLUME,
46 .default_value = 0xff,
47 .type = V4L2_CTRL_TYPE_INTEGER,
51 #ifndef CONFIG_RADIO_GEMTEK_PORT
52 #define CONFIG_RADIO_GEMTEK_PORT -1
55 static int io = CONFIG_RADIO_GEMTEK_PORT;
56 static int radio_nr = -1;
57 static spinlock_t lock;
62 unsigned long curfreq;
69 /* the correct way to mute the gemtek may be to write the last written
70 * frequency || 0x10, but just writing 0x10 once seems to do it as well
72 static void gemtek_mute(struct gemtek_device *dev)
82 static void gemtek_unmute(struct gemtek_device *dev)
92 static void zero(void)
100 static void one(void)
108 static int gemtek_setfreq(struct gemtek_device *dev, unsigned long freq)
112 /* freq = 78.25*((float)freq/16000.0 + 10.52); */
127 /* 28 frequency bits (lsb first) */
128 for (i = 0; i < 14; i++)
133 /* 36 unknown bits */
134 for (i = 0; i < 11; i++)
137 for (i = 0; i < 4; i++)
153 static int gemtek_getsigstr(struct gemtek_device *dev)
159 if (inb(io) & 8) /* bit set = no signal present */
161 return 1; /* signal present */
164 static int gemtek_do_ioctl(struct inode *inode, struct file *file,
165 unsigned int cmd, void *arg)
167 struct video_device *dev = video_devdata(file);
168 struct gemtek_device *rt=dev->priv;
172 case VIDIOC_QUERYCAP:
174 struct v4l2_capability *v = arg;
175 memset(v,0,sizeof(*v));
176 strlcpy(v->driver, "radio-gemtek", sizeof (v->driver));
177 strlcpy(v->card, "GemTek", sizeof (v->card));
178 sprintf(v->bus_info,"ISA");
179 v->version = RADIO_VERSION;
180 v->capabilities = V4L2_CAP_TUNER;
186 struct v4l2_tuner *v = arg;
191 memset(v,0,sizeof(*v));
192 strcpy(v->name, "FM");
193 v->type = V4L2_TUNER_RADIO;
195 v->rangelow=(87*16000);
196 v->rangehigh=(108*16000);
197 v->rxsubchans =V4L2_TUNER_SUB_MONO;
198 v->capability=V4L2_TUNER_CAP_LOW;
199 v->audmode = V4L2_TUNER_MODE_MONO;
200 v->signal=0xFFFF*gemtek_getsigstr(rt);
206 struct v4l2_tuner *v = arg;
213 case VIDIOC_S_FREQUENCY:
215 struct v4l2_frequency *f = arg;
217 rt->curfreq = f->frequency;
218 /* needs to be called twice in order for getsigstr to work */
219 gemtek_setfreq(rt, rt->curfreq);
220 gemtek_setfreq(rt, rt->curfreq);
223 case VIDIOC_G_FREQUENCY:
225 struct v4l2_frequency *f = arg;
227 f->type = V4L2_TUNER_RADIO;
228 f->frequency = rt->curfreq;
232 case VIDIOC_QUERYCTRL:
234 struct v4l2_queryctrl *qc = arg;
237 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
238 if (qc->id && qc->id == radio_qctrl[i].id) {
239 memcpy(qc, &(radio_qctrl[i]),
248 struct v4l2_control *ctrl= arg;
251 case V4L2_CID_AUDIO_MUTE:
252 ctrl->value=rt->muted;
254 case V4L2_CID_AUDIO_VOLUME:
265 struct v4l2_control *ctrl= arg;
268 case V4L2_CID_AUDIO_MUTE:
275 case V4L2_CID_AUDIO_VOLUME:
286 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
291 static int gemtek_ioctl(struct inode *inode, struct file *file,
292 unsigned int cmd, unsigned long arg)
294 return video_usercopy(inode, file, cmd, arg, gemtek_do_ioctl);
297 static struct gemtek_device gemtek_unit;
299 static const struct file_operations gemtek_fops = {
300 .owner = THIS_MODULE,
301 .open = video_exclusive_open,
302 .release = video_exclusive_release,
303 .ioctl = gemtek_ioctl,
304 .compat_ioctl = v4l_compat_ioctl32,
308 static struct video_device gemtek_radio=
310 .owner = THIS_MODULE,
311 .name = "GemTek radio",
312 .type = VID_TYPE_TUNER,
314 .fops = &gemtek_fops,
317 static int __init gemtek_init(void)
321 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");
325 if (!request_region(io, 4, "gemtek"))
327 printk(KERN_ERR "gemtek: port 0x%x already in use\n", io);
331 gemtek_radio.priv=&gemtek_unit;
333 if(video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr)==-1)
335 release_region(io, 4);
338 printk(KERN_INFO "GemTek Radio Card driver.\n");
340 spin_lock_init(&lock);
342 /* this is _maybe_ unnecessary */
345 /* mute card - prevents noisy bootups */
346 gemtek_unit.muted = 0;
347 gemtek_mute(&gemtek_unit);
352 MODULE_AUTHOR("Jonas Munsin");
353 MODULE_DESCRIPTION("A driver for the GemTek Radio Card");
354 MODULE_LICENSE("GPL");
356 module_param(io, int, 0);
357 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)).");
358 module_param(radio_nr, int, 0);
360 static void __exit gemtek_cleanup(void)
362 video_unregister_device(&gemtek_radio);
363 release_region(io,4);
366 module_init(gemtek_init);
367 module_exit(gemtek_cleanup);
371 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"