aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/radio/radio-mr800.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/radio/radio-mr800.c')
-rw-r--r--drivers/media/radio/radio-mr800.c221
1 files changed, 152 insertions, 69 deletions
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
index fdfc7bf86b9e..ded25bfb366e 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -22,7 +22,7 @@
22 */ 22 */
23 23
24/* 24/*
25 * Big thanks to authors of dsbr100.c and radio-si470x.c 25 * Big thanks to authors and contributors of dsbr100.c and radio-si470x.c
26 * 26 *
27 * When work was looked pretty good, i discover this: 27 * When work was looked pretty good, i discover this:
28 * http://av-usbradio.sourceforge.net/index.php 28 * http://av-usbradio.sourceforge.net/index.php
@@ -30,18 +30,23 @@
30 * Latest release of theirs project was in 2005. 30 * Latest release of theirs project was in 2005.
31 * Probably, this driver could be improved trough using their 31 * Probably, this driver could be improved trough using their
32 * achievements (specifications given). 32 * achievements (specifications given).
33 * So, we have smth to begin with. 33 * Also, Faidon Liambotis <paravoid@debian.org> wrote nice driver for this radio
34 * in 2007. He allowed to use his driver to improve current mr800 radio driver.
35 * http://kerneltrap.org/mailarchive/linux-usb-devel/2007/10/11/342492
34 * 36 *
35 * History:
36 * Version 0.01: First working version. 37 * Version 0.01: First working version.
37 * It's required to blacklist AverMedia USB Radio 38 * It's required to blacklist AverMedia USB Radio
38 * in usbhid/hid-quirks.c 39 * in usbhid/hid-quirks.c
40 * Version 0.10: A lot of cleanups and fixes: unpluging the device,
41 * few mutex locks were added, codinstyle issues, etc.
42 * Added stereo support. Thanks to
43 * Douglas Schilling Landgraf <dougsland@gmail.com> and
44 * David Ellingsworth <david@identd.dyndns.org>
45 * for discussion, help and support.
39 * 46 *
40 * Many things to do: 47 * Many things to do:
41 * - Correct power managment of device (suspend & resume) 48 * - Correct power managment of device (suspend & resume)
42 * - Make x86 independance (little-endian and big-endian stuff)
43 * - Add code for scanning and smooth tuning 49 * - Add code for scanning and smooth tuning
44 * - Checked and add stereo&mono stuff
45 * - Add code for sensitivity value 50 * - Add code for sensitivity value
46 * - Correct mistakes 51 * - Correct mistakes
47 * - In Japan another FREQ_MIN and FREQ_MAX 52 * - In Japan another FREQ_MIN and FREQ_MAX
@@ -62,8 +67,8 @@
62/* driver and module definitions */ 67/* driver and module definitions */
63#define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>" 68#define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>"
64#define DRIVER_DESC "AverMedia MR 800 USB FM radio driver" 69#define DRIVER_DESC "AverMedia MR 800 USB FM radio driver"
65#define DRIVER_VERSION "0.01" 70#define DRIVER_VERSION "0.10"
66#define RADIO_VERSION KERNEL_VERSION(0, 0, 1) 71#define RADIO_VERSION KERNEL_VERSION(0, 1, 0)
67 72
68MODULE_AUTHOR(DRIVER_AUTHOR); 73MODULE_AUTHOR(DRIVER_AUTHOR);
69MODULE_DESCRIPTION(DRIVER_DESC); 74MODULE_DESCRIPTION(DRIVER_DESC);
@@ -87,6 +92,22 @@ devices, that would be 76 and 91. */
87#define FREQ_MAX 108.0 92#define FREQ_MAX 108.0
88#define FREQ_MUL 16000 93#define FREQ_MUL 16000
89 94
95/*
96 * Commands that device should understand
97 * List isnt full and will be updated with implementation of new functions
98 */
99#define AMRADIO_SET_FREQ 0xa4
100#define AMRADIO_SET_MUTE 0xab
101#define AMRADIO_SET_MONO 0xae
102
103/* Comfortable defines for amradio_set_mute */
104#define AMRADIO_START 0x00
105#define AMRADIO_STOP 0x01
106
107/* Comfortable defines for amradio_set_stereo */
108#define WANT_STEREO 0x00
109#define WANT_MONO 0x01
110
90/* module parameter */ 111/* module parameter */
91static int radio_nr = -1; 112static int radio_nr = -1;
92module_param(radio_nr, int, 0); 113module_param(radio_nr, int, 0);
@@ -169,43 +190,48 @@ static struct usb_driver usb_amradio_driver = {
169 .supports_autosuspend = 0, 190 .supports_autosuspend = 0,
170}; 191};
171 192
172/* switch on radio. Send 8 bytes to device. */ 193/* switch on/off the radio. Send 8 bytes to device */
173static int amradio_start(struct amradio_device *radio) 194static int amradio_set_mute(struct amradio_device *radio, char argument)
174{ 195{
175 int retval; 196 int retval;
176 int size; 197 int size;
177 198
199 /* safety check */
200 if (radio->removed)
201 return -EIO;
202
178 mutex_lock(&radio->lock); 203 mutex_lock(&radio->lock);
179 204
180 radio->buffer[0] = 0x00; 205 radio->buffer[0] = 0x00;
181 radio->buffer[1] = 0x55; 206 radio->buffer[1] = 0x55;
182 radio->buffer[2] = 0xaa; 207 radio->buffer[2] = 0xaa;
183 radio->buffer[3] = 0x00; 208 radio->buffer[3] = 0x00;
184 radio->buffer[4] = 0xab; 209 radio->buffer[4] = AMRADIO_SET_MUTE;
185 radio->buffer[5] = 0x00; 210 radio->buffer[5] = argument;
186 radio->buffer[6] = 0x00; 211 radio->buffer[6] = 0x00;
187 radio->buffer[7] = 0x00; 212 radio->buffer[7] = 0x00;
188 213
189 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2), 214 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
190 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT); 215 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
191 216
192 if (retval) { 217 if (retval < 0 || size != BUFFER_LENGTH) {
193 mutex_unlock(&radio->lock); 218 mutex_unlock(&radio->lock);
194 return retval; 219 return retval;
195 } 220 }
196 221
197 radio->muted = 0; 222 radio->muted = argument;
198 223
199 mutex_unlock(&radio->lock); 224 mutex_unlock(&radio->lock);
200 225
201 return retval; 226 return retval;
202} 227}
203 228
204/* switch off radio */ 229/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
205static int amradio_stop(struct amradio_device *radio) 230static int amradio_setfreq(struct amradio_device *radio, int freq)
206{ 231{
207 int retval; 232 int retval;
208 int size; 233 int size;
234 unsigned short freq_send = 0x10 + (freq >> 3) / 25;
209 235
210 /* safety check */ 236 /* safety check */
211 if (radio->removed) 237 if (radio->removed)
@@ -216,33 +242,46 @@ static int amradio_stop(struct amradio_device *radio)
216 radio->buffer[0] = 0x00; 242 radio->buffer[0] = 0x00;
217 radio->buffer[1] = 0x55; 243 radio->buffer[1] = 0x55;
218 radio->buffer[2] = 0xaa; 244 radio->buffer[2] = 0xaa;
219 radio->buffer[3] = 0x00; 245 radio->buffer[3] = 0x03;
220 radio->buffer[4] = 0xab; 246 radio->buffer[4] = AMRADIO_SET_FREQ;
221 radio->buffer[5] = 0x01; 247 radio->buffer[5] = 0x00;
222 radio->buffer[6] = 0x00; 248 radio->buffer[6] = 0x00;
223 radio->buffer[7] = 0x00; 249 radio->buffer[7] = 0x08;
224 250
225 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2), 251 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
226 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT); 252 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
227 253
228 if (retval) { 254 if (retval < 0 || size != BUFFER_LENGTH) {
229 mutex_unlock(&radio->lock); 255 mutex_unlock(&radio->lock);
230 return retval; 256 return retval;
231 } 257 }
232 258
233 radio->muted = 1; 259 /* frequency is calculated from freq_send and placed in first 2 bytes */
260 radio->buffer[0] = (freq_send >> 8) & 0xff;
261 radio->buffer[1] = freq_send & 0xff;
262 radio->buffer[2] = 0x01;
263 radio->buffer[3] = 0x00;
264 radio->buffer[4] = 0x00;
265 /* 5 and 6 bytes of buffer already = 0x00 */
266 radio->buffer[7] = 0x00;
267
268 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
269 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
270
271 if (retval < 0 || size != BUFFER_LENGTH) {
272 mutex_unlock(&radio->lock);
273 return retval;
274 }
234 275
235 mutex_unlock(&radio->lock); 276 mutex_unlock(&radio->lock);
236 277
237 return retval; 278 return retval;
238} 279}
239 280
240/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */ 281static int amradio_set_stereo(struct amradio_device *radio, char argument)
241static int amradio_setfreq(struct amradio_device *radio, int freq)
242{ 282{
243 int retval; 283 int retval;
244 int size; 284 int size;
245 unsigned short freq_send = 0x13 + (freq >> 3) / 25;
246 285
247 /* safety check */ 286 /* safety check */
248 if (radio->removed) 287 if (radio->removed)
@@ -253,50 +292,33 @@ static int amradio_setfreq(struct amradio_device *radio, int freq)
253 radio->buffer[0] = 0x00; 292 radio->buffer[0] = 0x00;
254 radio->buffer[1] = 0x55; 293 radio->buffer[1] = 0x55;
255 radio->buffer[2] = 0xaa; 294 radio->buffer[2] = 0xaa;
256 radio->buffer[3] = 0x03;
257 radio->buffer[4] = 0xa4;
258 radio->buffer[5] = 0x00;
259 radio->buffer[6] = 0x00;
260 radio->buffer[7] = 0x08;
261
262 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
263 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
264
265 if (retval) {
266 mutex_unlock(&radio->lock);
267 return retval;
268 }
269
270 /* frequency is calculated from freq_send and placed in first 2 bytes */
271 radio->buffer[0] = (freq_send >> 8) & 0xff;
272 radio->buffer[1] = freq_send & 0xff;
273 radio->buffer[2] = 0x01;
274 radio->buffer[3] = 0x00; 295 radio->buffer[3] = 0x00;
275 radio->buffer[4] = 0x00; 296 radio->buffer[4] = AMRADIO_SET_MONO;
276 /* 5 and 6 bytes of buffer already = 0x00 */ 297 radio->buffer[5] = argument;
298 radio->buffer[6] = 0x00;
277 radio->buffer[7] = 0x00; 299 radio->buffer[7] = 0x00;
278 300
279 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2), 301 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
280 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT); 302 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
281 303
282 if (retval) { 304 if (retval < 0 || size != BUFFER_LENGTH) {
305 radio->stereo = -1;
283 mutex_unlock(&radio->lock); 306 mutex_unlock(&radio->lock);
284 return retval; 307 return retval;
285 } 308 }
286 309
287 radio->stereo = 0; 310 radio->stereo = 1;
288 311
289 mutex_unlock(&radio->lock); 312 mutex_unlock(&radio->lock);
290 313
291 return retval; 314 return retval;
292} 315}
293 316
294/* USB subsystem interface begins here */ 317/* Handle unplugging the device.
295 318 * We call video_unregister_device in any case.
296/* handle unplugging of the device, release data structures 319 * The last function called in this procedure is
297if nothing keeps us from doing it. If something is still 320 * usb_amradio_device_release.
298keeping us busy, the release callback of v4l will take care 321 */
299of releasing it. */
300static void usb_amradio_disconnect(struct usb_interface *intf) 322static void usb_amradio_disconnect(struct usb_interface *intf)
301{ 323{
302 struct amradio_device *radio = usb_get_intfdata(intf); 324 struct amradio_device *radio = usb_get_intfdata(intf);
@@ -313,9 +335,11 @@ static void usb_amradio_disconnect(struct usb_interface *intf)
313static int vidioc_querycap(struct file *file, void *priv, 335static int vidioc_querycap(struct file *file, void *priv,
314 struct v4l2_capability *v) 336 struct v4l2_capability *v)
315{ 337{
338 struct amradio_device *radio = video_drvdata(file);
339
316 strlcpy(v->driver, "radio-mr800", sizeof(v->driver)); 340 strlcpy(v->driver, "radio-mr800", sizeof(v->driver));
317 strlcpy(v->card, "AverMedia MR 800 USB FM Radio", sizeof(v->card)); 341 strlcpy(v->card, "AverMedia MR 800 USB FM Radio", sizeof(v->card));
318 sprintf(v->bus_info, "USB"); 342 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
319 v->version = RADIO_VERSION; 343 v->version = RADIO_VERSION;
320 v->capabilities = V4L2_CAP_TUNER; 344 v->capabilities = V4L2_CAP_TUNER;
321 return 0; 345 return 0;
@@ -326,6 +350,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
326 struct v4l2_tuner *v) 350 struct v4l2_tuner *v)
327{ 351{
328 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 352 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
353 int retval;
329 354
330 /* safety check */ 355 /* safety check */
331 if (radio->removed) 356 if (radio->removed)
@@ -337,7 +362,16 @@ static int vidioc_g_tuner(struct file *file, void *priv,
337/* TODO: Add function which look is signal stereo or not 362/* TODO: Add function which look is signal stereo or not
338 * amradio_getstat(radio); 363 * amradio_getstat(radio);
339 */ 364 */
340 radio->stereo = -1; 365
366/* we call amradio_set_stereo to set radio->stereo
367 * Honestly, amradio_getstat should cover this in future and
368 * amradio_set_stereo shouldn't be here
369 */
370 retval = amradio_set_stereo(radio, WANT_STEREO);
371 if (retval < 0)
372 amradio_dev_warn(&radio->videodev->dev,
373 "set stereo failed\n");
374
341 strcpy(v->name, "FM"); 375 strcpy(v->name, "FM");
342 v->type = V4L2_TUNER_RADIO; 376 v->type = V4L2_TUNER_RADIO;
343 v->rangelow = FREQ_MIN * FREQ_MUL; 377 v->rangelow = FREQ_MIN * FREQ_MUL;
@@ -358,6 +392,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
358 struct v4l2_tuner *v) 392 struct v4l2_tuner *v)
359{ 393{
360 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 394 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
395 int retval;
361 396
362 /* safety check */ 397 /* safety check */
363 if (radio->removed) 398 if (radio->removed)
@@ -365,6 +400,25 @@ static int vidioc_s_tuner(struct file *file, void *priv,
365 400
366 if (v->index > 0) 401 if (v->index > 0)
367 return -EINVAL; 402 return -EINVAL;
403
404 /* mono/stereo selector */
405 switch (v->audmode) {
406 case V4L2_TUNER_MODE_MONO:
407 retval = amradio_set_stereo(radio, WANT_MONO);
408 if (retval < 0)
409 amradio_dev_warn(&radio->videodev->dev,
410 "set mono failed\n");
411 break;
412 case V4L2_TUNER_MODE_STEREO:
413 retval = amradio_set_stereo(radio, WANT_STEREO);
414 if (retval < 0)
415 amradio_dev_warn(&radio->videodev->dev,
416 "set stereo failed\n");
417 break;
418 default:
419 return -EINVAL;
420 }
421
368 return 0; 422 return 0;
369} 423}
370 424
@@ -373,13 +427,18 @@ static int vidioc_s_frequency(struct file *file, void *priv,
373 struct v4l2_frequency *f) 427 struct v4l2_frequency *f)
374{ 428{
375 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 429 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
430 int retval;
376 431
377 /* safety check */ 432 /* safety check */
378 if (radio->removed) 433 if (radio->removed)
379 return -EIO; 434 return -EIO;
380 435
436 mutex_lock(&radio->lock);
381 radio->curfreq = f->frequency; 437 radio->curfreq = f->frequency;
382 if (amradio_setfreq(radio, radio->curfreq) < 0) 438 mutex_unlock(&radio->lock);
439
440 retval = amradio_setfreq(radio, radio->curfreq);
441 if (retval < 0)
383 amradio_dev_warn(&radio->videodev->dev, 442 amradio_dev_warn(&radio->videodev->dev,
384 "set frequency failed\n"); 443 "set frequency failed\n");
385 return 0; 444 return 0;
@@ -438,6 +497,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
438 struct v4l2_control *ctrl) 497 struct v4l2_control *ctrl)
439{ 498{
440 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 499 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
500 int retval;
441 501
442 /* safety check */ 502 /* safety check */
443 if (radio->removed) 503 if (radio->removed)
@@ -446,13 +506,15 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
446 switch (ctrl->id) { 506 switch (ctrl->id) {
447 case V4L2_CID_AUDIO_MUTE: 507 case V4L2_CID_AUDIO_MUTE:
448 if (ctrl->value) { 508 if (ctrl->value) {
449 if (amradio_stop(radio) < 0) { 509 retval = amradio_set_mute(radio, AMRADIO_STOP);
510 if (retval < 0) {
450 amradio_dev_warn(&radio->videodev->dev, 511 amradio_dev_warn(&radio->videodev->dev,
451 "amradio_stop failed\n"); 512 "amradio_stop failed\n");
452 return -1; 513 return -1;
453 } 514 }
454 } else { 515 } else {
455 if (amradio_start(radio) < 0) { 516 retval = amradio_set_mute(radio, AMRADIO_START);
517 if (retval < 0) {
456 amradio_dev_warn(&radio->videodev->dev, 518 amradio_dev_warn(&radio->videodev->dev,
457 "amradio_start failed\n"); 519 "amradio_start failed\n");
458 return -1; 520 return -1;
@@ -503,20 +565,29 @@ static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
503static int usb_amradio_open(struct file *file) 565static int usb_amradio_open(struct file *file)
504{ 566{
505 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 567 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
568 int retval;
506 569
507 lock_kernel(); 570 lock_kernel();
508 571
509 radio->users = 1; 572 radio->users = 1;
510 radio->muted = 1; 573 radio->muted = 1;
511 574
512 if (amradio_start(radio) < 0) { 575 retval = amradio_set_mute(radio, AMRADIO_START);
576 if (retval < 0) {
513 amradio_dev_warn(&radio->videodev->dev, 577 amradio_dev_warn(&radio->videodev->dev,
514 "radio did not start up properly\n"); 578 "radio did not start up properly\n");
515 radio->users = 0; 579 radio->users = 0;
516 unlock_kernel(); 580 unlock_kernel();
517 return -EIO; 581 return -EIO;
518 } 582 }
519 if (amradio_setfreq(radio, radio->curfreq) < 0) 583
584 retval = amradio_set_stereo(radio, WANT_STEREO);
585 if (retval < 0)
586 amradio_dev_warn(&radio->videodev->dev,
587 "set stereo failed\n");
588
589 retval = amradio_setfreq(radio, radio->curfreq);
590 if (retval < 0)
520 amradio_dev_warn(&radio->videodev->dev, 591 amradio_dev_warn(&radio->videodev->dev,
521 "set frequency failed\n"); 592 "set frequency failed\n");
522 593
@@ -533,10 +604,12 @@ static int usb_amradio_close(struct file *file)
533 if (!radio) 604 if (!radio)
534 return -ENODEV; 605 return -ENODEV;
535 606
607 mutex_lock(&radio->lock);
536 radio->users = 0; 608 radio->users = 0;
609 mutex_unlock(&radio->lock);
537 610
538 if (!radio->removed) { 611 if (!radio->removed) {
539 retval = amradio_stop(radio); 612 retval = amradio_set_mute(radio, AMRADIO_STOP);
540 if (retval < 0) 613 if (retval < 0)
541 amradio_dev_warn(&radio->videodev->dev, 614 amradio_dev_warn(&radio->videodev->dev,
542 "amradio_stop failed\n"); 615 "amradio_stop failed\n");
@@ -549,8 +622,10 @@ static int usb_amradio_close(struct file *file)
549static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message) 622static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
550{ 623{
551 struct amradio_device *radio = usb_get_intfdata(intf); 624 struct amradio_device *radio = usb_get_intfdata(intf);
625 int retval;
552 626
553 if (amradio_stop(radio) < 0) 627 retval = amradio_set_mute(radio, AMRADIO_STOP);
628 if (retval < 0)
554 dev_warn(&intf->dev, "amradio_stop failed\n"); 629 dev_warn(&intf->dev, "amradio_stop failed\n");
555 630
556 dev_info(&intf->dev, "going into suspend..\n"); 631 dev_info(&intf->dev, "going into suspend..\n");
@@ -562,8 +637,10 @@ static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
562static int usb_amradio_resume(struct usb_interface *intf) 637static int usb_amradio_resume(struct usb_interface *intf)
563{ 638{
564 struct amradio_device *radio = usb_get_intfdata(intf); 639 struct amradio_device *radio = usb_get_intfdata(intf);
640 int retval;
565 641
566 if (amradio_start(radio) < 0) 642 retval = amradio_set_mute(radio, AMRADIO_START);
643 if (retval < 0)
567 dev_warn(&intf->dev, "amradio_start failed\n"); 644 dev_warn(&intf->dev, "amradio_start failed\n");
568 645
569 dev_info(&intf->dev, "coming out of suspend..\n"); 646 dev_info(&intf->dev, "coming out of suspend..\n");
@@ -614,28 +691,32 @@ static struct video_device amradio_videodev_template = {
614 .release = usb_amradio_device_release, 691 .release = usb_amradio_device_release,
615}; 692};
616 693
617/* check if the device is present and register with v4l and 694/* check if the device is present and register with v4l and usb if it is */
618usb if it is */
619static int usb_amradio_probe(struct usb_interface *intf, 695static int usb_amradio_probe(struct usb_interface *intf,
620 const struct usb_device_id *id) 696 const struct usb_device_id *id)
621{ 697{
622 struct amradio_device *radio; 698 struct amradio_device *radio;
699 int retval;
623 700
624 radio = kmalloc(sizeof(struct amradio_device), GFP_KERNEL); 701 radio = kmalloc(sizeof(struct amradio_device), GFP_KERNEL);
625 702
626 if (!(radio)) 703 if (!radio) {
704 dev_err(&intf->dev, "kmalloc for amradio_device failed\n");
627 return -ENOMEM; 705 return -ENOMEM;
706 }
628 707
629 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL); 708 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
630 709
631 if (!(radio->buffer)) { 710 if (!radio->buffer) {
711 dev_err(&intf->dev, "kmalloc for radio->buffer failed\n");
632 kfree(radio); 712 kfree(radio);
633 return -ENOMEM; 713 return -ENOMEM;
634 } 714 }
635 715
636 radio->videodev = video_device_alloc(); 716 radio->videodev = video_device_alloc();
637 717
638 if (!(radio->videodev)) { 718 if (!radio->videodev) {
719 dev_err(&intf->dev, "video_device_alloc failed\n");
639 kfree(radio->buffer); 720 kfree(radio->buffer);
640 kfree(radio); 721 kfree(radio);
641 return -ENOMEM; 722 return -ENOMEM;
@@ -648,12 +729,14 @@ static int usb_amradio_probe(struct usb_interface *intf,
648 radio->users = 0; 729 radio->users = 0;
649 radio->usbdev = interface_to_usbdev(intf); 730 radio->usbdev = interface_to_usbdev(intf);
650 radio->curfreq = 95.16 * FREQ_MUL; 731 radio->curfreq = 95.16 * FREQ_MUL;
732 radio->stereo = -1;
651 733
652 mutex_init(&radio->lock); 734 mutex_init(&radio->lock);
653 735
654 video_set_drvdata(radio->videodev, radio); 736 video_set_drvdata(radio->videodev, radio);
655 if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) { 737 retval = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr);
656 dev_warn(&intf->dev, "could not register video device\n"); 738 if (retval < 0) {
739 dev_err(&intf->dev, "could not register video device\n");
657 video_device_release(radio->videodev); 740 video_device_release(radio->videodev);
658 kfree(radio->buffer); 741 kfree(radio->buffer);
659 kfree(radio); 742 kfree(radio);