xref: /openbmc/linux/drivers/media/radio/dsbr100.c (revision 82ced6fd)
1 /* A driver for the D-Link DSB-R100 USB radio and Gemtek USB Radio 21.
2  The device plugs into both the USB and an analog audio input, so this thing
3  only deals with initialisation and frequency setting, the
4  audio data has to be handled by a sound driver.
5 
6  Major issue: I can't find out where the device reports the signal
7  strength, and indeed the windows software appearantly just looks
8  at the stereo indicator as well.  So, scanning will only find
9  stereo stations.  Sad, but I can't help it.
10 
11  Also, the windows program sends oodles of messages over to the
12  device, and I couldn't figure out their meaning.  My suspicion
13  is that they don't have any:-)
14 
15  You might find some interesting stuff about this module at
16  http://unimut.fsk.uni-heidelberg.de/unimut/demi/dsbr
17 
18  Copyright (c) 2000 Markus Demleitner <msdemlei@cl.uni-heidelberg.de>
19 
20  This program is free software; you can redistribute it and/or modify
21  it under the terms of the GNU General Public License as published by
22  the Free Software Foundation; either version 2 of the License, or
23  (at your option) any later version.
24 
25  This program is distributed in the hope that it will be useful,
26  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  GNU General Public License for more details.
29 
30  You should have received a copy of the GNU General Public License
31  along with this program; if not, write to the Free Software
32  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 
34  History:
35 
36  Version 0.45:
37 	Converted to v4l2_device.
38 
39  Version 0.44:
40 	Add suspend/resume functions, fix unplug of device,
41 	a lot of cleanups and fixes by Alexey Klimov <klimov.linux@gmail.com>
42 
43  Version 0.43:
44 	Oliver Neukum: avoided DMA coherency issue
45 
46  Version 0.42:
47 	Converted dsbr100 to use video_ioctl2
48 	by Douglas Landgraf <dougsland@gmail.com>
49 
50  Version 0.41-ac1:
51 	Alan Cox: Some cleanups and fixes
52 
53  Version 0.41:
54 	Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
55 
56  Version 0.40:
57 	Markus: Updates for 2.6.x kernels, code layout changes, name sanitizing
58 
59  Version 0.30:
60 	Markus: Updates for 2.5.x kernel and more ISO compliant source
61 
62  Version 0.25:
63 	PSL and Markus: Cleanup, radio now doesn't stop on device close
64 
65  Version 0.24:
66 	Markus: Hope I got these silly VIDEO_TUNER_LOW issues finally
67 	right.  Some minor cleanup, improved standalone compilation
68 
69  Version 0.23:
70 	Markus: Sign extension bug fixed by declaring transfer_buffer unsigned
71 
72  Version 0.22:
73 	Markus: Some (brown bag) cleanup in what VIDIOCSTUNER returns,
74 	thanks to Mike Cox for pointing the problem out.
75 
76  Version 0.21:
77 	Markus: Minor cleanup, warnings if something goes wrong, lame attempt
78 	to adhere to Documentation/CodingStyle
79 
80  Version 0.2:
81 	Brad Hards <bradh@dynamite.com.au>: Fixes to make it work as non-module
82 	Markus: Copyright clarification
83 
84  Version 0.01: Markus: initial release
85 
86 */
87 
88 #include <linux/kernel.h>
89 #include <linux/module.h>
90 #include <linux/init.h>
91 #include <linux/slab.h>
92 #include <linux/input.h>
93 #include <linux/videodev2.h>
94 #include <media/v4l2-device.h>
95 #include <media/v4l2-ioctl.h>
96 #include <linux/usb.h>
97 
98 /*
99  * Version Information
100  */
101 #include <linux/version.h>	/* for KERNEL_VERSION MACRO	*/
102 
103 #define DRIVER_VERSION "v0.45"
104 #define RADIO_VERSION KERNEL_VERSION(0, 4, 5)
105 
106 #define DRIVER_AUTHOR "Markus Demleitner <msdemlei@tucana.harvard.edu>"
107 #define DRIVER_DESC "D-Link DSB-R100 USB FM radio driver"
108 
109 #define DSB100_VENDOR 0x04b4
110 #define DSB100_PRODUCT 0x1002
111 
112 /* Commands the device appears to understand */
113 #define DSB100_TUNE 1
114 #define DSB100_ONOFF 2
115 
116 #define TB_LEN 16
117 
118 /* Frequency limits in MHz -- these are European values.  For Japanese
119 devices, that would be 76 and 91.  */
120 #define FREQ_MIN  87.5
121 #define FREQ_MAX 108.0
122 #define FREQ_MUL 16000
123 
124 #define videodev_to_radio(d) container_of(d, struct dsbr100_device, videodev)
125 
126 static int usb_dsbr100_probe(struct usb_interface *intf,
127 			     const struct usb_device_id *id);
128 static void usb_dsbr100_disconnect(struct usb_interface *intf);
129 static int usb_dsbr100_open(struct file *file);
130 static int usb_dsbr100_close(struct file *file);
131 static int usb_dsbr100_suspend(struct usb_interface *intf,
132 						pm_message_t message);
133 static int usb_dsbr100_resume(struct usb_interface *intf);
134 
135 static int radio_nr = -1;
136 module_param(radio_nr, int, 0);
137 
138 /* Data for one (physical) device */
139 struct dsbr100_device {
140 	struct usb_device *usbdev;
141 	struct video_device videodev;
142 	struct v4l2_device v4l2_dev;
143 
144 	u8 *transfer_buffer;
145 	struct mutex lock;	/* buffer locking */
146 	int curfreq;
147 	int stereo;
148 	int users;
149 	int removed;
150 	int muted;
151 };
152 
153 static struct usb_device_id usb_dsbr100_device_table [] = {
154 	{ USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) },
155 	{ }						/* Terminating entry */
156 };
157 
158 MODULE_DEVICE_TABLE (usb, usb_dsbr100_device_table);
159 
160 /* USB subsystem interface */
161 static struct usb_driver usb_dsbr100_driver = {
162 	.name			= "dsbr100",
163 	.probe			= usb_dsbr100_probe,
164 	.disconnect		= usb_dsbr100_disconnect,
165 	.id_table		= usb_dsbr100_device_table,
166 	.suspend		= usb_dsbr100_suspend,
167 	.resume			= usb_dsbr100_resume,
168 	.reset_resume		= usb_dsbr100_resume,
169 	.supports_autosuspend	= 0,
170 };
171 
172 /* Low-level device interface begins here */
173 
174 /* switch on radio */
175 static int dsbr100_start(struct dsbr100_device *radio)
176 {
177 	int retval;
178 	int request;
179 
180 	mutex_lock(&radio->lock);
181 
182 	retval = usb_control_msg(radio->usbdev,
183 		usb_rcvctrlpipe(radio->usbdev, 0),
184 		USB_REQ_GET_STATUS,
185 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
186 		0x00, 0xC7, radio->transfer_buffer, 8, 300);
187 
188 	if (retval < 0) {
189 		request = USB_REQ_GET_STATUS;
190 		goto usb_control_msg_failed;
191 	}
192 
193 	retval = usb_control_msg(radio->usbdev,
194 		usb_rcvctrlpipe(radio->usbdev, 0),
195 		DSB100_ONOFF,
196 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
197 		0x01, 0x00, radio->transfer_buffer, 8, 300);
198 
199 	if (retval < 0) {
200 		request = DSB100_ONOFF;
201 		goto usb_control_msg_failed;
202 	}
203 
204 	radio->muted = 0;
205 	mutex_unlock(&radio->lock);
206 	return (radio->transfer_buffer)[0];
207 
208 usb_control_msg_failed:
209 	mutex_unlock(&radio->lock);
210 	dev_err(&radio->usbdev->dev,
211 		"%s - usb_control_msg returned %i, request %i\n",
212 			__func__, retval, request);
213 	return retval;
214 
215 }
216 
217 /* switch off radio */
218 static int dsbr100_stop(struct dsbr100_device *radio)
219 {
220 	int retval;
221 	int request;
222 
223 	mutex_lock(&radio->lock);
224 
225 	retval = usb_control_msg(radio->usbdev,
226 		usb_rcvctrlpipe(radio->usbdev, 0),
227 		USB_REQ_GET_STATUS,
228 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
229 		0x16, 0x1C, radio->transfer_buffer, 8, 300);
230 
231 	if (retval < 0) {
232 		request = USB_REQ_GET_STATUS;
233 		goto usb_control_msg_failed;
234 	}
235 
236 	retval = usb_control_msg(radio->usbdev,
237 		usb_rcvctrlpipe(radio->usbdev, 0),
238 		DSB100_ONOFF,
239 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
240 		0x00, 0x00, radio->transfer_buffer, 8, 300);
241 
242 	if (retval < 0) {
243 		request = DSB100_ONOFF;
244 		goto usb_control_msg_failed;
245 	}
246 
247 	radio->muted = 1;
248 	mutex_unlock(&radio->lock);
249 	return (radio->transfer_buffer)[0];
250 
251 usb_control_msg_failed:
252 	mutex_unlock(&radio->lock);
253 	dev_err(&radio->usbdev->dev,
254 		"%s - usb_control_msg returned %i, request %i\n",
255 			__func__, retval, request);
256 	return retval;
257 
258 }
259 
260 /* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
261 static int dsbr100_setfreq(struct dsbr100_device *radio, int freq)
262 {
263 	int retval;
264 	int request;
265 
266 	freq = (freq / 16 * 80) / 1000 + 856;
267 	mutex_lock(&radio->lock);
268 
269 	retval = usb_control_msg(radio->usbdev,
270 		usb_rcvctrlpipe(radio->usbdev, 0),
271 		DSB100_TUNE,
272 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
273 		(freq >> 8) & 0x00ff, freq & 0xff,
274 		radio->transfer_buffer, 8, 300);
275 
276 	if (retval < 0) {
277 		request = DSB100_TUNE;
278 		goto usb_control_msg_failed;
279 	}
280 
281 	retval = usb_control_msg(radio->usbdev,
282 		usb_rcvctrlpipe(radio->usbdev, 0),
283 		USB_REQ_GET_STATUS,
284 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
285 		0x96, 0xB7, radio->transfer_buffer, 8, 300);
286 
287 	if (retval < 0) {
288 		request = USB_REQ_GET_STATUS;
289 		goto usb_control_msg_failed;
290 	}
291 
292 	retval = usb_control_msg(radio->usbdev,
293 		usb_rcvctrlpipe(radio->usbdev, 0),
294 		USB_REQ_GET_STATUS,
295 		USB_TYPE_VENDOR | USB_RECIP_DEVICE |  USB_DIR_IN,
296 		0x00, 0x24, radio->transfer_buffer, 8, 300);
297 
298 	if (retval < 0) {
299 		request = USB_REQ_GET_STATUS;
300 		goto usb_control_msg_failed;
301 	}
302 
303 	radio->stereo = !((radio->transfer_buffer)[0] & 0x01);
304 	mutex_unlock(&radio->lock);
305 	return (radio->transfer_buffer)[0];
306 
307 usb_control_msg_failed:
308 	radio->stereo = -1;
309 	mutex_unlock(&radio->lock);
310 	dev_err(&radio->usbdev->dev,
311 		"%s - usb_control_msg returned %i, request %i\n",
312 			__func__, retval, request);
313 	return retval;
314 }
315 
316 /* return the device status.  This is, in effect, just whether it
317 sees a stereo signal or not.  Pity. */
318 static void dsbr100_getstat(struct dsbr100_device *radio)
319 {
320 	int retval;
321 
322 	mutex_lock(&radio->lock);
323 
324 	retval = usb_control_msg(radio->usbdev,
325 		usb_rcvctrlpipe(radio->usbdev, 0),
326 		USB_REQ_GET_STATUS,
327 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
328 		0x00 , 0x24, radio->transfer_buffer, 8, 300);
329 
330 	if (retval < 0) {
331 		radio->stereo = -1;
332 		dev_err(&radio->usbdev->dev,
333 			"%s - usb_control_msg returned %i, request %i\n",
334 				__func__, retval, USB_REQ_GET_STATUS);
335 	} else {
336 		radio->stereo = !(radio->transfer_buffer[0] & 0x01);
337 	}
338 
339 	mutex_unlock(&radio->lock);
340 }
341 
342 /* USB subsystem interface begins here */
343 
344 /*
345  * Handle unplugging of the device.
346  * We call video_unregister_device in any case.
347  * The last function called in this procedure is
348  * usb_dsbr100_video_device_release
349  */
350 static void usb_dsbr100_disconnect(struct usb_interface *intf)
351 {
352 	struct dsbr100_device *radio = usb_get_intfdata(intf);
353 
354 	usb_set_intfdata (intf, NULL);
355 
356 	mutex_lock(&radio->lock);
357 	radio->removed = 1;
358 	mutex_unlock(&radio->lock);
359 
360 	video_unregister_device(&radio->videodev);
361 	v4l2_device_disconnect(&radio->v4l2_dev);
362 }
363 
364 
365 static int vidioc_querycap(struct file *file, void *priv,
366 					struct v4l2_capability *v)
367 {
368 	struct dsbr100_device *radio = video_drvdata(file);
369 
370 	strlcpy(v->driver, "dsbr100", sizeof(v->driver));
371 	strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card));
372 	usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
373 	v->version = RADIO_VERSION;
374 	v->capabilities = V4L2_CAP_TUNER;
375 	return 0;
376 }
377 
378 static int vidioc_g_tuner(struct file *file, void *priv,
379 				struct v4l2_tuner *v)
380 {
381 	struct dsbr100_device *radio = video_drvdata(file);
382 
383 	/* safety check */
384 	if (radio->removed)
385 		return -EIO;
386 
387 	if (v->index > 0)
388 		return -EINVAL;
389 
390 	dsbr100_getstat(radio);
391 	strcpy(v->name, "FM");
392 	v->type = V4L2_TUNER_RADIO;
393 	v->rangelow = FREQ_MIN * FREQ_MUL;
394 	v->rangehigh = FREQ_MAX * FREQ_MUL;
395 	v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
396 	v->capability = V4L2_TUNER_CAP_LOW;
397 	if(radio->stereo)
398 		v->audmode = V4L2_TUNER_MODE_STEREO;
399 	else
400 		v->audmode = V4L2_TUNER_MODE_MONO;
401 	v->signal = 0xffff;     /* We can't get the signal strength */
402 	return 0;
403 }
404 
405 static int vidioc_s_tuner(struct file *file, void *priv,
406 				struct v4l2_tuner *v)
407 {
408 	struct dsbr100_device *radio = video_drvdata(file);
409 
410 	/* safety check */
411 	if (radio->removed)
412 		return -EIO;
413 
414 	if (v->index > 0)
415 		return -EINVAL;
416 
417 	return 0;
418 }
419 
420 static int vidioc_s_frequency(struct file *file, void *priv,
421 				struct v4l2_frequency *f)
422 {
423 	struct dsbr100_device *radio = video_drvdata(file);
424 	int retval;
425 
426 	/* safety check */
427 	if (radio->removed)
428 		return -EIO;
429 
430 	mutex_lock(&radio->lock);
431 	radio->curfreq = f->frequency;
432 	mutex_unlock(&radio->lock);
433 
434 	retval = dsbr100_setfreq(radio, radio->curfreq);
435 	if (retval < 0)
436 		dev_warn(&radio->usbdev->dev, "Set frequency failed\n");
437 	return 0;
438 }
439 
440 static int vidioc_g_frequency(struct file *file, void *priv,
441 				struct v4l2_frequency *f)
442 {
443 	struct dsbr100_device *radio = video_drvdata(file);
444 
445 	/* safety check */
446 	if (radio->removed)
447 		return -EIO;
448 
449 	f->type = V4L2_TUNER_RADIO;
450 	f->frequency = radio->curfreq;
451 	return 0;
452 }
453 
454 static int vidioc_queryctrl(struct file *file, void *priv,
455 				struct v4l2_queryctrl *qc)
456 {
457 	switch (qc->id) {
458 	case V4L2_CID_AUDIO_MUTE:
459 		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
460 	}
461 
462 	return -EINVAL;
463 }
464 
465 static int vidioc_g_ctrl(struct file *file, void *priv,
466 				struct v4l2_control *ctrl)
467 {
468 	struct dsbr100_device *radio = video_drvdata(file);
469 
470 	/* safety check */
471 	if (radio->removed)
472 		return -EIO;
473 
474 	switch (ctrl->id) {
475 	case V4L2_CID_AUDIO_MUTE:
476 		ctrl->value = radio->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 dsbr100_device *radio = video_drvdata(file);
486 	int retval;
487 
488 	/* safety check */
489 	if (radio->removed)
490 		return -EIO;
491 
492 	switch (ctrl->id) {
493 	case V4L2_CID_AUDIO_MUTE:
494 		if (ctrl->value) {
495 			retval = dsbr100_stop(radio);
496 			if (retval < 0) {
497 				dev_warn(&radio->usbdev->dev,
498 					 "Radio did not respond properly\n");
499 				return -EBUSY;
500 			}
501 		} else {
502 			retval = dsbr100_start(radio);
503 			if (retval < 0) {
504 				dev_warn(&radio->usbdev->dev,
505 					 "Radio did not respond properly\n");
506 				return -EBUSY;
507 			}
508 		}
509 		return 0;
510 	}
511 	return -EINVAL;
512 }
513 
514 static int vidioc_g_audio(struct file *file, void *priv,
515 				struct v4l2_audio *a)
516 {
517 	if (a->index > 1)
518 		return -EINVAL;
519 
520 	strcpy(a->name, "Radio");
521 	a->capability = V4L2_AUDCAP_STEREO;
522 	return 0;
523 }
524 
525 static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
526 {
527 	*i = 0;
528 	return 0;
529 }
530 
531 static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
532 {
533 	if (i != 0)
534 		return -EINVAL;
535 	return 0;
536 }
537 
538 static int vidioc_s_audio(struct file *file, void *priv,
539 					struct v4l2_audio *a)
540 {
541 	if (a->index != 0)
542 		return -EINVAL;
543 	return 0;
544 }
545 
546 static int usb_dsbr100_open(struct file *file)
547 {
548 	struct dsbr100_device *radio = video_drvdata(file);
549 	int retval;
550 
551 	lock_kernel();
552 	radio->users = 1;
553 	radio->muted = 1;
554 
555 	retval = dsbr100_start(radio);
556 	if (retval < 0) {
557 		dev_warn(&radio->usbdev->dev,
558 			 "Radio did not start up properly\n");
559 		radio->users = 0;
560 		unlock_kernel();
561 		return -EIO;
562 	}
563 
564 	retval = dsbr100_setfreq(radio, radio->curfreq);
565 	if (retval < 0)
566 		dev_warn(&radio->usbdev->dev,
567 			"set frequency failed\n");
568 
569 	unlock_kernel();
570 	return 0;
571 }
572 
573 static int usb_dsbr100_close(struct file *file)
574 {
575 	struct dsbr100_device *radio = video_drvdata(file);
576 	int retval;
577 
578 	if (!radio)
579 		return -ENODEV;
580 
581 	mutex_lock(&radio->lock);
582 	radio->users = 0;
583 	mutex_unlock(&radio->lock);
584 
585 	if (!radio->removed) {
586 		retval = dsbr100_stop(radio);
587 		if (retval < 0) {
588 			dev_warn(&radio->usbdev->dev,
589 				"dsbr100_stop failed\n");
590 		}
591 
592 	}
593 	return 0;
594 }
595 
596 /* Suspend device - stop device. */
597 static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message)
598 {
599 	struct dsbr100_device *radio = usb_get_intfdata(intf);
600 	int retval;
601 
602 	retval = dsbr100_stop(radio);
603 	if (retval < 0)
604 		dev_warn(&intf->dev, "dsbr100_stop failed\n");
605 
606 	dev_info(&intf->dev, "going into suspend..\n");
607 
608 	return 0;
609 }
610 
611 /* Resume device - start device. */
612 static int usb_dsbr100_resume(struct usb_interface *intf)
613 {
614 	struct dsbr100_device *radio = usb_get_intfdata(intf);
615 	int retval;
616 
617 	retval = dsbr100_start(radio);
618 	if (retval < 0)
619 		dev_warn(&intf->dev, "dsbr100_start failed\n");
620 
621 	dev_info(&intf->dev, "coming out of suspend..\n");
622 
623 	return 0;
624 }
625 
626 /* free data structures */
627 static void usb_dsbr100_video_device_release(struct video_device *videodev)
628 {
629 	struct dsbr100_device *radio = videodev_to_radio(videodev);
630 
631 	v4l2_device_unregister(&radio->v4l2_dev);
632 	kfree(radio->transfer_buffer);
633 	kfree(radio);
634 }
635 
636 /* File system interface */
637 static const struct v4l2_file_operations usb_dsbr100_fops = {
638 	.owner		= THIS_MODULE,
639 	.open		= usb_dsbr100_open,
640 	.release	= usb_dsbr100_close,
641 	.ioctl		= video_ioctl2,
642 };
643 
644 static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
645 	.vidioc_querycap    = vidioc_querycap,
646 	.vidioc_g_tuner     = vidioc_g_tuner,
647 	.vidioc_s_tuner     = vidioc_s_tuner,
648 	.vidioc_g_frequency = vidioc_g_frequency,
649 	.vidioc_s_frequency = vidioc_s_frequency,
650 	.vidioc_queryctrl   = vidioc_queryctrl,
651 	.vidioc_g_ctrl      = vidioc_g_ctrl,
652 	.vidioc_s_ctrl      = vidioc_s_ctrl,
653 	.vidioc_g_audio     = vidioc_g_audio,
654 	.vidioc_s_audio     = vidioc_s_audio,
655 	.vidioc_g_input     = vidioc_g_input,
656 	.vidioc_s_input     = vidioc_s_input,
657 };
658 
659 /* check if the device is present and register with v4l and usb if it is */
660 static int usb_dsbr100_probe(struct usb_interface *intf,
661 				const struct usb_device_id *id)
662 {
663 	struct dsbr100_device *radio;
664 	struct v4l2_device *v4l2_dev;
665 	int retval;
666 
667 	radio = kzalloc(sizeof(struct dsbr100_device), GFP_KERNEL);
668 
669 	if (!radio)
670 		return -ENOMEM;
671 
672 	radio->transfer_buffer = kmalloc(TB_LEN, GFP_KERNEL);
673 
674 	if (!(radio->transfer_buffer)) {
675 		kfree(radio);
676 		return -ENOMEM;
677 	}
678 
679 	v4l2_dev = &radio->v4l2_dev;
680 
681 	retval = v4l2_device_register(&intf->dev, v4l2_dev);
682 	if (retval < 0) {
683 		v4l2_err(v4l2_dev, "couldn't register v4l2_device\n");
684 		kfree(radio->transfer_buffer);
685 		kfree(radio);
686 		return retval;
687 	}
688 
689 	strlcpy(radio->videodev.name, v4l2_dev->name, sizeof(radio->videodev.name));
690 	radio->videodev.v4l2_dev = v4l2_dev;
691 	radio->videodev.fops = &usb_dsbr100_fops;
692 	radio->videodev.ioctl_ops = &usb_dsbr100_ioctl_ops;
693 	radio->videodev.release = usb_dsbr100_video_device_release;
694 
695 	mutex_init(&radio->lock);
696 
697 	radio->removed = 0;
698 	radio->users = 0;
699 	radio->usbdev = interface_to_usbdev(intf);
700 	radio->curfreq = FREQ_MIN * FREQ_MUL;
701 
702 	video_set_drvdata(&radio->videodev, radio);
703 
704 	retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr);
705 	if (retval < 0) {
706 		v4l2_err(v4l2_dev, "couldn't register video device\n");
707 		v4l2_device_unregister(v4l2_dev);
708 		kfree(radio->transfer_buffer);
709 		kfree(radio);
710 		return -EIO;
711 	}
712 	usb_set_intfdata(intf, radio);
713 	return 0;
714 }
715 
716 static int __init dsbr100_init(void)
717 {
718 	int retval = usb_register(&usb_dsbr100_driver);
719 	printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
720 	       DRIVER_DESC "\n");
721 	return retval;
722 }
723 
724 static void __exit dsbr100_exit(void)
725 {
726 	usb_deregister(&usb_dsbr100_driver);
727 }
728 
729 module_init (dsbr100_init);
730 module_exit (dsbr100_exit);
731 
732 MODULE_AUTHOR( DRIVER_AUTHOR );
733 MODULE_DESCRIPTION( DRIVER_DESC );
734 MODULE_LICENSE("GPL");
735