├── UVCKernelPatches
├── copyzImage.sh
├── buildKernel.sh
├── applyUVCPatch.sh
├── scripts
│ ├── copyzImage.sh
│ ├── makeKernel.sh
│ ├── applyUVCPatch.sh
│ └── installKernelSources.sh
├── getKernelSources.sh
├── patchUVCInclude.diff
├── README.md
├── patchUVCDriver.diff
└── Patched Files
│ ├── uvcvideo.h
│ ├── videodev2.h
│ └── uvc_driver.c
├── installQtCreator.sh
├── setupTK1.sh
├── install_glfw3.sh
├── installLibrealsenseUVC.sh
├── installLibrealsense.sh
├── LICENSE.md
├── arm.patch
└── README.md
/UVCKernelPatches/copyzImage.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | sudo ./scripts/copyzImage.sh
3 |
--------------------------------------------------------------------------------
/UVCKernelPatches/buildKernel.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | sudo ./scripts/makeKernel.sh
3 |
4 |
--------------------------------------------------------------------------------
/UVCKernelPatches/applyUVCPatch.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | sudo ./scripts/applyUVCPatch.sh
3 |
4 |
--------------------------------------------------------------------------------
/UVCKernelPatches/scripts/copyzImage.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | cd /usr/src/kernel
3 | sudo cp arch/arm/boot/zImage /boot/zImage
4 | grep -q -F 'uvcvideo' /etc/modules || echo 'uvcvideo' | tee -a /etc/modules
5 |
--------------------------------------------------------------------------------
/UVCKernelPatches/getKernelSources.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Install the kernel source for L4T 21.4
3 | # The source for the kernel comes from: https://developer.nvidia.com/linux-tegra-r214
4 | sudo ./scripts/installKernelSources.sh
5 |
--------------------------------------------------------------------------------
/UVCKernelPatches/scripts/makeKernel.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Builds the kernel and modules
3 | # Assumes that the .config file is available
4 | cd /usr/src/kernel
5 | make prepare
6 | make modules_prepare
7 | make -j4
8 | make modules
9 | make modules_install
10 |
11 |
--------------------------------------------------------------------------------
/UVCKernelPatches/scripts/applyUVCPatch.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Apply the UVC patches need for Realsense cameras
3 | PATCHDIR=$PWD
4 | cd /usr/src/kernel
5 | echo $PATCHDIR
6 | patch -p 4 -i $PATCHDIR/patchUVCDriver.diff
7 | patch -p 4 -i $PATCHDIR/patchUVCInclude.diff
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/installQtCreator.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Install Qt and Qt Creator
3 |
4 | sudo apt-get install build-essential qdbus qmlscene qt5-default qt5-qmake \
5 | qtbase5-dev-tools qtchooser qtdeclarative5-dev xbitmaps \
6 | xterm libqt5svg5-dev qttools5-dev qtscript5-dev \
7 | qtdeclarative5-folderlistmodel-plugin qtdeclarative5-controls-plugin \
8 | qt5-default qtcreator -y
9 |
10 |
--------------------------------------------------------------------------------
/UVCKernelPatches/scripts/installKernelSources.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | apt-add-repository universe
3 | apt-get update
4 | apt-get install libqt4-dev pkg-config -y
5 | cd /usr/src
6 | wget http://developer.download.nvidia.com/embedded/L4T/r21_Release_v4.0/source/kernel_src.tbz2
7 | tar -xvf kernel_src.tbz2
8 | cd kernel
9 | zcat /proc/config.gz > .config
10 | make xconfig
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/setupTK1.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Configure a NVIDIA Jetson
3 | # and setup USB 3.0 port to run USB; usb_port_owner_info=2 indicates USB 3.0
4 | sudo sed -i 's/usb_port_owner_info=0/usb_port_owner_info=2/' /boot/extlinux/extlinux.conf
5 | # Disable USB autosuspend
6 | sudo sed -i '$s/$/ usbcore.autosuspend=-1/' /boot/extlinux/extlinux.conf
7 | # /bin/ required for echo to work correctly in /bin/sh file
8 | /bin/echo -e "\e[1;32mPlease reboot for changes to take effect.\e[0m"
9 |
10 |
--------------------------------------------------------------------------------
/install_glfw3.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 | # Installs glfw3 from source as a shared lib
3 |
4 | # Make sure glfw (or any previous version) is not already installed
5 | sudo apt-get update
6 |
7 | sudo apt-get install build-essential cmake git xorg-dev libglu1-mesa-dev
8 |
9 | git clone https://github.com/glfw/glfw.git /tmp/glfw
10 |
11 | cd /tmp/glfw
12 |
13 | # Jetson TK1 currently has issues with releases past 3.1.2
14 | git checkout 3.1.2
15 |
16 | cmake . -DBUILD_SHARED_LIBS=ON
17 |
18 | make
19 |
20 | sudo make install
21 |
22 | sudo ldconfig
23 |
24 | rm -rf /tmp/glfw
25 |
26 | echo "Done installing glfw3!"
27 |
--------------------------------------------------------------------------------
/installLibrealsenseUVC.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Install the Intel Realsense library librealsense on a Jetson Development Kit
3 | # Copyright (c) 2016 Jetsonhacks
4 | # MIT License
5 | # sudo apt-get update && sudo apt-get upgrade
6 | sudo apt-get install libusb-1.0-0-dev
7 | # Install glfw3 3.1.2 ; Jetson TK1 currently has issues with later releases
8 | ./install_glfw3.sh
9 | # Install into home directory
10 | cd ~/
11 | git clone https://github.com/IntelRealSense/librealsense.git
12 | cd librealsense
13 | # Checkout version 0.9.2 of librealsense, last tested version
14 | git checkout v0.9.2
15 | # git checkout 495d18667aba615a3e19501ce96e28492a71b46e
16 | # Patches uvc-v4l2.cpp to avoid crash; removes -sse flag from .pro file
17 | patch -p 1 -i ~/installLibrealsense/arm.patch
18 | # Copy over the udev rules so that camera can be run from user space
19 | sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
20 | sudo cp config/uvc.conf /etc/modprobe.d/
21 | sudo udevadm control --reload-rules && udevadm trigger
22 | # Make and Install
23 | make BACKEND=LIBUVC
24 | sudo make install
25 |
26 |
27 |
--------------------------------------------------------------------------------
/installLibrealsense.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Install the Intel Realsense library librealsense on a Jetson Development Kit
3 | # Copyright (c) 2016 Jetsonhacks
4 | # MIT License
5 | # sudo apt-get update && sudo apt-get upgrade ; done by glfw3
6 | # Install glfw3 3.1.2 ; Jetson TK1 currently has issues with later releases
7 | ./install_glfw3.sh
8 | sudo apt-get install libusb-1.0-0-dev
9 | # Install librealsense into home directory
10 | cd ~/
11 | git clone https://github.com/IntelRealSense/librealsense.git
12 | cd librealsense
13 | # Checkout version 0.9.2 of librealsense, last tested version
14 | git checkout v0.9.2
15 | # git checkout 495d18667aba615a3e19501ce96e28492a71b46e
16 | # Patches uvc-v4l2.cpp to avoid crash; removes -sse flag from .pro file
17 | patch -p 1 -i ~/installLibrealsense/arm.patch
18 | # Copy over the udev rules so that camera can be run from user space
19 | sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
20 | sudo cp config/uvc.conf /etc/modprobe.d/
21 | sudo udevadm control --reload-rules && udevadm trigger
22 | # Make and Install
23 | make
24 | sudo make install
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Jetsonhacks
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/arm.patch:
--------------------------------------------------------------------------------
1 | diff --git a/librealsense.qtcreator/realsense.pro b/librealsense.qtcreator/realsense.pro
2 | index 8a16690..2fe7ed5 100644
3 | --- a/librealsense.qtcreator/realsense.pro
4 | +++ b/librealsense.qtcreator/realsense.pro
5 | @@ -9,7 +9,7 @@ INCLUDEPATH += ../include
6 | CONFIG += link_pkgconfig
7 | PKGCONFIG += libusb-1.0
8 | LIBS += -pthread
9 | -QMAKE_CXXFLAGS += -std=c++11 -fPIC -pedantic -mssse3
10 | +QMAKE_CXXFLAGS += -std=c++11 -fPIC -pedantic
11 | QMAKE_CXXFLAGS += -Wno-missing-field-initializers -Wno-switch -Wno-multichar
12 | QMAKE_CXXFLAGS += -DRS_USE_V4L2_BACKEND
13 |
14 |
15 | diff --git a/src/uvc-v4l2.cpp b/src/uvc-v4l2.cpp
16 | index 1cde638..4d69df6 100644
17 | --- a/src/uvc-v4l2.cpp
18 | +++ b/src/uvc-v4l2.cpp
19 | @@ -247,15 +247,7 @@ namespace rsimpl
20 | buf.index = i;
21 | if(xioctl(fd, VIDIOC_QBUF, &buf) < 0) throw_error("VIDIOC_QBUF");
22 | }
23 | -
24 | v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
25 | - for(int i=0; i<10; ++i)
26 | - {
27 | - if(xioctl(fd, VIDIOC_STREAMON, &type) < 0)
28 | - {
29 | - std::this_thread::sleep_for(std::chrono::milliseconds(100));
30 | - }
31 | - }
32 | if(xioctl(fd, VIDIOC_STREAMON, &type) < 0) throw_error("VIDIOC_STREAMON");
33 |
34 | is_capturing = true;
35 |
--------------------------------------------------------------------------------
/UVCKernelPatches/patchUVCInclude.diff:
--------------------------------------------------------------------------------
1 | diff -rcNP /usr/src/pristine-kernel/include/uapi/linux/videodev2.h /usr/src/kernel/include/uapi/linux/videodev2.h
2 | *** /usr/src/pristine-kernel/include/uapi/linux/videodev2.h 2015-06-25 15:18:19.000000000 -0700
3 | --- /usr/src/kernel/include/uapi/linux/videodev2.h 2016-06-04 21:52:20.336488224 -0700
4 | ***************
5 | *** 401,406 ****
6 | --- 401,418 ----
7 | #define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */
8 | #define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
9 |
10 | + /* Intel RealSense-specific formats */
11 | + #define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */
12 | + #define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */
13 | + #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */
14 | + #define V4L2_PIX_FMT_RW10 v4l2_fourcc('R', 'W', '1', '0') /* Raw data 10-bit */
15 | + #define V4L2_PIX_FMT_INVZ v4l2_fourcc('I', 'N', 'V', 'Z') /* 16 Depth */
16 | + #define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I') /* 24 Depth/IR 16:8 */
17 | + #define V4L2_PIX_FMT_INVR v4l2_fourcc('I', 'N', 'V', 'R') /* 16 Depth */
18 | + #define V4L2_PIX_FMT_INRI v4l2_fourcc('I', 'N', 'R', 'I') /* 24 Depth/IR 16:8 */
19 | + #define V4L2_PIX_FMT_INVI v4l2_fourcc('I', 'N', 'V', 'I') /* 8 IR */
20 | + #define V4L2_PIX_FMT_RELI v4l2_fourcc('R', 'E', 'L', 'I') /* 8 IR alternating on off illumination */
21 | +
22 | /* Vendor-specific formats */
23 | #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
24 | #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Installs the librealsense library for the Intel RealSense cameras on the NVIDIA Jetson platform.
2 |
3 | For the Jetson TK1 Development Kit, a Patch is supplied for the Linux kernel which allows
4 | V4L2 to work properly. This patch is in the 'UVCKernelPatches' directory. You must rebuild
5 | the kernel on the TK1 for librealsense to work correctly. After the kernel
6 | is rebuilt, run the 'installLibrealsense.sh' shell file from this directory to install
7 | librealsense on the TK1.
8 |
9 | For the NVIDIA Jetson TX1 Development Kit, please use the repository:
10 |
11 | https://github.com/jetsonhacks/installLibrealsenseTX1
12 |
13 | Installation is broken up into two parts. The shell file 'installLibrealsense.sh' installs dependences for the librealsense library on the Jetson, including libusb-dev and the glfw library, and then clones the librealsense library, patches it for ARM, and then builds the library and installs it. As a convenience, the script also builds the examples using the LIBUVC backend, which end up in the 'bin' directory.
14 |
15 | Note: As of this writing (June 3, 2016) the Jetson TK1 uses v3.1.2 of the glfw, as later versions crash. The version supplied within librealsense currently builds v3.2, which causes issues.
16 |
17 | There is also a shell file for installing Qt Creator, which can be used to work with the supplied Qt Creator project files included in the installation.
18 |
19 | The Jetson Development Kits have a feature used for power saving, called autosuspend, which will power down the USB ports after they have been idle for a while. The script 'disableAutosuspend.sh' will turn that feature off, which is needed for the RealSense camera.
20 |
21 | Note: The Jetson TK1 is setup for using USB 2.0. The RealSense cameras are USB 3.0, which requires reconfiguration of the TK1. For example:
22 |
23 | Jetson TK1: Setup USB port to run USB 3.0; usb_port_owner_info=2 indicates USB 3.0
24 |
25 | sudo sed -i 's/usb_port_owner_info=0/usb_port_owner_info=2/' /boot/extlinux/extlinux.conf
26 |
27 | The Jetson TX1 enables USB 3.0 by default.
28 |
29 | The RealSense R200 is the only camera tested so far.
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/UVCKernelPatches/README.md:
--------------------------------------------------------------------------------
1 | This directory contains patches for L4T 21.4 on the NVIDIA Jetson TK1
2 | to support Intel RealSense cameras. You will need to build a new kernel.
3 | Please read through this document before altering your system.
4 |
5 | This document assumes that you know how to build a kernel for the TK1, similar to the instructions at:
6 |
7 | https://devtalk.nvidia.com/default/topic/762653/-howto-build-own-kernel-for-jetson-tk1/
8 |
9 | To start, download the kernel source and decompress it into /usr/src
10 |
11 | The kernel sources for L4T 21.4 are available at:
12 |
13 | https://developer.nvidia.com/linux-tegra-r214
14 |
15 | Note:
16 |
17 | There is a convenience script provided for downloading the kernel source (this will also open a configuration editor):
18 |
19 | $ ./getKernelSources.sh
20 |
21 |
22 | USB Video Class (UVC)
23 |
24 | The RealSense libraries adds configuration information to the UVC device driver. This directory contains patches for the stock 3.10 kernel sources to integrate those changes.
25 |
26 | This document describes creating a UVC module called 'uvcvideo.ko'
27 |
28 | The default kernel has uvcvideo built-in. As a convenience, the file 'dotConfig' is a .config file which configures the kernel to use uvcvideo as a module, and retains the same kernel local-version identifier:
29 |
30 | -gdacac96
31 |
32 | as the stock L4T 21.4 kernel. The file 'dotConfig' is the .config file that is modified
33 | as described (it can be used as the .config in the kernel directory assuming no other
34 | changes to the kernel are needed).
35 |
36 | The settings in the kernel config file for uvcvideo is:
37 |
38 | Device Drivers->Multimedia support->Media USB Adapters->USB Video Class(UVC)
39 |
40 | Set this to build as a module
41 |
42 |
43 | You can then apply the UVC patches similar to:
44 |
45 | \# Switch to /usr/src/kernel
46 | \# Try a dry run first by adding --dry-run flag to the patch command
47 |
48 | $ patch -p 4 -i \/patchUVCDriver.diff
49 | $ patch -p 4 -i \/patchUVCInclude.diff
50 |
51 | where \ represents the path to where the patches are stored, i.e this directory.
52 |
53 | Note: The folder 'Patched Files' in this directory holds copies of the files
54 | (after patches applied) that are patched in the above process.
55 |
56 | Note that a convenience file is provide to do the above steps.
57 |
58 | $ ./applyUVCPatch.sh
59 |
60 | Once the patches are applied, make the kernel and the modules:
61 |
62 |
63 | make prepare
64 | make modules_prepare
65 | make -j4
66 | make modules
67 | make modules_install
68 |
69 |
70 | Note that a convenience file is provided for the above steps:
71 |
72 | $ ./buildKernel.sh
73 |
74 | After the build is complete, you can save the zImage for flashing on the TK1 to external media. This image can then be used to flash the Jetson with the new configuration.
75 |
76 | You can copy the zImage to the boot directory:
77 |
78 | $ sudo cp arch/arm/boot/zImage /boot/zImage
79 |
80 | which will cause the new kernel to be used on boot.
81 |
82 | In order to have uvcvideo.ko load at boot time, in the file:
83 |
84 | /etc/modules
85 |
86 | add the line:
87 |
88 | uvcvideo
89 |
90 | This will load the uvcvideo driver at boot time.
91 |
92 | A convenience file is provided to copy the zImage and add the module name to /etc/modules :
93 |
94 | $ ./copyzImage.sh
95 |
96 | In the case where the zImage was copied to the boot directory, rebooting the Jetson
97 | will cause the new kernel and modules to be used.
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/UVCKernelPatches/patchUVCDriver.diff:
--------------------------------------------------------------------------------
1 | diff -rcNP /usr/src/pristine-kernel/drivers/media/usb/uvc/uvc_driver.c /usr/src/kernel/drivers/media/usb/uvc/uvc_driver.c
2 | *** /usr/src/pristine-kernel/drivers/media/usb/uvc/uvc_driver.c 2015-06-25 15:18:11.000000000 -0700
3 | --- /usr/src/kernel/drivers/media/usb/uvc/uvc_driver.c 2016-06-04 21:46:59.717037079 -0700
4 | ***************
5 | *** 107,112 ****
6 | --- 107,167 ----
7 | .guid = UVC_GUID_FORMAT_Y16,
8 | .fcc = V4L2_PIX_FMT_Y16,
9 | },
10 | + {
11 | + .name = "Greyscale 8 L/R (Y8I)",
12 | + .guid = UVC_GUID_FORMAT_Y8I,
13 | + .fcc = V4L2_PIX_FMT_Y8I,
14 | + },
15 | + {
16 | + .name = "Greyscale 12 L/R (Y12I)",
17 | + .guid = UVC_GUID_FORMAT_Y12I,
18 | + .fcc = V4L2_PIX_FMT_Y12I,
19 | + },
20 | + {
21 | + .name = "Depth data 16-bit (Z16)",
22 | + .guid = UVC_GUID_FORMAT_Z16,
23 | + .fcc = V4L2_PIX_FMT_Z16,
24 | + },
25 | + {
26 | + .name = "Raw data 10-bit (RW10)",
27 | + .guid = UVC_GUID_FORMAT_RW10,
28 | + .fcc = V4L2_PIX_FMT_RW10,
29 | + },
30 | + {
31 | + .name = "Depth 16-bit (INVZ)",
32 | + .guid = UVC_GUID_FORMAT_INVZ,
33 | + .fcc = V4L2_PIX_FMT_INVZ,
34 | + },
35 | + {
36 | + .name = "Depth:IR 16:8 24-bit (INZI)",
37 | + .guid = UVC_GUID_FORMAT_INZI,
38 | + .fcc = V4L2_PIX_FMT_INZI,
39 | + },
40 | + {
41 | + .name = "Depth 16-bit (INVR)",
42 | + .guid = UVC_GUID_FORMAT_INVR,
43 | + .fcc = V4L2_PIX_FMT_INVR,
44 | + },
45 | + {
46 | + .name = "Depth:IR 16:8 24-bit (INRI)",
47 | + .guid = UVC_GUID_FORMAT_INRI,
48 | + .fcc = V4L2_PIX_FMT_INRI,
49 | + },
50 | + {
51 | + .name = "Infrared 8-bit (INVI)",
52 | + .guid = UVC_GUID_FORMAT_INVI,
53 | + .fcc = V4L2_PIX_FMT_INVI,
54 | + },
55 | + {
56 | + .name = "FlickerIR 8-bit (RELI)",
57 | + .guid = UVC_GUID_FORMAT_RELI,
58 | + .fcc = V4L2_PIX_FMT_RELI,
59 | + },
60 | + {
61 | + .name = "BGGR Bayer (BY8 )",
62 | + .guid = UVC_GUID_FORMAT_BY8,
63 | + .fcc = V4L2_PIX_FMT_SBGGR8,
64 | + },
65 | {
66 | .name = "RGB Bayer",
67 | .guid = UVC_GUID_FORMAT_BY8,
68 | ***************
69 | *** 121,127 ****
70 | .name = "H.264",
71 | .guid = UVC_GUID_FORMAT_H264,
72 | .fcc = V4L2_PIX_FMT_H264,
73 | ! },
74 | };
75 |
76 | /* ------------------------------------------------------------------------
77 | --- 176,182 ----
78 | .name = "H.264",
79 | .guid = UVC_GUID_FORMAT_H264,
80 | .fcc = V4L2_PIX_FMT_H264,
81 | ! }
82 | };
83 |
84 | /* ------------------------------------------------------------------------
85 | diff -rcNP /usr/src/pristine-kernel/drivers/media/usb/uvc/uvcvideo.h /usr/src/kernel/drivers/media/usb/uvc/uvcvideo.h
86 | *** /usr/src/pristine-kernel/drivers/media/usb/uvc/uvcvideo.h 2015-06-25 15:18:11.000000000 -0700
87 | --- /usr/src/kernel/drivers/media/usb/uvc/uvcvideo.h 2016-06-04 21:47:11.977998765 -0700
88 | ***************
89 | *** 91,96 ****
90 | --- 91,126 ----
91 | #define UVC_GUID_FORMAT_Y16 \
92 | { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
93 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
94 | + #define UVC_GUID_FORMAT_Y8I \
95 | + { 'Y', '8', 'I', ' ', 0x00, 0x00, 0x10, 0x00, \
96 | + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
97 | + #define UVC_GUID_FORMAT_Y12I \
98 | + { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \
99 | + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
100 | + #define UVC_GUID_FORMAT_Z16 \
101 | + { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
102 | + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
103 | + #define UVC_GUID_FORMAT_RW10 \
104 | + { 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \
105 | + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
106 | + #define UVC_GUID_FORMAT_INVZ \
107 | + { 'I', 'N', 'V', 'Z', 0x90, 0x2d, 0x58, 0x4a, \
108 | + 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
109 | + #define UVC_GUID_FORMAT_INZI \
110 | + { 'I', 'N', 'Z', 'I', 0x66, 0x1a, 0x42, 0xa2, \
111 | + 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a}
112 | + #define UVC_GUID_FORMAT_INVR \
113 | + { 'I', 'N', 'V', 'R', 0x90, 0x2d, 0x58, 0x4a, \
114 | + 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
115 | + #define UVC_GUID_FORMAT_INRI \
116 | + { 'I', 'N', 'R', 'I', 0x90, 0x2d, 0x58, 0x4a, \
117 | + 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
118 | + #define UVC_GUID_FORMAT_INVI \
119 | + { 'I', 'N', 'V', 'I', 0xdb, 0x57, 0x49, 0x5e, \
120 | + 0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f}
121 | + #define UVC_GUID_FORMAT_RELI \
122 | + { 'R', 'E', 'L', 'I', 0x14, 0x13, 0x43, 0xf9, \
123 | + 0xa7, 0x5a, 0xee, 0x6b, 0xbf, 0x01, 0x2e, 0x23}
124 | #define UVC_GUID_FORMAT_BY8 \
125 | { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
126 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
127 |
--------------------------------------------------------------------------------
/UVCKernelPatches/Patched Files/uvcvideo.h:
--------------------------------------------------------------------------------
1 | #ifndef _USB_VIDEO_H_
2 | #define _USB_VIDEO_H_
3 |
4 | #ifndef __KERNEL__
5 | #error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
6 | #endif /* __KERNEL__ */
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | /* --------------------------------------------------------------------------
21 | * UVC constants
22 | */
23 |
24 | #define UVC_TERM_INPUT 0x0000
25 | #define UVC_TERM_OUTPUT 0x8000
26 | #define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
27 |
28 | #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
29 | #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
30 | #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
31 | #define UVC_ENTITY_IS_ITERM(entity) \
32 | (UVC_ENTITY_IS_TERM(entity) && \
33 | ((entity)->type & 0x8000) == UVC_TERM_INPUT)
34 | #define UVC_ENTITY_IS_OTERM(entity) \
35 | (UVC_ENTITY_IS_TERM(entity) && \
36 | ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
37 |
38 |
39 | /* ------------------------------------------------------------------------
40 | * GUIDs
41 | */
42 | #define UVC_GUID_UVC_CAMERA \
43 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
45 | #define UVC_GUID_UVC_OUTPUT \
46 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
48 | #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
49 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
51 | #define UVC_GUID_UVC_PROCESSING \
52 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
54 | #define UVC_GUID_UVC_SELECTOR \
55 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
57 |
58 | #define UVC_GUID_FORMAT_MJPEG \
59 | { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
60 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
61 | #define UVC_GUID_FORMAT_YUY2 \
62 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
63 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
64 | #define UVC_GUID_FORMAT_YUY2_ISIGHT \
65 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
66 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
67 | #define UVC_GUID_FORMAT_NV12 \
68 | { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
69 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
70 | #define UVC_GUID_FORMAT_YV12 \
71 | { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
72 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
73 | #define UVC_GUID_FORMAT_I420 \
74 | { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
75 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
76 | #define UVC_GUID_FORMAT_UYVY \
77 | { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
78 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
79 | #define UVC_GUID_FORMAT_Y800 \
80 | { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
81 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
82 | #define UVC_GUID_FORMAT_Y8 \
83 | { 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \
84 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
85 | #define UVC_GUID_FORMAT_Y10 \
86 | { 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \
87 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
88 | #define UVC_GUID_FORMAT_Y12 \
89 | { 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \
90 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
91 | #define UVC_GUID_FORMAT_Y16 \
92 | { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
93 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
94 | #define UVC_GUID_FORMAT_Y8I \
95 | { 'Y', '8', 'I', ' ', 0x00, 0x00, 0x10, 0x00, \
96 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
97 | #define UVC_GUID_FORMAT_Y12I \
98 | { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \
99 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
100 | #define UVC_GUID_FORMAT_Z16 \
101 | { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
102 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
103 | #define UVC_GUID_FORMAT_RW10 \
104 | { 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \
105 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
106 | #define UVC_GUID_FORMAT_INVZ \
107 | { 'I', 'N', 'V', 'Z', 0x90, 0x2d, 0x58, 0x4a, \
108 | 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
109 | #define UVC_GUID_FORMAT_INZI \
110 | { 'I', 'N', 'Z', 'I', 0x66, 0x1a, 0x42, 0xa2, \
111 | 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a}
112 | #define UVC_GUID_FORMAT_INVR \
113 | { 'I', 'N', 'V', 'R', 0x90, 0x2d, 0x58, 0x4a, \
114 | 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
115 | #define UVC_GUID_FORMAT_INRI \
116 | { 'I', 'N', 'R', 'I', 0x90, 0x2d, 0x58, 0x4a, \
117 | 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
118 | #define UVC_GUID_FORMAT_INVI \
119 | { 'I', 'N', 'V', 'I', 0xdb, 0x57, 0x49, 0x5e, \
120 | 0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f}
121 | #define UVC_GUID_FORMAT_RELI \
122 | { 'R', 'E', 'L', 'I', 0x14, 0x13, 0x43, 0xf9, \
123 | 0xa7, 0x5a, 0xee, 0x6b, 0xbf, 0x01, 0x2e, 0x23}
124 | #define UVC_GUID_FORMAT_BY8 \
125 | { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
126 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
127 | #define UVC_GUID_FORMAT_RGBP \
128 | { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
129 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
130 | #define UVC_GUID_FORMAT_M420 \
131 | { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
132 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
133 |
134 | #define UVC_GUID_FORMAT_H264 \
135 | { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \
136 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
137 |
138 | /* ------------------------------------------------------------------------
139 | * Driver specific constants.
140 | */
141 |
142 | #define DRIVER_VERSION "1.1.1"
143 |
144 | /* Number of isochronous URBs. */
145 | #define UVC_URBS 5
146 | /* Maximum number of packets per URB. */
147 | #define UVC_MAX_PACKETS 32
148 | /* Maximum number of video buffers. */
149 | #define UVC_MAX_VIDEO_BUFFERS 32
150 | /* Maximum status buffer size in bytes of interrupt URB. */
151 | #define UVC_MAX_STATUS_SIZE 16
152 |
153 | #define UVC_CTRL_CONTROL_TIMEOUT 300
154 | #define UVC_CTRL_STREAMING_TIMEOUT 5000
155 |
156 | /* Maximum allowed number of control mappings per device */
157 | #define UVC_MAX_CONTROL_MAPPINGS 1024
158 | #define UVC_MAX_CONTROL_MENU_ENTRIES 32
159 |
160 | /* Devices quirks */
161 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001
162 | #define UVC_QUIRK_PROBE_MINMAX 0x00000002
163 | #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
164 | #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
165 | #define UVC_QUIRK_STREAM_NO_FID 0x00000010
166 | #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
167 | #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
168 | #define UVC_QUIRK_PROBE_DEF 0x00000100
169 | #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
170 |
171 | /* Format flags */
172 | #define UVC_FMT_FLAG_COMPRESSED 0x00000001
173 | #define UVC_FMT_FLAG_STREAM 0x00000002
174 |
175 | /* ------------------------------------------------------------------------
176 | * Structures.
177 | */
178 |
179 | struct uvc_device;
180 |
181 | /* TODO: Put the most frequently accessed fields at the beginning of
182 | * structures to maximize cache efficiency.
183 | */
184 | struct uvc_control_info {
185 | struct list_head mappings;
186 |
187 | __u8 entity[16];
188 | __u8 index; /* Bit index in bmControls */
189 | __u8 selector;
190 |
191 | __u16 size;
192 | __u32 flags;
193 | };
194 |
195 | struct uvc_control_mapping {
196 | struct list_head list;
197 | struct list_head ev_subs;
198 |
199 | __u32 id;
200 | __u8 name[32];
201 | __u8 entity[16];
202 | __u8 selector;
203 |
204 | __u8 size;
205 | __u8 offset;
206 | enum v4l2_ctrl_type v4l2_type;
207 | __u32 data_type;
208 |
209 | struct uvc_menu_info *menu_info;
210 | __u32 menu_count;
211 |
212 | __u32 master_id;
213 | __s32 master_manual;
214 | __u32 slave_ids[2];
215 |
216 | __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
217 | const __u8 *data);
218 | void (*set) (struct uvc_control_mapping *mapping, __s32 value,
219 | __u8 *data);
220 | };
221 |
222 | struct uvc_control {
223 | struct uvc_entity *entity;
224 | struct uvc_control_info info;
225 |
226 | __u8 index; /* Used to match the uvc_control entry with a
227 | uvc_control_info. */
228 | __u8 dirty:1,
229 | loaded:1,
230 | modified:1,
231 | cached:1,
232 | initialized:1;
233 |
234 | __u8 *uvc_data;
235 | };
236 |
237 | struct uvc_format_desc {
238 | char *name;
239 | __u8 guid[16];
240 | __u32 fcc;
241 | };
242 |
243 | /* The term 'entity' refers to both UVC units and UVC terminals.
244 | *
245 | * The type field is either the terminal type (wTerminalType in the terminal
246 | * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
247 | * As the bDescriptorSubtype field is one byte long, the type value will
248 | * always have a null MSB for units. All terminal types defined by the UVC
249 | * specification have a non-null MSB, so it is safe to use the MSB to
250 | * differentiate between units and terminals as long as the descriptor parsing
251 | * code makes sure terminal types have a non-null MSB.
252 | *
253 | * For terminals, the type's most significant bit stores the terminal
254 | * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
255 | * always be accessed with the UVC_ENTITY_* macros and never directly.
256 | */
257 |
258 | #define UVC_ENTITY_FLAG_DEFAULT (1 << 0)
259 |
260 | struct uvc_entity {
261 | struct list_head list; /* Entity as part of a UVC device. */
262 | struct list_head chain; /* Entity as part of a video device
263 | * chain. */
264 | unsigned int flags;
265 |
266 | __u8 id;
267 | __u16 type;
268 | char name[64];
269 |
270 | /* Media controller-related fields. */
271 | struct video_device *vdev;
272 | struct v4l2_subdev subdev;
273 | unsigned int num_pads;
274 | unsigned int num_links;
275 | struct media_pad *pads;
276 |
277 | union {
278 | struct {
279 | __u16 wObjectiveFocalLengthMin;
280 | __u16 wObjectiveFocalLengthMax;
281 | __u16 wOcularFocalLength;
282 | __u8 bControlSize;
283 | __u8 *bmControls;
284 | } camera;
285 |
286 | struct {
287 | __u8 bControlSize;
288 | __u8 *bmControls;
289 | __u8 bTransportModeSize;
290 | __u8 *bmTransportModes;
291 | } media;
292 |
293 | struct {
294 | } output;
295 |
296 | struct {
297 | __u16 wMaxMultiplier;
298 | __u8 bControlSize;
299 | __u8 *bmControls;
300 | __u8 bmVideoStandards;
301 | } processing;
302 |
303 | struct {
304 | } selector;
305 |
306 | struct {
307 | __u8 guidExtensionCode[16];
308 | __u8 bNumControls;
309 | __u8 bControlSize;
310 | __u8 *bmControls;
311 | __u8 *bmControlsType;
312 | } extension;
313 | };
314 |
315 | __u8 bNrInPins;
316 | __u8 *baSourceID;
317 |
318 | unsigned int ncontrols;
319 | struct uvc_control *controls;
320 | };
321 |
322 | struct uvc_frame {
323 | __u8 bFrameIndex;
324 | __u8 bmCapabilities;
325 | __u16 wWidth;
326 | __u16 wHeight;
327 | __u32 dwMinBitRate;
328 | __u32 dwMaxBitRate;
329 | __u32 dwMaxVideoFrameBufferSize;
330 | __u8 bFrameIntervalType;
331 | __u32 dwDefaultFrameInterval;
332 | __u32 *dwFrameInterval;
333 | };
334 |
335 | struct uvc_format {
336 | __u8 type;
337 | __u8 index;
338 | __u8 bpp;
339 | __u8 colorspace;
340 | __u32 fcc;
341 | __u32 flags;
342 |
343 | char name[32];
344 |
345 | unsigned int nframes;
346 | struct uvc_frame *frame;
347 | };
348 |
349 | struct uvc_streaming_header {
350 | __u8 bNumFormats;
351 | __u8 bEndpointAddress;
352 | __u8 bTerminalLink;
353 | __u8 bControlSize;
354 | __u8 *bmaControls;
355 | /* The following fields are used by input headers only. */
356 | __u8 bmInfo;
357 | __u8 bStillCaptureMethod;
358 | __u8 bTriggerSupport;
359 | __u8 bTriggerUsage;
360 | };
361 |
362 | enum uvc_buffer_state {
363 | UVC_BUF_STATE_IDLE = 0,
364 | UVC_BUF_STATE_QUEUED = 1,
365 | UVC_BUF_STATE_ACTIVE = 2,
366 | UVC_BUF_STATE_READY = 3,
367 | UVC_BUF_STATE_DONE = 4,
368 | UVC_BUF_STATE_ERROR = 5,
369 | };
370 |
371 | struct uvc_buffer {
372 | struct vb2_buffer buf;
373 | struct list_head queue;
374 |
375 | enum uvc_buffer_state state;
376 | unsigned int error;
377 |
378 | void *mem;
379 | unsigned int length;
380 | unsigned int bytesused;
381 |
382 | u32 pts;
383 | };
384 |
385 | #define UVC_QUEUE_DISCONNECTED (1 << 0)
386 | #define UVC_QUEUE_DROP_CORRUPTED (1 << 1)
387 |
388 | struct uvc_video_queue {
389 | struct vb2_queue queue;
390 | struct mutex mutex; /* Protects queue */
391 |
392 | unsigned int flags;
393 | unsigned int buf_used;
394 |
395 | spinlock_t irqlock; /* Protects irqqueue */
396 | struct list_head irqqueue;
397 | };
398 |
399 | struct uvc_video_chain {
400 | struct uvc_device *dev;
401 | struct list_head list;
402 |
403 | struct list_head entities; /* All entities */
404 | struct uvc_entity *processing; /* Processing unit */
405 | struct uvc_entity *selector; /* Selector unit */
406 |
407 | struct mutex ctrl_mutex; /* Protects ctrl.info */
408 |
409 | struct v4l2_prio_state prio; /* V4L2 priority state */
410 | u32 caps; /* V4L2 chain-wide caps */
411 | };
412 |
413 | struct uvc_stats_frame {
414 | unsigned int size; /* Number of bytes captured */
415 | unsigned int first_data; /* Index of the first non-empty packet */
416 |
417 | unsigned int nb_packets; /* Number of packets */
418 | unsigned int nb_empty; /* Number of empty packets */
419 | unsigned int nb_invalid; /* Number of packets with an invalid header */
420 | unsigned int nb_errors; /* Number of packets with the error bit set */
421 |
422 | unsigned int nb_pts; /* Number of packets with a PTS timestamp */
423 | unsigned int nb_pts_diffs; /* Number of PTS differences inside a frame */
424 | unsigned int last_pts_diff; /* Index of the last PTS difference */
425 | bool has_initial_pts; /* Whether the first non-empty packet has a PTS */
426 | bool has_early_pts; /* Whether a PTS is present before the first non-empty packet */
427 | u32 pts; /* PTS of the last packet */
428 |
429 | unsigned int nb_scr; /* Number of packets with a SCR timestamp */
430 | unsigned int nb_scr_diffs; /* Number of SCR.STC differences inside a frame */
431 | u16 scr_sof; /* SCR.SOF of the last packet */
432 | u32 scr_stc; /* SCR.STC of the last packet */
433 | };
434 |
435 | struct uvc_stats_stream {
436 | struct timespec start_ts; /* Stream start timestamp */
437 | struct timespec stop_ts; /* Stream stop timestamp */
438 |
439 | unsigned int nb_frames; /* Number of frames */
440 |
441 | unsigned int nb_packets; /* Number of packets */
442 | unsigned int nb_empty; /* Number of empty packets */
443 | unsigned int nb_invalid; /* Number of packets with an invalid header */
444 | unsigned int nb_errors; /* Number of packets with the error bit set */
445 |
446 | unsigned int nb_pts_constant; /* Number of frames with constant PTS */
447 | unsigned int nb_pts_early; /* Number of frames with early PTS */
448 | unsigned int nb_pts_initial; /* Number of frames with initial PTS */
449 |
450 | unsigned int nb_scr_count_ok; /* Number of frames with at least one SCR per non empty packet */
451 | unsigned int nb_scr_diffs_ok; /* Number of frames with varying SCR.STC */
452 | unsigned int scr_sof_count; /* STC.SOF counter accumulated since stream start */
453 | unsigned int scr_sof; /* STC.SOF of the last packet */
454 | unsigned int min_sof; /* Minimum STC.SOF value */
455 | unsigned int max_sof; /* Maximum STC.SOF value */
456 | };
457 |
458 | struct uvc_streaming {
459 | struct list_head list;
460 | struct uvc_device *dev;
461 | struct video_device *vdev;
462 | struct uvc_video_chain *chain;
463 | atomic_t active;
464 |
465 | struct usb_interface *intf;
466 | int intfnum;
467 | __u16 maxpsize;
468 |
469 | struct uvc_streaming_header header;
470 | enum v4l2_buf_type type;
471 |
472 | unsigned int nformats;
473 | struct uvc_format *format;
474 |
475 | struct uvc_streaming_control ctrl;
476 | struct uvc_format *def_format;
477 | struct uvc_format *cur_format;
478 | struct uvc_frame *cur_frame;
479 | /* Protect access to ctrl, cur_format, cur_frame and hardware video
480 | * probe control.
481 | */
482 | struct mutex mutex;
483 |
484 | /* Buffers queue. */
485 | unsigned int frozen : 1;
486 | struct uvc_video_queue queue;
487 | void (*decode) (struct urb *urb, struct uvc_streaming *video,
488 | struct uvc_buffer *buf);
489 |
490 | /* Context data used by the bulk completion handler. */
491 | struct {
492 | __u8 header[256];
493 | unsigned int header_size;
494 | int skip_payload;
495 | __u32 payload_size;
496 | __u32 max_payload_size;
497 | } bulk;
498 |
499 | struct urb *urb[UVC_URBS];
500 | char *urb_buffer[UVC_URBS];
501 | dma_addr_t urb_dma[UVC_URBS];
502 | unsigned int urb_size;
503 |
504 | __u32 sequence;
505 | __u8 last_fid;
506 |
507 | /* debugfs */
508 | struct dentry *debugfs_dir;
509 | struct {
510 | struct uvc_stats_frame frame;
511 | struct uvc_stats_stream stream;
512 | } stats;
513 |
514 | /* Timestamps support. */
515 | struct uvc_clock {
516 | struct uvc_clock_sample {
517 | u32 dev_stc;
518 | u16 dev_sof;
519 | struct timespec host_ts;
520 | u16 host_sof;
521 | } *samples;
522 |
523 | unsigned int head;
524 | unsigned int count;
525 | unsigned int size;
526 |
527 | u16 last_sof;
528 | u16 sof_offset;
529 |
530 | spinlock_t lock;
531 | } clock;
532 | };
533 |
534 | enum uvc_device_state {
535 | UVC_DEV_DISCONNECTED = 1,
536 | };
537 |
538 | struct uvc_device {
539 | struct usb_device *udev;
540 | struct usb_interface *intf;
541 | unsigned long warnings;
542 | __u32 quirks;
543 | int intfnum;
544 | char name[32];
545 |
546 | enum uvc_device_state state;
547 | atomic_t users;
548 | atomic_t nmappings;
549 |
550 | /* Video control interface */
551 | #ifdef CONFIG_MEDIA_CONTROLLER
552 | struct media_device mdev;
553 | #endif
554 | struct v4l2_device vdev;
555 | __u16 uvc_version;
556 | __u32 clock_frequency;
557 |
558 | struct list_head entities;
559 | struct list_head chains;
560 |
561 | /* Video Streaming interfaces */
562 | struct list_head streams;
563 | atomic_t nstreams;
564 |
565 | /* Status Interrupt Endpoint */
566 | struct usb_host_endpoint *int_ep;
567 | struct urb *int_urb;
568 | __u8 *status;
569 | struct input_dev *input;
570 | char input_phys[64];
571 | };
572 |
573 | enum uvc_handle_state {
574 | UVC_HANDLE_PASSIVE = 0,
575 | UVC_HANDLE_ACTIVE = 1,
576 | };
577 |
578 | struct uvc_fh {
579 | struct v4l2_fh vfh;
580 | struct uvc_video_chain *chain;
581 | struct uvc_streaming *stream;
582 | enum uvc_handle_state state;
583 | };
584 |
585 | struct uvc_driver {
586 | struct usb_driver driver;
587 | };
588 |
589 | /* ------------------------------------------------------------------------
590 | * Debugging, printing and logging
591 | */
592 |
593 | #define UVC_TRACE_PROBE (1 << 0)
594 | #define UVC_TRACE_DESCR (1 << 1)
595 | #define UVC_TRACE_CONTROL (1 << 2)
596 | #define UVC_TRACE_FORMAT (1 << 3)
597 | #define UVC_TRACE_CAPTURE (1 << 4)
598 | #define UVC_TRACE_CALLS (1 << 5)
599 | #define UVC_TRACE_IOCTL (1 << 6)
600 | #define UVC_TRACE_FRAME (1 << 7)
601 | #define UVC_TRACE_SUSPEND (1 << 8)
602 | #define UVC_TRACE_STATUS (1 << 9)
603 | #define UVC_TRACE_VIDEO (1 << 10)
604 | #define UVC_TRACE_STATS (1 << 11)
605 | #define UVC_TRACE_CLOCK (1 << 12)
606 |
607 | #define UVC_WARN_MINMAX 0
608 | #define UVC_WARN_PROBE_DEF 1
609 | #define UVC_WARN_XU_GET_RES 2
610 |
611 | extern unsigned int uvc_clock_param;
612 | extern unsigned int uvc_no_drop_param;
613 | extern unsigned int uvc_trace_param;
614 | extern unsigned int uvc_timeout_param;
615 |
616 | #define uvc_trace(flag, msg...) \
617 | do { \
618 | if (uvc_trace_param & flag) \
619 | printk(KERN_DEBUG "uvcvideo: " msg); \
620 | } while (0)
621 |
622 | #define uvc_warn_once(dev, warn, msg...) \
623 | do { \
624 | if (!test_and_set_bit(warn, &dev->warnings)) \
625 | printk(KERN_INFO "uvcvideo: " msg); \
626 | } while (0)
627 |
628 | #define uvc_printk(level, msg...) \
629 | printk(level "uvcvideo: " msg)
630 |
631 | /* --------------------------------------------------------------------------
632 | * Internal functions.
633 | */
634 |
635 | /* Core driver */
636 | extern struct uvc_driver uvc_driver;
637 |
638 | extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
639 |
640 | /* Video buffers queue management. */
641 | extern int uvc_queue_init(struct uvc_video_queue *queue,
642 | enum v4l2_buf_type type, int drop_corrupted);
643 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
644 | struct v4l2_requestbuffers *rb);
645 | extern void uvc_free_buffers(struct uvc_video_queue *queue);
646 | extern int uvc_query_buffer(struct uvc_video_queue *queue,
647 | struct v4l2_buffer *v4l2_buf);
648 | extern int uvc_queue_buffer(struct uvc_video_queue *queue,
649 | struct v4l2_buffer *v4l2_buf);
650 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
651 | struct v4l2_buffer *v4l2_buf, int nonblocking);
652 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
653 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
654 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
655 | struct uvc_buffer *buf);
656 | extern int uvc_queue_mmap(struct uvc_video_queue *queue,
657 | struct vm_area_struct *vma);
658 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
659 | struct file *file, poll_table *wait);
660 | #ifndef CONFIG_MMU
661 | extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
662 | unsigned long pgoff);
663 | #endif
664 | extern int uvc_queue_allocated(struct uvc_video_queue *queue);
665 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
666 | {
667 | return vb2_is_streaming(&queue->queue);
668 | }
669 |
670 | /* V4L2 interface */
671 | extern const struct v4l2_file_operations uvc_fops;
672 |
673 | /* Media controller */
674 | extern int uvc_mc_register_entities(struct uvc_video_chain *chain);
675 | extern void uvc_mc_cleanup_entity(struct uvc_entity *entity);
676 |
677 | /* Video */
678 | extern int uvc_video_init(struct uvc_streaming *stream);
679 | extern int uvc_video_suspend(struct uvc_streaming *stream);
680 | extern int uvc_video_resume(struct uvc_streaming *stream, int reset);
681 | extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
682 | extern int uvc_probe_video(struct uvc_streaming *stream,
683 | struct uvc_streaming_control *probe);
684 | extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
685 | __u8 intfnum, __u8 cs, void *data, __u16 size);
686 | void uvc_video_clock_update(struct uvc_streaming *stream,
687 | struct v4l2_buffer *v4l2_buf,
688 | struct uvc_buffer *buf);
689 |
690 | /* Status */
691 | extern int uvc_status_init(struct uvc_device *dev);
692 | extern void uvc_status_cleanup(struct uvc_device *dev);
693 | extern int uvc_status_start(struct uvc_device *dev);
694 | extern void uvc_status_stop(struct uvc_device *dev);
695 | extern int uvc_status_suspend(struct uvc_device *dev);
696 | extern int uvc_status_resume(struct uvc_device *dev);
697 |
698 | /* Controls */
699 | extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;
700 |
701 | extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
702 | struct v4l2_queryctrl *v4l2_ctrl);
703 | extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
704 | struct v4l2_querymenu *query_menu);
705 |
706 | extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
707 | const struct uvc_control_mapping *mapping);
708 | extern int uvc_ctrl_init_device(struct uvc_device *dev);
709 | extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
710 | extern int uvc_ctrl_resume_device(struct uvc_device *dev);
711 |
712 | extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
713 | extern int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
714 | const struct v4l2_ext_control *xctrls,
715 | unsigned int xctrls_count);
716 | static inline int uvc_ctrl_commit(struct uvc_fh *handle,
717 | const struct v4l2_ext_control *xctrls,
718 | unsigned int xctrls_count)
719 | {
720 | return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count);
721 | }
722 | static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
723 | {
724 | return __uvc_ctrl_commit(handle, 1, NULL, 0);
725 | }
726 |
727 | extern int uvc_ctrl_get(struct uvc_video_chain *chain,
728 | struct v4l2_ext_control *xctrl);
729 | extern int uvc_ctrl_set(struct uvc_video_chain *chain,
730 | struct v4l2_ext_control *xctrl);
731 |
732 | extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
733 | struct uvc_xu_control_query *xqry);
734 |
735 | /* Utility functions */
736 | extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
737 | unsigned int n_terms, unsigned int threshold);
738 | extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
739 | uint32_t denominator);
740 | extern struct usb_host_endpoint *uvc_find_endpoint(
741 | struct usb_host_interface *alts, __u8 epaddr);
742 |
743 | /* Quirks support */
744 | void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
745 | struct uvc_buffer *buf);
746 |
747 | /* debugfs and statistics */
748 | int uvc_debugfs_init(void);
749 | void uvc_debugfs_cleanup(void);
750 | int uvc_debugfs_init_stream(struct uvc_streaming *stream);
751 | void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream);
752 |
753 | size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf,
754 | size_t size);
755 |
756 | #endif
757 |
--------------------------------------------------------------------------------
/UVCKernelPatches/Patched Files/videodev2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Video for Linux Two header file
3 | *
4 | * Copyright (C) 1999-2012 the contributors
5 | *
6 | * This program is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation; either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * Alternatively you can redistribute this file under the terms of the
17 | * BSD license as stated below:
18 | *
19 | * Redistribution and use in source and binary forms, with or without
20 | * modification, are permitted provided that the following conditions
21 | * are met:
22 | * 1. Redistributions of source code must retain the above copyright
23 | * notice, this list of conditions and the following disclaimer.
24 | * 2. Redistributions in binary form must reproduce the above copyright
25 | * notice, this list of conditions and the following disclaimer in
26 | * the documentation and/or other materials provided with the
27 | * distribution.
28 | * 3. The names of its contributors may not be used to endorse or promote
29 | * products derived from this software without specific prior written
30 | * permission.
31 | *
32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
38 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 | *
44 | * Header file for v4l or V4L2 drivers and applications
45 | * with public API.
46 | * All kernel-specific stuff were moved to media/v4l2-dev.h, so
47 | * no #if __KERNEL tests are allowed here
48 | *
49 | * See http://linuxtv.org for more info
50 | *
51 | * Author: Bill Dirks
52 | * Justin Schoeman
53 | * Hans Verkuil
54 | * et al.
55 | */
56 | #ifndef _UAPI__LINUX_VIDEODEV2_H
57 | #define _UAPI__LINUX_VIDEODEV2_H
58 |
59 | #ifndef __KERNEL__
60 | #include
61 | #endif
62 | #include
63 | #include
64 | #include
65 | #include
66 | #include
67 |
68 | /*
69 | * Common stuff for both V4L1 and V4L2
70 | * Moved from videodev.h
71 | */
72 | #define VIDEO_MAX_FRAME 32
73 | #define VIDEO_MAX_PLANES 8
74 |
75 | /*
76 | * M I S C E L L A N E O U S
77 | */
78 |
79 | /* Four-character-code (FOURCC) */
80 | #define v4l2_fourcc(a, b, c, d)\
81 | ((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))
82 |
83 | /*
84 | * E N U M S
85 | */
86 | enum v4l2_field {
87 | V4L2_FIELD_ANY = 0, /* driver can choose from none,
88 | top, bottom, interlaced
89 | depending on whatever it thinks
90 | is approximate ... */
91 | V4L2_FIELD_NONE = 1, /* this device has no fields ... */
92 | V4L2_FIELD_TOP = 2, /* top field only */
93 | V4L2_FIELD_BOTTOM = 3, /* bottom field only */
94 | V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */
95 | V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one
96 | buffer, top-bottom order */
97 | V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */
98 | V4L2_FIELD_ALTERNATE = 7, /* both fields alternating into
99 | separate buffers */
100 | V4L2_FIELD_INTERLACED_TB = 8, /* both fields interlaced, top field
101 | first and the top field is
102 | transmitted first */
103 | V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top field
104 | first and the bottom field is
105 | transmitted first */
106 | };
107 | #define V4L2_FIELD_HAS_TOP(field) \
108 | ((field) == V4L2_FIELD_TOP ||\
109 | (field) == V4L2_FIELD_INTERLACED ||\
110 | (field) == V4L2_FIELD_INTERLACED_TB ||\
111 | (field) == V4L2_FIELD_INTERLACED_BT ||\
112 | (field) == V4L2_FIELD_SEQ_TB ||\
113 | (field) == V4L2_FIELD_SEQ_BT)
114 | #define V4L2_FIELD_HAS_BOTTOM(field) \
115 | ((field) == V4L2_FIELD_BOTTOM ||\
116 | (field) == V4L2_FIELD_INTERLACED ||\
117 | (field) == V4L2_FIELD_INTERLACED_TB ||\
118 | (field) == V4L2_FIELD_INTERLACED_BT ||\
119 | (field) == V4L2_FIELD_SEQ_TB ||\
120 | (field) == V4L2_FIELD_SEQ_BT)
121 | #define V4L2_FIELD_HAS_BOTH(field) \
122 | ((field) == V4L2_FIELD_INTERLACED ||\
123 | (field) == V4L2_FIELD_INTERLACED_TB ||\
124 | (field) == V4L2_FIELD_INTERLACED_BT ||\
125 | (field) == V4L2_FIELD_SEQ_TB ||\
126 | (field) == V4L2_FIELD_SEQ_BT)
127 |
128 | enum v4l2_buf_type {
129 | V4L2_BUF_TYPE_VIDEO_CAPTURE = 1,
130 | V4L2_BUF_TYPE_VIDEO_OUTPUT = 2,
131 | V4L2_BUF_TYPE_VIDEO_OVERLAY = 3,
132 | V4L2_BUF_TYPE_VBI_CAPTURE = 4,
133 | V4L2_BUF_TYPE_VBI_OUTPUT = 5,
134 | V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6,
135 | V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7,
136 | #if 1
137 | /* Experimental */
138 | V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8,
139 | #endif
140 | V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9,
141 | V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = 10,
142 | /* Deprecated, do not use */
143 | V4L2_BUF_TYPE_PRIVATE = 0x80,
144 | };
145 |
146 | #define V4L2_TYPE_IS_MULTIPLANAR(type) \
147 | ((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE \
148 | || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
149 |
150 | #define V4L2_TYPE_IS_OUTPUT(type) \
151 | ((type) == V4L2_BUF_TYPE_VIDEO_OUTPUT \
152 | || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE \
153 | || (type) == V4L2_BUF_TYPE_VIDEO_OVERLAY \
154 | || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY \
155 | || (type) == V4L2_BUF_TYPE_VBI_OUTPUT \
156 | || (type) == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT)
157 |
158 | enum v4l2_tuner_type {
159 | V4L2_TUNER_RADIO = 1,
160 | V4L2_TUNER_ANALOG_TV = 2,
161 | V4L2_TUNER_DIGITAL_TV = 3,
162 | };
163 |
164 | enum v4l2_memory {
165 | V4L2_MEMORY_MMAP = 1,
166 | V4L2_MEMORY_USERPTR = 2,
167 | V4L2_MEMORY_OVERLAY = 3,
168 | V4L2_MEMORY_DMABUF = 4,
169 | };
170 |
171 | /* see also http://vektor.theorem.ca/graphics/ycbcr/ */
172 | enum v4l2_colorspace {
173 | /* ITU-R 601 -- broadcast NTSC/PAL */
174 | V4L2_COLORSPACE_SMPTE170M = 1,
175 |
176 | /* 1125-Line (US) HDTV */
177 | V4L2_COLORSPACE_SMPTE240M = 2,
178 |
179 | /* HD and modern captures. */
180 | V4L2_COLORSPACE_REC709 = 3,
181 |
182 | /* broken BT878 extents (601, luma range 16-253 instead of 16-235) */
183 | V4L2_COLORSPACE_BT878 = 4,
184 |
185 | /* These should be useful. Assume 601 extents. */
186 | V4L2_COLORSPACE_470_SYSTEM_M = 5,
187 | V4L2_COLORSPACE_470_SYSTEM_BG = 6,
188 |
189 | /* I know there will be cameras that send this. So, this is
190 | * unspecified chromaticities and full 0-255 on each of the
191 | * Y'CbCr components
192 | */
193 | V4L2_COLORSPACE_JPEG = 7,
194 |
195 | /* For RGB colourspaces, this is probably a good start. */
196 | V4L2_COLORSPACE_SRGB = 8,
197 | };
198 |
199 | enum v4l2_priority {
200 | V4L2_PRIORITY_UNSET = 0, /* not initialized */
201 | V4L2_PRIORITY_BACKGROUND = 1,
202 | V4L2_PRIORITY_INTERACTIVE = 2,
203 | V4L2_PRIORITY_RECORD = 3,
204 | V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE,
205 | };
206 |
207 | struct v4l2_rect {
208 | __s32 left;
209 | __s32 top;
210 | __s32 width;
211 | __s32 height;
212 | };
213 |
214 | struct v4l2_fract {
215 | __u32 numerator;
216 | __u32 denominator;
217 | };
218 |
219 | /**
220 | * struct v4l2_capability - Describes V4L2 device caps returned by VIDIOC_QUERYCAP
221 | *
222 | * @driver: name of the driver module (e.g. "bttv")
223 | * @card: name of the card (e.g. "Hauppauge WinTV")
224 | * @bus_info: name of the bus (e.g. "PCI:" + pci_name(pci_dev) )
225 | * @version: KERNEL_VERSION
226 | * @capabilities: capabilities of the physical device as a whole
227 | * @device_caps: capabilities accessed via this particular device (node)
228 | * @reserved: reserved fields for future extensions
229 | */
230 | struct v4l2_capability {
231 | __u8 driver[16];
232 | __u8 card[32];
233 | __u8 bus_info[32];
234 | __u32 version;
235 | __u32 capabilities;
236 | __u32 device_caps;
237 | __u32 reserved[3];
238 | };
239 |
240 | /* Values for 'capabilities' field */
241 | #define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */
242 | #define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */
243 | #define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */
244 | #define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */
245 | #define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */
246 | #define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */
247 | #define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */
248 | #define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */
249 | #define V4L2_CAP_VIDEO_OUTPUT_OVERLAY 0x00000200 /* Can do video output overlay */
250 | #define V4L2_CAP_HW_FREQ_SEEK 0x00000400 /* Can do hardware frequency seek */
251 | #define V4L2_CAP_RDS_OUTPUT 0x00000800 /* Is an RDS encoder */
252 |
253 | /* Is a video capture device that supports multiplanar formats */
254 | #define V4L2_CAP_VIDEO_CAPTURE_MPLANE 0x00001000
255 | /* Is a video output device that supports multiplanar formats */
256 | #define V4L2_CAP_VIDEO_OUTPUT_MPLANE 0x00002000
257 | /* Is a video mem-to-mem device that supports multiplanar formats */
258 | #define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000
259 | /* Is a video mem-to-mem device */
260 | #define V4L2_CAP_VIDEO_M2M 0x00008000
261 |
262 | #define V4L2_CAP_TUNER 0x00010000 /* has a tuner */
263 | #define V4L2_CAP_AUDIO 0x00020000 /* has audio support */
264 | #define V4L2_CAP_RADIO 0x00040000 /* is a radio device */
265 | #define V4L2_CAP_MODULATOR 0x00080000 /* has a modulator */
266 |
267 | #define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */
268 | #define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */
269 | #define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */
270 |
271 | #define V4L2_CAP_DEVICE_CAPS 0x80000000 /* sets device capabilities field */
272 |
273 | /*
274 | * V I D E O I M A G E F O R M A T
275 | */
276 | struct v4l2_pix_format {
277 | __u32 width;
278 | __u32 height;
279 | __u32 pixelformat;
280 | __u32 field; /* enum v4l2_field */
281 | __u32 bytesperline; /* for padding, zero if unused */
282 | __u32 sizeimage;
283 | __u32 colorspace; /* enum v4l2_colorspace */
284 | __u32 priv; /* private data, depends on pixelformat */
285 | };
286 |
287 | /* Pixel format FOURCC depth Description */
288 |
289 | /* RGB formats */
290 | #define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R', 'G', 'B', '1') /* 8 RGB-3-3-2 */
291 | #define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R', '4', '4', '4') /* 16 xxxxrrrr ggggbbbb */
292 | #define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R', 'G', 'B', 'O') /* 16 RGB-5-5-5 */
293 | #define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
294 | #define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R', 'G', 'B', 'Q') /* 16 RGB-5-5-5 BE */
295 | #define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R', 'G', 'B', 'R') /* 16 RGB-5-6-5 BE */
296 | #define V4L2_PIX_FMT_BGR666 v4l2_fourcc('B', 'G', 'R', 'H') /* 18 BGR-6-6-6 */
297 | #define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */
298 | #define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */
299 | #define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */
300 | #define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */
301 |
302 | /* Grey formats */
303 | #define V4L2_PIX_FMT_GREY v4l2_fourcc('G', 'R', 'E', 'Y') /* 8 Greyscale */
304 | #define V4L2_PIX_FMT_Y4 v4l2_fourcc('Y', '0', '4', ' ') /* 4 Greyscale */
305 | #define V4L2_PIX_FMT_Y6 v4l2_fourcc('Y', '0', '6', ' ') /* 6 Greyscale */
306 | #define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */
307 | #define V4L2_PIX_FMT_Y12 v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */
308 | #define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */
309 |
310 | /* Grey bit-packed formats */
311 | #define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */
312 |
313 | /* Palette formats */
314 | #define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */
315 |
316 | /* Chrominance formats */
317 | #define V4L2_PIX_FMT_UV8 v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */
318 |
319 | /* Luminance+Chrominance formats */
320 | #define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */
321 | #define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */
322 | #define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */
323 | #define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */
324 | #define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */
325 | #define V4L2_PIX_FMT_UYVY v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */
326 | #define V4L2_PIX_FMT_VYUY v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */
327 | #define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4', '2', '2', 'P') /* 16 YVU422 planar */
328 | #define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4', '1', '1', 'P') /* 16 YVU411 planar */
329 | #define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y', '4', '1', 'P') /* 12 YUV 4:1:1 */
330 | #define V4L2_PIX_FMT_YUV444 v4l2_fourcc('Y', '4', '4', '4') /* 16 xxxxyyyy uuuuvvvv */
331 | #define V4L2_PIX_FMT_YUV555 v4l2_fourcc('Y', 'U', 'V', 'O') /* 16 YUV-5-5-5 */
332 | #define V4L2_PIX_FMT_YUV565 v4l2_fourcc('Y', 'U', 'V', 'P') /* 16 YUV-5-6-5 */
333 | #define V4L2_PIX_FMT_YUV32 v4l2_fourcc('Y', 'U', 'V', '4') /* 32 YUV-8-8-8-8 */
334 | #define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y', 'U', 'V', '9') /* 9 YUV 4:1:0 */
335 | #define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */
336 | #define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* 8 8-bit color */
337 | #define V4L2_PIX_FMT_HM12 v4l2_fourcc('H', 'M', '1', '2') /* 8 YUV 4:2:0 16x16 macroblocks */
338 | #define V4L2_PIX_FMT_M420 v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */
339 |
340 | /* two planes -- one Y, one Cr + Cb interleaved */
341 | #define V4L2_PIX_FMT_NV12 v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */
342 | #define V4L2_PIX_FMT_NV21 v4l2_fourcc('N', 'V', '2', '1') /* 12 Y/CrCb 4:2:0 */
343 | #define V4L2_PIX_FMT_NV16 v4l2_fourcc('N', 'V', '1', '6') /* 16 Y/CbCr 4:2:2 */
344 | #define V4L2_PIX_FMT_NV61 v4l2_fourcc('N', 'V', '6', '1') /* 16 Y/CrCb 4:2:2 */
345 | #define V4L2_PIX_FMT_NV24 v4l2_fourcc('N', 'V', '2', '4') /* 24 Y/CbCr 4:4:4 */
346 | #define V4L2_PIX_FMT_NV42 v4l2_fourcc('N', 'V', '4', '2') /* 24 Y/CrCb 4:4:4 */
347 |
348 | /* two non contiguous planes - one Y, one Cr + Cb interleaved */
349 | #define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 */
350 | #define V4L2_PIX_FMT_NV21M v4l2_fourcc('N', 'M', '2', '1') /* 21 Y/CrCb 4:2:0 */
351 | #define V4L2_PIX_FMT_NV12MT v4l2_fourcc('T', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 64x32 macroblocks */
352 | #define V4L2_PIX_FMT_NV12MT_16X16 v4l2_fourcc('V', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 macroblocks */
353 |
354 | /* three non contiguous planes - Y, Cb, Cr */
355 | #define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2') /* 12 YUV420 planar */
356 | #define V4L2_PIX_FMT_YVU420M v4l2_fourcc('Y', 'M', '2', '1') /* 12 YVU420 planar */
357 |
358 | /* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
359 | #define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B', 'A', '8', '1') /* 8 BGBG.. GRGR.. */
360 | #define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
361 | #define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
362 | #define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
363 | #define V4L2_PIX_FMT_SBGGR10 v4l2_fourcc('B', 'G', '1', '0') /* 10 BGBG.. GRGR.. */
364 | #define V4L2_PIX_FMT_SGBRG10 v4l2_fourcc('G', 'B', '1', '0') /* 10 GBGB.. RGRG.. */
365 | #define V4L2_PIX_FMT_SGRBG10 v4l2_fourcc('B', 'A', '1', '0') /* 10 GRGR.. BGBG.. */
366 | #define V4L2_PIX_FMT_SRGGB10 v4l2_fourcc('R', 'G', '1', '0') /* 10 RGRG.. GBGB.. */
367 | #define V4L2_PIX_FMT_SBGGR12 v4l2_fourcc('B', 'G', '1', '2') /* 12 BGBG.. GRGR.. */
368 | #define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */
369 | #define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */
370 | #define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */
371 | /* 10bit raw bayer a-law compressed to 8 bits */
372 | #define V4L2_PIX_FMT_SBGGR10ALAW8 v4l2_fourcc('a', 'B', 'A', '8')
373 | #define V4L2_PIX_FMT_SGBRG10ALAW8 v4l2_fourcc('a', 'G', 'A', '8')
374 | #define V4L2_PIX_FMT_SGRBG10ALAW8 v4l2_fourcc('a', 'g', 'A', '8')
375 | #define V4L2_PIX_FMT_SRGGB10ALAW8 v4l2_fourcc('a', 'R', 'A', '8')
376 | /* 10bit raw bayer DPCM compressed to 8 bits */
377 | #define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8')
378 | #define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8')
379 | #define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0')
380 | #define V4L2_PIX_FMT_SRGGB10DPCM8 v4l2_fourcc('b', 'R', 'A', '8')
381 | /*
382 | * 10bit raw bayer, expanded to 16 bits
383 | * xxxxrrrrrrrrrrxxxxgggggggggg xxxxggggggggggxxxxbbbbbbbbbb...
384 | */
385 | #define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') /* 16 BGBG.. GRGR.. */
386 |
387 | /* compressed formats */
388 | #define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */
389 | #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG */
390 | #define V4L2_PIX_FMT_DV v4l2_fourcc('d', 'v', 's', 'd') /* 1394 */
391 | #define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */
392 | #define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
393 | #define V4L2_PIX_FMT_H264_NO_SC v4l2_fourcc('A', 'V', 'C', '1') /* H264 without start codes */
394 | #define V4L2_PIX_FMT_H264_MVC v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */
395 | #define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3') /* H263 */
396 | #define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */
397 | #define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */
398 | #define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 ES */
399 | #define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */
400 | #define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */
401 | #define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */
402 | #define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
403 |
404 | /* Intel RealSense-specific formats */
405 | #define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */
406 | #define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */
407 | #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */
408 | #define V4L2_PIX_FMT_RW10 v4l2_fourcc('R', 'W', '1', '0') /* Raw data 10-bit */
409 | #define V4L2_PIX_FMT_INVZ v4l2_fourcc('I', 'N', 'V', 'Z') /* 16 Depth */
410 | #define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I') /* 24 Depth/IR 16:8 */
411 | #define V4L2_PIX_FMT_INVR v4l2_fourcc('I', 'N', 'V', 'R') /* 16 Depth */
412 | #define V4L2_PIX_FMT_INRI v4l2_fourcc('I', 'N', 'R', 'I') /* 24 Depth/IR 16:8 */
413 | #define V4L2_PIX_FMT_INVI v4l2_fourcc('I', 'N', 'V', 'I') /* 8 IR */
414 | #define V4L2_PIX_FMT_RELI v4l2_fourcc('R', 'E', 'L', 'I') /* 8 IR alternating on off illumination */
415 |
416 | /* Vendor-specific formats */
417 | #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
418 | #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */
419 | #define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */
420 | #define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */
421 | #define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */
422 | #define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */
423 | #define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */
424 | #define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */
425 | #define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */
426 | #define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */
427 | #define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */
428 | #define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */
429 | #define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */
430 | #define V4L2_PIX_FMT_JL2005BCD v4l2_fourcc('J', 'L', '2', '0') /* compressed RGGB bayer */
431 | #define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */
432 | #define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */
433 | #define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */
434 | #define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */
435 | #define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
436 | #define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */
437 | #define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */
438 | #define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */
439 | #define V4L2_PIX_FMT_KONICA420 v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */
440 | #define V4L2_PIX_FMT_JPGL v4l2_fourcc('J', 'P', 'G', 'L') /* JPEG-Lite */
441 | #define V4L2_PIX_FMT_SE401 v4l2_fourcc('S', '4', '0', '1') /* se401 janggu compressed rgb */
442 | #define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */
443 |
444 | /*
445 | * F O R M A T E N U M E R A T I O N
446 | */
447 | struct v4l2_fmtdesc {
448 | __u32 index; /* Format number */
449 | __u32 type; /* enum v4l2_buf_type */
450 | __u32 flags;
451 | __u8 description[32]; /* Description string */
452 | __u32 pixelformat; /* Format fourcc */
453 | __u32 reserved[4];
454 | };
455 |
456 | #define V4L2_FMT_FLAG_COMPRESSED 0x0001
457 | #define V4L2_FMT_FLAG_EMULATED 0x0002
458 |
459 | #if 1
460 | /* Experimental Frame Size and frame rate enumeration */
461 | /*
462 | * F R A M E S I Z E E N U M E R A T I O N
463 | */
464 | enum v4l2_frmsizetypes {
465 | V4L2_FRMSIZE_TYPE_DISCRETE = 1,
466 | V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,
467 | V4L2_FRMSIZE_TYPE_STEPWISE = 3,
468 | };
469 |
470 | struct v4l2_frmsize_discrete {
471 | __u32 width; /* Frame width [pixel] */
472 | __u32 height; /* Frame height [pixel] */
473 | };
474 |
475 | struct v4l2_frmsize_stepwise {
476 | __u32 min_width; /* Minimum frame width [pixel] */
477 | __u32 max_width; /* Maximum frame width [pixel] */
478 | __u32 step_width; /* Frame width step size [pixel] */
479 | __u32 min_height; /* Minimum frame height [pixel] */
480 | __u32 max_height; /* Maximum frame height [pixel] */
481 | __u32 step_height; /* Frame height step size [pixel] */
482 | };
483 |
484 | struct v4l2_frmsizeenum {
485 | __u32 index; /* Frame size number */
486 | __u32 pixel_format; /* Pixel format */
487 | __u32 type; /* Frame size type the device supports. */
488 |
489 | union { /* Frame size */
490 | struct v4l2_frmsize_discrete discrete;
491 | struct v4l2_frmsize_stepwise stepwise;
492 | };
493 |
494 | __u32 reserved[2]; /* Reserved space for future use */
495 | };
496 |
497 | /*
498 | * F R A M E R A T E E N U M E R A T I O N
499 | */
500 | enum v4l2_frmivaltypes {
501 | V4L2_FRMIVAL_TYPE_DISCRETE = 1,
502 | V4L2_FRMIVAL_TYPE_CONTINUOUS = 2,
503 | V4L2_FRMIVAL_TYPE_STEPWISE = 3,
504 | };
505 |
506 | struct v4l2_frmival_stepwise {
507 | struct v4l2_fract min; /* Minimum frame interval [s] */
508 | struct v4l2_fract max; /* Maximum frame interval [s] */
509 | struct v4l2_fract step; /* Frame interval step size [s] */
510 | };
511 |
512 | struct v4l2_frmivalenum {
513 | __u32 index; /* Frame format index */
514 | __u32 pixel_format; /* Pixel format */
515 | __u32 width; /* Frame width */
516 | __u32 height; /* Frame height */
517 | __u32 type; /* Frame interval type the device supports. */
518 |
519 | union { /* Frame interval */
520 | struct v4l2_fract discrete;
521 | struct v4l2_frmival_stepwise stepwise;
522 | };
523 |
524 | __u32 reserved[2]; /* Reserved space for future use */
525 | };
526 | #endif
527 |
528 | /*
529 | * T I M E C O D E
530 | */
531 | struct v4l2_timecode {
532 | __u32 type;
533 | __u32 flags;
534 | __u8 frames;
535 | __u8 seconds;
536 | __u8 minutes;
537 | __u8 hours;
538 | __u8 userbits[4];
539 | };
540 |
541 | /* Type */
542 | #define V4L2_TC_TYPE_24FPS 1
543 | #define V4L2_TC_TYPE_25FPS 2
544 | #define V4L2_TC_TYPE_30FPS 3
545 | #define V4L2_TC_TYPE_50FPS 4
546 | #define V4L2_TC_TYPE_60FPS 5
547 |
548 | /* Flags */
549 | #define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */
550 | #define V4L2_TC_FLAG_COLORFRAME 0x0002
551 | #define V4L2_TC_USERBITS_field 0x000C
552 | #define V4L2_TC_USERBITS_USERDEFINED 0x0000
553 | #define V4L2_TC_USERBITS_8BITCHARS 0x0008
554 | /* The above is based on SMPTE timecodes */
555 |
556 | struct v4l2_jpegcompression {
557 | int quality;
558 |
559 | int APPn; /* Number of APP segment to be written,
560 | * must be 0..15 */
561 | int APP_len; /* Length of data in JPEG APPn segment */
562 | char APP_data[60]; /* Data in the JPEG APPn segment. */
563 |
564 | int COM_len; /* Length of data in JPEG COM segment */
565 | char COM_data[60]; /* Data in JPEG COM segment */
566 |
567 | __u32 jpeg_markers; /* Which markers should go into the JPEG
568 | * output. Unless you exactly know what
569 | * you do, leave them untouched.
570 | * Inluding less markers will make the
571 | * resulting code smaller, but there will
572 | * be fewer applications which can read it.
573 | * The presence of the APP and COM marker
574 | * is influenced by APP_len and COM_len
575 | * ONLY, not by this property! */
576 |
577 | #define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
578 | #define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
579 | #define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
580 | #define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */
581 | #define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will
582 | * allways use APP0 */
583 | };
584 |
585 | /*
586 | * M E M O R Y - M A P P I N G B U F F E R S
587 | */
588 | struct v4l2_requestbuffers {
589 | __u32 count;
590 | __u32 type; /* enum v4l2_buf_type */
591 | __u32 memory; /* enum v4l2_memory */
592 | __u32 reserved[2];
593 | };
594 |
595 | /**
596 | * struct v4l2_plane - plane info for multi-planar buffers
597 | * @bytesused: number of bytes occupied by data in the plane (payload)
598 | * @length: size of this plane (NOT the payload) in bytes
599 | * @mem_offset: when memory in the associated struct v4l2_buffer is
600 | * V4L2_MEMORY_MMAP, equals the offset from the start of
601 | * the device memory for this plane (or is a "cookie" that
602 | * should be passed to mmap() called on the video node)
603 | * @userptr: when memory is V4L2_MEMORY_USERPTR, a userspace pointer
604 | * pointing to this plane
605 | * @fd: when memory is V4L2_MEMORY_DMABUF, a userspace file
606 | * descriptor associated with this plane
607 | * @data_offset: offset in the plane to the start of data; usually 0,
608 | * unless there is a header in front of the data
609 | *
610 | * Multi-planar buffers consist of one or more planes, e.g. an YCbCr buffer
611 | * with two planes can have one plane for Y, and another for interleaved CbCr
612 | * components. Each plane can reside in a separate memory buffer, or even in
613 | * a completely separate memory node (e.g. in embedded devices).
614 | */
615 | struct v4l2_plane {
616 | __u32 bytesused;
617 | __u32 length;
618 | union {
619 | __u32 mem_offset;
620 | unsigned long userptr;
621 | __s32 fd;
622 | } m;
623 | __u32 data_offset;
624 | __u32 reserved[11];
625 | };
626 |
627 | /**
628 | * struct v4l2_buffer - video buffer info
629 | * @index: id number of the buffer
630 | * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for
631 | * multiplanar buffers);
632 | * @bytesused: number of bytes occupied by data in the buffer (payload);
633 | * unused (set to 0) for multiplanar buffers
634 | * @flags: buffer informational flags
635 | * @field: enum v4l2_field; field order of the image in the buffer
636 | * @timestamp: frame timestamp
637 | * @timecode: frame timecode
638 | * @sequence: sequence count of this frame
639 | * @memory: enum v4l2_memory; the method, in which the actual video data is
640 | * passed
641 | * @offset: for non-multiplanar buffers with memory == V4L2_MEMORY_MMAP;
642 | * offset from the start of the device memory for this plane,
643 | * (or a "cookie" that should be passed to mmap() as offset)
644 | * @userptr: for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR;
645 | * a userspace pointer pointing to this buffer
646 | * @fd: for non-multiplanar buffers with memory == V4L2_MEMORY_DMABUF;
647 | * a userspace file descriptor associated with this buffer
648 | * @planes: for multiplanar buffers; userspace pointer to the array of plane
649 | * info structs for this buffer
650 | * @length: size in bytes of the buffer (NOT its payload) for single-plane
651 | * buffers (when type != *_MPLANE); number of elements in the
652 | * planes array for multi-plane buffers
653 | * @input: input number from which the video data has has been captured
654 | *
655 | * Contains data exchanged by application and driver using one of the Streaming
656 | * I/O methods.
657 | */
658 | struct v4l2_buffer {
659 | __u32 index;
660 | __u32 type;
661 | __u32 bytesused;
662 | __u32 flags;
663 | __u32 field;
664 | struct timeval timestamp;
665 | struct v4l2_timecode timecode;
666 | __u32 sequence;
667 |
668 | /* memory location */
669 | __u32 memory;
670 | union {
671 | __u32 offset;
672 | unsigned long userptr;
673 | struct v4l2_plane *planes;
674 | __s32 fd;
675 | } m;
676 | __u32 length;
677 | __u32 reserved2;
678 | __u32 reserved;
679 | };
680 |
681 | /* Flags for 'flags' field */
682 | #define V4L2_BUF_FLAG_MAPPED 0x0001 /* Buffer is mapped (flag) */
683 | #define V4L2_BUF_FLAG_QUEUED 0x0002 /* Buffer is queued for processing */
684 | #define V4L2_BUF_FLAG_DONE 0x0004 /* Buffer is ready */
685 | #define V4L2_BUF_FLAG_KEYFRAME 0x0008 /* Image is a keyframe (I-frame) */
686 | #define V4L2_BUF_FLAG_PFRAME 0x0010 /* Image is a P-frame */
687 | #define V4L2_BUF_FLAG_BFRAME 0x0020 /* Image is a B-frame */
688 | /* Buffer is ready, but the data contained within is corrupted. */
689 | #define V4L2_BUF_FLAG_ERROR 0x0040
690 | #define V4L2_BUF_FLAG_TIMECODE 0x0100 /* timecode field is valid */
691 | #define V4L2_BUF_FLAG_PREPARED 0x0400 /* Buffer is prepared for queuing */
692 | /* Cache handling flags */
693 | #define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x0800
694 | #define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x1000
695 | /* Timestamp type */
696 | #define V4L2_BUF_FLAG_TIMESTAMP_MASK 0xe000
697 | #define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN 0x0000
698 | #define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 0x2000
699 | #define V4L2_BUF_FLAG_TIMESTAMP_COPY 0x4000
700 |
701 | /**
702 | * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor
703 | *
704 | * @index: id number of the buffer
705 | * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for
706 | * multiplanar buffers);
707 | * @plane: index of the plane to be exported, 0 for single plane queues
708 | * @flags: flags for newly created file, currently only O_CLOEXEC is
709 | * supported, refer to manual of open syscall for more details
710 | * @fd: file descriptor associated with DMABUF (set by driver)
711 | *
712 | * Contains data used for exporting a video buffer as DMABUF file descriptor.
713 | * The buffer is identified by a 'cookie' returned by VIDIOC_QUERYBUF
714 | * (identical to the cookie used to mmap() the buffer to userspace). All
715 | * reserved fields must be set to zero. The field reserved0 is expected to
716 | * become a structure 'type' allowing an alternative layout of the structure
717 | * content. Therefore this field should not be used for any other extensions.
718 | */
719 | struct v4l2_exportbuffer {
720 | __u32 type; /* enum v4l2_buf_type */
721 | __u32 index;
722 | __u32 plane;
723 | __u32 flags;
724 | __s32 fd;
725 | __u32 reserved[11];
726 | };
727 |
728 | /*
729 | * O V E R L A Y P R E V I E W
730 | */
731 | struct v4l2_framebuffer {
732 | __u32 capability;
733 | __u32 flags;
734 | /* FIXME: in theory we should pass something like PCI device + memory
735 | * region + offset instead of some physical address */
736 | void *base;
737 | struct v4l2_pix_format fmt;
738 | };
739 | /* Flags for the 'capability' field. Read only */
740 | #define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001
741 | #define V4L2_FBUF_CAP_CHROMAKEY 0x0002
742 | #define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004
743 | #define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008
744 | #define V4L2_FBUF_CAP_LOCAL_ALPHA 0x0010
745 | #define V4L2_FBUF_CAP_GLOBAL_ALPHA 0x0020
746 | #define V4L2_FBUF_CAP_LOCAL_INV_ALPHA 0x0040
747 | #define V4L2_FBUF_CAP_SRC_CHROMAKEY 0x0080
748 | /* Flags for the 'flags' field. */
749 | #define V4L2_FBUF_FLAG_PRIMARY 0x0001
750 | #define V4L2_FBUF_FLAG_OVERLAY 0x0002
751 | #define V4L2_FBUF_FLAG_CHROMAKEY 0x0004
752 | #define V4L2_FBUF_FLAG_LOCAL_ALPHA 0x0008
753 | #define V4L2_FBUF_FLAG_GLOBAL_ALPHA 0x0010
754 | #define V4L2_FBUF_FLAG_LOCAL_INV_ALPHA 0x0020
755 | #define V4L2_FBUF_FLAG_SRC_CHROMAKEY 0x0040
756 |
757 | struct v4l2_clip {
758 | struct v4l2_rect c;
759 | struct v4l2_clip __user *next;
760 | };
761 |
762 | struct v4l2_window {
763 | struct v4l2_rect w;
764 | __u32 field; /* enum v4l2_field */
765 | __u32 chromakey;
766 | struct v4l2_clip __user *clips;
767 | __u32 clipcount;
768 | void __user *bitmap;
769 | __u8 global_alpha;
770 | };
771 |
772 | /*
773 | * C A P T U R E P A R A M E T E R S
774 | */
775 | struct v4l2_captureparm {
776 | __u32 capability; /* Supported modes */
777 | __u32 capturemode; /* Current mode */
778 | struct v4l2_fract timeperframe; /* Time per frame in seconds */
779 | __u32 extendedmode; /* Driver-specific extensions */
780 | __u32 readbuffers; /* # of buffers for read */
781 | __u32 reserved[4];
782 | };
783 |
784 | /* Flags for 'capability' and 'capturemode' fields */
785 | #define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */
786 | #define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */
787 |
788 | struct v4l2_outputparm {
789 | __u32 capability; /* Supported modes */
790 | __u32 outputmode; /* Current mode */
791 | struct v4l2_fract timeperframe; /* Time per frame in seconds */
792 | __u32 extendedmode; /* Driver-specific extensions */
793 | __u32 writebuffers; /* # of buffers for write */
794 | __u32 reserved[4];
795 | };
796 |
797 | /*
798 | * I N P U T I M A G E C R O P P I N G
799 | */
800 | struct v4l2_cropcap {
801 | __u32 type; /* enum v4l2_buf_type */
802 | struct v4l2_rect bounds;
803 | struct v4l2_rect defrect;
804 | struct v4l2_fract pixelaspect;
805 | };
806 |
807 | struct v4l2_crop {
808 | __u32 type; /* enum v4l2_buf_type */
809 | struct v4l2_rect c;
810 | };
811 |
812 | /**
813 | * struct v4l2_selection - selection info
814 | * @type: buffer type (do not use *_MPLANE types)
815 | * @target: Selection target, used to choose one of possible rectangles;
816 | * defined in v4l2-common.h; V4L2_SEL_TGT_* .
817 | * @flags: constraints flags, defined in v4l2-common.h; V4L2_SEL_FLAG_*.
818 | * @r: coordinates of selection window
819 | * @reserved: for future use, rounds structure size to 64 bytes, set to zero
820 | *
821 | * Hardware may use multiple helper windows to process a video stream.
822 | * The structure is used to exchange this selection areas between
823 | * an application and a driver.
824 | */
825 | struct v4l2_selection {
826 | __u32 type;
827 | __u32 target;
828 | __u32 flags;
829 | struct v4l2_rect r;
830 | __u32 reserved[9];
831 | };
832 |
833 |
834 | /*
835 | * A N A L O G V I D E O S T A N D A R D
836 | */
837 |
838 | typedef __u64 v4l2_std_id;
839 |
840 | /* one bit for each */
841 | #define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001)
842 | #define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002)
843 | #define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004)
844 | #define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008)
845 | #define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010)
846 | #define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020)
847 | #define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040)
848 | #define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080)
849 |
850 | #define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100)
851 | #define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200)
852 | #define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400)
853 | #define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800)
854 |
855 | #define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) /* BTSC */
856 | #define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) /* EIA-J */
857 | #define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000)
858 | #define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000) /* FM A2 */
859 |
860 | #define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000)
861 | #define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000)
862 | #define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000)
863 | #define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000)
864 | #define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000)
865 | #define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000)
866 | #define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000)
867 | #define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000)
868 |
869 | /* ATSC/HDTV */
870 | #define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000)
871 | #define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000)
872 |
873 | /* FIXME:
874 | Although std_id is 64 bits, there is an issue on PPC32 architecture that
875 | makes switch(__u64) to break. So, there's a hack on v4l2-common.c rounding
876 | this value to 32 bits.
877 | As, currently, the max value is for V4L2_STD_ATSC_16_VSB (30 bits wide),
878 | it should work fine. However, if needed to add more than two standards,
879 | v4l2-common.c should be fixed.
880 | */
881 |
882 | /*
883 | * Some macros to merge video standards in order to make live easier for the
884 | * drivers and V4L2 applications
885 | */
886 |
887 | /*
888 | * "Common" NTSC/M - It should be noticed that V4L2_STD_NTSC_443 is
889 | * Missing here.
890 | */
891 | #define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\
892 | V4L2_STD_NTSC_M_JP |\
893 | V4L2_STD_NTSC_M_KR)
894 | /* Secam macros */
895 | #define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\
896 | V4L2_STD_SECAM_K |\
897 | V4L2_STD_SECAM_K1)
898 | /* All Secam Standards */
899 | #define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\
900 | V4L2_STD_SECAM_G |\
901 | V4L2_STD_SECAM_H |\
902 | V4L2_STD_SECAM_DK |\
903 | V4L2_STD_SECAM_L |\
904 | V4L2_STD_SECAM_LC)
905 | /* PAL macros */
906 | #define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\
907 | V4L2_STD_PAL_B1 |\
908 | V4L2_STD_PAL_G)
909 | #define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\
910 | V4L2_STD_PAL_D1 |\
911 | V4L2_STD_PAL_K)
912 | /*
913 | * "Common" PAL - This macro is there to be compatible with the old
914 | * V4L1 concept of "PAL": /BGDKHI.
915 | * Several PAL standards are mising here: /M, /N and /Nc
916 | */
917 | #define V4L2_STD_PAL (V4L2_STD_PAL_BG |\
918 | V4L2_STD_PAL_DK |\
919 | V4L2_STD_PAL_H |\
920 | V4L2_STD_PAL_I)
921 | /* Chroma "agnostic" standards */
922 | #define V4L2_STD_B (V4L2_STD_PAL_B |\
923 | V4L2_STD_PAL_B1 |\
924 | V4L2_STD_SECAM_B)
925 | #define V4L2_STD_G (V4L2_STD_PAL_G |\
926 | V4L2_STD_SECAM_G)
927 | #define V4L2_STD_H (V4L2_STD_PAL_H |\
928 | V4L2_STD_SECAM_H)
929 | #define V4L2_STD_L (V4L2_STD_SECAM_L |\
930 | V4L2_STD_SECAM_LC)
931 | #define V4L2_STD_GH (V4L2_STD_G |\
932 | V4L2_STD_H)
933 | #define V4L2_STD_DK (V4L2_STD_PAL_DK |\
934 | V4L2_STD_SECAM_DK)
935 | #define V4L2_STD_BG (V4L2_STD_B |\
936 | V4L2_STD_G)
937 | #define V4L2_STD_MN (V4L2_STD_PAL_M |\
938 | V4L2_STD_PAL_N |\
939 | V4L2_STD_PAL_Nc |\
940 | V4L2_STD_NTSC)
941 |
942 | /* Standards where MTS/BTSC stereo could be found */
943 | #define V4L2_STD_MTS (V4L2_STD_NTSC_M |\
944 | V4L2_STD_PAL_M |\
945 | V4L2_STD_PAL_N |\
946 | V4L2_STD_PAL_Nc)
947 |
948 | /* Standards for Countries with 60Hz Line frequency */
949 | #define V4L2_STD_525_60 (V4L2_STD_PAL_M |\
950 | V4L2_STD_PAL_60 |\
951 | V4L2_STD_NTSC |\
952 | V4L2_STD_NTSC_443)
953 | /* Standards for Countries with 50Hz Line frequency */
954 | #define V4L2_STD_625_50 (V4L2_STD_PAL |\
955 | V4L2_STD_PAL_N |\
956 | V4L2_STD_PAL_Nc |\
957 | V4L2_STD_SECAM)
958 |
959 | #define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\
960 | V4L2_STD_ATSC_16_VSB)
961 | /* Macros with none and all analog standards */
962 | #define V4L2_STD_UNKNOWN 0
963 | #define V4L2_STD_ALL (V4L2_STD_525_60 |\
964 | V4L2_STD_625_50)
965 |
966 | struct v4l2_standard {
967 | __u32 index;
968 | v4l2_std_id id;
969 | __u8 name[24];
970 | struct v4l2_fract frameperiod; /* Frames, not fields */
971 | __u32 framelines;
972 | __u32 reserved[4];
973 | };
974 |
975 | /*
976 | * D V B T T I M I N G S
977 | */
978 |
979 | /** struct v4l2_bt_timings - BT.656/BT.1120 timing data
980 | * @width: total width of the active video in pixels
981 | * @height: total height of the active video in lines
982 | * @interlaced: Interlaced or progressive
983 | * @polarities: Positive or negative polarities
984 | * @pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000
985 | * @hfrontporch:Horizontal front porch in pixels
986 | * @hsync: Horizontal Sync length in pixels
987 | * @hbackporch: Horizontal back porch in pixels
988 | * @vfrontporch:Vertical front porch in lines
989 | * @vsync: Vertical Sync length in lines
990 | * @vbackporch: Vertical back porch in lines
991 | * @il_vfrontporch:Vertical front porch for the even field
992 | * (aka field 2) of interlaced field formats
993 | * @il_vsync: Vertical Sync length for the even field
994 | * (aka field 2) of interlaced field formats
995 | * @il_vbackporch:Vertical back porch for the even field
996 | * (aka field 2) of interlaced field formats
997 | * @standards: Standards the timing belongs to
998 | * @flags: Flags
999 | * @reserved: Reserved fields, must be zeroed.
1000 | *
1001 | * A note regarding vertical interlaced timings: height refers to the total
1002 | * height of the active video frame (= two fields). The blanking timings refer
1003 | * to the blanking of each field. So the height of the total frame is
1004 | * calculated as follows:
1005 | *
1006 | * tot_height = height + vfrontporch + vsync + vbackporch +
1007 | * il_vfrontporch + il_vsync + il_vbackporch
1008 | *
1009 | * The active height of each field is height / 2.
1010 | */
1011 | struct v4l2_bt_timings {
1012 | __u32 width;
1013 | __u32 height;
1014 | __u32 interlaced;
1015 | __u32 polarities;
1016 | __u64 pixelclock;
1017 | __u32 hfrontporch;
1018 | __u32 hsync;
1019 | __u32 hbackporch;
1020 | __u32 vfrontporch;
1021 | __u32 vsync;
1022 | __u32 vbackporch;
1023 | __u32 il_vfrontporch;
1024 | __u32 il_vsync;
1025 | __u32 il_vbackporch;
1026 | __u32 standards;
1027 | __u32 flags;
1028 | __u32 reserved[14];
1029 | } __attribute__ ((packed));
1030 |
1031 | /* Interlaced or progressive format */
1032 | #define V4L2_DV_PROGRESSIVE 0
1033 | #define V4L2_DV_INTERLACED 1
1034 |
1035 | /* Polarities. If bit is not set, it is assumed to be negative polarity */
1036 | #define V4L2_DV_VSYNC_POS_POL 0x00000001
1037 | #define V4L2_DV_HSYNC_POS_POL 0x00000002
1038 |
1039 | /* Timings standards */
1040 | #define V4L2_DV_BT_STD_CEA861 (1 << 0) /* CEA-861 Digital TV Profile */
1041 | #define V4L2_DV_BT_STD_DMT (1 << 1) /* VESA Discrete Monitor Timings */
1042 | #define V4L2_DV_BT_STD_CVT (1 << 2) /* VESA Coordinated Video Timings */
1043 | #define V4L2_DV_BT_STD_GTF (1 << 3) /* VESA Generalized Timings Formula */
1044 |
1045 | /* Flags */
1046 |
1047 | /* CVT/GTF specific: timing uses reduced blanking (CVT) or the 'Secondary
1048 | GTF' curve (GTF). In both cases the horizontal and/or vertical blanking
1049 | intervals are reduced, allowing a higher resolution over the same
1050 | bandwidth. This is a read-only flag. */
1051 | #define V4L2_DV_FL_REDUCED_BLANKING (1 << 0)
1052 | /* CEA-861 specific: set for CEA-861 formats with a framerate of a multiple
1053 | of six. These formats can be optionally played at 1 / 1.001 speed.
1054 | This is a read-only flag. */
1055 | #define V4L2_DV_FL_CAN_REDUCE_FPS (1 << 1)
1056 | /* CEA-861 specific: only valid for video transmitters, the flag is cleared
1057 | by receivers.
1058 | If the framerate of the format is a multiple of six, then the pixelclock
1059 | used to set up the transmitter is divided by 1.001 to make it compatible
1060 | with 60 Hz based standards such as NTSC and PAL-M that use a framerate of
1061 | 29.97 Hz. Otherwise this flag is cleared. If the transmitter can't generate
1062 | such frequencies, then the flag will also be cleared. */
1063 | #define V4L2_DV_FL_REDUCED_FPS (1 << 2)
1064 | /* Specific to interlaced formats: if set, then field 1 is really one half-line
1065 | longer and field 2 is really one half-line shorter, so each field has
1066 | exactly the same number of half-lines. Whether half-lines can be detected
1067 | or used depends on the hardware. */
1068 | #define V4L2_DV_FL_HALF_LINE (1 << 3)
1069 |
1070 |
1071 | /** struct v4l2_dv_timings - DV timings
1072 | * @type: the type of the timings
1073 | * @bt: BT656/1120 timings
1074 | */
1075 | struct v4l2_dv_timings {
1076 | __u32 type;
1077 | union {
1078 | struct v4l2_bt_timings bt;
1079 | __u32 reserved[32];
1080 | };
1081 | } __attribute__ ((packed));
1082 |
1083 | /* Values for the type field */
1084 | #define V4L2_DV_BT_656_1120 0 /* BT.656/1120 timing type */
1085 |
1086 |
1087 | /** struct v4l2_enum_dv_timings - DV timings enumeration
1088 | * @index: enumeration index
1089 | * @reserved: must be zeroed
1090 | * @timings: the timings for the given index
1091 | */
1092 | struct v4l2_enum_dv_timings {
1093 | __u32 index;
1094 | __u32 reserved[3];
1095 | struct v4l2_dv_timings timings;
1096 | };
1097 |
1098 | /** struct v4l2_bt_timings_cap - BT.656/BT.1120 timing capabilities
1099 | * @min_width: width in pixels
1100 | * @max_width: width in pixels
1101 | * @min_height: height in lines
1102 | * @max_height: height in lines
1103 | * @min_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000
1104 | * @max_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000
1105 | * @standards: Supported standards
1106 | * @capabilities: Supported capabilities
1107 | * @reserved: Must be zeroed
1108 | */
1109 | struct v4l2_bt_timings_cap {
1110 | __u32 min_width;
1111 | __u32 max_width;
1112 | __u32 min_height;
1113 | __u32 max_height;
1114 | __u64 min_pixelclock;
1115 | __u64 max_pixelclock;
1116 | __u32 standards;
1117 | __u32 capabilities;
1118 | __u32 reserved[16];
1119 | } __attribute__ ((packed));
1120 |
1121 | /* Supports interlaced formats */
1122 | #define V4L2_DV_BT_CAP_INTERLACED (1 << 0)
1123 | /* Supports progressive formats */
1124 | #define V4L2_DV_BT_CAP_PROGRESSIVE (1 << 1)
1125 | /* Supports CVT/GTF reduced blanking */
1126 | #define V4L2_DV_BT_CAP_REDUCED_BLANKING (1 << 2)
1127 | /* Supports custom formats */
1128 | #define V4L2_DV_BT_CAP_CUSTOM (1 << 3)
1129 |
1130 | /** struct v4l2_dv_timings_cap - DV timings capabilities
1131 | * @type: the type of the timings (same as in struct v4l2_dv_timings)
1132 | * @bt: the BT656/1120 timings capabilities
1133 | */
1134 | struct v4l2_dv_timings_cap {
1135 | __u32 type;
1136 | __u32 reserved[3];
1137 | union {
1138 | struct v4l2_bt_timings_cap bt;
1139 | __u32 raw_data[32];
1140 | };
1141 | };
1142 |
1143 |
1144 | /*
1145 | * V I D E O I N P U T S
1146 | */
1147 | struct v4l2_input {
1148 | __u32 index; /* Which input */
1149 | __u8 name[32]; /* Label */
1150 | __u32 type; /* Type of input */
1151 | __u32 audioset; /* Associated audios (bitfield) */
1152 | __u32 tuner; /* enum v4l2_tuner_type */
1153 | v4l2_std_id std;
1154 | __u32 status;
1155 | __u32 capabilities;
1156 | __u32 reserved[3];
1157 | };
1158 |
1159 | /* Values for the 'type' field */
1160 | #define V4L2_INPUT_TYPE_TUNER 1
1161 | #define V4L2_INPUT_TYPE_CAMERA 2
1162 |
1163 | /* field 'status' - general */
1164 | #define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */
1165 | #define V4L2_IN_ST_NO_SIGNAL 0x00000002
1166 | #define V4L2_IN_ST_NO_COLOR 0x00000004
1167 |
1168 | /* field 'status' - sensor orientation */
1169 | /* If sensor is mounted upside down set both bits */
1170 | #define V4L2_IN_ST_HFLIP 0x00000010 /* Frames are flipped horizontally */
1171 | #define V4L2_IN_ST_VFLIP 0x00000020 /* Frames are flipped vertically */
1172 |
1173 | /* field 'status' - analog */
1174 | #define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */
1175 | #define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */
1176 |
1177 | /* field 'status' - digital */
1178 | #define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */
1179 | #define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */
1180 | #define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed */
1181 |
1182 | /* field 'status' - VCR and set-top box */
1183 | #define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */
1184 | #define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */
1185 | #define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant */
1186 |
1187 | /* capabilities flags */
1188 | #define V4L2_IN_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */
1189 | #define V4L2_IN_CAP_CUSTOM_TIMINGS V4L2_IN_CAP_DV_TIMINGS /* For compatibility */
1190 | #define V4L2_IN_CAP_STD 0x00000004 /* Supports S_STD */
1191 |
1192 | /*
1193 | * V I D E O O U T P U T S
1194 | */
1195 | struct v4l2_output {
1196 | __u32 index; /* Which output */
1197 | __u8 name[32]; /* Label */
1198 | __u32 type; /* Type of output */
1199 | __u32 audioset; /* Associated audios (bitfield) */
1200 | __u32 modulator; /* Associated modulator */
1201 | v4l2_std_id std;
1202 | __u32 capabilities;
1203 | __u32 reserved[3];
1204 | };
1205 | /* Values for the 'type' field */
1206 | #define V4L2_OUTPUT_TYPE_MODULATOR 1
1207 | #define V4L2_OUTPUT_TYPE_ANALOG 2
1208 | #define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3
1209 |
1210 | /* capabilities flags */
1211 | #define V4L2_OUT_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */
1212 | #define V4L2_OUT_CAP_CUSTOM_TIMINGS V4L2_OUT_CAP_DV_TIMINGS /* For compatibility */
1213 | #define V4L2_OUT_CAP_STD 0x00000004 /* Supports S_STD */
1214 |
1215 | /*
1216 | * C O N T R O L S
1217 | */
1218 | struct v4l2_control {
1219 | __u32 id;
1220 | __s32 value;
1221 | };
1222 |
1223 | struct v4l2_ext_control {
1224 | __u32 id;
1225 | __u32 size;
1226 | __u32 reserved2[1];
1227 | union {
1228 | __s32 value;
1229 | __s64 value64;
1230 | char *string;
1231 | };
1232 | } __attribute__ ((packed));
1233 |
1234 | struct v4l2_ext_controls {
1235 | __u32 ctrl_class;
1236 | __u32 count;
1237 | __u32 error_idx;
1238 | __u32 reserved[2];
1239 | struct v4l2_ext_control *controls;
1240 | };
1241 |
1242 | #define V4L2_CTRL_ID_MASK (0x0fffffff)
1243 | #define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
1244 | #define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
1245 |
1246 | enum v4l2_ctrl_type {
1247 | V4L2_CTRL_TYPE_INTEGER = 1,
1248 | V4L2_CTRL_TYPE_BOOLEAN = 2,
1249 | V4L2_CTRL_TYPE_MENU = 3,
1250 | V4L2_CTRL_TYPE_BUTTON = 4,
1251 | V4L2_CTRL_TYPE_INTEGER64 = 5,
1252 | V4L2_CTRL_TYPE_CTRL_CLASS = 6,
1253 | V4L2_CTRL_TYPE_STRING = 7,
1254 | V4L2_CTRL_TYPE_BITMASK = 8,
1255 | V4L2_CTRL_TYPE_INTEGER_MENU = 9,
1256 | };
1257 |
1258 | /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
1259 | struct v4l2_queryctrl {
1260 | __u32 id;
1261 | __u32 type; /* enum v4l2_ctrl_type */
1262 | __u8 name[32]; /* Whatever */
1263 | __s32 minimum; /* Note signedness */
1264 | __s32 maximum;
1265 | __s32 step;
1266 | __s32 default_value;
1267 | __u32 flags;
1268 | __u32 reserved[2];
1269 | };
1270 |
1271 | /* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */
1272 | struct v4l2_querymenu {
1273 | __u32 id;
1274 | __u32 index;
1275 | union {
1276 | __u8 name[32]; /* Whatever */
1277 | __s64 value;
1278 | };
1279 | __u32 reserved;
1280 | } __attribute__ ((packed));
1281 |
1282 | /* Control flags */
1283 | #define V4L2_CTRL_FLAG_DISABLED 0x0001
1284 | #define V4L2_CTRL_FLAG_GRABBED 0x0002
1285 | #define V4L2_CTRL_FLAG_READ_ONLY 0x0004
1286 | #define V4L2_CTRL_FLAG_UPDATE 0x0008
1287 | #define V4L2_CTRL_FLAG_INACTIVE 0x0010
1288 | #define V4L2_CTRL_FLAG_SLIDER 0x0020
1289 | #define V4L2_CTRL_FLAG_WRITE_ONLY 0x0040
1290 | #define V4L2_CTRL_FLAG_VOLATILE 0x0080
1291 |
1292 | /* Query flag, to be ORed with the control ID */
1293 | #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000
1294 |
1295 | /* User-class control IDs defined by V4L2 */
1296 | #define V4L2_CID_MAX_CTRLS 1024
1297 | /* IDs reserved for driver specific controls */
1298 | #define V4L2_CID_PRIVATE_BASE 0x08000000
1299 |
1300 |
1301 | /*
1302 | * T U N I N G
1303 | */
1304 | struct v4l2_tuner {
1305 | __u32 index;
1306 | __u8 name[32];
1307 | __u32 type; /* enum v4l2_tuner_type */
1308 | __u32 capability;
1309 | __u32 rangelow;
1310 | __u32 rangehigh;
1311 | __u32 rxsubchans;
1312 | __u32 audmode;
1313 | __s32 signal;
1314 | __s32 afc;
1315 | __u32 reserved[4];
1316 | };
1317 |
1318 | struct v4l2_modulator {
1319 | __u32 index;
1320 | __u8 name[32];
1321 | __u32 capability;
1322 | __u32 rangelow;
1323 | __u32 rangehigh;
1324 | __u32 txsubchans;
1325 | __u32 reserved[4];
1326 | };
1327 |
1328 | /* Flags for the 'capability' field */
1329 | #define V4L2_TUNER_CAP_LOW 0x0001
1330 | #define V4L2_TUNER_CAP_NORM 0x0002
1331 | #define V4L2_TUNER_CAP_HWSEEK_BOUNDED 0x0004
1332 | #define V4L2_TUNER_CAP_HWSEEK_WRAP 0x0008
1333 | #define V4L2_TUNER_CAP_STEREO 0x0010
1334 | #define V4L2_TUNER_CAP_LANG2 0x0020
1335 | #define V4L2_TUNER_CAP_SAP 0x0020
1336 | #define V4L2_TUNER_CAP_LANG1 0x0040
1337 | #define V4L2_TUNER_CAP_RDS 0x0080
1338 | #define V4L2_TUNER_CAP_RDS_BLOCK_IO 0x0100
1339 | #define V4L2_TUNER_CAP_RDS_CONTROLS 0x0200
1340 | #define V4L2_TUNER_CAP_FREQ_BANDS 0x0400
1341 | #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM 0x0800
1342 |
1343 | /* Flags for the 'rxsubchans' field */
1344 | #define V4L2_TUNER_SUB_MONO 0x0001
1345 | #define V4L2_TUNER_SUB_STEREO 0x0002
1346 | #define V4L2_TUNER_SUB_LANG2 0x0004
1347 | #define V4L2_TUNER_SUB_SAP 0x0004
1348 | #define V4L2_TUNER_SUB_LANG1 0x0008
1349 | #define V4L2_TUNER_SUB_RDS 0x0010
1350 |
1351 | /* Values for the 'audmode' field */
1352 | #define V4L2_TUNER_MODE_MONO 0x0000
1353 | #define V4L2_TUNER_MODE_STEREO 0x0001
1354 | #define V4L2_TUNER_MODE_LANG2 0x0002
1355 | #define V4L2_TUNER_MODE_SAP 0x0002
1356 | #define V4L2_TUNER_MODE_LANG1 0x0003
1357 | #define V4L2_TUNER_MODE_LANG1_LANG2 0x0004
1358 |
1359 | struct v4l2_frequency {
1360 | __u32 tuner;
1361 | __u32 type; /* enum v4l2_tuner_type */
1362 | __u32 frequency;
1363 | __u32 reserved[8];
1364 | };
1365 |
1366 | #define V4L2_BAND_MODULATION_VSB (1 << 1)
1367 | #define V4L2_BAND_MODULATION_FM (1 << 2)
1368 | #define V4L2_BAND_MODULATION_AM (1 << 3)
1369 |
1370 | struct v4l2_frequency_band {
1371 | __u32 tuner;
1372 | __u32 type; /* enum v4l2_tuner_type */
1373 | __u32 index;
1374 | __u32 capability;
1375 | __u32 rangelow;
1376 | __u32 rangehigh;
1377 | __u32 modulation;
1378 | __u32 reserved[9];
1379 | };
1380 |
1381 | struct v4l2_hw_freq_seek {
1382 | __u32 tuner;
1383 | __u32 type; /* enum v4l2_tuner_type */
1384 | __u32 seek_upward;
1385 | __u32 wrap_around;
1386 | __u32 spacing;
1387 | __u32 rangelow;
1388 | __u32 rangehigh;
1389 | __u32 reserved[5];
1390 | };
1391 |
1392 | /*
1393 | * R D S
1394 | */
1395 |
1396 | struct v4l2_rds_data {
1397 | __u8 lsb;
1398 | __u8 msb;
1399 | __u8 block;
1400 | } __attribute__ ((packed));
1401 |
1402 | #define V4L2_RDS_BLOCK_MSK 0x7
1403 | #define V4L2_RDS_BLOCK_A 0
1404 | #define V4L2_RDS_BLOCK_B 1
1405 | #define V4L2_RDS_BLOCK_C 2
1406 | #define V4L2_RDS_BLOCK_D 3
1407 | #define V4L2_RDS_BLOCK_C_ALT 4
1408 | #define V4L2_RDS_BLOCK_INVALID 7
1409 |
1410 | #define V4L2_RDS_BLOCK_CORRECTED 0x40
1411 | #define V4L2_RDS_BLOCK_ERROR 0x80
1412 |
1413 | /*
1414 | * A U D I O
1415 | */
1416 | struct v4l2_audio {
1417 | __u32 index;
1418 | __u8 name[32];
1419 | __u32 capability;
1420 | __u32 mode;
1421 | __u32 reserved[2];
1422 | };
1423 |
1424 | /* Flags for the 'capability' field */
1425 | #define V4L2_AUDCAP_STEREO 0x00001
1426 | #define V4L2_AUDCAP_AVL 0x00002
1427 |
1428 | /* Flags for the 'mode' field */
1429 | #define V4L2_AUDMODE_AVL 0x00001
1430 |
1431 | struct v4l2_audioout {
1432 | __u32 index;
1433 | __u8 name[32];
1434 | __u32 capability;
1435 | __u32 mode;
1436 | __u32 reserved[2];
1437 | };
1438 |
1439 | /*
1440 | * M P E G S E R V I C E S
1441 | *
1442 | * NOTE: EXPERIMENTAL API
1443 | */
1444 | #if 1
1445 | #define V4L2_ENC_IDX_FRAME_I (0)
1446 | #define V4L2_ENC_IDX_FRAME_P (1)
1447 | #define V4L2_ENC_IDX_FRAME_B (2)
1448 | #define V4L2_ENC_IDX_FRAME_MASK (0xf)
1449 |
1450 | struct v4l2_enc_idx_entry {
1451 | __u64 offset;
1452 | __u64 pts;
1453 | __u32 length;
1454 | __u32 flags;
1455 | __u32 reserved[2];
1456 | };
1457 |
1458 | #define V4L2_ENC_IDX_ENTRIES (64)
1459 | struct v4l2_enc_idx {
1460 | __u32 entries;
1461 | __u32 entries_cap;
1462 | __u32 reserved[4];
1463 | struct v4l2_enc_idx_entry entry[V4L2_ENC_IDX_ENTRIES];
1464 | };
1465 |
1466 |
1467 | #define V4L2_ENC_CMD_START (0)
1468 | #define V4L2_ENC_CMD_STOP (1)
1469 | #define V4L2_ENC_CMD_PAUSE (2)
1470 | #define V4L2_ENC_CMD_RESUME (3)
1471 |
1472 | /* Flags for V4L2_ENC_CMD_STOP */
1473 | #define V4L2_ENC_CMD_STOP_AT_GOP_END (1 << 0)
1474 |
1475 | struct v4l2_encoder_cmd {
1476 | __u32 cmd;
1477 | __u32 flags;
1478 | union {
1479 | struct {
1480 | __u32 data[8];
1481 | } raw;
1482 | };
1483 | };
1484 |
1485 | /* Decoder commands */
1486 | #define V4L2_DEC_CMD_START (0)
1487 | #define V4L2_DEC_CMD_STOP (1)
1488 | #define V4L2_DEC_CMD_PAUSE (2)
1489 | #define V4L2_DEC_CMD_RESUME (3)
1490 |
1491 | /* Flags for V4L2_DEC_CMD_START */
1492 | #define V4L2_DEC_CMD_START_MUTE_AUDIO (1 << 0)
1493 |
1494 | /* Flags for V4L2_DEC_CMD_PAUSE */
1495 | #define V4L2_DEC_CMD_PAUSE_TO_BLACK (1 << 0)
1496 |
1497 | /* Flags for V4L2_DEC_CMD_STOP */
1498 | #define V4L2_DEC_CMD_STOP_TO_BLACK (1 << 0)
1499 | #define V4L2_DEC_CMD_STOP_IMMEDIATELY (1 << 1)
1500 |
1501 | /* Play format requirements (returned by the driver): */
1502 |
1503 | /* The decoder has no special format requirements */
1504 | #define V4L2_DEC_START_FMT_NONE (0)
1505 | /* The decoder requires full GOPs */
1506 | #define V4L2_DEC_START_FMT_GOP (1)
1507 |
1508 | /* The structure must be zeroed before use by the application
1509 | This ensures it can be extended safely in the future. */
1510 | struct v4l2_decoder_cmd {
1511 | __u32 cmd;
1512 | __u32 flags;
1513 | union {
1514 | struct {
1515 | __u64 pts;
1516 | } stop;
1517 |
1518 | struct {
1519 | /* 0 or 1000 specifies normal speed,
1520 | 1 specifies forward single stepping,
1521 | -1 specifies backward single stepping,
1522 | >1: playback at speed/1000 of the normal speed,
1523 | <-1: reverse playback at (-speed/1000) of the normal speed. */
1524 | __s32 speed;
1525 | __u32 format;
1526 | } start;
1527 |
1528 | struct {
1529 | __u32 data[16];
1530 | } raw;
1531 | };
1532 | };
1533 | #endif
1534 |
1535 |
1536 | /*
1537 | * D A T A S E R V I C E S ( V B I )
1538 | *
1539 | * Data services API by Michael Schimek
1540 | */
1541 |
1542 | /* Raw VBI */
1543 | struct v4l2_vbi_format {
1544 | __u32 sampling_rate; /* in 1 Hz */
1545 | __u32 offset;
1546 | __u32 samples_per_line;
1547 | __u32 sample_format; /* V4L2_PIX_FMT_* */
1548 | __s32 start[2];
1549 | __u32 count[2];
1550 | __u32 flags; /* V4L2_VBI_* */
1551 | __u32 reserved[2]; /* must be zero */
1552 | };
1553 |
1554 | /* VBI flags */
1555 | #define V4L2_VBI_UNSYNC (1 << 0)
1556 | #define V4L2_VBI_INTERLACED (1 << 1)
1557 |
1558 | /* Sliced VBI
1559 | *
1560 | * This implements is a proposal V4L2 API to allow SLICED VBI
1561 | * required for some hardware encoders. It should change without
1562 | * notice in the definitive implementation.
1563 | */
1564 |
1565 | struct v4l2_sliced_vbi_format {
1566 | __u16 service_set;
1567 | /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
1568 | service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
1569 | (equals frame lines 313-336 for 625 line video
1570 | standards, 263-286 for 525 line standards) */
1571 | __u16 service_lines[2][24];
1572 | __u32 io_size;
1573 | __u32 reserved[2]; /* must be zero */
1574 | };
1575 |
1576 | /* Teletext World System Teletext
1577 | (WST), defined on ITU-R BT.653-2 */
1578 | #define V4L2_SLICED_TELETEXT_B (0x0001)
1579 | /* Video Program System, defined on ETS 300 231*/
1580 | #define V4L2_SLICED_VPS (0x0400)
1581 | /* Closed Caption, defined on EIA-608 */
1582 | #define V4L2_SLICED_CAPTION_525 (0x1000)
1583 | /* Wide Screen System, defined on ITU-R BT1119.1 */
1584 | #define V4L2_SLICED_WSS_625 (0x4000)
1585 |
1586 | #define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525)
1587 | #define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625)
1588 |
1589 | struct v4l2_sliced_vbi_cap {
1590 | __u16 service_set;
1591 | /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
1592 | service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
1593 | (equals frame lines 313-336 for 625 line video
1594 | standards, 263-286 for 525 line standards) */
1595 | __u16 service_lines[2][24];
1596 | __u32 type; /* enum v4l2_buf_type */
1597 | __u32 reserved[3]; /* must be 0 */
1598 | };
1599 |
1600 | struct v4l2_sliced_vbi_data {
1601 | __u32 id;
1602 | __u32 field; /* 0: first field, 1: second field */
1603 | __u32 line; /* 1-23 */
1604 | __u32 reserved; /* must be 0 */
1605 | __u8 data[48];
1606 | };
1607 |
1608 | /*
1609 | * Sliced VBI data inserted into MPEG Streams
1610 | */
1611 |
1612 | /*
1613 | * V4L2_MPEG_STREAM_VBI_FMT_IVTV:
1614 | *
1615 | * Structure of payload contained in an MPEG 2 Private Stream 1 PES Packet in an
1616 | * MPEG-2 Program Pack that contains V4L2_MPEG_STREAM_VBI_FMT_IVTV Sliced VBI
1617 | * data
1618 | *
1619 | * Note, the MPEG-2 Program Pack and Private Stream 1 PES packet header
1620 | * definitions are not included here. See the MPEG-2 specifications for details
1621 | * on these headers.
1622 | */
1623 |
1624 | /* Line type IDs */
1625 | #define V4L2_MPEG_VBI_IVTV_TELETEXT_B (1)
1626 | #define V4L2_MPEG_VBI_IVTV_CAPTION_525 (4)
1627 | #define V4L2_MPEG_VBI_IVTV_WSS_625 (5)
1628 | #define V4L2_MPEG_VBI_IVTV_VPS (7)
1629 |
1630 | struct v4l2_mpeg_vbi_itv0_line {
1631 | __u8 id; /* One of V4L2_MPEG_VBI_IVTV_* above */
1632 | __u8 data[42]; /* Sliced VBI data for the line */
1633 | } __attribute__ ((packed));
1634 |
1635 | struct v4l2_mpeg_vbi_itv0 {
1636 | __le32 linemask[2]; /* Bitmasks of VBI service lines present */
1637 | struct v4l2_mpeg_vbi_itv0_line line[35];
1638 | } __attribute__ ((packed));
1639 |
1640 | struct v4l2_mpeg_vbi_ITV0 {
1641 | struct v4l2_mpeg_vbi_itv0_line line[36];
1642 | } __attribute__ ((packed));
1643 |
1644 | #define V4L2_MPEG_VBI_IVTV_MAGIC0 "itv0"
1645 | #define V4L2_MPEG_VBI_IVTV_MAGIC1 "ITV0"
1646 |
1647 | struct v4l2_mpeg_vbi_fmt_ivtv {
1648 | __u8 magic[4];
1649 | union {
1650 | struct v4l2_mpeg_vbi_itv0 itv0;
1651 | struct v4l2_mpeg_vbi_ITV0 ITV0;
1652 | };
1653 | } __attribute__ ((packed));
1654 |
1655 | /*
1656 | * A G G R E G A T E S T R U C T U R E S
1657 | */
1658 |
1659 | /**
1660 | * struct v4l2_plane_pix_format - additional, per-plane format definition
1661 | * @sizeimage: maximum size in bytes required for data, for which
1662 | * this plane will be used
1663 | * @bytesperline: distance in bytes between the leftmost pixels in two
1664 | * adjacent lines
1665 | */
1666 | struct v4l2_plane_pix_format {
1667 | __u32 sizeimage;
1668 | __u16 bytesperline;
1669 | __u16 reserved[7];
1670 | } __attribute__ ((packed));
1671 |
1672 | /**
1673 | * struct v4l2_pix_format_mplane - multiplanar format definition
1674 | * @width: image width in pixels
1675 | * @height: image height in pixels
1676 | * @pixelformat: little endian four character code (fourcc)
1677 | * @field: enum v4l2_field; field order (for interlaced video)
1678 | * @colorspace: enum v4l2_colorspace; supplemental to pixelformat
1679 | * @plane_fmt: per-plane information
1680 | * @num_planes: number of planes for this format
1681 | */
1682 | struct v4l2_pix_format_mplane {
1683 | __u32 width;
1684 | __u32 height;
1685 | __u32 pixelformat;
1686 | __u32 field;
1687 | __u32 colorspace;
1688 |
1689 | struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES];
1690 | __u8 num_planes;
1691 | __u8 reserved[11];
1692 | } __attribute__ ((packed));
1693 |
1694 | /**
1695 | * struct v4l2_format - stream data format
1696 | * @type: enum v4l2_buf_type; type of the data stream
1697 | * @pix: definition of an image format
1698 | * @pix_mp: definition of a multiplanar image format
1699 | * @win: definition of an overlaid image
1700 | * @vbi: raw VBI capture or output parameters
1701 | * @sliced: sliced VBI capture or output parameters
1702 | * @raw_data: placeholder for future extensions and custom formats
1703 | */
1704 | struct v4l2_format {
1705 | __u32 type;
1706 | union {
1707 | struct v4l2_pix_format pix; /* V4L2_BUF_TYPE_VIDEO_CAPTURE */
1708 | struct v4l2_pix_format_mplane pix_mp; /* V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE */
1709 | struct v4l2_window win; /* V4L2_BUF_TYPE_VIDEO_OVERLAY */
1710 | struct v4l2_vbi_format vbi; /* V4L2_BUF_TYPE_VBI_CAPTURE */
1711 | struct v4l2_sliced_vbi_format sliced; /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */
1712 | __u8 raw_data[200]; /* user-defined */
1713 | } fmt;
1714 | };
1715 |
1716 | /* Stream type-dependent parameters
1717 | */
1718 | struct v4l2_streamparm {
1719 | __u32 type; /* enum v4l2_buf_type */
1720 | union {
1721 | struct v4l2_captureparm capture;
1722 | struct v4l2_outputparm output;
1723 | __u8 raw_data[200]; /* user-defined */
1724 | } parm;
1725 | };
1726 |
1727 | /*
1728 | * E V E N T S
1729 | */
1730 |
1731 | #define V4L2_EVENT_ALL 0
1732 | #define V4L2_EVENT_VSYNC 1
1733 | #define V4L2_EVENT_EOS 2
1734 | #define V4L2_EVENT_CTRL 3
1735 | #define V4L2_EVENT_FRAME_SYNC 4
1736 | #define V4L2_EVENT_PRIVATE_START 0x08000000
1737 |
1738 | /* Payload for V4L2_EVENT_VSYNC */
1739 | struct v4l2_event_vsync {
1740 | /* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */
1741 | __u8 field;
1742 | } __attribute__ ((packed));
1743 |
1744 | /* Payload for V4L2_EVENT_CTRL */
1745 | #define V4L2_EVENT_CTRL_CH_VALUE (1 << 0)
1746 | #define V4L2_EVENT_CTRL_CH_FLAGS (1 << 1)
1747 | #define V4L2_EVENT_CTRL_CH_RANGE (1 << 2)
1748 |
1749 | struct v4l2_event_ctrl {
1750 | __u32 changes;
1751 | __u32 type;
1752 | union {
1753 | __s32 value;
1754 | __s64 value64;
1755 | };
1756 | __u32 flags;
1757 | __s32 minimum;
1758 | __s32 maximum;
1759 | __s32 step;
1760 | __s32 default_value;
1761 | };
1762 |
1763 | struct v4l2_event_frame_sync {
1764 | __u32 frame_sequence;
1765 | };
1766 |
1767 | struct v4l2_event {
1768 | __u32 type;
1769 | union {
1770 | struct v4l2_event_vsync vsync;
1771 | struct v4l2_event_ctrl ctrl;
1772 | struct v4l2_event_frame_sync frame_sync;
1773 | __u8 data[64];
1774 | } u;
1775 | __u32 pending;
1776 | __u32 sequence;
1777 | struct timespec timestamp;
1778 | __u32 id;
1779 | __u32 reserved[8];
1780 | };
1781 |
1782 | #define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0)
1783 | #define V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK (1 << 1)
1784 |
1785 | struct v4l2_event_subscription {
1786 | __u32 type;
1787 | __u32 id;
1788 | __u32 flags;
1789 | __u32 reserved[5];
1790 | };
1791 |
1792 | /*
1793 | * A D V A N C E D D E B U G G I N G
1794 | *
1795 | * NOTE: EXPERIMENTAL API, NEVER RELY ON THIS IN APPLICATIONS!
1796 | * FOR DEBUGGING, TESTING AND INTERNAL USE ONLY!
1797 | */
1798 |
1799 | /* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */
1800 |
1801 | #define V4L2_CHIP_MATCH_BRIDGE 0 /* Match against chip ID on the bridge (0 for the bridge) */
1802 | #define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE
1803 | #define V4L2_CHIP_MATCH_I2C_DRIVER 1 /* Match against I2C driver name */
1804 | #define V4L2_CHIP_MATCH_I2C_ADDR 2 /* Match against I2C 7-bit address */
1805 | #define V4L2_CHIP_MATCH_AC97 3 /* Match against anciliary AC97 chip */
1806 | #define V4L2_CHIP_MATCH_SUBDEV 4 /* Match against subdev index */
1807 |
1808 | struct v4l2_dbg_match {
1809 | __u32 type; /* Match type */
1810 | union { /* Match this chip, meaning determined by type */
1811 | __u32 addr;
1812 | char name[32];
1813 | };
1814 | } __attribute__ ((packed));
1815 |
1816 | struct v4l2_dbg_register {
1817 | struct v4l2_dbg_match match;
1818 | __u32 size; /* register size in bytes */
1819 | __u64 reg;
1820 | __u64 val;
1821 | } __attribute__ ((packed));
1822 |
1823 | /* VIDIOC_DBG_G_CHIP_IDENT */
1824 | struct v4l2_dbg_chip_ident {
1825 | struct v4l2_dbg_match match;
1826 | __u32 ident; /* chip identifier as specified in */
1827 | __u32 revision; /* chip revision, chip specific */
1828 | } __attribute__ ((packed));
1829 |
1830 | #define V4L2_CHIP_FL_READABLE (1 << 0)
1831 | #define V4L2_CHIP_FL_WRITABLE (1 << 1)
1832 |
1833 | /* VIDIOC_DBG_G_CHIP_INFO */
1834 | struct v4l2_dbg_chip_info {
1835 | struct v4l2_dbg_match match;
1836 | char name[32];
1837 | __u32 flags;
1838 | __u32 reserved[32];
1839 | } __attribute__ ((packed));
1840 |
1841 | /**
1842 | * struct v4l2_create_buffers - VIDIOC_CREATE_BUFS argument
1843 | * @index: on return, index of the first created buffer
1844 | * @count: entry: number of requested buffers,
1845 | * return: number of created buffers
1846 | * @memory: enum v4l2_memory; buffer memory type
1847 | * @format: frame format, for which buffers are requested
1848 | * @reserved: future extensions
1849 | */
1850 | struct v4l2_create_buffers {
1851 | __u32 index;
1852 | __u32 count;
1853 | __u32 memory;
1854 | struct v4l2_format format;
1855 | __u32 reserved[8];
1856 | };
1857 |
1858 | /*
1859 | * I O C T L C O D E S F O R V I D E O D E V I C E S
1860 | *
1861 | */
1862 | #define VIDIOC_QUERYCAP _IOR('V', 0, struct v4l2_capability)
1863 | #define VIDIOC_RESERVED _IO('V', 1)
1864 | #define VIDIOC_ENUM_FMT _IOWR('V', 2, struct v4l2_fmtdesc)
1865 | #define VIDIOC_G_FMT _IOWR('V', 4, struct v4l2_format)
1866 | #define VIDIOC_S_FMT _IOWR('V', 5, struct v4l2_format)
1867 | #define VIDIOC_REQBUFS _IOWR('V', 8, struct v4l2_requestbuffers)
1868 | #define VIDIOC_QUERYBUF _IOWR('V', 9, struct v4l2_buffer)
1869 | #define VIDIOC_G_FBUF _IOR('V', 10, struct v4l2_framebuffer)
1870 | #define VIDIOC_S_FBUF _IOW('V', 11, struct v4l2_framebuffer)
1871 | #define VIDIOC_OVERLAY _IOW('V', 14, int)
1872 | #define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer)
1873 | #define VIDIOC_EXPBUF _IOWR('V', 16, struct v4l2_exportbuffer)
1874 | #define VIDIOC_DQBUF _IOWR('V', 17, struct v4l2_buffer)
1875 | #define VIDIOC_STREAMON _IOW('V', 18, int)
1876 | #define VIDIOC_STREAMOFF _IOW('V', 19, int)
1877 | #define VIDIOC_G_PARM _IOWR('V', 21, struct v4l2_streamparm)
1878 | #define VIDIOC_S_PARM _IOWR('V', 22, struct v4l2_streamparm)
1879 | #define VIDIOC_G_STD _IOR('V', 23, v4l2_std_id)
1880 | #define VIDIOC_S_STD _IOW('V', 24, v4l2_std_id)
1881 | #define VIDIOC_ENUMSTD _IOWR('V', 25, struct v4l2_standard)
1882 | #define VIDIOC_ENUMINPUT _IOWR('V', 26, struct v4l2_input)
1883 | #define VIDIOC_G_CTRL _IOWR('V', 27, struct v4l2_control)
1884 | #define VIDIOC_S_CTRL _IOWR('V', 28, struct v4l2_control)
1885 | #define VIDIOC_G_TUNER _IOWR('V', 29, struct v4l2_tuner)
1886 | #define VIDIOC_S_TUNER _IOW('V', 30, struct v4l2_tuner)
1887 | #define VIDIOC_G_AUDIO _IOR('V', 33, struct v4l2_audio)
1888 | #define VIDIOC_S_AUDIO _IOW('V', 34, struct v4l2_audio)
1889 | #define VIDIOC_QUERYCTRL _IOWR('V', 36, struct v4l2_queryctrl)
1890 | #define VIDIOC_QUERYMENU _IOWR('V', 37, struct v4l2_querymenu)
1891 | #define VIDIOC_G_INPUT _IOR('V', 38, int)
1892 | #define VIDIOC_S_INPUT _IOWR('V', 39, int)
1893 | #define VIDIOC_G_OUTPUT _IOR('V', 46, int)
1894 | #define VIDIOC_S_OUTPUT _IOWR('V', 47, int)
1895 | #define VIDIOC_ENUMOUTPUT _IOWR('V', 48, struct v4l2_output)
1896 | #define VIDIOC_G_AUDOUT _IOR('V', 49, struct v4l2_audioout)
1897 | #define VIDIOC_S_AUDOUT _IOW('V', 50, struct v4l2_audioout)
1898 | #define VIDIOC_G_MODULATOR _IOWR('V', 54, struct v4l2_modulator)
1899 | #define VIDIOC_S_MODULATOR _IOW('V', 55, struct v4l2_modulator)
1900 | #define VIDIOC_G_FREQUENCY _IOWR('V', 56, struct v4l2_frequency)
1901 | #define VIDIOC_S_FREQUENCY _IOW('V', 57, struct v4l2_frequency)
1902 | #define VIDIOC_CROPCAP _IOWR('V', 58, struct v4l2_cropcap)
1903 | #define VIDIOC_G_CROP _IOWR('V', 59, struct v4l2_crop)
1904 | #define VIDIOC_S_CROP _IOW('V', 60, struct v4l2_crop)
1905 | #define VIDIOC_G_JPEGCOMP _IOR('V', 61, struct v4l2_jpegcompression)
1906 | #define VIDIOC_S_JPEGCOMP _IOW('V', 62, struct v4l2_jpegcompression)
1907 | #define VIDIOC_QUERYSTD _IOR('V', 63, v4l2_std_id)
1908 | #define VIDIOC_TRY_FMT _IOWR('V', 64, struct v4l2_format)
1909 | #define VIDIOC_ENUMAUDIO _IOWR('V', 65, struct v4l2_audio)
1910 | #define VIDIOC_ENUMAUDOUT _IOWR('V', 66, struct v4l2_audioout)
1911 | #define VIDIOC_G_PRIORITY _IOR('V', 67, __u32) /* enum v4l2_priority */
1912 | #define VIDIOC_S_PRIORITY _IOW('V', 68, __u32) /* enum v4l2_priority */
1913 | #define VIDIOC_G_SLICED_VBI_CAP _IOWR('V', 69, struct v4l2_sliced_vbi_cap)
1914 | #define VIDIOC_LOG_STATUS _IO('V', 70)
1915 | #define VIDIOC_G_EXT_CTRLS _IOWR('V', 71, struct v4l2_ext_controls)
1916 | #define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls)
1917 | #define VIDIOC_TRY_EXT_CTRLS _IOWR('V', 73, struct v4l2_ext_controls)
1918 | #define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum)
1919 | #define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum)
1920 | #define VIDIOC_G_ENC_INDEX _IOR('V', 76, struct v4l2_enc_idx)
1921 | #define VIDIOC_ENCODER_CMD _IOWR('V', 77, struct v4l2_encoder_cmd)
1922 | #define VIDIOC_TRY_ENCODER_CMD _IOWR('V', 78, struct v4l2_encoder_cmd)
1923 |
1924 | /* Experimental, meant for debugging, testing and internal use.
1925 | Only implemented if CONFIG_VIDEO_ADV_DEBUG is defined.
1926 | You must be root to use these ioctls. Never use these in applications! */
1927 | #define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register)
1928 | #define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register)
1929 |
1930 | /* Experimental, meant for debugging, testing and internal use.
1931 | Never use this ioctl in applications!
1932 | Note: this ioctl is deprecated in favor of VIDIOC_DBG_G_CHIP_INFO and
1933 | will go away in the future. */
1934 | #define VIDIOC_DBG_G_CHIP_IDENT _IOWR('V', 81, struct v4l2_dbg_chip_ident)
1935 |
1936 | #define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek)
1937 |
1938 | #define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings)
1939 | #define VIDIOC_G_DV_TIMINGS _IOWR('V', 88, struct v4l2_dv_timings)
1940 | #define VIDIOC_DQEVENT _IOR('V', 89, struct v4l2_event)
1941 | #define VIDIOC_SUBSCRIBE_EVENT _IOW('V', 90, struct v4l2_event_subscription)
1942 | #define VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription)
1943 |
1944 | /* Experimental, the below two ioctls may change over the next couple of kernel
1945 | versions */
1946 | #define VIDIOC_CREATE_BUFS _IOWR('V', 92, struct v4l2_create_buffers)
1947 | #define VIDIOC_PREPARE_BUF _IOWR('V', 93, struct v4l2_buffer)
1948 |
1949 | /* Experimental selection API */
1950 | #define VIDIOC_G_SELECTION _IOWR('V', 94, struct v4l2_selection)
1951 | #define VIDIOC_S_SELECTION _IOWR('V', 95, struct v4l2_selection)
1952 |
1953 | /* Experimental, these two ioctls may change over the next couple of kernel
1954 | versions. */
1955 | #define VIDIOC_DECODER_CMD _IOWR('V', 96, struct v4l2_decoder_cmd)
1956 | #define VIDIOC_TRY_DECODER_CMD _IOWR('V', 97, struct v4l2_decoder_cmd)
1957 |
1958 | /* Experimental, these three ioctls may change over the next couple of kernel
1959 | versions. */
1960 | #define VIDIOC_ENUM_DV_TIMINGS _IOWR('V', 98, struct v4l2_enum_dv_timings)
1961 | #define VIDIOC_QUERY_DV_TIMINGS _IOR('V', 99, struct v4l2_dv_timings)
1962 | #define VIDIOC_DV_TIMINGS_CAP _IOWR('V', 100, struct v4l2_dv_timings_cap)
1963 |
1964 | /* Experimental, this ioctl may change over the next couple of kernel
1965 | versions. */
1966 | #define VIDIOC_ENUM_FREQ_BANDS _IOWR('V', 101, struct v4l2_frequency_band)
1967 |
1968 | /* Experimental, meant for debugging, testing and internal use.
1969 | Never use these in applications! */
1970 | #define VIDIOC_DBG_G_CHIP_INFO _IOWR('V', 102, struct v4l2_dbg_chip_info)
1971 |
1972 | /* Reminder: when adding new ioctls please add support for them to
1973 | drivers/media/video/v4l2-compat-ioctl32.c as well! */
1974 |
1975 | #define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */
1976 |
1977 | #endif /* _UAPI__LINUX_VIDEODEV2_H */
1978 |
--------------------------------------------------------------------------------
/UVCKernelPatches/Patched Files/uvc_driver.c:
--------------------------------------------------------------------------------
1 | /*
2 | * uvc_driver.c -- USB Video Class driver
3 | *
4 | * Copyright (C) 2005-2010
5 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 2 of the License, or
10 | * (at your option) any later version.
11 | *
12 | */
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include
27 |
28 | #include "uvcvideo.h"
29 |
30 | #define DRIVER_AUTHOR "Laurent Pinchart " \
31 | ""
32 | #define DRIVER_DESC "USB Video Class driver"
33 |
34 | unsigned int uvc_clock_param = CLOCK_MONOTONIC;
35 | unsigned int uvc_no_drop_param;
36 | static unsigned int uvc_quirks_param = -1;
37 | unsigned int uvc_trace_param;
38 | unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
39 |
40 | /* ------------------------------------------------------------------------
41 | * Video formats
42 | */
43 |
44 | static struct uvc_format_desc uvc_fmts[] = {
45 | {
46 | .name = "YUV 4:2:2 (YUYV)",
47 | .guid = UVC_GUID_FORMAT_YUY2,
48 | .fcc = V4L2_PIX_FMT_YUYV,
49 | },
50 | {
51 | .name = "YUV 4:2:2 (YUYV)",
52 | .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
53 | .fcc = V4L2_PIX_FMT_YUYV,
54 | },
55 | {
56 | .name = "YUV 4:2:0 (NV12)",
57 | .guid = UVC_GUID_FORMAT_NV12,
58 | .fcc = V4L2_PIX_FMT_NV12,
59 | },
60 | {
61 | .name = "MJPEG",
62 | .guid = UVC_GUID_FORMAT_MJPEG,
63 | .fcc = V4L2_PIX_FMT_MJPEG,
64 | },
65 | {
66 | .name = "YVU 4:2:0 (YV12)",
67 | .guid = UVC_GUID_FORMAT_YV12,
68 | .fcc = V4L2_PIX_FMT_YVU420,
69 | },
70 | {
71 | .name = "YUV 4:2:0 (I420)",
72 | .guid = UVC_GUID_FORMAT_I420,
73 | .fcc = V4L2_PIX_FMT_YUV420,
74 | },
75 | {
76 | .name = "YUV 4:2:0 (M420)",
77 | .guid = UVC_GUID_FORMAT_M420,
78 | .fcc = V4L2_PIX_FMT_M420,
79 | },
80 | {
81 | .name = "YUV 4:2:2 (UYVY)",
82 | .guid = UVC_GUID_FORMAT_UYVY,
83 | .fcc = V4L2_PIX_FMT_UYVY,
84 | },
85 | {
86 | .name = "Greyscale 8-bit (Y800)",
87 | .guid = UVC_GUID_FORMAT_Y800,
88 | .fcc = V4L2_PIX_FMT_GREY,
89 | },
90 | {
91 | .name = "Greyscale 8-bit (Y8 )",
92 | .guid = UVC_GUID_FORMAT_Y8,
93 | .fcc = V4L2_PIX_FMT_GREY,
94 | },
95 | {
96 | .name = "Greyscale 10-bit (Y10 )",
97 | .guid = UVC_GUID_FORMAT_Y10,
98 | .fcc = V4L2_PIX_FMT_Y10,
99 | },
100 | {
101 | .name = "Greyscale 12-bit (Y12 )",
102 | .guid = UVC_GUID_FORMAT_Y12,
103 | .fcc = V4L2_PIX_FMT_Y12,
104 | },
105 | {
106 | .name = "Greyscale 16-bit (Y16 )",
107 | .guid = UVC_GUID_FORMAT_Y16,
108 | .fcc = V4L2_PIX_FMT_Y16,
109 | },
110 | {
111 | .name = "Greyscale 8 L/R (Y8I)",
112 | .guid = UVC_GUID_FORMAT_Y8I,
113 | .fcc = V4L2_PIX_FMT_Y8I,
114 | },
115 | {
116 | .name = "Greyscale 12 L/R (Y12I)",
117 | .guid = UVC_GUID_FORMAT_Y12I,
118 | .fcc = V4L2_PIX_FMT_Y12I,
119 | },
120 | {
121 | .name = "Depth data 16-bit (Z16)",
122 | .guid = UVC_GUID_FORMAT_Z16,
123 | .fcc = V4L2_PIX_FMT_Z16,
124 | },
125 | {
126 | .name = "Raw data 10-bit (RW10)",
127 | .guid = UVC_GUID_FORMAT_RW10,
128 | .fcc = V4L2_PIX_FMT_RW10,
129 | },
130 | {
131 | .name = "Depth 16-bit (INVZ)",
132 | .guid = UVC_GUID_FORMAT_INVZ,
133 | .fcc = V4L2_PIX_FMT_INVZ,
134 | },
135 | {
136 | .name = "Depth:IR 16:8 24-bit (INZI)",
137 | .guid = UVC_GUID_FORMAT_INZI,
138 | .fcc = V4L2_PIX_FMT_INZI,
139 | },
140 | {
141 | .name = "Depth 16-bit (INVR)",
142 | .guid = UVC_GUID_FORMAT_INVR,
143 | .fcc = V4L2_PIX_FMT_INVR,
144 | },
145 | {
146 | .name = "Depth:IR 16:8 24-bit (INRI)",
147 | .guid = UVC_GUID_FORMAT_INRI,
148 | .fcc = V4L2_PIX_FMT_INRI,
149 | },
150 | {
151 | .name = "Infrared 8-bit (INVI)",
152 | .guid = UVC_GUID_FORMAT_INVI,
153 | .fcc = V4L2_PIX_FMT_INVI,
154 | },
155 | {
156 | .name = "FlickerIR 8-bit (RELI)",
157 | .guid = UVC_GUID_FORMAT_RELI,
158 | .fcc = V4L2_PIX_FMT_RELI,
159 | },
160 | {
161 | .name = "BGGR Bayer (BY8 )",
162 | .guid = UVC_GUID_FORMAT_BY8,
163 | .fcc = V4L2_PIX_FMT_SBGGR8,
164 | },
165 | {
166 | .name = "RGB Bayer",
167 | .guid = UVC_GUID_FORMAT_BY8,
168 | .fcc = V4L2_PIX_FMT_SBGGR8,
169 | },
170 | {
171 | .name = "RGB565",
172 | .guid = UVC_GUID_FORMAT_RGBP,
173 | .fcc = V4L2_PIX_FMT_RGB565,
174 | },
175 | {
176 | .name = "H.264",
177 | .guid = UVC_GUID_FORMAT_H264,
178 | .fcc = V4L2_PIX_FMT_H264,
179 | }
180 | };
181 |
182 | /* ------------------------------------------------------------------------
183 | * Utility functions
184 | */
185 |
186 | struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
187 | __u8 epaddr)
188 | {
189 | struct usb_host_endpoint *ep;
190 | unsigned int i;
191 |
192 | for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
193 | ep = &alts->endpoint[i];
194 | if (ep->desc.bEndpointAddress == epaddr)
195 | return ep;
196 | }
197 |
198 | return NULL;
199 | }
200 |
201 | static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
202 | {
203 | unsigned int len = ARRAY_SIZE(uvc_fmts);
204 | unsigned int i;
205 |
206 | for (i = 0; i < len; ++i) {
207 | if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
208 | return &uvc_fmts[i];
209 | }
210 |
211 | return NULL;
212 | }
213 |
214 | static __u32 uvc_colorspace(const __u8 primaries)
215 | {
216 | static const __u8 colorprimaries[] = {
217 | 0,
218 | V4L2_COLORSPACE_SRGB,
219 | V4L2_COLORSPACE_470_SYSTEM_M,
220 | V4L2_COLORSPACE_470_SYSTEM_BG,
221 | V4L2_COLORSPACE_SMPTE170M,
222 | V4L2_COLORSPACE_SMPTE240M,
223 | };
224 |
225 | if (primaries < ARRAY_SIZE(colorprimaries))
226 | return colorprimaries[primaries];
227 |
228 | return 0;
229 | }
230 |
231 | /* Simplify a fraction using a simple continued fraction decomposition. The
232 | * idea here is to convert fractions such as 333333/10000000 to 1/30 using
233 | * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
234 | * arbitrary parameters to remove non-significative terms from the simple
235 | * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
236 | * respectively seems to give nice results.
237 | */
238 | void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
239 | unsigned int n_terms, unsigned int threshold)
240 | {
241 | uint32_t *an;
242 | uint32_t x, y, r;
243 | unsigned int i, n;
244 |
245 | an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
246 | if (an == NULL)
247 | return;
248 |
249 | /* Convert the fraction to a simple continued fraction. See
250 | * http://mathforum.org/dr.math/faq/faq.fractions.html
251 | * Stop if the current term is bigger than or equal to the given
252 | * threshold.
253 | */
254 | x = *numerator;
255 | y = *denominator;
256 |
257 | for (n = 0; n < n_terms && y != 0; ++n) {
258 | an[n] = x / y;
259 | if (an[n] >= threshold) {
260 | if (n < 2)
261 | n++;
262 | break;
263 | }
264 |
265 | r = x - an[n] * y;
266 | x = y;
267 | y = r;
268 | }
269 |
270 | /* Expand the simple continued fraction back to an integer fraction. */
271 | x = 0;
272 | y = 1;
273 |
274 | for (i = n; i > 0; --i) {
275 | r = y;
276 | y = an[i-1] * y + x;
277 | x = r;
278 | }
279 |
280 | *numerator = y;
281 | *denominator = x;
282 | kfree(an);
283 | }
284 |
285 | /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
286 | * to compute numerator / denominator * 10000000 using 32 bit fixed point
287 | * arithmetic only.
288 | */
289 | uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
290 | {
291 | uint32_t multiplier;
292 |
293 | /* Saturate the result if the operation would overflow. */
294 | if (denominator == 0 ||
295 | numerator/denominator >= ((uint32_t)-1)/10000000)
296 | return (uint32_t)-1;
297 |
298 | /* Divide both the denominator and the multiplier by two until
299 | * numerator * multiplier doesn't overflow. If anyone knows a better
300 | * algorithm please let me know.
301 | */
302 | multiplier = 10000000;
303 | while (numerator > ((uint32_t)-1)/multiplier) {
304 | multiplier /= 2;
305 | denominator /= 2;
306 | }
307 |
308 | return denominator ? numerator * multiplier / denominator : 0;
309 | }
310 |
311 | /* ------------------------------------------------------------------------
312 | * Terminal and unit management
313 | */
314 |
315 | struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
316 | {
317 | struct uvc_entity *entity;
318 |
319 | list_for_each_entry(entity, &dev->entities, list) {
320 | if (entity->id == id)
321 | return entity;
322 | }
323 |
324 | return NULL;
325 | }
326 |
327 | static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
328 | int id, struct uvc_entity *entity)
329 | {
330 | unsigned int i;
331 |
332 | if (entity == NULL)
333 | entity = list_entry(&dev->entities, struct uvc_entity, list);
334 |
335 | list_for_each_entry_continue(entity, &dev->entities, list) {
336 | for (i = 0; i < entity->bNrInPins; ++i)
337 | if (entity->baSourceID[i] == id)
338 | return entity;
339 | }
340 |
341 | return NULL;
342 | }
343 |
344 | static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
345 | {
346 | struct uvc_streaming *stream;
347 |
348 | list_for_each_entry(stream, &dev->streams, list) {
349 | if (stream->header.bTerminalLink == id)
350 | return stream;
351 | }
352 |
353 | return NULL;
354 | }
355 |
356 | /* ------------------------------------------------------------------------
357 | * Descriptors parsing
358 | */
359 |
360 | static int uvc_parse_format(struct uvc_device *dev,
361 | struct uvc_streaming *streaming, struct uvc_format *format,
362 | __u32 **intervals, unsigned char *buffer, int buflen)
363 | {
364 | struct usb_interface *intf = streaming->intf;
365 | struct usb_host_interface *alts = intf->cur_altsetting;
366 | struct uvc_format_desc *fmtdesc;
367 | struct uvc_frame *frame;
368 | const unsigned char *start = buffer;
369 | unsigned int interval;
370 | unsigned int i, n;
371 | __u8 ftype;
372 |
373 | format->type = buffer[2];
374 | format->index = buffer[3];
375 |
376 | switch (buffer[2]) {
377 | case UVC_VS_FORMAT_UNCOMPRESSED:
378 | case UVC_VS_FORMAT_FRAME_BASED:
379 | n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
380 | if (buflen < n) {
381 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
382 | "interface %d FORMAT error\n",
383 | dev->udev->devnum,
384 | alts->desc.bInterfaceNumber);
385 | return -EINVAL;
386 | }
387 |
388 | /* Find the format descriptor from its GUID. */
389 | fmtdesc = uvc_format_by_guid(&buffer[5]);
390 |
391 | if (fmtdesc != NULL) {
392 | strlcpy(format->name, fmtdesc->name,
393 | sizeof format->name);
394 | format->fcc = fmtdesc->fcc;
395 | } else {
396 | uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
397 | &buffer[5]);
398 | snprintf(format->name, sizeof(format->name), "%pUl\n",
399 | &buffer[5]);
400 | format->fcc = 0;
401 | }
402 |
403 | format->bpp = buffer[21];
404 | if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
405 | ftype = UVC_VS_FRAME_UNCOMPRESSED;
406 | } else {
407 | ftype = UVC_VS_FRAME_FRAME_BASED;
408 | if (buffer[27])
409 | format->flags = UVC_FMT_FLAG_COMPRESSED;
410 | }
411 | break;
412 |
413 | case UVC_VS_FORMAT_MJPEG:
414 | if (buflen < 11) {
415 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
416 | "interface %d FORMAT error\n",
417 | dev->udev->devnum,
418 | alts->desc.bInterfaceNumber);
419 | return -EINVAL;
420 | }
421 |
422 | strlcpy(format->name, "MJPEG", sizeof format->name);
423 | format->fcc = V4L2_PIX_FMT_MJPEG;
424 | format->flags = UVC_FMT_FLAG_COMPRESSED;
425 | format->bpp = 0;
426 | ftype = UVC_VS_FRAME_MJPEG;
427 | break;
428 |
429 | case UVC_VS_FORMAT_DV:
430 | if (buflen < 9) {
431 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
432 | "interface %d FORMAT error\n",
433 | dev->udev->devnum,
434 | alts->desc.bInterfaceNumber);
435 | return -EINVAL;
436 | }
437 |
438 | switch (buffer[8] & 0x7f) {
439 | case 0:
440 | strlcpy(format->name, "SD-DV", sizeof format->name);
441 | break;
442 | case 1:
443 | strlcpy(format->name, "SDL-DV", sizeof format->name);
444 | break;
445 | case 2:
446 | strlcpy(format->name, "HD-DV", sizeof format->name);
447 | break;
448 | default:
449 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
450 | "interface %d: unknown DV format %u\n",
451 | dev->udev->devnum,
452 | alts->desc.bInterfaceNumber, buffer[8]);
453 | return -EINVAL;
454 | }
455 |
456 | strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
457 | sizeof format->name);
458 |
459 | format->fcc = V4L2_PIX_FMT_DV;
460 | format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
461 | format->bpp = 0;
462 | ftype = 0;
463 |
464 | /* Create a dummy frame descriptor. */
465 | frame = &format->frame[0];
466 | memset(&format->frame[0], 0, sizeof format->frame[0]);
467 | frame->bFrameIntervalType = 1;
468 | frame->dwDefaultFrameInterval = 1;
469 | frame->dwFrameInterval = *intervals;
470 | *(*intervals)++ = 1;
471 | format->nframes = 1;
472 | break;
473 |
474 | case UVC_VS_FORMAT_MPEG2TS:
475 | case UVC_VS_FORMAT_STREAM_BASED:
476 | /* Not supported yet. */
477 | default:
478 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
479 | "interface %d unsupported format %u\n",
480 | dev->udev->devnum, alts->desc.bInterfaceNumber,
481 | buffer[2]);
482 | return -EINVAL;
483 | }
484 |
485 | uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
486 |
487 | buflen -= buffer[0];
488 | buffer += buffer[0];
489 |
490 | /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
491 | * based formats have frame descriptors.
492 | */
493 | while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
494 | buffer[2] == ftype) {
495 | frame = &format->frame[format->nframes];
496 | if (ftype != UVC_VS_FRAME_FRAME_BASED)
497 | n = buflen > 25 ? buffer[25] : 0;
498 | else
499 | n = buflen > 21 ? buffer[21] : 0;
500 |
501 | n = n ? n : 3;
502 |
503 | if (buflen < 26 + 4*n) {
504 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
505 | "interface %d FRAME error\n", dev->udev->devnum,
506 | alts->desc.bInterfaceNumber);
507 | return -EINVAL;
508 | }
509 |
510 | frame->bFrameIndex = buffer[3];
511 | frame->bmCapabilities = buffer[4];
512 | frame->wWidth = get_unaligned_le16(&buffer[5]);
513 | frame->wHeight = get_unaligned_le16(&buffer[7]);
514 | frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
515 | frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
516 | if (ftype != UVC_VS_FRAME_FRAME_BASED) {
517 | frame->dwMaxVideoFrameBufferSize =
518 | get_unaligned_le32(&buffer[17]);
519 | frame->dwDefaultFrameInterval =
520 | get_unaligned_le32(&buffer[21]);
521 | frame->bFrameIntervalType = buffer[25];
522 | } else {
523 | frame->dwMaxVideoFrameBufferSize = 0;
524 | frame->dwDefaultFrameInterval =
525 | get_unaligned_le32(&buffer[17]);
526 | frame->bFrameIntervalType = buffer[21];
527 | }
528 | frame->dwFrameInterval = *intervals;
529 |
530 | /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
531 | * completely. Observed behaviours range from setting the
532 | * value to 1.1x the actual frame size to hardwiring the
533 | * 16 low bits to 0. This results in a higher than necessary
534 | * memory usage as well as a wrong image size information. For
535 | * uncompressed formats this can be fixed by computing the
536 | * value from the frame size.
537 | */
538 | if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
539 | frame->dwMaxVideoFrameBufferSize = format->bpp
540 | * frame->wWidth * frame->wHeight / 8;
541 |
542 | /* Some bogus devices report dwMinFrameInterval equal to
543 | * dwMaxFrameInterval and have dwFrameIntervalStep set to
544 | * zero. Setting all null intervals to 1 fixes the problem and
545 | * some other divisions by zero that could happen.
546 | */
547 | for (i = 0; i < n; ++i) {
548 | interval = get_unaligned_le32(&buffer[26+4*i]);
549 | *(*intervals)++ = interval ? interval : 1;
550 | }
551 |
552 | /* Make sure that the default frame interval stays between
553 | * the boundaries.
554 | */
555 | n -= frame->bFrameIntervalType ? 1 : 2;
556 | frame->dwDefaultFrameInterval =
557 | min(frame->dwFrameInterval[n],
558 | max(frame->dwFrameInterval[0],
559 | frame->dwDefaultFrameInterval));
560 |
561 | if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
562 | frame->bFrameIntervalType = 1;
563 | frame->dwFrameInterval[0] =
564 | frame->dwDefaultFrameInterval;
565 | }
566 |
567 | uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
568 | frame->wWidth, frame->wHeight,
569 | 10000000/frame->dwDefaultFrameInterval,
570 | (100000000/frame->dwDefaultFrameInterval)%10);
571 |
572 | format->nframes++;
573 | buflen -= buffer[0];
574 | buffer += buffer[0];
575 | }
576 |
577 | if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
578 | buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
579 | buflen -= buffer[0];
580 | buffer += buffer[0];
581 | }
582 |
583 | if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
584 | buffer[2] == UVC_VS_COLORFORMAT) {
585 | if (buflen < 6) {
586 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
587 | "interface %d COLORFORMAT error\n",
588 | dev->udev->devnum,
589 | alts->desc.bInterfaceNumber);
590 | return -EINVAL;
591 | }
592 |
593 | format->colorspace = uvc_colorspace(buffer[3]);
594 |
595 | buflen -= buffer[0];
596 | buffer += buffer[0];
597 | }
598 |
599 | return buffer - start;
600 | }
601 |
602 | static int uvc_parse_streaming(struct uvc_device *dev,
603 | struct usb_interface *intf)
604 | {
605 | struct uvc_streaming *streaming = NULL;
606 | struct uvc_format *format;
607 | struct uvc_frame *frame;
608 | struct usb_host_interface *alts = &intf->altsetting[0];
609 | unsigned char *_buffer, *buffer = alts->extra;
610 | int _buflen, buflen = alts->extralen;
611 | unsigned int nformats = 0, nframes = 0, nintervals = 0;
612 | unsigned int size, i, n, p;
613 | __u32 *interval;
614 | __u16 psize;
615 | int ret = -EINVAL;
616 |
617 | if (intf->cur_altsetting->desc.bInterfaceSubClass
618 | != UVC_SC_VIDEOSTREAMING) {
619 | uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
620 | "video streaming interface\n", dev->udev->devnum,
621 | intf->altsetting[0].desc.bInterfaceNumber);
622 | return -EINVAL;
623 | }
624 |
625 | if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
626 | uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
627 | "claimed\n", dev->udev->devnum,
628 | intf->altsetting[0].desc.bInterfaceNumber);
629 | return -EINVAL;
630 | }
631 |
632 | streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
633 | if (streaming == NULL) {
634 | usb_driver_release_interface(&uvc_driver.driver, intf);
635 | return -EINVAL;
636 | }
637 |
638 | mutex_init(&streaming->mutex);
639 | streaming->dev = dev;
640 | streaming->intf = usb_get_intf(intf);
641 | streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
642 |
643 | /* The Pico iMage webcam has its class-specific interface descriptors
644 | * after the endpoint descriptors.
645 | */
646 | if (buflen == 0) {
647 | for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
648 | struct usb_host_endpoint *ep = &alts->endpoint[i];
649 |
650 | if (ep->extralen == 0)
651 | continue;
652 |
653 | if (ep->extralen > 2 &&
654 | ep->extra[1] == USB_DT_CS_INTERFACE) {
655 | uvc_trace(UVC_TRACE_DESCR, "trying extra data "
656 | "from endpoint %u.\n", i);
657 | buffer = alts->endpoint[i].extra;
658 | buflen = alts->endpoint[i].extralen;
659 | break;
660 | }
661 | }
662 | }
663 |
664 | /* Skip the standard interface descriptors. */
665 | while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
666 | buflen -= buffer[0];
667 | buffer += buffer[0];
668 | }
669 |
670 | if (buflen <= 2) {
671 | uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
672 | "interface descriptors found.\n");
673 | goto error;
674 | }
675 |
676 | /* Parse the header descriptor. */
677 | switch (buffer[2]) {
678 | case UVC_VS_OUTPUT_HEADER:
679 | streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
680 | size = 9;
681 | break;
682 |
683 | case UVC_VS_INPUT_HEADER:
684 | streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
685 | size = 13;
686 | break;
687 |
688 | default:
689 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
690 | "%d HEADER descriptor not found.\n", dev->udev->devnum,
691 | alts->desc.bInterfaceNumber);
692 | goto error;
693 | }
694 |
695 | p = buflen >= 4 ? buffer[3] : 0;
696 | n = buflen >= size ? buffer[size-1] : 0;
697 |
698 | if (buflen < size + p*n) {
699 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
700 | "interface %d HEADER descriptor is invalid.\n",
701 | dev->udev->devnum, alts->desc.bInterfaceNumber);
702 | goto error;
703 | }
704 |
705 | streaming->header.bNumFormats = p;
706 | streaming->header.bEndpointAddress = buffer[6];
707 | if (buffer[2] == UVC_VS_INPUT_HEADER) {
708 | streaming->header.bmInfo = buffer[7];
709 | streaming->header.bTerminalLink = buffer[8];
710 | streaming->header.bStillCaptureMethod = buffer[9];
711 | streaming->header.bTriggerSupport = buffer[10];
712 | streaming->header.bTriggerUsage = buffer[11];
713 | } else {
714 | streaming->header.bTerminalLink = buffer[7];
715 | }
716 | streaming->header.bControlSize = n;
717 |
718 | streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
719 | GFP_KERNEL);
720 | if (streaming->header.bmaControls == NULL) {
721 | ret = -ENOMEM;
722 | goto error;
723 | }
724 |
725 | buflen -= buffer[0];
726 | buffer += buffer[0];
727 |
728 | _buffer = buffer;
729 | _buflen = buflen;
730 |
731 | /* Count the format and frame descriptors. */
732 | while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
733 | switch (_buffer[2]) {
734 | case UVC_VS_FORMAT_UNCOMPRESSED:
735 | case UVC_VS_FORMAT_MJPEG:
736 | case UVC_VS_FORMAT_FRAME_BASED:
737 | nformats++;
738 | break;
739 |
740 | case UVC_VS_FORMAT_DV:
741 | /* DV format has no frame descriptor. We will create a
742 | * dummy frame descriptor with a dummy frame interval.
743 | */
744 | nformats++;
745 | nframes++;
746 | nintervals++;
747 | break;
748 |
749 | case UVC_VS_FORMAT_MPEG2TS:
750 | case UVC_VS_FORMAT_STREAM_BASED:
751 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
752 | "interface %d FORMAT %u is not supported.\n",
753 | dev->udev->devnum,
754 | alts->desc.bInterfaceNumber, _buffer[2]);
755 | break;
756 |
757 | case UVC_VS_FRAME_UNCOMPRESSED:
758 | case UVC_VS_FRAME_MJPEG:
759 | nframes++;
760 | if (_buflen > 25)
761 | nintervals += _buffer[25] ? _buffer[25] : 3;
762 | break;
763 |
764 | case UVC_VS_FRAME_FRAME_BASED:
765 | nframes++;
766 | if (_buflen > 21)
767 | nintervals += _buffer[21] ? _buffer[21] : 3;
768 | break;
769 | }
770 |
771 | _buflen -= _buffer[0];
772 | _buffer += _buffer[0];
773 | }
774 |
775 | if (nformats == 0) {
776 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
777 | "%d has no supported formats defined.\n",
778 | dev->udev->devnum, alts->desc.bInterfaceNumber);
779 | goto error;
780 | }
781 |
782 | size = nformats * sizeof *format + nframes * sizeof *frame
783 | + nintervals * sizeof *interval;
784 | format = kzalloc(size, GFP_KERNEL);
785 | if (format == NULL) {
786 | ret = -ENOMEM;
787 | goto error;
788 | }
789 |
790 | frame = (struct uvc_frame *)&format[nformats];
791 | interval = (__u32 *)&frame[nframes];
792 |
793 | streaming->format = format;
794 | streaming->nformats = nformats;
795 |
796 | /* Parse the format descriptors. */
797 | while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
798 | switch (buffer[2]) {
799 | case UVC_VS_FORMAT_UNCOMPRESSED:
800 | case UVC_VS_FORMAT_MJPEG:
801 | case UVC_VS_FORMAT_DV:
802 | case UVC_VS_FORMAT_FRAME_BASED:
803 | format->frame = frame;
804 | ret = uvc_parse_format(dev, streaming, format,
805 | &interval, buffer, buflen);
806 | if (ret < 0)
807 | goto error;
808 |
809 | frame += format->nframes;
810 | format++;
811 |
812 | buflen -= ret;
813 | buffer += ret;
814 | continue;
815 |
816 | default:
817 | break;
818 | }
819 |
820 | buflen -= buffer[0];
821 | buffer += buffer[0];
822 | }
823 |
824 | if (buflen)
825 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
826 | "%d has %u bytes of trailing descriptor garbage.\n",
827 | dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
828 |
829 | /* Parse the alternate settings to find the maximum bandwidth. */
830 | for (i = 0; i < intf->num_altsetting; ++i) {
831 | struct usb_host_endpoint *ep;
832 | alts = &intf->altsetting[i];
833 | ep = uvc_find_endpoint(alts,
834 | streaming->header.bEndpointAddress);
835 | if (ep == NULL)
836 | continue;
837 |
838 | psize = le16_to_cpu(ep->desc.wMaxPacketSize);
839 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
840 | if (psize > streaming->maxpsize)
841 | streaming->maxpsize = psize;
842 | }
843 |
844 | list_add_tail(&streaming->list, &dev->streams);
845 | return 0;
846 |
847 | error:
848 | usb_driver_release_interface(&uvc_driver.driver, intf);
849 | usb_put_intf(intf);
850 | kfree(streaming->format);
851 | kfree(streaming->header.bmaControls);
852 | kfree(streaming);
853 | return ret;
854 | }
855 |
856 | static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
857 | unsigned int num_pads, unsigned int extra_size)
858 | {
859 | struct uvc_entity *entity;
860 | unsigned int num_inputs;
861 | unsigned int size;
862 | unsigned int i;
863 |
864 | extra_size = ALIGN(extra_size, sizeof(*entity->pads));
865 | num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
866 | size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
867 | + num_inputs;
868 | entity = kzalloc(size, GFP_KERNEL);
869 | if (entity == NULL)
870 | return NULL;
871 |
872 | entity->id = id;
873 | entity->type = type;
874 |
875 | entity->num_links = 0;
876 | entity->num_pads = num_pads;
877 | entity->pads = ((void *)(entity + 1)) + extra_size;
878 |
879 | for (i = 0; i < num_inputs; ++i)
880 | entity->pads[i].flags = MEDIA_PAD_FL_SINK;
881 | if (!UVC_ENTITY_IS_OTERM(entity))
882 | entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
883 |
884 | entity->bNrInPins = num_inputs;
885 | entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
886 |
887 | return entity;
888 | }
889 |
890 | /* Parse vendor-specific extensions. */
891 | static int uvc_parse_vendor_control(struct uvc_device *dev,
892 | const unsigned char *buffer, int buflen)
893 | {
894 | struct usb_device *udev = dev->udev;
895 | struct usb_host_interface *alts = dev->intf->cur_altsetting;
896 | struct uvc_entity *unit;
897 | unsigned int n, p;
898 | int handled = 0;
899 |
900 | switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
901 | case 0x046d: /* Logitech */
902 | if (buffer[1] != 0x41 || buffer[2] != 0x01)
903 | break;
904 |
905 | /* Logitech implements several vendor specific functions
906 | * through vendor specific extension units (LXU).
907 | *
908 | * The LXU descriptors are similar to XU descriptors
909 | * (see "USB Device Video Class for Video Devices", section
910 | * 3.7.2.6 "Extension Unit Descriptor") with the following
911 | * differences:
912 | *
913 | * ----------------------------------------------------------
914 | * 0 bLength 1 Number
915 | * Size of this descriptor, in bytes: 24+p+n*2
916 | * ----------------------------------------------------------
917 | * 23+p+n bmControlsType N Bitmap
918 | * Individual bits in the set are defined:
919 | * 0: Absolute
920 | * 1: Relative
921 | *
922 | * This bitset is mapped exactly the same as bmControls.
923 | * ----------------------------------------------------------
924 | * 23+p+n*2 bReserved 1 Boolean
925 | * ----------------------------------------------------------
926 | * 24+p+n*2 iExtension 1 Index
927 | * Index of a string descriptor that describes this
928 | * extension unit.
929 | * ----------------------------------------------------------
930 | */
931 | p = buflen >= 22 ? buffer[21] : 0;
932 | n = buflen >= 25 + p ? buffer[22+p] : 0;
933 |
934 | if (buflen < 25 + p + 2*n) {
935 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
936 | "interface %d EXTENSION_UNIT error\n",
937 | udev->devnum, alts->desc.bInterfaceNumber);
938 | break;
939 | }
940 |
941 | unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
942 | p + 1, 2*n);
943 | if (unit == NULL)
944 | return -ENOMEM;
945 |
946 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
947 | unit->extension.bNumControls = buffer[20];
948 | memcpy(unit->baSourceID, &buffer[22], p);
949 | unit->extension.bControlSize = buffer[22+p];
950 | unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
951 | unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
952 | + n;
953 | memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
954 |
955 | if (buffer[24+p+2*n] != 0)
956 | usb_string(udev, buffer[24+p+2*n], unit->name,
957 | sizeof unit->name);
958 | else
959 | sprintf(unit->name, "Extension %u", buffer[3]);
960 |
961 | list_add_tail(&unit->list, &dev->entities);
962 | handled = 1;
963 | break;
964 | }
965 |
966 | return handled;
967 | }
968 |
969 | static int uvc_parse_standard_control(struct uvc_device *dev,
970 | const unsigned char *buffer, int buflen)
971 | {
972 | struct usb_device *udev = dev->udev;
973 | struct uvc_entity *unit, *term;
974 | struct usb_interface *intf;
975 | struct usb_host_interface *alts = dev->intf->cur_altsetting;
976 | unsigned int i, n, p, len;
977 | __u16 type;
978 |
979 | switch (buffer[2]) {
980 | case UVC_VC_HEADER:
981 | n = buflen >= 12 ? buffer[11] : 0;
982 |
983 | if (buflen < 12 || buflen < 12 + n) {
984 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
985 | "interface %d HEADER error\n", udev->devnum,
986 | alts->desc.bInterfaceNumber);
987 | return -EINVAL;
988 | }
989 |
990 | dev->uvc_version = get_unaligned_le16(&buffer[3]);
991 | dev->clock_frequency = get_unaligned_le32(&buffer[7]);
992 |
993 | /* Parse all USB Video Streaming interfaces. */
994 | for (i = 0; i < n; ++i) {
995 | intf = usb_ifnum_to_if(udev, buffer[12+i]);
996 | if (intf == NULL) {
997 | uvc_trace(UVC_TRACE_DESCR, "device %d "
998 | "interface %d doesn't exists\n",
999 | udev->devnum, i);
1000 | continue;
1001 | }
1002 |
1003 | uvc_parse_streaming(dev, intf);
1004 | }
1005 | break;
1006 |
1007 | case UVC_VC_INPUT_TERMINAL:
1008 | if (buflen < 8) {
1009 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1010 | "interface %d INPUT_TERMINAL error\n",
1011 | udev->devnum, alts->desc.bInterfaceNumber);
1012 | return -EINVAL;
1013 | }
1014 |
1015 | /* Make sure the terminal type MSB is not null, otherwise it
1016 | * could be confused with a unit.
1017 | */
1018 | type = get_unaligned_le16(&buffer[4]);
1019 | if ((type & 0xff00) == 0) {
1020 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1021 | "interface %d INPUT_TERMINAL %d has invalid "
1022 | "type 0x%04x, skipping\n", udev->devnum,
1023 | alts->desc.bInterfaceNumber,
1024 | buffer[3], type);
1025 | return 0;
1026 | }
1027 |
1028 | n = 0;
1029 | p = 0;
1030 | len = 8;
1031 |
1032 | if (type == UVC_ITT_CAMERA) {
1033 | n = buflen >= 15 ? buffer[14] : 0;
1034 | len = 15;
1035 |
1036 | } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1037 | n = buflen >= 9 ? buffer[8] : 0;
1038 | p = buflen >= 10 + n ? buffer[9+n] : 0;
1039 | len = 10;
1040 | }
1041 |
1042 | if (buflen < len + n + p) {
1043 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1044 | "interface %d INPUT_TERMINAL error\n",
1045 | udev->devnum, alts->desc.bInterfaceNumber);
1046 | return -EINVAL;
1047 | }
1048 |
1049 | term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1050 | 1, n + p);
1051 | if (term == NULL)
1052 | return -ENOMEM;
1053 |
1054 | if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1055 | term->camera.bControlSize = n;
1056 | term->camera.bmControls = (__u8 *)term + sizeof *term;
1057 | term->camera.wObjectiveFocalLengthMin =
1058 | get_unaligned_le16(&buffer[8]);
1059 | term->camera.wObjectiveFocalLengthMax =
1060 | get_unaligned_le16(&buffer[10]);
1061 | term->camera.wOcularFocalLength =
1062 | get_unaligned_le16(&buffer[12]);
1063 | memcpy(term->camera.bmControls, &buffer[15], n);
1064 | } else if (UVC_ENTITY_TYPE(term) ==
1065 | UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1066 | term->media.bControlSize = n;
1067 | term->media.bmControls = (__u8 *)term + sizeof *term;
1068 | term->media.bTransportModeSize = p;
1069 | term->media.bmTransportModes = (__u8 *)term
1070 | + sizeof *term + n;
1071 | memcpy(term->media.bmControls, &buffer[9], n);
1072 | memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1073 | }
1074 |
1075 | if (buffer[7] != 0)
1076 | usb_string(udev, buffer[7], term->name,
1077 | sizeof term->name);
1078 | else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1079 | sprintf(term->name, "Camera %u", buffer[3]);
1080 | else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1081 | sprintf(term->name, "Media %u", buffer[3]);
1082 | else
1083 | sprintf(term->name, "Input %u", buffer[3]);
1084 |
1085 | list_add_tail(&term->list, &dev->entities);
1086 | break;
1087 |
1088 | case UVC_VC_OUTPUT_TERMINAL:
1089 | if (buflen < 9) {
1090 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1091 | "interface %d OUTPUT_TERMINAL error\n",
1092 | udev->devnum, alts->desc.bInterfaceNumber);
1093 | return -EINVAL;
1094 | }
1095 |
1096 | /* Make sure the terminal type MSB is not null, otherwise it
1097 | * could be confused with a unit.
1098 | */
1099 | type = get_unaligned_le16(&buffer[4]);
1100 | if ((type & 0xff00) == 0) {
1101 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1102 | "interface %d OUTPUT_TERMINAL %d has invalid "
1103 | "type 0x%04x, skipping\n", udev->devnum,
1104 | alts->desc.bInterfaceNumber, buffer[3], type);
1105 | return 0;
1106 | }
1107 |
1108 | term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1109 | 1, 0);
1110 | if (term == NULL)
1111 | return -ENOMEM;
1112 |
1113 | memcpy(term->baSourceID, &buffer[7], 1);
1114 |
1115 | if (buffer[8] != 0)
1116 | usb_string(udev, buffer[8], term->name,
1117 | sizeof term->name);
1118 | else
1119 | sprintf(term->name, "Output %u", buffer[3]);
1120 |
1121 | list_add_tail(&term->list, &dev->entities);
1122 | break;
1123 |
1124 | case UVC_VC_SELECTOR_UNIT:
1125 | p = buflen >= 5 ? buffer[4] : 0;
1126 |
1127 | if (buflen < 5 || buflen < 6 + p) {
1128 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1129 | "interface %d SELECTOR_UNIT error\n",
1130 | udev->devnum, alts->desc.bInterfaceNumber);
1131 | return -EINVAL;
1132 | }
1133 |
1134 | unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1135 | if (unit == NULL)
1136 | return -ENOMEM;
1137 |
1138 | memcpy(unit->baSourceID, &buffer[5], p);
1139 |
1140 | if (buffer[5+p] != 0)
1141 | usb_string(udev, buffer[5+p], unit->name,
1142 | sizeof unit->name);
1143 | else
1144 | sprintf(unit->name, "Selector %u", buffer[3]);
1145 |
1146 | list_add_tail(&unit->list, &dev->entities);
1147 | break;
1148 |
1149 | case UVC_VC_PROCESSING_UNIT:
1150 | n = buflen >= 8 ? buffer[7] : 0;
1151 | p = dev->uvc_version >= 0x0110 ? 10 : 9;
1152 |
1153 | if (buflen < p + n) {
1154 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1155 | "interface %d PROCESSING_UNIT error\n",
1156 | udev->devnum, alts->desc.bInterfaceNumber);
1157 | return -EINVAL;
1158 | }
1159 |
1160 | unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1161 | if (unit == NULL)
1162 | return -ENOMEM;
1163 |
1164 | memcpy(unit->baSourceID, &buffer[4], 1);
1165 | unit->processing.wMaxMultiplier =
1166 | get_unaligned_le16(&buffer[5]);
1167 | unit->processing.bControlSize = buffer[7];
1168 | unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1169 | memcpy(unit->processing.bmControls, &buffer[8], n);
1170 | if (dev->uvc_version >= 0x0110)
1171 | unit->processing.bmVideoStandards = buffer[9+n];
1172 |
1173 | if (buffer[8+n] != 0)
1174 | usb_string(udev, buffer[8+n], unit->name,
1175 | sizeof unit->name);
1176 | else
1177 | sprintf(unit->name, "Processing %u", buffer[3]);
1178 |
1179 | list_add_tail(&unit->list, &dev->entities);
1180 | break;
1181 |
1182 | case UVC_VC_EXTENSION_UNIT:
1183 | p = buflen >= 22 ? buffer[21] : 0;
1184 | n = buflen >= 24 + p ? buffer[22+p] : 0;
1185 |
1186 | if (buflen < 24 + p + n) {
1187 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1188 | "interface %d EXTENSION_UNIT error\n",
1189 | udev->devnum, alts->desc.bInterfaceNumber);
1190 | return -EINVAL;
1191 | }
1192 |
1193 | unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1194 | if (unit == NULL)
1195 | return -ENOMEM;
1196 |
1197 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1198 | unit->extension.bNumControls = buffer[20];
1199 | memcpy(unit->baSourceID, &buffer[22], p);
1200 | unit->extension.bControlSize = buffer[22+p];
1201 | unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1202 | memcpy(unit->extension.bmControls, &buffer[23+p], n);
1203 |
1204 | if (buffer[23+p+n] != 0)
1205 | usb_string(udev, buffer[23+p+n], unit->name,
1206 | sizeof unit->name);
1207 | else
1208 | sprintf(unit->name, "Extension %u", buffer[3]);
1209 |
1210 | list_add_tail(&unit->list, &dev->entities);
1211 | break;
1212 |
1213 | default:
1214 | uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1215 | "descriptor (%u)\n", buffer[2]);
1216 | break;
1217 | }
1218 |
1219 | return 0;
1220 | }
1221 |
1222 | static int uvc_parse_control(struct uvc_device *dev)
1223 | {
1224 | struct usb_host_interface *alts = dev->intf->cur_altsetting;
1225 | unsigned char *buffer = alts->extra;
1226 | int buflen = alts->extralen;
1227 | int ret;
1228 |
1229 | /* Parse the default alternate setting only, as the UVC specification
1230 | * defines a single alternate setting, the default alternate setting
1231 | * zero.
1232 | */
1233 |
1234 | while (buflen > 2) {
1235 | if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1236 | buffer[1] != USB_DT_CS_INTERFACE)
1237 | goto next_descriptor;
1238 |
1239 | if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1240 | return ret;
1241 |
1242 | next_descriptor:
1243 | buflen -= buffer[0];
1244 | buffer += buffer[0];
1245 | }
1246 |
1247 | /* Check if the optional status endpoint is present. Built-in iSight
1248 | * webcams have an interrupt endpoint but spit proprietary data that
1249 | * don't conform to the UVC status endpoint messages. Don't try to
1250 | * handle the interrupt endpoint for those cameras.
1251 | */
1252 | if (alts->desc.bNumEndpoints == 1 &&
1253 | !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1254 | struct usb_host_endpoint *ep = &alts->endpoint[0];
1255 | struct usb_endpoint_descriptor *desc = &ep->desc;
1256 |
1257 | if (usb_endpoint_is_int_in(desc) &&
1258 | le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1259 | desc->bInterval != 0) {
1260 | uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1261 | "(addr %02x).\n", desc->bEndpointAddress);
1262 | dev->int_ep = ep;
1263 | }
1264 | }
1265 |
1266 | return 0;
1267 | }
1268 |
1269 | /* ------------------------------------------------------------------------
1270 | * UVC device scan
1271 | */
1272 |
1273 | /*
1274 | * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1275 | * and containing the following units:
1276 | *
1277 | * - one or more Output Terminals (USB Streaming or Display)
1278 | * - zero or one Processing Unit
1279 | * - zero, one or more single-input Selector Units
1280 | * - zero or one multiple-input Selector Units, provided all inputs are
1281 | * connected to input terminals
1282 | * - zero, one or mode single-input Extension Units
1283 | * - one or more Input Terminals (Camera, External or USB Streaming)
1284 | *
1285 | * The terminal and units must match on of the following structures:
1286 | *
1287 | * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1288 | * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1289 | * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1290 | *
1291 | * +---------+ +---------+ -> OTT_*(0)
1292 | * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1293 | * +---------+ +---------+ -> OTT_*(n)
1294 | *
1295 | * The Processing Unit and Extension Units can be in any order. Additional
1296 | * Extension Units connected to the main chain as single-unit branches are
1297 | * also supported. Single-input Selector Units are ignored.
1298 | */
1299 | static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1300 | struct uvc_entity *entity)
1301 | {
1302 | switch (UVC_ENTITY_TYPE(entity)) {
1303 | case UVC_VC_EXTENSION_UNIT:
1304 | if (uvc_trace_param & UVC_TRACE_PROBE)
1305 | printk(" <- XU %d", entity->id);
1306 |
1307 | if (entity->bNrInPins != 1) {
1308 | uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1309 | "than 1 input pin.\n", entity->id);
1310 | return -1;
1311 | }
1312 |
1313 | break;
1314 |
1315 | case UVC_VC_PROCESSING_UNIT:
1316 | if (uvc_trace_param & UVC_TRACE_PROBE)
1317 | printk(" <- PU %d", entity->id);
1318 |
1319 | if (chain->processing != NULL) {
1320 | uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1321 | "Processing Units in chain.\n");
1322 | return -1;
1323 | }
1324 |
1325 | chain->processing = entity;
1326 | break;
1327 |
1328 | case UVC_VC_SELECTOR_UNIT:
1329 | if (uvc_trace_param & UVC_TRACE_PROBE)
1330 | printk(" <- SU %d", entity->id);
1331 |
1332 | /* Single-input selector units are ignored. */
1333 | if (entity->bNrInPins == 1)
1334 | break;
1335 |
1336 | if (chain->selector != NULL) {
1337 | uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1338 | "Units in chain.\n");
1339 | return -1;
1340 | }
1341 |
1342 | chain->selector = entity;
1343 | break;
1344 |
1345 | case UVC_ITT_VENDOR_SPECIFIC:
1346 | case UVC_ITT_CAMERA:
1347 | case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1348 | if (uvc_trace_param & UVC_TRACE_PROBE)
1349 | printk(" <- IT %d\n", entity->id);
1350 |
1351 | break;
1352 |
1353 | case UVC_OTT_VENDOR_SPECIFIC:
1354 | case UVC_OTT_DISPLAY:
1355 | case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1356 | if (uvc_trace_param & UVC_TRACE_PROBE)
1357 | printk(" OT %d", entity->id);
1358 |
1359 | break;
1360 |
1361 | case UVC_TT_STREAMING:
1362 | if (UVC_ENTITY_IS_ITERM(entity)) {
1363 | if (uvc_trace_param & UVC_TRACE_PROBE)
1364 | printk(" <- IT %d\n", entity->id);
1365 | } else {
1366 | if (uvc_trace_param & UVC_TRACE_PROBE)
1367 | printk(" OT %d", entity->id);
1368 | }
1369 |
1370 | break;
1371 |
1372 | default:
1373 | uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1374 | "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1375 | return -1;
1376 | }
1377 |
1378 | list_add_tail(&entity->chain, &chain->entities);
1379 | return 0;
1380 | }
1381 |
1382 | static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1383 | struct uvc_entity *entity, struct uvc_entity *prev)
1384 | {
1385 | struct uvc_entity *forward;
1386 | int found;
1387 |
1388 | /* Forward scan */
1389 | forward = NULL;
1390 | found = 0;
1391 |
1392 | while (1) {
1393 | forward = uvc_entity_by_reference(chain->dev, entity->id,
1394 | forward);
1395 | if (forward == NULL)
1396 | break;
1397 | if (forward == prev)
1398 | continue;
1399 |
1400 | switch (UVC_ENTITY_TYPE(forward)) {
1401 | case UVC_VC_EXTENSION_UNIT:
1402 | if (forward->bNrInPins != 1) {
1403 | uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1404 | "has more than 1 input pin.\n",
1405 | entity->id);
1406 | return -EINVAL;
1407 | }
1408 |
1409 | list_add_tail(&forward->chain, &chain->entities);
1410 | if (uvc_trace_param & UVC_TRACE_PROBE) {
1411 | if (!found)
1412 | printk(" (->");
1413 |
1414 | printk(" XU %d", forward->id);
1415 | found = 1;
1416 | }
1417 | break;
1418 |
1419 | case UVC_OTT_VENDOR_SPECIFIC:
1420 | case UVC_OTT_DISPLAY:
1421 | case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1422 | case UVC_TT_STREAMING:
1423 | if (UVC_ENTITY_IS_ITERM(forward)) {
1424 | uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1425 | "terminal %u.\n", forward->id);
1426 | return -EINVAL;
1427 | }
1428 |
1429 | list_add_tail(&forward->chain, &chain->entities);
1430 | if (uvc_trace_param & UVC_TRACE_PROBE) {
1431 | if (!found)
1432 | printk(" (->");
1433 |
1434 | printk(" OT %d", forward->id);
1435 | found = 1;
1436 | }
1437 | break;
1438 | }
1439 | }
1440 | if (found)
1441 | printk(")");
1442 |
1443 | return 0;
1444 | }
1445 |
1446 | static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1447 | struct uvc_entity **_entity)
1448 | {
1449 | struct uvc_entity *entity = *_entity;
1450 | struct uvc_entity *term;
1451 | int id = -EINVAL, i;
1452 |
1453 | switch (UVC_ENTITY_TYPE(entity)) {
1454 | case UVC_VC_EXTENSION_UNIT:
1455 | case UVC_VC_PROCESSING_UNIT:
1456 | id = entity->baSourceID[0];
1457 | break;
1458 |
1459 | case UVC_VC_SELECTOR_UNIT:
1460 | /* Single-input selector units are ignored. */
1461 | if (entity->bNrInPins == 1) {
1462 | id = entity->baSourceID[0];
1463 | break;
1464 | }
1465 |
1466 | if (uvc_trace_param & UVC_TRACE_PROBE)
1467 | printk(" <- IT");
1468 |
1469 | chain->selector = entity;
1470 | for (i = 0; i < entity->bNrInPins; ++i) {
1471 | id = entity->baSourceID[i];
1472 | term = uvc_entity_by_id(chain->dev, id);
1473 | if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1474 | uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1475 | "input %d isn't connected to an "
1476 | "input terminal\n", entity->id, i);
1477 | return -1;
1478 | }
1479 |
1480 | if (uvc_trace_param & UVC_TRACE_PROBE)
1481 | printk(" %d", term->id);
1482 |
1483 | list_add_tail(&term->chain, &chain->entities);
1484 | uvc_scan_chain_forward(chain, term, entity);
1485 | }
1486 |
1487 | if (uvc_trace_param & UVC_TRACE_PROBE)
1488 | printk("\n");
1489 |
1490 | id = 0;
1491 | break;
1492 |
1493 | case UVC_ITT_VENDOR_SPECIFIC:
1494 | case UVC_ITT_CAMERA:
1495 | case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1496 | case UVC_OTT_VENDOR_SPECIFIC:
1497 | case UVC_OTT_DISPLAY:
1498 | case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1499 | case UVC_TT_STREAMING:
1500 | id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1501 | break;
1502 | }
1503 |
1504 | if (id <= 0) {
1505 | *_entity = NULL;
1506 | return id;
1507 | }
1508 |
1509 | entity = uvc_entity_by_id(chain->dev, id);
1510 | if (entity == NULL) {
1511 | uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1512 | "unknown entity %d.\n", id);
1513 | return -EINVAL;
1514 | }
1515 |
1516 | *_entity = entity;
1517 | return 0;
1518 | }
1519 |
1520 | static int uvc_scan_chain(struct uvc_video_chain *chain,
1521 | struct uvc_entity *term)
1522 | {
1523 | struct uvc_entity *entity, *prev;
1524 |
1525 | uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1526 |
1527 | entity = term;
1528 | prev = NULL;
1529 |
1530 | while (entity != NULL) {
1531 | /* Entity must not be part of an existing chain */
1532 | if (entity->chain.next || entity->chain.prev) {
1533 | uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1534 | "entity %d already in chain.\n", entity->id);
1535 | return -EINVAL;
1536 | }
1537 |
1538 | /* Process entity */
1539 | if (uvc_scan_chain_entity(chain, entity) < 0)
1540 | return -EINVAL;
1541 |
1542 | /* Forward scan */
1543 | if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1544 | return -EINVAL;
1545 |
1546 | /* Backward scan */
1547 | prev = entity;
1548 | if (uvc_scan_chain_backward(chain, &entity) < 0)
1549 | return -EINVAL;
1550 | }
1551 |
1552 | return 0;
1553 | }
1554 |
1555 | static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1556 | char *buffer)
1557 | {
1558 | struct uvc_entity *term;
1559 | unsigned int nterms = 0;
1560 | char *p = buffer;
1561 |
1562 | list_for_each_entry(term, terms, chain) {
1563 | if (!UVC_ENTITY_IS_TERM(term) ||
1564 | UVC_TERM_DIRECTION(term) != dir)
1565 | continue;
1566 |
1567 | if (nterms)
1568 | p += sprintf(p, ",");
1569 | if (++nterms >= 4) {
1570 | p += sprintf(p, "...");
1571 | break;
1572 | }
1573 | p += sprintf(p, "%u", term->id);
1574 | }
1575 |
1576 | return p - buffer;
1577 | }
1578 |
1579 | static const char *uvc_print_chain(struct uvc_video_chain *chain)
1580 | {
1581 | static char buffer[43];
1582 | char *p = buffer;
1583 |
1584 | p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1585 | p += sprintf(p, " -> ");
1586 | uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1587 |
1588 | return buffer;
1589 | }
1590 |
1591 | /*
1592 | * Scan the device for video chains and register video devices.
1593 | *
1594 | * Chains are scanned starting at their output terminals and walked backwards.
1595 | */
1596 | static int uvc_scan_device(struct uvc_device *dev)
1597 | {
1598 | struct uvc_video_chain *chain;
1599 | struct uvc_entity *term;
1600 |
1601 | list_for_each_entry(term, &dev->entities, list) {
1602 | if (!UVC_ENTITY_IS_OTERM(term))
1603 | continue;
1604 |
1605 | /* If the terminal is already included in a chain, skip it.
1606 | * This can happen for chains that have multiple output
1607 | * terminals, where all output terminals beside the first one
1608 | * will be inserted in the chain in forward scans.
1609 | */
1610 | if (term->chain.next || term->chain.prev)
1611 | continue;
1612 |
1613 | chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1614 | if (chain == NULL)
1615 | return -ENOMEM;
1616 |
1617 | INIT_LIST_HEAD(&chain->entities);
1618 | mutex_init(&chain->ctrl_mutex);
1619 | chain->dev = dev;
1620 | v4l2_prio_init(&chain->prio);
1621 |
1622 | term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1623 |
1624 | if (uvc_scan_chain(chain, term) < 0) {
1625 | kfree(chain);
1626 | continue;
1627 | }
1628 |
1629 | uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1630 | uvc_print_chain(chain));
1631 |
1632 | list_add_tail(&chain->list, &dev->chains);
1633 | }
1634 |
1635 | if (list_empty(&dev->chains)) {
1636 | uvc_printk(KERN_INFO, "No valid video chain found.\n");
1637 | return -1;
1638 | }
1639 |
1640 | return 0;
1641 | }
1642 |
1643 | /* ------------------------------------------------------------------------
1644 | * Video device registration and unregistration
1645 | */
1646 |
1647 | /*
1648 | * Delete the UVC device.
1649 | *
1650 | * Called by the kernel when the last reference to the uvc_device structure
1651 | * is released.
1652 | *
1653 | * As this function is called after or during disconnect(), all URBs have
1654 | * already been canceled by the USB core. There is no need to kill the
1655 | * interrupt URB manually.
1656 | */
1657 | static void uvc_delete(struct uvc_device *dev)
1658 | {
1659 | struct list_head *p, *n;
1660 |
1661 | usb_put_intf(dev->intf);
1662 | usb_put_dev(dev->udev);
1663 |
1664 | uvc_status_cleanup(dev);
1665 | uvc_ctrl_cleanup_device(dev);
1666 |
1667 | if (dev->vdev.dev)
1668 | v4l2_device_unregister(&dev->vdev);
1669 | #ifdef CONFIG_MEDIA_CONTROLLER
1670 | if (media_devnode_is_registered(&dev->mdev.devnode))
1671 | media_device_unregister(&dev->mdev);
1672 | #endif
1673 |
1674 | list_for_each_safe(p, n, &dev->chains) {
1675 | struct uvc_video_chain *chain;
1676 | chain = list_entry(p, struct uvc_video_chain, list);
1677 | kfree(chain);
1678 | }
1679 |
1680 | list_for_each_safe(p, n, &dev->entities) {
1681 | struct uvc_entity *entity;
1682 | entity = list_entry(p, struct uvc_entity, list);
1683 | #ifdef CONFIG_MEDIA_CONTROLLER
1684 | uvc_mc_cleanup_entity(entity);
1685 | #endif
1686 | if (entity->vdev) {
1687 | video_device_release(entity->vdev);
1688 | entity->vdev = NULL;
1689 | }
1690 | kfree(entity);
1691 | }
1692 |
1693 | list_for_each_safe(p, n, &dev->streams) {
1694 | struct uvc_streaming *streaming;
1695 | streaming = list_entry(p, struct uvc_streaming, list);
1696 | usb_driver_release_interface(&uvc_driver.driver,
1697 | streaming->intf);
1698 | usb_put_intf(streaming->intf);
1699 | kfree(streaming->format);
1700 | kfree(streaming->header.bmaControls);
1701 | kfree(streaming);
1702 | }
1703 |
1704 | kfree(dev);
1705 | }
1706 |
1707 | static void uvc_release(struct video_device *vdev)
1708 | {
1709 | struct uvc_streaming *stream = video_get_drvdata(vdev);
1710 | struct uvc_device *dev = stream->dev;
1711 |
1712 | /* Decrement the registered streams count and delete the device when it
1713 | * reaches zero.
1714 | */
1715 | if (atomic_dec_and_test(&dev->nstreams))
1716 | uvc_delete(dev);
1717 | }
1718 |
1719 | /*
1720 | * Unregister the video devices.
1721 | */
1722 | static void uvc_unregister_video(struct uvc_device *dev)
1723 | {
1724 | struct uvc_streaming *stream;
1725 |
1726 | /* Unregistering all video devices might result in uvc_delete() being
1727 | * called from inside the loop if there's no open file handle. To avoid
1728 | * that, increment the stream count before iterating over the streams
1729 | * and decrement it when done.
1730 | */
1731 | atomic_inc(&dev->nstreams);
1732 |
1733 | list_for_each_entry(stream, &dev->streams, list) {
1734 | if (stream->vdev == NULL)
1735 | continue;
1736 |
1737 | video_unregister_device(stream->vdev);
1738 | stream->vdev = NULL;
1739 |
1740 | uvc_debugfs_cleanup_stream(stream);
1741 | }
1742 |
1743 | /* Decrement the stream count and call uvc_delete explicitly if there
1744 | * are no stream left.
1745 | */
1746 | if (atomic_dec_and_test(&dev->nstreams))
1747 | uvc_delete(dev);
1748 | }
1749 |
1750 | static int uvc_register_video(struct uvc_device *dev,
1751 | struct uvc_streaming *stream)
1752 | {
1753 | struct video_device *vdev;
1754 | int ret;
1755 |
1756 | /* Initialize the streaming interface with default streaming
1757 | * parameters.
1758 | */
1759 | ret = uvc_video_init(stream);
1760 | if (ret < 0) {
1761 | uvc_printk(KERN_ERR, "Failed to initialize the device "
1762 | "(%d).\n", ret);
1763 | return ret;
1764 | }
1765 |
1766 | uvc_debugfs_init_stream(stream);
1767 |
1768 | /* Register the device with V4L. */
1769 | vdev = video_device_alloc();
1770 | if (vdev == NULL) {
1771 | uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
1772 | ret);
1773 | return -ENOMEM;
1774 | }
1775 |
1776 | /* We already hold a reference to dev->udev. The video device will be
1777 | * unregistered before the reference is released, so we don't need to
1778 | * get another one.
1779 | */
1780 | vdev->v4l2_dev = &dev->vdev;
1781 | vdev->fops = &uvc_fops;
1782 | vdev->release = uvc_release;
1783 | vdev->prio = &stream->chain->prio;
1784 | set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
1785 | if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1786 | vdev->vfl_dir = VFL_DIR_TX;
1787 | strlcpy(vdev->name, dev->name, sizeof vdev->name);
1788 |
1789 | /* Set the driver data before calling video_register_device, otherwise
1790 | * uvc_v4l2_open might race us.
1791 | */
1792 | stream->vdev = vdev;
1793 | video_set_drvdata(vdev, stream);
1794 |
1795 | ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1796 | if (ret < 0) {
1797 | uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1798 | ret);
1799 | stream->vdev = NULL;
1800 | video_device_release(vdev);
1801 | return ret;
1802 | }
1803 |
1804 | if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1805 | stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1806 | else
1807 | stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1808 |
1809 | atomic_inc(&dev->nstreams);
1810 | return 0;
1811 | }
1812 |
1813 | /*
1814 | * Register all video devices in all chains.
1815 | */
1816 | static int uvc_register_terms(struct uvc_device *dev,
1817 | struct uvc_video_chain *chain)
1818 | {
1819 | struct uvc_streaming *stream;
1820 | struct uvc_entity *term;
1821 | int ret;
1822 |
1823 | list_for_each_entry(term, &chain->entities, chain) {
1824 | if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1825 | continue;
1826 |
1827 | stream = uvc_stream_by_id(dev, term->id);
1828 | if (stream == NULL) {
1829 | uvc_printk(KERN_INFO, "No streaming interface found "
1830 | "for terminal %u.", term->id);
1831 | continue;
1832 | }
1833 |
1834 | stream->chain = chain;
1835 | ret = uvc_register_video(dev, stream);
1836 | if (ret < 0)
1837 | return ret;
1838 |
1839 | term->vdev = stream->vdev;
1840 | }
1841 |
1842 | return 0;
1843 | }
1844 |
1845 | static int uvc_register_chains(struct uvc_device *dev)
1846 | {
1847 | struct uvc_video_chain *chain;
1848 | int ret;
1849 |
1850 | list_for_each_entry(chain, &dev->chains, list) {
1851 | ret = uvc_register_terms(dev, chain);
1852 | if (ret < 0)
1853 | return ret;
1854 |
1855 | #ifdef CONFIG_MEDIA_CONTROLLER
1856 | ret = uvc_mc_register_entities(chain);
1857 | if (ret < 0) {
1858 | uvc_printk(KERN_INFO, "Failed to register entites "
1859 | "(%d).\n", ret);
1860 | }
1861 | #endif
1862 | }
1863 |
1864 | return 0;
1865 | }
1866 |
1867 | /* ------------------------------------------------------------------------
1868 | * USB probe, disconnect, suspend and resume
1869 | */
1870 |
1871 | static int uvc_probe(struct usb_interface *intf,
1872 | const struct usb_device_id *id)
1873 | {
1874 | struct usb_device *udev = interface_to_usbdev(intf);
1875 | struct uvc_device *dev;
1876 | int ret;
1877 |
1878 | if (id->idVendor && id->idProduct)
1879 | uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1880 | "(%04x:%04x)\n", udev->devpath, id->idVendor,
1881 | id->idProduct);
1882 | else
1883 | uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1884 | udev->devpath);
1885 |
1886 | /* Allocate memory for the device and initialize it. */
1887 | if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1888 | return -ENOMEM;
1889 |
1890 | INIT_LIST_HEAD(&dev->entities);
1891 | INIT_LIST_HEAD(&dev->chains);
1892 | INIT_LIST_HEAD(&dev->streams);
1893 | atomic_set(&dev->nstreams, 0);
1894 | atomic_set(&dev->users, 0);
1895 | atomic_set(&dev->nmappings, 0);
1896 |
1897 | dev->udev = usb_get_dev(udev);
1898 | dev->intf = usb_get_intf(intf);
1899 | dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1900 | dev->quirks = (uvc_quirks_param == -1)
1901 | ? id->driver_info : uvc_quirks_param;
1902 |
1903 | if (udev->product != NULL)
1904 | strlcpy(dev->name, udev->product, sizeof dev->name);
1905 | else
1906 | snprintf(dev->name, sizeof dev->name,
1907 | "UVC Camera (%04x:%04x)",
1908 | le16_to_cpu(udev->descriptor.idVendor),
1909 | le16_to_cpu(udev->descriptor.idProduct));
1910 |
1911 | /* Parse the Video Class control descriptor. */
1912 | if (uvc_parse_control(dev) < 0) {
1913 | uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1914 | "descriptors.\n");
1915 | goto error;
1916 | }
1917 |
1918 | uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1919 | dev->uvc_version >> 8, dev->uvc_version & 0xff,
1920 | udev->product ? udev->product : "",
1921 | le16_to_cpu(udev->descriptor.idVendor),
1922 | le16_to_cpu(udev->descriptor.idProduct));
1923 |
1924 | if (dev->quirks != id->driver_info) {
1925 | uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1926 | "parameter for testing purpose.\n", dev->quirks);
1927 | uvc_printk(KERN_INFO, "Please report required quirks to the "
1928 | "linux-uvc-devel mailing list.\n");
1929 | }
1930 |
1931 | /* Register the media and V4L2 devices. */
1932 | #ifdef CONFIG_MEDIA_CONTROLLER
1933 | dev->mdev.dev = &intf->dev;
1934 | strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
1935 | if (udev->serial)
1936 | strlcpy(dev->mdev.serial, udev->serial,
1937 | sizeof(dev->mdev.serial));
1938 | strcpy(dev->mdev.bus_info, udev->devpath);
1939 | dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
1940 | dev->mdev.driver_version = LINUX_VERSION_CODE;
1941 | if (media_device_register(&dev->mdev) < 0)
1942 | goto error;
1943 |
1944 | dev->vdev.mdev = &dev->mdev;
1945 | #endif
1946 | if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
1947 | goto error;
1948 |
1949 | /* Initialize controls. */
1950 | if (uvc_ctrl_init_device(dev) < 0)
1951 | goto error;
1952 |
1953 | /* Scan the device for video chains. */
1954 | if (uvc_scan_device(dev) < 0)
1955 | goto error;
1956 |
1957 | /* Register video device nodes. */
1958 | if (uvc_register_chains(dev) < 0)
1959 | goto error;
1960 |
1961 | /* Save our data pointer in the interface data. */
1962 | usb_set_intfdata(intf, dev);
1963 |
1964 | /* Initialize the interrupt URB. */
1965 | if ((ret = uvc_status_init(dev)) < 0) {
1966 | uvc_printk(KERN_INFO, "Unable to initialize the status "
1967 | "endpoint (%d), status interrupt will not be "
1968 | "supported.\n", ret);
1969 | }
1970 |
1971 | uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1972 | usb_enable_autosuspend(udev);
1973 | return 0;
1974 |
1975 | error:
1976 | uvc_unregister_video(dev);
1977 | return -ENODEV;
1978 | }
1979 |
1980 | static void uvc_disconnect(struct usb_interface *intf)
1981 | {
1982 | struct uvc_device *dev = usb_get_intfdata(intf);
1983 |
1984 | /* Set the USB interface data to NULL. This can be done outside the
1985 | * lock, as there's no other reader.
1986 | */
1987 | usb_set_intfdata(intf, NULL);
1988 |
1989 | if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1990 | UVC_SC_VIDEOSTREAMING)
1991 | return;
1992 |
1993 | dev->state |= UVC_DEV_DISCONNECTED;
1994 |
1995 | uvc_unregister_video(dev);
1996 | }
1997 |
1998 | static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1999 | {
2000 | struct uvc_device *dev = usb_get_intfdata(intf);
2001 | struct uvc_streaming *stream;
2002 |
2003 | uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
2004 | intf->cur_altsetting->desc.bInterfaceNumber);
2005 |
2006 | /* Controls are cached on the fly so they don't need to be saved. */
2007 | if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2008 | UVC_SC_VIDEOCONTROL)
2009 | return uvc_status_suspend(dev);
2010 |
2011 | list_for_each_entry(stream, &dev->streams, list) {
2012 | if (stream->intf == intf)
2013 | return uvc_video_suspend(stream);
2014 | }
2015 |
2016 | uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2017 | "mismatch.\n");
2018 | return -EINVAL;
2019 | }
2020 |
2021 | static int __uvc_resume(struct usb_interface *intf, int reset)
2022 | {
2023 | struct uvc_device *dev = usb_get_intfdata(intf);
2024 | struct uvc_streaming *stream;
2025 |
2026 | uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2027 | intf->cur_altsetting->desc.bInterfaceNumber);
2028 |
2029 | if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2030 | UVC_SC_VIDEOCONTROL) {
2031 | if (reset) {
2032 | int ret = uvc_ctrl_resume_device(dev);
2033 |
2034 | if (ret < 0)
2035 | return ret;
2036 | }
2037 |
2038 | return uvc_status_resume(dev);
2039 | }
2040 |
2041 | list_for_each_entry(stream, &dev->streams, list) {
2042 | if (stream->intf == intf)
2043 | return uvc_video_resume(stream, reset);
2044 | }
2045 |
2046 | uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2047 | "mismatch.\n");
2048 | return -EINVAL;
2049 | }
2050 |
2051 | static int uvc_resume(struct usb_interface *intf)
2052 | {
2053 | return __uvc_resume(intf, 0);
2054 | }
2055 |
2056 | static int uvc_reset_resume(struct usb_interface *intf)
2057 | {
2058 | return __uvc_resume(intf, 1);
2059 | }
2060 |
2061 | /* ------------------------------------------------------------------------
2062 | * Module parameters
2063 | */
2064 |
2065 | static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
2066 | {
2067 | if (uvc_clock_param == CLOCK_MONOTONIC)
2068 | return sprintf(buffer, "CLOCK_MONOTONIC");
2069 | else
2070 | return sprintf(buffer, "CLOCK_REALTIME");
2071 | }
2072 |
2073 | static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
2074 | {
2075 | if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2076 | val += strlen("clock_");
2077 |
2078 | if (strcasecmp(val, "monotonic") == 0)
2079 | uvc_clock_param = CLOCK_MONOTONIC;
2080 | else if (strcasecmp(val, "realtime") == 0)
2081 | uvc_clock_param = CLOCK_REALTIME;
2082 | else
2083 | return -EINVAL;
2084 |
2085 | return 0;
2086 | }
2087 |
2088 | module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2089 | &uvc_clock_param, S_IRUGO|S_IWUSR);
2090 | MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2091 | module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2092 | MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2093 | module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2094 | MODULE_PARM_DESC(quirks, "Forced device quirks");
2095 | module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2096 | MODULE_PARM_DESC(trace, "Trace level bitmask");
2097 | module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2098 | MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2099 |
2100 | /* ------------------------------------------------------------------------
2101 | * Driver initialization and cleanup
2102 | */
2103 |
2104 | /*
2105 | * The Logitech cameras listed below have their interface class set to
2106 | * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2107 | * though they are compliant.
2108 | */
2109 | static struct usb_device_id uvc_ids[] = {
2110 | /* LogiLink Wireless Webcam */
2111 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2112 | | USB_DEVICE_ID_MATCH_INT_INFO,
2113 | .idVendor = 0x0416,
2114 | .idProduct = 0xa91a,
2115 | .bInterfaceClass = USB_CLASS_VIDEO,
2116 | .bInterfaceSubClass = 1,
2117 | .bInterfaceProtocol = 0,
2118 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2119 | /* Genius eFace 2025 */
2120 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2121 | | USB_DEVICE_ID_MATCH_INT_INFO,
2122 | .idVendor = 0x0458,
2123 | .idProduct = 0x706e,
2124 | .bInterfaceClass = USB_CLASS_VIDEO,
2125 | .bInterfaceSubClass = 1,
2126 | .bInterfaceProtocol = 0,
2127 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2128 | /* Microsoft Lifecam NX-6000 */
2129 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2130 | | USB_DEVICE_ID_MATCH_INT_INFO,
2131 | .idVendor = 0x045e,
2132 | .idProduct = 0x00f8,
2133 | .bInterfaceClass = USB_CLASS_VIDEO,
2134 | .bInterfaceSubClass = 1,
2135 | .bInterfaceProtocol = 0,
2136 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2137 | /* Microsoft Lifecam VX-7000 */
2138 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2139 | | USB_DEVICE_ID_MATCH_INT_INFO,
2140 | .idVendor = 0x045e,
2141 | .idProduct = 0x0723,
2142 | .bInterfaceClass = USB_CLASS_VIDEO,
2143 | .bInterfaceSubClass = 1,
2144 | .bInterfaceProtocol = 0,
2145 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2146 | /* Logitech Quickcam Fusion */
2147 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2148 | | USB_DEVICE_ID_MATCH_INT_INFO,
2149 | .idVendor = 0x046d,
2150 | .idProduct = 0x08c1,
2151 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2152 | .bInterfaceSubClass = 1,
2153 | .bInterfaceProtocol = 0 },
2154 | /* Logitech Quickcam Orbit MP */
2155 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2156 | | USB_DEVICE_ID_MATCH_INT_INFO,
2157 | .idVendor = 0x046d,
2158 | .idProduct = 0x08c2,
2159 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2160 | .bInterfaceSubClass = 1,
2161 | .bInterfaceProtocol = 0 },
2162 | /* Logitech Quickcam Pro for Notebook */
2163 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2164 | | USB_DEVICE_ID_MATCH_INT_INFO,
2165 | .idVendor = 0x046d,
2166 | .idProduct = 0x08c3,
2167 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2168 | .bInterfaceSubClass = 1,
2169 | .bInterfaceProtocol = 0 },
2170 | /* Logitech Quickcam Pro 5000 */
2171 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2172 | | USB_DEVICE_ID_MATCH_INT_INFO,
2173 | .idVendor = 0x046d,
2174 | .idProduct = 0x08c5,
2175 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2176 | .bInterfaceSubClass = 1,
2177 | .bInterfaceProtocol = 0 },
2178 | /* Logitech Quickcam OEM Dell Notebook */
2179 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2180 | | USB_DEVICE_ID_MATCH_INT_INFO,
2181 | .idVendor = 0x046d,
2182 | .idProduct = 0x08c6,
2183 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2184 | .bInterfaceSubClass = 1,
2185 | .bInterfaceProtocol = 0 },
2186 | /* Logitech Quickcam OEM Cisco VT Camera II */
2187 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2188 | | USB_DEVICE_ID_MATCH_INT_INFO,
2189 | .idVendor = 0x046d,
2190 | .idProduct = 0x08c7,
2191 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2192 | .bInterfaceSubClass = 1,
2193 | .bInterfaceProtocol = 0 },
2194 | /* Chicony CNF7129 (Asus EEE 100HE) */
2195 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2196 | | USB_DEVICE_ID_MATCH_INT_INFO,
2197 | .idVendor = 0x04f2,
2198 | .idProduct = 0xb071,
2199 | .bInterfaceClass = USB_CLASS_VIDEO,
2200 | .bInterfaceSubClass = 1,
2201 | .bInterfaceProtocol = 0,
2202 | .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2203 | /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2204 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2205 | | USB_DEVICE_ID_MATCH_INT_INFO,
2206 | .idVendor = 0x058f,
2207 | .idProduct = 0x3820,
2208 | .bInterfaceClass = USB_CLASS_VIDEO,
2209 | .bInterfaceSubClass = 1,
2210 | .bInterfaceProtocol = 0,
2211 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2212 | /* Dell XPS m1530 */
2213 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2214 | | USB_DEVICE_ID_MATCH_INT_INFO,
2215 | .idVendor = 0x05a9,
2216 | .idProduct = 0x2640,
2217 | .bInterfaceClass = USB_CLASS_VIDEO,
2218 | .bInterfaceSubClass = 1,
2219 | .bInterfaceProtocol = 0,
2220 | .driver_info = UVC_QUIRK_PROBE_DEF },
2221 | /* Apple Built-In iSight */
2222 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2223 | | USB_DEVICE_ID_MATCH_INT_INFO,
2224 | .idVendor = 0x05ac,
2225 | .idProduct = 0x8501,
2226 | .bInterfaceClass = USB_CLASS_VIDEO,
2227 | .bInterfaceSubClass = 1,
2228 | .bInterfaceProtocol = 0,
2229 | .driver_info = UVC_QUIRK_PROBE_MINMAX
2230 | | UVC_QUIRK_BUILTIN_ISIGHT },
2231 | /* Foxlink ("HP Webcam" on HP Mini 5103) */
2232 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2233 | | USB_DEVICE_ID_MATCH_INT_INFO,
2234 | .idVendor = 0x05c8,
2235 | .idProduct = 0x0403,
2236 | .bInterfaceClass = USB_CLASS_VIDEO,
2237 | .bInterfaceSubClass = 1,
2238 | .bInterfaceProtocol = 0,
2239 | .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2240 | /* Genesys Logic USB 2.0 PC Camera */
2241 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2242 | | USB_DEVICE_ID_MATCH_INT_INFO,
2243 | .idVendor = 0x05e3,
2244 | .idProduct = 0x0505,
2245 | .bInterfaceClass = USB_CLASS_VIDEO,
2246 | .bInterfaceSubClass = 1,
2247 | .bInterfaceProtocol = 0,
2248 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2249 | /* Hercules Classic Silver */
2250 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2251 | | USB_DEVICE_ID_MATCH_INT_INFO,
2252 | .idVendor = 0x06f8,
2253 | .idProduct = 0x300c,
2254 | .bInterfaceClass = USB_CLASS_VIDEO,
2255 | .bInterfaceSubClass = 1,
2256 | .bInterfaceProtocol = 0,
2257 | .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2258 | /* ViMicro Vega */
2259 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2260 | | USB_DEVICE_ID_MATCH_INT_INFO,
2261 | .idVendor = 0x0ac8,
2262 | .idProduct = 0x332d,
2263 | .bInterfaceClass = USB_CLASS_VIDEO,
2264 | .bInterfaceSubClass = 1,
2265 | .bInterfaceProtocol = 0,
2266 | .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2267 | /* ViMicro - Minoru3D */
2268 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2269 | | USB_DEVICE_ID_MATCH_INT_INFO,
2270 | .idVendor = 0x0ac8,
2271 | .idProduct = 0x3410,
2272 | .bInterfaceClass = USB_CLASS_VIDEO,
2273 | .bInterfaceSubClass = 1,
2274 | .bInterfaceProtocol = 0,
2275 | .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2276 | /* ViMicro Venus - Minoru3D */
2277 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2278 | | USB_DEVICE_ID_MATCH_INT_INFO,
2279 | .idVendor = 0x0ac8,
2280 | .idProduct = 0x3420,
2281 | .bInterfaceClass = USB_CLASS_VIDEO,
2282 | .bInterfaceSubClass = 1,
2283 | .bInterfaceProtocol = 0,
2284 | .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2285 | /* Ophir Optronics - SPCAM 620U */
2286 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2287 | | USB_DEVICE_ID_MATCH_INT_INFO,
2288 | .idVendor = 0x0bd3,
2289 | .idProduct = 0x0555,
2290 | .bInterfaceClass = USB_CLASS_VIDEO,
2291 | .bInterfaceSubClass = 1,
2292 | .bInterfaceProtocol = 0,
2293 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2294 | /* MT6227 */
2295 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2296 | | USB_DEVICE_ID_MATCH_INT_INFO,
2297 | .idVendor = 0x0e8d,
2298 | .idProduct = 0x0004,
2299 | .bInterfaceClass = USB_CLASS_VIDEO,
2300 | .bInterfaceSubClass = 1,
2301 | .bInterfaceProtocol = 0,
2302 | .driver_info = UVC_QUIRK_PROBE_MINMAX
2303 | | UVC_QUIRK_PROBE_DEF },
2304 | /* IMC Networks (Medion Akoya) */
2305 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2306 | | USB_DEVICE_ID_MATCH_INT_INFO,
2307 | .idVendor = 0x13d3,
2308 | .idProduct = 0x5103,
2309 | .bInterfaceClass = USB_CLASS_VIDEO,
2310 | .bInterfaceSubClass = 1,
2311 | .bInterfaceProtocol = 0,
2312 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2313 | /* JMicron USB2.0 XGA WebCam */
2314 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2315 | | USB_DEVICE_ID_MATCH_INT_INFO,
2316 | .idVendor = 0x152d,
2317 | .idProduct = 0x0310,
2318 | .bInterfaceClass = USB_CLASS_VIDEO,
2319 | .bInterfaceSubClass = 1,
2320 | .bInterfaceProtocol = 0,
2321 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2322 | /* Syntek (HP Spartan) */
2323 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2324 | | USB_DEVICE_ID_MATCH_INT_INFO,
2325 | .idVendor = 0x174f,
2326 | .idProduct = 0x5212,
2327 | .bInterfaceClass = USB_CLASS_VIDEO,
2328 | .bInterfaceSubClass = 1,
2329 | .bInterfaceProtocol = 0,
2330 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2331 | /* Syntek (Samsung Q310) */
2332 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2333 | | USB_DEVICE_ID_MATCH_INT_INFO,
2334 | .idVendor = 0x174f,
2335 | .idProduct = 0x5931,
2336 | .bInterfaceClass = USB_CLASS_VIDEO,
2337 | .bInterfaceSubClass = 1,
2338 | .bInterfaceProtocol = 0,
2339 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2340 | /* Syntek (Packard Bell EasyNote MX52 */
2341 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2342 | | USB_DEVICE_ID_MATCH_INT_INFO,
2343 | .idVendor = 0x174f,
2344 | .idProduct = 0x8a12,
2345 | .bInterfaceClass = USB_CLASS_VIDEO,
2346 | .bInterfaceSubClass = 1,
2347 | .bInterfaceProtocol = 0,
2348 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2349 | /* Syntek (Asus F9SG) */
2350 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2351 | | USB_DEVICE_ID_MATCH_INT_INFO,
2352 | .idVendor = 0x174f,
2353 | .idProduct = 0x8a31,
2354 | .bInterfaceClass = USB_CLASS_VIDEO,
2355 | .bInterfaceSubClass = 1,
2356 | .bInterfaceProtocol = 0,
2357 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2358 | /* Syntek (Asus U3S) */
2359 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2360 | | USB_DEVICE_ID_MATCH_INT_INFO,
2361 | .idVendor = 0x174f,
2362 | .idProduct = 0x8a33,
2363 | .bInterfaceClass = USB_CLASS_VIDEO,
2364 | .bInterfaceSubClass = 1,
2365 | .bInterfaceProtocol = 0,
2366 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2367 | /* Syntek (JAOtech Smart Terminal) */
2368 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2369 | | USB_DEVICE_ID_MATCH_INT_INFO,
2370 | .idVendor = 0x174f,
2371 | .idProduct = 0x8a34,
2372 | .bInterfaceClass = USB_CLASS_VIDEO,
2373 | .bInterfaceSubClass = 1,
2374 | .bInterfaceProtocol = 0,
2375 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2376 | /* Miricle 307K */
2377 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2378 | | USB_DEVICE_ID_MATCH_INT_INFO,
2379 | .idVendor = 0x17dc,
2380 | .idProduct = 0x0202,
2381 | .bInterfaceClass = USB_CLASS_VIDEO,
2382 | .bInterfaceSubClass = 1,
2383 | .bInterfaceProtocol = 0,
2384 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2385 | /* Lenovo Thinkpad SL400/SL500 */
2386 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2387 | | USB_DEVICE_ID_MATCH_INT_INFO,
2388 | .idVendor = 0x17ef,
2389 | .idProduct = 0x480b,
2390 | .bInterfaceClass = USB_CLASS_VIDEO,
2391 | .bInterfaceSubClass = 1,
2392 | .bInterfaceProtocol = 0,
2393 | .driver_info = UVC_QUIRK_STREAM_NO_FID },
2394 | /* Aveo Technology USB 2.0 Camera */
2395 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2396 | | USB_DEVICE_ID_MATCH_INT_INFO,
2397 | .idVendor = 0x1871,
2398 | .idProduct = 0x0306,
2399 | .bInterfaceClass = USB_CLASS_VIDEO,
2400 | .bInterfaceSubClass = 1,
2401 | .bInterfaceProtocol = 0,
2402 | .driver_info = UVC_QUIRK_PROBE_MINMAX
2403 | | UVC_QUIRK_PROBE_EXTRAFIELDS },
2404 | /* Ecamm Pico iMage */
2405 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2406 | | USB_DEVICE_ID_MATCH_INT_INFO,
2407 | .idVendor = 0x18cd,
2408 | .idProduct = 0xcafe,
2409 | .bInterfaceClass = USB_CLASS_VIDEO,
2410 | .bInterfaceSubClass = 1,
2411 | .bInterfaceProtocol = 0,
2412 | .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2413 | /* Manta MM-353 Plako */
2414 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2415 | | USB_DEVICE_ID_MATCH_INT_INFO,
2416 | .idVendor = 0x18ec,
2417 | .idProduct = 0x3188,
2418 | .bInterfaceClass = USB_CLASS_VIDEO,
2419 | .bInterfaceSubClass = 1,
2420 | .bInterfaceProtocol = 0,
2421 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2422 | /* FSC WebCam V30S */
2423 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2424 | | USB_DEVICE_ID_MATCH_INT_INFO,
2425 | .idVendor = 0x18ec,
2426 | .idProduct = 0x3288,
2427 | .bInterfaceClass = USB_CLASS_VIDEO,
2428 | .bInterfaceSubClass = 1,
2429 | .bInterfaceProtocol = 0,
2430 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2431 | /* Arkmicro unbranded */
2432 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2433 | | USB_DEVICE_ID_MATCH_INT_INFO,
2434 | .idVendor = 0x18ec,
2435 | .idProduct = 0x3290,
2436 | .bInterfaceClass = USB_CLASS_VIDEO,
2437 | .bInterfaceSubClass = 1,
2438 | .bInterfaceProtocol = 0,
2439 | .driver_info = UVC_QUIRK_PROBE_DEF },
2440 | /* The Imaging Source USB CCD cameras */
2441 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2442 | | USB_DEVICE_ID_MATCH_INT_INFO,
2443 | .idVendor = 0x199e,
2444 | .idProduct = 0x8102,
2445 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2446 | .bInterfaceSubClass = 1,
2447 | .bInterfaceProtocol = 0 },
2448 | /* Bodelin ProScopeHR */
2449 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2450 | | USB_DEVICE_ID_MATCH_DEV_HI
2451 | | USB_DEVICE_ID_MATCH_INT_INFO,
2452 | .idVendor = 0x19ab,
2453 | .idProduct = 0x1000,
2454 | .bcdDevice_hi = 0x0126,
2455 | .bInterfaceClass = USB_CLASS_VIDEO,
2456 | .bInterfaceSubClass = 1,
2457 | .bInterfaceProtocol = 0,
2458 | .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2459 | /* MSI StarCam 370i */
2460 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2461 | | USB_DEVICE_ID_MATCH_INT_INFO,
2462 | .idVendor = 0x1b3b,
2463 | .idProduct = 0x2951,
2464 | .bInterfaceClass = USB_CLASS_VIDEO,
2465 | .bInterfaceSubClass = 1,
2466 | .bInterfaceProtocol = 0,
2467 | .driver_info = UVC_QUIRK_PROBE_MINMAX },
2468 | /* SiGma Micro USB Web Camera */
2469 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2470 | | USB_DEVICE_ID_MATCH_INT_INFO,
2471 | .idVendor = 0x1c4f,
2472 | .idProduct = 0x3000,
2473 | .bInterfaceClass = USB_CLASS_VIDEO,
2474 | .bInterfaceSubClass = 1,
2475 | .bInterfaceProtocol = 0,
2476 | .driver_info = UVC_QUIRK_PROBE_MINMAX
2477 | | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2478 | /* Generic USB Video Class */
2479 | { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2480 | {}
2481 | };
2482 |
2483 | MODULE_DEVICE_TABLE(usb, uvc_ids);
2484 |
2485 | struct uvc_driver uvc_driver = {
2486 | .driver = {
2487 | .name = "uvcvideo",
2488 | .probe = uvc_probe,
2489 | .disconnect = uvc_disconnect,
2490 | .suspend = uvc_suspend,
2491 | .resume = uvc_resume,
2492 | .reset_resume = uvc_reset_resume,
2493 | .id_table = uvc_ids,
2494 | .supports_autosuspend = 1,
2495 | },
2496 | };
2497 |
2498 | static int __init uvc_init(void)
2499 | {
2500 | int ret;
2501 |
2502 | uvc_debugfs_init();
2503 |
2504 | ret = usb_register(&uvc_driver.driver);
2505 | if (ret < 0) {
2506 | uvc_debugfs_cleanup();
2507 | return ret;
2508 | }
2509 |
2510 | printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2511 | return 0;
2512 | }
2513 |
2514 | static void __exit uvc_cleanup(void)
2515 | {
2516 | usb_deregister(&uvc_driver.driver);
2517 | uvc_debugfs_cleanup();
2518 | }
2519 |
2520 | module_init(uvc_init);
2521 | module_exit(uvc_cleanup);
2522 |
2523 | MODULE_AUTHOR(DRIVER_AUTHOR);
2524 | MODULE_DESCRIPTION(DRIVER_DESC);
2525 | MODULE_LICENSE("GPL");
2526 | MODULE_VERSION(DRIVER_VERSION);
2527 |
2528 |
--------------------------------------------------------------------------------