Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: usbvision: remove deprecated driver

To quote the TODO of this driver:

--------------------------------------------------------------
The driver is deprecated and scheduled for removal by the end
of 2020.

In order to prevent removal the following actions would have to
be taken:

- clean up the code
- convert to the vb2 framework
- fix the disconnect and free-on-last-user handling (i.e., add
a release callback for struct v4l2_device and rework the code
to use that correctly).
--------------------------------------------------------------

Nobody picked this up, so it's time to retire this driver.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
50044aa7 d034731b

-6529
-1
Documentation/admin-guide/media/usb-cardlist.rst
··· 112 112 em28xx-cardlist 113 113 tm6000-cardlist 114 114 siano-cardlist 115 - usbvision-cardlist 116 115 117 116 gspca-cardlist 118 117
-283
Documentation/admin-guide/media/usbvision-cardlist.rst
··· 1 - .. SPDX-License-Identifier: GPL-2.0 2 - 3 - USBvision cards list 4 - ==================== 5 - 6 - .. tabularcolumns:: |p{1.4cm}|p{11.1cm}|p{4.2cm}| 7 - 8 - .. flat-table:: 9 - :header-rows: 1 10 - :widths: 2 19 18 11 - :stub-columns: 0 12 - 13 - * - Card number 14 - - Card name 15 - - USB IDs 16 - 17 - * - 0 18 - - Xanboo 19 - - 0a6f:0400 20 - 21 - * - 1 22 - - Belkin USB VideoBus II Adapter 23 - - 050d:0106 24 - 25 - * - 2 26 - - Belkin Components USB VideoBus 27 - - 050d:0207 28 - 29 - * - 3 30 - - Belkin USB VideoBus II 31 - - 050d:0208 32 - 33 - * - 4 34 - - echoFX InterView Lite 35 - - 0571:0002 36 - 37 - * - 5 38 - - USBGear USBG-V1 resp. HAMA USB 39 - - 0573:0003 40 - 41 - * - 6 42 - - D-Link V100 43 - - 0573:0400 44 - 45 - * - 7 46 - - X10 USB Camera 47 - - 0573:2000 48 - 49 - * - 8 50 - - Hauppauge WinTV USB Live (PAL B/G) 51 - - 0573:2d00 52 - 53 - * - 9 54 - - Hauppauge WinTV USB Live Pro (NTSC M/N) 55 - - 0573:2d01 56 - 57 - * - 10 58 - - Zoran Co. PMD (Nogatech) AV-grabber Manhattan 59 - - 0573:2101 60 - 61 - * - 11 62 - - Nogatech USB-TV (NTSC) FM 63 - - 0573:4100 64 - 65 - * - 12 66 - - PNY USB-TV (NTSC) FM 67 - - 0573:4110 68 - 69 - * - 13 70 - - PixelView PlayTv-USB PRO (PAL) FM 71 - - 0573:4450 72 - 73 - * - 14 74 - - ZTV ZT-721 2.4GHz USB A/V Receiver 75 - - 0573:4550 76 - 77 - * - 15 78 - - Hauppauge WinTV USB (NTSC M/N) 79 - - 0573:4d00 80 - 81 - * - 16 82 - - Hauppauge WinTV USB (PAL B/G) 83 - - 0573:4d01 84 - 85 - * - 17 86 - - Hauppauge WinTV USB (PAL I) 87 - - 0573:4d02 88 - 89 - * - 18 90 - - Hauppauge WinTV USB (PAL/SECAM L) 91 - - 0573:4d03 92 - 93 - * - 19 94 - - Hauppauge WinTV USB (PAL D/K) 95 - - 0573:4d04 96 - 97 - * - 20 98 - - Hauppauge WinTV USB (NTSC FM) 99 - - 0573:4d10 100 - 101 - * - 21 102 - - Hauppauge WinTV USB (PAL B/G FM) 103 - - 0573:4d11 104 - 105 - * - 22 106 - - Hauppauge WinTV USB (PAL I FM) 107 - - 0573:4d12 108 - 109 - * - 23 110 - - Hauppauge WinTV USB (PAL D/K FM) 111 - - 0573:4d14 112 - 113 - * - 24 114 - - Hauppauge WinTV USB Pro (NTSC M/N) 115 - - 0573:4d2a 116 - 117 - * - 25 118 - - Hauppauge WinTV USB Pro (NTSC M/N) V2 119 - - 0573:4d2b 120 - 121 - * - 26 122 - - Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L) 123 - - 0573:4d2c 124 - 125 - * - 27 126 - - Hauppauge WinTV USB Pro (NTSC M/N) V3 127 - - 0573:4d20 128 - 129 - * - 28 130 - - Hauppauge WinTV USB Pro (PAL B/G) 131 - - 0573:4d21 132 - 133 - * - 29 134 - - Hauppauge WinTV USB Pro (PAL I) 135 - - 0573:4d22 136 - 137 - * - 30 138 - - Hauppauge WinTV USB Pro (PAL/SECAM L) 139 - - 0573:4d23 140 - 141 - * - 31 142 - - Hauppauge WinTV USB Pro (PAL D/K) 143 - - 0573:4d24 144 - 145 - * - 32 146 - - Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L) 147 - - 0573:4d25 148 - 149 - * - 33 150 - - Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L) V2 151 - - 0573:4d26 152 - 153 - * - 34 154 - - Hauppauge WinTV USB Pro (PAL B/G) V2 155 - - 0573:4d27 156 - 157 - * - 35 158 - - Hauppauge WinTV USB Pro (PAL B/G,D/K) 159 - - 0573:4d28 160 - 161 - * - 36 162 - - Hauppauge WinTV USB Pro (PAL I,D/K) 163 - - 0573:4d29 164 - 165 - * - 37 166 - - Hauppauge WinTV USB Pro (NTSC M/N FM) 167 - - 0573:4d30 168 - 169 - * - 38 170 - - Hauppauge WinTV USB Pro (PAL B/G FM) 171 - - 0573:4d31 172 - 173 - * - 39 174 - - Hauppauge WinTV USB Pro (PAL I FM) 175 - - 0573:4d32 176 - 177 - * - 40 178 - - Hauppauge WinTV USB Pro (PAL D/K FM) 179 - - 0573:4d34 180 - 181 - * - 41 182 - - Hauppauge WinTV USB Pro (Temic PAL/SECAM B/G/I/D/K/L FM) 183 - - 0573:4d35 184 - 185 - * - 42 186 - - Hauppauge WinTV USB Pro (Temic PAL B/G FM) 187 - - 0573:4d36 188 - 189 - * - 43 190 - - Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L FM) 191 - - 0573:4d37 192 - 193 - * - 44 194 - - Hauppauge WinTV USB Pro (NTSC M/N FM) V2 195 - - 0573:4d38 196 - 197 - * - 45 198 - - Camtel Technology USB TV Genie Pro FM Model TVB330 199 - - 0768:0006 200 - 201 - * - 46 202 - - Digital Video Creator I 203 - - 07d0:0001 204 - 205 - * - 47 206 - - Global Village GV-007 (NTSC) 207 - - 07d0:0002 208 - 209 - * - 48 210 - - Dazzle Fusion Model DVC-50 Rev 1 (NTSC) 211 - - 07d0:0003 212 - 213 - * - 49 214 - - Dazzle Fusion Model DVC-80 Rev 1 (PAL) 215 - - 07d0:0004 216 - 217 - * - 50 218 - - Dazzle Fusion Model DVC-90 Rev 1 (SECAM) 219 - - 07d0:0005 220 - 221 - * - 51 222 - - Eskape Labs MyTV2Go 223 - - 07f8:9104 224 - 225 - * - 52 226 - - Pinnacle Studio PCTV USB (PAL) 227 - - 2304:010d 228 - 229 - * - 53 230 - - Pinnacle Studio PCTV USB (SECAM) 231 - - 2304:0109 232 - 233 - * - 54 234 - - Pinnacle Studio PCTV USB (PAL) FM 235 - - 2304:0110 236 - 237 - * - 55 238 - - Miro PCTV USB 239 - - 2304:0111 240 - 241 - * - 56 242 - - Pinnacle Studio PCTV USB (NTSC) FM 243 - - 2304:0112 244 - 245 - * - 57 246 - - Pinnacle Studio PCTV USB (PAL) FM V2 247 - - 2304:0210 248 - 249 - * - 58 250 - - Pinnacle Studio PCTV USB (NTSC) FM V2 251 - - 2304:0212 252 - 253 - * - 59 254 - - Pinnacle Studio PCTV USB (PAL) FM V3 255 - - 2304:0214 256 - 257 - * - 60 258 - - Pinnacle Studio Linx Video input cable (NTSC) 259 - - 2304:0300 260 - 261 - * - 61 262 - - Pinnacle Studio Linx Video input cable (PAL) 263 - - 2304:0301 264 - 265 - * - 62 266 - - Pinnacle PCTV Bungee USB (PAL) FM 267 - - 2304:0419 268 - 269 - * - 63 270 - - Hauppauge WinTv-USB 271 - - 2400:4200 272 - 273 - * - 64 274 - - Pinnacle Studio PCTV USB (NTSC) FM V3 275 - - 2304:0113 276 - 277 - * - 65 278 - - Nogatech USB MicroCam NTSC (NV3000N) 279 - - 0573:3000 280 - 281 - * - 66 282 - - Nogatech USB MicroCam PAL (NV3001P) 283 - - 0573:3001
-8
MAINTAINERS
··· 18116 18116 F: drivers/media/usb/uvc/ 18117 18117 F: include/uapi/linux/uvcvideo.h 18118 18118 18119 - USB VISION DRIVER 18120 - M: Hans Verkuil <hverkuil@xs4all.nl> 18121 - L: linux-media@vger.kernel.org 18122 - S: Odd Fixes 18123 - W: https://linuxtv.org 18124 - T: git git://linuxtv.org/media_tree.git 18125 - F: drivers/staging/media/usbvision/ 18126 - 18127 18119 USB WEBCAM GADGET 18128 18120 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 18129 18121 L: linux-usb@vger.kernel.org
-4
drivers/staging/media/Kconfig
··· 46 46 47 47 source "drivers/staging/media/rkisp1/Kconfig" 48 48 49 - if MEDIA_ANALOG_TV_SUPPORT 50 - source "drivers/staging/media/usbvision/Kconfig" 51 - endif 52 - 53 49 endif
-1
drivers/staging/media/Makefile
··· 12 12 obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3/ 13 13 obj-$(CONFIG_PHY_ROCKCHIP_DPHY_RX0) += phy-rockchip-dphy-rx0/ 14 14 obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += rkisp1/ 15 - obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
-18
drivers/staging/media/usbvision/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0-only 2 - config VIDEO_USBVISION 3 - tristate "USB video devices based on Nogatech NT1003/1004/1005 (Deprecated)" 4 - depends on MEDIA_USB_SUPPORT && I2C && VIDEO_V4L2 && USB 5 - select VIDEO_TUNER 6 - select VIDEO_SAA711X if MEDIA_SUBDRV_AUTOSELECT 7 - help 8 - There are more than 50 different USB video devices based on 9 - NT1003/1004/1005 USB Bridges. This driver enables using those 10 - devices. 11 - 12 - This driver is deprecated and scheduled for removal by the 13 - end of 2020. See the TODO file in drivers/staging/media/usbvision 14 - for a list of actions that have to be done in order to prevent 15 - removal of this driver. 16 - 17 - To compile this driver as a module, choose M here: the 18 - module will be called usbvision.
-4
drivers/staging/media/usbvision/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0-only 2 - usbvision-objs := usbvision-core.o usbvision-video.o usbvision-i2c.o usbvision-cards.o 3 - 4 - obj-$(CONFIG_VIDEO_USBVISION) += usbvision.o
-11
drivers/staging/media/usbvision/TODO
··· 1 - The driver is deprecated and scheduled for removal by the end 2 - of 2020. 3 - 4 - In order to prevent removal the following actions would have to 5 - be taken: 6 - 7 - - clean up the code 8 - - convert to the vb2 framework 9 - - fix the disconnect and free-on-last-user handling (i.e., add 10 - a release callback for struct v4l2_device and rework the code 11 - to use that correctly).
-1120
drivers/staging/media/usbvision/usbvision-cards.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * usbvision-cards.c 4 - * usbvision cards definition file 5 - * 6 - * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> 7 - * 8 - * This module is part of usbvision driver project. 9 - * Updates to driver completed by Dwaine P. Garden 10 - */ 11 - 12 - 13 - #include <linux/list.h> 14 - #include <linux/module.h> 15 - #include <media/v4l2-dev.h> 16 - #include <media/tuner.h> 17 - #include "usbvision.h" 18 - #include "usbvision-cards.h" 19 - 20 - /* Supported Devices: A table for usbvision.c*/ 21 - struct usbvision_device_data_st usbvision_device_data[] = { 22 - [XANBOO] = { 23 - .interface = -1, 24 - .codec = CODEC_SAA7113, 25 - .video_channels = 4, 26 - .video_norm = V4L2_STD_NTSC, 27 - .audio_channels = 1, 28 - .radio = 0, 29 - .vbi = 1, 30 - .tuner = 0, 31 - .tuner_type = 0, 32 - .x_offset = -1, 33 - .y_offset = -1, 34 - .model_string = "Xanboo", 35 - }, 36 - [BELKIN_VIDEOBUS_II] = { 37 - .interface = -1, 38 - .codec = CODEC_SAA7113, 39 - .video_channels = 2, 40 - .video_norm = V4L2_STD_PAL, 41 - .audio_channels = 1, 42 - .radio = 0, 43 - .vbi = 1, 44 - .tuner = 0, 45 - .tuner_type = 0, 46 - .x_offset = 0, 47 - .y_offset = 3, 48 - .dvi_yuv_override = 1, 49 - .dvi_yuv = 7, 50 - .model_string = "Belkin USB VideoBus II Adapter", 51 - }, 52 - [BELKIN_VIDEOBUS] = { 53 - .interface = -1, 54 - .codec = CODEC_SAA7111, 55 - .video_channels = 2, 56 - .video_norm = V4L2_STD_NTSC, 57 - .audio_channels = 1, 58 - .radio = 0, 59 - .vbi = 1, 60 - .tuner = 0, 61 - .tuner_type = 0, 62 - .x_offset = -1, 63 - .y_offset = -1, 64 - .model_string = "Belkin Components USB VideoBus", 65 - }, 66 - [BELKIN_USB_VIDEOBUS_II] = { 67 - .interface = -1, 68 - .codec = CODEC_SAA7113, 69 - .video_channels = 2, 70 - .video_norm = V4L2_STD_NTSC, 71 - .audio_channels = 1, 72 - .radio = 0, 73 - .vbi = 1, 74 - .tuner = 0, 75 - .tuner_type = 0, 76 - .x_offset = 0, 77 - .y_offset = 3, 78 - .dvi_yuv_override = 1, 79 - .dvi_yuv = 7, 80 - .model_string = "Belkin USB VideoBus II", 81 - }, 82 - [ECHOFX_INTERVIEW_LITE] = { 83 - .interface = 0, 84 - .codec = CODEC_SAA7111, 85 - .video_channels = 2, 86 - .video_norm = V4L2_STD_PAL, 87 - .audio_channels = 0, 88 - .radio = 0, 89 - .vbi = 1, 90 - .tuner = 0, 91 - .tuner_type = 0, 92 - .x_offset = -1, 93 - .y_offset = -1, 94 - .dvi_yuv_override = 1, 95 - .dvi_yuv = 7, 96 - .model_string = "echoFX InterView Lite", 97 - }, 98 - [USBGEAR_USBG_V1] = { 99 - .interface = -1, 100 - .codec = CODEC_SAA7111, 101 - .video_channels = 2, 102 - .video_norm = V4L2_STD_NTSC, 103 - .audio_channels = 1, 104 - .radio = 0, 105 - .vbi = 1, 106 - .tuner = 0, 107 - .tuner_type = 0, 108 - .x_offset = -1, 109 - .y_offset = -1, 110 - .model_string = "USBGear USBG-V1 resp. HAMA USB", 111 - }, 112 - [D_LINK_V100] = { 113 - .interface = -1, 114 - .codec = CODEC_SAA7113, 115 - .video_channels = 4, 116 - .video_norm = V4L2_STD_NTSC, 117 - .audio_channels = 0, 118 - .radio = 0, 119 - .vbi = 1, 120 - .tuner = 0, 121 - .tuner_type = 0, 122 - .x_offset = 0, 123 - .y_offset = 3, 124 - .dvi_yuv_override = 1, 125 - .dvi_yuv = 7, 126 - .model_string = "D-Link V100", 127 - }, 128 - [X10_USB_CAMERA] = { 129 - .interface = -1, 130 - .codec = CODEC_SAA7111, 131 - .video_channels = 2, 132 - .video_norm = V4L2_STD_NTSC, 133 - .audio_channels = 1, 134 - .radio = 0, 135 - .vbi = 1, 136 - .tuner = 0, 137 - .tuner_type = 0, 138 - .x_offset = -1, 139 - .y_offset = -1, 140 - .model_string = "X10 USB Camera", 141 - }, 142 - [HPG_WINTV_LIVE_PAL_BG] = { 143 - .interface = -1, 144 - .codec = CODEC_SAA7111, 145 - .video_channels = 2, 146 - .video_norm = V4L2_STD_PAL, 147 - .audio_channels = 1, 148 - .radio = 0, 149 - .vbi = 1, 150 - .tuner = 0, 151 - .tuner_type = 0, 152 - .x_offset = -1, 153 - .y_offset = 3, 154 - .dvi_yuv_override = 1, 155 - .dvi_yuv = 7, 156 - .model_string = "Hauppauge WinTV USB Live (PAL B/G)", 157 - }, 158 - [HPG_WINTV_LIVE_PRO_NTSC_MN] = { 159 - .interface = -1, 160 - .codec = CODEC_SAA7113, 161 - .video_channels = 2, 162 - .video_norm = V4L2_STD_NTSC, 163 - .audio_channels = 0, 164 - .radio = 0, 165 - .vbi = 1, 166 - .tuner = 0, 167 - .tuner_type = 0, 168 - .x_offset = 0, 169 - .y_offset = 3, 170 - .dvi_yuv_override = 1, 171 - .dvi_yuv = 7, 172 - .model_string = "Hauppauge WinTV USB Live Pro (NTSC M/N)", 173 - }, 174 - [ZORAN_PMD_NOGATECH] = { 175 - .interface = -1, 176 - .codec = CODEC_SAA7113, 177 - .video_channels = 2, 178 - .video_norm = V4L2_STD_PAL, 179 - .audio_channels = 2, 180 - .radio = 0, 181 - .vbi = 1, 182 - .tuner = 0, 183 - .tuner_type = 0, 184 - .x_offset = 0, 185 - .y_offset = 3, 186 - .dvi_yuv_override = 1, 187 - .dvi_yuv = 7, 188 - .model_string = "Zoran Co. PMD (Nogatech) AV-grabber Manhattan", 189 - }, 190 - [NOGATECH_USB_TV_NTSC_FM] = { 191 - .interface = -1, 192 - .codec = CODEC_SAA7111, 193 - .video_channels = 3, 194 - .video_norm = V4L2_STD_NTSC, 195 - .audio_channels = 1, 196 - .radio = 1, 197 - .vbi = 1, 198 - .tuner = 1, 199 - .tuner_type = TUNER_PHILIPS_NTSC_M, 200 - .x_offset = -1, 201 - .y_offset = 20, 202 - .model_string = "Nogatech USB-TV (NTSC) FM", 203 - }, 204 - [PNY_USB_TV_NTSC_FM] = { 205 - .interface = -1, 206 - .codec = CODEC_SAA7111, 207 - .video_channels = 3, 208 - .video_norm = V4L2_STD_NTSC, 209 - .audio_channels = 1, 210 - .radio = 1, 211 - .vbi = 1, 212 - .tuner = 1, 213 - .tuner_type = TUNER_PHILIPS_NTSC_M, 214 - .x_offset = -1, 215 - .y_offset = 20, 216 - .model_string = "PNY USB-TV (NTSC) FM", 217 - }, 218 - [PV_PLAYTV_USB_PRO_PAL_FM] = { 219 - .interface = 0, 220 - .codec = CODEC_SAA7113, 221 - .video_channels = 3, 222 - .video_norm = V4L2_STD_PAL, 223 - .audio_channels = 1, 224 - .radio = 1, 225 - .vbi = 1, 226 - .tuner = 1, 227 - .tuner_type = TUNER_PHILIPS_PAL, 228 - .x_offset = 0, 229 - .y_offset = 3, 230 - .dvi_yuv_override = 1, 231 - .dvi_yuv = 7, 232 - .model_string = "PixelView PlayTv-USB PRO (PAL) FM", 233 - }, 234 - [ZT_721] = { 235 - .interface = 0, 236 - .codec = CODEC_SAA7113, 237 - .video_channels = 3, 238 - .video_norm = V4L2_STD_PAL, 239 - .audio_channels = 1, 240 - .radio = 1, 241 - .vbi = 1, 242 - .tuner = 1, 243 - .tuner_type = TUNER_PHILIPS_PAL, 244 - .x_offset = 0, 245 - .y_offset = 3, 246 - .dvi_yuv_override = 1, 247 - .dvi_yuv = 7, 248 - .model_string = "ZTV ZT-721 2.4GHz USB A/V Receiver", 249 - }, 250 - [HPG_WINTV_NTSC_MN] = { 251 - .interface = -1, 252 - .codec = CODEC_SAA7111, 253 - .video_channels = 3, 254 - .video_norm = V4L2_STD_NTSC, 255 - .audio_channels = 1, 256 - .radio = 0, 257 - .vbi = 1, 258 - .tuner = 1, 259 - .tuner_type = TUNER_PHILIPS_NTSC_M, 260 - .x_offset = -1, 261 - .y_offset = 20, 262 - .model_string = "Hauppauge WinTV USB (NTSC M/N)", 263 - }, 264 - [HPG_WINTV_PAL_BG] = { 265 - .interface = -1, 266 - .codec = CODEC_SAA7111, 267 - .video_channels = 3, 268 - .video_norm = V4L2_STD_PAL, 269 - .audio_channels = 1, 270 - .radio = 0, 271 - .vbi = 1, 272 - .tuner = 1, 273 - .tuner_type = TUNER_PHILIPS_PAL, 274 - .x_offset = -1, 275 - .y_offset = -1, 276 - .model_string = "Hauppauge WinTV USB (PAL B/G)", 277 - }, 278 - [HPG_WINTV_PAL_I] = { 279 - .interface = -1, 280 - .codec = CODEC_SAA7111, 281 - .video_channels = 3, 282 - .video_norm = V4L2_STD_PAL, 283 - .audio_channels = 1, 284 - .radio = 0, 285 - .vbi = 1, 286 - .tuner = 1, 287 - .tuner_type = TUNER_PHILIPS_PAL, 288 - .x_offset = -1, 289 - .y_offset = -1, 290 - .model_string = "Hauppauge WinTV USB (PAL I)", 291 - }, 292 - [HPG_WINTV_PAL_SECAM_L] = { 293 - .interface = -1, 294 - .codec = CODEC_SAA7111, 295 - .video_channels = 3, 296 - .video_norm = V4L2_STD_SECAM, 297 - .audio_channels = 1, 298 - .radio = 0, 299 - .vbi = 1, 300 - .tuner = 1, 301 - .tuner_type = TUNER_PHILIPS_SECAM, 302 - .x_offset = 0x80, 303 - .y_offset = 0x16, 304 - .model_string = "Hauppauge WinTV USB (PAL/SECAM L)", 305 - }, 306 - [HPG_WINTV_PAL_D_K] = { 307 - .interface = -1, 308 - .codec = CODEC_SAA7111, 309 - .video_channels = 3, 310 - .video_norm = V4L2_STD_PAL, 311 - .audio_channels = 1, 312 - .radio = 0, 313 - .vbi = 1, 314 - .tuner = 1, 315 - .tuner_type = TUNER_PHILIPS_PAL, 316 - .x_offset = -1, 317 - .y_offset = -1, 318 - .model_string = "Hauppauge WinTV USB (PAL D/K)", 319 - }, 320 - [HPG_WINTV_NTSC_FM] = { 321 - .interface = -1, 322 - .codec = CODEC_SAA7111, 323 - .video_channels = 3, 324 - .video_norm = V4L2_STD_NTSC, 325 - .audio_channels = 1, 326 - .radio = 1, 327 - .vbi = 1, 328 - .tuner = 1, 329 - .tuner_type = TUNER_PHILIPS_NTSC_M, 330 - .x_offset = -1, 331 - .y_offset = -1, 332 - .model_string = "Hauppauge WinTV USB (NTSC FM)", 333 - }, 334 - [HPG_WINTV_PAL_BG_FM] = { 335 - .interface = -1, 336 - .codec = CODEC_SAA7111, 337 - .video_channels = 3, 338 - .video_norm = V4L2_STD_PAL, 339 - .audio_channels = 1, 340 - .radio = 1, 341 - .vbi = 1, 342 - .tuner = 1, 343 - .tuner_type = TUNER_PHILIPS_PAL, 344 - .x_offset = -1, 345 - .y_offset = -1, 346 - .model_string = "Hauppauge WinTV USB (PAL B/G FM)", 347 - }, 348 - [HPG_WINTV_PAL_I_FM] = { 349 - .interface = -1, 350 - .codec = CODEC_SAA7111, 351 - .video_channels = 3, 352 - .video_norm = V4L2_STD_PAL, 353 - .audio_channels = 1, 354 - .radio = 1, 355 - .vbi = 1, 356 - .tuner = 1, 357 - .tuner_type = TUNER_PHILIPS_PAL, 358 - .x_offset = -1, 359 - .y_offset = -1, 360 - .model_string = "Hauppauge WinTV USB (PAL I FM)", 361 - }, 362 - [HPG_WINTV_PAL_D_K_FM] = { 363 - .interface = -1, 364 - .codec = CODEC_SAA7111, 365 - .video_channels = 3, 366 - .video_norm = V4L2_STD_PAL, 367 - .audio_channels = 1, 368 - .radio = 1, 369 - .vbi = 1, 370 - .tuner = 1, 371 - .tuner_type = TUNER_PHILIPS_PAL, 372 - .x_offset = -1, 373 - .y_offset = -1, 374 - .model_string = "Hauppauge WinTV USB (PAL D/K FM)", 375 - }, 376 - [HPG_WINTV_PRO_NTSC_MN] = { 377 - .interface = 0, 378 - .codec = CODEC_SAA7113, 379 - .video_channels = 3, 380 - .video_norm = V4L2_STD_NTSC, 381 - .audio_channels = 1, 382 - .radio = 1, 383 - .vbi = 1, 384 - .tuner = 1, 385 - .tuner_type = TUNER_MICROTUNE_4049FM5, 386 - .x_offset = 0, 387 - .y_offset = 3, 388 - .dvi_yuv_override = 1, 389 - .dvi_yuv = 7, 390 - .model_string = "Hauppauge WinTV USB Pro (NTSC M/N)", 391 - }, 392 - [HPG_WINTV_PRO_NTSC_MN_V2] = { 393 - .interface = 0, 394 - .codec = CODEC_SAA7113, 395 - .video_channels = 3, 396 - .video_norm = V4L2_STD_NTSC, 397 - .audio_channels = 1, 398 - .radio = 1, 399 - .vbi = 1, 400 - .tuner = 1, 401 - .tuner_type = TUNER_MICROTUNE_4049FM5, 402 - .x_offset = 0, 403 - .y_offset = 3, 404 - .dvi_yuv_override = 1, 405 - .dvi_yuv = 7, 406 - .model_string = "Hauppauge WinTV USB Pro (NTSC M/N) V2", 407 - }, 408 - [HPG_WINTV_PRO_PAL] = { 409 - .interface = 0, 410 - .codec = CODEC_SAA7113, 411 - .video_channels = 3, 412 - .video_norm = V4L2_STD_PAL, 413 - .audio_channels = 1, 414 - .radio = 0, 415 - .vbi = 1, 416 - .tuner = 1, 417 - .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 418 - .x_offset = 0, 419 - .y_offset = 3, 420 - .dvi_yuv_override = 1, 421 - .dvi_yuv = 7, 422 - .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L)", 423 - }, 424 - [HPG_WINTV_PRO_NTSC_MN_V3] = { 425 - .interface = 0, 426 - .codec = CODEC_SAA7113, 427 - .video_channels = 3, 428 - .video_norm = V4L2_STD_NTSC, 429 - .audio_channels = 1, 430 - .radio = 1, 431 - .vbi = 1, 432 - .tuner = 1, 433 - .tuner_type = TUNER_PHILIPS_NTSC_M, 434 - .x_offset = 0, 435 - .y_offset = 3, 436 - .dvi_yuv_override = 1, 437 - .dvi_yuv = 7, 438 - .model_string = "Hauppauge WinTV USB Pro (NTSC M/N) V3", 439 - }, 440 - [HPG_WINTV_PRO_PAL_BG] = { 441 - .interface = 0, 442 - .codec = CODEC_SAA7113, 443 - .video_channels = 3, 444 - .video_norm = V4L2_STD_PAL, 445 - .audio_channels = 1, 446 - .radio = 0, 447 - .vbi = 1, 448 - .tuner = 1, 449 - .tuner_type = TUNER_PHILIPS_PAL, 450 - .x_offset = 0, 451 - .y_offset = 3, 452 - .dvi_yuv_override = 1, 453 - .dvi_yuv = 7, 454 - .model_string = "Hauppauge WinTV USB Pro (PAL B/G)", 455 - }, 456 - [HPG_WINTV_PRO_PAL_I] = { 457 - .interface = 0, 458 - .codec = CODEC_SAA7113, 459 - .video_channels = 3, 460 - .video_norm = V4L2_STD_PAL, 461 - .audio_channels = 1, 462 - .radio = 0, 463 - .vbi = 1, 464 - .tuner = 1, 465 - .tuner_type = TUNER_PHILIPS_PAL, 466 - .x_offset = 0, 467 - .y_offset = 3, 468 - .dvi_yuv_override = 1, 469 - .dvi_yuv = 7, 470 - .model_string = "Hauppauge WinTV USB Pro (PAL I)", 471 - }, 472 - [HPG_WINTV_PRO_PAL_SECAM_L] = { 473 - .interface = -1, 474 - .codec = CODEC_SAA7113, 475 - .video_channels = 3, 476 - .video_norm = V4L2_STD_SECAM, 477 - .audio_channels = 1, 478 - .radio = 0, 479 - .vbi = 1, 480 - .tuner = 1, 481 - .tuner_type = TUNER_PHILIPS_SECAM, 482 - .x_offset = 0, 483 - .y_offset = 3, 484 - .dvi_yuv_override = 1, 485 - .dvi_yuv = 7, 486 - .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM L)", 487 - }, 488 - [HPG_WINTV_PRO_PAL_D_K] = { 489 - .interface = -1, 490 - .codec = CODEC_SAA7113, 491 - .video_channels = 3, 492 - .video_norm = V4L2_STD_PAL, 493 - .audio_channels = 1, 494 - .radio = 0, 495 - .vbi = 1, 496 - .tuner = 1, 497 - .tuner_type = TUNER_PHILIPS_PAL, 498 - .x_offset = 0, 499 - .y_offset = 3, 500 - .dvi_yuv_override = 1, 501 - .dvi_yuv = 7, 502 - .model_string = "Hauppauge WinTV USB Pro (PAL D/K)", 503 - }, 504 - [HPG_WINTV_PRO_PAL_SECAM] = { 505 - .interface = -1, 506 - .codec = CODEC_SAA7113, 507 - .video_channels = 3, 508 - .video_norm = V4L2_STD_SECAM, 509 - .audio_channels = 1, 510 - .radio = 0, 511 - .vbi = 1, 512 - .tuner = 1, 513 - .tuner_type = TUNER_PHILIPS_SECAM, 514 - .x_offset = 0, 515 - .y_offset = 3, 516 - .dvi_yuv_override = 1, 517 - .dvi_yuv = 7, 518 - .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L)", 519 - }, 520 - [HPG_WINTV_PRO_PAL_SECAM_V2] = { 521 - .interface = -1, 522 - .codec = CODEC_SAA7113, 523 - .video_channels = 3, 524 - .video_norm = V4L2_STD_SECAM, 525 - .audio_channels = 1, 526 - .radio = 0, 527 - .vbi = 1, 528 - .tuner = 1, 529 - .tuner_type = TUNER_PHILIPS_SECAM, 530 - .x_offset = 0, 531 - .y_offset = 3, 532 - .dvi_yuv_override = 1, 533 - .dvi_yuv = 7, 534 - .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L) V2", 535 - }, 536 - [HPG_WINTV_PRO_PAL_BG_V2] = { 537 - .interface = -1, 538 - .codec = CODEC_SAA7113, 539 - .video_channels = 3, 540 - .video_norm = V4L2_STD_PAL, 541 - .audio_channels = 1, 542 - .radio = 0, 543 - .vbi = 1, 544 - .tuner = 1, 545 - .tuner_type = TUNER_ALPS_TSBE1_PAL, 546 - .x_offset = 0, 547 - .y_offset = 3, 548 - .dvi_yuv_override = 1, 549 - .dvi_yuv = 7, 550 - .model_string = "Hauppauge WinTV USB Pro (PAL B/G) V2", 551 - }, 552 - [HPG_WINTV_PRO_PAL_BG_D_K] = { 553 - .interface = -1, 554 - .codec = CODEC_SAA7113, 555 - .video_channels = 3, 556 - .video_norm = V4L2_STD_PAL, 557 - .audio_channels = 1, 558 - .radio = 0, 559 - .vbi = 1, 560 - .tuner = 1, 561 - .tuner_type = TUNER_ALPS_TSBE1_PAL, 562 - .x_offset = 0, 563 - .y_offset = 3, 564 - .dvi_yuv_override = 1, 565 - .dvi_yuv = 7, 566 - .model_string = "Hauppauge WinTV USB Pro (PAL B/G,D/K)", 567 - }, 568 - [HPG_WINTV_PRO_PAL_I_D_K] = { 569 - .interface = -1, 570 - .codec = CODEC_SAA7113, 571 - .video_channels = 3, 572 - .video_norm = V4L2_STD_PAL, 573 - .audio_channels = 1, 574 - .radio = 0, 575 - .vbi = 1, 576 - .tuner = 1, 577 - .tuner_type = TUNER_LG_PAL_NEW_TAPC, 578 - .x_offset = 0, 579 - .y_offset = 3, 580 - .dvi_yuv_override = 1, 581 - .dvi_yuv = 7, 582 - .model_string = "Hauppauge WinTV USB Pro (PAL I,D/K)", 583 - }, 584 - [HPG_WINTV_PRO_NTSC_MN_FM] = { 585 - .interface = -1, 586 - .codec = CODEC_SAA7113, 587 - .video_channels = 3, 588 - .video_norm = V4L2_STD_NTSC, 589 - .audio_channels = 1, 590 - .radio = 1, 591 - .vbi = 1, 592 - .tuner = 1, 593 - .tuner_type = TUNER_PHILIPS_NTSC_M, 594 - .x_offset = 0, 595 - .y_offset = 3, 596 - .dvi_yuv_override = 1, 597 - .dvi_yuv = 7, 598 - .model_string = "Hauppauge WinTV USB Pro (NTSC M/N FM)", 599 - }, 600 - [HPG_WINTV_PRO_PAL_BG_FM] = { 601 - .interface = 0, 602 - .codec = CODEC_SAA7113, 603 - .video_channels = 3, 604 - .video_norm = V4L2_STD_PAL, 605 - .audio_channels = 1, 606 - .radio = 1, 607 - .vbi = 1, 608 - .tuner = 1, 609 - .tuner_type = TUNER_PHILIPS_PAL, 610 - .x_offset = 0, 611 - .y_offset = 3, 612 - .dvi_yuv_override = 1, 613 - .dvi_yuv = 7, 614 - .model_string = "Hauppauge WinTV USB Pro (PAL B/G FM)", 615 - }, 616 - [HPG_WINTV_PRO_PAL_I_FM] = { 617 - .interface = 0, 618 - .codec = CODEC_SAA7113, 619 - .video_channels = 3, 620 - .video_norm = V4L2_STD_PAL, 621 - .audio_channels = 1, 622 - .radio = 1, 623 - .vbi = 1, 624 - .tuner = 1, 625 - .tuner_type = TUNER_PHILIPS_PAL, 626 - .x_offset = 0, 627 - .y_offset = 3, 628 - .dvi_yuv_override = 1, 629 - .dvi_yuv = 7, 630 - .model_string = "Hauppauge WinTV USB Pro (PAL I FM)", 631 - }, 632 - [HPG_WINTV_PRO_PAL_D_K_FM] = { 633 - .interface = 0, 634 - .codec = CODEC_SAA7113, 635 - .video_channels = 3, 636 - .video_norm = V4L2_STD_PAL, 637 - .audio_channels = 1, 638 - .radio = 1, 639 - .vbi = 1, 640 - .tuner = 1, 641 - .tuner_type = TUNER_PHILIPS_PAL, 642 - .x_offset = 0, 643 - .y_offset = 3, 644 - .dvi_yuv_override = 1, 645 - .dvi_yuv = 7, 646 - .model_string = "Hauppauge WinTV USB Pro (PAL D/K FM)", 647 - }, 648 - [HPG_WINTV_PRO_TEMIC_PAL_FM] = { 649 - .interface = 0, 650 - .codec = CODEC_SAA7113, 651 - .video_channels = 3, 652 - .video_norm = V4L2_STD_PAL, 653 - .audio_channels = 1, 654 - .radio = 1, 655 - .vbi = 1, 656 - .tuner = 1, 657 - .tuner_type = TUNER_MICROTUNE_4049FM5, 658 - .x_offset = 0, 659 - .y_offset = 3, 660 - .dvi_yuv_override = 1, 661 - .dvi_yuv = 7, 662 - .model_string = "Hauppauge WinTV USB Pro (Temic PAL/SECAM B/G/I/D/K/L FM)", 663 - }, 664 - [HPG_WINTV_PRO_TEMIC_PAL_BG_FM] = { 665 - .interface = 0, 666 - .codec = CODEC_SAA7113, 667 - .video_channels = 3, 668 - .video_norm = V4L2_STD_PAL, 669 - .audio_channels = 1, 670 - .radio = 1, 671 - .vbi = 1, 672 - .tuner = 1, 673 - .tuner_type = TUNER_MICROTUNE_4049FM5, 674 - .x_offset = 0, 675 - .y_offset = 3, 676 - .dvi_yuv_override = 1, 677 - .dvi_yuv = 7, 678 - .model_string = "Hauppauge WinTV USB Pro (Temic PAL B/G FM)", 679 - }, 680 - [HPG_WINTV_PRO_PAL_FM] = { 681 - .interface = 0, 682 - .codec = CODEC_SAA7113, 683 - .video_channels = 3, 684 - .video_norm = V4L2_STD_PAL, 685 - .audio_channels = 1, 686 - .radio = 1, 687 - .vbi = 1, 688 - .tuner = 1, 689 - .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 690 - .x_offset = 0, 691 - .y_offset = 3, 692 - .dvi_yuv_override = 1, 693 - .dvi_yuv = 7, 694 - .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L FM)", 695 - }, 696 - [HPG_WINTV_PRO_NTSC_MN_FM_V2] = { 697 - .interface = 0, 698 - .codec = CODEC_SAA7113, 699 - .video_channels = 3, 700 - .video_norm = V4L2_STD_NTSC, 701 - .audio_channels = 1, 702 - .radio = 1, 703 - .vbi = 1, 704 - .tuner = 1, 705 - .tuner_type = TUNER_PHILIPS_NTSC_M, 706 - .x_offset = 0, 707 - .y_offset = 3, 708 - .dvi_yuv_override = 1, 709 - .dvi_yuv = 7, 710 - .model_string = "Hauppauge WinTV USB Pro (NTSC M/N FM) V2", 711 - }, 712 - [CAMTEL_TVB330] = { 713 - .interface = -1, 714 - .codec = CODEC_SAA7113, 715 - .video_channels = 3, 716 - .video_norm = V4L2_STD_NTSC, 717 - .audio_channels = 1, 718 - .radio = 1, 719 - .vbi = 1, 720 - .tuner = 1, 721 - .tuner_type = TUNER_PHILIPS_NTSC_M, 722 - .x_offset = 5, 723 - .y_offset = 5, 724 - .model_string = "Camtel Technology USB TV Genie Pro FM Model TVB330", 725 - }, 726 - [DIGITAL_VIDEO_CREATOR_I] = { 727 - .interface = -1, 728 - .codec = CODEC_SAA7113, 729 - .video_channels = 2, 730 - .video_norm = V4L2_STD_PAL, 731 - .audio_channels = 0, 732 - .radio = 0, 733 - .vbi = 1, 734 - .tuner = 0, 735 - .tuner_type = 0, 736 - .x_offset = 0, 737 - .y_offset = 3, 738 - .dvi_yuv_override = 1, 739 - .dvi_yuv = 7, 740 - .model_string = "Digital Video Creator I", 741 - }, 742 - [GLOBAL_VILLAGE_GV_007_NTSC] = { 743 - .interface = -1, 744 - .codec = CODEC_SAA7111, 745 - .video_channels = 2, 746 - .video_norm = V4L2_STD_NTSC, 747 - .audio_channels = 0, 748 - .radio = 0, 749 - .vbi = 1, 750 - .tuner = 0, 751 - .tuner_type = 0, 752 - .x_offset = 82, 753 - .y_offset = 20, 754 - .dvi_yuv_override = 1, 755 - .dvi_yuv = 7, 756 - .model_string = "Global Village GV-007 (NTSC)", 757 - }, 758 - [DAZZLE_DVC_50_REV_1_NTSC] = { 759 - .interface = 0, 760 - .codec = CODEC_SAA7113, 761 - .video_channels = 2, 762 - .video_norm = V4L2_STD_NTSC, 763 - .audio_channels = 0, 764 - .radio = 0, 765 - .vbi = 1, 766 - .tuner = 0, 767 - .tuner_type = 0, 768 - .x_offset = 0, 769 - .y_offset = 3, 770 - .dvi_yuv_override = 1, 771 - .dvi_yuv = 7, 772 - .model_string = "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)", 773 - }, 774 - [DAZZLE_DVC_80_REV_1_PAL] = { 775 - .interface = 0, 776 - .codec = CODEC_SAA7113, 777 - .video_channels = 2, 778 - .video_norm = V4L2_STD_PAL, 779 - .audio_channels = 0, 780 - .radio = 0, 781 - .vbi = 1, 782 - .tuner = 0, 783 - .tuner_type = 0, 784 - .x_offset = 0, 785 - .y_offset = 3, 786 - .dvi_yuv_override = 1, 787 - .dvi_yuv = 7, 788 - .model_string = "Dazzle Fusion Model DVC-80 Rev 1 (PAL)", 789 - }, 790 - [DAZZLE_DVC_90_REV_1_SECAM] = { 791 - .interface = 0, 792 - .codec = CODEC_SAA7113, 793 - .video_channels = 2, 794 - .video_norm = V4L2_STD_SECAM, 795 - .audio_channels = 0, 796 - .radio = 0, 797 - .vbi = 1, 798 - .tuner = 0, 799 - .tuner_type = 0, 800 - .x_offset = 0, 801 - .y_offset = 3, 802 - .dvi_yuv_override = 1, 803 - .dvi_yuv = 7, 804 - .model_string = "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)", 805 - }, 806 - [ESKAPE_LABS_MYTV2GO] = { 807 - .interface = 0, 808 - .codec = CODEC_SAA7113, 809 - .video_channels = 2, 810 - .video_norm = V4L2_STD_PAL, 811 - .audio_channels = 1, 812 - .radio = 1, 813 - .vbi = 1, 814 - .tuner = 1, 815 - .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 816 - .x_offset = 0, 817 - .y_offset = 3, 818 - .dvi_yuv_override = 1, 819 - .dvi_yuv = 7, 820 - .model_string = "Eskape Labs MyTV2Go", 821 - }, 822 - [PINNA_PCTV_USB_PAL] = { 823 - .interface = -1, 824 - .codec = CODEC_SAA7111, 825 - .video_channels = 3, 826 - .video_norm = V4L2_STD_PAL, 827 - .audio_channels = 1, 828 - .radio = 0, 829 - .vbi = 0, 830 - .tuner = 1, 831 - .tuner_type = TUNER_TEMIC_4066FY5_PAL_I, 832 - .x_offset = -1, 833 - .y_offset = -1, 834 - .model_string = "Pinnacle Studio PCTV USB (PAL)", 835 - }, 836 - [PINNA_PCTV_USB_SECAM] = { 837 - .interface = -1, 838 - .codec = CODEC_SAA7111, 839 - .video_channels = 3, 840 - .video_norm = V4L2_STD_SECAM, 841 - .audio_channels = 1, 842 - .radio = 0, 843 - .vbi = 1, 844 - .tuner = 1, 845 - .tuner_type = TUNER_PHILIPS_SECAM, 846 - .x_offset = -1, 847 - .y_offset = -1, 848 - .model_string = "Pinnacle Studio PCTV USB (SECAM)", 849 - }, 850 - [PINNA_PCTV_USB_PAL_FM] = { 851 - .interface = -1, 852 - .codec = CODEC_SAA7111, 853 - .video_channels = 3, 854 - .video_norm = V4L2_STD_PAL, 855 - .audio_channels = 1, 856 - .radio = 1, 857 - .vbi = 1, 858 - .tuner = 1, 859 - .tuner_type = TUNER_PHILIPS_PAL, 860 - .x_offset = 128, 861 - .y_offset = 23, 862 - .model_string = "Pinnacle Studio PCTV USB (PAL) FM", 863 - }, 864 - [MIRO_PCTV_USB] = { 865 - .interface = -1, 866 - .codec = CODEC_SAA7111, 867 - .video_channels = 3, 868 - .video_norm = V4L2_STD_PAL, 869 - .audio_channels = 1, 870 - .radio = 0, 871 - .vbi = 1, 872 - .tuner = 1, 873 - .tuner_type = TUNER_PHILIPS_PAL, 874 - .x_offset = -1, 875 - .y_offset = -1, 876 - .model_string = "Miro PCTV USB", 877 - }, 878 - [PINNA_PCTV_USB_NTSC_FM] = { 879 - .interface = -1, 880 - .codec = CODEC_SAA7111, 881 - .video_channels = 3, 882 - .video_norm = V4L2_STD_NTSC, 883 - .audio_channels = 1, 884 - .radio = 1, 885 - .vbi = 1, 886 - .tuner = 1, 887 - .tuner_type = TUNER_PHILIPS_NTSC_M, 888 - .x_offset = -1, 889 - .y_offset = -1, 890 - .model_string = "Pinnacle Studio PCTV USB (NTSC) FM", 891 - }, 892 - [PINNA_PCTV_USB_NTSC_FM_V3] = { 893 - .interface = -1, 894 - .codec = CODEC_SAA7111, 895 - .video_channels = 3, 896 - .video_norm = V4L2_STD_NTSC, 897 - .audio_channels = 1, 898 - .radio = 1, 899 - .vbi = 1, 900 - .tuner = 1, 901 - .tuner_type = TUNER_PHILIPS_NTSC_M, 902 - .x_offset = -1, 903 - .y_offset = -1, 904 - .model_string = "Pinnacle Studio PCTV USB (NTSC) FM V3", 905 - }, 906 - [PINNA_PCTV_USB_PAL_FM_V2] = { 907 - .interface = -1, 908 - .codec = CODEC_SAA7113, 909 - .video_channels = 3, 910 - .video_norm = V4L2_STD_PAL, 911 - .audio_channels = 1, 912 - .radio = 1, 913 - .vbi = 1, 914 - .tuner = 1, 915 - .tuner_type = TUNER_TEMIC_4009FR5_PAL, 916 - .x_offset = 0, 917 - .y_offset = 3, 918 - .dvi_yuv_override = 1, 919 - .dvi_yuv = 7, 920 - .model_string = "Pinnacle Studio PCTV USB (PAL) FM V2", 921 - }, 922 - [PINNA_PCTV_USB_NTSC_FM_V2] = { 923 - .interface = -1, 924 - .codec = CODEC_SAA7111, 925 - .video_channels = 3, 926 - .video_norm = V4L2_STD_NTSC, 927 - .audio_channels = 1, 928 - .radio = 1, 929 - .vbi = 1, 930 - .tuner = 1, 931 - .tuner_type = TUNER_TEMIC_4039FR5_NTSC, 932 - .x_offset = 0, 933 - .y_offset = 3, 934 - .dvi_yuv_override = 1, 935 - .dvi_yuv = 7, 936 - .model_string = "Pinnacle Studio PCTV USB (NTSC) FM V2", 937 - }, 938 - [PINNA_PCTV_USB_PAL_FM_V3] = { 939 - .interface = -1, 940 - .codec = CODEC_SAA7113, 941 - .video_channels = 3, 942 - .video_norm = V4L2_STD_PAL, 943 - .audio_channels = 1, 944 - .radio = 1, 945 - .vbi = 1, 946 - .tuner = 1, 947 - .tuner_type = TUNER_TEMIC_4009FR5_PAL, 948 - .x_offset = 0, 949 - .y_offset = 3, 950 - .dvi_yuv_override = 1, 951 - .dvi_yuv = 7, 952 - .model_string = "Pinnacle Studio PCTV USB (PAL) FM V3", 953 - }, 954 - [PINNA_LINX_VD_IN_CAB_NTSC] = { 955 - .interface = -1, 956 - .codec = CODEC_SAA7113, 957 - .video_channels = 2, 958 - .video_norm = V4L2_STD_NTSC, 959 - .audio_channels = 1, 960 - .radio = 0, 961 - .vbi = 1, 962 - .tuner = 0, 963 - .tuner_type = 0, 964 - .x_offset = 0, 965 - .y_offset = 3, 966 - .dvi_yuv_override = 1, 967 - .dvi_yuv = 7, 968 - .model_string = "Pinnacle Studio Linx Video input cable (NTSC)", 969 - }, 970 - [PINNA_LINX_VD_IN_CAB_PAL] = { 971 - .interface = -1, 972 - .codec = CODEC_SAA7113, 973 - .video_channels = 2, 974 - .video_norm = V4L2_STD_PAL, 975 - .audio_channels = 1, 976 - .radio = 0, 977 - .vbi = 1, 978 - .tuner = 0, 979 - .tuner_type = 0, 980 - .x_offset = 0, 981 - .y_offset = 3, 982 - .dvi_yuv_override = 1, 983 - .dvi_yuv = 7, 984 - .model_string = "Pinnacle Studio Linx Video input cable (PAL)", 985 - }, 986 - [PINNA_PCTV_BUNGEE_PAL_FM] = { 987 - .interface = -1, 988 - .codec = CODEC_SAA7113, 989 - .video_channels = 3, 990 - .video_norm = V4L2_STD_PAL, 991 - .audio_channels = 1, 992 - .radio = 1, 993 - .vbi = 1, 994 - .tuner = 1, 995 - .tuner_type = TUNER_TEMIC_4009FR5_PAL, 996 - .x_offset = 0, 997 - .y_offset = 3, 998 - .dvi_yuv_override = 1, 999 - .dvi_yuv = 7, 1000 - .model_string = "Pinnacle PCTV Bungee USB (PAL) FM", 1001 - }, 1002 - [HPG_WINTV] = { 1003 - .interface = -1, 1004 - .codec = CODEC_SAA7111, 1005 - .video_channels = 3, 1006 - .video_norm = V4L2_STD_NTSC, 1007 - .audio_channels = 1, 1008 - .radio = 0, 1009 - .vbi = 1, 1010 - .tuner = 1, 1011 - .tuner_type = TUNER_PHILIPS_NTSC_M, 1012 - .x_offset = -1, 1013 - .y_offset = -1, 1014 - .model_string = "Hauppauge WinTv-USB", 1015 - }, 1016 - [MICROCAM_NTSC] = { 1017 - .interface = -1, 1018 - .codec = CODEC_WEBCAM, 1019 - .video_channels = 1, 1020 - .video_norm = V4L2_STD_NTSC, 1021 - .audio_channels = 0, 1022 - .radio = 0, 1023 - .vbi = 0, 1024 - .tuner = 0, 1025 - .tuner_type = 0, 1026 - .x_offset = 71, 1027 - .y_offset = 15, 1028 - .model_string = "Nogatech USB MicroCam NTSC (NV3000N)", 1029 - }, 1030 - [MICROCAM_PAL] = { 1031 - .interface = -1, 1032 - .codec = CODEC_WEBCAM, 1033 - .video_channels = 1, 1034 - .video_norm = V4L2_STD_PAL, 1035 - .audio_channels = 0, 1036 - .radio = 0, 1037 - .vbi = 0, 1038 - .tuner = 0, 1039 - .tuner_type = 0, 1040 - .x_offset = 71, 1041 - .y_offset = 18, 1042 - .model_string = "Nogatech USB MicroCam PAL (NV3001P)", 1043 - }, 1044 - }; 1045 - const int usbvision_device_data_size = ARRAY_SIZE(usbvision_device_data); 1046 - 1047 - /* Supported Devices */ 1048 - 1049 - struct usb_device_id usbvision_table[] = { 1050 - { USB_DEVICE(0x0a6f, 0x0400), .driver_info = XANBOO }, 1051 - { USB_DEVICE(0x050d, 0x0106), .driver_info = BELKIN_VIDEOBUS_II }, 1052 - { USB_DEVICE(0x050d, 0x0207), .driver_info = BELKIN_VIDEOBUS }, 1053 - { USB_DEVICE(0x050d, 0x0208), .driver_info = BELKIN_USB_VIDEOBUS_II }, 1054 - { USB_DEVICE(0x0571, 0x0002), .driver_info = ECHOFX_INTERVIEW_LITE }, 1055 - { USB_DEVICE(0x0573, 0x0003), .driver_info = USBGEAR_USBG_V1 }, 1056 - { USB_DEVICE(0x0573, 0x0400), .driver_info = D_LINK_V100 }, 1057 - { USB_DEVICE(0x0573, 0x2000), .driver_info = X10_USB_CAMERA }, 1058 - { USB_DEVICE(0x0573, 0x2d00), .driver_info = HPG_WINTV_LIVE_PAL_BG }, 1059 - { USB_DEVICE(0x0573, 0x2d01), .driver_info = HPG_WINTV_LIVE_PRO_NTSC_MN }, 1060 - { USB_DEVICE(0x0573, 0x2101), .driver_info = ZORAN_PMD_NOGATECH }, 1061 - { USB_DEVICE(0x0573, 0x3000), .driver_info = MICROCAM_NTSC }, 1062 - { USB_DEVICE(0x0573, 0x3001), .driver_info = MICROCAM_PAL }, 1063 - { USB_DEVICE(0x0573, 0x4100), .driver_info = NOGATECH_USB_TV_NTSC_FM }, 1064 - { USB_DEVICE(0x0573, 0x4110), .driver_info = PNY_USB_TV_NTSC_FM }, 1065 - { USB_DEVICE(0x0573, 0x4450), .driver_info = PV_PLAYTV_USB_PRO_PAL_FM }, 1066 - { USB_DEVICE(0x0573, 0x4550), .driver_info = ZT_721 }, 1067 - { USB_DEVICE(0x0573, 0x4d00), .driver_info = HPG_WINTV_NTSC_MN }, 1068 - { USB_DEVICE(0x0573, 0x4d01), .driver_info = HPG_WINTV_PAL_BG }, 1069 - { USB_DEVICE(0x0573, 0x4d02), .driver_info = HPG_WINTV_PAL_I }, 1070 - { USB_DEVICE(0x0573, 0x4d03), .driver_info = HPG_WINTV_PAL_SECAM_L }, 1071 - { USB_DEVICE(0x0573, 0x4d04), .driver_info = HPG_WINTV_PAL_D_K }, 1072 - { USB_DEVICE(0x0573, 0x4d10), .driver_info = HPG_WINTV_NTSC_FM }, 1073 - { USB_DEVICE(0x0573, 0x4d11), .driver_info = HPG_WINTV_PAL_BG_FM }, 1074 - { USB_DEVICE(0x0573, 0x4d12), .driver_info = HPG_WINTV_PAL_I_FM }, 1075 - { USB_DEVICE(0x0573, 0x4d14), .driver_info = HPG_WINTV_PAL_D_K_FM }, 1076 - { USB_DEVICE(0x0573, 0x4d2a), .driver_info = HPG_WINTV_PRO_NTSC_MN }, 1077 - { USB_DEVICE(0x0573, 0x4d2b), .driver_info = HPG_WINTV_PRO_NTSC_MN_V2 }, 1078 - { USB_DEVICE(0x0573, 0x4d2c), .driver_info = HPG_WINTV_PRO_PAL }, 1079 - { USB_DEVICE(0x0573, 0x4d20), .driver_info = HPG_WINTV_PRO_NTSC_MN_V3 }, 1080 - { USB_DEVICE(0x0573, 0x4d21), .driver_info = HPG_WINTV_PRO_PAL_BG }, 1081 - { USB_DEVICE(0x0573, 0x4d22), .driver_info = HPG_WINTV_PRO_PAL_I }, 1082 - { USB_DEVICE(0x0573, 0x4d23), .driver_info = HPG_WINTV_PRO_PAL_SECAM_L }, 1083 - { USB_DEVICE(0x0573, 0x4d24), .driver_info = HPG_WINTV_PRO_PAL_D_K }, 1084 - { USB_DEVICE(0x0573, 0x4d25), .driver_info = HPG_WINTV_PRO_PAL_SECAM }, 1085 - { USB_DEVICE(0x0573, 0x4d26), .driver_info = HPG_WINTV_PRO_PAL_SECAM_V2 }, 1086 - { USB_DEVICE(0x0573, 0x4d27), .driver_info = HPG_WINTV_PRO_PAL_BG_V2 }, 1087 - { USB_DEVICE(0x0573, 0x4d28), .driver_info = HPG_WINTV_PRO_PAL_BG_D_K }, 1088 - { USB_DEVICE(0x0573, 0x4d29), .driver_info = HPG_WINTV_PRO_PAL_I_D_K }, 1089 - { USB_DEVICE(0x0573, 0x4d30), .driver_info = HPG_WINTV_PRO_NTSC_MN_FM }, 1090 - { USB_DEVICE(0x0573, 0x4d31), .driver_info = HPG_WINTV_PRO_PAL_BG_FM }, 1091 - { USB_DEVICE(0x0573, 0x4d32), .driver_info = HPG_WINTV_PRO_PAL_I_FM }, 1092 - { USB_DEVICE(0x0573, 0x4d34), .driver_info = HPG_WINTV_PRO_PAL_D_K_FM }, 1093 - { USB_DEVICE(0x0573, 0x4d35), .driver_info = HPG_WINTV_PRO_TEMIC_PAL_FM }, 1094 - { USB_DEVICE(0x0573, 0x4d36), .driver_info = HPG_WINTV_PRO_TEMIC_PAL_BG_FM }, 1095 - { USB_DEVICE(0x0573, 0x4d37), .driver_info = HPG_WINTV_PRO_PAL_FM }, 1096 - { USB_DEVICE(0x0573, 0x4d38), .driver_info = HPG_WINTV_PRO_NTSC_MN_FM_V2 }, 1097 - { USB_DEVICE(0x0768, 0x0006), .driver_info = CAMTEL_TVB330 }, 1098 - { USB_DEVICE(0x07d0, 0x0001), .driver_info = DIGITAL_VIDEO_CREATOR_I }, 1099 - { USB_DEVICE(0x07d0, 0x0002), .driver_info = GLOBAL_VILLAGE_GV_007_NTSC }, 1100 - { USB_DEVICE(0x07d0, 0x0003), .driver_info = DAZZLE_DVC_50_REV_1_NTSC }, 1101 - { USB_DEVICE(0x07d0, 0x0004), .driver_info = DAZZLE_DVC_80_REV_1_PAL }, 1102 - { USB_DEVICE(0x07d0, 0x0005), .driver_info = DAZZLE_DVC_90_REV_1_SECAM }, 1103 - { USB_DEVICE(0x07f8, 0x9104), .driver_info = ESKAPE_LABS_MYTV2GO }, 1104 - { USB_DEVICE(0x2304, 0x010d), .driver_info = PINNA_PCTV_USB_PAL }, 1105 - { USB_DEVICE(0x2304, 0x0109), .driver_info = PINNA_PCTV_USB_SECAM }, 1106 - { USB_DEVICE(0x2304, 0x0110), .driver_info = PINNA_PCTV_USB_PAL_FM }, 1107 - { USB_DEVICE(0x2304, 0x0111), .driver_info = MIRO_PCTV_USB }, 1108 - { USB_DEVICE(0x2304, 0x0112), .driver_info = PINNA_PCTV_USB_NTSC_FM }, 1109 - { USB_DEVICE(0x2304, 0x0113), .driver_info = PINNA_PCTV_USB_NTSC_FM_V3 }, 1110 - { USB_DEVICE(0x2304, 0x0210), .driver_info = PINNA_PCTV_USB_PAL_FM_V2 }, 1111 - { USB_DEVICE(0x2304, 0x0212), .driver_info = PINNA_PCTV_USB_NTSC_FM_V2 }, 1112 - { USB_DEVICE(0x2304, 0x0214), .driver_info = PINNA_PCTV_USB_PAL_FM_V3 }, 1113 - { USB_DEVICE(0x2304, 0x0300), .driver_info = PINNA_LINX_VD_IN_CAB_NTSC }, 1114 - { USB_DEVICE(0x2304, 0x0301), .driver_info = PINNA_LINX_VD_IN_CAB_PAL }, 1115 - { USB_DEVICE(0x2304, 0x0419), .driver_info = PINNA_PCTV_BUNGEE_PAL_FM }, 1116 - { USB_DEVICE(0x2400, 0x4200), .driver_info = HPG_WINTV }, 1117 - { }, /* terminate list */ 1118 - }; 1119 - 1120 - MODULE_DEVICE_TABLE(usb, usbvision_table);
-70
drivers/staging/media/usbvision/usbvision-cards.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #define XANBOO 0 3 - #define BELKIN_VIDEOBUS_II 1 4 - #define BELKIN_VIDEOBUS 2 5 - #define BELKIN_USB_VIDEOBUS_II 3 6 - #define ECHOFX_INTERVIEW_LITE 4 7 - #define USBGEAR_USBG_V1 5 8 - #define D_LINK_V100 6 9 - #define X10_USB_CAMERA 7 10 - #define HPG_WINTV_LIVE_PAL_BG 8 11 - #define HPG_WINTV_LIVE_PRO_NTSC_MN 9 12 - #define ZORAN_PMD_NOGATECH 10 13 - #define NOGATECH_USB_TV_NTSC_FM 11 14 - #define PNY_USB_TV_NTSC_FM 12 15 - #define PV_PLAYTV_USB_PRO_PAL_FM 13 16 - #define ZT_721 14 17 - #define HPG_WINTV_NTSC_MN 15 18 - #define HPG_WINTV_PAL_BG 16 19 - #define HPG_WINTV_PAL_I 17 20 - #define HPG_WINTV_PAL_SECAM_L 18 21 - #define HPG_WINTV_PAL_D_K 19 22 - #define HPG_WINTV_NTSC_FM 20 23 - #define HPG_WINTV_PAL_BG_FM 21 24 - #define HPG_WINTV_PAL_I_FM 22 25 - #define HPG_WINTV_PAL_D_K_FM 23 26 - #define HPG_WINTV_PRO_NTSC_MN 24 27 - #define HPG_WINTV_PRO_NTSC_MN_V2 25 28 - #define HPG_WINTV_PRO_PAL 26 29 - #define HPG_WINTV_PRO_NTSC_MN_V3 27 30 - #define HPG_WINTV_PRO_PAL_BG 28 31 - #define HPG_WINTV_PRO_PAL_I 29 32 - #define HPG_WINTV_PRO_PAL_SECAM_L 30 33 - #define HPG_WINTV_PRO_PAL_D_K 31 34 - #define HPG_WINTV_PRO_PAL_SECAM 32 35 - #define HPG_WINTV_PRO_PAL_SECAM_V2 33 36 - #define HPG_WINTV_PRO_PAL_BG_V2 34 37 - #define HPG_WINTV_PRO_PAL_BG_D_K 35 38 - #define HPG_WINTV_PRO_PAL_I_D_K 36 39 - #define HPG_WINTV_PRO_NTSC_MN_FM 37 40 - #define HPG_WINTV_PRO_PAL_BG_FM 38 41 - #define HPG_WINTV_PRO_PAL_I_FM 39 42 - #define HPG_WINTV_PRO_PAL_D_K_FM 40 43 - #define HPG_WINTV_PRO_TEMIC_PAL_FM 41 44 - #define HPG_WINTV_PRO_TEMIC_PAL_BG_FM 42 45 - #define HPG_WINTV_PRO_PAL_FM 43 46 - #define HPG_WINTV_PRO_NTSC_MN_FM_V2 44 47 - #define CAMTEL_TVB330 45 48 - #define DIGITAL_VIDEO_CREATOR_I 46 49 - #define GLOBAL_VILLAGE_GV_007_NTSC 47 50 - #define DAZZLE_DVC_50_REV_1_NTSC 48 51 - #define DAZZLE_DVC_80_REV_1_PAL 49 52 - #define DAZZLE_DVC_90_REV_1_SECAM 50 53 - #define ESKAPE_LABS_MYTV2GO 51 54 - #define PINNA_PCTV_USB_PAL 52 55 - #define PINNA_PCTV_USB_SECAM 53 56 - #define PINNA_PCTV_USB_PAL_FM 54 57 - #define MIRO_PCTV_USB 55 58 - #define PINNA_PCTV_USB_NTSC_FM 56 59 - #define PINNA_PCTV_USB_PAL_FM_V2 57 60 - #define PINNA_PCTV_USB_NTSC_FM_V2 58 61 - #define PINNA_PCTV_USB_PAL_FM_V3 59 62 - #define PINNA_LINX_VD_IN_CAB_NTSC 60 63 - #define PINNA_LINX_VD_IN_CAB_PAL 61 64 - #define PINNA_PCTV_BUNGEE_PAL_FM 62 65 - #define HPG_WINTV 63 66 - #define PINNA_PCTV_USB_NTSC_FM_V3 64 67 - #define MICROCAM_NTSC 65 68 - #define MICROCAM_PAL 66 69 - 70 - extern const int usbvision_device_data_size;
-2428
drivers/staging/media/usbvision/usbvision-core.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * usbvision-core.c - driver for NT100x USB video capture devices 4 - * 5 - * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> 6 - * Dwaine Garden <dwainegarden@rogers.com> 7 - * 8 - * This module is part of usbvision driver project. 9 - * Updates to driver completed by Dwaine P. Garden 10 - */ 11 - 12 - #include <linux/kernel.h> 13 - #include <linux/list.h> 14 - #include <linux/timer.h> 15 - #include <linux/gfp.h> 16 - #include <linux/mm.h> 17 - #include <linux/highmem.h> 18 - #include <linux/vmalloc.h> 19 - #include <linux/module.h> 20 - #include <linux/init.h> 21 - #include <linux/spinlock.h> 22 - #include <linux/io.h> 23 - #include <linux/videodev2.h> 24 - #include <linux/i2c.h> 25 - 26 - #include <media/i2c/saa7115.h> 27 - #include <media/v4l2-common.h> 28 - #include <media/tuner.h> 29 - 30 - #include <linux/workqueue.h> 31 - 32 - #include "usbvision.h" 33 - 34 - static unsigned int core_debug; 35 - module_param(core_debug, int, 0644); 36 - MODULE_PARM_DESC(core_debug, "enable debug messages [core]"); 37 - 38 - static int adjust_compression = 1; /* Set the compression to be adaptive */ 39 - module_param(adjust_compression, int, 0444); 40 - MODULE_PARM_DESC(adjust_compression, " Set the ADPCM compression for the device. Default: 1 (On)"); 41 - 42 - /* To help people with Black and White output with using s-video input. 43 - * Some cables and input device are wired differently. */ 44 - static int switch_svideo_input; 45 - module_param(switch_svideo_input, int, 0444); 46 - MODULE_PARM_DESC(switch_svideo_input, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)"); 47 - 48 - static unsigned int adjust_x_offset = -1; 49 - module_param(adjust_x_offset, int, 0644); 50 - MODULE_PARM_DESC(adjust_x_offset, "adjust X offset display [core]"); 51 - 52 - static unsigned int adjust_y_offset = -1; 53 - module_param(adjust_y_offset, int, 0644); 54 - MODULE_PARM_DESC(adjust_y_offset, "adjust Y offset display [core]"); 55 - 56 - 57 - #define ENABLE_HEXDUMP 0 /* Enable if you need it */ 58 - 59 - 60 - #ifdef USBVISION_DEBUG 61 - #define PDEBUG(level, fmt, args...) { \ 62 - if (core_debug & (level)) \ 63 - printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ 64 - __func__, __LINE__ , ## args); \ 65 - } 66 - #else 67 - #define PDEBUG(level, fmt, args...) do {} while (0) 68 - #endif 69 - 70 - #define DBG_HEADER (1 << 0) 71 - #define DBG_IRQ (1 << 1) 72 - #define DBG_ISOC (1 << 2) 73 - #define DBG_PARSE (1 << 3) 74 - #define DBG_SCRATCH (1 << 4) 75 - #define DBG_FUNC (1 << 5) 76 - 77 - /* The value of 'scratch_buf_size' affects quality of the picture 78 - * in many ways. Shorter buffers may cause loss of data when client 79 - * is too slow. Larger buffers are memory-consuming and take longer 80 - * to work with. This setting can be adjusted, but the default value 81 - * should be OK for most desktop users. 82 - */ 83 - #define DEFAULT_SCRATCH_BUF_SIZE (0x20000) /* 128kB memory scratch buffer */ 84 - static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE; 85 - 86 - /* Function prototypes */ 87 - static int usbvision_request_intra(struct usb_usbvision *usbvision); 88 - static int usbvision_unrequest_intra(struct usb_usbvision *usbvision); 89 - static int usbvision_adjust_compression(struct usb_usbvision *usbvision); 90 - static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision); 91 - 92 - /*******************************/ 93 - /* Memory management functions */ 94 - /*******************************/ 95 - 96 - /* 97 - * Here we want the physical address of the memory. 98 - * This is used when initializing the contents of the area. 99 - */ 100 - 101 - static void *usbvision_rvmalloc(unsigned long size) 102 - { 103 - void *mem; 104 - unsigned long adr; 105 - 106 - size = PAGE_ALIGN(size); 107 - mem = vmalloc_32(size); 108 - if (!mem) 109 - return NULL; 110 - 111 - memset(mem, 0, size); /* Clear the ram out, no junk to the user */ 112 - adr = (unsigned long) mem; 113 - while (size > 0) { 114 - SetPageReserved(vmalloc_to_page((void *)adr)); 115 - adr += PAGE_SIZE; 116 - size -= PAGE_SIZE; 117 - } 118 - 119 - return mem; 120 - } 121 - 122 - static void usbvision_rvfree(void *mem, unsigned long size) 123 - { 124 - unsigned long adr; 125 - 126 - if (!mem) 127 - return; 128 - 129 - size = PAGE_ALIGN(size); 130 - 131 - adr = (unsigned long) mem; 132 - while ((long) size > 0) { 133 - ClearPageReserved(vmalloc_to_page((void *)adr)); 134 - adr += PAGE_SIZE; 135 - size -= PAGE_SIZE; 136 - } 137 - 138 - vfree(mem); 139 - } 140 - 141 - 142 - #if ENABLE_HEXDUMP 143 - static void usbvision_hexdump(const unsigned char *data, int len) 144 - { 145 - char tmp[80]; 146 - int i, k; 147 - 148 - for (i = k = 0; len > 0; i++, len--) { 149 - if (i > 0 && (i % 16 == 0)) { 150 - printk("%s\n", tmp); 151 - k = 0; 152 - } 153 - k += sprintf(&tmp[k], "%02x ", data[i]); 154 - } 155 - if (k > 0) 156 - printk(KERN_CONT "%s\n", tmp); 157 - } 158 - #endif 159 - 160 - /******************************** 161 - * scratch ring buffer handling 162 - ********************************/ 163 - static int scratch_len(struct usb_usbvision *usbvision) /* This returns the amount of data actually in the buffer */ 164 - { 165 - int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr; 166 - 167 - if (len < 0) 168 - len += scratch_buf_size; 169 - PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len); 170 - 171 - return len; 172 - } 173 - 174 - 175 - /* This returns the free space left in the buffer */ 176 - static int scratch_free(struct usb_usbvision *usbvision) 177 - { 178 - int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr; 179 - if (free <= 0) 180 - free += scratch_buf_size; 181 - if (free) { 182 - free -= 1; /* at least one byte in the buffer must */ 183 - /* left blank, otherwise there is no chance to differ between full and empty */ 184 - } 185 - PDEBUG(DBG_SCRATCH, "return %d\n", free); 186 - 187 - return free; 188 - } 189 - 190 - 191 - /* This puts data into the buffer */ 192 - static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, 193 - int len) 194 - { 195 - int len_part; 196 - 197 - if (usbvision->scratch_write_ptr + len < scratch_buf_size) { 198 - memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len); 199 - usbvision->scratch_write_ptr += len; 200 - } else { 201 - len_part = scratch_buf_size - usbvision->scratch_write_ptr; 202 - memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part); 203 - if (len == len_part) { 204 - usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */ 205 - } else { 206 - memcpy(usbvision->scratch, data + len_part, len - len_part); 207 - usbvision->scratch_write_ptr = len - len_part; 208 - } 209 - } 210 - 211 - PDEBUG(DBG_SCRATCH, "len=%d, new write_ptr=%d\n", len, usbvision->scratch_write_ptr); 212 - 213 - return len; 214 - } 215 - 216 - /* This marks the write_ptr as position of new frame header */ 217 - static void scratch_mark_header(struct usb_usbvision *usbvision) 218 - { 219 - PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr); 220 - 221 - usbvision->scratch_headermarker[usbvision->scratch_headermarker_write_ptr] = 222 - usbvision->scratch_write_ptr; 223 - usbvision->scratch_headermarker_write_ptr += 1; 224 - usbvision->scratch_headermarker_write_ptr %= USBVISION_NUM_HEADERMARKER; 225 - } 226 - 227 - /* This gets data from the buffer at the given "ptr" position */ 228 - static int scratch_get_extra(struct usb_usbvision *usbvision, 229 - unsigned char *data, int *ptr, int len) 230 - { 231 - int len_part; 232 - 233 - if (*ptr + len < scratch_buf_size) { 234 - memcpy(data, usbvision->scratch + *ptr, len); 235 - *ptr += len; 236 - } else { 237 - len_part = scratch_buf_size - *ptr; 238 - memcpy(data, usbvision->scratch + *ptr, len_part); 239 - if (len == len_part) { 240 - *ptr = 0; /* just set the y_ptr to zero */ 241 - } else { 242 - memcpy(data + len_part, usbvision->scratch, len - len_part); 243 - *ptr = len - len_part; 244 - } 245 - } 246 - 247 - PDEBUG(DBG_SCRATCH, "len=%d, new ptr=%d\n", len, *ptr); 248 - 249 - return len; 250 - } 251 - 252 - 253 - /* This sets the scratch extra read pointer */ 254 - static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, 255 - int len) 256 - { 257 - *ptr = (usbvision->scratch_read_ptr + len) % scratch_buf_size; 258 - 259 - PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr); 260 - } 261 - 262 - 263 - /* This increments the scratch extra read pointer */ 264 - static void scratch_inc_extra_ptr(int *ptr, int len) 265 - { 266 - *ptr = (*ptr + len) % scratch_buf_size; 267 - 268 - PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr); 269 - } 270 - 271 - 272 - /* This gets data from the buffer */ 273 - static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, 274 - int len) 275 - { 276 - int len_part; 277 - 278 - if (usbvision->scratch_read_ptr + len < scratch_buf_size) { 279 - memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len); 280 - usbvision->scratch_read_ptr += len; 281 - } else { 282 - len_part = scratch_buf_size - usbvision->scratch_read_ptr; 283 - memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part); 284 - if (len == len_part) { 285 - usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */ 286 - } else { 287 - memcpy(data + len_part, usbvision->scratch, len - len_part); 288 - usbvision->scratch_read_ptr = len - len_part; 289 - } 290 - } 291 - 292 - PDEBUG(DBG_SCRATCH, "len=%d, new read_ptr=%d\n", len, usbvision->scratch_read_ptr); 293 - 294 - return len; 295 - } 296 - 297 - 298 - /* This sets read pointer to next header and returns it */ 299 - static int scratch_get_header(struct usb_usbvision *usbvision, 300 - struct usbvision_frame_header *header) 301 - { 302 - int err_code = 0; 303 - 304 - PDEBUG(DBG_SCRATCH, "from read_ptr=%d", usbvision->scratch_headermarker_read_ptr); 305 - 306 - while (usbvision->scratch_headermarker_write_ptr - 307 - usbvision->scratch_headermarker_read_ptr != 0) { 308 - usbvision->scratch_read_ptr = 309 - usbvision->scratch_headermarker[usbvision->scratch_headermarker_read_ptr]; 310 - usbvision->scratch_headermarker_read_ptr += 1; 311 - usbvision->scratch_headermarker_read_ptr %= USBVISION_NUM_HEADERMARKER; 312 - scratch_get(usbvision, (unsigned char *)header, USBVISION_HEADER_LENGTH); 313 - if ((header->magic_1 == USBVISION_MAGIC_1) 314 - && (header->magic_2 == USBVISION_MAGIC_2) 315 - && (header->header_length == USBVISION_HEADER_LENGTH)) { 316 - err_code = USBVISION_HEADER_LENGTH; 317 - header->frame_width = header->frame_width_lo + (header->frame_width_hi << 8); 318 - header->frame_height = header->frame_height_lo + (header->frame_height_hi << 8); 319 - break; 320 - } 321 - } 322 - 323 - return err_code; 324 - } 325 - 326 - 327 - /* This removes len bytes of old data from the buffer */ 328 - static void scratch_rm_old(struct usb_usbvision *usbvision, int len) 329 - { 330 - usbvision->scratch_read_ptr += len; 331 - usbvision->scratch_read_ptr %= scratch_buf_size; 332 - PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr); 333 - } 334 - 335 - 336 - /* This resets the buffer - kills all data in it too */ 337 - static void scratch_reset(struct usb_usbvision *usbvision) 338 - { 339 - PDEBUG(DBG_SCRATCH, "\n"); 340 - 341 - usbvision->scratch_read_ptr = 0; 342 - usbvision->scratch_write_ptr = 0; 343 - usbvision->scratch_headermarker_read_ptr = 0; 344 - usbvision->scratch_headermarker_write_ptr = 0; 345 - usbvision->isocstate = isoc_state_no_frame; 346 - } 347 - 348 - int usbvision_scratch_alloc(struct usb_usbvision *usbvision) 349 - { 350 - usbvision->scratch = vmalloc_32(scratch_buf_size); 351 - scratch_reset(usbvision); 352 - if (usbvision->scratch == NULL) { 353 - dev_err(&usbvision->dev->dev, 354 - "%s: unable to allocate %d bytes for scratch\n", 355 - __func__, scratch_buf_size); 356 - return -ENOMEM; 357 - } 358 - return 0; 359 - } 360 - 361 - void usbvision_scratch_free(struct usb_usbvision *usbvision) 362 - { 363 - vfree(usbvision->scratch); 364 - usbvision->scratch = NULL; 365 - } 366 - 367 - /* 368 - * usbvision_decompress_alloc() 369 - * 370 - * allocates intermediate buffer for decompression 371 - */ 372 - int usbvision_decompress_alloc(struct usb_usbvision *usbvision) 373 - { 374 - int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 375 - 376 - usbvision->intra_frame_buffer = vmalloc_32(IFB_size); 377 - if (usbvision->intra_frame_buffer == NULL) { 378 - dev_err(&usbvision->dev->dev, 379 - "%s: unable to allocate %d for compr. frame buffer\n", 380 - __func__, IFB_size); 381 - return -ENOMEM; 382 - } 383 - return 0; 384 - } 385 - 386 - /* 387 - * usbvision_decompress_free() 388 - * 389 - * frees intermediate buffer for decompression 390 - */ 391 - void usbvision_decompress_free(struct usb_usbvision *usbvision) 392 - { 393 - vfree(usbvision->intra_frame_buffer); 394 - usbvision->intra_frame_buffer = NULL; 395 - 396 - } 397 - 398 - /************************************************************ 399 - * Here comes the data parsing stuff that is run as interrupt 400 - ************************************************************/ 401 - /* 402 - * usbvision_find_header() 403 - * 404 - * Locate one of supported header markers in the scratch buffer. 405 - */ 406 - static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision) 407 - { 408 - struct usbvision_frame *frame; 409 - int found_header = 0; 410 - 411 - frame = usbvision->cur_frame; 412 - 413 - while (scratch_get_header(usbvision, &frame->isoc_header) == USBVISION_HEADER_LENGTH) { 414 - /* found header in scratch */ 415 - PDEBUG(DBG_HEADER, "found header: 0x%02x%02x %d %d %d %d %#x 0x%02x %u %u", 416 - frame->isoc_header.magic_2, 417 - frame->isoc_header.magic_1, 418 - frame->isoc_header.header_length, 419 - frame->isoc_header.frame_num, 420 - frame->isoc_header.frame_phase, 421 - frame->isoc_header.frame_latency, 422 - frame->isoc_header.data_format, 423 - frame->isoc_header.format_param, 424 - frame->isoc_header.frame_width, 425 - frame->isoc_header.frame_height); 426 - 427 - if (usbvision->request_intra) { 428 - if (frame->isoc_header.format_param & 0x80) { 429 - found_header = 1; 430 - usbvision->last_isoc_frame_num = -1; /* do not check for lost frames this time */ 431 - usbvision_unrequest_intra(usbvision); 432 - break; 433 - } 434 - } else { 435 - found_header = 1; 436 - break; 437 - } 438 - } 439 - 440 - if (found_header) { 441 - frame->frmwidth = frame->isoc_header.frame_width * usbvision->stretch_width; 442 - frame->frmheight = frame->isoc_header.frame_height * usbvision->stretch_height; 443 - frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth) >> 3; 444 - } else { /* no header found */ 445 - PDEBUG(DBG_HEADER, "skipping scratch data, no header"); 446 - scratch_reset(usbvision); 447 - return parse_state_end_parse; 448 - } 449 - 450 - /* found header */ 451 - if (frame->isoc_header.data_format == ISOC_MODE_COMPRESS) { 452 - /* check isoc_header.frame_num for lost frames */ 453 - if (usbvision->last_isoc_frame_num >= 0) { 454 - if (((usbvision->last_isoc_frame_num + 1) % 32) != frame->isoc_header.frame_num) { 455 - /* unexpected frame drop: need to request new intra frame */ 456 - PDEBUG(DBG_HEADER, "Lost frame before %d on USB", frame->isoc_header.frame_num); 457 - usbvision_request_intra(usbvision); 458 - return parse_state_next_frame; 459 - } 460 - } 461 - usbvision->last_isoc_frame_num = frame->isoc_header.frame_num; 462 - } 463 - usbvision->header_count++; 464 - frame->scanstate = scan_state_lines; 465 - frame->curline = 0; 466 - 467 - return parse_state_continue; 468 - } 469 - 470 - static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvision, 471 - long *pcopylen) 472 - { 473 - volatile struct usbvision_frame *frame; 474 - unsigned char *f; 475 - int len; 476 - int i; 477 - unsigned char yuyv[4] = { 180, 128, 10, 128 }; /* YUV components */ 478 - unsigned char rv, gv, bv; /* RGB components */ 479 - int clipmask_index, bytes_per_pixel; 480 - int stretch_bytes, clipmask_add; 481 - 482 - frame = usbvision->cur_frame; 483 - f = frame->data + (frame->v4l2_linesize * frame->curline); 484 - 485 - /* Make sure there's enough data for the entire line */ 486 - len = (frame->isoc_header.frame_width * 2) + 5; 487 - if (scratch_len(usbvision) < len) { 488 - PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len); 489 - return parse_state_out; 490 - } 491 - 492 - if ((frame->curline + 1) >= frame->frmheight) 493 - return parse_state_next_frame; 494 - 495 - bytes_per_pixel = frame->v4l2_format.bytes_per_pixel; 496 - stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel; 497 - clipmask_index = frame->curline * MAX_FRAME_WIDTH; 498 - clipmask_add = usbvision->stretch_width; 499 - 500 - for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) { 501 - scratch_get(usbvision, &yuyv[0], 4); 502 - 503 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 504 - *f++ = yuyv[0]; /* Y */ 505 - *f++ = yuyv[3]; /* U */ 506 - } else { 507 - YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv); 508 - switch (frame->v4l2_format.format) { 509 - case V4L2_PIX_FMT_RGB565: 510 - *f++ = (0x1F & rv) | 511 - (0xE0 & (gv << 5)); 512 - *f++ = (0x07 & (gv >> 3)) | 513 - (0xF8 & bv); 514 - break; 515 - case V4L2_PIX_FMT_RGB24: 516 - *f++ = rv; 517 - *f++ = gv; 518 - *f++ = bv; 519 - break; 520 - case V4L2_PIX_FMT_RGB32: 521 - *f++ = rv; 522 - *f++ = gv; 523 - *f++ = bv; 524 - f++; 525 - break; 526 - case V4L2_PIX_FMT_RGB555: 527 - *f++ = (0x1F & rv) | 528 - (0xE0 & (gv << 5)); 529 - *f++ = (0x03 & (gv >> 3)) | 530 - (0x7C & (bv << 2)); 531 - break; 532 - } 533 - } 534 - clipmask_index += clipmask_add; 535 - f += stretch_bytes; 536 - 537 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 538 - *f++ = yuyv[2]; /* Y */ 539 - *f++ = yuyv[1]; /* V */ 540 - } else { 541 - YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv); 542 - switch (frame->v4l2_format.format) { 543 - case V4L2_PIX_FMT_RGB565: 544 - *f++ = (0x1F & rv) | 545 - (0xE0 & (gv << 5)); 546 - *f++ = (0x07 & (gv >> 3)) | 547 - (0xF8 & bv); 548 - break; 549 - case V4L2_PIX_FMT_RGB24: 550 - *f++ = rv; 551 - *f++ = gv; 552 - *f++ = bv; 553 - break; 554 - case V4L2_PIX_FMT_RGB32: 555 - *f++ = rv; 556 - *f++ = gv; 557 - *f++ = bv; 558 - f++; 559 - break; 560 - case V4L2_PIX_FMT_RGB555: 561 - *f++ = (0x1F & rv) | 562 - (0xE0 & (gv << 5)); 563 - *f++ = (0x03 & (gv >> 3)) | 564 - (0x7C & (bv << 2)); 565 - break; 566 - } 567 - } 568 - clipmask_index += clipmask_add; 569 - f += stretch_bytes; 570 - } 571 - 572 - frame->curline += usbvision->stretch_height; 573 - *pcopylen += frame->v4l2_linesize * usbvision->stretch_height; 574 - 575 - if (frame->curline >= frame->frmheight) 576 - return parse_state_next_frame; 577 - return parse_state_continue; 578 - } 579 - 580 - /* The decompression routine */ 581 - static int usbvision_decompress(struct usb_usbvision *usbvision, unsigned char *compressed, 582 - unsigned char *decompressed, int *start_pos, 583 - int *block_typestart_pos, int len) 584 - { 585 - int rest_pixel, idx, pos, extra_pos, block_len, block_type_pos, block_type_len; 586 - unsigned char block_byte, block_code, block_type, block_type_byte, integrator; 587 - 588 - integrator = 0; 589 - pos = *start_pos; 590 - block_type_pos = *block_typestart_pos; 591 - extra_pos = pos; 592 - block_len = 0; 593 - block_byte = 0; 594 - block_code = 0; 595 - block_type = 0; 596 - block_type_byte = 0; 597 - block_type_len = 0; 598 - rest_pixel = len; 599 - 600 - for (idx = 0; idx < len; idx++) { 601 - if (block_len == 0) { 602 - if (block_type_len == 0) { 603 - block_type_byte = compressed[block_type_pos]; 604 - block_type_pos++; 605 - block_type_len = 4; 606 - } 607 - block_type = (block_type_byte & 0xC0) >> 6; 608 - 609 - /* statistic: */ 610 - usbvision->compr_block_types[block_type]++; 611 - 612 - pos = extra_pos; 613 - if (block_type == 0) { 614 - if (rest_pixel >= 24) { 615 - idx += 23; 616 - rest_pixel -= 24; 617 - integrator = decompressed[idx]; 618 - } else { 619 - idx += rest_pixel - 1; 620 - rest_pixel = 0; 621 - } 622 - } else { 623 - block_code = compressed[pos]; 624 - pos++; 625 - if (rest_pixel >= 24) 626 - block_len = 24; 627 - else 628 - block_len = rest_pixel; 629 - rest_pixel -= block_len; 630 - extra_pos = pos + (block_len / 4); 631 - } 632 - block_type_byte <<= 2; 633 - block_type_len -= 1; 634 - } 635 - if (block_len > 0) { 636 - if ((block_len % 4) == 0) { 637 - block_byte = compressed[pos]; 638 - pos++; 639 - } 640 - if (block_type == 1) /* inter Block */ 641 - integrator = decompressed[idx]; 642 - switch (block_byte & 0xC0) { 643 - case 0x03 << 6: 644 - integrator += compressed[extra_pos]; 645 - extra_pos++; 646 - break; 647 - case 0x02 << 6: 648 - integrator += block_code; 649 - break; 650 - case 0x00: 651 - integrator -= block_code; 652 - break; 653 - } 654 - decompressed[idx] = integrator; 655 - block_byte <<= 2; 656 - block_len -= 1; 657 - } 658 - } 659 - *start_pos = extra_pos; 660 - *block_typestart_pos = block_type_pos; 661 - return idx; 662 - } 663 - 664 - 665 - /* 666 - * usbvision_parse_compress() 667 - * 668 - * Parse compressed frame from the scratch buffer, put 669 - * decoded RGB value into the current frame buffer and add the written 670 - * number of bytes (RGB) to the *pcopylen. 671 - * 672 - */ 673 - static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision, 674 - long *pcopylen) 675 - { 676 - #define USBVISION_STRIP_MAGIC 0x5A 677 - #define USBVISION_STRIP_LEN_MAX 400 678 - #define USBVISION_STRIP_HEADER_LEN 3 679 - 680 - struct usbvision_frame *frame; 681 - unsigned char *f, *u = NULL, *v = NULL; 682 - unsigned char strip_data[USBVISION_STRIP_LEN_MAX]; 683 - unsigned char strip_header[USBVISION_STRIP_HEADER_LEN]; 684 - int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos; 685 - int clipmask_index; 686 - int image_size; 687 - unsigned char rv, gv, bv; 688 - static unsigned char *Y, *U, *V; 689 - 690 - frame = usbvision->cur_frame; 691 - image_size = frame->frmwidth * frame->frmheight; 692 - if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) || 693 - (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) { /* this is a planar format */ 694 - /* ... v4l2_linesize not used here. */ 695 - f = frame->data + (frame->width * frame->curline); 696 - } else 697 - f = frame->data + (frame->v4l2_linesize * frame->curline); 698 - 699 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */ 700 - /* get base of u and b planes add halfoffset */ 701 - u = frame->data 702 - + image_size 703 - + (frame->frmwidth >> 1) * frame->curline; 704 - v = u + (image_size >> 1); 705 - } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) { 706 - v = frame->data + image_size + ((frame->curline * (frame->width)) >> 2); 707 - u = v + (image_size >> 2); 708 - } 709 - 710 - if (frame->curline == 0) 711 - usbvision_adjust_compression(usbvision); 712 - 713 - if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN) 714 - return parse_state_out; 715 - 716 - /* get strip header without changing the scratch_read_ptr */ 717 - scratch_set_extra_ptr(usbvision, &strip_ptr, 0); 718 - scratch_get_extra(usbvision, &strip_header[0], &strip_ptr, 719 - USBVISION_STRIP_HEADER_LEN); 720 - 721 - if (strip_header[0] != USBVISION_STRIP_MAGIC) { 722 - /* wrong strip magic */ 723 - usbvision->strip_magic_errors++; 724 - return parse_state_next_frame; 725 - } 726 - 727 - if (frame->curline != (int)strip_header[2]) { 728 - /* line number mismatch error */ 729 - usbvision->strip_line_number_errors++; 730 - } 731 - 732 - strip_len = 2 * (unsigned int)strip_header[1]; 733 - if (strip_len > USBVISION_STRIP_LEN_MAX) { 734 - /* strip overrun */ 735 - /* I think this never happens */ 736 - usbvision_request_intra(usbvision); 737 - } 738 - 739 - if (scratch_len(usbvision) < strip_len) { 740 - /* there is not enough data for the strip */ 741 - return parse_state_out; 742 - } 743 - 744 - if (usbvision->intra_frame_buffer) { 745 - Y = usbvision->intra_frame_buffer + frame->frmwidth * frame->curline; 746 - U = usbvision->intra_frame_buffer + image_size + (frame->frmwidth / 2) * (frame->curline / 2); 747 - V = usbvision->intra_frame_buffer + image_size / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2); 748 - } else { 749 - return parse_state_next_frame; 750 - } 751 - 752 - clipmask_index = frame->curline * MAX_FRAME_WIDTH; 753 - 754 - scratch_get(usbvision, strip_data, strip_len); 755 - 756 - idx_end = frame->frmwidth; 757 - block_type_pos = USBVISION_STRIP_HEADER_LEN; 758 - startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2; 759 - block_pos = startblock_pos; 760 - 761 - usbvision->block_pos = block_pos; 762 - 763 - usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end); 764 - if (strip_len > usbvision->max_strip_len) 765 - usbvision->max_strip_len = strip_len; 766 - 767 - if (frame->curline % 2) 768 - usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end / 2); 769 - else 770 - usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end / 2); 771 - 772 - if (block_pos > usbvision->comprblock_pos) 773 - usbvision->comprblock_pos = block_pos; 774 - if (block_pos > strip_len) 775 - usbvision->strip_len_errors++; 776 - 777 - for (idx = 0; idx < idx_end; idx++) { 778 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 779 - *f++ = Y[idx]; 780 - *f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2]; 781 - } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) { 782 - *f++ = Y[idx]; 783 - if (idx & 0x01) 784 - *u++ = U[idx >> 1]; 785 - else 786 - *v++ = V[idx >> 1]; 787 - } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) { 788 - *f++ = Y[idx]; 789 - if (!((idx & 0x01) | (frame->curline & 0x01))) { 790 - /* only need do this for 1 in 4 pixels */ 791 - /* intraframe buffer is YUV420 format */ 792 - *u++ = U[idx >> 1]; 793 - *v++ = V[idx >> 1]; 794 - } 795 - } else { 796 - YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv); 797 - switch (frame->v4l2_format.format) { 798 - case V4L2_PIX_FMT_GREY: 799 - *f++ = Y[idx]; 800 - break; 801 - case V4L2_PIX_FMT_RGB555: 802 - *f++ = (0x1F & rv) | 803 - (0xE0 & (gv << 5)); 804 - *f++ = (0x03 & (gv >> 3)) | 805 - (0x7C & (bv << 2)); 806 - break; 807 - case V4L2_PIX_FMT_RGB565: 808 - *f++ = (0x1F & rv) | 809 - (0xE0 & (gv << 5)); 810 - *f++ = (0x07 & (gv >> 3)) | 811 - (0xF8 & bv); 812 - break; 813 - case V4L2_PIX_FMT_RGB24: 814 - *f++ = rv; 815 - *f++ = gv; 816 - *f++ = bv; 817 - break; 818 - case V4L2_PIX_FMT_RGB32: 819 - *f++ = rv; 820 - *f++ = gv; 821 - *f++ = bv; 822 - f++; 823 - break; 824 - } 825 - } 826 - clipmask_index++; 827 - } 828 - /* Deal with non-integer no. of bytes for YUV420P */ 829 - if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420) 830 - *pcopylen += frame->v4l2_linesize; 831 - else 832 - *pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1; 833 - 834 - frame->curline += 1; 835 - 836 - if (frame->curline >= frame->frmheight) 837 - return parse_state_next_frame; 838 - return parse_state_continue; 839 - 840 - } 841 - 842 - 843 - /* 844 - * usbvision_parse_lines_420() 845 - * 846 - * Parse two lines from the scratch buffer, put 847 - * decoded RGB value into the current frame buffer and add the written 848 - * number of bytes (RGB) to the *pcopylen. 849 - * 850 - */ 851 - static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvision, 852 - long *pcopylen) 853 - { 854 - struct usbvision_frame *frame; 855 - unsigned char *f_even = NULL, *f_odd = NULL; 856 - unsigned int pixel_per_line, block; 857 - int pixel, block_split; 858 - int y_ptr, u_ptr, v_ptr, y_odd_offset; 859 - const int y_block_size = 128; 860 - const int uv_block_size = 64; 861 - const int sub_block_size = 32; 862 - const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4; 863 - const int uv_step[] = { 0, 0, 0, 4 }, uv_step_size = 4; 864 - unsigned char y[2], u, v; /* YUV components */ 865 - int y_, u_, v_, vb, uvg, ur; 866 - int r_, g_, b_; /* RGB components */ 867 - unsigned char g; 868 - int clipmask_even_index, clipmask_odd_index, bytes_per_pixel; 869 - int clipmask_add, stretch_bytes; 870 - 871 - frame = usbvision->cur_frame; 872 - f_even = frame->data + (frame->v4l2_linesize * frame->curline); 873 - f_odd = f_even + frame->v4l2_linesize * usbvision->stretch_height; 874 - 875 - /* Make sure there's enough data for the entire line */ 876 - /* In this mode usbvision transfer 3 bytes for every 2 pixels */ 877 - /* I need two lines to decode the color */ 878 - bytes_per_pixel = frame->v4l2_format.bytes_per_pixel; 879 - stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel; 880 - clipmask_even_index = frame->curline * MAX_FRAME_WIDTH; 881 - clipmask_odd_index = clipmask_even_index + MAX_FRAME_WIDTH; 882 - clipmask_add = usbvision->stretch_width; 883 - pixel_per_line = frame->isoc_header.frame_width; 884 - 885 - if (scratch_len(usbvision) < (int)pixel_per_line * 3) { 886 - /* printk(KERN_DEBUG "out of data, need %d\n", len); */ 887 - return parse_state_out; 888 - } 889 - 890 - if ((frame->curline + 1) >= frame->frmheight) 891 - return parse_state_next_frame; 892 - 893 - block_split = (pixel_per_line%y_block_size) ? 1 : 0; /* are some blocks split into different lines? */ 894 - 895 - y_odd_offset = (pixel_per_line / y_block_size) * (y_block_size + uv_block_size) 896 - + block_split * uv_block_size; 897 - 898 - scratch_set_extra_ptr(usbvision, &y_ptr, y_odd_offset); 899 - scratch_set_extra_ptr(usbvision, &u_ptr, y_block_size); 900 - scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset 901 - + (4 - block_split) * sub_block_size); 902 - 903 - for (block = 0; block < (pixel_per_line / sub_block_size); block++) { 904 - for (pixel = 0; pixel < sub_block_size; pixel += 2) { 905 - scratch_get(usbvision, &y[0], 2); 906 - scratch_get_extra(usbvision, &u, &u_ptr, 1); 907 - scratch_get_extra(usbvision, &v, &v_ptr, 1); 908 - 909 - /* I don't use the YUV_TO_RGB macro for better performance */ 910 - v_ = v - 128; 911 - u_ = u - 128; 912 - vb = 132252 * v_; 913 - uvg = -53281 * u_ - 25625 * v_; 914 - ur = 104595 * u_; 915 - 916 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 917 - *f_even++ = y[0]; 918 - *f_even++ = v; 919 - } else { 920 - y_ = 76284 * (y[0] - 16); 921 - 922 - b_ = (y_ + vb) >> 16; 923 - g_ = (y_ + uvg) >> 16; 924 - r_ = (y_ + ur) >> 16; 925 - 926 - switch (frame->v4l2_format.format) { 927 - case V4L2_PIX_FMT_RGB565: 928 - g = LIMIT_RGB(g_); 929 - *f_even++ = 930 - (0x1F & LIMIT_RGB(r_)) | 931 - (0xE0 & (g << 5)); 932 - *f_even++ = 933 - (0x07 & (g >> 3)) | 934 - (0xF8 & LIMIT_RGB(b_)); 935 - break; 936 - case V4L2_PIX_FMT_RGB24: 937 - *f_even++ = LIMIT_RGB(r_); 938 - *f_even++ = LIMIT_RGB(g_); 939 - *f_even++ = LIMIT_RGB(b_); 940 - break; 941 - case V4L2_PIX_FMT_RGB32: 942 - *f_even++ = LIMIT_RGB(r_); 943 - *f_even++ = LIMIT_RGB(g_); 944 - *f_even++ = LIMIT_RGB(b_); 945 - f_even++; 946 - break; 947 - case V4L2_PIX_FMT_RGB555: 948 - g = LIMIT_RGB(g_); 949 - *f_even++ = (0x1F & LIMIT_RGB(r_)) | 950 - (0xE0 & (g << 5)); 951 - *f_even++ = (0x03 & (g >> 3)) | 952 - (0x7C & (LIMIT_RGB(b_) << 2)); 953 - break; 954 - } 955 - } 956 - clipmask_even_index += clipmask_add; 957 - f_even += stretch_bytes; 958 - 959 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 960 - *f_even++ = y[1]; 961 - *f_even++ = u; 962 - } else { 963 - y_ = 76284 * (y[1] - 16); 964 - 965 - b_ = (y_ + vb) >> 16; 966 - g_ = (y_ + uvg) >> 16; 967 - r_ = (y_ + ur) >> 16; 968 - 969 - switch (frame->v4l2_format.format) { 970 - case V4L2_PIX_FMT_RGB565: 971 - g = LIMIT_RGB(g_); 972 - *f_even++ = 973 - (0x1F & LIMIT_RGB(r_)) | 974 - (0xE0 & (g << 5)); 975 - *f_even++ = 976 - (0x07 & (g >> 3)) | 977 - (0xF8 & LIMIT_RGB(b_)); 978 - break; 979 - case V4L2_PIX_FMT_RGB24: 980 - *f_even++ = LIMIT_RGB(r_); 981 - *f_even++ = LIMIT_RGB(g_); 982 - *f_even++ = LIMIT_RGB(b_); 983 - break; 984 - case V4L2_PIX_FMT_RGB32: 985 - *f_even++ = LIMIT_RGB(r_); 986 - *f_even++ = LIMIT_RGB(g_); 987 - *f_even++ = LIMIT_RGB(b_); 988 - f_even++; 989 - break; 990 - case V4L2_PIX_FMT_RGB555: 991 - g = LIMIT_RGB(g_); 992 - *f_even++ = (0x1F & LIMIT_RGB(r_)) | 993 - (0xE0 & (g << 5)); 994 - *f_even++ = (0x03 & (g >> 3)) | 995 - (0x7C & (LIMIT_RGB(b_) << 2)); 996 - break; 997 - } 998 - } 999 - clipmask_even_index += clipmask_add; 1000 - f_even += stretch_bytes; 1001 - 1002 - scratch_get_extra(usbvision, &y[0], &y_ptr, 2); 1003 - 1004 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1005 - *f_odd++ = y[0]; 1006 - *f_odd++ = v; 1007 - } else { 1008 - y_ = 76284 * (y[0] - 16); 1009 - 1010 - b_ = (y_ + vb) >> 16; 1011 - g_ = (y_ + uvg) >> 16; 1012 - r_ = (y_ + ur) >> 16; 1013 - 1014 - switch (frame->v4l2_format.format) { 1015 - case V4L2_PIX_FMT_RGB565: 1016 - g = LIMIT_RGB(g_); 1017 - *f_odd++ = 1018 - (0x1F & LIMIT_RGB(r_)) | 1019 - (0xE0 & (g << 5)); 1020 - *f_odd++ = 1021 - (0x07 & (g >> 3)) | 1022 - (0xF8 & LIMIT_RGB(b_)); 1023 - break; 1024 - case V4L2_PIX_FMT_RGB24: 1025 - *f_odd++ = LIMIT_RGB(r_); 1026 - *f_odd++ = LIMIT_RGB(g_); 1027 - *f_odd++ = LIMIT_RGB(b_); 1028 - break; 1029 - case V4L2_PIX_FMT_RGB32: 1030 - *f_odd++ = LIMIT_RGB(r_); 1031 - *f_odd++ = LIMIT_RGB(g_); 1032 - *f_odd++ = LIMIT_RGB(b_); 1033 - f_odd++; 1034 - break; 1035 - case V4L2_PIX_FMT_RGB555: 1036 - g = LIMIT_RGB(g_); 1037 - *f_odd++ = (0x1F & LIMIT_RGB(r_)) | 1038 - (0xE0 & (g << 5)); 1039 - *f_odd++ = (0x03 & (g >> 3)) | 1040 - (0x7C & (LIMIT_RGB(b_) << 2)); 1041 - break; 1042 - } 1043 - } 1044 - clipmask_odd_index += clipmask_add; 1045 - f_odd += stretch_bytes; 1046 - 1047 - if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1048 - *f_odd++ = y[1]; 1049 - *f_odd++ = u; 1050 - } else { 1051 - y_ = 76284 * (y[1] - 16); 1052 - 1053 - b_ = (y_ + vb) >> 16; 1054 - g_ = (y_ + uvg) >> 16; 1055 - r_ = (y_ + ur) >> 16; 1056 - 1057 - switch (frame->v4l2_format.format) { 1058 - case V4L2_PIX_FMT_RGB565: 1059 - g = LIMIT_RGB(g_); 1060 - *f_odd++ = 1061 - (0x1F & LIMIT_RGB(r_)) | 1062 - (0xE0 & (g << 5)); 1063 - *f_odd++ = 1064 - (0x07 & (g >> 3)) | 1065 - (0xF8 & LIMIT_RGB(b_)); 1066 - break; 1067 - case V4L2_PIX_FMT_RGB24: 1068 - *f_odd++ = LIMIT_RGB(r_); 1069 - *f_odd++ = LIMIT_RGB(g_); 1070 - *f_odd++ = LIMIT_RGB(b_); 1071 - break; 1072 - case V4L2_PIX_FMT_RGB32: 1073 - *f_odd++ = LIMIT_RGB(r_); 1074 - *f_odd++ = LIMIT_RGB(g_); 1075 - *f_odd++ = LIMIT_RGB(b_); 1076 - f_odd++; 1077 - break; 1078 - case V4L2_PIX_FMT_RGB555: 1079 - g = LIMIT_RGB(g_); 1080 - *f_odd++ = (0x1F & LIMIT_RGB(r_)) | 1081 - (0xE0 & (g << 5)); 1082 - *f_odd++ = (0x03 & (g >> 3)) | 1083 - (0x7C & (LIMIT_RGB(b_) << 2)); 1084 - break; 1085 - } 1086 - } 1087 - clipmask_odd_index += clipmask_add; 1088 - f_odd += stretch_bytes; 1089 - } 1090 - 1091 - scratch_rm_old(usbvision, y_step[block % y_step_size] * sub_block_size); 1092 - scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size] 1093 - * sub_block_size); 1094 - scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size] 1095 - * sub_block_size); 1096 - scratch_inc_extra_ptr(&v_ptr, uv_step[(block + 2 * block_split) % uv_step_size] 1097 - * sub_block_size); 1098 - } 1099 - 1100 - scratch_rm_old(usbvision, pixel_per_line * 3 / 2 1101 - + block_split * sub_block_size); 1102 - 1103 - frame->curline += 2 * usbvision->stretch_height; 1104 - *pcopylen += frame->v4l2_linesize * 2 * usbvision->stretch_height; 1105 - 1106 - if (frame->curline >= frame->frmheight) 1107 - return parse_state_next_frame; 1108 - return parse_state_continue; 1109 - } 1110 - 1111 - /* 1112 - * usbvision_parse_data() 1113 - * 1114 - * Generic routine to parse the scratch buffer. It employs either 1115 - * usbvision_find_header() or usbvision_parse_lines() to do most 1116 - * of work. 1117 - * 1118 - */ 1119 - static void usbvision_parse_data(struct usb_usbvision *usbvision) 1120 - { 1121 - struct usbvision_frame *frame; 1122 - enum parse_state newstate; 1123 - long copylen = 0; 1124 - unsigned long lock_flags; 1125 - 1126 - frame = usbvision->cur_frame; 1127 - 1128 - PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision)); 1129 - 1130 - while (1) { 1131 - newstate = parse_state_out; 1132 - if (scratch_len(usbvision)) { 1133 - if (frame->scanstate == scan_state_scanning) { 1134 - newstate = usbvision_find_header(usbvision); 1135 - } else if (frame->scanstate == scan_state_lines) { 1136 - if (usbvision->isoc_mode == ISOC_MODE_YUV420) 1137 - newstate = usbvision_parse_lines_420(usbvision, &copylen); 1138 - else if (usbvision->isoc_mode == ISOC_MODE_YUV422) 1139 - newstate = usbvision_parse_lines_422(usbvision, &copylen); 1140 - else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) 1141 - newstate = usbvision_parse_compress(usbvision, &copylen); 1142 - } 1143 - } 1144 - if (newstate == parse_state_continue) 1145 - continue; 1146 - if ((newstate == parse_state_next_frame) || (newstate == parse_state_out)) 1147 - break; 1148 - return; /* parse_state_end_parse */ 1149 - } 1150 - 1151 - if (newstate == parse_state_next_frame) { 1152 - frame->grabstate = frame_state_done; 1153 - frame->ts = ktime_get_ns(); 1154 - frame->sequence = usbvision->frame_num; 1155 - 1156 - spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 1157 - list_move_tail(&(frame->frame), &usbvision->outqueue); 1158 - usbvision->cur_frame = NULL; 1159 - spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 1160 - 1161 - usbvision->frame_num++; 1162 - 1163 - /* This will cause the process to request another frame. */ 1164 - if (waitqueue_active(&usbvision->wait_frame)) { 1165 - PDEBUG(DBG_PARSE, "Wake up !"); 1166 - wake_up_interruptible(&usbvision->wait_frame); 1167 - } 1168 - } else { 1169 - frame->grabstate = frame_state_grabbing; 1170 - } 1171 - 1172 - /* Update the frame's uncompressed length. */ 1173 - frame->scanlength += copylen; 1174 - } 1175 - 1176 - 1177 - /* 1178 - * Make all of the blocks of data contiguous 1179 - */ 1180 - static int usbvision_compress_isochronous(struct usb_usbvision *usbvision, 1181 - struct urb *urb) 1182 - { 1183 - unsigned char *packet_data; 1184 - int i, totlen = 0; 1185 - 1186 - for (i = 0; i < urb->number_of_packets; i++) { 1187 - int packet_len = urb->iso_frame_desc[i].actual_length; 1188 - int packet_stat = urb->iso_frame_desc[i].status; 1189 - 1190 - packet_data = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 1191 - 1192 - /* Detect and ignore errored packets */ 1193 - if (packet_stat) { /* packet_stat != 0 ????????????? */ 1194 - PDEBUG(DBG_ISOC, "data error: [%d] len=%d, status=%X", i, packet_len, packet_stat); 1195 - usbvision->isoc_err_count++; 1196 - continue; 1197 - } 1198 - 1199 - /* Detect and ignore empty packets */ 1200 - if (packet_len < 0) { 1201 - PDEBUG(DBG_ISOC, "error packet [%d]", i); 1202 - usbvision->isoc_skip_count++; 1203 - continue; 1204 - } else if (packet_len == 0) { /* Frame end ????? */ 1205 - PDEBUG(DBG_ISOC, "null packet [%d]", i); 1206 - usbvision->isocstate = isoc_state_no_frame; 1207 - usbvision->isoc_skip_count++; 1208 - continue; 1209 - } else if (packet_len > usbvision->isoc_packet_size) { 1210 - PDEBUG(DBG_ISOC, "packet[%d] > isoc_packet_size", i); 1211 - usbvision->isoc_skip_count++; 1212 - continue; 1213 - } 1214 - 1215 - PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len); 1216 - 1217 - if (usbvision->isocstate == isoc_state_no_frame) { /* new frame begins */ 1218 - usbvision->isocstate = isoc_state_in_frame; 1219 - scratch_mark_header(usbvision); 1220 - usbvision_measure_bandwidth(usbvision); 1221 - PDEBUG(DBG_ISOC, "packet with header"); 1222 - } 1223 - 1224 - /* 1225 - * If usbvision continues to feed us with data but there is no 1226 - * consumption (if, for example, V4L client fell asleep) we 1227 - * may overflow the buffer. We have to move old data over to 1228 - * free room for new data. This is bad for old data. If we 1229 - * just drop new data then it's bad for new data... choose 1230 - * your favorite evil here. 1231 - */ 1232 - if (scratch_free(usbvision) < packet_len) { 1233 - usbvision->scratch_ovf_count++; 1234 - PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d", 1235 - scratch_len(usbvision), packet_len); 1236 - scratch_rm_old(usbvision, packet_len - scratch_free(usbvision)); 1237 - } 1238 - 1239 - /* Now we know that there is enough room in scratch buffer */ 1240 - scratch_put(usbvision, packet_data, packet_len); 1241 - totlen += packet_len; 1242 - usbvision->isoc_data_count += packet_len; 1243 - usbvision->isoc_packet_count++; 1244 - } 1245 - #if ENABLE_HEXDUMP 1246 - if (totlen > 0) { 1247 - static int foo; 1248 - 1249 - if (foo < 1) { 1250 - printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen); 1251 - usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen); 1252 - ++foo; 1253 - } 1254 - } 1255 - #endif 1256 - return totlen; 1257 - } 1258 - 1259 - static void usbvision_isoc_irq(struct urb *urb) 1260 - { 1261 - int err_code = 0; 1262 - int len; 1263 - struct usb_usbvision *usbvision = urb->context; 1264 - int i; 1265 - struct usbvision_frame **f; 1266 - 1267 - /* We don't want to do anything if we are about to be removed! */ 1268 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1269 - return; 1270 - 1271 - /* any urb with wrong status is ignored without acknowledgment */ 1272 - if (urb->status == -ENOENT) 1273 - return; 1274 - 1275 - f = &usbvision->cur_frame; 1276 - 1277 - /* Manage streaming interruption */ 1278 - if (usbvision->streaming == stream_interrupt) { 1279 - usbvision->streaming = stream_idle; 1280 - if ((*f)) { 1281 - (*f)->grabstate = frame_state_ready; 1282 - (*f)->scanstate = scan_state_scanning; 1283 - } 1284 - PDEBUG(DBG_IRQ, "stream interrupted"); 1285 - wake_up_interruptible(&usbvision->wait_stream); 1286 - } 1287 - 1288 - /* Copy the data received into our scratch buffer */ 1289 - len = usbvision_compress_isochronous(usbvision, urb); 1290 - 1291 - usbvision->isoc_urb_count++; 1292 - usbvision->urb_length = len; 1293 - 1294 - if (usbvision->streaming == stream_on) { 1295 - /* If we collected enough data let's parse! */ 1296 - if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH && 1297 - !list_empty(&(usbvision->inqueue))) { 1298 - if (!(*f)) { 1299 - (*f) = list_entry(usbvision->inqueue.next, 1300 - struct usbvision_frame, 1301 - frame); 1302 - } 1303 - usbvision_parse_data(usbvision); 1304 - } else { 1305 - /* If we don't have a frame 1306 - we're current working on, complain */ 1307 - PDEBUG(DBG_IRQ, 1308 - "received data, but no one needs it"); 1309 - scratch_reset(usbvision); 1310 - } 1311 - } else { 1312 - PDEBUG(DBG_IRQ, "received data, but no one needs it"); 1313 - scratch_reset(usbvision); 1314 - } 1315 - 1316 - for (i = 0; i < USBVISION_URB_FRAMES; i++) { 1317 - urb->iso_frame_desc[i].status = 0; 1318 - urb->iso_frame_desc[i].actual_length = 0; 1319 - } 1320 - 1321 - urb->status = 0; 1322 - urb->dev = usbvision->dev; 1323 - err_code = usb_submit_urb(urb, GFP_ATOMIC); 1324 - 1325 - if (err_code) { 1326 - dev_err(&usbvision->dev->dev, 1327 - "%s: usb_submit_urb failed: error %d\n", 1328 - __func__, err_code); 1329 - } 1330 - 1331 - return; 1332 - } 1333 - 1334 - /*************************************/ 1335 - /* Low level usbvision access functions */ 1336 - /*************************************/ 1337 - 1338 - /* 1339 - * usbvision_read_reg() 1340 - * 1341 - * return < 0 -> Error 1342 - * >= 0 -> Data 1343 - */ 1344 - 1345 - int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg) 1346 - { 1347 - int err_code = 0; 1348 - unsigned char *buffer = usbvision->ctrl_urb_buffer; 1349 - 1350 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1351 - return -1; 1352 - 1353 - err_code = usb_control_msg(usbvision->dev, usb_rcvctrlpipe(usbvision->dev, 1), 1354 - USBVISION_OP_CODE, 1355 - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 1356 - 0, (__u16) reg, buffer, 1, HZ); 1357 - 1358 - if (err_code < 0) { 1359 - dev_err(&usbvision->dev->dev, 1360 - "%s: failed: error %d\n", __func__, err_code); 1361 - return err_code; 1362 - } 1363 - return buffer[0]; 1364 - } 1365 - 1366 - /* 1367 - * usbvision_write_reg() 1368 - * 1369 - * return 1 -> Reg written 1370 - * 0 -> usbvision is not yet ready 1371 - * -1 -> Something went wrong 1372 - */ 1373 - 1374 - int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, 1375 - unsigned char value) 1376 - { 1377 - int err_code = 0; 1378 - 1379 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1380 - return 0; 1381 - 1382 - usbvision->ctrl_urb_buffer[0] = value; 1383 - err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1384 - USBVISION_OP_CODE, 1385 - USB_DIR_OUT | USB_TYPE_VENDOR | 1386 - USB_RECIP_ENDPOINT, 0, (__u16) reg, 1387 - usbvision->ctrl_urb_buffer, 1, HZ); 1388 - 1389 - if (err_code < 0) { 1390 - dev_err(&usbvision->dev->dev, 1391 - "%s: failed: error %d\n", __func__, err_code); 1392 - } 1393 - return err_code; 1394 - } 1395 - 1396 - 1397 - static void usbvision_ctrl_urb_complete(struct urb *urb) 1398 - { 1399 - struct usb_usbvision *usbvision = (struct usb_usbvision *)urb->context; 1400 - 1401 - PDEBUG(DBG_IRQ, ""); 1402 - usbvision->ctrl_urb_busy = 0; 1403 - } 1404 - 1405 - 1406 - static int usbvision_write_reg_irq(struct usb_usbvision *usbvision, int address, 1407 - unsigned char *data, int len) 1408 - { 1409 - int err_code = 0; 1410 - 1411 - PDEBUG(DBG_IRQ, ""); 1412 - if (len > 8) 1413 - return -EFAULT; 1414 - if (usbvision->ctrl_urb_busy) 1415 - return -EBUSY; 1416 - usbvision->ctrl_urb_busy = 1; 1417 - 1418 - usbvision->ctrl_urb_setup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; 1419 - usbvision->ctrl_urb_setup.bRequest = USBVISION_OP_CODE; 1420 - usbvision->ctrl_urb_setup.wValue = 0; 1421 - usbvision->ctrl_urb_setup.wIndex = cpu_to_le16(address); 1422 - usbvision->ctrl_urb_setup.wLength = cpu_to_le16(len); 1423 - usb_fill_control_urb(usbvision->ctrl_urb, usbvision->dev, 1424 - usb_sndctrlpipe(usbvision->dev, 1), 1425 - (unsigned char *)&usbvision->ctrl_urb_setup, 1426 - (void *)usbvision->ctrl_urb_buffer, len, 1427 - usbvision_ctrl_urb_complete, 1428 - (void *)usbvision); 1429 - 1430 - memcpy(usbvision->ctrl_urb_buffer, data, len); 1431 - 1432 - err_code = usb_submit_urb(usbvision->ctrl_urb, GFP_ATOMIC); 1433 - if (err_code < 0) { 1434 - /* error in usb_submit_urb() */ 1435 - usbvision->ctrl_urb_busy = 0; 1436 - } 1437 - PDEBUG(DBG_IRQ, "submit %d byte: error %d", len, err_code); 1438 - return err_code; 1439 - } 1440 - 1441 - 1442 - static int usbvision_init_compression(struct usb_usbvision *usbvision) 1443 - { 1444 - usbvision->last_isoc_frame_num = -1; 1445 - usbvision->isoc_data_count = 0; 1446 - usbvision->isoc_packet_count = 0; 1447 - usbvision->isoc_skip_count = 0; 1448 - usbvision->compr_level = 50; 1449 - usbvision->last_compr_level = -1; 1450 - usbvision->isoc_urb_count = 0; 1451 - usbvision->request_intra = 1; 1452 - usbvision->isoc_measure_bandwidth_count = 0; 1453 - 1454 - return 0; 1455 - } 1456 - 1457 - /* this function measures the used bandwidth since last call 1458 - * return: 0 : no error 1459 - * sets used_bandwidth to 1-100 : 1-100% of full bandwidth resp. to isoc_packet_size 1460 - */ 1461 - static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision) 1462 - { 1463 - if (usbvision->isoc_measure_bandwidth_count < 2) { /* this gives an average bandwidth of 3 frames */ 1464 - usbvision->isoc_measure_bandwidth_count++; 1465 - return 0; 1466 - } 1467 - if ((usbvision->isoc_packet_size > 0) && (usbvision->isoc_packet_count > 0)) { 1468 - usbvision->used_bandwidth = usbvision->isoc_data_count / 1469 - (usbvision->isoc_packet_count + usbvision->isoc_skip_count) * 1470 - 100 / usbvision->isoc_packet_size; 1471 - } 1472 - usbvision->isoc_measure_bandwidth_count = 0; 1473 - usbvision->isoc_data_count = 0; 1474 - usbvision->isoc_packet_count = 0; 1475 - usbvision->isoc_skip_count = 0; 1476 - return 0; 1477 - } 1478 - 1479 - static int usbvision_adjust_compression(struct usb_usbvision *usbvision) 1480 - { 1481 - int err_code = 0; 1482 - unsigned char buffer[6]; 1483 - 1484 - PDEBUG(DBG_IRQ, ""); 1485 - if ((adjust_compression) && (usbvision->used_bandwidth > 0)) { 1486 - usbvision->compr_level += (usbvision->used_bandwidth - 90) / 2; 1487 - RESTRICT_TO_RANGE(usbvision->compr_level, 0, 100); 1488 - if (usbvision->compr_level != usbvision->last_compr_level) { 1489 - int distortion; 1490 - 1491 - if (usbvision->bridge_type == BRIDGE_NT1004 || usbvision->bridge_type == BRIDGE_NT1005) { 1492 - buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM Threshold 1 */ 1493 - buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM Threshold 2 */ 1494 - distortion = 7 + 248 * usbvision->compr_level / 100; 1495 - buffer[2] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (inter) */ 1496 - buffer[3] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (intra) */ 1497 - distortion = 1 + 42 * usbvision->compr_level / 100; 1498 - buffer[4] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (inter) */ 1499 - buffer[5] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (intra) */ 1500 - } else { /* BRIDGE_NT1003 */ 1501 - buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM threshold 1 */ 1502 - buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM threshold 2 */ 1503 - distortion = 2 + 253 * usbvision->compr_level / 100; 1504 - buffer[2] = (unsigned char)(distortion & 0xFF); /* distortion threshold bit0-7 */ 1505 - buffer[3] = 0; /* (unsigned char)((distortion >> 8) & 0x0F); distortion threshold bit 8-11 */ 1506 - distortion = 0 + 43 * usbvision->compr_level / 100; 1507 - buffer[4] = (unsigned char)(distortion & 0xFF); /* maximum distortion bit0-7 */ 1508 - buffer[5] = 0; /* (unsigned char)((distortion >> 8) & 0x01); maximum distortion bit 8 */ 1509 - } 1510 - err_code = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6); 1511 - if (err_code == 0) { 1512 - PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0], 1513 - buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]); 1514 - usbvision->last_compr_level = usbvision->compr_level; 1515 - } 1516 - } 1517 - } 1518 - return err_code; 1519 - } 1520 - 1521 - static int usbvision_request_intra(struct usb_usbvision *usbvision) 1522 - { 1523 - unsigned char buffer[1]; 1524 - 1525 - PDEBUG(DBG_IRQ, ""); 1526 - usbvision->request_intra = 1; 1527 - buffer[0] = 1; 1528 - usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1); 1529 - return 0; 1530 - } 1531 - 1532 - static int usbvision_unrequest_intra(struct usb_usbvision *usbvision) 1533 - { 1534 - unsigned char buffer[1]; 1535 - 1536 - PDEBUG(DBG_IRQ, ""); 1537 - usbvision->request_intra = 0; 1538 - buffer[0] = 0; 1539 - usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1); 1540 - return 0; 1541 - } 1542 - 1543 - /******************************* 1544 - * usbvision utility functions 1545 - *******************************/ 1546 - 1547 - int usbvision_power_off(struct usb_usbvision *usbvision) 1548 - { 1549 - int err_code = 0; 1550 - 1551 - PDEBUG(DBG_FUNC, ""); 1552 - 1553 - err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 1554 - if (err_code == 1) 1555 - usbvision->power = 0; 1556 - PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code != 1) ? "ERROR" : "power is off", err_code); 1557 - return err_code; 1558 - } 1559 - 1560 - /* configure webcam image sensor using the serial port */ 1561 - static int usbvision_init_webcam(struct usb_usbvision *usbvision) 1562 - { 1563 - int rc; 1564 - int i; 1565 - static char init_values[38][3] = { 1566 - { 0x04, 0x12, 0x08 }, { 0x05, 0xff, 0xc8 }, { 0x06, 0x18, 0x07 }, { 0x07, 0x90, 0x00 }, 1567 - { 0x09, 0x00, 0x00 }, { 0x0a, 0x00, 0x00 }, { 0x0b, 0x08, 0x00 }, { 0x0d, 0xcc, 0xcc }, 1568 - { 0x0e, 0x13, 0x14 }, { 0x10, 0x9b, 0x83 }, { 0x11, 0x5a, 0x3f }, { 0x12, 0xe4, 0x73 }, 1569 - { 0x13, 0x88, 0x84 }, { 0x14, 0x89, 0x80 }, { 0x15, 0x00, 0x20 }, { 0x16, 0x00, 0x00 }, 1570 - { 0x17, 0xff, 0xa0 }, { 0x18, 0x6b, 0x20 }, { 0x19, 0x22, 0x40 }, { 0x1a, 0x10, 0x07 }, 1571 - { 0x1b, 0x00, 0x47 }, { 0x1c, 0x03, 0xe0 }, { 0x1d, 0x00, 0x00 }, { 0x1e, 0x00, 0x00 }, 1572 - { 0x1f, 0x00, 0x00 }, { 0x20, 0x00, 0x00 }, { 0x21, 0x00, 0x00 }, { 0x22, 0x00, 0x00 }, 1573 - { 0x23, 0x00, 0x00 }, { 0x24, 0x00, 0x00 }, { 0x25, 0x00, 0x00 }, { 0x26, 0x00, 0x00 }, 1574 - { 0x27, 0x00, 0x00 }, { 0x28, 0x00, 0x00 }, { 0x29, 0x00, 0x00 }, { 0x08, 0x80, 0x60 }, 1575 - { 0x0f, 0x2d, 0x24 }, { 0x0c, 0x80, 0x80 } 1576 - }; 1577 - unsigned char *value = usbvision->ctrl_urb_buffer; 1578 - 1579 - /* the only difference between PAL and NTSC init_values */ 1580 - if (usbvision_device_data[usbvision->dev_model].video_norm == V4L2_STD_NTSC) 1581 - init_values[4][1] = 0x34; 1582 - 1583 - for (i = 0; i < sizeof(init_values) / 3; i++) { 1584 - usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT); 1585 - memcpy(value, init_values[i], 3); 1586 - rc = usb_control_msg(usbvision->dev, 1587 - usb_sndctrlpipe(usbvision->dev, 1), 1588 - USBVISION_OP_CODE, 1589 - USB_DIR_OUT | USB_TYPE_VENDOR | 1590 - USB_RECIP_ENDPOINT, 0, 1591 - (__u16) USBVISION_SER_DAT1, value, 1592 - 3, HZ); 1593 - if (rc < 0) 1594 - return rc; 1595 - usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SIO); 1596 - /* write 3 bytes to the serial port using SIO mode */ 1597 - usbvision_write_reg(usbvision, USBVISION_SER_CONT, 3 | 0x10); 1598 - usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, 0); 1599 - usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT); 1600 - usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_IO_2); 1601 - usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_CLK_OUT); 1602 - usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_DAT_IO); 1603 - usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_CLK_OUT | USBVISION_DAT_IO); 1604 - } 1605 - 1606 - return 0; 1607 - } 1608 - 1609 - /* 1610 - * usbvision_set_video_format() 1611 - * 1612 - */ 1613 - static int usbvision_set_video_format(struct usb_usbvision *usbvision, int format) 1614 - { 1615 - static const char proc[] = "usbvision_set_video_format"; 1616 - unsigned char *value = usbvision->ctrl_urb_buffer; 1617 - int rc; 1618 - 1619 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1620 - return 0; 1621 - 1622 - PDEBUG(DBG_FUNC, "isoc_mode %#02x", format); 1623 - 1624 - if ((format != ISOC_MODE_YUV422) 1625 - && (format != ISOC_MODE_YUV420) 1626 - && (format != ISOC_MODE_COMPRESS)) { 1627 - printk(KERN_ERR "usbvision: unknown video format %02x, using default YUV420", 1628 - format); 1629 - format = ISOC_MODE_YUV420; 1630 - } 1631 - value[0] = 0x0A; /* TODO: See the effect of the filter */ 1632 - value[1] = format; /* Sets the VO_MODE register which follows FILT_CONT */ 1633 - rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1634 - USBVISION_OP_CODE, 1635 - USB_DIR_OUT | USB_TYPE_VENDOR | 1636 - USB_RECIP_ENDPOINT, 0, 1637 - (__u16) USBVISION_FILT_CONT, value, 2, HZ); 1638 - 1639 - if (rc < 0) { 1640 - printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - reconnect or reload driver.\n", 1641 - proc, rc); 1642 - } 1643 - usbvision->isoc_mode = format; 1644 - return rc; 1645 - } 1646 - 1647 - /* 1648 - * usbvision_set_output() 1649 - * 1650 - */ 1651 - 1652 - int usbvision_set_output(struct usb_usbvision *usbvision, int width, 1653 - int height) 1654 - { 1655 - int err_code = 0; 1656 - int usb_width, usb_height; 1657 - unsigned int frame_rate = 0, frame_drop = 0; 1658 - unsigned char *value = usbvision->ctrl_urb_buffer; 1659 - 1660 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1661 - return 0; 1662 - 1663 - if (width > MAX_USB_WIDTH) { 1664 - usb_width = width / 2; 1665 - usbvision->stretch_width = 2; 1666 - } else { 1667 - usb_width = width; 1668 - usbvision->stretch_width = 1; 1669 - } 1670 - 1671 - if (height > MAX_USB_HEIGHT) { 1672 - usb_height = height / 2; 1673 - usbvision->stretch_height = 2; 1674 - } else { 1675 - usb_height = height; 1676 - usbvision->stretch_height = 1; 1677 - } 1678 - 1679 - RESTRICT_TO_RANGE(usb_width, MIN_FRAME_WIDTH, MAX_USB_WIDTH); 1680 - usb_width &= ~(MIN_FRAME_WIDTH-1); 1681 - RESTRICT_TO_RANGE(usb_height, MIN_FRAME_HEIGHT, MAX_USB_HEIGHT); 1682 - usb_height &= ~(1); 1683 - 1684 - PDEBUG(DBG_FUNC, "usb %dx%d; screen %dx%d; stretch %dx%d", 1685 - usb_width, usb_height, width, height, 1686 - usbvision->stretch_width, usbvision->stretch_height); 1687 - 1688 - /* I'll not rewrite the same values */ 1689 - if ((usb_width != usbvision->curwidth) || (usb_height != usbvision->curheight)) { 1690 - value[0] = usb_width & 0xff; /* LSB */ 1691 - value[1] = (usb_width >> 8) & 0x03; /* MSB */ 1692 - value[2] = usb_height & 0xff; /* LSB */ 1693 - value[3] = (usb_height >> 8) & 0x03; /* MSB */ 1694 - 1695 - err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1696 - USBVISION_OP_CODE, 1697 - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 1698 - 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ); 1699 - 1700 - if (err_code < 0) { 1701 - dev_err(&usbvision->dev->dev, 1702 - "%s failed: error %d\n", __func__, err_code); 1703 - return err_code; 1704 - } 1705 - usbvision->curwidth = usbvision->stretch_width * usb_width; 1706 - usbvision->curheight = usbvision->stretch_height * usb_height; 1707 - } 1708 - 1709 - if (usbvision->isoc_mode == ISOC_MODE_YUV422) 1710 - frame_rate = (usbvision->isoc_packet_size * 1000) / (usb_width * usb_height * 2); 1711 - else if (usbvision->isoc_mode == ISOC_MODE_YUV420) 1712 - frame_rate = (usbvision->isoc_packet_size * 1000) / ((usb_width * usb_height * 12) / 8); 1713 - else 1714 - frame_rate = FRAMERATE_MAX; 1715 - 1716 - if (usbvision->tvnorm_id & V4L2_STD_625_50) 1717 - frame_drop = frame_rate * 32 / 25 - 1; 1718 - else if (usbvision->tvnorm_id & V4L2_STD_525_60) 1719 - frame_drop = frame_rate * 32 / 30 - 1; 1720 - 1721 - RESTRICT_TO_RANGE(frame_drop, FRAMERATE_MIN, FRAMERATE_MAX); 1722 - 1723 - PDEBUG(DBG_FUNC, "frame_rate %d fps, frame_drop %d", frame_rate, frame_drop); 1724 - 1725 - frame_drop = FRAMERATE_MAX; /* We can allow the maximum here, because dropping is controlled */ 1726 - 1727 - if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) { 1728 - if (usbvision_device_data[usbvision->dev_model].video_norm == V4L2_STD_PAL) 1729 - frame_drop = 25; 1730 - else 1731 - frame_drop = 30; 1732 - } 1733 - 1734 - /* frame_drop = 7; => frame_phase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ... 1735 - => frame_skip = 4; 1736 - => frame_rate = (7 + 1) * 25 / 32 = 200 / 32 = 6.25; 1737 - 1738 - frame_drop = 9; => frame_phase = 1, 5, 8, 11, 14, 17, 21, 24, 27, 1, 4, 8, ... 1739 - => frame_skip = 4, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, ... 1740 - => frame_rate = (9 + 1) * 25 / 32 = 250 / 32 = 7.8125; 1741 - */ 1742 - err_code = usbvision_write_reg(usbvision, USBVISION_FRM_RATE, frame_drop); 1743 - return err_code; 1744 - } 1745 - 1746 - 1747 - /* 1748 - * usbvision_frames_alloc 1749 - * allocate the required frames 1750 - */ 1751 - int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames) 1752 - { 1753 - int i; 1754 - 1755 - /* needs to be page aligned cause the buffers can be mapped individually! */ 1756 - usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth * 1757 - usbvision->curheight * 1758 - usbvision->palette.bytes_per_pixel); 1759 - 1760 - /* Try to do my best to allocate the frames the user want in the remaining memory */ 1761 - usbvision->num_frames = number_of_frames; 1762 - while (usbvision->num_frames > 0) { 1763 - usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size; 1764 - usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size); 1765 - if (usbvision->fbuf) 1766 - break; 1767 - usbvision->num_frames--; 1768 - } 1769 - 1770 - /* Allocate all buffers */ 1771 - for (i = 0; i < usbvision->num_frames; i++) { 1772 - usbvision->frame[i].index = i; 1773 - usbvision->frame[i].grabstate = frame_state_unused; 1774 - usbvision->frame[i].data = usbvision->fbuf + 1775 - i * usbvision->max_frame_size; 1776 - /* 1777 - * Set default sizes for read operation. 1778 - */ 1779 - usbvision->stretch_width = 1; 1780 - usbvision->stretch_height = 1; 1781 - usbvision->frame[i].width = usbvision->curwidth; 1782 - usbvision->frame[i].height = usbvision->curheight; 1783 - usbvision->frame[i].bytes_read = 0; 1784 - } 1785 - PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)", 1786 - usbvision->num_frames, usbvision->max_frame_size); 1787 - return usbvision->num_frames; 1788 - } 1789 - 1790 - /* 1791 - * usbvision_frames_free 1792 - * frees memory allocated for the frames 1793 - */ 1794 - void usbvision_frames_free(struct usb_usbvision *usbvision) 1795 - { 1796 - /* Have to free all that memory */ 1797 - PDEBUG(DBG_FUNC, "free %d frames", usbvision->num_frames); 1798 - 1799 - if (usbvision->fbuf != NULL) { 1800 - usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); 1801 - usbvision->fbuf = NULL; 1802 - 1803 - usbvision->num_frames = 0; 1804 - } 1805 - } 1806 - /* 1807 - * usbvision_empty_framequeues() 1808 - * prepare queues for incoming and outgoing frames 1809 - */ 1810 - void usbvision_empty_framequeues(struct usb_usbvision *usbvision) 1811 - { 1812 - u32 i; 1813 - 1814 - INIT_LIST_HEAD(&(usbvision->inqueue)); 1815 - INIT_LIST_HEAD(&(usbvision->outqueue)); 1816 - 1817 - for (i = 0; i < USBVISION_NUMFRAMES; i++) { 1818 - usbvision->frame[i].grabstate = frame_state_unused; 1819 - usbvision->frame[i].bytes_read = 0; 1820 - } 1821 - } 1822 - 1823 - /* 1824 - * usbvision_stream_interrupt() 1825 - * stops streaming 1826 - */ 1827 - int usbvision_stream_interrupt(struct usb_usbvision *usbvision) 1828 - { 1829 - int ret = 0; 1830 - 1831 - /* stop reading from the device */ 1832 - 1833 - usbvision->streaming = stream_interrupt; 1834 - ret = wait_event_timeout(usbvision->wait_stream, 1835 - (usbvision->streaming == stream_idle), 1836 - msecs_to_jiffies(USBVISION_NUMSBUF*USBVISION_URB_FRAMES)); 1837 - return ret; 1838 - } 1839 - 1840 - /* 1841 - * usbvision_set_compress_params() 1842 - * 1843 - */ 1844 - 1845 - static int usbvision_set_compress_params(struct usb_usbvision *usbvision) 1846 - { 1847 - static const char proc[] = "usbvision_set_compression_params: "; 1848 - int rc; 1849 - unsigned char *value = usbvision->ctrl_urb_buffer; 1850 - 1851 - value[0] = 0x0F; /* Intra-Compression cycle */ 1852 - value[1] = 0x01; /* Reg.45 one line per strip */ 1853 - value[2] = 0x00; /* Reg.46 Force intra mode on all new frames */ 1854 - value[3] = 0x00; /* Reg.47 FORCE_UP <- 0 normal operation (not force) */ 1855 - value[4] = 0xA2; /* Reg.48 BUF_THR I'm not sure if this does something in not compressed mode. */ 1856 - value[5] = 0x00; /* Reg.49 DVI_YUV This has nothing to do with compression */ 1857 - 1858 - /* caught values for NT1004 */ 1859 - /* value[0] = 0xFF; Never apply intra mode automatically */ 1860 - /* value[1] = 0xF1; Use full frame height for virtual strip width; One line per strip */ 1861 - /* value[2] = 0x01; Force intra mode on all new frames */ 1862 - /* value[3] = 0x00; Strip size 400 Bytes; do not force up */ 1863 - /* value[4] = 0xA2; */ 1864 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1865 - return 0; 1866 - 1867 - rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1868 - USBVISION_OP_CODE, 1869 - USB_DIR_OUT | USB_TYPE_VENDOR | 1870 - USB_RECIP_ENDPOINT, 0, 1871 - (__u16) USBVISION_INTRA_CYC, value, 5, HZ); 1872 - 1873 - if (rc < 0) { 1874 - printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n", 1875 - proc, rc); 1876 - return rc; 1877 - } 1878 - 1879 - if (usbvision->bridge_type == BRIDGE_NT1004) { 1880 - value[0] = 20; /* PCM Threshold 1 */ 1881 - value[1] = 12; /* PCM Threshold 2 */ 1882 - value[2] = 255; /* Distortion Threshold inter */ 1883 - value[3] = 255; /* Distortion Threshold intra */ 1884 - value[4] = 43; /* Max Distortion inter */ 1885 - value[5] = 43; /* Max Distortion intra */ 1886 - } else { 1887 - value[0] = 20; /* PCM Threshold 1 */ 1888 - value[1] = 12; /* PCM Threshold 2 */ 1889 - value[2] = 255; /* Distortion Threshold d7-d0 */ 1890 - value[3] = 0; /* Distortion Threshold d11-d8 */ 1891 - value[4] = 43; /* Max Distortion d7-d0 */ 1892 - value[5] = 0; /* Max Distortion d8 */ 1893 - } 1894 - 1895 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1896 - return 0; 1897 - 1898 - rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1899 - USBVISION_OP_CODE, 1900 - USB_DIR_OUT | USB_TYPE_VENDOR | 1901 - USB_RECIP_ENDPOINT, 0, 1902 - (__u16) USBVISION_PCM_THR1, value, 6, HZ); 1903 - 1904 - if (rc < 0) { 1905 - printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n", 1906 - proc, rc); 1907 - } 1908 - return rc; 1909 - } 1910 - 1911 - 1912 - /* 1913 - * usbvision_set_input() 1914 - * 1915 - * Set the input (saa711x, ...) size x y and other misc input params 1916 - * I've no idea if this parameters are right 1917 - * 1918 - */ 1919 - int usbvision_set_input(struct usb_usbvision *usbvision) 1920 - { 1921 - static const char proc[] = "usbvision_set_input: "; 1922 - int rc; 1923 - unsigned char *value = usbvision->ctrl_urb_buffer; 1924 - unsigned char dvi_yuv_value; 1925 - 1926 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1927 - return 0; 1928 - 1929 - /* Set input format expected from decoder*/ 1930 - if (usbvision_device_data[usbvision->dev_model].vin_reg1_override) { 1931 - value[0] = usbvision_device_data[usbvision->dev_model].vin_reg1; 1932 - } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) { 1933 - /* SAA7113 uses 8 bit output */ 1934 - value[0] = USBVISION_8_422_SYNC; 1935 - } else { 1936 - /* I'm sure only about d2-d0 [010] 16 bit 4:2:2 using sync pulses 1937 - * as that is how saa7111 is configured */ 1938 - value[0] = USBVISION_16_422_SYNC; 1939 - /* | USBVISION_VSNC_POL | USBVISION_VCLK_POL);*/ 1940 - } 1941 - 1942 - rc = usbvision_write_reg(usbvision, USBVISION_VIN_REG1, value[0]); 1943 - if (rc < 0) { 1944 - printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n", 1945 - proc, rc); 1946 - return rc; 1947 - } 1948 - 1949 - 1950 - if (usbvision->tvnorm_id & V4L2_STD_PAL) { 1951 - value[0] = 0xC0; 1952 - value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */ 1953 - value[2] = 0x20; 1954 - value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */ 1955 - value[4] = 0x60; 1956 - value[5] = 0x00; /* 0x0060 -> 96 Input video h offset */ 1957 - value[6] = 0x16; 1958 - value[7] = 0x00; /* 0x0016 -> 22 Input video v offset */ 1959 - } else if (usbvision->tvnorm_id & V4L2_STD_SECAM) { 1960 - value[0] = 0xC0; 1961 - value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */ 1962 - value[2] = 0x20; 1963 - value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */ 1964 - value[4] = 0x01; 1965 - value[5] = 0x00; /* 0x0001 -> 01 Input video h offset */ 1966 - value[6] = 0x01; 1967 - value[7] = 0x00; /* 0x0001 -> 01 Input video v offset */ 1968 - } else { /* V4L2_STD_NTSC */ 1969 - value[0] = 0xD0; 1970 - value[1] = 0x02; /* 0x02D0 -> 720 Input video line length */ 1971 - value[2] = 0xF0; 1972 - value[3] = 0x00; /* 0x00F0 -> 240 Input video number of lines */ 1973 - value[4] = 0x50; 1974 - value[5] = 0x00; /* 0x0050 -> 80 Input video h offset */ 1975 - value[6] = 0x10; 1976 - value[7] = 0x00; /* 0x0010 -> 16 Input video v offset */ 1977 - } 1978 - 1979 - /* webcam is only 480 pixels wide, both PAL and NTSC version */ 1980 - if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) { 1981 - value[0] = 0xe0; 1982 - value[1] = 0x01; /* 0x01E0 -> 480 Input video line length */ 1983 - } 1984 - 1985 - if (usbvision_device_data[usbvision->dev_model].x_offset >= 0) { 1986 - value[4] = usbvision_device_data[usbvision->dev_model].x_offset & 0xff; 1987 - value[5] = (usbvision_device_data[usbvision->dev_model].x_offset & 0x0300) >> 8; 1988 - } 1989 - 1990 - if (adjust_x_offset != -1) { 1991 - value[4] = adjust_x_offset & 0xff; 1992 - value[5] = (adjust_x_offset & 0x0300) >> 8; 1993 - } 1994 - 1995 - if (usbvision_device_data[usbvision->dev_model].y_offset >= 0) { 1996 - value[6] = usbvision_device_data[usbvision->dev_model].y_offset & 0xff; 1997 - value[7] = (usbvision_device_data[usbvision->dev_model].y_offset & 0x0300) >> 8; 1998 - } 1999 - 2000 - if (adjust_y_offset != -1) { 2001 - value[6] = adjust_y_offset & 0xff; 2002 - value[7] = (adjust_y_offset & 0x0300) >> 8; 2003 - } 2004 - 2005 - rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 2006 - USBVISION_OP_CODE, /* USBVISION specific code */ 2007 - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0, 2008 - (__u16) USBVISION_LXSIZE_I, value, 8, HZ); 2009 - if (rc < 0) { 2010 - printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n", 2011 - proc, rc); 2012 - return rc; 2013 - } 2014 - 2015 - 2016 - dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */ 2017 - 2018 - if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override) { 2019 - dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv; 2020 - } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) { 2021 - /* This changes as the fine sync control changes. Further investigation necessary */ 2022 - dvi_yuv_value = 0x06; 2023 - } 2024 - 2025 - return usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value); 2026 - } 2027 - 2028 - 2029 - /* 2030 - * usbvision_set_dram_settings() 2031 - * 2032 - * Set the buffer address needed by the usbvision dram to operate 2033 - * This values has been taken with usbsnoop. 2034 - * 2035 - */ 2036 - 2037 - static int usbvision_set_dram_settings(struct usb_usbvision *usbvision) 2038 - { 2039 - unsigned char *value = usbvision->ctrl_urb_buffer; 2040 - int rc; 2041 - 2042 - if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) { 2043 - value[0] = 0x42; 2044 - value[1] = 0x71; 2045 - value[2] = 0xff; 2046 - value[3] = 0x00; 2047 - value[4] = 0x98; 2048 - value[5] = 0xe0; 2049 - value[6] = 0x71; 2050 - value[7] = 0xff; 2051 - /* UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) */ 2052 - /* FDL: 0x00000-0x0E099 = 57498 Words */ 2053 - /* VDW: 0x0E3FF-0x3FFFF */ 2054 - } else { 2055 - value[0] = 0x42; 2056 - value[1] = 0x00; 2057 - value[2] = 0xff; 2058 - value[3] = 0x00; 2059 - value[4] = 0x00; 2060 - value[5] = 0x00; 2061 - value[6] = 0x00; 2062 - value[7] = 0xff; 2063 - } 2064 - /* These are the values of the address of the video buffer, 2065 - * they have to be loaded into the USBVISION_DRM_PRM1-8 2066 - * 2067 - * Start address of video output buffer for read: drm_prm1-2 -> 0x00000 2068 - * End address of video output buffer for read: drm_prm1-3 -> 0x1ffff 2069 - * Start address of video frame delay buffer: drm_prm1-4 -> 0x20000 2070 - * Only used in compressed mode 2071 - * End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff 2072 - * Only used in compressed mode 2073 - * Start address of video output buffer for write: drm_prm1-7 -> 0x00000 2074 - * End address of video output buffer for write: drm_prm1-8 -> 0x1ffff 2075 - */ 2076 - 2077 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 2078 - return 0; 2079 - 2080 - rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 2081 - USBVISION_OP_CODE, /* USBVISION specific code */ 2082 - USB_DIR_OUT | USB_TYPE_VENDOR | 2083 - USB_RECIP_ENDPOINT, 0, 2084 - (__u16) USBVISION_DRM_PRM1, value, 8, HZ); 2085 - 2086 - if (rc < 0) { 2087 - dev_err(&usbvision->dev->dev, "%s: ERROR=%d\n", __func__, rc); 2088 - return rc; 2089 - } 2090 - 2091 - /* Restart the video buffer logic */ 2092 - rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR | 2093 - USBVISION_RES_FDL | USBVISION_RES_VDW); 2094 - if (rc < 0) 2095 - return rc; 2096 - rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00); 2097 - 2098 - return rc; 2099 - } 2100 - 2101 - /* 2102 - * () 2103 - * 2104 - * Power on the device, enables suspend-resume logic 2105 - * & reset the isoc End-Point 2106 - * 2107 - */ 2108 - 2109 - int usbvision_power_on(struct usb_usbvision *usbvision) 2110 - { 2111 - int err_code = 0; 2112 - 2113 - PDEBUG(DBG_FUNC, ""); 2114 - 2115 - usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 2116 - usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2117 - USBVISION_SSPND_EN | USBVISION_RES2); 2118 - 2119 - if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) { 2120 - usbvision_write_reg(usbvision, USBVISION_VIN_REG1, 2121 - USBVISION_16_422_SYNC | USBVISION_HVALID_PO); 2122 - usbvision_write_reg(usbvision, USBVISION_VIN_REG2, 2123 - USBVISION_NOHVALID | USBVISION_KEEP_BLANK); 2124 - } 2125 - usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2126 - USBVISION_SSPND_EN | USBVISION_PWR_VID); 2127 - mdelay(10); 2128 - err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2129 - USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2); 2130 - if (err_code == 1) 2131 - usbvision->power = 1; 2132 - PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code < 0) ? "ERROR" : "power is on", err_code); 2133 - return err_code; 2134 - } 2135 - 2136 - 2137 - /* 2138 - * usbvision_begin_streaming() 2139 - * Sure you have to put bit 7 to 0, if not incoming frames are dropped, but no 2140 - * idea about the rest 2141 - */ 2142 - int usbvision_begin_streaming(struct usb_usbvision *usbvision) 2143 - { 2144 - if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) 2145 - usbvision_init_compression(usbvision); 2146 - return usbvision_write_reg(usbvision, USBVISION_VIN_REG2, 2147 - USBVISION_NOHVALID | usbvision->vin_reg2_preset); 2148 - } 2149 - 2150 - /* 2151 - * usbvision_restart_isoc() 2152 - * Not sure yet if touching here PWR_REG make loose the config 2153 - */ 2154 - 2155 - int usbvision_restart_isoc(struct usb_usbvision *usbvision) 2156 - { 2157 - int ret; 2158 - 2159 - ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2160 - USBVISION_SSPND_EN | USBVISION_PWR_VID); 2161 - if (ret < 0) 2162 - return ret; 2163 - ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2164 - USBVISION_SSPND_EN | USBVISION_PWR_VID | 2165 - USBVISION_RES2); 2166 - if (ret < 0) 2167 - return ret; 2168 - ret = usbvision_write_reg(usbvision, USBVISION_VIN_REG2, 2169 - USBVISION_KEEP_BLANK | USBVISION_NOHVALID | 2170 - usbvision->vin_reg2_preset); 2171 - if (ret < 0) 2172 - return ret; 2173 - 2174 - /* TODO: schedule timeout */ 2175 - while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1) 2176 - ; 2177 - 2178 - return 0; 2179 - } 2180 - 2181 - int usbvision_audio_off(struct usb_usbvision *usbvision) 2182 - { 2183 - if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) { 2184 - printk(KERN_ERR "usbvision_audio_off: can't write reg\n"); 2185 - return -1; 2186 - } 2187 - usbvision->audio_mute = 0; 2188 - usbvision->audio_channel = USBVISION_AUDIO_MUTE; 2189 - return 0; 2190 - } 2191 - 2192 - int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel) 2193 - { 2194 - if (!usbvision->audio_mute) { 2195 - if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, audio_channel) < 0) { 2196 - printk(KERN_ERR "usbvision_set_audio: can't write iopin register for audio switching\n"); 2197 - return -1; 2198 - } 2199 - } 2200 - usbvision->audio_channel = audio_channel; 2201 - return 0; 2202 - } 2203 - 2204 - int usbvision_setup(struct usb_usbvision *usbvision, int format) 2205 - { 2206 - if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) 2207 - usbvision_init_webcam(usbvision); 2208 - usbvision_set_video_format(usbvision, format); 2209 - usbvision_set_dram_settings(usbvision); 2210 - usbvision_set_compress_params(usbvision); 2211 - usbvision_set_input(usbvision); 2212 - usbvision_set_output(usbvision, MAX_USB_WIDTH, MAX_USB_HEIGHT); 2213 - usbvision_restart_isoc(usbvision); 2214 - 2215 - /* cosas del PCM */ 2216 - return USBVISION_IS_OPERATIONAL(usbvision); 2217 - } 2218 - 2219 - int usbvision_set_alternate(struct usb_usbvision *dev) 2220 - { 2221 - int err_code, prev_alt = dev->iface_alt; 2222 - int i; 2223 - 2224 - dev->iface_alt = 0; 2225 - for (i = 0; i < dev->num_alt; i++) 2226 - if (dev->alt_max_pkt_size[i] > dev->alt_max_pkt_size[dev->iface_alt]) 2227 - dev->iface_alt = i; 2228 - 2229 - if (dev->iface_alt != prev_alt) { 2230 - dev->isoc_packet_size = dev->alt_max_pkt_size[dev->iface_alt]; 2231 - PDEBUG(DBG_FUNC, "setting alternate %d with max_packet_size=%u", 2232 - dev->iface_alt, dev->isoc_packet_size); 2233 - err_code = usb_set_interface(dev->dev, dev->iface, dev->iface_alt); 2234 - if (err_code < 0) { 2235 - dev_err(&dev->dev->dev, 2236 - "cannot change alternate number to %d (error=%i)\n", 2237 - dev->iface_alt, err_code); 2238 - return err_code; 2239 - } 2240 - } 2241 - 2242 - PDEBUG(DBG_ISOC, "ISO Packet Length:%d", dev->isoc_packet_size); 2243 - 2244 - return 0; 2245 - } 2246 - 2247 - /* 2248 - * usbvision_init_isoc() 2249 - * 2250 - */ 2251 - int usbvision_init_isoc(struct usb_usbvision *usbvision) 2252 - { 2253 - struct usb_device *dev = usbvision->dev; 2254 - int buf_idx, err_code, reg_value; 2255 - int sb_size; 2256 - 2257 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 2258 - return -EFAULT; 2259 - 2260 - usbvision->cur_frame = NULL; 2261 - scratch_reset(usbvision); 2262 - 2263 - /* Alternate interface 1 is is the biggest frame size */ 2264 - err_code = usbvision_set_alternate(usbvision); 2265 - if (err_code < 0) { 2266 - usbvision->last_error = err_code; 2267 - return -EBUSY; 2268 - } 2269 - sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size; 2270 - 2271 - reg_value = (16 - usbvision_read_reg(usbvision, 2272 - USBVISION_ALTER_REG)) & 0x0F; 2273 - 2274 - usbvision->usb_bandwidth = reg_value >> 1; 2275 - PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", 2276 - usbvision->usb_bandwidth); 2277 - 2278 - 2279 - 2280 - /* We double buffer the Iso lists */ 2281 - 2282 - for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { 2283 - int j, k; 2284 - struct urb *urb; 2285 - 2286 - urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 2287 - if (urb == NULL) 2288 - return -ENOMEM; 2289 - usbvision->sbuf[buf_idx].urb = urb; 2290 - usbvision->sbuf[buf_idx].data = 2291 - usb_alloc_coherent(usbvision->dev, 2292 - sb_size, 2293 - GFP_KERNEL, 2294 - &urb->transfer_dma); 2295 - if (!usbvision->sbuf[buf_idx].data) 2296 - return -ENOMEM; 2297 - 2298 - urb->dev = dev; 2299 - urb->context = usbvision; 2300 - urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); 2301 - urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 2302 - urb->interval = 1; 2303 - urb->transfer_buffer = usbvision->sbuf[buf_idx].data; 2304 - urb->complete = usbvision_isoc_irq; 2305 - urb->number_of_packets = USBVISION_URB_FRAMES; 2306 - urb->transfer_buffer_length = 2307 - usbvision->isoc_packet_size * USBVISION_URB_FRAMES; 2308 - for (j = k = 0; j < USBVISION_URB_FRAMES; j++, 2309 - k += usbvision->isoc_packet_size) { 2310 - urb->iso_frame_desc[j].offset = k; 2311 - urb->iso_frame_desc[j].length = 2312 - usbvision->isoc_packet_size; 2313 - } 2314 - } 2315 - 2316 - /* Submit all URBs */ 2317 - for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { 2318 - err_code = usb_submit_urb(usbvision->sbuf[buf_idx].urb, 2319 - GFP_KERNEL); 2320 - if (err_code) { 2321 - dev_err(&usbvision->dev->dev, 2322 - "%s: usb_submit_urb(%d) failed: error %d\n", 2323 - __func__, buf_idx, err_code); 2324 - } 2325 - } 2326 - 2327 - usbvision->streaming = stream_idle; 2328 - PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x", 2329 - __func__, 2330 - usbvision->video_endp); 2331 - return 0; 2332 - } 2333 - 2334 - /* 2335 - * usbvision_stop_isoc() 2336 - * 2337 - * This procedure stops streaming and deallocates URBs. Then it 2338 - * activates zero-bandwidth alt. setting of the video interface. 2339 - * 2340 - */ 2341 - void usbvision_stop_isoc(struct usb_usbvision *usbvision) 2342 - { 2343 - int buf_idx, err_code, reg_value; 2344 - int sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size; 2345 - 2346 - if ((usbvision->streaming == stream_off) || (usbvision->dev == NULL)) 2347 - return; 2348 - 2349 - /* Unschedule all of the iso td's */ 2350 - for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { 2351 - usb_kill_urb(usbvision->sbuf[buf_idx].urb); 2352 - if (usbvision->sbuf[buf_idx].data) { 2353 - usb_free_coherent(usbvision->dev, 2354 - sb_size, 2355 - usbvision->sbuf[buf_idx].data, 2356 - usbvision->sbuf[buf_idx].urb->transfer_dma); 2357 - } 2358 - usb_free_urb(usbvision->sbuf[buf_idx].urb); 2359 - usbvision->sbuf[buf_idx].urb = NULL; 2360 - } 2361 - 2362 - PDEBUG(DBG_ISOC, "%s: streaming=stream_off\n", __func__); 2363 - usbvision->streaming = stream_off; 2364 - 2365 - if (!usbvision->remove_pending) { 2366 - /* Set packet size to 0 */ 2367 - usbvision->iface_alt = 0; 2368 - err_code = usb_set_interface(usbvision->dev, usbvision->iface, 2369 - usbvision->iface_alt); 2370 - if (err_code < 0) { 2371 - dev_err(&usbvision->dev->dev, 2372 - "%s: usb_set_interface() failed: error %d\n", 2373 - __func__, err_code); 2374 - usbvision->last_error = err_code; 2375 - } 2376 - reg_value = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F; 2377 - usbvision->isoc_packet_size = 2378 - (reg_value == 0) ? 0 : (reg_value * 64) - 1; 2379 - PDEBUG(DBG_ISOC, "ISO Packet Length:%d", 2380 - usbvision->isoc_packet_size); 2381 - 2382 - usbvision->usb_bandwidth = reg_value >> 1; 2383 - PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", 2384 - usbvision->usb_bandwidth); 2385 - } 2386 - } 2387 - 2388 - int usbvision_muxsel(struct usb_usbvision *usbvision, int channel) 2389 - { 2390 - /* inputs #0 and #3 are constant for every SAA711x. */ 2391 - /* inputs #1 and #2 are variable for SAA7111 and SAA7113 */ 2392 - int mode[4] = { SAA7115_COMPOSITE0, 0, 0, SAA7115_COMPOSITE3 }; 2393 - int audio[] = { 1, 0, 0, 0 }; 2394 - /* channel 0 is TV with audiochannel 1 (tuner mono) */ 2395 - /* channel 1 is Composite with audio channel 0 (line in) */ 2396 - /* channel 2 is S-Video with audio channel 0 (line in) */ 2397 - /* channel 3 is additional video inputs to the device with audio channel 0 (line in) */ 2398 - 2399 - RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs); 2400 - usbvision->ctl_input = channel; 2401 - 2402 - /* set the new channel */ 2403 - /* Regular USB TV Tuners -> channel: 0 = Television, 1 = Composite, 2 = S-Video */ 2404 - /* Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red */ 2405 - 2406 - switch (usbvision_device_data[usbvision->dev_model].codec) { 2407 - case CODEC_SAA7113: 2408 - mode[1] = SAA7115_COMPOSITE2; 2409 - if (switch_svideo_input) { 2410 - /* To handle problems with S-Video Input for 2411 - * some devices. Use switch_svideo_input 2412 - * parameter when loading the module.*/ 2413 - mode[2] = SAA7115_COMPOSITE1; 2414 - } else { 2415 - mode[2] = SAA7115_SVIDEO1; 2416 - } 2417 - break; 2418 - case CODEC_SAA7111: 2419 - default: 2420 - /* modes for saa7111 */ 2421 - mode[1] = SAA7115_COMPOSITE1; 2422 - mode[2] = SAA7115_SVIDEO1; 2423 - break; 2424 - } 2425 - call_all(usbvision, video, s_routing, mode[channel], 0, 0); 2426 - usbvision_set_audio(usbvision, audio[channel]); 2427 - return 0; 2428 - }
-438
drivers/staging/media/usbvision/usbvision-i2c.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * usbvision_i2c.c 4 - * i2c algorithm for USB-I2C Bridges 5 - * 6 - * Copyright (c) 1999-2007 Joerg Heckenbach <joerg@heckenbach-aw.de> 7 - * Dwaine Garden <dwainegarden@rogers.com> 8 - * 9 - * This module is part of usbvision driver project. 10 - * Updates to driver completed by Dwaine P. Garden 11 - */ 12 - 13 - 14 - #include <linux/kernel.h> 15 - #include <linux/module.h> 16 - #include <linux/delay.h> 17 - #include <linux/init.h> 18 - #include <linux/uaccess.h> 19 - #include <linux/ioport.h> 20 - #include <linux/errno.h> 21 - #include <linux/usb.h> 22 - #include <linux/i2c.h> 23 - #include "usbvision.h" 24 - 25 - #define DBG_I2C (1 << 0) 26 - 27 - static int i2c_debug; 28 - 29 - module_param(i2c_debug, int, 0644); /* debug_i2c_usb mode of the device driver */ 30 - MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 31 - 32 - #define PDEBUG(level, fmt, args...) { \ 33 - if (i2c_debug & (level)) \ 34 - printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ 35 - __func__, __LINE__ , ## args); \ 36 - } 37 - 38 - static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf, 39 - short len); 40 - static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf, 41 - short len); 42 - 43 - static inline int try_write_address(struct i2c_adapter *i2c_adap, 44 - unsigned char addr, int retries) 45 - { 46 - struct usb_usbvision *usbvision; 47 - int i, ret = -1; 48 - char buf[4]; 49 - 50 - usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); 51 - buf[0] = 0x00; 52 - for (i = 0; i <= retries; i++) { 53 - ret = (usbvision_i2c_write(usbvision, addr, buf, 1)); 54 - if (ret == 1) 55 - break; /* success! */ 56 - udelay(5); 57 - if (i == retries) /* no success */ 58 - break; 59 - udelay(10); 60 - } 61 - if (i) { 62 - PDEBUG(DBG_I2C, "Needed %d retries for address %#2x", i, addr); 63 - PDEBUG(DBG_I2C, "Maybe there's no device at this address"); 64 - } 65 - return ret; 66 - } 67 - 68 - static inline int try_read_address(struct i2c_adapter *i2c_adap, 69 - unsigned char addr, int retries) 70 - { 71 - struct usb_usbvision *usbvision; 72 - int i, ret = -1; 73 - char buf[4]; 74 - 75 - usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); 76 - for (i = 0; i <= retries; i++) { 77 - ret = (usbvision_i2c_read(usbvision, addr, buf, 1)); 78 - if (ret == 1) 79 - break; /* success! */ 80 - udelay(5); 81 - if (i == retries) /* no success */ 82 - break; 83 - udelay(10); 84 - } 85 - if (i) { 86 - PDEBUG(DBG_I2C, "Needed %d retries for address %#2x", i, addr); 87 - PDEBUG(DBG_I2C, "Maybe there's no device at this address"); 88 - } 89 - return ret; 90 - } 91 - 92 - static inline int usb_find_address(struct i2c_adapter *i2c_adap, 93 - struct i2c_msg *msg, int retries, 94 - unsigned char *add) 95 - { 96 - unsigned short flags = msg->flags; 97 - 98 - unsigned char addr; 99 - int ret; 100 - 101 - addr = (msg->addr << 1); 102 - if (flags & I2C_M_RD) 103 - addr |= 1; 104 - 105 - add[0] = addr; 106 - if (flags & I2C_M_RD) 107 - ret = try_read_address(i2c_adap, addr, retries); 108 - else 109 - ret = try_write_address(i2c_adap, addr, retries); 110 - 111 - if (ret != 1) 112 - return -EREMOTEIO; 113 - 114 - return 0; 115 - } 116 - 117 - static int 118 - usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) 119 - { 120 - struct i2c_msg *pmsg; 121 - struct usb_usbvision *usbvision; 122 - int i, ret; 123 - unsigned char addr = 0; 124 - 125 - usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); 126 - 127 - for (i = 0; i < num; i++) { 128 - pmsg = &msgs[i]; 129 - ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr); 130 - if (ret != 0) { 131 - PDEBUG(DBG_I2C, "got NAK from device, message #%d", i); 132 - return (ret < 0) ? ret : -EREMOTEIO; 133 - } 134 - 135 - if (pmsg->flags & I2C_M_RD) { 136 - /* read bytes into buffer */ 137 - ret = (usbvision_i2c_read(usbvision, addr, pmsg->buf, pmsg->len)); 138 - if (ret < pmsg->len) 139 - return (ret < 0) ? ret : -EREMOTEIO; 140 - } else { 141 - /* write bytes from buffer */ 142 - ret = (usbvision_i2c_write(usbvision, addr, pmsg->buf, pmsg->len)); 143 - if (ret < pmsg->len) 144 - return (ret < 0) ? ret : -EREMOTEIO; 145 - } 146 - } 147 - return num; 148 - } 149 - 150 - static u32 functionality(struct i2c_adapter *adap) 151 - { 152 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 153 - } 154 - 155 - /* -----exported algorithm data: ------------------------------------- */ 156 - 157 - static const struct i2c_algorithm usbvision_algo = { 158 - .master_xfer = usbvision_i2c_xfer, 159 - .smbus_xfer = NULL, 160 - .functionality = functionality, 161 - }; 162 - 163 - 164 - /* ----------------------------------------------------------------------- */ 165 - /* usbvision specific I2C functions */ 166 - /* ----------------------------------------------------------------------- */ 167 - static const struct i2c_adapter i2c_adap_template; 168 - 169 - int usbvision_i2c_register(struct usb_usbvision *usbvision) 170 - { 171 - static unsigned short saa711x_addrs[] = { 172 - 0x4a >> 1, 0x48 >> 1, /* SAA7111, SAA7111A and SAA7113 */ 173 - 0x42 >> 1, 0x40 >> 1, /* SAA7114, SAA7115 and SAA7118 */ 174 - I2C_CLIENT_END }; 175 - 176 - if (usbvision->registered_i2c) 177 - return 0; 178 - 179 - usbvision->i2c_adap = i2c_adap_template; 180 - 181 - snprintf(usbvision->i2c_adap.name, sizeof(usbvision->i2c_adap.name), 182 - "usbvision-%d-%s", 183 - usbvision->dev->bus->busnum, usbvision->dev->devpath); 184 - PDEBUG(DBG_I2C, "Adaptername: %s", usbvision->i2c_adap.name); 185 - usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; 186 - 187 - i2c_set_adapdata(&usbvision->i2c_adap, &usbvision->v4l2_dev); 188 - 189 - if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { 190 - printk(KERN_ERR "usbvision_i2c_register: can't write reg\n"); 191 - return -EBUSY; 192 - } 193 - 194 - PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); 195 - PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]"); 196 - 197 - /* register new adapter to i2c module... */ 198 - 199 - usbvision->i2c_adap.algo = &usbvision_algo; 200 - 201 - usbvision->i2c_adap.timeout = 100; /* default values, should */ 202 - usbvision->i2c_adap.retries = 3; /* be replaced by defines */ 203 - 204 - i2c_add_adapter(&usbvision->i2c_adap); 205 - 206 - PDEBUG(DBG_I2C, "i2c bus for %s registered", usbvision->i2c_adap.name); 207 - 208 - /* Request the load of the i2c modules we need */ 209 - switch (usbvision_device_data[usbvision->dev_model].codec) { 210 - case CODEC_SAA7113: 211 - case CODEC_SAA7111: 212 - /* Without this delay the detection of the saa711x is 213 - hit-and-miss. */ 214 - mdelay(10); 215 - v4l2_i2c_new_subdev(&usbvision->v4l2_dev, 216 - &usbvision->i2c_adap, 217 - "saa7115_auto", 0, saa711x_addrs); 218 - break; 219 - } 220 - if (usbvision_device_data[usbvision->dev_model].tuner == 1) { 221 - struct v4l2_subdev *sd; 222 - enum v4l2_i2c_tuner_type type; 223 - struct tuner_setup tun_setup; 224 - 225 - sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev, 226 - &usbvision->i2c_adap, 227 - "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 228 - /* depending on whether we found a demod or not, select 229 - the tuner type. */ 230 - type = sd ? ADDRS_TV_WITH_DEMOD : ADDRS_TV; 231 - 232 - sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev, 233 - &usbvision->i2c_adap, 234 - "tuner", 0, v4l2_i2c_tuner_addrs(type)); 235 - 236 - if (sd == NULL) 237 - return -ENODEV; 238 - if (usbvision->tuner_type != -1) { 239 - tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; 240 - tun_setup.type = usbvision->tuner_type; 241 - tun_setup.addr = v4l2_i2c_subdev_addr(sd); 242 - call_all(usbvision, tuner, s_type_addr, &tun_setup); 243 - } 244 - } 245 - usbvision->registered_i2c = 1; 246 - 247 - return 0; 248 - } 249 - 250 - int usbvision_i2c_unregister(struct usb_usbvision *usbvision) 251 - { 252 - if (!usbvision->registered_i2c) 253 - return 0; 254 - 255 - i2c_del_adapter(&(usbvision->i2c_adap)); 256 - usbvision->registered_i2c = 0; 257 - 258 - PDEBUG(DBG_I2C, "i2c bus for %s unregistered", usbvision->i2c_adap.name); 259 - 260 - return 0; 261 - } 262 - 263 - static int 264 - usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr, 265 - char *buf, short len) 266 - { 267 - int rc, retries; 268 - 269 - for (retries = 5;;) { 270 - rc = usbvision_write_reg(usbvision, USBVISION_SER_ADRS, addr); 271 - if (rc < 0) 272 - return rc; 273 - 274 - /* Initiate byte read cycle */ 275 - /* USBVISION_SER_CONT <- d0-d2 n. of bytes to r/w */ 276 - /* d3 0=Wr 1=Rd */ 277 - rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT, 278 - (len & 0x07) | 0x18); 279 - if (rc < 0) 280 - return rc; 281 - 282 - /* Test for Busy and ACK */ 283 - do { 284 - /* USBVISION_SER_CONT -> d4 == 0 busy */ 285 - rc = usbvision_read_reg(usbvision, USBVISION_SER_CONT); 286 - } while (rc > 0 && ((rc & 0x10) != 0)); /* Retry while busy */ 287 - if (rc < 0) 288 - return rc; 289 - 290 - /* USBVISION_SER_CONT -> d5 == 1 Not ack */ 291 - if ((rc & 0x20) == 0) /* Ack? */ 292 - break; 293 - 294 - /* I2C abort */ 295 - rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT, 0x00); 296 - if (rc < 0) 297 - return rc; 298 - 299 - if (--retries < 0) 300 - return -1; 301 - } 302 - 303 - switch (len) { 304 - case 4: 305 - buf[3] = usbvision_read_reg(usbvision, USBVISION_SER_DAT4); 306 - fallthrough; 307 - case 3: 308 - buf[2] = usbvision_read_reg(usbvision, USBVISION_SER_DAT3); 309 - fallthrough; 310 - case 2: 311 - buf[1] = usbvision_read_reg(usbvision, USBVISION_SER_DAT2); 312 - fallthrough; 313 - case 1: 314 - buf[0] = usbvision_read_reg(usbvision, USBVISION_SER_DAT1); 315 - break; 316 - default: 317 - printk(KERN_ERR 318 - "usbvision_i2c_read_max4: buffer length > 4\n"); 319 - } 320 - 321 - if (i2c_debug & DBG_I2C) { 322 - int idx; 323 - 324 - for (idx = 0; idx < len; idx++) 325 - PDEBUG(DBG_I2C, "read %x from address %x", (unsigned char)buf[idx], addr); 326 - } 327 - return len; 328 - } 329 - 330 - 331 - static int usbvision_i2c_write_max4(struct usb_usbvision *usbvision, 332 - unsigned char addr, const char *buf, 333 - short len) 334 - { 335 - int rc, retries; 336 - int i; 337 - unsigned char *value = usbvision->ctrl_urb_buffer; 338 - unsigned char ser_cont; 339 - 340 - ser_cont = (len & 0x07) | 0x10; 341 - 342 - value[0] = addr; 343 - value[1] = ser_cont; 344 - for (i = 0; i < len; i++) 345 - value[i + 2] = buf[i]; 346 - 347 - for (retries = 5;;) { 348 - rc = usb_control_msg(usbvision->dev, 349 - usb_sndctrlpipe(usbvision->dev, 1), 350 - USBVISION_OP_CODE, 351 - USB_DIR_OUT | USB_TYPE_VENDOR | 352 - USB_RECIP_ENDPOINT, 0, 353 - (__u16) USBVISION_SER_ADRS, value, 354 - len + 2, HZ); 355 - 356 - if (rc < 0) 357 - return rc; 358 - 359 - rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT, 360 - (len & 0x07) | 0x10); 361 - if (rc < 0) 362 - return rc; 363 - 364 - /* Test for Busy and ACK */ 365 - do { 366 - rc = usbvision_read_reg(usbvision, USBVISION_SER_CONT); 367 - } while (rc > 0 && ((rc & 0x10) != 0)); /* Retry while busy */ 368 - if (rc < 0) 369 - return rc; 370 - 371 - if ((rc & 0x20) == 0) /* Ack? */ 372 - break; 373 - 374 - /* I2C abort */ 375 - usbvision_write_reg(usbvision, USBVISION_SER_CONT, 0x00); 376 - 377 - if (--retries < 0) 378 - return -1; 379 - 380 - } 381 - 382 - if (i2c_debug & DBG_I2C) { 383 - int idx; 384 - 385 - for (idx = 0; idx < len; idx++) 386 - PDEBUG(DBG_I2C, "wrote %x at address %x", (unsigned char)buf[idx], addr); 387 - } 388 - return len; 389 - } 390 - 391 - static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf, 392 - short len) 393 - { 394 - char *buf_ptr = buf; 395 - int retval; 396 - int wrcount = 0; 397 - int count; 398 - int max_len = 4; 399 - 400 - while (len > 0) { 401 - count = (len > max_len) ? max_len : len; 402 - retval = usbvision_i2c_write_max4(usbvision, addr, buf_ptr, count); 403 - if (retval > 0) { 404 - len -= count; 405 - buf_ptr += count; 406 - wrcount += count; 407 - } else 408 - return (retval < 0) ? retval : -EFAULT; 409 - } 410 - return wrcount; 411 - } 412 - 413 - static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf, 414 - short len) 415 - { 416 - char temp[4]; 417 - int retval, i; 418 - int rdcount = 0; 419 - int count; 420 - 421 - while (len > 0) { 422 - count = (len > 3) ? 4 : len; 423 - retval = usbvision_i2c_read_max4(usbvision, addr, temp, count); 424 - if (retval > 0) { 425 - for (i = 0; i < len; i++) 426 - buf[rdcount + i] = temp[i]; 427 - len -= count; 428 - rdcount += count; 429 - } else 430 - return (retval < 0) ? retval : -EFAULT; 431 - } 432 - return rdcount; 433 - } 434 - 435 - static const struct i2c_adapter i2c_adap_template = { 436 - .owner = THIS_MODULE, 437 - .name = "usbvision", 438 - };
-1643
drivers/staging/media/usbvision/usbvision-video.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * USB USBVISION Video device driver 0.9.10 4 - * 5 - * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> 6 - * 7 - * This module is part of usbvision driver project. 8 - * 9 - * Let's call the version 0.... until compression decoding is completely 10 - * implemented. 11 - * 12 - * This driver is written by Jose Ignacio Gijon and Joerg Heckenbach. 13 - * It was based on USB CPiA driver written by Peter Pregler, 14 - * Scott J. Bertin and Johannes Erdfelt 15 - * Ideas are taken from bttv driver by Ralph Metzler, Marcus Metzler & 16 - * Gerd Knorr and zoran 36120/36125 driver by Pauline Middelink 17 - * Updates to driver completed by Dwaine P. Garden 18 - * 19 - * TODO: 20 - * - use submit_urb for all setup packets 21 - * - Fix memory settings for nt1004. It is 4 times as big as the 22 - * nt1003 memory. 23 - * - Add audio on endpoint 3 for nt1004 chip. 24 - * Seems impossible, needs a codec interface. Which one? 25 - * - Clean up the driver. 26 - * - optimization for performance. 27 - * - Add Videotext capability (VBI). Working on it..... 28 - * - Check audio for other devices 29 - */ 30 - 31 - #include <linux/kernel.h> 32 - #include <linux/list.h> 33 - #include <linux/timer.h> 34 - #include <linux/slab.h> 35 - #include <linux/mm.h> 36 - #include <linux/highmem.h> 37 - #include <linux/vmalloc.h> 38 - #include <linux/module.h> 39 - #include <linux/init.h> 40 - #include <linux/spinlock.h> 41 - #include <linux/io.h> 42 - #include <linux/videodev2.h> 43 - #include <linux/i2c.h> 44 - 45 - #include <media/i2c/saa7115.h> 46 - #include <media/v4l2-common.h> 47 - #include <media/v4l2-ioctl.h> 48 - #include <media/v4l2-event.h> 49 - #include <media/tuner.h> 50 - 51 - #include <linux/workqueue.h> 52 - 53 - #include "usbvision.h" 54 - #include "usbvision-cards.h" 55 - 56 - #define DRIVER_AUTHOR \ 57 - "Joerg Heckenbach <joerg@heckenbach-aw.de>, " \ 58 - "Dwaine Garden <DwaineGarden@rogers.com>" 59 - #define DRIVER_NAME "usbvision" 60 - #define DRIVER_ALIAS "USBVision" 61 - #define DRIVER_DESC "USBVision USB Video Device Driver for Linux" 62 - #define USBVISION_VERSION_STRING "0.9.11" 63 - 64 - #define ENABLE_HEXDUMP 0 /* Enable if you need it */ 65 - 66 - 67 - #ifdef USBVISION_DEBUG 68 - #define PDEBUG(level, fmt, args...) { \ 69 - if (video_debug & (level)) \ 70 - printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ 71 - __func__, __LINE__ , ## args); \ 72 - } 73 - #else 74 - #define PDEBUG(level, fmt, args...) do {} while (0) 75 - #endif 76 - 77 - #define DBG_IO (1 << 1) 78 - #define DBG_PROBE (1 << 2) 79 - #define DBG_MMAP (1 << 3) 80 - 81 - /* String operations */ 82 - #define rmspace(str) while (*str == ' ') str++; 83 - #define goto2next(str) while (*str != ' ') str++; while (*str == ' ') str++; 84 - 85 - 86 - /* sequential number of usbvision device */ 87 - static int usbvision_nr; 88 - 89 - static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = { 90 - { 1, 1, 8, V4L2_PIX_FMT_GREY }, 91 - { 1, 2, 16, V4L2_PIX_FMT_RGB565 }, 92 - { 1, 3, 24, V4L2_PIX_FMT_RGB24 }, 93 - { 1, 4, 32, V4L2_PIX_FMT_RGB32 }, 94 - { 1, 2, 16, V4L2_PIX_FMT_RGB555 }, 95 - { 1, 2, 16, V4L2_PIX_FMT_YUYV }, 96 - { 1, 2, 12, V4L2_PIX_FMT_YVU420 }, /* 1.5 ! */ 97 - { 1, 2, 16, V4L2_PIX_FMT_YUV422P } 98 - }; 99 - 100 - /* Function prototypes */ 101 - static void usbvision_release(struct usb_usbvision *usbvision); 102 - 103 - /* Default initialization of device driver parameters */ 104 - /* Set the default format for ISOC endpoint */ 105 - static int isoc_mode = ISOC_MODE_COMPRESS; 106 - /* Set the default Debug Mode of the device driver */ 107 - static int video_debug; 108 - /* Sequential Number of Video Device */ 109 - static int video_nr = -1; 110 - /* Sequential Number of Radio Device */ 111 - static int radio_nr = -1; 112 - 113 - /* Grab parameters for the device driver */ 114 - 115 - /* Showing parameters under SYSFS */ 116 - module_param(isoc_mode, int, 0444); 117 - module_param(video_debug, int, 0444); 118 - module_param(video_nr, int, 0444); 119 - module_param(radio_nr, int, 0444); 120 - 121 - MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)"); 122 - MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)"); 123 - MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)"); 124 - MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); 125 - 126 - 127 - /* Misc stuff */ 128 - MODULE_AUTHOR(DRIVER_AUTHOR); 129 - MODULE_DESCRIPTION(DRIVER_DESC); 130 - MODULE_LICENSE("GPL"); 131 - MODULE_VERSION(USBVISION_VERSION_STRING); 132 - MODULE_ALIAS(DRIVER_ALIAS); 133 - 134 - 135 - /*****************************************************************************/ 136 - /* SYSFS Code - Copied from the stv680.c usb module. */ 137 - /* Device information is located at /sys/class/video4linux/video0 */ 138 - /* Device parameters information is located at /sys/module/usbvision */ 139 - /* Device USB Information is located at */ 140 - /* /sys/bus/usb/drivers/USBVision Video Grabber */ 141 - /*****************************************************************************/ 142 - 143 - #define YES_NO(x) ((x) ? "Yes" : "No") 144 - 145 - static inline struct usb_usbvision *cd_to_usbvision(struct device *cd) 146 - { 147 - struct video_device *vdev = to_video_device(cd); 148 - return video_get_drvdata(vdev); 149 - } 150 - 151 - static ssize_t show_version(struct device *cd, 152 - struct device_attribute *attr, char *buf) 153 - { 154 - return sprintf(buf, "%s\n", USBVISION_VERSION_STRING); 155 - } 156 - static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); 157 - 158 - static ssize_t show_model(struct device *cd, 159 - struct device_attribute *attr, char *buf) 160 - { 161 - struct video_device *vdev = to_video_device(cd); 162 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 163 - return sprintf(buf, "%s\n", 164 - usbvision_device_data[usbvision->dev_model].model_string); 165 - } 166 - static DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 167 - 168 - static ssize_t show_hue(struct device *cd, 169 - struct device_attribute *attr, char *buf) 170 - { 171 - struct video_device *vdev = to_video_device(cd); 172 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 173 - s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl, 174 - V4L2_CID_HUE)); 175 - 176 - return sprintf(buf, "%d\n", val); 177 - } 178 - static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 179 - 180 - static ssize_t show_contrast(struct device *cd, 181 - struct device_attribute *attr, char *buf) 182 - { 183 - struct video_device *vdev = to_video_device(cd); 184 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 185 - s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl, 186 - V4L2_CID_CONTRAST)); 187 - 188 - return sprintf(buf, "%d\n", val); 189 - } 190 - static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 191 - 192 - static ssize_t show_brightness(struct device *cd, 193 - struct device_attribute *attr, char *buf) 194 - { 195 - struct video_device *vdev = to_video_device(cd); 196 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 197 - s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl, 198 - V4L2_CID_BRIGHTNESS)); 199 - 200 - return sprintf(buf, "%d\n", val); 201 - } 202 - static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 203 - 204 - static ssize_t show_saturation(struct device *cd, 205 - struct device_attribute *attr, char *buf) 206 - { 207 - struct video_device *vdev = to_video_device(cd); 208 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 209 - s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl, 210 - V4L2_CID_SATURATION)); 211 - 212 - return sprintf(buf, "%d\n", val); 213 - } 214 - static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 215 - 216 - static ssize_t show_streaming(struct device *cd, 217 - struct device_attribute *attr, char *buf) 218 - { 219 - struct video_device *vdev = to_video_device(cd); 220 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 221 - return sprintf(buf, "%s\n", 222 - YES_NO(usbvision->streaming == stream_on ? 1 : 0)); 223 - } 224 - static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); 225 - 226 - static ssize_t show_compression(struct device *cd, 227 - struct device_attribute *attr, char *buf) 228 - { 229 - struct video_device *vdev = to_video_device(cd); 230 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 231 - return sprintf(buf, "%s\n", 232 - YES_NO(usbvision->isoc_mode == ISOC_MODE_COMPRESS)); 233 - } 234 - static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); 235 - 236 - static ssize_t show_device_bridge(struct device *cd, 237 - struct device_attribute *attr, char *buf) 238 - { 239 - struct video_device *vdev = to_video_device(cd); 240 - struct usb_usbvision *usbvision = video_get_drvdata(vdev); 241 - return sprintf(buf, "%d\n", usbvision->bridge_type); 242 - } 243 - static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL); 244 - 245 - static void usbvision_create_sysfs(struct video_device *vdev) 246 - { 247 - int res; 248 - 249 - if (!vdev) 250 - return; 251 - do { 252 - res = device_create_file(&vdev->dev, &dev_attr_version); 253 - if (res < 0) 254 - break; 255 - res = device_create_file(&vdev->dev, &dev_attr_model); 256 - if (res < 0) 257 - break; 258 - res = device_create_file(&vdev->dev, &dev_attr_hue); 259 - if (res < 0) 260 - break; 261 - res = device_create_file(&vdev->dev, &dev_attr_contrast); 262 - if (res < 0) 263 - break; 264 - res = device_create_file(&vdev->dev, &dev_attr_brightness); 265 - if (res < 0) 266 - break; 267 - res = device_create_file(&vdev->dev, &dev_attr_saturation); 268 - if (res < 0) 269 - break; 270 - res = device_create_file(&vdev->dev, &dev_attr_streaming); 271 - if (res < 0) 272 - break; 273 - res = device_create_file(&vdev->dev, &dev_attr_compression); 274 - if (res < 0) 275 - break; 276 - res = device_create_file(&vdev->dev, &dev_attr_bridge); 277 - if (res >= 0) 278 - return; 279 - } while (0); 280 - 281 - dev_err(&vdev->dev, "%s error: %d\n", __func__, res); 282 - } 283 - 284 - static void usbvision_remove_sysfs(struct video_device *vdev) 285 - { 286 - if (vdev) { 287 - device_remove_file(&vdev->dev, &dev_attr_version); 288 - device_remove_file(&vdev->dev, &dev_attr_model); 289 - device_remove_file(&vdev->dev, &dev_attr_hue); 290 - device_remove_file(&vdev->dev, &dev_attr_contrast); 291 - device_remove_file(&vdev->dev, &dev_attr_brightness); 292 - device_remove_file(&vdev->dev, &dev_attr_saturation); 293 - device_remove_file(&vdev->dev, &dev_attr_streaming); 294 - device_remove_file(&vdev->dev, &dev_attr_compression); 295 - device_remove_file(&vdev->dev, &dev_attr_bridge); 296 - } 297 - } 298 - 299 - /* 300 - * usbvision_open() 301 - * 302 - * This is part of Video 4 Linux API. The driver can be opened by one 303 - * client only (checks internal counter 'usbvision->user'). The procedure 304 - * then allocates buffers needed for video processing. 305 - * 306 - */ 307 - static int usbvision_v4l2_open(struct file *file) 308 - { 309 - struct usb_usbvision *usbvision = video_drvdata(file); 310 - int err_code = 0; 311 - 312 - PDEBUG(DBG_IO, "open"); 313 - 314 - if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 315 - return -ERESTARTSYS; 316 - 317 - if (usbvision->remove_pending) { 318 - err_code = -ENODEV; 319 - goto unlock; 320 - } 321 - if (usbvision->user) { 322 - err_code = -EBUSY; 323 - } else { 324 - err_code = v4l2_fh_open(file); 325 - if (err_code) 326 - goto unlock; 327 - 328 - /* Allocate memory for the scratch ring buffer */ 329 - err_code = usbvision_scratch_alloc(usbvision); 330 - if (isoc_mode == ISOC_MODE_COMPRESS) { 331 - /* Allocate intermediate decompression buffers 332 - only if needed */ 333 - err_code = usbvision_decompress_alloc(usbvision); 334 - } 335 - if (err_code) { 336 - /* Deallocate all buffers if trouble */ 337 - usbvision_scratch_free(usbvision); 338 - usbvision_decompress_free(usbvision); 339 - } 340 - } 341 - 342 - /* If so far no errors then we shall start the camera */ 343 - if (!err_code) { 344 - /* Send init sequence only once, it's large! */ 345 - if (!usbvision->initialized) { 346 - int setup_ok = 0; 347 - setup_ok = usbvision_setup(usbvision, isoc_mode); 348 - if (setup_ok) 349 - usbvision->initialized = 1; 350 - else 351 - err_code = -EBUSY; 352 - } 353 - 354 - if (!err_code) { 355 - usbvision_begin_streaming(usbvision); 356 - err_code = usbvision_init_isoc(usbvision); 357 - /* device must be initialized before isoc transfer */ 358 - usbvision_muxsel(usbvision, 0); 359 - 360 - /* prepare queues */ 361 - usbvision_empty_framequeues(usbvision); 362 - usbvision->user++; 363 - } 364 - } 365 - 366 - unlock: 367 - mutex_unlock(&usbvision->v4l2_lock); 368 - 369 - PDEBUG(DBG_IO, "success"); 370 - return err_code; 371 - } 372 - 373 - /* 374 - * usbvision_v4l2_close() 375 - * 376 - * This is part of Video 4 Linux API. The procedure 377 - * stops streaming and deallocates all buffers that were earlier 378 - * allocated in usbvision_v4l2_open(). 379 - * 380 - */ 381 - static int usbvision_v4l2_close(struct file *file) 382 - { 383 - struct usb_usbvision *usbvision = video_drvdata(file); 384 - int r; 385 - 386 - PDEBUG(DBG_IO, "close"); 387 - 388 - mutex_lock(&usbvision->v4l2_lock); 389 - usbvision_audio_off(usbvision); 390 - usbvision_restart_isoc(usbvision); 391 - usbvision_stop_isoc(usbvision); 392 - 393 - usbvision_decompress_free(usbvision); 394 - usbvision_frames_free(usbvision); 395 - usbvision_empty_framequeues(usbvision); 396 - usbvision_scratch_free(usbvision); 397 - 398 - usbvision->user--; 399 - r = usbvision->remove_pending; 400 - mutex_unlock(&usbvision->v4l2_lock); 401 - 402 - if (r) { 403 - printk(KERN_INFO "%s: Final disconnect\n", __func__); 404 - usbvision_release(usbvision); 405 - return 0; 406 - } 407 - 408 - PDEBUG(DBG_IO, "success"); 409 - return v4l2_fh_release(file); 410 - } 411 - 412 - 413 - /* 414 - * usbvision_ioctl() 415 - * 416 - * This is part of Video 4 Linux API. The procedure handles ioctl() calls. 417 - * 418 - */ 419 - #ifdef CONFIG_VIDEO_ADV_DEBUG 420 - static int vidioc_g_register(struct file *file, void *priv, 421 - struct v4l2_dbg_register *reg) 422 - { 423 - struct usb_usbvision *usbvision = video_drvdata(file); 424 - int err_code; 425 - 426 - /* NT100x has a 8-bit register space */ 427 - err_code = usbvision_read_reg(usbvision, reg->reg&0xff); 428 - if (err_code < 0) { 429 - dev_err(&usbvision->vdev.dev, 430 - "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", 431 - __func__, err_code); 432 - return err_code; 433 - } 434 - reg->val = err_code; 435 - reg->size = 1; 436 - return 0; 437 - } 438 - 439 - static int vidioc_s_register(struct file *file, void *priv, 440 - const struct v4l2_dbg_register *reg) 441 - { 442 - struct usb_usbvision *usbvision = video_drvdata(file); 443 - int err_code; 444 - 445 - /* NT100x has a 8-bit register space */ 446 - err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val); 447 - if (err_code < 0) { 448 - dev_err(&usbvision->vdev.dev, 449 - "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", 450 - __func__, err_code); 451 - return err_code; 452 - } 453 - return 0; 454 - } 455 - #endif 456 - 457 - static int vidioc_querycap(struct file *file, void *priv, 458 - struct v4l2_capability *vc) 459 - { 460 - struct usb_usbvision *usbvision = video_drvdata(file); 461 - 462 - if (!usbvision->dev) 463 - return -ENODEV; 464 - 465 - strscpy(vc->driver, "USBVision", sizeof(vc->driver)); 466 - strscpy(vc->card, 467 - usbvision_device_data[usbvision->dev_model].model_string, 468 - sizeof(vc->card)); 469 - usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info)); 470 - vc->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | 471 - V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS; 472 - if (usbvision_device_data[usbvision->dev_model].radio) 473 - vc->capabilities |= V4L2_CAP_RADIO; 474 - if (usbvision->have_tuner) 475 - vc->capabilities |= V4L2_CAP_TUNER; 476 - return 0; 477 - } 478 - 479 - static int vidioc_enum_input(struct file *file, void *priv, 480 - struct v4l2_input *vi) 481 - { 482 - struct usb_usbvision *usbvision = video_drvdata(file); 483 - int chan; 484 - 485 - if (vi->index >= usbvision->video_inputs) 486 - return -EINVAL; 487 - if (usbvision->have_tuner) 488 - chan = vi->index; 489 - else 490 - chan = vi->index + 1; /* skip Television string*/ 491 - 492 - /* Determine the requested input characteristics 493 - specific for each usbvision card model */ 494 - switch (chan) { 495 - case 0: 496 - if (usbvision_device_data[usbvision->dev_model].video_channels == 4) { 497 - strscpy(vi->name, "White Video Input", sizeof(vi->name)); 498 - } else { 499 - strscpy(vi->name, "Television", sizeof(vi->name)); 500 - vi->type = V4L2_INPUT_TYPE_TUNER; 501 - vi->tuner = chan; 502 - vi->std = USBVISION_NORMS; 503 - } 504 - break; 505 - case 1: 506 - vi->type = V4L2_INPUT_TYPE_CAMERA; 507 - if (usbvision_device_data[usbvision->dev_model].video_channels == 4) 508 - strscpy(vi->name, "Green Video Input", sizeof(vi->name)); 509 - else 510 - strscpy(vi->name, "Composite Video Input", 511 - sizeof(vi->name)); 512 - vi->std = USBVISION_NORMS; 513 - break; 514 - case 2: 515 - vi->type = V4L2_INPUT_TYPE_CAMERA; 516 - if (usbvision_device_data[usbvision->dev_model].video_channels == 4) 517 - strscpy(vi->name, "Yellow Video Input", sizeof(vi->name)); 518 - else 519 - strscpy(vi->name, "S-Video Input", sizeof(vi->name)); 520 - vi->std = USBVISION_NORMS; 521 - break; 522 - case 3: 523 - vi->type = V4L2_INPUT_TYPE_CAMERA; 524 - strscpy(vi->name, "Red Video Input", sizeof(vi->name)); 525 - vi->std = USBVISION_NORMS; 526 - break; 527 - } 528 - return 0; 529 - } 530 - 531 - static int vidioc_g_input(struct file *file, void *priv, unsigned int *input) 532 - { 533 - struct usb_usbvision *usbvision = video_drvdata(file); 534 - 535 - *input = usbvision->ctl_input; 536 - return 0; 537 - } 538 - 539 - static int vidioc_s_input(struct file *file, void *priv, unsigned int input) 540 - { 541 - struct usb_usbvision *usbvision = video_drvdata(file); 542 - 543 - if (input >= usbvision->video_inputs) 544 - return -EINVAL; 545 - 546 - usbvision_muxsel(usbvision, input); 547 - usbvision_set_input(usbvision); 548 - usbvision_set_output(usbvision, 549 - usbvision->curwidth, 550 - usbvision->curheight); 551 - return 0; 552 - } 553 - 554 - static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id) 555 - { 556 - struct usb_usbvision *usbvision = video_drvdata(file); 557 - 558 - usbvision->tvnorm_id = id; 559 - 560 - call_all(usbvision, video, s_std, usbvision->tvnorm_id); 561 - /* propagate the change to the decoder */ 562 - usbvision_muxsel(usbvision, usbvision->ctl_input); 563 - 564 - return 0; 565 - } 566 - 567 - static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id) 568 - { 569 - struct usb_usbvision *usbvision = video_drvdata(file); 570 - 571 - *id = usbvision->tvnorm_id; 572 - return 0; 573 - } 574 - 575 - static int vidioc_g_tuner(struct file *file, void *priv, 576 - struct v4l2_tuner *vt) 577 - { 578 - struct usb_usbvision *usbvision = video_drvdata(file); 579 - 580 - if (vt->index) /* Only tuner 0 */ 581 - return -EINVAL; 582 - if (vt->type == V4L2_TUNER_RADIO) 583 - strscpy(vt->name, "Radio", sizeof(vt->name)); 584 - else 585 - strscpy(vt->name, "Television", sizeof(vt->name)); 586 - 587 - /* Let clients fill in the remainder of this struct */ 588 - call_all(usbvision, tuner, g_tuner, vt); 589 - 590 - return 0; 591 - } 592 - 593 - static int vidioc_s_tuner(struct file *file, void *priv, 594 - const struct v4l2_tuner *vt) 595 - { 596 - struct usb_usbvision *usbvision = video_drvdata(file); 597 - 598 - /* Only one tuner for now */ 599 - if (vt->index) 600 - return -EINVAL; 601 - /* let clients handle this */ 602 - call_all(usbvision, tuner, s_tuner, vt); 603 - 604 - return 0; 605 - } 606 - 607 - static int vidioc_g_frequency(struct file *file, void *priv, 608 - struct v4l2_frequency *freq) 609 - { 610 - struct usb_usbvision *usbvision = video_drvdata(file); 611 - 612 - /* Only one tuner */ 613 - if (freq->tuner) 614 - return -EINVAL; 615 - if (freq->type == V4L2_TUNER_RADIO) 616 - freq->frequency = usbvision->radio_freq; 617 - else 618 - freq->frequency = usbvision->tv_freq; 619 - 620 - return 0; 621 - } 622 - 623 - static int vidioc_s_frequency(struct file *file, void *priv, 624 - const struct v4l2_frequency *freq) 625 - { 626 - struct usb_usbvision *usbvision = video_drvdata(file); 627 - struct v4l2_frequency new_freq = *freq; 628 - 629 - /* Only one tuner for now */ 630 - if (freq->tuner) 631 - return -EINVAL; 632 - 633 - call_all(usbvision, tuner, s_frequency, freq); 634 - call_all(usbvision, tuner, g_frequency, &new_freq); 635 - if (freq->type == V4L2_TUNER_RADIO) 636 - usbvision->radio_freq = new_freq.frequency; 637 - else 638 - usbvision->tv_freq = new_freq.frequency; 639 - 640 - return 0; 641 - } 642 - 643 - static int vidioc_reqbufs(struct file *file, 644 - void *priv, struct v4l2_requestbuffers *vr) 645 - { 646 - struct usb_usbvision *usbvision = video_drvdata(file); 647 - int ret; 648 - 649 - RESTRICT_TO_RANGE(vr->count, 1, USBVISION_NUMFRAMES); 650 - 651 - /* Check input validity: 652 - the user must do a VIDEO CAPTURE and MMAP method. */ 653 - if (vr->memory != V4L2_MEMORY_MMAP) 654 - return -EINVAL; 655 - 656 - if (usbvision->streaming == stream_on) { 657 - ret = usbvision_stream_interrupt(usbvision); 658 - if (ret) 659 - return ret; 660 - } 661 - 662 - usbvision_frames_free(usbvision); 663 - usbvision_empty_framequeues(usbvision); 664 - vr->count = usbvision_frames_alloc(usbvision, vr->count); 665 - 666 - usbvision->cur_frame = NULL; 667 - 668 - return 0; 669 - } 670 - 671 - static int vidioc_querybuf(struct file *file, 672 - void *priv, struct v4l2_buffer *vb) 673 - { 674 - struct usb_usbvision *usbvision = video_drvdata(file); 675 - struct usbvision_frame *frame; 676 - 677 - /* FIXME : must control 678 - that buffers are mapped (VIDIOC_REQBUFS has been called) */ 679 - if (vb->index >= usbvision->num_frames) 680 - return -EINVAL; 681 - /* Updating the corresponding frame state */ 682 - vb->flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 683 - frame = &usbvision->frame[vb->index]; 684 - if (frame->grabstate >= frame_state_ready) 685 - vb->flags |= V4L2_BUF_FLAG_QUEUED; 686 - if (frame->grabstate >= frame_state_done) 687 - vb->flags |= V4L2_BUF_FLAG_DONE; 688 - if (frame->grabstate == frame_state_unused) 689 - vb->flags |= V4L2_BUF_FLAG_MAPPED; 690 - vb->memory = V4L2_MEMORY_MMAP; 691 - 692 - vb->m.offset = vb->index * PAGE_ALIGN(usbvision->max_frame_size); 693 - 694 - vb->memory = V4L2_MEMORY_MMAP; 695 - vb->field = V4L2_FIELD_NONE; 696 - vb->length = usbvision->curwidth * 697 - usbvision->curheight * 698 - usbvision->palette.bytes_per_pixel; 699 - v4l2_buffer_set_timestamp(vb, usbvision->frame[vb->index].ts); 700 - vb->sequence = usbvision->frame[vb->index].sequence; 701 - return 0; 702 - } 703 - 704 - static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *vb) 705 - { 706 - struct usb_usbvision *usbvision = video_drvdata(file); 707 - struct usbvision_frame *frame; 708 - unsigned long lock_flags; 709 - 710 - /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */ 711 - if (vb->index >= usbvision->num_frames) 712 - return -EINVAL; 713 - 714 - frame = &usbvision->frame[vb->index]; 715 - 716 - if (frame->grabstate != frame_state_unused) 717 - return -EAGAIN; 718 - 719 - /* Mark it as ready and enqueue frame */ 720 - frame->grabstate = frame_state_ready; 721 - frame->scanstate = scan_state_scanning; 722 - frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */ 723 - 724 - vb->flags &= ~V4L2_BUF_FLAG_DONE; 725 - 726 - /* set v4l2_format index */ 727 - frame->v4l2_format = usbvision->palette; 728 - 729 - spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 730 - list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue); 731 - spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 732 - 733 - return 0; 734 - } 735 - 736 - static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb) 737 - { 738 - struct usb_usbvision *usbvision = video_drvdata(file); 739 - int ret; 740 - struct usbvision_frame *f; 741 - unsigned long lock_flags; 742 - 743 - if (list_empty(&(usbvision->outqueue))) { 744 - if (usbvision->streaming == stream_idle) 745 - return -EINVAL; 746 - ret = wait_event_interruptible 747 - (usbvision->wait_frame, 748 - !list_empty(&(usbvision->outqueue))); 749 - if (ret) 750 - return ret; 751 - } 752 - 753 - spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 754 - f = list_entry(usbvision->outqueue.next, 755 - struct usbvision_frame, frame); 756 - list_del(usbvision->outqueue.next); 757 - spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 758 - 759 - f->grabstate = frame_state_unused; 760 - 761 - vb->memory = V4L2_MEMORY_MMAP; 762 - vb->flags = V4L2_BUF_FLAG_MAPPED | 763 - V4L2_BUF_FLAG_QUEUED | 764 - V4L2_BUF_FLAG_DONE | 765 - V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 766 - vb->index = f->index; 767 - vb->sequence = f->sequence; 768 - v4l2_buffer_set_timestamp(vb, f->ts); 769 - vb->field = V4L2_FIELD_NONE; 770 - vb->bytesused = f->scanlength; 771 - 772 - return 0; 773 - } 774 - 775 - static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 776 - { 777 - struct usb_usbvision *usbvision = video_drvdata(file); 778 - 779 - usbvision->streaming = stream_on; 780 - call_all(usbvision, video, s_stream, 1); 781 - 782 - return 0; 783 - } 784 - 785 - static int vidioc_streamoff(struct file *file, 786 - void *priv, enum v4l2_buf_type type) 787 - { 788 - struct usb_usbvision *usbvision = video_drvdata(file); 789 - 790 - if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 791 - return -EINVAL; 792 - 793 - if (usbvision->streaming == stream_on) { 794 - usbvision_stream_interrupt(usbvision); 795 - /* Stop all video streamings */ 796 - call_all(usbvision, video, s_stream, 0); 797 - } 798 - usbvision_empty_framequeues(usbvision); 799 - 800 - return 0; 801 - } 802 - 803 - static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 804 - struct v4l2_fmtdesc *vfd) 805 - { 806 - if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1) 807 - return -EINVAL; 808 - vfd->pixelformat = usbvision_v4l2_format[vfd->index].format; 809 - return 0; 810 - } 811 - 812 - static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 813 - struct v4l2_format *vf) 814 - { 815 - struct usb_usbvision *usbvision = video_drvdata(file); 816 - vf->fmt.pix.width = usbvision->curwidth; 817 - vf->fmt.pix.height = usbvision->curheight; 818 - vf->fmt.pix.pixelformat = usbvision->palette.format; 819 - vf->fmt.pix.bytesperline = 820 - usbvision->curwidth * usbvision->palette.bytes_per_pixel; 821 - vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline * usbvision->curheight; 822 - vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 823 - vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ 824 - 825 - return 0; 826 - } 827 - 828 - static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 829 - struct v4l2_format *vf) 830 - { 831 - struct usb_usbvision *usbvision = video_drvdata(file); 832 - int format_idx; 833 - 834 - /* Find requested format in available ones */ 835 - for (format_idx = 0; format_idx < USBVISION_SUPPORTED_PALETTES; format_idx++) { 836 - if (vf->fmt.pix.pixelformat == 837 - usbvision_v4l2_format[format_idx].format) { 838 - usbvision->palette = usbvision_v4l2_format[format_idx]; 839 - break; 840 - } 841 - } 842 - /* robustness */ 843 - if (format_idx == USBVISION_SUPPORTED_PALETTES) 844 - return -EINVAL; 845 - RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH); 846 - RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); 847 - 848 - vf->fmt.pix.bytesperline = vf->fmt.pix.width* 849 - usbvision->palette.bytes_per_pixel; 850 - vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height; 851 - vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 852 - vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ 853 - 854 - return 0; 855 - } 856 - 857 - static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 858 - struct v4l2_format *vf) 859 - { 860 - struct usb_usbvision *usbvision = video_drvdata(file); 861 - int ret; 862 - 863 - ret = vidioc_try_fmt_vid_cap(file, priv, vf); 864 - if (ret) 865 - return ret; 866 - 867 - /* stop io in case it is already in progress */ 868 - if (usbvision->streaming == stream_on) { 869 - ret = usbvision_stream_interrupt(usbvision); 870 - if (ret) 871 - return ret; 872 - } 873 - usbvision_frames_free(usbvision); 874 - usbvision_empty_framequeues(usbvision); 875 - 876 - usbvision->cur_frame = NULL; 877 - 878 - /* by now we are committed to the new data... */ 879 - usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height); 880 - 881 - return 0; 882 - } 883 - 884 - static ssize_t usbvision_read(struct file *file, char __user *buf, 885 - size_t count, loff_t *ppos) 886 - { 887 - struct usb_usbvision *usbvision = video_drvdata(file); 888 - int noblock = file->f_flags & O_NONBLOCK; 889 - unsigned long lock_flags; 890 - int ret, i; 891 - struct usbvision_frame *frame; 892 - 893 - PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__, 894 - (unsigned long)count, noblock); 895 - 896 - if (!USBVISION_IS_OPERATIONAL(usbvision) || !buf) 897 - return -EFAULT; 898 - 899 - /* This entry point is compatible with the mmap routines 900 - so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF 901 - to get frames or call read on the device. */ 902 - if (!usbvision->num_frames) { 903 - /* First, allocate some frames to work with 904 - if this has not been done with VIDIOC_REQBUF */ 905 - usbvision_frames_free(usbvision); 906 - usbvision_empty_framequeues(usbvision); 907 - usbvision_frames_alloc(usbvision, USBVISION_NUMFRAMES); 908 - } 909 - 910 - if (usbvision->streaming != stream_on) { 911 - /* no stream is running, make it running ! */ 912 - usbvision->streaming = stream_on; 913 - call_all(usbvision, video, s_stream, 1); 914 - } 915 - 916 - /* Then, enqueue as many frames as possible 917 - (like a user of VIDIOC_QBUF would do) */ 918 - for (i = 0; i < usbvision->num_frames; i++) { 919 - frame = &usbvision->frame[i]; 920 - if (frame->grabstate == frame_state_unused) { 921 - /* Mark it as ready and enqueue frame */ 922 - frame->grabstate = frame_state_ready; 923 - frame->scanstate = scan_state_scanning; 924 - /* Accumulated in usbvision_parse_data() */ 925 - frame->scanlength = 0; 926 - 927 - /* set v4l2_format index */ 928 - frame->v4l2_format = usbvision->palette; 929 - 930 - spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 931 - list_add_tail(&frame->frame, &usbvision->inqueue); 932 - spin_unlock_irqrestore(&usbvision->queue_lock, 933 - lock_flags); 934 - } 935 - } 936 - 937 - /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */ 938 - if (list_empty(&(usbvision->outqueue))) { 939 - if (noblock) 940 - return -EAGAIN; 941 - 942 - ret = wait_event_interruptible 943 - (usbvision->wait_frame, 944 - !list_empty(&(usbvision->outqueue))); 945 - if (ret) 946 - return ret; 947 - } 948 - 949 - spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 950 - frame = list_entry(usbvision->outqueue.next, 951 - struct usbvision_frame, frame); 952 - list_del(usbvision->outqueue.next); 953 - spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 954 - 955 - /* An error returns an empty frame */ 956 - if (frame->grabstate == frame_state_error) { 957 - frame->bytes_read = 0; 958 - return 0; 959 - } 960 - 961 - PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", 962 - __func__, 963 - frame->index, frame->bytes_read, frame->scanlength); 964 - 965 - /* copy bytes to user space; we allow for partials reads */ 966 - if ((count + frame->bytes_read) > (unsigned long)frame->scanlength) 967 - count = frame->scanlength - frame->bytes_read; 968 - 969 - if (copy_to_user(buf, frame->data + frame->bytes_read, count)) 970 - return -EFAULT; 971 - 972 - frame->bytes_read += count; 973 - PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", 974 - __func__, 975 - (unsigned long)count, frame->bytes_read); 976 - 977 - /* 978 - * FIXME: 979 - * For now, forget the frame if it has not been read in one shot. 980 - */ 981 - frame->bytes_read = 0; 982 - 983 - /* Mark it as available to be used again. */ 984 - frame->grabstate = frame_state_unused; 985 - 986 - return count; 987 - } 988 - 989 - static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf, 990 - size_t count, loff_t *ppos) 991 - { 992 - struct usb_usbvision *usbvision = video_drvdata(file); 993 - int res; 994 - 995 - if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 996 - return -ERESTARTSYS; 997 - res = usbvision_read(file, buf, count, ppos); 998 - mutex_unlock(&usbvision->v4l2_lock); 999 - return res; 1000 - } 1001 - 1002 - static int usbvision_mmap(struct file *file, struct vm_area_struct *vma) 1003 - { 1004 - unsigned long size = vma->vm_end - vma->vm_start, 1005 - start = vma->vm_start; 1006 - void *pos; 1007 - u32 i; 1008 - struct usb_usbvision *usbvision = video_drvdata(file); 1009 - 1010 - PDEBUG(DBG_MMAP, "mmap"); 1011 - 1012 - if (!USBVISION_IS_OPERATIONAL(usbvision)) 1013 - return -EFAULT; 1014 - 1015 - if (!(vma->vm_flags & VM_WRITE) || 1016 - size != PAGE_ALIGN(usbvision->max_frame_size)) { 1017 - return -EINVAL; 1018 - } 1019 - 1020 - for (i = 0; i < usbvision->num_frames; i++) { 1021 - if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) == 1022 - vma->vm_pgoff) 1023 - break; 1024 - } 1025 - if (i == usbvision->num_frames) { 1026 - PDEBUG(DBG_MMAP, 1027 - "mmap: user supplied mapping address is out of range"); 1028 - return -EINVAL; 1029 - } 1030 - 1031 - /* VM_IO is eventually going to replace PageReserved altogether */ 1032 - vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; 1033 - 1034 - pos = usbvision->frame[i].data; 1035 - while (size > 0) { 1036 - if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 1037 - PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed"); 1038 - return -EAGAIN; 1039 - } 1040 - start += PAGE_SIZE; 1041 - pos += PAGE_SIZE; 1042 - size -= PAGE_SIZE; 1043 - } 1044 - 1045 - return 0; 1046 - } 1047 - 1048 - static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 1049 - { 1050 - struct usb_usbvision *usbvision = video_drvdata(file); 1051 - int res; 1052 - 1053 - if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 1054 - return -ERESTARTSYS; 1055 - res = usbvision_mmap(file, vma); 1056 - mutex_unlock(&usbvision->v4l2_lock); 1057 - return res; 1058 - } 1059 - 1060 - /* 1061 - * Here comes the stuff for radio on usbvision based devices 1062 - * 1063 - */ 1064 - static int usbvision_radio_open(struct file *file) 1065 - { 1066 - struct usb_usbvision *usbvision = video_drvdata(file); 1067 - int err_code = 0; 1068 - 1069 - PDEBUG(DBG_IO, "%s:", __func__); 1070 - 1071 - if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 1072 - return -ERESTARTSYS; 1073 - 1074 - if (usbvision->remove_pending) { 1075 - err_code = -ENODEV; 1076 - goto out; 1077 - } 1078 - err_code = v4l2_fh_open(file); 1079 - if (err_code) 1080 - goto out; 1081 - if (usbvision->user) { 1082 - dev_err(&usbvision->rdev.dev, 1083 - "%s: Someone tried to open an already opened USBVision Radio!\n", 1084 - __func__); 1085 - err_code = -EBUSY; 1086 - } else { 1087 - /* Alternate interface 1 is is the biggest frame size */ 1088 - err_code = usbvision_set_alternate(usbvision); 1089 - if (err_code < 0) { 1090 - usbvision->last_error = err_code; 1091 - err_code = -EBUSY; 1092 - goto out; 1093 - } 1094 - 1095 - /* If so far no errors then we shall start the radio */ 1096 - usbvision->radio = 1; 1097 - call_all(usbvision, tuner, s_radio); 1098 - usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO); 1099 - usbvision->user++; 1100 - } 1101 - out: 1102 - mutex_unlock(&usbvision->v4l2_lock); 1103 - return err_code; 1104 - } 1105 - 1106 - 1107 - static int usbvision_radio_close(struct file *file) 1108 - { 1109 - struct usb_usbvision *usbvision = video_drvdata(file); 1110 - int r; 1111 - 1112 - PDEBUG(DBG_IO, ""); 1113 - 1114 - mutex_lock(&usbvision->v4l2_lock); 1115 - /* Set packet size to 0 */ 1116 - usbvision->iface_alt = 0; 1117 - if (usbvision->dev) 1118 - usb_set_interface(usbvision->dev, usbvision->iface, 1119 - usbvision->iface_alt); 1120 - 1121 - usbvision_audio_off(usbvision); 1122 - usbvision->radio = 0; 1123 - usbvision->user--; 1124 - r = usbvision->remove_pending; 1125 - mutex_unlock(&usbvision->v4l2_lock); 1126 - 1127 - if (r) { 1128 - printk(KERN_INFO "%s: Final disconnect\n", __func__); 1129 - v4l2_fh_release(file); 1130 - usbvision_release(usbvision); 1131 - return 0; 1132 - } 1133 - 1134 - PDEBUG(DBG_IO, "success"); 1135 - return v4l2_fh_release(file); 1136 - } 1137 - 1138 - /* Video registration stuff */ 1139 - 1140 - /* Video template */ 1141 - static const struct v4l2_file_operations usbvision_fops = { 1142 - .owner = THIS_MODULE, 1143 - .open = usbvision_v4l2_open, 1144 - .release = usbvision_v4l2_close, 1145 - .read = usbvision_v4l2_read, 1146 - .mmap = usbvision_v4l2_mmap, 1147 - .unlocked_ioctl = video_ioctl2, 1148 - }; 1149 - 1150 - static const struct v4l2_ioctl_ops usbvision_ioctl_ops = { 1151 - .vidioc_querycap = vidioc_querycap, 1152 - .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1153 - .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1154 - .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1155 - .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1156 - .vidioc_reqbufs = vidioc_reqbufs, 1157 - .vidioc_querybuf = vidioc_querybuf, 1158 - .vidioc_qbuf = vidioc_qbuf, 1159 - .vidioc_dqbuf = vidioc_dqbuf, 1160 - .vidioc_s_std = vidioc_s_std, 1161 - .vidioc_g_std = vidioc_g_std, 1162 - .vidioc_enum_input = vidioc_enum_input, 1163 - .vidioc_g_input = vidioc_g_input, 1164 - .vidioc_s_input = vidioc_s_input, 1165 - .vidioc_streamon = vidioc_streamon, 1166 - .vidioc_streamoff = vidioc_streamoff, 1167 - .vidioc_g_tuner = vidioc_g_tuner, 1168 - .vidioc_s_tuner = vidioc_s_tuner, 1169 - .vidioc_g_frequency = vidioc_g_frequency, 1170 - .vidioc_s_frequency = vidioc_s_frequency, 1171 - .vidioc_log_status = v4l2_ctrl_log_status, 1172 - .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1173 - .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1174 - #ifdef CONFIG_VIDEO_ADV_DEBUG 1175 - .vidioc_g_register = vidioc_g_register, 1176 - .vidioc_s_register = vidioc_s_register, 1177 - #endif 1178 - }; 1179 - 1180 - static struct video_device usbvision_video_template = { 1181 - .fops = &usbvision_fops, 1182 - .ioctl_ops = &usbvision_ioctl_ops, 1183 - .name = "usbvision-video", 1184 - .release = video_device_release_empty, 1185 - .tvnorms = USBVISION_NORMS, 1186 - }; 1187 - 1188 - 1189 - /* Radio template */ 1190 - static const struct v4l2_file_operations usbvision_radio_fops = { 1191 - .owner = THIS_MODULE, 1192 - .open = usbvision_radio_open, 1193 - .release = usbvision_radio_close, 1194 - .poll = v4l2_ctrl_poll, 1195 - .unlocked_ioctl = video_ioctl2, 1196 - }; 1197 - 1198 - static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = { 1199 - .vidioc_querycap = vidioc_querycap, 1200 - .vidioc_g_tuner = vidioc_g_tuner, 1201 - .vidioc_s_tuner = vidioc_s_tuner, 1202 - .vidioc_g_frequency = vidioc_g_frequency, 1203 - .vidioc_s_frequency = vidioc_s_frequency, 1204 - .vidioc_log_status = v4l2_ctrl_log_status, 1205 - .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1206 - .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1207 - }; 1208 - 1209 - static struct video_device usbvision_radio_template = { 1210 - .fops = &usbvision_radio_fops, 1211 - .name = "usbvision-radio", 1212 - .release = video_device_release_empty, 1213 - .ioctl_ops = &usbvision_radio_ioctl_ops, 1214 - }; 1215 - 1216 - 1217 - static void usbvision_vdev_init(struct usb_usbvision *usbvision, 1218 - struct video_device *vdev, 1219 - const struct video_device *vdev_template, 1220 - const char *name) 1221 - { 1222 - struct usb_device *usb_dev = usbvision->dev; 1223 - 1224 - if (!usb_dev) { 1225 - dev_err(&usbvision->dev->dev, 1226 - "%s: usbvision->dev is not set\n", __func__); 1227 - return; 1228 - } 1229 - 1230 - *vdev = *vdev_template; 1231 - vdev->lock = &usbvision->v4l2_lock; 1232 - vdev->v4l2_dev = &usbvision->v4l2_dev; 1233 - snprintf(vdev->name, sizeof(vdev->name), "%s", name); 1234 - video_set_drvdata(vdev, usbvision); 1235 - } 1236 - 1237 - /* unregister video4linux devices */ 1238 - static void usbvision_unregister_video(struct usb_usbvision *usbvision) 1239 - { 1240 - /* Radio Device: */ 1241 - if (video_is_registered(&usbvision->rdev)) { 1242 - PDEBUG(DBG_PROBE, "unregister %s [v4l2]", 1243 - video_device_node_name(&usbvision->rdev)); 1244 - video_unregister_device(&usbvision->rdev); 1245 - } 1246 - 1247 - /* Video Device: */ 1248 - if (video_is_registered(&usbvision->vdev)) { 1249 - PDEBUG(DBG_PROBE, "unregister %s [v4l2]", 1250 - video_device_node_name(&usbvision->vdev)); 1251 - video_unregister_device(&usbvision->vdev); 1252 - } 1253 - } 1254 - 1255 - /* register video4linux devices */ 1256 - static int usbvision_register_video(struct usb_usbvision *usbvision) 1257 - { 1258 - int res = -ENOMEM; 1259 - 1260 - /* Video Device: */ 1261 - usbvision_vdev_init(usbvision, &usbvision->vdev, 1262 - &usbvision_video_template, "USBVision Video"); 1263 - if (!usbvision->have_tuner) { 1264 - v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY); 1265 - v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER); 1266 - v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY); 1267 - v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER); 1268 - } 1269 - usbvision->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | 1270 - V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 1271 - if (usbvision->have_tuner) 1272 - usbvision->vdev.device_caps |= V4L2_CAP_TUNER; 1273 - 1274 - if (video_register_device(&usbvision->vdev, VFL_TYPE_VIDEO, video_nr) < 0) 1275 - goto err_exit; 1276 - printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", 1277 - usbvision->nr, video_device_node_name(&usbvision->vdev)); 1278 - 1279 - /* Radio Device: */ 1280 - if (usbvision_device_data[usbvision->dev_model].radio) { 1281 - /* usbvision has radio */ 1282 - usbvision_vdev_init(usbvision, &usbvision->rdev, 1283 - &usbvision_radio_template, "USBVision Radio"); 1284 - usbvision->rdev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER; 1285 - if (video_register_device(&usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0) 1286 - goto err_exit; 1287 - printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", 1288 - usbvision->nr, video_device_node_name(&usbvision->rdev)); 1289 - } 1290 - /* all done */ 1291 - return 0; 1292 - 1293 - err_exit: 1294 - dev_err(&usbvision->dev->dev, 1295 - "USBVision[%d]: video_register_device() failed\n", 1296 - usbvision->nr); 1297 - usbvision_unregister_video(usbvision); 1298 - return res; 1299 - } 1300 - 1301 - /* 1302 - * usbvision_alloc() 1303 - * 1304 - * This code allocates the struct usb_usbvision. 1305 - * It is filled with default values. 1306 - * 1307 - * Returns NULL on error, a pointer to usb_usbvision else. 1308 - * 1309 - */ 1310 - static struct usb_usbvision *usbvision_alloc(struct usb_device *dev, 1311 - struct usb_interface *intf) 1312 - { 1313 - struct usb_usbvision *usbvision; 1314 - 1315 - usbvision = kzalloc(sizeof(*usbvision), GFP_KERNEL); 1316 - if (!usbvision) 1317 - return NULL; 1318 - 1319 - usbvision->dev = dev; 1320 - if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev)) 1321 - goto err_free; 1322 - 1323 - if (v4l2_ctrl_handler_init(&usbvision->hdl, 4)) 1324 - goto err_unreg; 1325 - usbvision->v4l2_dev.ctrl_handler = &usbvision->hdl; 1326 - mutex_init(&usbvision->v4l2_lock); 1327 - 1328 - /* prepare control urb for control messages during interrupts */ 1329 - usbvision->ctrl_urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 1330 - if (!usbvision->ctrl_urb) 1331 - goto err_unreg; 1332 - 1333 - return usbvision; 1334 - 1335 - err_unreg: 1336 - v4l2_ctrl_handler_free(&usbvision->hdl); 1337 - v4l2_device_unregister(&usbvision->v4l2_dev); 1338 - err_free: 1339 - kfree(usbvision); 1340 - return NULL; 1341 - } 1342 - 1343 - /* 1344 - * usbvision_release() 1345 - * 1346 - * This code does final release of struct usb_usbvision. This happens 1347 - * after the device is disconnected -and- all clients closed their files. 1348 - * 1349 - */ 1350 - static void usbvision_release(struct usb_usbvision *usbvision) 1351 - { 1352 - PDEBUG(DBG_PROBE, ""); 1353 - 1354 - usbvision->initialized = 0; 1355 - 1356 - usbvision_remove_sysfs(&usbvision->vdev); 1357 - usbvision_unregister_video(usbvision); 1358 - kfree(usbvision->alt_max_pkt_size); 1359 - 1360 - usb_free_urb(usbvision->ctrl_urb); 1361 - 1362 - v4l2_ctrl_handler_free(&usbvision->hdl); 1363 - v4l2_device_unregister(&usbvision->v4l2_dev); 1364 - kfree(usbvision); 1365 - 1366 - PDEBUG(DBG_PROBE, "success"); 1367 - } 1368 - 1369 - 1370 - /*********************** usb interface **********************************/ 1371 - 1372 - static void usbvision_configure_video(struct usb_usbvision *usbvision) 1373 - { 1374 - int model; 1375 - 1376 - if (!usbvision) 1377 - return; 1378 - 1379 - model = usbvision->dev_model; 1380 - usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */ 1381 - 1382 - if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) { 1383 - usbvision->vin_reg2_preset = 1384 - usbvision_device_data[usbvision->dev_model].vin_reg2; 1385 - } else { 1386 - usbvision->vin_reg2_preset = 0; 1387 - } 1388 - 1389 - usbvision->tvnorm_id = usbvision_device_data[model].video_norm; 1390 - usbvision->video_inputs = usbvision_device_data[model].video_channels; 1391 - usbvision->ctl_input = 0; 1392 - usbvision->radio_freq = 87.5 * 16000; 1393 - usbvision->tv_freq = 400 * 16; 1394 - 1395 - /* This should be here to make i2c clients to be able to register */ 1396 - /* first switch off audio */ 1397 - if (usbvision_device_data[model].audio_channels > 0) 1398 - usbvision_audio_off(usbvision); 1399 - /* and then power up the tuner */ 1400 - usbvision_power_on(usbvision); 1401 - usbvision_i2c_register(usbvision); 1402 - } 1403 - 1404 - /* 1405 - * usbvision_probe() 1406 - * 1407 - * This procedure queries device descriptor and accepts the interface 1408 - * if it looks like USBVISION video device 1409 - * 1410 - */ 1411 - static int usbvision_probe(struct usb_interface *intf, 1412 - const struct usb_device_id *devid) 1413 - { 1414 - struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf)); 1415 - struct usb_interface *uif; 1416 - __u8 ifnum = intf->altsetting->desc.bInterfaceNumber; 1417 - const struct usb_host_interface *interface; 1418 - struct usb_usbvision *usbvision = NULL; 1419 - const struct usb_endpoint_descriptor *endpoint; 1420 - int model, i, ret; 1421 - 1422 - PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u", 1423 - le16_to_cpu(dev->descriptor.idVendor), 1424 - le16_to_cpu(dev->descriptor.idProduct), ifnum); 1425 - 1426 - model = devid->driver_info; 1427 - if (model < 0 || model >= usbvision_device_data_size) { 1428 - PDEBUG(DBG_PROBE, "model out of bounds %d", model); 1429 - ret = -ENODEV; 1430 - goto err_usb; 1431 - } 1432 - printk(KERN_INFO "%s: %s found\n", __func__, 1433 - usbvision_device_data[model].model_string); 1434 - 1435 - if (usbvision_device_data[model].interface >= 0) 1436 - interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0]; 1437 - else if (ifnum < dev->actconfig->desc.bNumInterfaces) 1438 - interface = &dev->actconfig->interface[ifnum]->altsetting[0]; 1439 - else { 1440 - dev_err(&intf->dev, "interface %d is invalid, max is %d\n", 1441 - ifnum, dev->actconfig->desc.bNumInterfaces - 1); 1442 - ret = -ENODEV; 1443 - goto err_usb; 1444 - } 1445 - 1446 - if (interface->desc.bNumEndpoints < 2) { 1447 - dev_err(&intf->dev, "interface %d has %d endpoints, but must have minimum 2\n", 1448 - ifnum, interface->desc.bNumEndpoints); 1449 - ret = -ENODEV; 1450 - goto err_usb; 1451 - } 1452 - endpoint = &interface->endpoint[1].desc; 1453 - 1454 - if (!usb_endpoint_xfer_isoc(endpoint)) { 1455 - dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n", 1456 - __func__, ifnum); 1457 - dev_err(&intf->dev, "%s: Endpoint attributes %d", 1458 - __func__, endpoint->bmAttributes); 1459 - ret = -ENODEV; 1460 - goto err_usb; 1461 - } 1462 - if (usb_endpoint_dir_out(endpoint)) { 1463 - dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n", 1464 - __func__, ifnum); 1465 - ret = -ENODEV; 1466 - goto err_usb; 1467 - } 1468 - 1469 - usbvision = usbvision_alloc(dev, intf); 1470 - if (!usbvision) { 1471 - dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__); 1472 - ret = -ENOMEM; 1473 - goto err_usb; 1474 - } 1475 - 1476 - if (dev->descriptor.bNumConfigurations > 1) 1477 - usbvision->bridge_type = BRIDGE_NT1004; 1478 - else if (model == DAZZLE_DVC_90_REV_1_SECAM) 1479 - usbvision->bridge_type = BRIDGE_NT1005; 1480 - else 1481 - usbvision->bridge_type = BRIDGE_NT1003; 1482 - PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type); 1483 - 1484 - /* compute alternate max packet sizes */ 1485 - uif = dev->actconfig->interface[0]; 1486 - 1487 - usbvision->num_alt = uif->num_altsetting; 1488 - PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt); 1489 - usbvision->alt_max_pkt_size = kmalloc_array(32, usbvision->num_alt, 1490 - GFP_KERNEL); 1491 - if (!usbvision->alt_max_pkt_size) { 1492 - ret = -ENOMEM; 1493 - goto err_pkt; 1494 - } 1495 - 1496 - for (i = 0; i < usbvision->num_alt; i++) { 1497 - u16 tmp; 1498 - 1499 - if (uif->altsetting[i].desc.bNumEndpoints < 2) { 1500 - ret = -ENODEV; 1501 - goto err_pkt; 1502 - } 1503 - 1504 - tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc. 1505 - wMaxPacketSize); 1506 - usbvision->alt_max_pkt_size[i] = 1507 - (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 1508 - PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i", i, 1509 - usbvision->alt_max_pkt_size[i]); 1510 - } 1511 - 1512 - 1513 - usbvision->nr = usbvision_nr++; 1514 - 1515 - spin_lock_init(&usbvision->queue_lock); 1516 - init_waitqueue_head(&usbvision->wait_frame); 1517 - init_waitqueue_head(&usbvision->wait_stream); 1518 - 1519 - usbvision->have_tuner = usbvision_device_data[model].tuner; 1520 - if (usbvision->have_tuner) 1521 - usbvision->tuner_type = usbvision_device_data[model].tuner_type; 1522 - 1523 - usbvision->dev_model = model; 1524 - usbvision->remove_pending = 0; 1525 - usbvision->iface = ifnum; 1526 - usbvision->iface_alt = 0; 1527 - usbvision->video_endp = endpoint->bEndpointAddress; 1528 - usbvision->isoc_packet_size = 0; 1529 - usbvision->usb_bandwidth = 0; 1530 - usbvision->user = 0; 1531 - usbvision->streaming = stream_off; 1532 - usbvision_configure_video(usbvision); 1533 - usbvision_register_video(usbvision); 1534 - 1535 - usbvision_create_sysfs(&usbvision->vdev); 1536 - 1537 - PDEBUG(DBG_PROBE, "success"); 1538 - return 0; 1539 - 1540 - err_pkt: 1541 - usbvision_release(usbvision); 1542 - err_usb: 1543 - usb_put_dev(dev); 1544 - return ret; 1545 - } 1546 - 1547 - 1548 - /* 1549 - * usbvision_disconnect() 1550 - * 1551 - * This procedure stops all driver activity, deallocates interface-private 1552 - * structure (pointed by 'ptr') and after that driver should be removable 1553 - * with no ill consequences. 1554 - * 1555 - */ 1556 - static void usbvision_disconnect(struct usb_interface *intf) 1557 - { 1558 - struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf)); 1559 - int u; 1560 - 1561 - PDEBUG(DBG_PROBE, ""); 1562 - 1563 - if (!usbvision) { 1564 - pr_err("%s: usb_get_intfdata() failed\n", __func__); 1565 - return; 1566 - } 1567 - 1568 - mutex_lock(&usbvision->v4l2_lock); 1569 - 1570 - /* At this time we ask to cancel outstanding URBs */ 1571 - usbvision_stop_isoc(usbvision); 1572 - 1573 - v4l2_device_disconnect(&usbvision->v4l2_dev); 1574 - usbvision_i2c_unregister(usbvision); 1575 - usbvision->remove_pending = 1; /* Now all ISO data will be ignored */ 1576 - u = usbvision->user; 1577 - 1578 - usb_put_dev(usbvision->dev); 1579 - usbvision->dev = NULL; /* USB device is no more */ 1580 - 1581 - mutex_unlock(&usbvision->v4l2_lock); 1582 - 1583 - if (u) { 1584 - printk(KERN_INFO "%s: In use, disconnect pending\n", 1585 - __func__); 1586 - wake_up_interruptible(&usbvision->wait_frame); 1587 - wake_up_interruptible(&usbvision->wait_stream); 1588 - } else { 1589 - usbvision_release(usbvision); 1590 - } 1591 - 1592 - PDEBUG(DBG_PROBE, "success"); 1593 - } 1594 - 1595 - static struct usb_driver usbvision_driver = { 1596 - .name = "usbvision", 1597 - .id_table = usbvision_table, 1598 - .probe = usbvision_probe, 1599 - .disconnect = usbvision_disconnect, 1600 - }; 1601 - 1602 - /* 1603 - * usbvision_init() 1604 - * 1605 - * This code is run to initialize the driver. 1606 - * 1607 - */ 1608 - static int __init usbvision_init(void) 1609 - { 1610 - int err_code; 1611 - 1612 - PDEBUG(DBG_PROBE, ""); 1613 - 1614 - PDEBUG(DBG_IO, "IO debugging is enabled [video]"); 1615 - PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]"); 1616 - PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]"); 1617 - 1618 - /* disable planar mode support unless compression enabled */ 1619 - if (isoc_mode != ISOC_MODE_COMPRESS) { 1620 - /* FIXME : not the right way to set supported flag */ 1621 - usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */ 1622 - usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */ 1623 - } 1624 - 1625 - err_code = usb_register(&usbvision_driver); 1626 - 1627 - if (err_code == 0) { 1628 - printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n"); 1629 - PDEBUG(DBG_PROBE, "success"); 1630 - } 1631 - return err_code; 1632 - } 1633 - 1634 - static void __exit usbvision_exit(void) 1635 - { 1636 - PDEBUG(DBG_PROBE, ""); 1637 - 1638 - usb_deregister(&usbvision_driver); 1639 - PDEBUG(DBG_PROBE, "success"); 1640 - } 1641 - 1642 - module_init(usbvision_init); 1643 - module_exit(usbvision_exit);
-500
drivers/staging/media/usbvision/usbvision.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /* 3 - * USBVISION.H 4 - * usbvision header file 5 - * 6 - * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> 7 - * Dwaine Garden <dwainegarden@rogers.com> 8 - * 9 - * Report problems to v4l MailingList: linux-media@vger.kernel.org 10 - * 11 - * This module is part of usbvision driver project. 12 - * Updates to driver completed by Dwaine P. Garden 13 - * v4l2 conversion by Thierry Merle <thierry.merle@free.fr> 14 - */ 15 - 16 - 17 - #ifndef __LINUX_USBVISION_H 18 - #define __LINUX_USBVISION_H 19 - 20 - #include <linux/list.h> 21 - #include <linux/usb.h> 22 - #include <linux/i2c.h> 23 - #include <linux/mutex.h> 24 - #include <media/v4l2-device.h> 25 - #include <media/v4l2-ctrls.h> 26 - #include <media/tuner.h> 27 - #include <linux/videodev2.h> 28 - 29 - #define USBVISION_DEBUG /* Turn on debug messages */ 30 - 31 - #define USBVISION_PWR_REG 0x00 32 - #define USBVISION_SSPND_EN (1 << 1) 33 - #define USBVISION_RES2 (1 << 2) 34 - #define USBVISION_PWR_VID (1 << 5) 35 - #define USBVISION_E2_EN (1 << 7) 36 - #define USBVISION_CONFIG_REG 0x01 37 - #define USBVISION_ADRS_REG 0x02 38 - #define USBVISION_ALTER_REG 0x03 39 - #define USBVISION_FORCE_ALTER_REG 0x04 40 - #define USBVISION_STATUS_REG 0x05 41 - #define USBVISION_IOPIN_REG 0x06 42 - #define USBVISION_IO_1 (1 << 0) 43 - #define USBVISION_IO_2 (1 << 1) 44 - #define USBVISION_AUDIO_IN 0 45 - #define USBVISION_AUDIO_TV 1 46 - #define USBVISION_AUDIO_RADIO 2 47 - #define USBVISION_AUDIO_MUTE 3 48 - #define USBVISION_SER_MODE 0x07 49 - #define USBVISION_CLK_OUT (1 << 0) 50 - #define USBVISION_DAT_IO (1 << 1) 51 - #define USBVISION_SENS_OUT (1 << 2) 52 - #define USBVISION_SER_MODE_SOFT (0 << 4) 53 - #define USBVISION_SER_MODE_SIO (1 << 4) 54 - #define USBVISION_SER_ADRS 0x08 55 - #define USBVISION_SER_CONT 0x09 56 - #define USBVISION_SER_DAT1 0x0A 57 - #define USBVISION_SER_DAT2 0x0B 58 - #define USBVISION_SER_DAT3 0x0C 59 - #define USBVISION_SER_DAT4 0x0D 60 - #define USBVISION_EE_DATA 0x0E 61 - #define USBVISION_EE_LSBAD 0x0F 62 - #define USBVISION_EE_CONT 0x10 63 - #define USBVISION_DRM_CONT 0x12 64 - #define USBVISION_REF (1 << 0) 65 - #define USBVISION_RES_UR (1 << 2) 66 - #define USBVISION_RES_FDL (1 << 3) 67 - #define USBVISION_RES_VDW (1 << 4) 68 - #define USBVISION_DRM_PRM1 0x13 69 - #define USBVISION_DRM_PRM2 0x14 70 - #define USBVISION_DRM_PRM3 0x15 71 - #define USBVISION_DRM_PRM4 0x16 72 - #define USBVISION_DRM_PRM5 0x17 73 - #define USBVISION_DRM_PRM6 0x18 74 - #define USBVISION_DRM_PRM7 0x19 75 - #define USBVISION_DRM_PRM8 0x1A 76 - #define USBVISION_VIN_REG1 0x1B 77 - #define USBVISION_8_422_SYNC 0x01 78 - #define USBVISION_16_422_SYNC 0x02 79 - #define USBVISION_VSNC_POL (1 << 3) 80 - #define USBVISION_HSNC_POL (1 << 4) 81 - #define USBVISION_FID_POL (1 << 5) 82 - #define USBVISION_HVALID_PO (1 << 6) 83 - #define USBVISION_VCLK_POL (1 << 7) 84 - #define USBVISION_VIN_REG2 0x1C 85 - #define USBVISION_AUTO_FID (1 << 0) 86 - #define USBVISION_NONE_INTER (1 << 1) 87 - #define USBVISION_NOHVALID (1 << 2) 88 - #define USBVISION_UV_ID (1 << 3) 89 - #define USBVISION_FIX_2C (1 << 4) 90 - #define USBVISION_SEND_FID (1 << 5) 91 - #define USBVISION_KEEP_BLANK (1 << 7) 92 - #define USBVISION_LXSIZE_I 0x1D 93 - #define USBVISION_MXSIZE_I 0x1E 94 - #define USBVISION_LYSIZE_I 0x1F 95 - #define USBVISION_MYSIZE_I 0x20 96 - #define USBVISION_LX_OFFST 0x21 97 - #define USBVISION_MX_OFFST 0x22 98 - #define USBVISION_LY_OFFST 0x23 99 - #define USBVISION_MY_OFFST 0x24 100 - #define USBVISION_FRM_RATE 0x25 101 - #define USBVISION_LXSIZE_O 0x26 102 - #define USBVISION_MXSIZE_O 0x27 103 - #define USBVISION_LYSIZE_O 0x28 104 - #define USBVISION_MYSIZE_O 0x29 105 - #define USBVISION_FILT_CONT 0x2A 106 - #define USBVISION_VO_MODE 0x2B 107 - #define USBVISION_INTRA_CYC 0x2C 108 - #define USBVISION_STRIP_SZ 0x2D 109 - #define USBVISION_FORCE_INTRA 0x2E 110 - #define USBVISION_FORCE_UP 0x2F 111 - #define USBVISION_BUF_THR 0x30 112 - #define USBVISION_DVI_YUV 0x31 113 - #define USBVISION_AUDIO_CONT 0x32 114 - #define USBVISION_AUD_PK_LEN 0x33 115 - #define USBVISION_BLK_PK_LEN 0x34 116 - #define USBVISION_PCM_THR1 0x38 117 - #define USBVISION_PCM_THR2 0x39 118 - #define USBVISION_DIST_THR_L 0x3A 119 - #define USBVISION_DIST_THR_H 0x3B 120 - #define USBVISION_MAX_DIST_L 0x3C 121 - #define USBVISION_MAX_DIST_H 0x3D 122 - #define USBVISION_OP_CODE 0x33 123 - 124 - #define MAX_BYTES_PER_PIXEL 4 125 - 126 - #define MIN_FRAME_WIDTH 64 127 - #define MAX_USB_WIDTH 320 /* 384 */ 128 - #define MAX_FRAME_WIDTH 320 /* 384 */ /* stretching sometimes causes crashes*/ 129 - 130 - #define MIN_FRAME_HEIGHT 48 131 - #define MAX_USB_HEIGHT 240 /* 288 */ 132 - #define MAX_FRAME_HEIGHT 240 /* 288 */ /* Stretching sometimes causes crashes*/ 133 - 134 - #define MAX_FRAME_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * MAX_BYTES_PER_PIXEL) 135 - #define USBVISION_CLIPMASK_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT / 8) /* bytesize of clipmask */ 136 - 137 - #define USBVISION_URB_FRAMES 32 138 - 139 - #define USBVISION_NUM_HEADERMARKER 20 140 - #define USBVISION_NUMFRAMES 3 /* Maximum number of frames an application can get */ 141 - #define USBVISION_NUMSBUF 2 /* Dimensioning the USB S buffering */ 142 - 143 - #define USBVISION_POWEROFF_TIME (3 * HZ) /* 3 seconds */ 144 - 145 - 146 - #define FRAMERATE_MIN 0 147 - #define FRAMERATE_MAX 31 148 - 149 - enum { 150 - ISOC_MODE_YUV422 = 0x03, 151 - ISOC_MODE_YUV420 = 0x14, 152 - ISOC_MODE_COMPRESS = 0x60, 153 - }; 154 - 155 - /* This macro restricts an int variable to an inclusive range */ 156 - #define RESTRICT_TO_RANGE(v, mi, ma) \ 157 - { if (((int)v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); } 158 - 159 - /* 160 - * We use macros to do YUV -> RGB conversion because this is 161 - * very important for speed and totally unimportant for size. 162 - * 163 - * YUV -> RGB Conversion 164 - * --------------------- 165 - * 166 - * B = 1.164*(Y-16) + 2.018*(V-128) 167 - * G = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128) 168 - * R = 1.164*(Y-16) + 1.596*(U-128) 169 - * 170 - * If you fancy integer arithmetic (as you should), hear this: 171 - * 172 - * 65536*B = 76284*(Y-16) + 132252*(V-128) 173 - * 65536*G = 76284*(Y-16) - 53281*(U-128) - 25625*(V-128) 174 - * 65536*R = 76284*(Y-16) + 104595*(U-128) 175 - * 176 - * Make sure the output values are within [0..255] range. 177 - */ 178 - #define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x))) 179 - #define YUV_TO_RGB_BY_THE_BOOK(my, mu, mv, mr, mg, mb) { \ 180 - int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \ 181 - mm_y = (my) - 16; \ 182 - mm_u = (mu) - 128; \ 183 - mm_v = (mv) - 128; \ 184 - mm_yc = mm_y * 76284; \ 185 - mm_b = (mm_yc + 132252 * mm_v) >> 16; \ 186 - mm_g = (mm_yc - 53281 * mm_u - 25625 * mm_v) >> 16; \ 187 - mm_r = (mm_yc + 104595 * mm_u) >> 16; \ 188 - mb = LIMIT_RGB(mm_b); \ 189 - mg = LIMIT_RGB(mm_g); \ 190 - mr = LIMIT_RGB(mm_r); \ 191 - } 192 - 193 - /* 194 - * This macro checks if usbvision is still operational. The 'usbvision' 195 - * pointer must be valid, usbvision->dev must be valid, we are not 196 - * removing the device and the device has not erred on us. 197 - */ 198 - #define USBVISION_IS_OPERATIONAL(udevice) (\ 199 - (udevice != NULL) && \ 200 - ((udevice)->dev != NULL) && \ 201 - ((udevice)->last_error == 0) && \ 202 - (!(udevice)->remove_pending)) 203 - 204 - #define I2C_USB_ADAP_MAX 16 205 - 206 - #define USBVISION_NORMS (V4L2_STD_PAL | V4L2_STD_NTSC | V4L2_STD_SECAM | V4L2_STD_PAL_M) 207 - 208 - /* ----------------------------------------------------------------- */ 209 - /* usbvision video structures */ 210 - /* ----------------------------------------------------------------- */ 211 - enum scan_state { 212 - scan_state_scanning, /* Scanning for header */ 213 - scan_state_lines /* Parsing lines */ 214 - }; 215 - 216 - /* Completion states of the data parser */ 217 - enum parse_state { 218 - parse_state_continue, /* Just parse next item */ 219 - parse_state_next_frame, /* Frame done, send it to V4L */ 220 - parse_state_out, /* Not enough data for frame */ 221 - parse_state_end_parse /* End parsing */ 222 - }; 223 - 224 - enum frame_state { 225 - frame_state_unused, /* Unused (no MCAPTURE) */ 226 - frame_state_ready, /* Ready to start grabbing */ 227 - frame_state_grabbing, /* In the process of being grabbed into */ 228 - frame_state_done, /* Finished grabbing, but not been synced yet */ 229 - frame_state_done_hold, /* Are syncing or reading */ 230 - frame_state_error, /* Something bad happened while processing */ 231 - }; 232 - 233 - /* stream states */ 234 - enum stream_state { 235 - stream_off, /* Driver streaming is completely OFF */ 236 - stream_idle, /* Driver streaming is ready to be put ON by the application */ 237 - stream_interrupt, /* Driver streaming must be interrupted */ 238 - stream_on, /* Driver streaming is put ON by the application */ 239 - }; 240 - 241 - enum isoc_state { 242 - isoc_state_in_frame, /* Isoc packet is member of frame */ 243 - isoc_state_no_frame, /* Isoc packet is not member of any frame */ 244 - }; 245 - 246 - struct usb_device; 247 - 248 - struct usbvision_sbuf { 249 - char *data; 250 - struct urb *urb; 251 - }; 252 - 253 - #define USBVISION_MAGIC_1 0x55 254 - #define USBVISION_MAGIC_2 0xAA 255 - #define USBVISION_HEADER_LENGTH 0x0c 256 - #define USBVISION_SAA7111_ADDR 0x48 257 - #define USBVISION_SAA7113_ADDR 0x4a 258 - #define USBVISION_IIC_LRACK 0x20 259 - #define USBVISION_IIC_LRNACK 0x30 260 - #define USBVISION_FRAME_FORMAT_PARAM_INTRA (1<<7) 261 - 262 - struct usbvision_v4l2_format_st { 263 - int supported; 264 - int bytes_per_pixel; 265 - int depth; 266 - int format; 267 - }; 268 - #define USBVISION_SUPPORTED_PALETTES ARRAY_SIZE(usbvision_v4l2_format) 269 - 270 - struct usbvision_frame_header { 271 - unsigned char magic_1; /* 0 magic */ 272 - unsigned char magic_2; /* 1 magic */ 273 - unsigned char header_length; /* 2 */ 274 - unsigned char frame_num; /* 3 */ 275 - unsigned char frame_phase; /* 4 */ 276 - unsigned char frame_latency; /* 5 */ 277 - unsigned char data_format; /* 6 */ 278 - unsigned char format_param; /* 7 */ 279 - unsigned char frame_width_lo; /* 8 */ 280 - unsigned char frame_width_hi; /* 9 */ 281 - unsigned char frame_height_lo; /* 10 */ 282 - unsigned char frame_height_hi; /* 11 */ 283 - __u16 frame_width; /* 8 - 9 after endian correction*/ 284 - __u16 frame_height; /* 10 - 11 after endian correction*/ 285 - }; 286 - 287 - struct usbvision_frame { 288 - char *data; /* Frame buffer */ 289 - struct usbvision_frame_header isoc_header; /* Header from stream */ 290 - 291 - int width; /* Width application is expecting */ 292 - int height; /* Height */ 293 - int index; /* Frame index */ 294 - int frmwidth; /* Width the frame actually is */ 295 - int frmheight; /* Height */ 296 - 297 - volatile int grabstate; /* State of grabbing */ 298 - int scanstate; /* State of scanning */ 299 - 300 - struct list_head frame; 301 - 302 - int curline; /* Line of frame we're working on */ 303 - 304 - long scanlength; /* uncompressed, raw data length of frame */ 305 - long bytes_read; /* amount of scanlength that has been read from data */ 306 - struct usbvision_v4l2_format_st v4l2_format; /* format the user needs*/ 307 - int v4l2_linesize; /* bytes for one videoline*/ 308 - u64 ts; 309 - int sequence; /* How many video frames we send to user */ 310 - }; 311 - 312 - #define CODEC_SAA7113 7113 313 - #define CODEC_SAA7111 7111 314 - #define CODEC_WEBCAM 3000 315 - #define BRIDGE_NT1003 1003 316 - #define BRIDGE_NT1004 1004 317 - #define BRIDGE_NT1005 1005 318 - 319 - struct usbvision_device_data_st { 320 - __u64 video_norm; 321 - const char *model_string; 322 - int interface; /* to handle special interface number like BELKIN and Hauppauge WinTV-USB II */ 323 - __u16 codec; 324 - unsigned video_channels:3; 325 - unsigned audio_channels:2; 326 - unsigned radio:1; 327 - unsigned vbi:1; 328 - unsigned tuner:1; 329 - unsigned vin_reg1_override:1; /* Override default value with */ 330 - unsigned vin_reg2_override:1; /* vin_reg1, vin_reg2, etc. */ 331 - unsigned dvi_yuv_override:1; 332 - __u8 vin_reg1; 333 - __u8 vin_reg2; 334 - __u8 dvi_yuv; 335 - __u8 tuner_type; 336 - __s16 x_offset; 337 - __s16 y_offset; 338 - }; 339 - 340 - /* Declared on usbvision-cards.c */ 341 - extern struct usbvision_device_data_st usbvision_device_data[]; 342 - extern struct usb_device_id usbvision_table[]; 343 - 344 - struct usb_usbvision { 345 - struct v4l2_device v4l2_dev; 346 - struct v4l2_ctrl_handler hdl; 347 - struct video_device vdev; /* Video Device */ 348 - struct video_device rdev; /* Radio Device */ 349 - 350 - /* i2c Declaration Section*/ 351 - struct i2c_adapter i2c_adap; 352 - int registered_i2c; 353 - 354 - struct urb *ctrl_urb; 355 - unsigned char ctrl_urb_buffer[8]; 356 - int ctrl_urb_busy; 357 - struct usb_ctrlrequest ctrl_urb_setup; 358 - 359 - /* configuration part */ 360 - int have_tuner; 361 - int tuner_type; 362 - int bridge_type; /* NT1003, NT1004, NT1005 */ 363 - int radio; 364 - int video_inputs; /* # of inputs */ 365 - unsigned long radio_freq; 366 - unsigned long tv_freq; 367 - int audio_mute; 368 - int audio_channel; 369 - int isoc_mode; /* format of video data for the usb isoc-transfer */ 370 - unsigned int nr; /* Number of the device */ 371 - 372 - /* Device structure */ 373 - struct usb_device *dev; 374 - /* usb transfer */ 375 - int num_alt; /* Number of alternative settings */ 376 - unsigned int *alt_max_pkt_size; /* array of max_packet_size */ 377 - unsigned char iface; /* Video interface number */ 378 - unsigned char iface_alt; /* Alt settings */ 379 - unsigned char vin_reg2_preset; 380 - struct mutex v4l2_lock; 381 - int power; /* is the device powered on? */ 382 - int user; /* user count for exclusive use */ 383 - int initialized; /* Had we already sent init sequence? */ 384 - int dev_model; /* What type of USBVISION device we got? */ 385 - enum stream_state streaming; /* Are we streaming Isochronous? */ 386 - int last_error; /* What calamity struck us? */ 387 - int curwidth; /* width of the frame the device is currently set to*/ 388 - int curheight; /* height of the frame the device is currently set to*/ 389 - int stretch_width; /* stretch-factor for frame width (from usb to screen)*/ 390 - int stretch_height; /* stretch-factor for frame height (from usb to screen)*/ 391 - char *fbuf; /* Videodev buffer area for mmap*/ 392 - int max_frame_size; /* Bytes in one video frame */ 393 - int fbuf_size; /* Videodev buffer size */ 394 - spinlock_t queue_lock; /* spinlock for protecting mods on inqueue and outqueue */ 395 - struct list_head inqueue, outqueue; /* queued frame list and ready to dequeue frame list */ 396 - wait_queue_head_t wait_frame; /* Processes waiting */ 397 - wait_queue_head_t wait_stream; /* Processes waiting */ 398 - struct usbvision_frame *cur_frame; /* pointer to current frame, set by usbvision_find_header */ 399 - struct usbvision_frame frame[USBVISION_NUMFRAMES]; /* frame buffer */ 400 - int num_frames; /* number of frames allocated */ 401 - struct usbvision_sbuf sbuf[USBVISION_NUMSBUF]; /* S buffering */ 402 - volatile int remove_pending; /* If set then about to exit */ 403 - 404 - /* Scratch space from the Isochronous Pipe.*/ 405 - unsigned char *scratch; 406 - int scratch_read_ptr; 407 - int scratch_write_ptr; 408 - int scratch_headermarker[USBVISION_NUM_HEADERMARKER]; 409 - int scratch_headermarker_read_ptr; 410 - int scratch_headermarker_write_ptr; 411 - enum isoc_state isocstate; 412 - struct usbvision_v4l2_format_st palette; 413 - 414 - struct v4l2_capability vcap; /* Video capabilities */ 415 - unsigned int ctl_input; /* selected input */ 416 - v4l2_std_id tvnorm_id; /* selected tv norm */ 417 - unsigned char video_endp; /* 0x82 for USBVISION devices based */ 418 - 419 - /* Decompression stuff: */ 420 - unsigned char *intra_frame_buffer; /* Buffer for reference frame */ 421 - int block_pos; /* for test only */ 422 - int request_intra; /* 0 = normal; 1 = intra frame is requested; */ 423 - int last_isoc_frame_num; /* check for lost isoc frames */ 424 - int isoc_packet_size; /* need to calculate used_bandwidth */ 425 - int used_bandwidth; /* used bandwidth 0-100%, need to set compr_level */ 426 - int compr_level; /* How strong (100) or weak (0) is compression */ 427 - int last_compr_level; /* How strong (100) or weak (0) was compression */ 428 - int usb_bandwidth; /* Mbit/s */ 429 - 430 - /* Statistics that can be overlaid on the screen */ 431 - unsigned long isoc_urb_count; /* How many URBs we received so far */ 432 - unsigned long urb_length; /* Length of last URB */ 433 - unsigned long isoc_data_count; /* How many bytes we received */ 434 - unsigned long header_count; /* How many frame headers we found */ 435 - unsigned long scratch_ovf_count; /* How many times we overflowed scratch */ 436 - unsigned long isoc_skip_count; /* How many empty ISO packets received */ 437 - unsigned long isoc_err_count; /* How many bad ISO packets received */ 438 - unsigned long isoc_packet_count; /* How many packets we totally got */ 439 - int isoc_measure_bandwidth_count; 440 - int frame_num; /* How many video frames we send to user */ 441 - int max_strip_len; /* How big is the biggest strip */ 442 - int comprblock_pos; 443 - int strip_len_errors; /* How many times was block_pos greater than strip_len */ 444 - int strip_magic_errors; 445 - int strip_line_number_errors; 446 - int compr_block_types[4]; 447 - }; 448 - 449 - static inline struct usb_usbvision *to_usbvision(struct v4l2_device *v4l2_dev) 450 - { 451 - return container_of(v4l2_dev, struct usb_usbvision, v4l2_dev); 452 - } 453 - 454 - #define call_all(usbvision, o, f, args...) \ 455 - v4l2_device_call_all(&usbvision->v4l2_dev, 0, o, f, ##args) 456 - 457 - /* --------------------------------------------------------------- */ 458 - /* defined in usbvision-i2c.c */ 459 - /* i2c-algo-usb declaration */ 460 - /* --------------------------------------------------------------- */ 461 - 462 - /* ----------------------------------------------------------------------- */ 463 - /* usbvision specific I2C functions */ 464 - /* ----------------------------------------------------------------------- */ 465 - int usbvision_i2c_register(struct usb_usbvision *usbvision); 466 - int usbvision_i2c_unregister(struct usb_usbvision *usbvision); 467 - 468 - /* defined in usbvision-core.c */ 469 - int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg); 470 - int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, 471 - unsigned char value); 472 - 473 - int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames); 474 - void usbvision_frames_free(struct usb_usbvision *usbvision); 475 - int usbvision_scratch_alloc(struct usb_usbvision *usbvision); 476 - void usbvision_scratch_free(struct usb_usbvision *usbvision); 477 - int usbvision_decompress_alloc(struct usb_usbvision *usbvision); 478 - void usbvision_decompress_free(struct usb_usbvision *usbvision); 479 - 480 - int usbvision_setup(struct usb_usbvision *usbvision, int format); 481 - int usbvision_init_isoc(struct usb_usbvision *usbvision); 482 - int usbvision_restart_isoc(struct usb_usbvision *usbvision); 483 - void usbvision_stop_isoc(struct usb_usbvision *usbvision); 484 - int usbvision_set_alternate(struct usb_usbvision *dev); 485 - 486 - int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel); 487 - int usbvision_audio_off(struct usb_usbvision *usbvision); 488 - 489 - int usbvision_begin_streaming(struct usb_usbvision *usbvision); 490 - void usbvision_empty_framequeues(struct usb_usbvision *dev); 491 - int usbvision_stream_interrupt(struct usb_usbvision *dev); 492 - 493 - int usbvision_muxsel(struct usb_usbvision *usbvision, int channel); 494 - int usbvision_set_input(struct usb_usbvision *usbvision); 495 - int usbvision_set_output(struct usb_usbvision *usbvision, int width, int height); 496 - 497 - int usbvision_power_off(struct usb_usbvision *usbvision); 498 - int usbvision_power_on(struct usb_usbvision *usbvision); 499 - 500 - #endif /* __LINUX_USBVISION_H */