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 * Coverted 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 */
27 #ifndef CONFIG_RADIO_GEMTEK_PORT
28 #define CONFIG_RADIO_GEMTEK_PORT -1
31 static int io
= CONFIG_RADIO_GEMTEK_PORT
;
37 unsigned long curfreq
;
44 /* the correct way to mute the gemtek may be to write the last written
45 * frequency || 0x10, but just writing 0x10 once seems to do it as well
47 static void gemtek_mute(struct gemtek_device
*dev
)
55 static void gemtek_unmute(struct gemtek_device
*dev
)
63 static void zero(void)
79 static int gemtek_setfreq(struct gemtek_device
*dev
, unsigned long freq
)
83 /* freq = 78.25*((float)freq/16000.0 + 10.52); */
96 /* 28 frequency bits (lsb first) */
97 for (i
= 0; i
< 14; i
++)
102 /* 36 unknown bits */
103 for (i
= 0; i
< 11; i
++)
106 for (i
= 0; i
< 4; i
++)
120 int gemtek_getsigstr(struct gemtek_device
*dev
)
124 if (inb(io
) & 8) /* bit set = no signal present */
126 return 1; /* signal present */
129 static int gemtek_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
131 struct gemtek_device
*rt
=dev
->priv
;
137 struct video_capability v
;
138 v
.type
=VID_TYPE_TUNER
;
141 /* No we don't do pictures */
146 strcpy(v
.name
, "GemTek");
147 if(copy_to_user(arg
,&v
,sizeof(v
)))
153 struct video_tuner v
;
154 if(copy_from_user(&v
, arg
,sizeof(v
))!=0)
156 if(v
.tuner
) /* Only 1 tuner */
159 v
.rangehigh
=108*16000;
160 v
.flags
=VIDEO_TUNER_LOW
;
161 v
.mode
=VIDEO_MODE_AUTO
;
162 v
.signal
=0xFFFF*gemtek_getsigstr(rt
);
163 strcpy(v
.name
, "FM");
164 if(copy_to_user(arg
,&v
, sizeof(v
)))
170 struct video_tuner v
;
171 if(copy_from_user(&v
, arg
, sizeof(v
)))
175 /* Only 1 tuner so no setting needed ! */
179 if(copy_to_user(arg
, &rt
->curfreq
, sizeof(rt
->curfreq
)))
183 if(copy_from_user(&rt
->curfreq
, arg
,sizeof(rt
->curfreq
)))
185 /* needs to be called twice in order for getsigstr to work */
186 gemtek_setfreq(rt
, rt
->curfreq
);
187 gemtek_setfreq(rt
, rt
->curfreq
);
191 struct video_audio v
;
192 memset(&v
,0, sizeof(v
));
193 v
.flags
|=VIDEO_AUDIO_MUTABLE
;
196 strcpy(v
.name
, "Radio");
197 if(copy_to_user(arg
,&v
, sizeof(v
)))
203 struct video_audio v
;
204 if(copy_from_user(&v
, arg
, sizeof(v
)))
209 if(v
.flags
&VIDEO_AUDIO_MUTE
)
221 static int gemtek_open(struct video_device
*dev
, int flags
)
230 static void gemtek_close(struct video_device
*dev
)
236 static struct gemtek_device gemtek_unit
;
238 static struct video_device gemtek_radio
=
245 NULL
, /* Can't read (no capture ability) */
246 NULL
, /* Can't write */
247 NULL
, /* Can't poll */
253 __initfunc(int gemtek_init(struct video_init
*v
))
255 if (check_region(io
, 4))
257 printk(KERN_ERR
"gemtek: port 0x%x already in use\n", io
);
261 gemtek_radio
.priv
=&gemtek_unit
;
263 if(video_register_device(&gemtek_radio
, VFL_TYPE_RADIO
)==-1)
266 request_region(io
, 4, "gemtek");
267 printk(KERN_INFO
"GemTek Radio Card driver.\n");
269 /* mute card - prevents noisy bootups */
272 gemtek_unit
.muted
= 1;
274 /* this is _maybe_ unnecessary */
282 MODULE_AUTHOR("Jonas Munsin");
283 MODULE_DESCRIPTION("A driver for the GemTek Radio Card");
284 MODULE_PARM(io
, "i");
285 MODULE_PARM_DESC(io
, "I/O address of the GemTek card (0x20c, 0x30c, 0x24c or 0x34c)");
289 int init_module(void)
293 printk(KERN_ERR
"You must set an I/O address with io=0x20c, io=0x30c, io=0x24c or io=0x34c\n");
296 return gemtek_init(NULL
);
299 void cleanup_module(void)
301 video_unregister_device(&gemtek_radio
);
302 release_region(io
,4);
309 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"