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> /* check_region, 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 <linux/config.h> /* CONFIG_RADIO_GEMTEK_PORT */
26 #include <linux/spinlock.h>
28 #ifndef CONFIG_RADIO_GEMTEK_PORT
29 #define CONFIG_RADIO_GEMTEK_PORT -1
32 static int io
= CONFIG_RADIO_GEMTEK_PORT
;
33 static int radio_nr
= -1;
34 static spinlock_t lock
;
39 unsigned long curfreq
;
46 /* the correct way to mute the gemtek may be to write the last written
47 * frequency || 0x10, but just writing 0x10 once seems to do it as well
49 static void gemtek_mute(struct gemtek_device
*dev
)
59 static void gemtek_unmute(struct gemtek_device
*dev
)
69 static void zero(void)
85 static int gemtek_setfreq(struct gemtek_device
*dev
, unsigned long freq
)
89 /* freq = 78.25*((float)freq/16000.0 + 10.52); */
104 /* 28 frequency bits (lsb first) */
105 for (i
= 0; i
< 14; i
++)
110 /* 36 unknown bits */
111 for (i
= 0; i
< 11; i
++)
114 for (i
= 0; i
< 4; i
++)
130 static int gemtek_getsigstr(struct gemtek_device
*dev
)
136 if (inb(io
) & 8) /* bit set = no signal present */
138 return 1; /* signal present */
141 static int gemtek_do_ioctl(struct inode
*inode
, struct file
*file
,
142 unsigned int cmd
, void *arg
)
144 struct video_device
*dev
= video_devdata(file
);
145 struct gemtek_device
*rt
=dev
->priv
;
151 struct video_capability
*v
= arg
;
152 memset(v
,0,sizeof(*v
));
153 v
->type
=VID_TYPE_TUNER
;
156 strcpy(v
->name
, "GemTek");
161 struct video_tuner
*v
= arg
;
162 if(v
->tuner
) /* Only 1 tuner */
164 v
->rangelow
=87*16000;
165 v
->rangehigh
=108*16000;
166 v
->flags
=VIDEO_TUNER_LOW
;
167 v
->mode
=VIDEO_MODE_AUTO
;
168 v
->signal
=0xFFFF*gemtek_getsigstr(rt
);
169 strcpy(v
->name
, "FM");
174 struct video_tuner
*v
= arg
;
177 /* Only 1 tuner so no setting needed ! */
182 unsigned long *freq
= arg
;
188 unsigned long *freq
= arg
;
190 /* needs to be called twice in order for getsigstr to work */
191 gemtek_setfreq(rt
, rt
->curfreq
);
192 gemtek_setfreq(rt
, rt
->curfreq
);
197 struct video_audio
*v
= arg
;
198 memset(v
,0, sizeof(*v
));
199 v
->flags
|=VIDEO_AUDIO_MUTABLE
;
202 strcpy(v
->name
, "Radio");
207 struct video_audio
*v
= arg
;
211 if(v
->flags
&VIDEO_AUDIO_MUTE
)
223 static int gemtek_ioctl(struct inode
*inode
, struct file
*file
,
224 unsigned int cmd
, unsigned long arg
)
226 return video_usercopy(inode
, file
, cmd
, arg
, gemtek_do_ioctl
);
229 static struct gemtek_device gemtek_unit
;
231 static struct file_operations gemtek_fops
= {
232 .owner
= THIS_MODULE
,
233 .open
= video_exclusive_open
,
234 .release
= video_exclusive_release
,
235 .ioctl
= gemtek_ioctl
,
239 static struct video_device gemtek_radio
=
241 .owner
= THIS_MODULE
,
242 .name
= "GemTek radio",
243 .type
= VID_TYPE_TUNER
,
244 .hardware
= VID_HARDWARE_GEMTEK
,
245 .fops
= &gemtek_fops
,
248 static int __init
gemtek_init(void)
252 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");
256 if (!request_region(io
, 4, "gemtek"))
258 printk(KERN_ERR
"gemtek: port 0x%x already in use\n", io
);
262 gemtek_radio
.priv
=&gemtek_unit
;
264 if(video_register_device(&gemtek_radio
, VFL_TYPE_RADIO
, radio_nr
)==-1)
266 release_region(io
, 4);
269 printk(KERN_INFO
"GemTek Radio Card driver.\n");
271 spin_lock_init(&lock
);
273 /* this is _maybe_ unnecessary */
276 /* mute card - prevents noisy bootups */
277 gemtek_unit
.muted
= 0;
278 gemtek_mute(&gemtek_unit
);
283 MODULE_AUTHOR("Jonas Munsin");
284 MODULE_DESCRIPTION("A driver for the GemTek Radio Card");
285 MODULE_LICENSE("GPL");
287 module_param(io
, int, 0);
288 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)).");
289 module_param(radio_nr
, int, 0);
291 static void __exit
gemtek_cleanup(void)
293 video_unregister_device(&gemtek_radio
);
294 release_region(io
,4);
297 module_init(gemtek_init
);
298 module_exit(gemtek_cleanup
);
302 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"