1 /* GemTek radio card driver for Linux (C) 1998 Jonas Munsin <jmunsin@iki.fi>
2  *
3  * GemTek hasn't released any specs on the card, so the protocol had to
4  * be reverse engineered with dosemu.
5  *
6  * Besides the protocol changes, this is mostly a copy of:
7  *
8  *    RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
9  *
10  *    Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
11  *    Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
12  *    Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
13  *
14  * TODO: Allow for more than one of these foolish entities :-)
15  *
16  * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
17  */
18 
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 <linux/videodev2.h>	/* kernel radio structs		*/
24 #include <linux/version.h>	/* for KERNEL_VERSION MACRO	*/
25 #include <linux/mutex.h>
26 #include <linux/io.h>		/* outb, outb_p			*/
27 #include <linux/uaccess.h>	/* copy to/from user		*/
28 #include <media/v4l2-ioctl.h>
29 #include <media/v4l2-device.h>
30 
31 #define RADIO_VERSION KERNEL_VERSION(0, 0, 3)
32 
33 /*
34  * Module info.
35  */
36 
37 MODULE_AUTHOR("Jonas Munsin, Pekka Sepp�nen <pexu@kapsi.fi>");
38 MODULE_DESCRIPTION("A driver for the GemTek Radio card.");
39 MODULE_LICENSE("GPL");
40 
41 /*
42  * Module params.
43  */
44 
45 #ifndef CONFIG_RADIO_GEMTEK_PORT
46 #define CONFIG_RADIO_GEMTEK_PORT -1
47 #endif
48 #ifndef CONFIG_RADIO_GEMTEK_PROBE
49 #define CONFIG_RADIO_GEMTEK_PROBE 1
50 #endif
51 
52 static int io		= CONFIG_RADIO_GEMTEK_PORT;
53 static int probe	= CONFIG_RADIO_GEMTEK_PROBE;
54 static int hardmute;
55 static int shutdown	= 1;
56 static int keepmuted	= 1;
57 static int initmute	= 1;
58 static int radio_nr	= -1;
59 
60 module_param(io, int, 0444);
61 MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic "
62 	 "probing is disabled or fails. The most common I/O ports are: 0x20c "
63 	 "0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to "
64 	 "work for the combined sound/radiocard).");
65 
66 module_param(probe, bool, 0444);
67 MODULE_PARM_DESC(probe, "Enable automatic device probing. Note: only the most "
68 	"common I/O ports used by the card are probed.");
69 
70 module_param(hardmute, bool, 0644);
71 MODULE_PARM_DESC(hardmute, "Enable `hard muting' by shutting down PLL, may "
72 	 "reduce static noise.");
73 
74 module_param(shutdown, bool, 0644);
75 MODULE_PARM_DESC(shutdown, "Enable shutting down PLL and muting line when "
76 	 "module is unloaded.");
77 
78 module_param(keepmuted, bool, 0644);
79 MODULE_PARM_DESC(keepmuted, "Keep card muted even when frequency is changed.");
80 
81 module_param(initmute, bool, 0444);
82 MODULE_PARM_DESC(initmute, "Mute card when module is loaded.");
83 
84 module_param(radio_nr, int, 0444);
85 
86 /*
87  * Functions for controlling the card.
88  */
89 #define GEMTEK_LOWFREQ	(87*16000)
90 #define GEMTEK_HIGHFREQ	(108*16000)
91 
92 /*
93  * Frequency calculation constants.  Intermediate frequency 10.52 MHz (nominal
94  * value 10.7 MHz), reference divisor 6.39 kHz (nominal 6.25 kHz).
95  */
96 #define FSCALE		8
97 #define IF_OFFSET	((unsigned int)(10.52 * 16000 * (1<<FSCALE)))
98 #define REF_FREQ	((unsigned int)(6.39 * 16 * (1<<FSCALE)))
99 
100 #define GEMTEK_CK		0x01	/* Clock signal			*/
101 #define GEMTEK_DA		0x02	/* Serial data			*/
102 #define GEMTEK_CE		0x04	/* Chip enable			*/
103 #define GEMTEK_NS		0x08	/* No signal			*/
104 #define GEMTEK_MT		0x10	/* Line mute			*/
105 #define GEMTEK_STDF_3_125_KHZ	0x01	/* Standard frequency 3.125 kHz	*/
106 #define GEMTEK_PLL_OFF		0x07	/* PLL off			*/
107 
108 #define BU2614_BUS_SIZE	32	/* BU2614 / BU2614FS bus size		*/
109 
110 #define SHORT_DELAY 5		/* usec */
111 #define LONG_DELAY 75		/* usec */
112 
113 struct gemtek {
114 	struct v4l2_device v4l2_dev;
115 	struct video_device vdev;
116 	struct mutex lock;
117 	unsigned long lastfreq;
118 	int muted;
119 	int verified;
120 	int io;
121 	u32 bu2614data;
122 };
123 
124 static struct gemtek gemtek_card;
125 
126 #define BU2614_FREQ_BITS 	16 /* D0..D15, Frequency data		*/
127 #define BU2614_PORT_BITS	3 /* P0..P2, Output port control data	*/
128 #define BU2614_VOID_BITS	4 /* unused 				*/
129 #define BU2614_FMES_BITS	1 /* CT, Frequency measurement beginning data */
130 #define BU2614_STDF_BITS	3 /* R0..R2, Standard frequency data	*/
131 #define BU2614_SWIN_BITS	1 /* S, Switch between FMIN / AMIN	*/
132 #define BU2614_SWAL_BITS        1 /* PS, Swallow counter division (AMIN only)*/
133 #define BU2614_VOID2_BITS	1 /* unused				*/
134 #define BU2614_FMUN_BITS	1 /* GT, Frequency measurement time & unlock */
135 #define BU2614_TEST_BITS	1 /* TS, Test data is input		*/
136 
137 #define BU2614_FREQ_SHIFT 	0
138 #define BU2614_PORT_SHIFT	(BU2614_FREQ_BITS + BU2614_FREQ_SHIFT)
139 #define BU2614_VOID_SHIFT	(BU2614_PORT_BITS + BU2614_PORT_SHIFT)
140 #define BU2614_FMES_SHIFT	(BU2614_VOID_BITS + BU2614_VOID_SHIFT)
141 #define BU2614_STDF_SHIFT	(BU2614_FMES_BITS + BU2614_FMES_SHIFT)
142 #define BU2614_SWIN_SHIFT	(BU2614_STDF_BITS + BU2614_STDF_SHIFT)
143 #define BU2614_SWAL_SHIFT	(BU2614_SWIN_BITS + BU2614_SWIN_SHIFT)
144 #define BU2614_VOID2_SHIFT	(BU2614_SWAL_BITS + BU2614_SWAL_SHIFT)
145 #define BU2614_FMUN_SHIFT	(BU2614_VOID2_BITS + BU2614_VOID2_SHIFT)
146 #define BU2614_TEST_SHIFT	(BU2614_FMUN_BITS + BU2614_FMUN_SHIFT)
147 
148 #define MKMASK(field)	(((1<<BU2614_##field##_BITS) - 1) << \
149 			BU2614_##field##_SHIFT)
150 #define BU2614_PORT_MASK	MKMASK(PORT)
151 #define BU2614_FREQ_MASK	MKMASK(FREQ)
152 #define BU2614_VOID_MASK	MKMASK(VOID)
153 #define BU2614_FMES_MASK	MKMASK(FMES)
154 #define BU2614_STDF_MASK	MKMASK(STDF)
155 #define BU2614_SWIN_MASK	MKMASK(SWIN)
156 #define BU2614_SWAL_MASK	MKMASK(SWAL)
157 #define BU2614_VOID2_MASK	MKMASK(VOID2)
158 #define BU2614_FMUN_MASK	MKMASK(FMUN)
159 #define BU2614_TEST_MASK	MKMASK(TEST)
160 
161 /*
162  * Set data which will be sent to BU2614FS.
163  */
164 #define gemtek_bu2614_set(dev, field, data) ((dev)->bu2614data = \
165 	((dev)->bu2614data & ~field##_MASK) | ((data) << field##_SHIFT))
166 
167 /*
168  * Transmit settings to BU2614FS over GemTek IC.
169  */
170 static void gemtek_bu2614_transmit(struct gemtek *gt)
171 {
172 	int i, bit, q, mute;
173 
174 	mutex_lock(&gt->lock);
175 
176 	mute = gt->muted ? GEMTEK_MT : 0x00;
177 
178 	outb_p(mute | GEMTEK_DA | GEMTEK_CK, gt->io);
179 	udelay(SHORT_DELAY);
180 	outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, gt->io);
181 	udelay(LONG_DELAY);
182 
183 	for (i = 0, q = gt->bu2614data; i < 32; i++, q >>= 1) {
184 		bit = (q & 1) ? GEMTEK_DA : 0;
185 		outb_p(mute | GEMTEK_CE | bit, gt->io);
186 		udelay(SHORT_DELAY);
187 		outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, gt->io);
188 		udelay(SHORT_DELAY);
189 	}
190 
191 	outb_p(mute | GEMTEK_DA | GEMTEK_CK, gt->io);
192 	udelay(SHORT_DELAY);
193 	outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, gt->io);
194 	udelay(LONG_DELAY);
195 
196 	mutex_unlock(&gt->lock);
197 }
198 
199 /*
200  * Calculate divisor from FM-frequency for BU2614FS (3.125 KHz STDF expected).
201  */
202 static unsigned long gemtek_convfreq(unsigned long freq)
203 {
204 	return ((freq<<FSCALE) + IF_OFFSET + REF_FREQ/2) / REF_FREQ;
205 }
206 
207 /*
208  * Set FM-frequency.
209  */
210 static void gemtek_setfreq(struct gemtek *gt, unsigned long freq)
211 {
212 	if (keepmuted && hardmute && gt->muted)
213 		return;
214 
215 	freq = clamp_val(freq, GEMTEK_LOWFREQ, GEMTEK_HIGHFREQ);
216 
217 	gt->lastfreq = freq;
218 	gt->muted = 0;
219 
220 	gemtek_bu2614_set(gt, BU2614_PORT, 0);
221 	gemtek_bu2614_set(gt, BU2614_FMES, 0);
222 	gemtek_bu2614_set(gt, BU2614_SWIN, 0);	/* FM-mode	*/
223 	gemtek_bu2614_set(gt, BU2614_SWAL, 0);
224 	gemtek_bu2614_set(gt, BU2614_FMUN, 1);	/* GT bit set	*/
225 	gemtek_bu2614_set(gt, BU2614_TEST, 0);
226 
227 	gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_STDF_3_125_KHZ);
228 	gemtek_bu2614_set(gt, BU2614_FREQ, gemtek_convfreq(freq));
229 
230 	gemtek_bu2614_transmit(gt);
231 }
232 
233 /*
234  * Set mute flag.
235  */
236 static void gemtek_mute(struct gemtek *gt)
237 {
238 	int i;
239 
240 	gt->muted = 1;
241 
242 	if (hardmute) {
243 		/* Turn off PLL, disable data output */
244 		gemtek_bu2614_set(gt, BU2614_PORT, 0);
245 		gemtek_bu2614_set(gt, BU2614_FMES, 0);	/* CT bit off	*/
246 		gemtek_bu2614_set(gt, BU2614_SWIN, 0);	/* FM-mode	*/
247 		gemtek_bu2614_set(gt, BU2614_SWAL, 0);
248 		gemtek_bu2614_set(gt, BU2614_FMUN, 0);	/* GT bit off	*/
249 		gemtek_bu2614_set(gt, BU2614_TEST, 0);
250 		gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_PLL_OFF);
251 		gemtek_bu2614_set(gt, BU2614_FREQ, 0);
252 		gemtek_bu2614_transmit(gt);
253 		return;
254 	}
255 
256 	mutex_lock(&gt->lock);
257 
258 	/* Read bus contents (CE, CK and DA). */
259 	i = inb_p(gt->io);
260 	/* Write it back with mute flag set. */
261 	outb_p((i >> 5) | GEMTEK_MT, gt->io);
262 	udelay(SHORT_DELAY);
263 
264 	mutex_unlock(&gt->lock);
265 }
266 
267 /*
268  * Unset mute flag.
269  */
270 static void gemtek_unmute(struct gemtek *gt)
271 {
272 	int i;
273 
274 	gt->muted = 0;
275 	if (hardmute) {
276 		/* Turn PLL back on. */
277 		gemtek_setfreq(gt, gt->lastfreq);
278 		return;
279 	}
280 	mutex_lock(&gt->lock);
281 
282 	i = inb_p(gt->io);
283 	outb_p(i >> 5, gt->io);
284 	udelay(SHORT_DELAY);
285 
286 	mutex_unlock(&gt->lock);
287 }
288 
289 /*
290  * Get signal strength (= stereo status).
291  */
292 static inline int gemtek_getsigstr(struct gemtek *gt)
293 {
294 	int sig;
295 
296 	mutex_lock(&gt->lock);
297 	sig = inb_p(gt->io) & GEMTEK_NS ? 0 : 1;
298 	mutex_unlock(&gt->lock);
299 	return sig;
300 }
301 
302 /*
303  * Check if requested card acts like GemTek Radio card.
304  */
305 static int gemtek_verify(struct gemtek *gt, int port)
306 {
307 	int i, q;
308 
309 	if (gt->verified == port)
310 		return 1;
311 
312 	mutex_lock(&gt->lock);
313 
314 	q = inb_p(port);	/* Read bus contents before probing. */
315 	/* Try to turn on CE, CK and DA respectively and check if card responds
316 	   properly. */
317 	for (i = 0; i < 3; ++i) {
318 		outb_p(1 << i, port);
319 		udelay(SHORT_DELAY);
320 
321 		if ((inb_p(port) & (~GEMTEK_NS)) != (0x17 | (1 << (i + 5)))) {
322 			mutex_unlock(&gt->lock);
323 			return 0;
324 		}
325 	}
326 	outb_p(q >> 5, port);	/* Write bus contents back. */
327 	udelay(SHORT_DELAY);
328 
329 	mutex_unlock(&gt->lock);
330 	gt->verified = port;
331 
332 	return 1;
333 }
334 
335 /*
336  * Automatic probing for card.
337  */
338 static int gemtek_probe(struct gemtek *gt)
339 {
340 	struct v4l2_device *v4l2_dev = &gt->v4l2_dev;
341 	int ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c };
342 	int i;
343 
344 	if (!probe) {
345 		v4l2_info(v4l2_dev, "Automatic device probing disabled.\n");
346 		return -1;
347 	}
348 
349 	v4l2_info(v4l2_dev, "Automatic device probing enabled.\n");
350 
351 	for (i = 0; i < ARRAY_SIZE(ioports); ++i) {
352 		v4l2_info(v4l2_dev, "Trying I/O port 0x%x...\n", ioports[i]);
353 
354 		if (!request_region(ioports[i], 1, "gemtek-probe")) {
355 			v4l2_warn(v4l2_dev, "I/O port 0x%x busy!\n",
356 			       ioports[i]);
357 			continue;
358 		}
359 
360 		if (gemtek_verify(gt, ioports[i])) {
361 			v4l2_info(v4l2_dev, "Card found from I/O port "
362 			       "0x%x!\n", ioports[i]);
363 
364 			release_region(ioports[i], 1);
365 			gt->io = ioports[i];
366 			return gt->io;
367 		}
368 
369 		release_region(ioports[i], 1);
370 	}
371 
372 	v4l2_err(v4l2_dev, "Automatic probing failed!\n");
373 	return -1;
374 }
375 
376 /*
377  * Video 4 Linux stuff.
378  */
379 static int gemtek_open(struct file *file)
380 {
381 	return 0;
382 }
383 
384 static int gemtek_release(struct file *file)
385 {
386 	return 0;
387 }
388 
389 static const struct v4l2_file_operations gemtek_fops = {
390 	.owner		= THIS_MODULE,
391 	.open		= gemtek_open,
392 	.release	= gemtek_release,
393 	.ioctl		= video_ioctl2,
394 };
395 
396 static int vidioc_querycap(struct file *file, void *priv,
397 			   struct v4l2_capability *v)
398 {
399 	strlcpy(v->driver, "radio-gemtek", sizeof(v->driver));
400 	strlcpy(v->card, "GemTek", sizeof(v->card));
401 	strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
402 	v->version = RADIO_VERSION;
403 	v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
404 	return 0;
405 }
406 
407 static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
408 {
409 	struct gemtek *gt = video_drvdata(file);
410 
411 	if (v->index > 0)
412 		return -EINVAL;
413 
414 	strlcpy(v->name, "FM", sizeof(v->name));
415 	v->type = V4L2_TUNER_RADIO;
416 	v->rangelow = GEMTEK_LOWFREQ;
417 	v->rangehigh = GEMTEK_HIGHFREQ;
418 	v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
419 	v->signal = 0xffff * gemtek_getsigstr(gt);
420 	if (v->signal) {
421 		v->audmode = V4L2_TUNER_MODE_STEREO;
422 		v->rxsubchans = V4L2_TUNER_SUB_STEREO;
423 	} else {
424 		v->audmode = V4L2_TUNER_MODE_MONO;
425 		v->rxsubchans = V4L2_TUNER_SUB_MONO;
426 	}
427 	return 0;
428 }
429 
430 static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
431 {
432 	return (v->index != 0) ? -EINVAL : 0;
433 }
434 
435 static int vidioc_g_frequency(struct file *file, void *priv,
436 			      struct v4l2_frequency *f)
437 {
438 	struct gemtek *gt = video_drvdata(file);
439 
440 	if (f->tuner != 0)
441 		return -EINVAL;
442 	f->type = V4L2_TUNER_RADIO;
443 	f->frequency = gt->lastfreq;
444 	return 0;
445 }
446 
447 static int vidioc_s_frequency(struct file *file, void *priv,
448 			      struct v4l2_frequency *f)
449 {
450 	struct gemtek *gt = video_drvdata(file);
451 
452 	if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
453 		return -EINVAL;
454 	gemtek_setfreq(gt, f->frequency);
455 	return 0;
456 }
457 
458 static int vidioc_queryctrl(struct file *file, void *priv,
459 			    struct v4l2_queryctrl *qc)
460 {
461 	switch (qc->id) {
462 	case V4L2_CID_AUDIO_MUTE:
463 		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
464 	default:
465 		return -EINVAL;
466 	}
467 }
468 
469 static int vidioc_g_ctrl(struct file *file, void *priv,
470 			 struct v4l2_control *ctrl)
471 {
472 	struct gemtek *gt = video_drvdata(file);
473 
474 	switch (ctrl->id) {
475 	case V4L2_CID_AUDIO_MUTE:
476 		ctrl->value = gt->muted;
477 		return 0;
478 	}
479 	return -EINVAL;
480 }
481 
482 static int vidioc_s_ctrl(struct file *file, void *priv,
483 			 struct v4l2_control *ctrl)
484 {
485 	struct gemtek *gt = video_drvdata(file);
486 
487 	switch (ctrl->id) {
488 	case V4L2_CID_AUDIO_MUTE:
489 		if (ctrl->value)
490 			gemtek_mute(gt);
491 		else
492 			gemtek_unmute(gt);
493 		return 0;
494 	}
495 	return -EINVAL;
496 }
497 
498 static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
499 {
500 	*i = 0;
501 	return 0;
502 }
503 
504 static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
505 {
506 	return (i != 0) ? -EINVAL : 0;
507 }
508 
509 static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
510 {
511 	a->index = 0;
512 	strlcpy(a->name, "Radio", sizeof(a->name));
513 	a->capability = V4L2_AUDCAP_STEREO;
514 	return 0;
515 }
516 
517 static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
518 {
519 	return (a->index != 0) ? -EINVAL : 0;
520 }
521 
522 static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
523 	.vidioc_querycap	= vidioc_querycap,
524 	.vidioc_g_tuner		= vidioc_g_tuner,
525 	.vidioc_s_tuner		= vidioc_s_tuner,
526 	.vidioc_g_audio		= vidioc_g_audio,
527 	.vidioc_s_audio		= vidioc_s_audio,
528 	.vidioc_g_input		= vidioc_g_input,
529 	.vidioc_s_input		= vidioc_s_input,
530 	.vidioc_g_frequency	= vidioc_g_frequency,
531 	.vidioc_s_frequency	= vidioc_s_frequency,
532 	.vidioc_queryctrl	= vidioc_queryctrl,
533 	.vidioc_g_ctrl		= vidioc_g_ctrl,
534 	.vidioc_s_ctrl		= vidioc_s_ctrl
535 };
536 
537 /*
538  * Initialization / cleanup related stuff.
539  */
540 
541 static int __init gemtek_init(void)
542 {
543 	struct gemtek *gt = &gemtek_card;
544 	struct v4l2_device *v4l2_dev = &gt->v4l2_dev;
545 	int res;
546 
547 	strlcpy(v4l2_dev->name, "gemtek", sizeof(v4l2_dev->name));
548 
549 	v4l2_info(v4l2_dev, "GemTek Radio card driver: v0.0.3\n");
550 
551 	mutex_init(&gt->lock);
552 
553 	gt->verified = -1;
554 	gt->io = io;
555 	gemtek_probe(gt);
556 	if (gt->io) {
557 		if (!request_region(gt->io, 1, "gemtek")) {
558 			v4l2_err(v4l2_dev, "I/O port 0x%x already in use.\n", gt->io);
559 			return -EBUSY;
560 		}
561 
562 		if (!gemtek_verify(gt, gt->io))
563 			v4l2_warn(v4l2_dev, "Card at I/O port 0x%x does not "
564 			       "respond properly, check your "
565 			       "configuration.\n", gt->io);
566 		else
567 			v4l2_info(v4l2_dev, "Using I/O port 0x%x.\n", gt->io);
568 	} else if (probe) {
569 		v4l2_err(v4l2_dev, "Automatic probing failed and no "
570 		       "fixed I/O port defined.\n");
571 		return -ENODEV;
572 	} else {
573 		v4l2_err(v4l2_dev, "Automatic probing disabled but no fixed "
574 		       "I/O port defined.");
575 		return -EINVAL;
576 	}
577 
578 	res = v4l2_device_register(NULL, v4l2_dev);
579 	if (res < 0) {
580 		v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
581 		release_region(gt->io, 1);
582 		return res;
583 	}
584 
585 	strlcpy(gt->vdev.name, v4l2_dev->name, sizeof(gt->vdev.name));
586 	gt->vdev.v4l2_dev = v4l2_dev;
587 	gt->vdev.fops = &gemtek_fops;
588 	gt->vdev.ioctl_ops = &gemtek_ioctl_ops;
589 	gt->vdev.release = video_device_release_empty;
590 	video_set_drvdata(&gt->vdev, gt);
591 
592 	if (video_register_device(&gt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
593 		v4l2_device_unregister(v4l2_dev);
594 		release_region(gt->io, 1);
595 		return -EBUSY;
596 	}
597 
598 	/* Set defaults */
599 	gt->lastfreq = GEMTEK_LOWFREQ;
600 	gt->bu2614data = 0;
601 
602 	if (initmute)
603 		gemtek_mute(gt);
604 
605 	return 0;
606 }
607 
608 /*
609  * Module cleanup
610  */
611 static void __exit gemtek_exit(void)
612 {
613 	struct gemtek *gt = &gemtek_card;
614 	struct v4l2_device *v4l2_dev = &gt->v4l2_dev;
615 
616 	if (shutdown) {
617 		hardmute = 1;	/* Turn off PLL */
618 		gemtek_mute(gt);
619 	} else {
620 		v4l2_info(v4l2_dev, "Module unloaded but card not muted!\n");
621 	}
622 
623 	video_unregister_device(&gt->vdev);
624 	v4l2_device_unregister(&gt->v4l2_dev);
625 	release_region(gt->io, 1);
626 }
627 
628 module_init(gemtek_init);
629 module_exit(gemtek_exit);
630