aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb/msi2500/msi2500.c
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2014-08-24 21:54:06 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2014-09-21 15:42:34 -0400
commit100b7931f4c300fd6c278d890a92b9668feaf44d (patch)
treee12d2b161b8a645ba1b5441daaa7631198c10a77 /drivers/media/usb/msi2500/msi2500.c
parentb8843c7979fc8ea54efeaef8e9d524c33c42f099 (diff)
[media] msi2500: logging changes
Kernel logging system needs pointer to usb interface device in order to print names and bus numbers properly. There was wrong device pointer given and log printings wasn't correct. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/usb/msi2500/msi2500.c')
-rw-r--r--drivers/media/usb/msi2500/msi2500.c157
1 files changed, 66 insertions, 91 deletions
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index e980aaa47b7c..647846b5904a 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -120,6 +120,7 @@ struct msi2500_frame_buf {
120}; 120};
121 121
122struct msi2500_state { 122struct msi2500_state {
123 struct device *dev;
123 struct video_device vdev; 124 struct video_device vdev;
124 struct v4l2_device v4l2_dev; 125 struct v4l2_device v4l2_dev;
125 struct v4l2_subdev *v4l2_subdev; 126 struct v4l2_subdev *v4l2_subdev;
@@ -153,7 +154,6 @@ struct msi2500_state {
153 u32 next_sample; /* for track lost packets */ 154 u32 next_sample; /* for track lost packets */
154 u32 sample; /* for sample rate calc */ 155 u32 sample; /* for sample rate calc */
155 unsigned long jiffies_next; 156 unsigned long jiffies_next;
156 unsigned int sample_ctrl_bit[4];
157}; 157};
158 158
159/* Private functions */ 159/* Private functions */
@@ -269,7 +269,7 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
269 sample[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | 269 sample[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 |
270 src[0] << 0; 270 src[0] << 0;
271 if (i == 0 && s->next_sample != sample[0]) { 271 if (i == 0 && s->next_sample != sample[0]) {
272 dev_dbg_ratelimited(&s->udev->dev, 272 dev_dbg_ratelimited(s->dev,
273 "%d samples lost, %d %08x:%08x\n", 273 "%d samples lost, %d %08x:%08x\n",
274 sample[0] - s->next_sample, 274 sample[0] - s->next_sample,
275 src_len, s->next_sample, sample[0]); 275 src_len, s->next_sample, sample[0]);
@@ -279,7 +279,7 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
279 * Dump all unknown 'garbage' data - maybe we will discover 279 * Dump all unknown 'garbage' data - maybe we will discover
280 * someday if there is something rational... 280 * someday if there is something rational...
281 */ 281 */
282 dev_dbg_ratelimited(&s->udev->dev, "%*ph\n", 12, &src[4]); 282 dev_dbg_ratelimited(s->dev, "%*ph\n", 12, &src[4]);
283 283
284 src += 16; /* skip header */ 284 src += 16; /* skip header */
285 285
@@ -322,8 +322,7 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
322 } 322 }
323 case MSI2500_PIX_FMT_SDR_MSI2500_384: /* 384 x IQ samples */ 323 case MSI2500_PIX_FMT_SDR_MSI2500_384: /* 384 x IQ samples */
324 /* Dump unknown 'garbage' data */ 324 /* Dump unknown 'garbage' data */
325 dev_dbg_ratelimited(&s->udev->dev, 325 dev_dbg_ratelimited(s->dev, "%*ph\n", 24, &src[1000]);
326 "%*ph\n", 24, &src[1000]);
327 memcpy(dst, src, 984); 326 memcpy(dst, src, 984);
328 src += 984 + 24; 327 src += 984 + 24;
329 dst += 984; 328 dst += 984;
@@ -365,8 +364,7 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
365 364
366 s->jiffies_next = jiffies + msecs_to_jiffies(MSECS); 365 s->jiffies_next = jiffies + msecs_to_jiffies(MSECS);
367 s->sample = s->next_sample; 366 s->sample = s->next_sample;
368 dev_dbg(&s->udev->dev, 367 dev_dbg(s->dev, "size=%u samples=%u msecs=%u sample rate=%lu\n",
369 "size=%u samples=%u msecs=%u sample rate=%lu\n",
370 src_len, samples, msecs, 368 src_len, samples, msecs,
371 samples * 1000UL / msecs); 369 samples * 1000UL / msecs);
372 } 370 }
@@ -387,19 +385,16 @@ static void msi2500_isoc_handler(struct urb *urb)
387 385
388 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 386 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
389 urb->status == -ESHUTDOWN)) { 387 urb->status == -ESHUTDOWN)) {
390 dev_dbg(&s->udev->dev, "URB (%p) unlinked %ssynchronuously\n", 388 dev_dbg(s->dev, "URB (%p) unlinked %ssynchronuously\n",
391 urb, urb->status == -ENOENT ? "" : "a"); 389 urb, urb->status == -ENOENT ? "" : "a");
392 return; 390 return;
393 } 391 }
394 392
395 if (unlikely(urb->status != 0)) { 393 if (unlikely(urb->status != 0)) {
396 dev_dbg(&s->udev->dev, 394 dev_dbg(s->dev, "called with status %d\n", urb->status);
397 "msi2500_isoc_handler() called with status %d\n",
398 urb->status);
399 /* Give up after a number of contiguous errors */ 395 /* Give up after a number of contiguous errors */
400 if (++s->isoc_errors > MAX_ISOC_ERRORS) 396 if (++s->isoc_errors > MAX_ISOC_ERRORS)
401 dev_dbg(&s->udev->dev, 397 dev_dbg(s->dev, "Too many ISOC errors, bailing out\n");
402 "Too many ISOC errors, bailing out\n");
403 goto handler_end; 398 goto handler_end;
404 } else { 399 } else {
405 /* Reset ISOC error counter. We did get here, after all. */ 400 /* Reset ISOC error counter. We did get here, after all. */
@@ -413,7 +408,7 @@ static void msi2500_isoc_handler(struct urb *urb)
413 /* Check frame error */ 408 /* Check frame error */
414 fstatus = urb->iso_frame_desc[i].status; 409 fstatus = urb->iso_frame_desc[i].status;
415 if (unlikely(fstatus)) { 410 if (unlikely(fstatus)) {
416 dev_dbg_ratelimited(&s->udev->dev, 411 dev_dbg_ratelimited(s->dev,
417 "frame=%d/%d has error %d skipping\n", 412 "frame=%d/%d has error %d skipping\n",
418 i, urb->number_of_packets, fstatus); 413 i, urb->number_of_packets, fstatus);
419 continue; 414 continue;
@@ -430,7 +425,7 @@ static void msi2500_isoc_handler(struct urb *urb)
430 fbuf = msi2500_get_next_fill_buf(s); 425 fbuf = msi2500_get_next_fill_buf(s);
431 if (unlikely(fbuf == NULL)) { 426 if (unlikely(fbuf == NULL)) {
432 s->vb_full++; 427 s->vb_full++;
433 dev_dbg_ratelimited(&s->udev->dev, 428 dev_dbg_ratelimited(s->dev,
434 "videobuf is full, %d packets dropped\n", 429 "videobuf is full, %d packets dropped\n",
435 s->vb_full); 430 s->vb_full);
436 continue; 431 continue;
@@ -446,22 +441,19 @@ static void msi2500_isoc_handler(struct urb *urb)
446handler_end: 441handler_end:
447 i = usb_submit_urb(urb, GFP_ATOMIC); 442 i = usb_submit_urb(urb, GFP_ATOMIC);
448 if (unlikely(i != 0)) 443 if (unlikely(i != 0))
449 dev_dbg(&s->udev->dev, 444 dev_dbg(s->dev, "Error (%d) re-submitting urb\n", i);
450 "Error (%d) re-submitting urb in msi2500_isoc_handler\n",
451 i);
452} 445}
453 446
454static void msi2500_iso_stop(struct msi2500_state *s) 447static void msi2500_iso_stop(struct msi2500_state *s)
455{ 448{
456 int i; 449 int i;
457 450
458 dev_dbg(&s->udev->dev, "%s:\n", __func__); 451 dev_dbg(s->dev, "\n");
459 452
460 /* Unlinking ISOC buffers one by one */ 453 /* Unlinking ISOC buffers one by one */
461 for (i = 0; i < MAX_ISO_BUFS; i++) { 454 for (i = 0; i < MAX_ISO_BUFS; i++) {
462 if (s->urbs[i]) { 455 if (s->urbs[i]) {
463 dev_dbg(&s->udev->dev, "Unlinking URB %p\n", 456 dev_dbg(s->dev, "Unlinking URB %p\n", s->urbs[i]);
464 s->urbs[i]);
465 usb_kill_urb(s->urbs[i]); 457 usb_kill_urb(s->urbs[i]);
466 } 458 }
467 } 459 }
@@ -471,12 +463,12 @@ static void msi2500_iso_free(struct msi2500_state *s)
471{ 463{
472 int i; 464 int i;
473 465
474 dev_dbg(&s->udev->dev, "%s:\n", __func__); 466 dev_dbg(s->dev, "\n");
475 467
476 /* Freeing ISOC buffers one by one */ 468 /* Freeing ISOC buffers one by one */
477 for (i = 0; i < MAX_ISO_BUFS; i++) { 469 for (i = 0; i < MAX_ISO_BUFS; i++) {
478 if (s->urbs[i]) { 470 if (s->urbs[i]) {
479 dev_dbg(&s->udev->dev, "Freeing URB\n"); 471 dev_dbg(s->dev, "Freeing URB\n");
480 if (s->urbs[i]->transfer_buffer) { 472 if (s->urbs[i]->transfer_buffer) {
481 usb_free_coherent(s->udev, 473 usb_free_coherent(s->udev,
482 s->urbs[i]->transfer_buffer_length, 474 s->urbs[i]->transfer_buffer_length,
@@ -492,7 +484,7 @@ static void msi2500_iso_free(struct msi2500_state *s)
492/* Both v4l2_lock and vb_queue_lock should be locked when calling this */ 484/* Both v4l2_lock and vb_queue_lock should be locked when calling this */
493static void msi2500_isoc_cleanup(struct msi2500_state *s) 485static void msi2500_isoc_cleanup(struct msi2500_state *s)
494{ 486{
495 dev_dbg(&s->udev->dev, "%s:\n", __func__); 487 dev_dbg(s->dev, "\n");
496 488
497 msi2500_iso_stop(s); 489 msi2500_iso_stop(s);
498 msi2500_iso_free(s); 490 msi2500_iso_free(s);
@@ -504,7 +496,7 @@ static int msi2500_isoc_init(struct msi2500_state *s)
504 struct urb *urb; 496 struct urb *urb;
505 int i, j, ret; 497 int i, j, ret;
506 498
507 dev_dbg(&s->udev->dev, "%s:\n", __func__); 499 dev_dbg(s->dev, "\n");
508 500
509 s->isoc_errors = 0; 501 s->isoc_errors = 0;
510 502
@@ -516,13 +508,12 @@ static int msi2500_isoc_init(struct msi2500_state *s)
516 for (i = 0; i < MAX_ISO_BUFS; i++) { 508 for (i = 0; i < MAX_ISO_BUFS; i++) {
517 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); 509 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
518 if (urb == NULL) { 510 if (urb == NULL) {
519 dev_err(&s->udev->dev, 511 dev_err(s->dev, "Failed to allocate urb %d\n", i);
520 "Failed to allocate urb %d\n", i);
521 msi2500_isoc_cleanup(s); 512 msi2500_isoc_cleanup(s);
522 return -ENOMEM; 513 return -ENOMEM;
523 } 514 }
524 s->urbs[i] = urb; 515 s->urbs[i] = urb;
525 dev_dbg(&s->udev->dev, "Allocated URB at 0x%p\n", urb); 516 dev_dbg(s->dev, "Allocated URB at 0x%p\n", urb);
526 517
527 urb->interval = 1; 518 urb->interval = 1;
528 urb->dev = s->udev; 519 urb->dev = s->udev;
@@ -532,8 +523,7 @@ static int msi2500_isoc_init(struct msi2500_state *s)
532 ISO_BUFFER_SIZE, 523 ISO_BUFFER_SIZE,
533 GFP_KERNEL, &urb->transfer_dma); 524 GFP_KERNEL, &urb->transfer_dma);
534 if (urb->transfer_buffer == NULL) { 525 if (urb->transfer_buffer == NULL) {
535 dev_err(&s->udev->dev, 526 dev_err(s->dev, "Failed to allocate urb buffer %d\n",
536 "Failed to allocate urb buffer %d\n",
537 i); 527 i);
538 msi2500_isoc_cleanup(s); 528 msi2500_isoc_cleanup(s);
539 return -ENOMEM; 529 return -ENOMEM;
@@ -553,13 +543,12 @@ static int msi2500_isoc_init(struct msi2500_state *s)
553 for (i = 0; i < MAX_ISO_BUFS; i++) { 543 for (i = 0; i < MAX_ISO_BUFS; i++) {
554 ret = usb_submit_urb(s->urbs[i], GFP_KERNEL); 544 ret = usb_submit_urb(s->urbs[i], GFP_KERNEL);
555 if (ret) { 545 if (ret) {
556 dev_err(&s->udev->dev, 546 dev_err(s->dev, "usb_submit_urb %d failed with error %d\n",
557 "isoc_init() submit_urb %d failed with error %d\n",
558 i, ret); 547 i, ret);
559 msi2500_isoc_cleanup(s); 548 msi2500_isoc_cleanup(s);
560 return ret; 549 return ret;
561 } 550 }
562 dev_dbg(&s->udev->dev, "URB 0x%p submitted.\n", s->urbs[i]); 551 dev_dbg(s->dev, "URB 0x%p submitted.\n", s->urbs[i]);
563 } 552 }
564 553
565 /* All is done... */ 554 /* All is done... */
@@ -571,7 +560,7 @@ static void msi2500_cleanup_queued_bufs(struct msi2500_state *s)
571{ 560{
572 unsigned long flags = 0; 561 unsigned long flags = 0;
573 562
574 dev_dbg(&s->udev->dev, "%s:\n", __func__); 563 dev_dbg(s->dev, "\n");
575 564
576 spin_lock_irqsave(&s->queued_bufs_lock, flags); 565 spin_lock_irqsave(&s->queued_bufs_lock, flags);
577 while (!list_empty(&s->queued_bufs)) { 566 while (!list_empty(&s->queued_bufs)) {
@@ -592,7 +581,7 @@ static void msi2500_disconnect(struct usb_interface *intf)
592 struct msi2500_state *s = 581 struct msi2500_state *s =
593 container_of(v, struct msi2500_state, v4l2_dev); 582 container_of(v, struct msi2500_state, v4l2_dev);
594 583
595 dev_dbg(&s->udev->dev, "%s:\n", __func__); 584 dev_dbg(s->dev, "\n");
596 585
597 mutex_lock(&s->vb_queue_lock); 586 mutex_lock(&s->vb_queue_lock);
598 mutex_lock(&s->v4l2_lock); 587 mutex_lock(&s->v4l2_lock);
@@ -612,7 +601,7 @@ static int msi2500_querycap(struct file *file, void *fh,
612{ 601{
613 struct msi2500_state *s = video_drvdata(file); 602 struct msi2500_state *s = video_drvdata(file);
614 603
615 dev_dbg(&s->udev->dev, "%s:\n", __func__); 604 dev_dbg(s->dev, "\n");
616 605
617 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); 606 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
618 strlcpy(cap->card, s->vdev.name, sizeof(cap->card)); 607 strlcpy(cap->card, s->vdev.name, sizeof(cap->card));
@@ -630,14 +619,13 @@ static int msi2500_queue_setup(struct vb2_queue *vq,
630{ 619{
631 struct msi2500_state *s = vb2_get_drv_priv(vq); 620 struct msi2500_state *s = vb2_get_drv_priv(vq);
632 621
633 dev_dbg(&s->udev->dev, "%s: *nbuffers=%d\n", __func__, *nbuffers); 622 dev_dbg(s->dev, "nbuffers=%d\n", *nbuffers);
634 623
635 /* Absolute min and max number of buffers available for mmap() */ 624 /* Absolute min and max number of buffers available for mmap() */
636 *nbuffers = clamp_t(unsigned int, *nbuffers, 8, 32); 625 *nbuffers = clamp_t(unsigned int, *nbuffers, 8, 32);
637 *nplanes = 1; 626 *nplanes = 1;
638 sizes[0] = PAGE_ALIGN(s->buffersize); 627 sizes[0] = PAGE_ALIGN(s->buffersize);
639 dev_dbg(&s->udev->dev, "%s: nbuffers=%d sizes[0]=%d\n", 628 dev_dbg(s->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]);
640 __func__, *nbuffers, sizes[0]);
641 return 0; 629 return 0;
642} 630}
643 631
@@ -664,16 +652,15 @@ static void msi2500_buf_queue(struct vb2_buffer *vb)
664#define CMD_STOP_STREAMING 0x45 652#define CMD_STOP_STREAMING 0x45
665#define CMD_READ_UNKNOW 0x48 653#define CMD_READ_UNKNOW 0x48
666 654
667#define msi2500_dbg_usb_control_msg(_udev, _r, _t, _v, _i, _b, _l) { \ 655#define msi2500_dbg_usb_control_msg(_dev, _r, _t, _v, _i, _b, _l) { \
668 char *_direction; \ 656 char *_direction; \
669 if (_t & USB_DIR_IN) \ 657 if (_t & USB_DIR_IN) \
670 _direction = "<<<"; \ 658 _direction = "<<<"; \
671 else \ 659 else \
672 _direction = ">>>"; \ 660 _direction = ">>>"; \
673 dev_dbg(&_udev->dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x " \ 661 dev_dbg(_dev, "%02x %02x %02x %02x %02x %02x %02x %02x %s %*ph\n", \
674 "%s %*ph\n", __func__, _t, _r, _v & 0xff, _v >> 8, \ 662 _t, _r, _v & 0xff, _v >> 8, _i & 0xff, _i >> 8, \
675 _i & 0xff, _i >> 8, _l & 0xff, _l >> 8, _direction, \ 663 _l & 0xff, _l >> 8, _direction, _l, _b); \
676 _l, _b); \
677} 664}
678 665
679static int msi2500_ctrl_msg(struct msi2500_state *s, u8 cmd, u32 data) 666static int msi2500_ctrl_msg(struct msi2500_state *s, u8 cmd, u32 data)
@@ -684,18 +671,16 @@ static int msi2500_ctrl_msg(struct msi2500_state *s, u8 cmd, u32 data)
684 u16 value = (data >> 0) & 0xffff; 671 u16 value = (data >> 0) & 0xffff;
685 u16 index = (data >> 16) & 0xffff; 672 u16 index = (data >> 16) & 0xffff;
686 673
687 msi2500_dbg_usb_control_msg(s->udev, 674 msi2500_dbg_usb_control_msg(s->dev,
688 request, requesttype, value, index, NULL, 0); 675 request, requesttype, value, index, NULL, 0);
689
690 ret = usb_control_msg(s->udev, usb_sndctrlpipe(s->udev, 0), 676 ret = usb_control_msg(s->udev, usb_sndctrlpipe(s->udev, 0),
691 request, requesttype, value, index, NULL, 0, 2000); 677 request, requesttype, value, index, NULL, 0, 2000);
692
693 if (ret) 678 if (ret)
694 dev_err(&s->udev->dev, "%s: failed %d, cmd %02x, data %04x\n", 679 dev_err(s->dev, "failed %d, cmd %02x, data %04x\n",
695 __func__, ret, cmd, data); 680 ret, cmd, data);
696 681
697 return ret; 682 return ret;
698}; 683}
699 684
700#define F_REF 24000000 685#define F_REF 24000000
701#define DIV_R_IN 2 686#define DIV_R_IN 2
@@ -784,8 +769,7 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
784 769
785 for (div_r_out = 4; div_r_out < 16; div_r_out += 2) { 770 for (div_r_out = 4; div_r_out < 16; div_r_out += 2) {
786 f_vco = f_sr * div_r_out * 12; 771 f_vco = f_sr * div_r_out * 12;
787 dev_dbg(&s->udev->dev, "%s: div_r_out=%d f_vco=%d\n", 772 dev_dbg(s->dev, "div_r_out=%d f_vco=%d\n", div_r_out, f_vco);
788 __func__, div_r_out, f_vco);
789 if (f_vco >= 202000000) 773 if (f_vco >= 202000000)
790 break; 774 break;
791 } 775 }
@@ -799,10 +783,8 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
799 reg3 |= ((fract >> 20) & 0x000001) << 15; /* [20] */ 783 reg3 |= ((fract >> 20) & 0x000001) << 15; /* [20] */
800 reg4 |= ((fract >> 0) & 0x0fffff) << 8; /* [19:0] */ 784 reg4 |= ((fract >> 0) & 0x0fffff) << 8; /* [19:0] */
801 785
802 dev_dbg(&s->udev->dev, 786 dev_dbg(s->dev, "f_sr=%d f_vco=%d div_n=%d div_m=%d div_r_out=%d reg3=%08x reg4=%08x\n",
803 "%s: f_sr=%d f_vco=%d div_n=%d div_m=%d div_r_out=%d reg3=%08x reg4=%08x\n", 787 f_sr, f_vco, div_n, div_m, div_r_out, reg3, reg4);
804 __func__, f_sr, f_vco, div_n, div_m, div_r_out, reg3,
805 reg4);
806 788
807 ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00608008); 789 ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00608008);
808 if (ret) 790 if (ret)
@@ -837,14 +819,14 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
837 goto err; 819 goto err;
838err: 820err:
839 return ret; 821 return ret;
840}; 822}
841 823
842static int msi2500_start_streaming(struct vb2_queue *vq, unsigned int count) 824static int msi2500_start_streaming(struct vb2_queue *vq, unsigned int count)
843{ 825{
844 struct msi2500_state *s = vb2_get_drv_priv(vq); 826 struct msi2500_state *s = vb2_get_drv_priv(vq);
845 int ret; 827 int ret;
846 828
847 dev_dbg(&s->udev->dev, "%s:\n", __func__); 829 dev_dbg(s->dev, "\n");
848 830
849 if (!s->udev) 831 if (!s->udev)
850 return -ENODEV; 832 return -ENODEV;
@@ -872,7 +854,7 @@ static void msi2500_stop_streaming(struct vb2_queue *vq)
872{ 854{
873 struct msi2500_state *s = vb2_get_drv_priv(vq); 855 struct msi2500_state *s = vb2_get_drv_priv(vq);
874 856
875 dev_dbg(&s->udev->dev, "%s:\n", __func__); 857 dev_dbg(s->dev, "\n");
876 858
877 mutex_lock(&s->v4l2_lock); 859 mutex_lock(&s->v4l2_lock);
878 860
@@ -908,7 +890,7 @@ static int msi2500_enum_fmt_sdr_cap(struct file *file, void *priv,
908{ 890{
909 struct msi2500_state *s = video_drvdata(file); 891 struct msi2500_state *s = video_drvdata(file);
910 892
911 dev_dbg(&s->udev->dev, "%s: index=%d\n", __func__, f->index); 893 dev_dbg(s->dev, "index=%d\n", f->index);
912 894
913 if (f->index >= s->num_formats) 895 if (f->index >= s->num_formats)
914 return -EINVAL; 896 return -EINVAL;
@@ -924,7 +906,7 @@ static int msi2500_g_fmt_sdr_cap(struct file *file, void *priv,
924{ 906{
925 struct msi2500_state *s = video_drvdata(file); 907 struct msi2500_state *s = video_drvdata(file);
926 908
927 dev_dbg(&s->udev->dev, "%s: pixelformat fourcc %4.4s\n", __func__, 909 dev_dbg(s->dev, "pixelformat fourcc %4.4s\n",
928 (char *)&s->pixelformat); 910 (char *)&s->pixelformat);
929 911
930 f->fmt.sdr.pixelformat = s->pixelformat; 912 f->fmt.sdr.pixelformat = s->pixelformat;
@@ -941,7 +923,7 @@ static int msi2500_s_fmt_sdr_cap(struct file *file, void *priv,
941 struct vb2_queue *q = &s->vb_queue; 923 struct vb2_queue *q = &s->vb_queue;
942 int i; 924 int i;
943 925
944 dev_dbg(&s->udev->dev, "%s: pixelformat fourcc %4.4s\n", __func__, 926 dev_dbg(s->dev, "pixelformat fourcc %4.4s\n",
945 (char *)&f->fmt.sdr.pixelformat); 927 (char *)&f->fmt.sdr.pixelformat);
946 928
947 if (vb2_is_busy(q)) 929 if (vb2_is_busy(q))
@@ -971,7 +953,7 @@ static int msi2500_try_fmt_sdr_cap(struct file *file, void *priv,
971 struct msi2500_state *s = video_drvdata(file); 953 struct msi2500_state *s = video_drvdata(file);
972 int i; 954 int i;
973 955
974 dev_dbg(&s->udev->dev, "%s: pixelformat fourcc %4.4s\n", __func__, 956 dev_dbg(s->dev, "pixelformat fourcc %4.4s\n",
975 (char *)&f->fmt.sdr.pixelformat); 957 (char *)&f->fmt.sdr.pixelformat);
976 958
977 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 959 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
@@ -994,7 +976,7 @@ static int msi2500_s_tuner(struct file *file, void *priv,
994 struct msi2500_state *s = video_drvdata(file); 976 struct msi2500_state *s = video_drvdata(file);
995 int ret; 977 int ret;
996 978
997 dev_dbg(&s->udev->dev, "%s: index=%d\n", __func__, v->index); 979 dev_dbg(s->dev, "index=%d\n", v->index);
998 980
999 if (v->index == 0) 981 if (v->index == 0)
1000 ret = 0; 982 ret = 0;
@@ -1011,7 +993,7 @@ static int msi2500_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
1011 struct msi2500_state *s = video_drvdata(file); 993 struct msi2500_state *s = video_drvdata(file);
1012 int ret; 994 int ret;
1013 995
1014 dev_dbg(&s->udev->dev, "%s: index=%d\n", __func__, v->index); 996 dev_dbg(s->dev, "index=%d\n", v->index);
1015 997
1016 if (v->index == 0) { 998 if (v->index == 0) {
1017 strlcpy(v->name, "Mirics MSi2500", sizeof(v->name)); 999 strlcpy(v->name, "Mirics MSi2500", sizeof(v->name));
@@ -1035,8 +1017,7 @@ static int msi2500_g_frequency(struct file *file, void *priv,
1035 struct msi2500_state *s = video_drvdata(file); 1017 struct msi2500_state *s = video_drvdata(file);
1036 int ret = 0; 1018 int ret = 0;
1037 1019
1038 dev_dbg(&s->udev->dev, "%s: tuner=%d type=%d\n", 1020 dev_dbg(s->dev, "tuner=%d type=%d\n", f->tuner, f->type);
1039 __func__, f->tuner, f->type);
1040 1021
1041 if (f->tuner == 0) { 1022 if (f->tuner == 0) {
1042 f->frequency = s->f_adc; 1023 f->frequency = s->f_adc;
@@ -1057,15 +1038,14 @@ static int msi2500_s_frequency(struct file *file, void *priv,
1057 struct msi2500_state *s = video_drvdata(file); 1038 struct msi2500_state *s = video_drvdata(file);
1058 int ret; 1039 int ret;
1059 1040
1060 dev_dbg(&s->udev->dev, "%s: tuner=%d type=%d frequency=%u\n", 1041 dev_dbg(s->dev, "tuner=%d type=%d frequency=%u\n",
1061 __func__, f->tuner, f->type, f->frequency); 1042 f->tuner, f->type, f->frequency);
1062 1043
1063 if (f->tuner == 0) { 1044 if (f->tuner == 0) {
1064 s->f_adc = clamp_t(unsigned int, f->frequency, 1045 s->f_adc = clamp_t(unsigned int, f->frequency,
1065 bands[0].rangelow, 1046 bands[0].rangelow,
1066 bands[0].rangehigh); 1047 bands[0].rangehigh);
1067 dev_dbg(&s->udev->dev, "%s: ADC frequency=%u Hz\n", 1048 dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc);
1068 __func__, s->f_adc);
1069 ret = msi2500_set_usb_adc(s); 1049 ret = msi2500_set_usb_adc(s);
1070 } else if (f->tuner == 1) { 1050 } else if (f->tuner == 1) {
1071 ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_frequency, f); 1051 ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_frequency, f);
@@ -1082,8 +1062,8 @@ static int msi2500_enum_freq_bands(struct file *file, void *priv,
1082 struct msi2500_state *s = video_drvdata(file); 1062 struct msi2500_state *s = video_drvdata(file);
1083 int ret; 1063 int ret;
1084 1064
1085 dev_dbg(&s->udev->dev, "%s: tuner=%d type=%d index=%d\n", 1065 dev_dbg(s->dev, "tuner=%d type=%d index=%d\n",
1086 __func__, band->tuner, band->type, band->index); 1066 band->tuner, band->type, band->index);
1087 1067
1088 if (band->tuner == 0) { 1068 if (band->tuner == 0) {
1089 if (band->index >= ARRAY_SIZE(bands)) { 1069 if (band->index >= ARRAY_SIZE(bands)) {
@@ -1168,8 +1148,7 @@ static int msi2500_transfer_one_message(struct spi_master *master,
1168 u32 data; 1148 u32 data;
1169 1149
1170 list_for_each_entry(t, &m->transfers, transfer_list) { 1150 list_for_each_entry(t, &m->transfers, transfer_list) {
1171 dev_dbg(&s->udev->dev, "%s: msg=%*ph\n", 1151 dev_dbg(s->dev, "msg=%*ph\n", t->len, t->tx_buf);
1172 __func__, t->len, t->tx_buf);
1173 data = 0x09; /* reg 9 is SPI adapter */ 1152 data = 0x09; /* reg 9 is SPI adapter */
1174 data |= ((u8 *)t->tx_buf)[0] << 8; 1153 data |= ((u8 *)t->tx_buf)[0] << 8;
1175 data |= ((u8 *)t->tx_buf)[1] << 16; 1154 data |= ((u8 *)t->tx_buf)[1] << 16;
@@ -1185,8 +1164,7 @@ static int msi2500_transfer_one_message(struct spi_master *master,
1185static int msi2500_probe(struct usb_interface *intf, 1164static int msi2500_probe(struct usb_interface *intf,
1186 const struct usb_device_id *id) 1165 const struct usb_device_id *id)
1187{ 1166{
1188 struct usb_device *udev = interface_to_usbdev(intf); 1167 struct msi2500_state *s;
1189 struct msi2500_state *s = NULL;
1190 struct v4l2_subdev *sd; 1168 struct v4l2_subdev *sd;
1191 struct spi_master *master; 1169 struct spi_master *master;
1192 int ret; 1170 int ret;
@@ -1199,7 +1177,7 @@ static int msi2500_probe(struct usb_interface *intf,
1199 1177
1200 s = kzalloc(sizeof(struct msi2500_state), GFP_KERNEL); 1178 s = kzalloc(sizeof(struct msi2500_state), GFP_KERNEL);
1201 if (s == NULL) { 1179 if (s == NULL) {
1202 pr_err("Could not allocate memory for msi2500_state\n"); 1180 dev_err(&intf->dev, "Could not allocate memory for state\n");
1203 return -ENOMEM; 1181 return -ENOMEM;
1204 } 1182 }
1205 1183
@@ -1207,7 +1185,8 @@ static int msi2500_probe(struct usb_interface *intf,
1207 mutex_init(&s->vb_queue_lock); 1185 mutex_init(&s->vb_queue_lock);
1208 spin_lock_init(&s->queued_bufs_lock); 1186 spin_lock_init(&s->queued_bufs_lock);
1209 INIT_LIST_HEAD(&s->queued_bufs); 1187 INIT_LIST_HEAD(&s->queued_bufs);
1210 s->udev = udev; 1188 s->dev = &intf->dev;
1189 s->udev = interface_to_usbdev(intf);
1211 s->f_adc = bands[0].rangelow; 1190 s->f_adc = bands[0].rangelow;
1212 s->pixelformat = formats[0].pixelformat; 1191 s->pixelformat = formats[0].pixelformat;
1213 s->buffersize = formats[0].buffersize; 1192 s->buffersize = formats[0].buffersize;
@@ -1225,7 +1204,7 @@ static int msi2500_probe(struct usb_interface *intf,
1225 s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1204 s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1226 ret = vb2_queue_init(&s->vb_queue); 1205 ret = vb2_queue_init(&s->vb_queue);
1227 if (ret) { 1206 if (ret) {
1228 dev_err(&s->udev->dev, "Could not initialize vb2 queue\n"); 1207 dev_err(s->dev, "Could not initialize vb2 queue\n");
1229 goto err_free_mem; 1208 goto err_free_mem;
1230 } 1209 }
1231 1210
@@ -1239,13 +1218,12 @@ static int msi2500_probe(struct usb_interface *intf,
1239 s->v4l2_dev.release = msi2500_video_release; 1218 s->v4l2_dev.release = msi2500_video_release;
1240 ret = v4l2_device_register(&intf->dev, &s->v4l2_dev); 1219 ret = v4l2_device_register(&intf->dev, &s->v4l2_dev);
1241 if (ret) { 1220 if (ret) {
1242 dev_err(&s->udev->dev, 1221 dev_err(s->dev, "Failed to register v4l2-device (%d)\n", ret);
1243 "Failed to register v4l2-device (%d)\n", ret);
1244 goto err_free_mem; 1222 goto err_free_mem;
1245 } 1223 }
1246 1224
1247 /* SPI master adapter */ 1225 /* SPI master adapter */
1248 master = spi_alloc_master(&s->udev->dev, 0); 1226 master = spi_alloc_master(s->dev, 0);
1249 if (master == NULL) { 1227 if (master == NULL) {
1250 ret = -ENOMEM; 1228 ret = -ENOMEM;
1251 goto err_unregister_v4l2_dev; 1229 goto err_unregister_v4l2_dev;
@@ -1266,7 +1244,7 @@ static int msi2500_probe(struct usb_interface *intf,
1266 sd = v4l2_spi_new_subdev(&s->v4l2_dev, master, &board_info); 1244 sd = v4l2_spi_new_subdev(&s->v4l2_dev, master, &board_info);
1267 s->v4l2_subdev = sd; 1245 s->v4l2_subdev = sd;
1268 if (sd == NULL) { 1246 if (sd == NULL) {
1269 dev_err(&s->udev->dev, "cannot get v4l2 subdevice\n"); 1247 dev_err(s->dev, "cannot get v4l2 subdevice\n");
1270 ret = -ENODEV; 1248 ret = -ENODEV;
1271 goto err_unregister_master; 1249 goto err_unregister_master;
1272 } 1250 }
@@ -1275,7 +1253,7 @@ static int msi2500_probe(struct usb_interface *intf,
1275 v4l2_ctrl_handler_init(&s->hdl, 0); 1253 v4l2_ctrl_handler_init(&s->hdl, 0);
1276 if (s->hdl.error) { 1254 if (s->hdl.error) {
1277 ret = s->hdl.error; 1255 ret = s->hdl.error;
1278 dev_err(&s->udev->dev, "Could not initialize controls\n"); 1256 dev_err(s->dev, "Could not initialize controls\n");
1279 goto err_free_controls; 1257 goto err_free_controls;
1280 } 1258 }
1281 1259
@@ -1288,16 +1266,13 @@ static int msi2500_probe(struct usb_interface *intf,
1288 1266
1289 ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1); 1267 ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1);
1290 if (ret) { 1268 if (ret) {
1291 dev_err(&s->udev->dev, 1269 dev_err(s->dev, "Failed to register as video device (%d)\n",
1292 "Failed to register as video device (%d)\n",
1293 ret); 1270 ret);
1294 goto err_unregister_v4l2_dev; 1271 goto err_unregister_v4l2_dev;
1295 } 1272 }
1296 dev_info(&s->udev->dev, "Registered as %s\n", 1273 dev_info(s->dev, "Registered as %s\n",
1297 video_device_node_name(&s->vdev)); 1274 video_device_node_name(&s->vdev));
1298 dev_notice(&s->udev->dev, 1275 dev_notice(s->dev, "SDR API is still slightly experimental and functionality changes may follow\n");
1299 "%s: SDR API is still slightly experimental and functionality changes may follow\n",
1300 KBUILD_MODNAME);
1301 1276
1302 return 0; 1277 return 0;
1303 1278