R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * * |
| 3 | * easycap.h * |
| 4 | * * |
| 5 | *****************************************************************************/ |
| 6 | /* |
| 7 | * |
| 8 | * Copyright (C) 2010 R.M. Thomas <rmthomas@sciolus.org> |
| 9 | * |
| 10 | * |
| 11 | * This is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * The software is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this software; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | */ |
| 26 | /*****************************************************************************/ |
| 27 | /*---------------------------------------------------------------------------*/ |
| 28 | /* |
| 29 | * THE FOLLOWING PARAMETERS ARE UNDEFINED: |
| 30 | * |
| 31 | * EASYCAP_DEBUG |
| 32 | * EASYCAP_IS_VIDEODEV_CLIENT |
| 33 | * EASYCAP_NEEDS_USBVIDEO_H |
| 34 | * EASYCAP_NEEDS_V4L2_DEVICE_H |
| 35 | * EASYCAP_NEEDS_V4L2_FOPS |
Mike Thomas | 268dfed | 2010-11-07 20:11:36 +0000 | [diff] [blame] | 36 | * EASYCAP_NEEDS_UNLOCKED_IOCTL |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 37 | * |
| 38 | * IF REQUIRED THEY MUST BE EXTERNALLY DEFINED, FOR EXAMPLE AS COMPILER |
| 39 | * OPTIONS. |
| 40 | */ |
| 41 | /*---------------------------------------------------------------------------*/ |
| 42 | |
| 43 | #if (!defined(EASYCAP_H)) |
| 44 | #define EASYCAP_H |
| 45 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 46 | /*---------------------------------------------------------------------------*/ |
| 47 | /* |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 48 | * THESE ARE NORMALLY DEFINED |
| 49 | */ |
| 50 | /*---------------------------------------------------------------------------*/ |
| 51 | #define PATIENCE 500 |
| 52 | #undef PREFER_NTSC |
| 53 | #define PERSEVERE |
| 54 | /*---------------------------------------------------------------------------*/ |
| 55 | /* |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 56 | * THESE ARE FOR MAINTENANCE ONLY - NORMALLY UNDEFINED: |
| 57 | */ |
| 58 | /*---------------------------------------------------------------------------*/ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 59 | #undef EASYCAP_TESTCARD |
| 60 | #undef EASYCAP_TESTTONE |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 61 | #undef NOREADBACK |
| 62 | #undef AUDIOTIME |
| 63 | /*---------------------------------------------------------------------------*/ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 64 | #include <linux/kernel.h> |
| 65 | #include <linux/errno.h> |
| 66 | #include <linux/init.h> |
| 67 | #include <linux/slab.h> |
Randy Dunlap | 72f9fc7 | 2010-11-22 12:12:37 -0800 | [diff] [blame] | 68 | #include <linux/smp_lock.h> |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 69 | #include <linux/module.h> |
| 70 | #include <linux/kref.h> |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 71 | #include <linux/usb.h> |
| 72 | #include <linux/uaccess.h> |
| 73 | |
| 74 | #include <linux/i2c.h> |
| 75 | #include <linux/version.h> |
| 76 | #include <linux/workqueue.h> |
| 77 | #include <linux/poll.h> |
| 78 | #include <linux/mm.h> |
| 79 | #include <linux/fs.h> |
| 80 | #include <linux/delay.h> |
| 81 | #include <linux/types.h> |
| 82 | |
| 83 | /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ |
| 84 | #if defined(EASYCAP_IS_VIDEODEV_CLIENT) |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 85 | #include <media/v4l2-dev.h> |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 86 | #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H) |
| 87 | #include <media/v4l2-device.h> |
| 88 | #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/ |
| 89 | #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ |
| 90 | /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 91 | #include <linux/videodev2.h> |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 92 | #include <linux/soundcard.h> |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 93 | #if defined(EASYCAP_NEEDS_USBVIDEO_H) |
| 94 | #include <config/video/usbvideo.h> |
| 95 | #endif /*EASYCAP_NEEDS_USBVIDEO_H*/ |
| 96 | |
| 97 | #if (!defined(PAGE_SIZE)) |
| 98 | #error "PAGE_SIZE not defined" |
| 99 | #endif |
| 100 | |
| 101 | #define STRINGIZE_AGAIN(x) #x |
| 102 | #define STRINGIZE(x) STRINGIZE_AGAIN(x) |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 103 | /*---------------------------------------------------------------------------*/ |
| 104 | /* VENDOR, PRODUCT: Syntek Semiconductor Co., Ltd |
| 105 | * |
| 106 | * EITHER EasyCAP USB 2.0 Video Adapter with Audio, Model No. DC60 |
| 107 | * with input cabling: AUDIO(L), AUDIO(R), CVBS, S-VIDEO. |
| 108 | * |
| 109 | * OR EasyCAP 4CHANNEL USB 2.0 DVR, Model No. EasyCAP002 |
| 110 | * with input cabling: MICROPHONE, CVBS1, CVBS2, CVBS3, CVBS4. |
| 111 | */ |
| 112 | /*---------------------------------------------------------------------------*/ |
| 113 | #define USB_EASYCAP_VENDOR_ID 0x05e1 |
| 114 | #define USB_EASYCAP_PRODUCT_ID 0x0408 |
| 115 | |
Mike Thomas | ce36ced | 2010-11-07 19:56:40 +0000 | [diff] [blame] | 116 | #define EASYCAP_DRIVER_VERSION "0.8.41" |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 117 | #define EASYCAP_DRIVER_DESCRIPTION "easycapdc60" |
| 118 | |
| 119 | #define USB_SKEL_MINOR_BASE 192 |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 120 | #define DONGLE_MANY 8 |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 121 | #define INPUT_MANY 6 |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 122 | /*---------------------------------------------------------------------------*/ |
| 123 | /* |
| 124 | * DEFAULT LUMINANCE, CONTRAST, SATURATION AND HUE |
| 125 | */ |
| 126 | /*---------------------------------------------------------------------------*/ |
| 127 | #define SAA_0A_DEFAULT 0x7F |
| 128 | #define SAA_0B_DEFAULT 0x3F |
| 129 | #define SAA_0C_DEFAULT 0x2F |
| 130 | #define SAA_0D_DEFAULT 0x00 |
| 131 | /*---------------------------------------------------------------------------*/ |
| 132 | /* |
| 133 | * VIDEO STREAMING PARAMETERS: |
| 134 | * USB 2.0 PROVIDES FOR HIGH-BANDWIDTH ENDPOINTS WITH AN UPPER LIMIT |
| 135 | * OF 3072 BYTES PER MICROFRAME for wMaxPacketSize. |
| 136 | */ |
| 137 | /*---------------------------------------------------------------------------*/ |
| 138 | #define VIDEO_ISOC_BUFFER_MANY 16 |
| 139 | #define VIDEO_ISOC_ORDER 3 |
| 140 | #define VIDEO_ISOC_FRAMESPERDESC ((unsigned int) 1 << VIDEO_ISOC_ORDER) |
| 141 | #define USB_2_0_MAXPACKETSIZE 3072 |
| 142 | #if (USB_2_0_MAXPACKETSIZE > PAGE_SIZE) |
| 143 | #error video_isoc_buffer[.] will not be big enough |
| 144 | #endif |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 145 | #define VIDEO_JUNK_TOLERATE VIDEO_ISOC_BUFFER_MANY |
Mike Thomas | 849322a | 2010-11-07 20:03:50 +0000 | [diff] [blame] | 146 | #define VIDEO_LOST_TOLERATE 50 |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 147 | /*---------------------------------------------------------------------------*/ |
| 148 | /* |
| 149 | * VIDEO BUFFERS |
| 150 | */ |
| 151 | /*---------------------------------------------------------------------------*/ |
| 152 | #define FIELD_BUFFER_SIZE (203 * PAGE_SIZE) |
| 153 | #define FRAME_BUFFER_SIZE (405 * PAGE_SIZE) |
| 154 | #define FIELD_BUFFER_MANY 4 |
| 155 | #define FRAME_BUFFER_MANY 6 |
| 156 | /*---------------------------------------------------------------------------*/ |
| 157 | /* |
| 158 | * AUDIO STREAMING PARAMETERS |
| 159 | */ |
| 160 | /*---------------------------------------------------------------------------*/ |
| 161 | #define AUDIO_ISOC_BUFFER_MANY 16 |
| 162 | #define AUDIO_ISOC_ORDER 3 |
| 163 | #define AUDIO_ISOC_BUFFER_SIZE (PAGE_SIZE << AUDIO_ISOC_ORDER) |
| 164 | /*---------------------------------------------------------------------------*/ |
| 165 | /* |
| 166 | * AUDIO BUFFERS |
| 167 | */ |
| 168 | /*---------------------------------------------------------------------------*/ |
| 169 | #define AUDIO_FRAGMENT_MANY 32 |
| 170 | /*---------------------------------------------------------------------------*/ |
| 171 | /* |
Mike Thomas | 3d423e9 | 2010-07-11 10:51:13 +0100 | [diff] [blame] | 172 | * IT IS ESSENTIAL THAT EVEN-NUMBERED STANDARDS ARE 25 FRAMES PER SECOND, |
| 173 | * ODD-NUMBERED STANDARDS ARE 30 FRAMES PER SECOND. |
| 174 | * THE NUMBERING OF STANDARDS MUST NOT BE CHANGED WITHOUT DUE CARE. NOT |
| 175 | * ONLY MUST THE PARAMETER |
| 176 | * STANDARD_MANY |
| 177 | * BE CHANGED TO CORRESPOND TO THE NEW NUMBER OF STANDARDS, BUT ALSO THE |
| 178 | * NUMBERING MUST REMAIN AN UNBROKEN ASCENDING SEQUENCE: DUMMY STANDARDS |
| 179 | * MAY NEED TO BE ADDED. APPROPRIATE CHANGES WILL ALWAYS BE REQUIRED IN |
| 180 | * ROUTINE fillin_formats() AND POSSIBLY ELSEWHERE. BEWARE. |
| 181 | */ |
| 182 | /*---------------------------------------------------------------------------*/ |
| 183 | #define PAL_BGHIN 0 |
| 184 | #define PAL_Nc 2 |
| 185 | #define SECAM 4 |
| 186 | #define NTSC_N 6 |
| 187 | #define NTSC_N_443 8 |
| 188 | #define NTSC_M 1 |
| 189 | #define NTSC_443 3 |
| 190 | #define NTSC_M_JP 5 |
| 191 | #define PAL_60 7 |
| 192 | #define PAL_M 9 |
Mike Thomas | 40b8d50 | 2010-11-07 20:02:15 +0000 | [diff] [blame] | 193 | #define PAL_BGHIN_SLOW 10 |
| 194 | #define PAL_Nc_SLOW 12 |
| 195 | #define SECAM_SLOW 14 |
| 196 | #define NTSC_N_SLOW 16 |
| 197 | #define NTSC_N_443_SLOW 18 |
| 198 | #define NTSC_M_SLOW 11 |
| 199 | #define NTSC_443_SLOW 13 |
| 200 | #define NTSC_M_JP_SLOW 15 |
| 201 | #define PAL_60_SLOW 17 |
| 202 | #define PAL_M_SLOW 19 |
| 203 | #define STANDARD_MANY 20 |
Mike Thomas | 3d423e9 | 2010-07-11 10:51:13 +0100 | [diff] [blame] | 204 | /*---------------------------------------------------------------------------*/ |
| 205 | /* |
| 206 | * ENUMS |
| 207 | */ |
| 208 | /*---------------------------------------------------------------------------*/ |
| 209 | enum { |
| 210 | AT_720x576, |
| 211 | AT_704x576, |
| 212 | AT_640x480, |
| 213 | AT_720x480, |
| 214 | AT_360x288, |
| 215 | AT_320x240, |
| 216 | AT_360x240, |
| 217 | RESOLUTION_MANY |
| 218 | }; |
| 219 | enum { |
| 220 | FMT_UYVY, |
| 221 | FMT_YUY2, |
| 222 | FMT_RGB24, |
| 223 | FMT_RGB32, |
| 224 | FMT_BGR24, |
| 225 | FMT_BGR32, |
| 226 | PIXELFORMAT_MANY |
| 227 | }; |
| 228 | enum { |
| 229 | FIELD_NONE, |
| 230 | FIELD_INTERLACED, |
Mike Thomas | 3d423e9 | 2010-07-11 10:51:13 +0100 | [diff] [blame] | 231 | INTERLACE_MANY |
| 232 | }; |
| 233 | #define SETTINGS_MANY (STANDARD_MANY * \ |
| 234 | RESOLUTION_MANY * \ |
| 235 | 2 * \ |
| 236 | PIXELFORMAT_MANY * \ |
| 237 | INTERLACE_MANY) |
| 238 | /*---------------------------------------------------------------------------*/ |
| 239 | /* |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 240 | * STRUCTURE DEFINITIONS |
| 241 | */ |
| 242 | /*---------------------------------------------------------------------------*/ |
Mike Thomas | ae59dad | 2010-11-07 20:09:19 +0000 | [diff] [blame] | 243 | struct easycap_dongle { |
| 244 | struct easycap *peasycap; |
| 245 | struct mutex mutex_video; |
| 246 | struct mutex mutex_audio; |
| 247 | }; |
| 248 | /*---------------------------------------------------------------------------*/ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 249 | struct data_buffer { |
| 250 | struct list_head list_head; |
| 251 | void *pgo; |
| 252 | void *pto; |
| 253 | __u16 kount; |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 254 | __u16 input; |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 255 | }; |
| 256 | /*---------------------------------------------------------------------------*/ |
| 257 | struct data_urb { |
| 258 | struct list_head list_head; |
| 259 | struct urb *purb; |
| 260 | int isbuf; |
| 261 | int length; |
| 262 | }; |
| 263 | /*---------------------------------------------------------------------------*/ |
Mike Thomas | 3d423e9 | 2010-07-11 10:51:13 +0100 | [diff] [blame] | 264 | struct easycap_standard { |
| 265 | __u16 mask; |
| 266 | struct v4l2_standard v4l2_standard; |
| 267 | }; |
| 268 | struct easycap_format { |
| 269 | __u16 mask; |
| 270 | char name[128]; |
| 271 | struct v4l2_format v4l2_format; |
| 272 | }; |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 273 | struct inputset { |
| 274 | int input; |
| 275 | int input_ok; |
| 276 | int standard_offset; |
| 277 | int standard_offset_ok; |
| 278 | int format_offset; |
| 279 | int format_offset_ok; |
| 280 | int brightness; |
| 281 | int brightness_ok; |
| 282 | int contrast; |
| 283 | int contrast_ok; |
| 284 | int saturation; |
| 285 | int saturation_ok; |
| 286 | int hue; |
| 287 | int hue_ok; |
| 288 | }; |
Mike Thomas | 3d423e9 | 2010-07-11 10:51:13 +0100 | [diff] [blame] | 289 | /*---------------------------------------------------------------------------*/ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 290 | /* |
| 291 | * easycap.ilk == 0 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=256 |
| 292 | * easycap.ilk == 2 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=9 |
| 293 | * easycap.ilk == 3 => FOUR-CVBS HARDWARE, AUDIO wMaxPacketSize=9 |
| 294 | */ |
| 295 | /*---------------------------------------------------------------------------*/ |
| 296 | struct easycap { |
Mike Thomas | 268dfed | 2010-11-07 20:11:36 +0000 | [diff] [blame] | 297 | #define TELLTALE "expectedstring" |
| 298 | char telltale[16]; |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 299 | int isdongle; |
| 300 | |
| 301 | /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ |
| 302 | #if defined(EASYCAP_IS_VIDEODEV_CLIENT) |
| 303 | struct video_device video_device; |
| 304 | #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H) |
| 305 | struct v4l2_device v4l2_device; |
| 306 | #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/ |
| 307 | #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ |
| 308 | /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 309 | int status; |
Mike Thomas | 3d423e9 | 2010-07-11 10:51:13 +0100 | [diff] [blame] | 310 | unsigned int audio_pages_per_fragment; |
| 311 | unsigned int audio_bytes_per_fragment; |
| 312 | unsigned int audio_buffer_page_many; |
| 313 | |
| 314 | #define UPSAMPLE |
| 315 | #if defined(UPSAMPLE) |
| 316 | __s16 oldaudio; |
| 317 | #endif /*UPSAMPLE*/ |
| 318 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 319 | int ilk; |
| 320 | bool microphone; |
| 321 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 322 | struct usb_device *pusb_device; |
| 323 | struct usb_interface *pusb_interface; |
| 324 | |
| 325 | struct kref kref; |
| 326 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 327 | int queued[FRAME_BUFFER_MANY]; |
| 328 | int done[FRAME_BUFFER_MANY]; |
| 329 | |
| 330 | wait_queue_head_t wq_video; |
| 331 | wait_queue_head_t wq_audio; |
| 332 | |
| 333 | int input; |
| 334 | int polled; |
| 335 | int standard_offset; |
| 336 | int format_offset; |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 337 | struct inputset inputset[INPUT_MANY]; |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 338 | |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 339 | bool ntsc; |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 340 | int fps; |
| 341 | int usec; |
| 342 | int tolerate; |
Mike Thomas | 40b8d50 | 2010-11-07 20:02:15 +0000 | [diff] [blame] | 343 | int skip; |
| 344 | int skipped; |
Mike Thomas | 849322a | 2010-11-07 20:03:50 +0000 | [diff] [blame] | 345 | int lost[INPUT_MANY]; |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 346 | int merit[180]; |
| 347 | |
| 348 | struct timeval timeval0; |
| 349 | struct timeval timeval1; |
| 350 | struct timeval timeval2; |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 351 | struct timeval timeval3; |
| 352 | struct timeval timeval6; |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 353 | struct timeval timeval7; |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 354 | struct timeval timeval8; |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 355 | long long int dnbydt; |
| 356 | |
| 357 | int video_interface; |
| 358 | int video_altsetting_on; |
| 359 | int video_altsetting_off; |
| 360 | int video_endpointnumber; |
| 361 | int video_isoc_maxframesize; |
| 362 | int video_isoc_buffer_size; |
| 363 | int video_isoc_framesperdesc; |
| 364 | |
| 365 | int video_isoc_streaming; |
| 366 | int video_isoc_sequence; |
| 367 | int video_idle; |
| 368 | int video_eof; |
| 369 | int video_junk; |
| 370 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 371 | struct data_buffer video_isoc_buffer[VIDEO_ISOC_BUFFER_MANY]; |
| 372 | struct data_buffer \ |
| 373 | field_buffer[FIELD_BUFFER_MANY][(FIELD_BUFFER_SIZE/PAGE_SIZE)]; |
| 374 | struct data_buffer \ |
| 375 | frame_buffer[FRAME_BUFFER_MANY][(FRAME_BUFFER_SIZE/PAGE_SIZE)]; |
| 376 | |
| 377 | struct list_head urb_video_head; |
| 378 | struct list_head *purb_video_head; |
| 379 | |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 380 | __u8 cache[8]; |
| 381 | __u8 *pcache; |
| 382 | int video_mt; |
| 383 | int audio_mt; |
| 384 | long long audio_bytes; |
| 385 | __u32 isequence; |
| 386 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 387 | int vma_many; |
| 388 | |
| 389 | /*---------------------------------------------------------------------------*/ |
| 390 | /* |
| 391 | * BUFFER INDICATORS |
| 392 | */ |
| 393 | /*---------------------------------------------------------------------------*/ |
| 394 | int field_fill; /* Field buffer being filled by easycap_complete(). */ |
| 395 | /* Bumped only by easycap_complete(). */ |
| 396 | int field_page; /* Page of field buffer page being filled by */ |
| 397 | /* easycap_complete(). */ |
| 398 | int field_read; /* Field buffer to be read by field2frame(). */ |
| 399 | /* Bumped only by easycap_complete(). */ |
| 400 | int frame_fill; /* Frame buffer being filled by field2frame(). */ |
| 401 | /* Bumped only by easycap_dqbuf() when */ |
| 402 | /* field2frame() has created a complete frame. */ |
| 403 | int frame_read; /* Frame buffer offered to user by DQBUF. */ |
| 404 | /* Set only by easycap_dqbuf() to trail frame_fill.*/ |
| 405 | int frame_lock; /* Flag set to 1 by DQBUF and cleared by QBUF */ |
| 406 | /*---------------------------------------------------------------------------*/ |
| 407 | /* |
| 408 | * IMAGE PROPERTIES |
| 409 | */ |
| 410 | /*---------------------------------------------------------------------------*/ |
| 411 | __u32 pixelformat; |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 412 | int width; |
| 413 | int height; |
| 414 | int bytesperpixel; |
| 415 | bool byteswaporder; |
| 416 | bool decimatepixel; |
| 417 | bool offerfields; |
| 418 | int frame_buffer_used; |
| 419 | int frame_buffer_many; |
| 420 | int videofieldamount; |
| 421 | |
| 422 | int brightness; |
| 423 | int contrast; |
| 424 | int saturation; |
| 425 | int hue; |
| 426 | |
| 427 | int allocation_video_urb; |
| 428 | int allocation_video_page; |
| 429 | int allocation_video_struct; |
| 430 | int registered_video; |
| 431 | /*---------------------------------------------------------------------------*/ |
| 432 | /* |
| 433 | * SOUND PROPERTIES |
| 434 | */ |
| 435 | /*---------------------------------------------------------------------------*/ |
| 436 | int audio_interface; |
| 437 | int audio_altsetting_on; |
| 438 | int audio_altsetting_off; |
| 439 | int audio_endpointnumber; |
| 440 | int audio_isoc_maxframesize; |
| 441 | int audio_isoc_buffer_size; |
| 442 | int audio_isoc_framesperdesc; |
| 443 | |
| 444 | int audio_isoc_streaming; |
| 445 | int audio_idle; |
| 446 | int audio_eof; |
| 447 | int volume; |
| 448 | int mute; |
| 449 | |
| 450 | struct data_buffer audio_isoc_buffer[AUDIO_ISOC_BUFFER_MANY]; |
| 451 | |
| 452 | struct list_head urb_audio_head; |
| 453 | struct list_head *purb_audio_head; |
| 454 | /*---------------------------------------------------------------------------*/ |
| 455 | /* |
| 456 | * BUFFER INDICATORS |
| 457 | */ |
| 458 | /*---------------------------------------------------------------------------*/ |
| 459 | int audio_fill; /* Audio buffer being filled by easysnd_complete(). */ |
| 460 | /* Bumped only by easysnd_complete(). */ |
| 461 | int audio_read; /* Audio buffer page being read by easysnd_read(). */ |
| 462 | /* Set by easysnd_read() to trail audio_fill by */ |
| 463 | /* one fragment. */ |
| 464 | /*---------------------------------------------------------------------------*/ |
| 465 | /* |
| 466 | * SOUND PROPERTIES |
| 467 | */ |
| 468 | /*---------------------------------------------------------------------------*/ |
| 469 | |
| 470 | int audio_buffer_many; |
| 471 | |
| 472 | int allocation_audio_urb; |
| 473 | int allocation_audio_page; |
| 474 | int allocation_audio_struct; |
| 475 | int registered_audio; |
| 476 | |
| 477 | long long int audio_sample; |
| 478 | long long int audio_niveau; |
| 479 | long long int audio_square; |
| 480 | |
| 481 | struct data_buffer audio_buffer[]; |
| 482 | }; |
| 483 | /*---------------------------------------------------------------------------*/ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 484 | /* |
| 485 | * VIDEO FUNCTION PROTOTYPES |
| 486 | */ |
| 487 | /*---------------------------------------------------------------------------*/ |
| 488 | void easycap_complete(struct urb *); |
| 489 | int easycap_open(struct inode *, struct file *); |
| 490 | int easycap_release(struct inode *, struct file *); |
Mike Thomas | ae59dad | 2010-11-07 20:09:19 +0000 | [diff] [blame] | 491 | long easycap_ioctl_noinode(struct file *, unsigned int, \ |
| 492 | unsigned long); |
| 493 | int easycap_ioctl(struct inode *, struct file *, unsigned int, \ |
| 494 | unsigned long); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 495 | /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ |
| 496 | #if defined(EASYCAP_IS_VIDEODEV_CLIENT) |
| 497 | int easycap_open_noinode(struct file *); |
| 498 | int easycap_release_noinode(struct file *); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 499 | int videodev_release(struct video_device *); |
| 500 | #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ |
| 501 | /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |
| 502 | |
| 503 | unsigned int easycap_poll(struct file *, poll_table *); |
| 504 | int easycap_mmap(struct file *, struct vm_area_struct *); |
| 505 | int easycap_usb_probe(struct usb_interface *, \ |
| 506 | const struct usb_device_id *); |
| 507 | void easycap_usb_disconnect(struct usb_interface *); |
| 508 | void easycap_delete(struct kref *); |
| 509 | |
| 510 | void easycap_vma_open(struct vm_area_struct *); |
| 511 | void easycap_vma_close(struct vm_area_struct *); |
| 512 | int easycap_vma_fault(struct vm_area_struct *, struct vm_fault *); |
| 513 | int easycap_dqbuf(struct easycap *, int); |
| 514 | int submit_video_urbs(struct easycap *); |
| 515 | int kill_video_urbs(struct easycap *); |
| 516 | int field2frame(struct easycap *); |
| 517 | int redaub(struct easycap *, void *, void *, \ |
| 518 | int, int, __u8, __u8, bool); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 519 | void easycap_testcard(struct easycap *, int); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 520 | int fillin_formats(void); |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 521 | int reset(struct easycap *); |
| 522 | int newinput(struct easycap *, int); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 523 | int adjust_standard(struct easycap *, v4l2_std_id); |
| 524 | int adjust_format(struct easycap *, __u32, __u32, __u32, \ |
| 525 | int, bool); |
| 526 | int adjust_brightness(struct easycap *, int); |
| 527 | int adjust_contrast(struct easycap *, int); |
| 528 | int adjust_saturation(struct easycap *, int); |
| 529 | int adjust_hue(struct easycap *, int); |
| 530 | int adjust_volume(struct easycap *, int); |
| 531 | /*---------------------------------------------------------------------------*/ |
| 532 | /* |
| 533 | * AUDIO FUNCTION PROTOTYPES |
| 534 | */ |
| 535 | /*---------------------------------------------------------------------------*/ |
| 536 | void easysnd_complete(struct urb *); |
| 537 | ssize_t easysnd_read(struct file *, char __user *, size_t, loff_t *); |
| 538 | int easysnd_open(struct inode *, struct file *); |
| 539 | int easysnd_release(struct inode *, struct file *); |
Mike Thomas | ae59dad | 2010-11-07 20:09:19 +0000 | [diff] [blame] | 540 | long easysnd_ioctl_noinode(struct file *, unsigned int, \ |
| 541 | unsigned long); |
| 542 | int easysnd_ioctl(struct inode *, struct file *, unsigned int, \ |
| 543 | unsigned long); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 544 | unsigned int easysnd_poll(struct file *, poll_table *); |
| 545 | void easysnd_delete(struct kref *); |
| 546 | int submit_audio_urbs(struct easycap *); |
| 547 | int kill_audio_urbs(struct easycap *); |
| 548 | void easysnd_testtone(struct easycap *, int); |
| 549 | int audio_setup(struct easycap *); |
| 550 | /*---------------------------------------------------------------------------*/ |
| 551 | /* |
| 552 | * LOW-LEVEL FUNCTION PROTOTYPES |
| 553 | */ |
| 554 | /*---------------------------------------------------------------------------*/ |
| 555 | int audio_gainget(struct usb_device *); |
| 556 | int audio_gainset(struct usb_device *, __s8); |
| 557 | |
| 558 | int set_interface(struct usb_device *, __u16); |
| 559 | int wakeup_device(struct usb_device *); |
| 560 | int confirm_resolution(struct usb_device *); |
| 561 | int confirm_stream(struct usb_device *); |
| 562 | |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 563 | int setup_stk(struct usb_device *, bool); |
| 564 | int setup_saa(struct usb_device *, bool); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 565 | int setup_vt(struct usb_device *); |
Mike Thomas | f36bc37 | 2010-11-07 20:00:35 +0000 | [diff] [blame] | 566 | int check_stk(struct usb_device *, bool); |
| 567 | int check_saa(struct usb_device *, bool); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 568 | int ready_saa(struct usb_device *); |
| 569 | int merit_saa(struct usb_device *); |
| 570 | int check_vt(struct usb_device *); |
| 571 | int select_input(struct usb_device *, int, int); |
| 572 | int set_resolution(struct usb_device *, \ |
| 573 | __u16, __u16, __u16, __u16); |
| 574 | |
| 575 | int read_saa(struct usb_device *, __u16); |
| 576 | int read_stk(struct usb_device *, __u32); |
| 577 | int write_saa(struct usb_device *, __u16, __u16); |
| 578 | int wait_i2c(struct usb_device *); |
| 579 | int write_000(struct usb_device *, __u16, __u16); |
| 580 | int start_100(struct usb_device *); |
| 581 | int stop_100(struct usb_device *); |
| 582 | int write_300(struct usb_device *); |
| 583 | int read_vt(struct usb_device *, __u16); |
| 584 | int write_vt(struct usb_device *, __u16, __u16); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 585 | int regset(struct usb_device *, __u16, __u16); |
| 586 | int regget(struct usb_device *, __u16, void *); |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 587 | int isdongle(struct easycap *); |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 588 | /*---------------------------------------------------------------------------*/ |
| 589 | struct signed_div_result { |
| 590 | long long int quotient; |
| 591 | unsigned long long int remainder; |
| 592 | } signed_div(long long int, long long int); |
| 593 | /*---------------------------------------------------------------------------*/ |
| 594 | /* |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 595 | * MACROS |
| 596 | */ |
| 597 | /*---------------------------------------------------------------------------*/ |
| 598 | #define GET(X, Y, Z) do { \ |
| 599 | int rc; \ |
| 600 | *(Z) = (__u16)0; \ |
| 601 | rc = regget(X, Y, Z); \ |
| 602 | if (0 > rc) { \ |
| 603 | JOT(8, ":-(%i\n", __LINE__); return(rc); \ |
| 604 | } \ |
| 605 | } while (0) |
| 606 | |
| 607 | #define SET(X, Y, Z) do { \ |
| 608 | int rc; \ |
| 609 | rc = regset(X, Y, Z); \ |
| 610 | if (0 > rc) { \ |
| 611 | JOT(8, ":-(%i\n", __LINE__); return(rc); \ |
| 612 | } \ |
| 613 | } while (0) |
| 614 | /*---------------------------------------------------------------------------*/ |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 615 | /* |
| 616 | * MACROS SAM(...) AND JOM(...) ALLOW DIAGNOSTIC OUTPUT TO BE TAGGED WITH |
| 617 | * THE IDENTITY OF THE DONGLE TO WHICH IT APPLIES, BUT IF INVOKED WHEN THE |
| 618 | * POINTER peasycap IS INVALID AN Oops IS LIKELY, AND ITS CAUSE MAY NOT BE |
| 619 | * IMMEDIATELY OBVIOUS FROM A CASUAL READING OF THE SOURCE CODE. BEWARE. |
| 620 | */ |
| 621 | /*---------------------------------------------------------------------------*/ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 622 | #define SAY(format, args...) do { \ |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 623 | printk(KERN_DEBUG "easycap:: %s: " \ |
| 624 | format, __func__, ##args); \ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 625 | } while (0) |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 626 | #define SAM(format, args...) do { \ |
| 627 | printk(KERN_DEBUG "easycap::%i%s: " \ |
| 628 | format, peasycap->isdongle, __func__, ##args);\ |
| 629 | } while (0) |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 630 | |
| 631 | #if defined(EASYCAP_DEBUG) |
| 632 | #define JOT(n, format, args...) do { \ |
Randy Dunlap | 62af33e | 2010-11-11 10:44:22 -0800 | [diff] [blame] | 633 | if (n <= easycap_debug) { \ |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 634 | printk(KERN_DEBUG "easycap:: %s: " \ |
| 635 | format, __func__, ##args);\ |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 636 | } \ |
| 637 | } while (0) |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 638 | #define JOM(n, format, args...) do { \ |
Randy Dunlap | 62af33e | 2010-11-11 10:44:22 -0800 | [diff] [blame] | 639 | if (n <= easycap_debug) { \ |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 640 | printk(KERN_DEBUG "easycap::%i%s: " \ |
| 641 | format, peasycap->isdongle, __func__, ##args);\ |
| 642 | } \ |
| 643 | } while (0) |
| 644 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 645 | #else |
| 646 | #define JOT(n, format, args...) do {} while (0) |
Mike Thomas | e68703c | 2010-11-07 19:58:55 +0000 | [diff] [blame] | 647 | #define JOM(n, format, args...) do {} while (0) |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 648 | #endif /*EASYCAP_DEBUG*/ |
| 649 | |
R.M. Thomas | 702422b | 2010-06-18 12:29:49 -0700 | [diff] [blame] | 650 | #define MICROSECONDS(X, Y) \ |
| 651 | ((1000000*((long long int)(X.tv_sec - Y.tv_sec))) + \ |
| 652 | (long long int)(X.tv_usec - Y.tv_usec)) |
| 653 | |
| 654 | /*---------------------------------------------------------------------------*/ |
| 655 | /* |
| 656 | * (unsigned char *)P pointer to next byte pair |
| 657 | * (long int *)X pointer to accumulating count |
| 658 | * (long int *)Y pointer to accumulating sum |
| 659 | * (long long int *)Z pointer to accumulating sum of squares |
| 660 | */ |
| 661 | /*---------------------------------------------------------------------------*/ |
| 662 | #define SUMMER(P, X, Y, Z) do { \ |
| 663 | unsigned char *p; \ |
| 664 | unsigned int u0, u1, u2; \ |
| 665 | long int s; \ |
| 666 | p = (unsigned char *)(P); \ |
| 667 | u0 = (unsigned int) (*p); \ |
| 668 | u1 = (unsigned int) (*(p + 1)); \ |
| 669 | u2 = (unsigned int) ((u1 << 8) | u0); \ |
| 670 | if (0x8000 & u2) \ |
| 671 | s = -(long int)(0x7FFF & (~u2)); \ |
| 672 | else \ |
| 673 | s = (long int)(0x7FFF & u2); \ |
| 674 | *((X)) += (long int) 1; \ |
| 675 | *((Y)) += (long int) s; \ |
| 676 | *((Z)) += ((long long int)(s) * (long long int)(s)); \ |
| 677 | } while (0) |
| 678 | /*---------------------------------------------------------------------------*/ |
| 679 | |
| 680 | #endif /*EASYCAP_H*/ |