aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/usb/airspy/airspy.c172
1 files changed, 61 insertions, 111 deletions
diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c
index dee1fe2669a6..de9fc52d3763 100644
--- a/drivers/media/usb/airspy/airspy.c
+++ b/drivers/media/usb/airspy/airspy.c
@@ -107,6 +107,7 @@ struct airspy {
107#define USB_STATE_URB_BUF (1 << 3) 107#define USB_STATE_URB_BUF (1 << 3)
108 unsigned long flags; 108 unsigned long flags;
109 109
110 struct device *dev;
110 struct usb_device *udev; 111 struct usb_device *udev;
111 struct video_device vdev; 112 struct video_device vdev;
112 struct v4l2_device v4l2_dev; 113 struct v4l2_device v4l2_dev;
@@ -154,16 +155,15 @@ struct airspy {
154 unsigned int sample_measured; 155 unsigned int sample_measured;
155}; 156};
156 157
157#define airspy_dbg_usb_control_msg(_udev, _r, _t, _v, _i, _b, _l) { \ 158#define airspy_dbg_usb_control_msg(_dev, _r, _t, _v, _i, _b, _l) { \
158 char *_direction; \ 159 char *_direction; \
159 if (_t & USB_DIR_IN) \ 160 if (_t & USB_DIR_IN) \
160 _direction = "<<<"; \ 161 _direction = "<<<"; \
161 else \ 162 else \
162 _direction = ">>>"; \ 163 _direction = ">>>"; \
163 dev_dbg(&_udev->dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x " \ 164 dev_dbg(_dev, "%02x %02x %02x %02x %02x %02x %02x %02x %s %*ph\n", \
164 "%s %*ph\n", __func__, _t, _r, _v & 0xff, _v >> 8, \ 165 _t, _r, _v & 0xff, _v >> 8, _i & 0xff, _i >> 8, \
165 _i & 0xff, _i >> 8, _l & 0xff, _l >> 8, _direction, \ 166 _l & 0xff, _l >> 8, _direction, _l, _b); \
166 _l, _b); \
167} 167}
168 168
169/* execute firmware command */ 169/* execute firmware command */
@@ -192,7 +192,7 @@ static int airspy_ctrl_msg(struct airspy *s, u8 request, u16 value, u16 index,
192 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN); 192 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
193 break; 193 break;
194 default: 194 default:
195 dev_err(&s->udev->dev, "Unknown command %02x\n", request); 195 dev_err(s->dev, "Unknown command %02x\n", request);
196 ret = -EINVAL; 196 ret = -EINVAL;
197 goto err; 197 goto err;
198 } 198 }
@@ -203,11 +203,10 @@ static int airspy_ctrl_msg(struct airspy *s, u8 request, u16 value, u16 index,
203 203
204 ret = usb_control_msg(s->udev, pipe, request, requesttype, value, 204 ret = usb_control_msg(s->udev, pipe, request, requesttype, value,
205 index, s->buf, size, 1000); 205 index, s->buf, size, 1000);
206 airspy_dbg_usb_control_msg(s->udev, request, requesttype, value, 206 airspy_dbg_usb_control_msg(s->dev, request, requesttype, value,
207 index, s->buf, size); 207 index, s->buf, size);
208 if (ret < 0) { 208 if (ret < 0) {
209 dev_err(&s->udev->dev, 209 dev_err(s->dev, "usb_control_msg() failed %d request %02x\n",
210 "usb_control_msg() failed %d request %02x\n",
211 ret, request); 210 ret, request);
212 goto err; 211 goto err;
213 } 212 }
@@ -258,8 +257,7 @@ static unsigned int airspy_convert_stream(struct airspy *s,
258 257
259 s->jiffies_next = jiffies + msecs_to_jiffies(MSECS); 258 s->jiffies_next = jiffies + msecs_to_jiffies(MSECS);
260 s->sample_measured = s->sample; 259 s->sample_measured = s->sample;
261 dev_dbg(&s->udev->dev, 260 dev_dbg(s->dev, "slen=%d samples=%u msecs=%lu sample rate=%lu\n",
262 "slen=%d samples=%u msecs=%lu sample rate=%lu\n",
263 src_len, samples, MSECS, 261 src_len, samples, MSECS,
264 samples * 1000UL / MSECS); 262 samples * 1000UL / MSECS);
265 } 263 }
@@ -279,9 +277,8 @@ static void airspy_urb_complete(struct urb *urb)
279 struct airspy *s = urb->context; 277 struct airspy *s = urb->context;
280 struct airspy_frame_buf *fbuf; 278 struct airspy_frame_buf *fbuf;
281 279
282 dev_dbg_ratelimited(&s->udev->dev, 280 dev_dbg_ratelimited(s->dev, "status=%d length=%d/%d errors=%d\n",
283 "%s: status=%d length=%d/%d errors=%d\n", 281 urb->status, urb->actual_length,
284 __func__, urb->status, urb->actual_length,
285 urb->transfer_buffer_length, urb->error_count); 282 urb->transfer_buffer_length, urb->error_count);
286 283
287 switch (urb->status) { 284 switch (urb->status) {
@@ -293,8 +290,7 @@ static void airspy_urb_complete(struct urb *urb)
293 case -ESHUTDOWN: 290 case -ESHUTDOWN:
294 return; 291 return;
295 default: /* error */ 292 default: /* error */
296 dev_err_ratelimited(&s->udev->dev, "URB failed %d\n", 293 dev_err_ratelimited(s->dev, "URB failed %d\n", urb->status);
297 urb->status);
298 break; 294 break;
299 } 295 }
300 296
@@ -305,7 +301,7 @@ static void airspy_urb_complete(struct urb *urb)
305 fbuf = airspy_get_next_fill_buf(s); 301 fbuf = airspy_get_next_fill_buf(s);
306 if (unlikely(fbuf == NULL)) { 302 if (unlikely(fbuf == NULL)) {
307 s->vb_full++; 303 s->vb_full++;
308 dev_notice_ratelimited(&s->udev->dev, 304 dev_notice_ratelimited(s->dev,
309 "videobuf is full, %d packets dropped\n", 305 "videobuf is full, %d packets dropped\n",
310 s->vb_full); 306 s->vb_full);
311 goto skip; 307 goto skip;
@@ -329,7 +325,7 @@ static int airspy_kill_urbs(struct airspy *s)
329 int i; 325 int i;
330 326
331 for (i = s->urbs_submitted - 1; i >= 0; i--) { 327 for (i = s->urbs_submitted - 1; i >= 0; i--) {
332 dev_dbg(&s->udev->dev, "%s: kill urb=%d\n", __func__, i); 328 dev_dbg(s->dev, "kill urb=%d\n", i);
333 /* stop the URB */ 329 /* stop the URB */
334 usb_kill_urb(s->urb_list[i]); 330 usb_kill_urb(s->urb_list[i]);
335 } 331 }
@@ -343,11 +339,10 @@ static int airspy_submit_urbs(struct airspy *s)
343 int i, ret; 339 int i, ret;
344 340
345 for (i = 0; i < s->urbs_initialized; i++) { 341 for (i = 0; i < s->urbs_initialized; i++) {
346 dev_dbg(&s->udev->dev, "%s: submit urb=%d\n", __func__, i); 342 dev_dbg(s->dev, "submit urb=%d\n", i);
347 ret = usb_submit_urb(s->urb_list[i], GFP_ATOMIC); 343 ret = usb_submit_urb(s->urb_list[i], GFP_ATOMIC);
348 if (ret) { 344 if (ret) {
349 dev_err(&s->udev->dev, 345 dev_err(s->dev, "Could not submit URB no. %d - get them all back\n",
350 "Could not submit URB no. %d - get them all back\n",
351 i); 346 i);
352 airspy_kill_urbs(s); 347 airspy_kill_urbs(s);
353 return ret; 348 return ret;
@@ -363,8 +358,7 @@ static int airspy_free_stream_bufs(struct airspy *s)
363 if (s->flags & USB_STATE_URB_BUF) { 358 if (s->flags & USB_STATE_URB_BUF) {
364 while (s->buf_num) { 359 while (s->buf_num) {
365 s->buf_num--; 360 s->buf_num--;
366 dev_dbg(&s->udev->dev, "%s: free buf=%d\n", 361 dev_dbg(s->dev, "free buf=%d\n", s->buf_num);
367 __func__, s->buf_num);
368 usb_free_coherent(s->udev, s->buf_size, 362 usb_free_coherent(s->udev, s->buf_size,
369 s->buf_list[s->buf_num], 363 s->buf_list[s->buf_num],
370 s->dma_addr[s->buf_num]); 364 s->dma_addr[s->buf_num]);
@@ -380,23 +374,20 @@ static int airspy_alloc_stream_bufs(struct airspy *s)
380 s->buf_num = 0; 374 s->buf_num = 0;
381 s->buf_size = BULK_BUFFER_SIZE; 375 s->buf_size = BULK_BUFFER_SIZE;
382 376
383 dev_dbg(&s->udev->dev, 377 dev_dbg(s->dev, "all in all I will use %u bytes for streaming\n",
384 "%s: all in all I will use %u bytes for streaming\n", 378 MAX_BULK_BUFS * BULK_BUFFER_SIZE);
385 __func__, MAX_BULK_BUFS * BULK_BUFFER_SIZE);
386 379
387 for (s->buf_num = 0; s->buf_num < MAX_BULK_BUFS; s->buf_num++) { 380 for (s->buf_num = 0; s->buf_num < MAX_BULK_BUFS; s->buf_num++) {
388 s->buf_list[s->buf_num] = usb_alloc_coherent(s->udev, 381 s->buf_list[s->buf_num] = usb_alloc_coherent(s->udev,
389 BULK_BUFFER_SIZE, GFP_ATOMIC, 382 BULK_BUFFER_SIZE, GFP_ATOMIC,
390 &s->dma_addr[s->buf_num]); 383 &s->dma_addr[s->buf_num]);
391 if (!s->buf_list[s->buf_num]) { 384 if (!s->buf_list[s->buf_num]) {
392 dev_dbg(&s->udev->dev, "%s: alloc buf=%d failed\n", 385 dev_dbg(s->dev, "alloc buf=%d failed\n", s->buf_num);
393 __func__, s->buf_num);
394 airspy_free_stream_bufs(s); 386 airspy_free_stream_bufs(s);
395 return -ENOMEM; 387 return -ENOMEM;
396 } 388 }
397 389
398 dev_dbg(&s->udev->dev, "%s: alloc buf=%d %p (dma %llu)\n", 390 dev_dbg(s->dev, "alloc buf=%d %p (dma %llu)\n", s->buf_num,
399 __func__, s->buf_num,
400 s->buf_list[s->buf_num], 391 s->buf_list[s->buf_num],
401 (long long)s->dma_addr[s->buf_num]); 392 (long long)s->dma_addr[s->buf_num]);
402 s->flags |= USB_STATE_URB_BUF; 393 s->flags |= USB_STATE_URB_BUF;
@@ -413,8 +404,7 @@ static int airspy_free_urbs(struct airspy *s)
413 404
414 for (i = s->urbs_initialized - 1; i >= 0; i--) { 405 for (i = s->urbs_initialized - 1; i >= 0; i--) {
415 if (s->urb_list[i]) { 406 if (s->urb_list[i]) {
416 dev_dbg(&s->udev->dev, "%s: free urb=%d\n", 407 dev_dbg(s->dev, "free urb=%d\n", i);
417 __func__, i);
418 /* free the URBs */ 408 /* free the URBs */
419 usb_free_urb(s->urb_list[i]); 409 usb_free_urb(s->urb_list[i]);
420 } 410 }
@@ -430,10 +420,10 @@ static int airspy_alloc_urbs(struct airspy *s)
430 420
431 /* allocate the URBs */ 421 /* allocate the URBs */
432 for (i = 0; i < MAX_BULK_BUFS; i++) { 422 for (i = 0; i < MAX_BULK_BUFS; i++) {
433 dev_dbg(&s->udev->dev, "%s: alloc urb=%d\n", __func__, i); 423 dev_dbg(s->dev, "alloc urb=%d\n", i);
434 s->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); 424 s->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC);
435 if (!s->urb_list[i]) { 425 if (!s->urb_list[i]) {
436 dev_dbg(&s->udev->dev, "%s: failed\n", __func__); 426 dev_dbg(s->dev, "failed\n");
437 for (j = 0; j < i; j++) 427 for (j = 0; j < i; j++)
438 usb_free_urb(s->urb_list[j]); 428 usb_free_urb(s->urb_list[j]);
439 return -ENOMEM; 429 return -ENOMEM;
@@ -458,7 +448,7 @@ static void airspy_cleanup_queued_bufs(struct airspy *s)
458{ 448{
459 unsigned long flags = 0; 449 unsigned long flags = 0;
460 450
461 dev_dbg(&s->udev->dev, "%s:\n", __func__); 451 dev_dbg(s->dev, "\n");
462 452
463 spin_lock_irqsave(&s->queued_bufs_lock, flags); 453 spin_lock_irqsave(&s->queued_bufs_lock, flags);
464 while (!list_empty(&s->queued_bufs)) { 454 while (!list_empty(&s->queued_bufs)) {
@@ -478,7 +468,7 @@ static void airspy_disconnect(struct usb_interface *intf)
478 struct v4l2_device *v = usb_get_intfdata(intf); 468 struct v4l2_device *v = usb_get_intfdata(intf);
479 struct airspy *s = container_of(v, struct airspy, v4l2_dev); 469 struct airspy *s = container_of(v, struct airspy, v4l2_dev);
480 470
481 dev_dbg(&s->udev->dev, "%s:\n", __func__); 471 dev_dbg(s->dev, "\n");
482 472
483 mutex_lock(&s->vb_queue_lock); 473 mutex_lock(&s->vb_queue_lock);
484 mutex_lock(&s->v4l2_lock); 474 mutex_lock(&s->v4l2_lock);
@@ -499,7 +489,7 @@ static int airspy_queue_setup(struct vb2_queue *vq,
499{ 489{
500 struct airspy *s = vb2_get_drv_priv(vq); 490 struct airspy *s = vb2_get_drv_priv(vq);
501 491
502 dev_dbg(&s->udev->dev, "%s: *nbuffers=%d\n", __func__, *nbuffers); 492 dev_dbg(s->dev, "nbuffers=%d\n", *nbuffers);
503 493
504 /* Need at least 8 buffers */ 494 /* Need at least 8 buffers */
505 if (vq->num_buffers + *nbuffers < 8) 495 if (vq->num_buffers + *nbuffers < 8)
@@ -507,8 +497,7 @@ static int airspy_queue_setup(struct vb2_queue *vq,
507 *nplanes = 1; 497 *nplanes = 1;
508 sizes[0] = PAGE_ALIGN(s->buffersize); 498 sizes[0] = PAGE_ALIGN(s->buffersize);
509 499
510 dev_dbg(&s->udev->dev, "%s: nbuffers=%d sizes[0]=%d\n", 500 dev_dbg(s->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]);
511 __func__, *nbuffers, sizes[0]);
512 return 0; 501 return 0;
513} 502}
514 503
@@ -535,7 +524,7 @@ static int airspy_start_streaming(struct vb2_queue *vq, unsigned int count)
535 struct airspy *s = vb2_get_drv_priv(vq); 524 struct airspy *s = vb2_get_drv_priv(vq);
536 int ret; 525 int ret;
537 526
538 dev_dbg(&s->udev->dev, "%s:\n", __func__); 527 dev_dbg(s->dev, "\n");
539 528
540 if (!s->udev) 529 if (!s->udev)
541 return -ENODEV; 530 return -ENODEV;
@@ -594,7 +583,7 @@ static void airspy_stop_streaming(struct vb2_queue *vq)
594{ 583{
595 struct airspy *s = vb2_get_drv_priv(vq); 584 struct airspy *s = vb2_get_drv_priv(vq);
596 585
597 dev_dbg(&s->udev->dev, "%s:\n", __func__); 586 dev_dbg(s->dev, "\n");
598 587
599 mutex_lock(&s->v4l2_lock); 588 mutex_lock(&s->v4l2_lock);
600 589
@@ -626,8 +615,6 @@ static int airspy_querycap(struct file *file, void *fh,
626{ 615{
627 struct airspy *s = video_drvdata(file); 616 struct airspy *s = video_drvdata(file);
628 617
629 dev_dbg(&s->udev->dev, "%s:\n", __func__);
630
631 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); 618 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
632 strlcpy(cap->card, s->vdev.name, sizeof(cap->card)); 619 strlcpy(cap->card, s->vdev.name, sizeof(cap->card));
633 usb_make_path(s->udev, cap->bus_info, sizeof(cap->bus_info)); 620 usb_make_path(s->udev, cap->bus_info, sizeof(cap->bus_info));
@@ -641,10 +628,6 @@ static int airspy_querycap(struct file *file, void *fh,
641static int airspy_enum_fmt_sdr_cap(struct file *file, void *priv, 628static int airspy_enum_fmt_sdr_cap(struct file *file, void *priv,
642 struct v4l2_fmtdesc *f) 629 struct v4l2_fmtdesc *f)
643{ 630{
644 struct airspy *s = video_drvdata(file);
645
646 dev_dbg(&s->udev->dev, "%s: index=%d\n", __func__, f->index);
647
648 if (f->index >= NUM_FORMATS) 631 if (f->index >= NUM_FORMATS)
649 return -EINVAL; 632 return -EINVAL;
650 633
@@ -659,9 +642,6 @@ static int airspy_g_fmt_sdr_cap(struct file *file, void *priv,
659{ 642{
660 struct airspy *s = video_drvdata(file); 643 struct airspy *s = video_drvdata(file);
661 644
662 dev_dbg(&s->udev->dev, "%s: pixelformat fourcc %4.4s\n", __func__,
663 (char *)&s->pixelformat);
664
665 f->fmt.sdr.pixelformat = s->pixelformat; 645 f->fmt.sdr.pixelformat = s->pixelformat;
666 f->fmt.sdr.buffersize = s->buffersize; 646 f->fmt.sdr.buffersize = s->buffersize;
667 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 647 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
@@ -676,9 +656,6 @@ static int airspy_s_fmt_sdr_cap(struct file *file, void *priv,
676 struct vb2_queue *q = &s->vb_queue; 656 struct vb2_queue *q = &s->vb_queue;
677 int i; 657 int i;
678 658
679 dev_dbg(&s->udev->dev, "%s: pixelformat fourcc %4.4s\n", __func__,
680 (char *)&f->fmt.sdr.pixelformat);
681
682 if (vb2_is_busy(q)) 659 if (vb2_is_busy(q))
683 return -EBUSY; 660 return -EBUSY;
684 661
@@ -703,12 +680,8 @@ static int airspy_s_fmt_sdr_cap(struct file *file, void *priv,
703static int airspy_try_fmt_sdr_cap(struct file *file, void *priv, 680static int airspy_try_fmt_sdr_cap(struct file *file, void *priv,
704 struct v4l2_format *f) 681 struct v4l2_format *f)
705{ 682{
706 struct airspy *s = video_drvdata(file);
707 int i; 683 int i;
708 684
709 dev_dbg(&s->udev->dev, "%s: pixelformat fourcc %4.4s\n", __func__,
710 (char *)&f->fmt.sdr.pixelformat);
711
712 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 685 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
713 for (i = 0; i < NUM_FORMATS; i++) { 686 for (i = 0; i < NUM_FORMATS; i++) {
714 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { 687 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
@@ -726,11 +699,8 @@ static int airspy_try_fmt_sdr_cap(struct file *file, void *priv,
726static int airspy_s_tuner(struct file *file, void *priv, 699static int airspy_s_tuner(struct file *file, void *priv,
727 const struct v4l2_tuner *v) 700 const struct v4l2_tuner *v)
728{ 701{
729 struct airspy *s = video_drvdata(file);
730 int ret; 702 int ret;
731 703
732 dev_dbg(&s->udev->dev, "%s: index=%d\n", __func__, v->index);
733
734 if (v->index == 0) 704 if (v->index == 0)
735 ret = 0; 705 ret = 0;
736 else if (v->index == 1) 706 else if (v->index == 1)
@@ -743,11 +713,8 @@ static int airspy_s_tuner(struct file *file, void *priv,
743 713
744static int airspy_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v) 714static int airspy_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
745{ 715{
746 struct airspy *s = video_drvdata(file);
747 int ret; 716 int ret;
748 717
749 dev_dbg(&s->udev->dev, "%s: index=%d\n", __func__, v->index);
750
751 if (v->index == 0) { 718 if (v->index == 0) {
752 strlcpy(v->name, "AirSpy ADC", sizeof(v->name)); 719 strlcpy(v->name, "AirSpy ADC", sizeof(v->name));
753 v->type = V4L2_TUNER_ADC; 720 v->type = V4L2_TUNER_ADC;
@@ -773,18 +740,18 @@ static int airspy_g_frequency(struct file *file, void *priv,
773 struct v4l2_frequency *f) 740 struct v4l2_frequency *f)
774{ 741{
775 struct airspy *s = video_drvdata(file); 742 struct airspy *s = video_drvdata(file);
776 int ret = 0; 743 int ret;
777
778 dev_dbg(&s->udev->dev, "%s: tuner=%d type=%d\n",
779 __func__, f->tuner, f->type);
780 744
781 if (f->tuner == 0) { 745 if (f->tuner == 0) {
782 f->type = V4L2_TUNER_ADC; 746 f->type = V4L2_TUNER_ADC;
783 f->frequency = s->f_adc; 747 f->frequency = s->f_adc;
748 dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc);
784 ret = 0; 749 ret = 0;
785 } else if (f->tuner == 1) { 750 } else if (f->tuner == 1) {
786 f->type = V4L2_TUNER_RF; 751 f->type = V4L2_TUNER_RF;
787 f->frequency = s->f_rf; 752 f->frequency = s->f_rf;
753 dev_dbg(s->dev, "RF frequency=%u Hz\n", s->f_rf);
754 ret = 0;
788 } else { 755 } else {
789 ret = -EINVAL; 756 ret = -EINVAL;
790 } 757 }
@@ -799,22 +766,17 @@ static int airspy_s_frequency(struct file *file, void *priv,
799 int ret; 766 int ret;
800 u8 buf[4]; 767 u8 buf[4];
801 768
802 dev_dbg(&s->udev->dev, "%s: tuner=%d type=%d frequency=%u\n",
803 __func__, f->tuner, f->type, f->frequency);
804
805 if (f->tuner == 0) { 769 if (f->tuner == 0) {
806 s->f_adc = clamp_t(unsigned int, f->frequency, 770 s->f_adc = clamp_t(unsigned int, f->frequency,
807 bands[0].rangelow, 771 bands[0].rangelow,
808 bands[0].rangehigh); 772 bands[0].rangehigh);
809 dev_dbg(&s->udev->dev, "%s: ADC frequency=%u Hz\n", 773 dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc);
810 __func__, s->f_adc);
811 ret = 0; 774 ret = 0;
812 } else if (f->tuner == 1) { 775 } else if (f->tuner == 1) {
813 s->f_rf = clamp_t(unsigned int, f->frequency, 776 s->f_rf = clamp_t(unsigned int, f->frequency,
814 bands_rf[0].rangelow, 777 bands_rf[0].rangelow,
815 bands_rf[0].rangehigh); 778 bands_rf[0].rangehigh);
816 dev_dbg(&s->udev->dev, "%s: RF frequency=%u Hz\n", 779 dev_dbg(s->dev, "RF frequency=%u Hz\n", s->f_rf);
817 __func__, s->f_rf);
818 buf[0] = (s->f_rf >> 0) & 0xff; 780 buf[0] = (s->f_rf >> 0) & 0xff;
819 buf[1] = (s->f_rf >> 8) & 0xff; 781 buf[1] = (s->f_rf >> 8) & 0xff;
820 buf[2] = (s->f_rf >> 16) & 0xff; 782 buf[2] = (s->f_rf >> 16) & 0xff;
@@ -830,12 +792,8 @@ static int airspy_s_frequency(struct file *file, void *priv,
830static int airspy_enum_freq_bands(struct file *file, void *priv, 792static int airspy_enum_freq_bands(struct file *file, void *priv,
831 struct v4l2_frequency_band *band) 793 struct v4l2_frequency_band *band)
832{ 794{
833 struct airspy *s = video_drvdata(file);
834 int ret; 795 int ret;
835 796
836 dev_dbg(&s->udev->dev, "%s: tuner=%d type=%d index=%d\n",
837 __func__, band->tuner, band->type, band->index);
838
839 if (band->tuner == 0) { 797 if (band->tuner == 0) {
840 if (band->index >= ARRAY_SIZE(bands)) { 798 if (band->index >= ARRAY_SIZE(bands)) {
841 ret = -EINVAL; 799 ret = -EINVAL;
@@ -918,10 +876,9 @@ static int airspy_set_lna_gain(struct airspy *s)
918 int ret; 876 int ret;
919 u8 u8tmp; 877 u8 u8tmp;
920 878
921 dev_dbg(&s->udev->dev, "%s: lna auto=%d->%d val=%d->%d\n", 879 dev_dbg(s->dev, "lna auto=%d->%d val=%d->%d\n",
922 __func__, s->lna_gain_auto->cur.val, 880 s->lna_gain_auto->cur.val, s->lna_gain_auto->val,
923 s->lna_gain_auto->val, s->lna_gain->cur.val, 881 s->lna_gain->cur.val, s->lna_gain->val);
924 s->lna_gain->val);
925 882
926 ret = airspy_ctrl_msg(s, CMD_SET_LNA_AGC, 0, s->lna_gain_auto->val, 883 ret = airspy_ctrl_msg(s, CMD_SET_LNA_AGC, 0, s->lna_gain_auto->val,
927 &u8tmp, 1); 884 &u8tmp, 1);
@@ -936,7 +893,7 @@ static int airspy_set_lna_gain(struct airspy *s)
936 } 893 }
937err: 894err:
938 if (ret) 895 if (ret)
939 dev_dbg(&s->udev->dev, "%s: failed=%d\n", __func__, ret); 896 dev_dbg(s->dev, "failed=%d\n", ret);
940 897
941 return ret; 898 return ret;
942} 899}
@@ -946,10 +903,9 @@ static int airspy_set_mixer_gain(struct airspy *s)
946 int ret; 903 int ret;
947 u8 u8tmp; 904 u8 u8tmp;
948 905
949 dev_dbg(&s->udev->dev, "%s: mixer auto=%d->%d val=%d->%d\n", 906 dev_dbg(s->dev, "mixer auto=%d->%d val=%d->%d\n",
950 __func__, s->mixer_gain_auto->cur.val, 907 s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val,
951 s->mixer_gain_auto->val, s->mixer_gain->cur.val, 908 s->mixer_gain->cur.val, s->mixer_gain->val);
952 s->mixer_gain->val);
953 909
954 ret = airspy_ctrl_msg(s, CMD_SET_MIXER_AGC, 0, s->mixer_gain_auto->val, 910 ret = airspy_ctrl_msg(s, CMD_SET_MIXER_AGC, 0, s->mixer_gain_auto->val,
955 &u8tmp, 1); 911 &u8tmp, 1);
@@ -964,7 +920,7 @@ static int airspy_set_mixer_gain(struct airspy *s)
964 } 920 }
965err: 921err:
966 if (ret) 922 if (ret)
967 dev_dbg(&s->udev->dev, "%s: failed=%d\n", __func__, ret); 923 dev_dbg(s->dev, "failed=%d\n", ret);
968 924
969 return ret; 925 return ret;
970} 926}
@@ -974,8 +930,7 @@ static int airspy_set_if_gain(struct airspy *s)
974 int ret; 930 int ret;
975 u8 u8tmp; 931 u8 u8tmp;
976 932
977 dev_dbg(&s->udev->dev, "%s: val=%d->%d\n", 933 dev_dbg(s->dev, "val=%d->%d\n", s->if_gain->cur.val, s->if_gain->val);
978 __func__, s->if_gain->cur.val, s->if_gain->val);
979 934
980 ret = airspy_ctrl_msg(s, CMD_SET_VGA_GAIN, 0, s->if_gain->val, 935 ret = airspy_ctrl_msg(s, CMD_SET_VGA_GAIN, 0, s->if_gain->val,
981 &u8tmp, 1); 936 &u8tmp, 1);
@@ -983,7 +938,7 @@ static int airspy_set_if_gain(struct airspy *s)
983 goto err; 938 goto err;
984err: 939err:
985 if (ret) 940 if (ret)
986 dev_dbg(&s->udev->dev, "%s: failed=%d\n", __func__, ret); 941 dev_dbg(s->dev, "failed=%d\n", ret);
987 942
988 return ret; 943 return ret;
989} 944}
@@ -1006,8 +961,8 @@ static int airspy_s_ctrl(struct v4l2_ctrl *ctrl)
1006 ret = airspy_set_if_gain(s); 961 ret = airspy_set_if_gain(s);
1007 break; 962 break;
1008 default: 963 default:
1009 dev_dbg(&s->udev->dev, "%s: unknown ctrl: id=%d name=%s\n", 964 dev_dbg(s->dev, "unknown ctrl: id=%d name=%s\n",
1010 __func__, ctrl->id, ctrl->name); 965 ctrl->id, ctrl->name);
1011 ret = -EINVAL; 966 ret = -EINVAL;
1012 } 967 }
1013 968
@@ -1021,15 +976,13 @@ static const struct v4l2_ctrl_ops airspy_ctrl_ops = {
1021static int airspy_probe(struct usb_interface *intf, 976static int airspy_probe(struct usb_interface *intf,
1022 const struct usb_device_id *id) 977 const struct usb_device_id *id)
1023{ 978{
1024 struct usb_device *udev = interface_to_usbdev(intf); 979 struct airspy *s;
1025 struct airspy *s = NULL;
1026 int ret; 980 int ret;
1027 u8 u8tmp, buf[BUF_SIZE]; 981 u8 u8tmp, buf[BUF_SIZE];
1028 982
1029 s = kzalloc(sizeof(struct airspy), GFP_KERNEL); 983 s = kzalloc(sizeof(struct airspy), GFP_KERNEL);
1030 if (s == NULL) { 984 if (s == NULL) {
1031 dev_err(&udev->dev, 985 dev_err(&intf->dev, "Could not allocate memory for state\n");
1032 "Could not allocate memory for airspy state\n");
1033 return -ENOMEM; 986 return -ENOMEM;
1034 } 987 }
1035 988
@@ -1037,7 +990,8 @@ static int airspy_probe(struct usb_interface *intf,
1037 mutex_init(&s->vb_queue_lock); 990 mutex_init(&s->vb_queue_lock);
1038 spin_lock_init(&s->queued_bufs_lock); 991 spin_lock_init(&s->queued_bufs_lock);
1039 INIT_LIST_HEAD(&s->queued_bufs); 992 INIT_LIST_HEAD(&s->queued_bufs);
1040 s->udev = udev; 993 s->dev = &intf->dev;
994 s->udev = interface_to_usbdev(intf);
1041 s->f_adc = bands[0].rangelow; 995 s->f_adc = bands[0].rangelow;
1042 s->f_rf = bands_rf[0].rangelow; 996 s->f_rf = bands_rf[0].rangelow;
1043 s->pixelformat = formats[0].pixelformat; 997 s->pixelformat = formats[0].pixelformat;
@@ -1049,14 +1003,14 @@ static int airspy_probe(struct usb_interface *intf,
1049 ret = airspy_ctrl_msg(s, CMD_VERSION_STRING_READ, 0, 0, 1003 ret = airspy_ctrl_msg(s, CMD_VERSION_STRING_READ, 0, 0,
1050 buf, BUF_SIZE); 1004 buf, BUF_SIZE);
1051 if (ret) { 1005 if (ret) {
1052 dev_err(&s->udev->dev, "Could not detect board\n"); 1006 dev_err(s->dev, "Could not detect board\n");
1053 goto err_free_mem; 1007 goto err_free_mem;
1054 } 1008 }
1055 1009
1056 buf[BUF_SIZE - 1] = '\0'; 1010 buf[BUF_SIZE - 1] = '\0';
1057 1011
1058 dev_info(&s->udev->dev, "Board ID: %02x\n", u8tmp); 1012 dev_info(s->dev, "Board ID: %02x\n", u8tmp);
1059 dev_info(&s->udev->dev, "Firmware version: %s\n", buf); 1013 dev_info(s->dev, "Firmware version: %s\n", buf);
1060 1014
1061 /* Init videobuf2 queue structure */ 1015 /* Init videobuf2 queue structure */
1062 s->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; 1016 s->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE;
@@ -1068,7 +1022,7 @@ static int airspy_probe(struct usb_interface *intf,
1068 s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1022 s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1069 ret = vb2_queue_init(&s->vb_queue); 1023 ret = vb2_queue_init(&s->vb_queue);
1070 if (ret) { 1024 if (ret) {
1071 dev_err(&s->udev->dev, "Could not initialize vb2 queue\n"); 1025 dev_err(s->dev, "Could not initialize vb2 queue\n");
1072 goto err_free_mem; 1026 goto err_free_mem;
1073 } 1027 }
1074 1028
@@ -1082,8 +1036,7 @@ static int airspy_probe(struct usb_interface *intf,
1082 s->v4l2_dev.release = airspy_video_release; 1036 s->v4l2_dev.release = airspy_video_release;
1083 ret = v4l2_device_register(&intf->dev, &s->v4l2_dev); 1037 ret = v4l2_device_register(&intf->dev, &s->v4l2_dev);
1084 if (ret) { 1038 if (ret) {
1085 dev_err(&s->udev->dev, 1039 dev_err(s->dev, "Failed to register v4l2-device (%d)\n", ret);
1086 "Failed to register v4l2-device (%d)\n", ret);
1087 goto err_free_mem; 1040 goto err_free_mem;
1088 } 1041 }
1089 1042
@@ -1103,7 +1056,7 @@ static int airspy_probe(struct usb_interface *intf,
1103 V4L2_CID_RF_TUNER_IF_GAIN, 0, 15, 1, 0); 1056 V4L2_CID_RF_TUNER_IF_GAIN, 0, 15, 1, 0);
1104 if (s->hdl.error) { 1057 if (s->hdl.error) {
1105 ret = s->hdl.error; 1058 ret = s->hdl.error;
1106 dev_err(&s->udev->dev, "Could not initialize controls\n"); 1059 dev_err(s->dev, "Could not initialize controls\n");
1107 goto err_free_controls; 1060 goto err_free_controls;
1108 } 1061 }
1109 1062
@@ -1115,16 +1068,13 @@ static int airspy_probe(struct usb_interface *intf,
1115 1068
1116 ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1); 1069 ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1);
1117 if (ret) { 1070 if (ret) {
1118 dev_err(&s->udev->dev, 1071 dev_err(s->dev, "Failed to register as video device (%d)\n",
1119 "Failed to register as video device (%d)\n",
1120 ret); 1072 ret);
1121 goto err_unregister_v4l2_dev; 1073 goto err_unregister_v4l2_dev;
1122 } 1074 }
1123 dev_info(&s->udev->dev, "Registered as %s\n", 1075 dev_info(s->dev, "Registered as %s\n",
1124 video_device_node_name(&s->vdev)); 1076 video_device_node_name(&s->vdev));
1125 dev_notice(&s->udev->dev, 1077 dev_notice(s->dev, "SDR API is still slightly experimental and functionality changes may follow\n");
1126 "%s: SDR API is still slightly experimental and functionality changes may follow\n",
1127 KBUILD_MODNAME);
1128 return 0; 1078 return 0;
1129 1079
1130err_free_controls: 1080err_free_controls: