aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb/em28xx/em28xx-video.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/usb/em28xx/em28xx-video.c')
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c391
1 files changed, 226 insertions, 165 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index a2ba2d905952..d70ee13cc52e 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -1,30 +1,26 @@
1/* 1// SPDX-License-Identifier: GPL-2.0+
2 em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB 2//
3 video capture devices 3// em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB
4 4// video capture devices
5 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> 5//
6 Markus Rechberger <mrechberger@gmail.com> 6// Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
7 Mauro Carvalho Chehab <mchehab@infradead.org> 7// Markus Rechberger <mrechberger@gmail.com>
8 Sascha Sommer <saschasommer@freenet.de> 8// Mauro Carvalho Chehab <mchehab@infradead.org>
9 Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com> 9// Sascha Sommer <saschasommer@freenet.de>
10 10// Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
11 Some parts based on SN9C10x PC Camera Controllers GPL driver made 11//
12 by Luca Risolia <luca.risolia@studio.unibo.it> 12// Some parts based on SN9C10x PC Camera Controllers GPL driver made
13 13// by Luca Risolia <luca.risolia@studio.unibo.it>
14 This program is free software; you can redistribute it and/or modify 14//
15 it under the terms of the GNU General Public License as published by 15// This program is free software; you can redistribute it and/or modify
16 the Free Software Foundation; either version 2 of the License, or 16// it under the terms of the GNU General Public License as published by
17 (at your option) any later version. 17// the Free Software Foundation; either version 2 of the License, or
18 18// (at your option) any later version.
19 This program is distributed in the hope that it will be useful, 19//
20 but WITHOUT ANY WARRANTY; without even the implied warranty of 20// This program is distributed in the hope that it will be useful,
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22 GNU General Public License for more details. 22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 23// GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28 24
29#include "em28xx.h" 25#include "em28xx.h"
30 26
@@ -77,7 +73,7 @@ MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint");
77 73
78MODULE_AUTHOR(DRIVER_AUTHOR); 74MODULE_AUTHOR(DRIVER_AUTHOR);
79MODULE_DESCRIPTION(DRIVER_DESC " - v4l2 interface"); 75MODULE_DESCRIPTION(DRIVER_DESC " - v4l2 interface");
80MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL v2");
81MODULE_VERSION(EM28XX_VERSION); 77MODULE_VERSION(EM28XX_VERSION);
82 78
83#define EM25XX_FRMDATAHDR_BYTE1 0x02 79#define EM25XX_FRMDATAHDR_BYTE1 0x02
@@ -148,7 +144,7 @@ static inline unsigned int norm_maxw(struct em28xx *dev)
148{ 144{
149 struct em28xx_v4l2 *v4l2 = dev->v4l2; 145 struct em28xx_v4l2 *v4l2 = dev->v4l2;
150 146
151 if (dev->board.is_webcam) 147 if (dev->is_webcam)
152 return v4l2->sensor_xres; 148 return v4l2->sensor_xres;
153 149
154 if (dev->board.max_range_640_480) 150 if (dev->board.max_range_640_480)
@@ -161,7 +157,7 @@ static inline unsigned int norm_maxh(struct em28xx *dev)
161{ 157{
162 struct em28xx_v4l2 *v4l2 = dev->v4l2; 158 struct em28xx_v4l2 *v4l2 = dev->v4l2;
163 159
164 if (dev->board.is_webcam) 160 if (dev->is_webcam)
165 return v4l2->sensor_yres; 161 return v4l2->sensor_yres;
166 162
167 if (dev->board.max_range_640_480) 163 if (dev->board.max_range_640_480)
@@ -176,7 +172,7 @@ static int em28xx_vbi_supported(struct em28xx *dev)
176 if (disable_vbi == 1) 172 if (disable_vbi == 1)
177 return 0; 173 return 0;
178 174
179 if (dev->board.is_webcam) 175 if (dev->is_webcam)
180 return 0; 176 return 0;
181 177
182 /* FIXME: check subdevices for VBI support */ 178 /* FIXME: check subdevices for VBI support */
@@ -250,7 +246,8 @@ static int em28xx_set_outfmt(struct em28xx *dev)
250 if (em28xx_vbi_supported(dev) == 1) { 246 if (em28xx_vbi_supported(dev) == 1) {
251 vinctrl |= EM28XX_VINCTRL_VBI_RAW; 247 vinctrl |= EM28XX_VINCTRL_VBI_RAW;
252 em28xx_write_reg(dev, EM28XX_R34_VBI_START_H, 0x00); 248 em28xx_write_reg(dev, EM28XX_R34_VBI_START_H, 0x00);
253 em28xx_write_reg(dev, EM28XX_R36_VBI_WIDTH, v4l2->vbi_width/4); 249 em28xx_write_reg(dev, EM28XX_R36_VBI_WIDTH,
250 v4l2->vbi_width / 4);
254 em28xx_write_reg(dev, EM28XX_R37_VBI_HEIGHT, v4l2->vbi_height); 251 em28xx_write_reg(dev, EM28XX_R37_VBI_HEIGHT, v4l2->vbi_height);
255 if (v4l2->norm & V4L2_STD_525_60) { 252 if (v4l2->norm & V4L2_STD_525_60) {
256 /* NTSC */ 253 /* NTSC */
@@ -320,8 +317,10 @@ static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v)
320 buf[0] = v; 317 buf[0] = v;
321 buf[1] = v >> 8; 318 buf[1] = v >> 8;
322 em28xx_write_regs(dev, EM28XX_R32_VSCALELOW, (char *)buf, 2); 319 em28xx_write_regs(dev, EM28XX_R32_VSCALELOW, (char *)buf, 2);
323 /* it seems that both H and V scalers must be active 320 /*
324 to work correctly */ 321 * it seems that both H and V scalers must be active
322 * to work correctly
323 */
325 mode = (h || v) ? 0x30 : 0x00; 324 mode = (h || v) ? 0x30 : 0x00;
326 } 325 }
327 return em28xx_write_reg(dev, EM28XX_R26_COMPR, mode); 326 return em28xx_write_reg(dev, EM28XX_R26_COMPR, mode);
@@ -345,13 +344,15 @@ static int em28xx_resolution_set(struct em28xx *dev)
345 344
346 em28xx_accumulator_set(dev, 1, (width - 4) >> 2, 1, (height - 4) >> 2); 345 em28xx_accumulator_set(dev, 1, (width - 4) >> 2, 1, (height - 4) >> 2);
347 346
348 /* If we don't set the start position to 2 in VBI mode, we end up 347 /*
349 with line 20/21 being YUYV encoded instead of being in 8-bit 348 * If we don't set the start position to 2 in VBI mode, we end up
350 greyscale. The core of the issue is that line 21 (and line 23 for 349 * with line 20/21 being YUYV encoded instead of being in 8-bit
351 PAL WSS) are inside of active video region, and as a result they 350 * greyscale. The core of the issue is that line 21 (and line 23 for
352 get the pixelformatting associated with that area. So by cropping 351 * PAL WSS) are inside of active video region, and as a result they
353 it out, we end up with the same format as the rest of the VBI 352 * get the pixelformatting associated with that area. So by cropping
354 region */ 353 * it out, we end up with the same format as the rest of the VBI
354 * region
355 */
355 if (em28xx_vbi_supported(dev) == 1) 356 if (em28xx_vbi_supported(dev) == 1)
356 em28xx_capture_area_set(dev, 0, 2, width, height); 357 em28xx_capture_area_set(dev, 0, 2, width, height);
357 else 358 else
@@ -365,14 +366,16 @@ static int em28xx_set_alternate(struct em28xx *dev)
365{ 366{
366 struct em28xx_v4l2 *v4l2 = dev->v4l2; 367 struct em28xx_v4l2 *v4l2 = dev->v4l2;
367 struct usb_device *udev = interface_to_usbdev(dev->intf); 368 struct usb_device *udev = interface_to_usbdev(dev->intf);
368 int errCode; 369 int err;
369 int i; 370 int i;
370 unsigned int min_pkt_size = v4l2->width * 2 + 4; 371 unsigned int min_pkt_size = v4l2->width * 2 + 4;
371 372
372 /* NOTE: for isoc transfers, only alt settings > 0 are allowed 373 /*
373 bulk transfers seem to work only with alt=0 ! */ 374 * NOTE: for isoc transfers, only alt settings > 0 are allowed
375 * bulk transfers seem to work only with alt=0 !
376 */
374 dev->alt = 0; 377 dev->alt = 0;
375 if ((alt > 0) && (alt < dev->num_alt)) { 378 if (alt > 0 && alt < dev->num_alt) {
376 em28xx_videodbg("alternate forced to %d\n", dev->alt); 379 em28xx_videodbg("alternate forced to %d\n", dev->alt);
377 dev->alt = alt; 380 dev->alt = alt;
378 goto set_alt; 381 goto set_alt;
@@ -380,9 +383,10 @@ static int em28xx_set_alternate(struct em28xx *dev)
380 if (dev->analog_xfer_bulk) 383 if (dev->analog_xfer_bulk)
381 goto set_alt; 384 goto set_alt;
382 385
383 /* When image size is bigger than a certain value, 386 /*
384 the frame size should be increased, otherwise, only 387 * When image size is bigger than a certain value,
385 green screen will be received. 388 * the frame size should be increased, otherwise, only
389 * green screen will be received.
386 */ 390 */
387 if (v4l2->width * 2 * v4l2->height > 720 * 240 * 2) 391 if (v4l2->width * 2 * v4l2->height > 720 * 240 * 2)
388 min_pkt_size *= 2; 392 min_pkt_size *= 2;
@@ -392,18 +396,22 @@ static int em28xx_set_alternate(struct em28xx *dev)
392 if (dev->alt_max_pkt_size_isoc[i] >= min_pkt_size) { 396 if (dev->alt_max_pkt_size_isoc[i] >= min_pkt_size) {
393 dev->alt = i; 397 dev->alt = i;
394 break; 398 break;
395 /* otherwise make sure that we end up with the maximum bandwidth 399 /*
396 because the min_pkt_size equation might be wrong... 400 * otherwise make sure that we end up with the maximum
397 */ 401 * bandwidth because the min_pkt_size equation might be wrong.
402 *
403 */
398 } else if (dev->alt_max_pkt_size_isoc[i] > 404 } else if (dev->alt_max_pkt_size_isoc[i] >
399 dev->alt_max_pkt_size_isoc[dev->alt]) 405 dev->alt_max_pkt_size_isoc[dev->alt])
400 dev->alt = i; 406 dev->alt = i;
401 } 407 }
402 408
403set_alt: 409set_alt:
404 /* NOTE: for bulk transfers, we need to call usb_set_interface() 410 /*
411 * NOTE: for bulk transfers, we need to call usb_set_interface()
405 * even if the previous settings were the same. Otherwise streaming 412 * even if the previous settings were the same. Otherwise streaming
406 * fails with all urbs having status = -EOVERFLOW ! */ 413 * fails with all urbs having status = -EOVERFLOW !
414 */
407 if (dev->analog_xfer_bulk) { 415 if (dev->analog_xfer_bulk) {
408 dev->max_pkt_size = 512; /* USB 2.0 spec */ 416 dev->max_pkt_size = 512; /* USB 2.0 spec */
409 dev->packet_multiplier = EM28XX_BULK_PACKET_MULTIPLIER; 417 dev->packet_multiplier = EM28XX_BULK_PACKET_MULTIPLIER;
@@ -416,19 +424,19 @@ set_alt:
416 } 424 }
417 em28xx_videodbg("setting alternate %d with wMaxPacketSize=%u\n", 425 em28xx_videodbg("setting alternate %d with wMaxPacketSize=%u\n",
418 dev->alt, dev->max_pkt_size); 426 dev->alt, dev->max_pkt_size);
419 errCode = usb_set_interface(udev, dev->ifnum, dev->alt); 427 err = usb_set_interface(udev, dev->ifnum, dev->alt);
420 if (errCode < 0) { 428 if (err < 0) {
421 dev_err(&dev->intf->dev, 429 dev_err(&dev->intf->dev,
422 "cannot change alternate number to %d (error=%i)\n", 430 "cannot change alternate number to %d (error=%i)\n",
423 dev->alt, errCode); 431 dev->alt, err);
424 return errCode; 432 return err;
425 } 433 }
426 return 0; 434 return 0;
427} 435}
428 436
429/* ------------------------------------------------------------------ 437/*
430 DMA and thread functions 438 * DMA and thread functions
431 ------------------------------------------------------------------*/ 439 */
432 440
433/* 441/*
434 * Finish the current buffer 442 * Finish the current buffer
@@ -514,8 +522,9 @@ static void em28xx_copy_video(struct em28xx *dev,
514 em28xx_isocdbg("Overflow of %zu bytes past buffer end(2)\n", 522 em28xx_isocdbg("Overflow of %zu bytes past buffer end(2)\n",
515 ((char *)startwrite + lencopy) - 523 ((char *)startwrite + lencopy) -
516 ((char *)buf->vb_buf + buf->length)); 524 ((char *)buf->vb_buf + buf->length));
517 lencopy = remain = (char *)buf->vb_buf + buf->length - 525 remain = (char *)buf->vb_buf + buf->length -
518 (char *)startwrite; 526 (char *)startwrite;
527 lencopy = remain;
519 } 528 }
520 if (lencopy <= 0) 529 if (lencopy <= 0)
521 break; 530 break;
@@ -623,11 +632,11 @@ finish_field_prepare_next(struct em28xx *dev,
623 struct em28xx_v4l2 *v4l2 = dev->v4l2; 632 struct em28xx_v4l2 *v4l2 = dev->v4l2;
624 633
625 if (v4l2->progressive || v4l2->top_field) { /* Brand new frame */ 634 if (v4l2->progressive || v4l2->top_field) { /* Brand new frame */
626 if (buf != NULL) 635 if (buf)
627 finish_buffer(dev, buf); 636 finish_buffer(dev, buf);
628 buf = get_next_buf(dev, dma_q); 637 buf = get_next_buf(dev, dma_q);
629 } 638 }
630 if (buf != NULL) { 639 if (buf) {
631 buf->top_field = v4l2->top_field; 640 buf->top_field = v4l2->top_field;
632 buf->pos = 0; 641 buf->pos = 0;
633 } 642 }
@@ -648,13 +657,17 @@ static inline void process_frame_data_em28xx(struct em28xx *dev,
648 struct em28xx_dmaqueue *dma_q = &dev->vidq; 657 struct em28xx_dmaqueue *dma_q = &dev->vidq;
649 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq; 658 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
650 659
651 /* capture type 0 = vbi start 660 /*
652 capture type 1 = vbi in progress 661 * capture type 0 = vbi start
653 capture type 2 = video start 662 * capture type 1 = vbi in progress
654 capture type 3 = video in progress */ 663 * capture type 2 = video start
664 * capture type 3 = video in progress
665 */
655 if (data_len >= 4) { 666 if (data_len >= 4) {
656 /* NOTE: Headers are always 4 bytes and 667 /*
657 * never split across packets */ 668 * NOTE: Headers are always 4 bytes and
669 * never split across packets
670 */
658 if (data_pkt[0] == 0x88 && data_pkt[1] == 0x88 && 671 if (data_pkt[0] == 0x88 && data_pkt[1] == 0x88 &&
659 data_pkt[2] == 0x88 && data_pkt[3] == 0x88) { 672 data_pkt[2] == 0x88 && data_pkt[3] == 0x88) {
660 /* Continuation */ 673 /* Continuation */
@@ -677,8 +690,10 @@ static inline void process_frame_data_em28xx(struct em28xx *dev,
677 data_len -= 4; 690 data_len -= 4;
678 } 691 }
679 } 692 }
680 /* NOTE: With bulk transfers, intermediate data packets 693 /*
681 * have no continuation header */ 694 * NOTE: With bulk transfers, intermediate data packets
695 * have no continuation header
696 */
682 697
683 if (v4l2->capture_type == 0) { 698 if (v4l2->capture_type == 0) {
684 vbi_buf = finish_field_prepare_next(dev, vbi_buf, vbi_dma_q); 699 vbi_buf = finish_field_prepare_next(dev, vbi_buf, vbi_dma_q);
@@ -692,7 +707,7 @@ static inline void process_frame_data_em28xx(struct em28xx *dev,
692 (vbi_size - v4l2->vbi_read) : data_len; 707 (vbi_size - v4l2->vbi_read) : data_len;
693 708
694 /* Copy VBI data */ 709 /* Copy VBI data */
695 if (vbi_buf != NULL) 710 if (vbi_buf)
696 em28xx_copy_vbi(dev, vbi_buf, data_pkt, vbi_data_len); 711 em28xx_copy_vbi(dev, vbi_buf, data_pkt, vbi_data_len);
697 v4l2->vbi_read += vbi_data_len; 712 v4l2->vbi_read += vbi_data_len;
698 713
@@ -710,7 +725,7 @@ static inline void process_frame_data_em28xx(struct em28xx *dev,
710 v4l2->capture_type = 3; 725 v4l2->capture_type = 3;
711 } 726 }
712 727
713 if (v4l2->capture_type == 3 && buf != NULL && data_len > 0) 728 if (v4l2->capture_type == 3 && buf && data_len > 0)
714 em28xx_copy_video(dev, buf, data_pkt, data_len); 729 em28xx_copy_video(dev, buf, data_pkt, data_len);
715} 730}
716 731
@@ -727,8 +742,10 @@ static inline void process_frame_data_em25xx(struct em28xx *dev,
727 bool frame_end = false; 742 bool frame_end = false;
728 743
729 /* Check for header */ 744 /* Check for header */
730 /* NOTE: at least with bulk transfers, only the first packet 745 /*
731 * has a header and has always set the FRAME_END bit */ 746 * NOTE: at least with bulk transfers, only the first packet
747 * has a header and has always set the FRAME_END bit
748 */
732 if (data_len >= 2) { /* em25xx header is only 2 bytes long */ 749 if (data_len >= 2) { /* em25xx header is only 2 bytes long */
733 if ((data_pkt[0] == EM25XX_FRMDATAHDR_BYTE1) && 750 if ((data_pkt[0] == EM25XX_FRMDATAHDR_BYTE1) &&
734 ((data_pkt[1] & ~EM25XX_FRMDATAHDR_BYTE2_MASK) == 0x00)) { 751 ((data_pkt[1] & ~EM25XX_FRMDATAHDR_BYTE2_MASK) == 0x00)) {
@@ -745,14 +762,15 @@ static inline void process_frame_data_em25xx(struct em28xx *dev,
745 buf = finish_field_prepare_next(dev, buf, dmaq); 762 buf = finish_field_prepare_next(dev, buf, dmaq);
746 dev->usb_ctl.vid_buf = buf; 763 dev->usb_ctl.vid_buf = buf;
747 } 764 }
748 /* NOTE: in ISOC mode when a new frame starts and buf==NULL, 765 /*
766 * NOTE: in ISOC mode when a new frame starts and buf==NULL,
749 * we COULD already prepare a buffer here to avoid skipping the 767 * we COULD already prepare a buffer here to avoid skipping the
750 * first frame. 768 * first frame.
751 */ 769 */
752 } 770 }
753 771
754 /* Copy data */ 772 /* Copy data */
755 if (buf != NULL && data_len > 0) 773 if (buf && data_len > 0)
756 em28xx_copy_video(dev, buf, data_pkt, data_len); 774 em28xx_copy_video(dev, buf, data_pkt, data_len);
757 775
758 /* Finish frame (ISOC only) => avoids lag of 1 frame */ 776 /* Finish frame (ISOC only) => avoids lag of 1 frame */
@@ -761,14 +779,17 @@ static inline void process_frame_data_em25xx(struct em28xx *dev,
761 dev->usb_ctl.vid_buf = buf; 779 dev->usb_ctl.vid_buf = buf;
762 } 780 }
763 781
764 /* NOTE: Tested with USB bulk transfers only ! 782 /*
783 * NOTES:
784 *
785 * 1) Tested with USB bulk transfers only !
765 * The wording in the datasheet suggests that isoc might work different. 786 * The wording in the datasheet suggests that isoc might work different.
766 * The current code assumes that with isoc transfers each packet has a 787 * The current code assumes that with isoc transfers each packet has a
767 * header like with the other em28xx devices. 788 * header like with the other em28xx devices.
789 *
790 * 2) Support for interlaced mode is pure theory. It has not been
791 * tested and it is unknown if these devices actually support it.
768 */ 792 */
769 /* NOTE: Support for interlaced mode is pure theory. It has not been
770 * tested and it is unknown if these devices actually support it. */
771 /* NOTE: No VBI support yet (these chips likely do not support VBI). */
772} 793}
773 794
774/* Processes and copies the URB data content (video and VBI data) */ 795/* Processes and copies the URB data content (video and VBI data) */
@@ -829,12 +850,11 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb)
829 else 850 else
830 process_frame_data_em28xx(dev, 851 process_frame_data_em28xx(dev,
831 usb_data_pkt, usb_data_len); 852 usb_data_pkt, usb_data_len);
832
833 } 853 }
834 return 1; 854 return 1;
835} 855}
836 856
837static int get_ressource(enum v4l2_buf_type f_type) 857static int get_resource(enum v4l2_buf_type f_type)
838{ 858{
839 switch (f_type) { 859 switch (f_type) {
840 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 860 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -842,14 +862,15 @@ static int get_ressource(enum v4l2_buf_type f_type)
842 case V4L2_BUF_TYPE_VBI_CAPTURE: 862 case V4L2_BUF_TYPE_VBI_CAPTURE:
843 return EM28XX_RESOURCE_VBI; 863 return EM28XX_RESOURCE_VBI;
844 default: 864 default:
845 BUG(); 865 WARN_ON(1);
866 return -1; /* Indicate that device is busy */
846 } 867 }
847} 868}
848 869
849/* Usage lock check functions */ 870/* Usage lock check functions */
850static int res_get(struct em28xx *dev, enum v4l2_buf_type f_type) 871static int res_get(struct em28xx *dev, enum v4l2_buf_type f_type)
851{ 872{
852 int res_type = get_ressource(f_type); 873 int res_type = get_resource(f_type);
853 874
854 /* is it free? */ 875 /* is it free? */
855 if (dev->resources & res_type) { 876 if (dev->resources & res_type) {
@@ -865,7 +886,7 @@ static int res_get(struct em28xx *dev, enum v4l2_buf_type f_type)
865 886
866static void res_free(struct em28xx *dev, enum v4l2_buf_type f_type) 887static void res_free(struct em28xx *dev, enum v4l2_buf_type f_type)
867{ 888{
868 int res_type = get_ressource(f_type); 889 int res_type = get_resource(f_type);
869 890
870 dev->resources &= ~res_type; 891 dev->resources &= ~res_type;
871 em28xx_videodbg("res: put %d\n", res_type); 892 em28xx_videodbg("res: put %d\n", res_type);
@@ -937,10 +958,11 @@ static int em28xx_enable_analog_tuner(struct em28xx *dev)
937 flags ? "enabled" : "disabled", 958 flags ? "enabled" : "disabled",
938 ret); 959 ret);
939 return ret; 960 return ret;
940 } else 961 }
941 em28xx_videodbg("link %s->%s was %s\n", 962
942 source->name, sink->name, 963 em28xx_videodbg("link %s->%s was %s\n",
943 flags ? "ENABLED" : "disabled"); 964 source->name, sink->name,
965 flags ? "ENABLED" : "disabled");
944 } 966 }
945#endif 967#endif
946 return 0; 968 return 0;
@@ -976,7 +998,7 @@ static void em28xx_v4l2_create_entities(struct em28xx *dev)
976 } 998 }
977 999
978 /* Webcams don't have input connectors */ 1000 /* Webcams don't have input connectors */
979 if (dev->board.is_webcam) 1001 if (dev->is_webcam)
980 return; 1002 return;
981 1003
982 /* Create entities for each input connector */ 1004 /* Create entities for each input connector */
@@ -1016,10 +1038,9 @@ static void em28xx_v4l2_create_entities(struct em28xx *dev)
1016#endif 1038#endif
1017} 1039}
1018 1040
1019 1041/*
1020/* ------------------------------------------------------------------ 1042 * Videobuf2 operations
1021 Videobuf2 operations 1043 */
1022 ------------------------------------------------------------------*/
1023 1044
1024static int queue_setup(struct vb2_queue *vq, 1045static int queue_setup(struct vb2_queue *vq,
1025 unsigned int *nbuffers, unsigned int *nplanes, 1046 unsigned int *nbuffers, unsigned int *nplanes,
@@ -1072,8 +1093,10 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
1072 1093
1073 em28xx_videodbg("%s\n", __func__); 1094 em28xx_videodbg("%s\n", __func__);
1074 1095
1075 /* Make sure streaming is not already in progress for this type 1096 /*
1076 of filehandle (e.g. video, vbi) */ 1097 * Make sure streaming is not already in progress for this type
1098 * of filehandle (e.g. video, vbi)
1099 */
1077 rc = res_get(dev, vq->type); 1100 rc = res_get(dev, vq->type);
1078 if (rc) 1101 if (rc)
1079 return rc; 1102 return rc;
@@ -1084,9 +1107,10 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
1084 /* Allocate the USB bandwidth */ 1107 /* Allocate the USB bandwidth */
1085 em28xx_set_alternate(dev); 1108 em28xx_set_alternate(dev);
1086 1109
1087 /* Needed, since GPIO might have disabled power of 1110 /*
1088 some i2c device 1111 * Needed, since GPIO might have disabled power of
1089 */ 1112 * some i2c device
1113 */
1090 em28xx_wake_i2c(dev); 1114 em28xx_wake_i2c(dev);
1091 1115
1092 v4l2->capture_type = -1; 1116 v4l2->capture_type = -1;
@@ -1145,7 +1169,7 @@ static void em28xx_stop_streaming(struct vb2_queue *vq)
1145 } 1169 }
1146 1170
1147 spin_lock_irqsave(&dev->slock, flags); 1171 spin_lock_irqsave(&dev->slock, flags);
1148 if (dev->usb_ctl.vid_buf != NULL) { 1172 if (dev->usb_ctl.vid_buf) {
1149 vb2_buffer_done(&dev->usb_ctl.vid_buf->vb.vb2_buf, 1173 vb2_buffer_done(&dev->usb_ctl.vid_buf->vb.vb2_buf,
1150 VB2_BUF_STATE_ERROR); 1174 VB2_BUF_STATE_ERROR);
1151 dev->usb_ctl.vid_buf = NULL; 1175 dev->usb_ctl.vid_buf = NULL;
@@ -1180,7 +1204,7 @@ void em28xx_stop_vbi_streaming(struct vb2_queue *vq)
1180 } 1204 }
1181 1205
1182 spin_lock_irqsave(&dev->slock, flags); 1206 spin_lock_irqsave(&dev->slock, flags);
1183 if (dev->usb_ctl.vbi_buf != NULL) { 1207 if (dev->usb_ctl.vbi_buf) {
1184 vb2_buffer_done(&dev->usb_ctl.vbi_buf->vb.vb2_buf, 1208 vb2_buffer_done(&dev->usb_ctl.vbi_buf->vb.vb2_buf,
1185 VB2_BUF_STATE_ERROR); 1209 VB2_BUF_STATE_ERROR);
1186 dev->usb_ctl.vbi_buf = NULL; 1210 dev->usb_ctl.vbi_buf = NULL;
@@ -1261,7 +1285,9 @@ static int em28xx_vb2_setup(struct em28xx *dev)
1261 return 0; 1285 return 0;
1262} 1286}
1263 1287
1264/********************* v4l2 interface **************************************/ 1288/*
1289 * v4l2 interface
1290 */
1265 1291
1266static void video_mux(struct em28xx *dev, int index) 1292static void video_mux(struct em28xx *dev, int index)
1267{ 1293{
@@ -1277,7 +1303,7 @@ static void video_mux(struct em28xx *dev, int index)
1277 v4l2_device_call_all(v4l2_dev, 0, video, s_routing, 1303 v4l2_device_call_all(v4l2_dev, 0, video, s_routing,
1278 INPUT(index)->vmux, 0, 0); 1304 INPUT(index)->vmux, 0, 0);
1279 1305
1280 if (dev->board.has_msp34xx) { 1306 if (dev->has_msp34xx) {
1281 if (dev->i2s_speed) { 1307 if (dev->i2s_speed) {
1282 v4l2_device_call_all(v4l2_dev, 0, audio, 1308 v4l2_device_call_all(v4l2_dev, 0, audio,
1283 s_i2s_clock_freq, dev->i2s_speed); 1309 s_i2s_clock_freq, dev->i2s_speed);
@@ -1394,9 +1420,9 @@ static void scale_to_size(struct em28xx *dev,
1394 *height = 1; 1420 *height = 1;
1395} 1421}
1396 1422
1397/* ------------------------------------------------------------------ 1423/*
1398 IOCTL vidioc handling 1424 * IOCTL vidioc handling
1399 ------------------------------------------------------------------*/ 1425 */
1400 1426
1401static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 1427static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1402 struct v4l2_format *f) 1428 struct v4l2_format *f)
@@ -1462,8 +1488,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1462 if (width == maxw && height == maxh) 1488 if (width == maxw && height == maxh)
1463 width /= 2; 1489 width /= 2;
1464 } else { 1490 } else {
1465 /* width must even because of the YUYV format 1491 /*
1466 height must be even because of interlacing */ 1492 * width must even because of the YUYV format
1493 * height must be even because of interlacing
1494 */
1467 v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1495 v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
1468 1, 0); 1496 1, 0);
1469 } 1497 }
@@ -1493,7 +1521,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1493} 1521}
1494 1522
1495static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc, 1523static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
1496 unsigned width, unsigned height) 1524 unsigned int width, unsigned int height)
1497{ 1525{
1498 struct em28xx_fmt *fmt; 1526 struct em28xx_fmt *fmt;
1499 struct em28xx_v4l2 *v4l2 = dev->v4l2; 1527 struct em28xx_v4l2 *v4l2 = dev->v4l2;
@@ -1582,17 +1610,26 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1582static int vidioc_g_parm(struct file *file, void *priv, 1610static int vidioc_g_parm(struct file *file, void *priv,
1583 struct v4l2_streamparm *p) 1611 struct v4l2_streamparm *p)
1584{ 1612{
1613 struct v4l2_subdev_frame_interval ival = { 0 };
1585 struct em28xx *dev = video_drvdata(file); 1614 struct em28xx *dev = video_drvdata(file);
1586 struct em28xx_v4l2 *v4l2 = dev->v4l2; 1615 struct em28xx_v4l2 *v4l2 = dev->v4l2;
1587 int rc = 0; 1616 int rc = 0;
1588 1617
1618 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1619 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1620 return -EINVAL;
1621
1589 p->parm.capture.readbuffers = EM28XX_MIN_BUF; 1622 p->parm.capture.readbuffers = EM28XX_MIN_BUF;
1590 if (dev->board.is_webcam) 1623 p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1624 if (dev->is_webcam) {
1591 rc = v4l2_device_call_until_err(&v4l2->v4l2_dev, 0, 1625 rc = v4l2_device_call_until_err(&v4l2->v4l2_dev, 0,
1592 video, g_parm, p); 1626 video, g_frame_interval, &ival);
1593 else 1627 if (!rc)
1628 p->parm.capture.timeperframe = ival.interval;
1629 } else {
1594 v4l2_video_std_frame_period(v4l2->norm, 1630 v4l2_video_std_frame_period(v4l2->norm,
1595 &p->parm.capture.timeperframe); 1631 &p->parm.capture.timeperframe);
1632 }
1596 1633
1597 return rc; 1634 return rc;
1598} 1635}
@@ -1601,10 +1638,27 @@ static int vidioc_s_parm(struct file *file, void *priv,
1601 struct v4l2_streamparm *p) 1638 struct v4l2_streamparm *p)
1602{ 1639{
1603 struct em28xx *dev = video_drvdata(file); 1640 struct em28xx *dev = video_drvdata(file);
1641 struct v4l2_subdev_frame_interval ival = {
1642 0,
1643 p->parm.capture.timeperframe
1644 };
1645 int rc = 0;
1646
1647 if (!dev->is_webcam)
1648 return -ENOTTY;
1649
1650 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1651 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1652 return -EINVAL;
1604 1653
1654 memset(&p->parm, 0, sizeof(p->parm));
1605 p->parm.capture.readbuffers = EM28XX_MIN_BUF; 1655 p->parm.capture.readbuffers = EM28XX_MIN_BUF;
1606 return v4l2_device_call_until_err(&dev->v4l2->v4l2_dev, 1656 p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1607 0, video, s_parm, p); 1657 rc = v4l2_device_call_until_err(&dev->v4l2->v4l2_dev, 0,
1658 video, s_frame_interval, &ival);
1659 if (!rc)
1660 p->parm.capture.timeperframe = ival.interval;
1661 return rc;
1608} 1662}
1609 1663
1610static int vidioc_enum_input(struct file *file, void *priv, 1664static int vidioc_enum_input(struct file *file, void *priv,
@@ -1616,20 +1670,19 @@ static int vidioc_enum_input(struct file *file, void *priv,
1616 n = i->index; 1670 n = i->index;
1617 if (n >= MAX_EM28XX_INPUT) 1671 if (n >= MAX_EM28XX_INPUT)
1618 return -EINVAL; 1672 return -EINVAL;
1619 if (0 == INPUT(n)->type) 1673 if (!INPUT(n)->type)
1620 return -EINVAL; 1674 return -EINVAL;
1621 1675
1622 i->index = n;
1623 i->type = V4L2_INPUT_TYPE_CAMERA; 1676 i->type = V4L2_INPUT_TYPE_CAMERA;
1624 1677
1625 strcpy(i->name, iname[INPUT(n)->type]); 1678 strcpy(i->name, iname[INPUT(n)->type]);
1626 1679
1627 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type)) 1680 if (INPUT(n)->type == EM28XX_VMUX_TELEVISION)
1628 i->type = V4L2_INPUT_TYPE_TUNER; 1681 i->type = V4L2_INPUT_TYPE_TUNER;
1629 1682
1630 i->std = dev->v4l2->vdev.tvnorms; 1683 i->std = dev->v4l2->vdev.tvnorms;
1631 /* webcams do not have the STD API */ 1684 /* webcams do not have the STD API */
1632 if (dev->board.is_webcam) 1685 if (dev->is_webcam)
1633 i->capabilities = 0; 1686 i->capabilities = 0;
1634 1687
1635 return 0; 1688 return 0;
@@ -1650,7 +1703,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1650 1703
1651 if (i >= MAX_EM28XX_INPUT) 1704 if (i >= MAX_EM28XX_INPUT)
1652 return -EINVAL; 1705 return -EINVAL;
1653 if (0 == INPUT(i)->type) 1706 if (!INPUT(i)->type)
1654 return -EINVAL; 1707 return -EINVAL;
1655 1708
1656 video_mux(dev, i); 1709 video_mux(dev, i);
@@ -1696,13 +1749,14 @@ static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1696 return 0; 1749 return 0;
1697} 1750}
1698 1751
1699static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a) 1752static int vidioc_s_audio(struct file *file, void *priv,
1753 const struct v4l2_audio *a)
1700{ 1754{
1701 struct em28xx *dev = video_drvdata(file); 1755 struct em28xx *dev = video_drvdata(file);
1702 1756
1703 if (a->index >= MAX_EM28XX_INPUT) 1757 if (a->index >= MAX_EM28XX_INPUT)
1704 return -EINVAL; 1758 return -EINVAL;
1705 if (0 == INPUT(a->index)->type) 1759 if (!INPUT(a->index)->type)
1706 return -EINVAL; 1760 return -EINVAL;
1707 1761
1708 dev->ctl_ainput = INPUT(a->index)->amux; 1762 dev->ctl_ainput = INPUT(a->index)->amux;
@@ -1719,7 +1773,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1719{ 1773{
1720 struct em28xx *dev = video_drvdata(file); 1774 struct em28xx *dev = video_drvdata(file);
1721 1775
1722 if (0 != t->index) 1776 if (t->index != 0)
1723 return -EINVAL; 1777 return -EINVAL;
1724 1778
1725 strcpy(t->name, "Tuner"); 1779 strcpy(t->name, "Tuner");
@@ -1733,7 +1787,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
1733{ 1787{
1734 struct em28xx *dev = video_drvdata(file); 1788 struct em28xx *dev = video_drvdata(file);
1735 1789
1736 if (0 != t->index) 1790 if (t->index != 0)
1737 return -EINVAL; 1791 return -EINVAL;
1738 1792
1739 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, s_tuner, t); 1793 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, s_tuner, t);
@@ -1746,7 +1800,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1746 struct em28xx *dev = video_drvdata(file); 1800 struct em28xx *dev = video_drvdata(file);
1747 struct em28xx_v4l2 *v4l2 = dev->v4l2; 1801 struct em28xx_v4l2 *v4l2 = dev->v4l2;
1748 1802
1749 if (0 != f->tuner) 1803 if (f->tuner != 0)
1750 return -EINVAL; 1804 return -EINVAL;
1751 1805
1752 f->frequency = v4l2->frequency; 1806 f->frequency = v4l2->frequency;
@@ -1760,7 +1814,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1760 struct em28xx *dev = video_drvdata(file); 1814 struct em28xx *dev = video_drvdata(file);
1761 struct em28xx_v4l2 *v4l2 = dev->v4l2; 1815 struct em28xx_v4l2 *v4l2 = dev->v4l2;
1762 1816
1763 if (0 != f->tuner) 1817 if (f->tuner != 0)
1764 return -EINVAL; 1818 return -EINVAL;
1765 1819
1766 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, s_frequency, f); 1820 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, s_frequency, f);
@@ -1884,8 +1938,9 @@ static int vidioc_querycap(struct file *file, void *priv,
1884 if (dev->tuner_type != TUNER_ABSENT) 1938 if (dev->tuner_type != TUNER_ABSENT)
1885 cap->device_caps |= V4L2_CAP_TUNER; 1939 cap->device_caps |= V4L2_CAP_TUNER;
1886 1940
1887 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS | 1941 cap->capabilities = cap->device_caps |
1888 V4L2_CAP_READWRITE | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; 1942 V4L2_CAP_DEVICE_CAPS | V4L2_CAP_READWRITE |
1943 V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1889 if (video_is_registered(&v4l2->vbi_dev)) 1944 if (video_is_registered(&v4l2->vbi_dev))
1890 cap->capabilities |= V4L2_CAP_VBI_CAPTURE; 1945 cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
1891 if (video_is_registered(&v4l2->radio_dev)) 1946 if (video_is_registered(&v4l2->radio_dev))
@@ -1978,9 +2033,9 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1978 return 0; 2033 return 0;
1979} 2034}
1980 2035
1981/* ----------------------------------------------------------- */ 2036/*
1982/* RADIO ESPECIFIC IOCTLS */ 2037 * RADIO ESPECIFIC IOCTLS
1983/* ----------------------------------------------------------- */ 2038 */
1984 2039
1985static int radio_g_tuner(struct file *file, void *priv, 2040static int radio_g_tuner(struct file *file, void *priv,
1986 struct v4l2_tuner *t) 2041 struct v4l2_tuner *t)
@@ -2002,7 +2057,7 @@ static int radio_s_tuner(struct file *file, void *priv,
2002{ 2057{
2003 struct em28xx *dev = video_drvdata(file); 2058 struct em28xx *dev = video_drvdata(file);
2004 2059
2005 if (0 != t->index) 2060 if (t->index != 0)
2006 return -EINVAL; 2061 return -EINVAL;
2007 2062
2008 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, s_tuner, t); 2063 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, s_tuner, t);
@@ -2097,7 +2152,7 @@ static int em28xx_v4l2_open(struct file *filp)
2097 * em28xx_v4l2_fini() 2152 * em28xx_v4l2_fini()
2098 * unregisters the v4l2,i2c and usb devices 2153 * unregisters the v4l2,i2c and usb devices
2099 * called when the device gets disconected or at module unload 2154 * called when the device gets disconected or at module unload
2100*/ 2155 */
2101static int em28xx_v4l2_fini(struct em28xx *dev) 2156static int em28xx_v4l2_fini(struct em28xx *dev)
2102{ 2157{
2103 struct em28xx_v4l2 *v4l2 = dev->v4l2; 2158 struct em28xx_v4l2 *v4l2 = dev->v4l2;
@@ -2112,7 +2167,7 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
2112 return 0; 2167 return 0;
2113 } 2168 }
2114 2169
2115 if (v4l2 == NULL) 2170 if (!v4l2)
2116 return 0; 2171 return 0;
2117 2172
2118 dev_info(&dev->intf->dev, "Closing video extension\n"); 2173 dev_info(&dev->intf->dev, "Closing video extension\n");
@@ -2127,17 +2182,17 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
2127 2182
2128 if (video_is_registered(&v4l2->radio_dev)) { 2183 if (video_is_registered(&v4l2->radio_dev)) {
2129 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", 2184 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n",
2130 video_device_node_name(&v4l2->radio_dev)); 2185 video_device_node_name(&v4l2->radio_dev));
2131 video_unregister_device(&v4l2->radio_dev); 2186 video_unregister_device(&v4l2->radio_dev);
2132 } 2187 }
2133 if (video_is_registered(&v4l2->vbi_dev)) { 2188 if (video_is_registered(&v4l2->vbi_dev)) {
2134 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", 2189 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n",
2135 video_device_node_name(&v4l2->vbi_dev)); 2190 video_device_node_name(&v4l2->vbi_dev));
2136 video_unregister_device(&v4l2->vbi_dev); 2191 video_unregister_device(&v4l2->vbi_dev);
2137 } 2192 }
2138 if (video_is_registered(&v4l2->vdev)) { 2193 if (video_is_registered(&v4l2->vdev)) {
2139 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", 2194 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n",
2140 video_device_node_name(&v4l2->vdev)); 2195 video_device_node_name(&v4l2->vdev));
2141 video_unregister_device(&v4l2->vdev); 2196 video_unregister_device(&v4l2->vdev);
2142 } 2197 }
2143 2198
@@ -2189,7 +2244,7 @@ static int em28xx_v4l2_close(struct file *filp)
2189 struct em28xx *dev = video_drvdata(filp); 2244 struct em28xx *dev = video_drvdata(filp);
2190 struct em28xx_v4l2 *v4l2 = dev->v4l2; 2245 struct em28xx_v4l2 *v4l2 = dev->v4l2;
2191 struct usb_device *udev = interface_to_usbdev(dev->intf); 2246 struct usb_device *udev = interface_to_usbdev(dev->intf);
2192 int errCode; 2247 int err;
2193 2248
2194 em28xx_videodbg("users=%d\n", v4l2->users); 2249 em28xx_videodbg("users=%d\n", v4l2->users);
2195 2250
@@ -2202,7 +2257,7 @@ static int em28xx_v4l2_close(struct file *filp)
2202 goto exit; 2257 goto exit;
2203 2258
2204 /* Save some power by putting tuner to sleep */ 2259 /* Save some power by putting tuner to sleep */
2205 v4l2_device_call_all(&v4l2->v4l2_dev, 0, core, s_power, 0); 2260 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, standby);
2206 2261
2207 /* do this before setting alternate! */ 2262 /* do this before setting alternate! */
2208 em28xx_set_mode(dev, EM28XX_SUSPEND); 2263 em28xx_set_mode(dev, EM28XX_SUSPEND);
@@ -2210,11 +2265,11 @@ static int em28xx_v4l2_close(struct file *filp)
2210 /* set alternate 0 */ 2265 /* set alternate 0 */
2211 dev->alt = 0; 2266 dev->alt = 0;
2212 em28xx_videodbg("setting alternate 0\n"); 2267 em28xx_videodbg("setting alternate 0\n");
2213 errCode = usb_set_interface(udev, 0, 0); 2268 err = usb_set_interface(udev, 0, 0);
2214 if (errCode < 0) { 2269 if (err < 0) {
2215 dev_err(&dev->intf->dev, 2270 dev_err(&dev->intf->dev,
2216 "cannot change alternate number to 0 (error=%i)\n", 2271 "cannot change alternate number to 0 (error=%i)\n",
2217 errCode); 2272 err);
2218 } 2273 }
2219 } 2274 }
2220 2275
@@ -2343,7 +2398,7 @@ static void em28xx_vdev_init(struct em28xx *dev,
2343 *vfd = *template; 2398 *vfd = *template;
2344 vfd->v4l2_dev = &dev->v4l2->v4l2_dev; 2399 vfd->v4l2_dev = &dev->v4l2->v4l2_dev;
2345 vfd->lock = &dev->lock; 2400 vfd->lock = &dev->lock;
2346 if (dev->board.is_webcam) 2401 if (dev->is_webcam)
2347 vfd->tvnorms = 0; 2402 vfd->tvnorms = 0;
2348 2403
2349 snprintf(vfd->name, sizeof(vfd->name), "%s %s", 2404 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
@@ -2372,7 +2427,7 @@ static void em28xx_tuner_setup(struct em28xx *dev, unsigned short tuner_addr)
2372 0, tuner, s_type_addr, &tun_setup); 2427 0, tuner, s_type_addr, &tun_setup);
2373 } 2428 }
2374 2429
2375 if ((dev->tuner_type != TUNER_ABSENT) && (dev->tuner_type)) { 2430 if (dev->tuner_type != TUNER_ABSENT && dev->tuner_type) {
2376 tun_setup.type = dev->tuner_type; 2431 tun_setup.type = dev->tuner_type;
2377 tun_setup.addr = tuner_addr; 2432 tun_setup.addr = tuner_addr;
2378 2433
@@ -2435,7 +2490,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2435 2490
2436 mutex_lock(&dev->lock); 2491 mutex_lock(&dev->lock);
2437 2492
2438 v4l2 = kzalloc(sizeof(struct em28xx_v4l2), GFP_KERNEL); 2493 v4l2 = kzalloc(sizeof(*v4l2), GFP_KERNEL);
2439 if (!v4l2) { 2494 if (!v4l2) {
2440 mutex_unlock(&dev->lock); 2495 mutex_unlock(&dev->lock);
2441 return -ENOMEM; 2496 return -ENOMEM;
@@ -2458,7 +2513,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2458 v4l2_ctrl_handler_init(hdl, 8); 2513 v4l2_ctrl_handler_init(hdl, 8);
2459 v4l2->v4l2_dev.ctrl_handler = hdl; 2514 v4l2->v4l2_dev.ctrl_handler = hdl;
2460 2515
2461 if (dev->board.is_webcam) 2516 if (dev->is_webcam)
2462 v4l2->progressive = true; 2517 v4l2->progressive = true;
2463 2518
2464 /* 2519 /*
@@ -2470,7 +2525,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2470 2525
2471 /* request some modules */ 2526 /* request some modules */
2472 2527
2473 if (dev->board.has_msp34xx) 2528 if (dev->has_msp34xx)
2474 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, 2529 v4l2_i2c_new_subdev(&v4l2->v4l2_dev,
2475 &dev->i2c_adap[dev->def_i2c_bus], 2530 &dev->i2c_adap[dev->def_i2c_bus],
2476 "msp3400", 0, msp3400_addrs); 2531 "msp3400", 0, msp3400_addrs);
@@ -2559,7 +2614,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2559 INIT_LIST_HEAD(&dev->vidq.active); 2614 INIT_LIST_HEAD(&dev->vidq.active);
2560 INIT_LIST_HEAD(&dev->vbiq.active); 2615 INIT_LIST_HEAD(&dev->vbiq.active);
2561 2616
2562 if (dev->board.has_msp34xx) { 2617 if (dev->has_msp34xx) {
2563 /* Send a reset to other chips via gpio */ 2618 /* Send a reset to other chips via gpio */
2564 ret = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xf7); 2619 ret = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xf7);
2565 if (ret < 0) { 2620 if (ret < 0) {
@@ -2568,7 +2623,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2568 __func__, ret); 2623 __func__, ret);
2569 goto unregister_dev; 2624 goto unregister_dev;
2570 } 2625 }
2571 msleep(3); 2626 usleep_range(10000, 11000);
2572 2627
2573 ret = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xff); 2628 ret = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xff);
2574 if (ret < 0) { 2629 if (ret < 0) {
@@ -2577,7 +2632,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2577 __func__, ret); 2632 __func__, ret);
2578 goto unregister_dev; 2633 goto unregister_dev;
2579 } 2634 }
2580 msleep(3); 2635 usleep_range(10000, 11000);
2581 } 2636 }
2582 2637
2583 /* set default norm */ 2638 /* set default norm */
@@ -2589,8 +2644,10 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2589 v4l2->format = &format[0]; 2644 v4l2->format = &format[0];
2590 2645
2591 maxw = norm_maxw(dev); 2646 maxw = norm_maxw(dev);
2592 /* MaxPacketSize for em2800 is too small to capture at full resolution 2647 /*
2593 * use half of maxw as the scaler can only scale to 50% */ 2648 * MaxPacketSize for em2800 is too small to capture at full resolution
2649 * use half of maxw as the scaler can only scale to 50%
2650 */
2594 if (dev->board.is_em2800) 2651 if (dev->board.is_em2800)
2595 maxw /= 2; 2652 maxw /= 2;
2596 2653
@@ -2611,29 +2668,33 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2611 em28xx_set_outfmt(dev); 2668 em28xx_set_outfmt(dev);
2612 2669
2613 /* Add image controls */ 2670 /* Add image controls */
2614 /* NOTE: at this point, the subdevices are already registered, so bridge 2671
2615 * controls are only added/enabled when no subdevice provides them */ 2672 /*
2616 if (NULL == v4l2_ctrl_find(hdl, V4L2_CID_CONTRAST)) 2673 * NOTE: at this point, the subdevices are already registered, so
2674 * bridge controls are only added/enabled when no subdevice provides
2675 * them
2676 */
2677 if (!v4l2_ctrl_find(hdl, V4L2_CID_CONTRAST))
2617 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops, 2678 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
2618 V4L2_CID_CONTRAST, 2679 V4L2_CID_CONTRAST,
2619 0, 0x1f, 1, CONTRAST_DEFAULT); 2680 0, 0x1f, 1, CONTRAST_DEFAULT);
2620 if (NULL == v4l2_ctrl_find(hdl, V4L2_CID_BRIGHTNESS)) 2681 if (!v4l2_ctrl_find(hdl, V4L2_CID_BRIGHTNESS))
2621 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops, 2682 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
2622 V4L2_CID_BRIGHTNESS, 2683 V4L2_CID_BRIGHTNESS,
2623 -0x80, 0x7f, 1, BRIGHTNESS_DEFAULT); 2684 -0x80, 0x7f, 1, BRIGHTNESS_DEFAULT);
2624 if (NULL == v4l2_ctrl_find(hdl, V4L2_CID_SATURATION)) 2685 if (!v4l2_ctrl_find(hdl, V4L2_CID_SATURATION))
2625 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops, 2686 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
2626 V4L2_CID_SATURATION, 2687 V4L2_CID_SATURATION,
2627 0, 0x1f, 1, SATURATION_DEFAULT); 2688 0, 0x1f, 1, SATURATION_DEFAULT);
2628 if (NULL == v4l2_ctrl_find(hdl, V4L2_CID_BLUE_BALANCE)) 2689 if (!v4l2_ctrl_find(hdl, V4L2_CID_BLUE_BALANCE))
2629 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops, 2690 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
2630 V4L2_CID_BLUE_BALANCE, 2691 V4L2_CID_BLUE_BALANCE,
2631 -0x30, 0x30, 1, BLUE_BALANCE_DEFAULT); 2692 -0x30, 0x30, 1, BLUE_BALANCE_DEFAULT);
2632 if (NULL == v4l2_ctrl_find(hdl, V4L2_CID_RED_BALANCE)) 2693 if (!v4l2_ctrl_find(hdl, V4L2_CID_RED_BALANCE))
2633 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops, 2694 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
2634 V4L2_CID_RED_BALANCE, 2695 V4L2_CID_RED_BALANCE,
2635 -0x30, 0x30, 1, RED_BALANCE_DEFAULT); 2696 -0x30, 0x30, 1, RED_BALANCE_DEFAULT);
2636 if (NULL == v4l2_ctrl_find(hdl, V4L2_CID_SHARPNESS)) 2697 if (!v4l2_ctrl_find(hdl, V4L2_CID_SHARPNESS))
2637 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops, 2698 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
2638 V4L2_CID_SHARPNESS, 2699 V4L2_CID_SHARPNESS,
2639 0, 0x0f, 1, SHARPNESS_DEFAULT); 2700 0, 0x0f, 1, SHARPNESS_DEFAULT);
@@ -2653,7 +2714,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2653 v4l2->vdev.queue->lock = &v4l2->vb_queue_lock; 2714 v4l2->vdev.queue->lock = &v4l2->vb_queue_lock;
2654 2715
2655 /* disable inapplicable ioctls */ 2716 /* disable inapplicable ioctls */
2656 if (dev->board.is_webcam) { 2717 if (dev->is_webcam) {
2657 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_QUERYSTD); 2718 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_QUERYSTD);
2658 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_G_STD); 2719 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_G_STD);
2659 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_S_STD); 2720 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_S_STD);
@@ -2683,7 +2744,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2683 /* Allocate and fill vbi video_device struct */ 2744 /* Allocate and fill vbi video_device struct */
2684 if (em28xx_vbi_supported(dev) == 1) { 2745 if (em28xx_vbi_supported(dev) == 1) {
2685 em28xx_vdev_init(dev, &v4l2->vbi_dev, &em28xx_video_template, 2746 em28xx_vdev_init(dev, &v4l2->vbi_dev, &em28xx_video_template,
2686 "vbi"); 2747 "vbi");
2687 2748
2688 v4l2->vbi_dev.queue = &v4l2->vb_vbiq; 2749 v4l2->vbi_dev.queue = &v4l2->vb_vbiq;
2689 v4l2->vbi_dev.queue->lock = &v4l2->vb_vbi_queue_lock; 2750 v4l2->vbi_dev.queue->lock = &v4l2->vb_vbi_queue_lock;
@@ -2713,7 +2774,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2713 2774
2714 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) { 2775 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
2715 em28xx_vdev_init(dev, &v4l2->radio_dev, &em28xx_radio_template, 2776 em28xx_vdev_init(dev, &v4l2->radio_dev, &em28xx_radio_template,
2716 "radio"); 2777 "radio");
2717 ret = video_register_device(&v4l2->radio_dev, VFL_TYPE_RADIO, 2778 ret = video_register_device(&v4l2->radio_dev, VFL_TYPE_RADIO,
2718 radio_nr[dev->devno]); 2779 radio_nr[dev->devno]);
2719 if (ret < 0) { 2780 if (ret < 0) {
@@ -2749,7 +2810,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
2749 video_device_node_name(&v4l2->vbi_dev)); 2810 video_device_node_name(&v4l2->vbi_dev));
2750 2811
2751 /* Save some power by putting tuner to sleep */ 2812 /* Save some power by putting tuner to sleep */
2752 v4l2_device_call_all(&v4l2->v4l2_dev, 0, core, s_power, 0); 2813 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, standby);
2753 2814
2754 /* initialize videobuf2 stuff */ 2815 /* initialize videobuf2 stuff */
2755 em28xx_vb2_setup(dev); 2816 em28xx_vb2_setup(dev);