1 /* 2 * USB IBM C-It Video Camera driver 3 * 4 * Supports Xirlink C-It Video Camera, IBM PC Camera, 5 * IBM NetCamera and Veo Stingray. 6 * 7 * Copyright (C) 2010 Hans de Goede <hdegoede@redhat.com> 8 * 9 * This driver is based on earlier work of: 10 * 11 * (C) Copyright 1999 Johannes Erdfelt 12 * (C) Copyright 1999 Randy Dunlap 13 * 14 * This program is free software; you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License as published by 16 * the Free Software Foundation; either version 2 of the License, or 17 * (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 * 28 */ 29 30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 31 32 #define MODULE_NAME "xirlink-cit" 33 34 #include <linux/input.h> 35 #include "gspca.h" 36 37 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); 38 MODULE_DESCRIPTION("Xirlink C-IT"); 39 MODULE_LICENSE("GPL"); 40 41 /* FIXME we should autodetect this */ 42 static int ibm_netcam_pro; 43 module_param(ibm_netcam_pro, int, 0); 44 MODULE_PARM_DESC(ibm_netcam_pro, 45 "Use IBM Netcamera Pro init sequences for Model 3 cams"); 46 47 /* FIXME this should be handled through the V4L2 input selection API */ 48 static int rca_input; 49 module_param(rca_input, int, 0644); 50 MODULE_PARM_DESC(rca_input, 51 "Use rca input instead of ccd sensor on Model 3 cams"); 52 53 /* specific webcam descriptor */ 54 struct sd { 55 struct gspca_dev gspca_dev; /* !! must be the first item */ 56 struct v4l2_ctrl *lighting; 57 u8 model; 58 #define CIT_MODEL0 0 /* bcd version 0.01 cams ie the xvp-500 */ 59 #define CIT_MODEL1 1 /* The model 1 - 4 nomenclature comes from the old */ 60 #define CIT_MODEL2 2 /* ibmcam driver */ 61 #define CIT_MODEL3 3 62 #define CIT_MODEL4 4 63 #define CIT_IBM_NETCAM_PRO 5 64 u8 input_index; 65 u8 button_state; 66 u8 stop_on_control_change; 67 u8 sof_read; 68 u8 sof_len; 69 }; 70 71 static void sd_stop0(struct gspca_dev *gspca_dev); 72 73 static const struct v4l2_pix_format cif_yuv_mode[] = { 74 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 75 .bytesperline = 176, 76 .sizeimage = 176 * 144 * 3 / 2 + 4, 77 .colorspace = V4L2_COLORSPACE_SRGB}, 78 {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 79 .bytesperline = 352, 80 .sizeimage = 352 * 288 * 3 / 2 + 4, 81 .colorspace = V4L2_COLORSPACE_SRGB}, 82 }; 83 84 static const struct v4l2_pix_format vga_yuv_mode[] = { 85 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 86 .bytesperline = 160, 87 .sizeimage = 160 * 120 * 3 / 2 + 4, 88 .colorspace = V4L2_COLORSPACE_SRGB}, 89 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 90 .bytesperline = 320, 91 .sizeimage = 320 * 240 * 3 / 2 + 4, 92 .colorspace = V4L2_COLORSPACE_SRGB}, 93 {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 94 .bytesperline = 640, 95 .sizeimage = 640 * 480 * 3 / 2 + 4, 96 .colorspace = V4L2_COLORSPACE_SRGB}, 97 }; 98 99 static const struct v4l2_pix_format model0_mode[] = { 100 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 101 .bytesperline = 160, 102 .sizeimage = 160 * 120 * 3 / 2 + 4, 103 .colorspace = V4L2_COLORSPACE_SRGB}, 104 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 105 .bytesperline = 176, 106 .sizeimage = 176 * 144 * 3 / 2 + 4, 107 .colorspace = V4L2_COLORSPACE_SRGB}, 108 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 109 .bytesperline = 320, 110 .sizeimage = 320 * 240 * 3 / 2 + 4, 111 .colorspace = V4L2_COLORSPACE_SRGB}, 112 }; 113 114 static const struct v4l2_pix_format model2_mode[] = { 115 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 116 .bytesperline = 160, 117 .sizeimage = 160 * 120 * 3 / 2 + 4, 118 .colorspace = V4L2_COLORSPACE_SRGB}, 119 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 120 .bytesperline = 176, 121 .sizeimage = 176 * 144 * 3 / 2 + 4, 122 .colorspace = V4L2_COLORSPACE_SRGB}, 123 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE, 124 .bytesperline = 320, 125 .sizeimage = 320 * 240 + 4, 126 .colorspace = V4L2_COLORSPACE_SRGB}, 127 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE, 128 .bytesperline = 352, 129 .sizeimage = 352 * 288 + 4, 130 .colorspace = V4L2_COLORSPACE_SRGB}, 131 }; 132 133 /* 134 * 01.01.08 - Added for RCA video in support -LO 135 * This struct is used to init the Model3 cam to use the RCA video in port 136 * instead of the CCD sensor. 137 */ 138 static const u16 rca_initdata[][3] = { 139 {0, 0x0000, 0x010c}, 140 {0, 0x0006, 0x012c}, 141 {0, 0x0078, 0x012d}, 142 {0, 0x0046, 0x012f}, 143 {0, 0xd141, 0x0124}, 144 {0, 0x0000, 0x0127}, 145 {0, 0xfea8, 0x0124}, 146 {1, 0x0000, 0x0116}, 147 {0, 0x0064, 0x0116}, 148 {1, 0x0000, 0x0115}, 149 {0, 0x0003, 0x0115}, 150 {0, 0x0008, 0x0123}, 151 {0, 0x0000, 0x0117}, 152 {0, 0x0000, 0x0112}, 153 {0, 0x0080, 0x0100}, 154 {0, 0x0000, 0x0100}, 155 {1, 0x0000, 0x0116}, 156 {0, 0x0060, 0x0116}, 157 {0, 0x0002, 0x0112}, 158 {0, 0x0000, 0x0123}, 159 {0, 0x0001, 0x0117}, 160 {0, 0x0040, 0x0108}, 161 {0, 0x0019, 0x012c}, 162 {0, 0x0040, 0x0116}, 163 {0, 0x000a, 0x0115}, 164 {0, 0x000b, 0x0115}, 165 {0, 0x0078, 0x012d}, 166 {0, 0x0046, 0x012f}, 167 {0, 0xd141, 0x0124}, 168 {0, 0x0000, 0x0127}, 169 {0, 0xfea8, 0x0124}, 170 {0, 0x0064, 0x0116}, 171 {0, 0x0000, 0x0115}, 172 {0, 0x0001, 0x0115}, 173 {0, 0xffff, 0x0124}, 174 {0, 0xfff9, 0x0124}, 175 {0, 0x0086, 0x0127}, 176 {0, 0xfff8, 0x0124}, 177 {0, 0xfffd, 0x0124}, 178 {0, 0x00aa, 0x0127}, 179 {0, 0xfff8, 0x0124}, 180 {0, 0xfffd, 0x0124}, 181 {0, 0x0000, 0x0127}, 182 {0, 0xfff8, 0x0124}, 183 {0, 0xfffd, 0x0124}, 184 {0, 0xfffa, 0x0124}, 185 {0, 0xffff, 0x0124}, 186 {0, 0xfff9, 0x0124}, 187 {0, 0x0086, 0x0127}, 188 {0, 0xfff8, 0x0124}, 189 {0, 0xfffd, 0x0124}, 190 {0, 0x00f2, 0x0127}, 191 {0, 0xfff8, 0x0124}, 192 {0, 0xfffd, 0x0124}, 193 {0, 0x000f, 0x0127}, 194 {0, 0xfff8, 0x0124}, 195 {0, 0xfffd, 0x0124}, 196 {0, 0xfffa, 0x0124}, 197 {0, 0xffff, 0x0124}, 198 {0, 0xfff9, 0x0124}, 199 {0, 0x0086, 0x0127}, 200 {0, 0xfff8, 0x0124}, 201 {0, 0xfffd, 0x0124}, 202 {0, 0x00f8, 0x0127}, 203 {0, 0xfff8, 0x0124}, 204 {0, 0xfffd, 0x0124}, 205 {0, 0x00fc, 0x0127}, 206 {0, 0xfff8, 0x0124}, 207 {0, 0xfffd, 0x0124}, 208 {0, 0xfffa, 0x0124}, 209 {0, 0xffff, 0x0124}, 210 {0, 0xfff9, 0x0124}, 211 {0, 0x0086, 0x0127}, 212 {0, 0xfff8, 0x0124}, 213 {0, 0xfffd, 0x0124}, 214 {0, 0x00f9, 0x0127}, 215 {0, 0xfff8, 0x0124}, 216 {0, 0xfffd, 0x0124}, 217 {0, 0x003c, 0x0127}, 218 {0, 0xfff8, 0x0124}, 219 {0, 0xfffd, 0x0124}, 220 {0, 0xfffa, 0x0124}, 221 {0, 0xffff, 0x0124}, 222 {0, 0xfff9, 0x0124}, 223 {0, 0x0086, 0x0127}, 224 {0, 0xfff8, 0x0124}, 225 {0, 0xfffd, 0x0124}, 226 {0, 0x0027, 0x0127}, 227 {0, 0xfff8, 0x0124}, 228 {0, 0xfffd, 0x0124}, 229 {0, 0x0019, 0x0127}, 230 {0, 0xfff8, 0x0124}, 231 {0, 0xfffd, 0x0124}, 232 {0, 0xfffa, 0x0124}, 233 {0, 0xfff9, 0x0124}, 234 {0, 0x0086, 0x0127}, 235 {0, 0xfff8, 0x0124}, 236 {0, 0xfffd, 0x0124}, 237 {0, 0x0037, 0x0127}, 238 {0, 0xfff8, 0x0124}, 239 {0, 0xfffd, 0x0124}, 240 {0, 0x0000, 0x0127}, 241 {0, 0xfff8, 0x0124}, 242 {0, 0xfffd, 0x0124}, 243 {0, 0x0021, 0x0127}, 244 {0, 0xfff8, 0x0124}, 245 {0, 0xfffd, 0x0124}, 246 {0, 0xfffa, 0x0124}, 247 {0, 0xfff9, 0x0124}, 248 {0, 0x0086, 0x0127}, 249 {0, 0xfff8, 0x0124}, 250 {0, 0xfffd, 0x0124}, 251 {0, 0x0038, 0x0127}, 252 {0, 0xfff8, 0x0124}, 253 {0, 0xfffd, 0x0124}, 254 {0, 0x0006, 0x0127}, 255 {0, 0xfff8, 0x0124}, 256 {0, 0xfffd, 0x0124}, 257 {0, 0x0045, 0x0127}, 258 {0, 0xfff8, 0x0124}, 259 {0, 0xfffd, 0x0124}, 260 {0, 0xfffa, 0x0124}, 261 {0, 0xfff9, 0x0124}, 262 {0, 0x0086, 0x0127}, 263 {0, 0xfff8, 0x0124}, 264 {0, 0xfffd, 0x0124}, 265 {0, 0x0037, 0x0127}, 266 {0, 0xfff8, 0x0124}, 267 {0, 0xfffd, 0x0124}, 268 {0, 0x0001, 0x0127}, 269 {0, 0xfff8, 0x0124}, 270 {0, 0xfffd, 0x0124}, 271 {0, 0x002a, 0x0127}, 272 {0, 0xfff8, 0x0124}, 273 {0, 0xfffd, 0x0124}, 274 {0, 0xfffa, 0x0124}, 275 {0, 0xfff9, 0x0124}, 276 {0, 0x0086, 0x0127}, 277 {0, 0xfff8, 0x0124}, 278 {0, 0xfffd, 0x0124}, 279 {0, 0x0038, 0x0127}, 280 {0, 0xfff8, 0x0124}, 281 {0, 0xfffd, 0x0124}, 282 {0, 0x0000, 0x0127}, 283 {0, 0xfff8, 0x0124}, 284 {0, 0xfffd, 0x0124}, 285 {0, 0x000e, 0x0127}, 286 {0, 0xfff8, 0x0124}, 287 {0, 0xfffd, 0x0124}, 288 {0, 0xfffa, 0x0124}, 289 {0, 0xfff9, 0x0124}, 290 {0, 0x0086, 0x0127}, 291 {0, 0xfff8, 0x0124}, 292 {0, 0xfffd, 0x0124}, 293 {0, 0x0037, 0x0127}, 294 {0, 0xfff8, 0x0124}, 295 {0, 0xfffd, 0x0124}, 296 {0, 0x0001, 0x0127}, 297 {0, 0xfff8, 0x0124}, 298 {0, 0xfffd, 0x0124}, 299 {0, 0x002b, 0x0127}, 300 {0, 0xfff8, 0x0124}, 301 {0, 0xfffd, 0x0124}, 302 {0, 0xfffa, 0x0124}, 303 {0, 0xfff9, 0x0124}, 304 {0, 0x0086, 0x0127}, 305 {0, 0xfff8, 0x0124}, 306 {0, 0xfffd, 0x0124}, 307 {0, 0x0038, 0x0127}, 308 {0, 0xfff8, 0x0124}, 309 {0, 0xfffd, 0x0124}, 310 {0, 0x0001, 0x0127}, 311 {0, 0xfff8, 0x0124}, 312 {0, 0xfffd, 0x0124}, 313 {0, 0x00f4, 0x0127}, 314 {0, 0xfff8, 0x0124}, 315 {0, 0xfffd, 0x0124}, 316 {0, 0xfffa, 0x0124}, 317 {0, 0xfff9, 0x0124}, 318 {0, 0x0086, 0x0127}, 319 {0, 0xfff8, 0x0124}, 320 {0, 0xfffd, 0x0124}, 321 {0, 0x0037, 0x0127}, 322 {0, 0xfff8, 0x0124}, 323 {0, 0xfffd, 0x0124}, 324 {0, 0x0001, 0x0127}, 325 {0, 0xfff8, 0x0124}, 326 {0, 0xfffd, 0x0124}, 327 {0, 0x002c, 0x0127}, 328 {0, 0xfff8, 0x0124}, 329 {0, 0xfffd, 0x0124}, 330 {0, 0xfffa, 0x0124}, 331 {0, 0xfff9, 0x0124}, 332 {0, 0x0086, 0x0127}, 333 {0, 0xfff8, 0x0124}, 334 {0, 0xfffd, 0x0124}, 335 {0, 0x0038, 0x0127}, 336 {0, 0xfff8, 0x0124}, 337 {0, 0xfffd, 0x0124}, 338 {0, 0x0001, 0x0127}, 339 {0, 0xfff8, 0x0124}, 340 {0, 0xfffd, 0x0124}, 341 {0, 0x0004, 0x0127}, 342 {0, 0xfff8, 0x0124}, 343 {0, 0xfffd, 0x0124}, 344 {0, 0xfffa, 0x0124}, 345 {0, 0xfff9, 0x0124}, 346 {0, 0x0086, 0x0127}, 347 {0, 0xfff8, 0x0124}, 348 {0, 0xfffd, 0x0124}, 349 {0, 0x0037, 0x0127}, 350 {0, 0xfff8, 0x0124}, 351 {0, 0xfffd, 0x0124}, 352 {0, 0x0001, 0x0127}, 353 {0, 0xfff8, 0x0124}, 354 {0, 0xfffd, 0x0124}, 355 {0, 0x002d, 0x0127}, 356 {0, 0xfff8, 0x0124}, 357 {0, 0xfffd, 0x0124}, 358 {0, 0xfffa, 0x0124}, 359 {0, 0xfff9, 0x0124}, 360 {0, 0x0086, 0x0127}, 361 {0, 0xfff8, 0x0124}, 362 {0, 0xfffd, 0x0124}, 363 {0, 0x0038, 0x0127}, 364 {0, 0xfff8, 0x0124}, 365 {0, 0xfffd, 0x0124}, 366 {0, 0x0000, 0x0127}, 367 {0, 0xfff8, 0x0124}, 368 {0, 0xfffd, 0x0124}, 369 {0, 0x0014, 0x0127}, 370 {0, 0xfff8, 0x0124}, 371 {0, 0xfffd, 0x0124}, 372 {0, 0xfffa, 0x0124}, 373 {0, 0xfff9, 0x0124}, 374 {0, 0x0086, 0x0127}, 375 {0, 0xfff8, 0x0124}, 376 {0, 0xfffd, 0x0124}, 377 {0, 0x0037, 0x0127}, 378 {0, 0xfff8, 0x0124}, 379 {0, 0xfffd, 0x0124}, 380 {0, 0x0001, 0x0127}, 381 {0, 0xfff8, 0x0124}, 382 {0, 0xfffd, 0x0124}, 383 {0, 0x002e, 0x0127}, 384 {0, 0xfff8, 0x0124}, 385 {0, 0xfffd, 0x0124}, 386 {0, 0xfffa, 0x0124}, 387 {0, 0xfff9, 0x0124}, 388 {0, 0x0086, 0x0127}, 389 {0, 0xfff8, 0x0124}, 390 {0, 0xfffd, 0x0124}, 391 {0, 0x0038, 0x0127}, 392 {0, 0xfff8, 0x0124}, 393 {0, 0xfffd, 0x0124}, 394 {0, 0x0003, 0x0127}, 395 {0, 0xfff8, 0x0124}, 396 {0, 0xfffd, 0x0124}, 397 {0, 0x0000, 0x0127}, 398 {0, 0xfff8, 0x0124}, 399 {0, 0xfffd, 0x0124}, 400 {0, 0xfffa, 0x0124}, 401 {0, 0xfff9, 0x0124}, 402 {0, 0x0086, 0x0127}, 403 {0, 0xfff8, 0x0124}, 404 {0, 0xfffd, 0x0124}, 405 {0, 0x0037, 0x0127}, 406 {0, 0xfff8, 0x0124}, 407 {0, 0xfffd, 0x0124}, 408 {0, 0x0001, 0x0127}, 409 {0, 0xfff8, 0x0124}, 410 {0, 0xfffd, 0x0124}, 411 {0, 0x002f, 0x0127}, 412 {0, 0xfff8, 0x0124}, 413 {0, 0xfffd, 0x0124}, 414 {0, 0xfffa, 0x0124}, 415 {0, 0xfff9, 0x0124}, 416 {0, 0x0086, 0x0127}, 417 {0, 0xfff8, 0x0124}, 418 {0, 0xfffd, 0x0124}, 419 {0, 0x0038, 0x0127}, 420 {0, 0xfff8, 0x0124}, 421 {0, 0xfffd, 0x0124}, 422 {0, 0x0003, 0x0127}, 423 {0, 0xfff8, 0x0124}, 424 {0, 0xfffd, 0x0124}, 425 {0, 0x0014, 0x0127}, 426 {0, 0xfff8, 0x0124}, 427 {0, 0xfffd, 0x0124}, 428 {0, 0xfffa, 0x0124}, 429 {0, 0xfff9, 0x0124}, 430 {0, 0x0086, 0x0127}, 431 {0, 0xfff8, 0x0124}, 432 {0, 0xfffd, 0x0124}, 433 {0, 0x0037, 0x0127}, 434 {0, 0xfff8, 0x0124}, 435 {0, 0xfffd, 0x0124}, 436 {0, 0x0001, 0x0127}, 437 {0, 0xfff8, 0x0124}, 438 {0, 0xfffd, 0x0124}, 439 {0, 0x0040, 0x0127}, 440 {0, 0xfff8, 0x0124}, 441 {0, 0xfffd, 0x0124}, 442 {0, 0xfffa, 0x0124}, 443 {0, 0xfff9, 0x0124}, 444 {0, 0x0086, 0x0127}, 445 {0, 0xfff8, 0x0124}, 446 {0, 0xfffd, 0x0124}, 447 {0, 0x0038, 0x0127}, 448 {0, 0xfff8, 0x0124}, 449 {0, 0xfffd, 0x0124}, 450 {0, 0x0000, 0x0127}, 451 {0, 0xfff8, 0x0124}, 452 {0, 0xfffd, 0x0124}, 453 {0, 0x0040, 0x0127}, 454 {0, 0xfff8, 0x0124}, 455 {0, 0xfffd, 0x0124}, 456 {0, 0xfffa, 0x0124}, 457 {0, 0xfff9, 0x0124}, 458 {0, 0x0086, 0x0127}, 459 {0, 0xfff8, 0x0124}, 460 {0, 0xfffd, 0x0124}, 461 {0, 0x0037, 0x0127}, 462 {0, 0xfff8, 0x0124}, 463 {0, 0xfffd, 0x0124}, 464 {0, 0x0001, 0x0127}, 465 {0, 0xfff8, 0x0124}, 466 {0, 0xfffd, 0x0124}, 467 {0, 0x0053, 0x0127}, 468 {0, 0xfff8, 0x0124}, 469 {0, 0xfffd, 0x0124}, 470 {0, 0xfffa, 0x0124}, 471 {0, 0xfff9, 0x0124}, 472 {0, 0x0086, 0x0127}, 473 {0, 0xfff8, 0x0124}, 474 {0, 0xfffd, 0x0124}, 475 {0, 0x0038, 0x0127}, 476 {0, 0xfff8, 0x0124}, 477 {0, 0xfffd, 0x0124}, 478 {0, 0x0000, 0x0127}, 479 {0, 0xfff8, 0x0124}, 480 {0, 0xfffd, 0x0124}, 481 {0, 0x0038, 0x0127}, 482 {0, 0xfff8, 0x0124}, 483 {0, 0xfffd, 0x0124}, 484 {0, 0xfffa, 0x0124}, 485 {0, 0x0000, 0x0101}, 486 {0, 0x00a0, 0x0103}, 487 {0, 0x0078, 0x0105}, 488 {0, 0x0000, 0x010a}, 489 {0, 0x0024, 0x010b}, 490 {0, 0x0028, 0x0119}, 491 {0, 0x0088, 0x011b}, 492 {0, 0x0002, 0x011d}, 493 {0, 0x0003, 0x011e}, 494 {0, 0x0000, 0x0129}, 495 {0, 0x00fc, 0x012b}, 496 {0, 0x0008, 0x0102}, 497 {0, 0x0000, 0x0104}, 498 {0, 0x0008, 0x011a}, 499 {0, 0x0028, 0x011c}, 500 {0, 0x0021, 0x012a}, 501 {0, 0x0000, 0x0118}, 502 {0, 0x0000, 0x0132}, 503 {0, 0x0000, 0x0109}, 504 {0, 0xfff9, 0x0124}, 505 {0, 0x0086, 0x0127}, 506 {0, 0xfff8, 0x0124}, 507 {0, 0xfffd, 0x0124}, 508 {0, 0x0037, 0x0127}, 509 {0, 0xfff8, 0x0124}, 510 {0, 0xfffd, 0x0124}, 511 {0, 0x0001, 0x0127}, 512 {0, 0xfff8, 0x0124}, 513 {0, 0xfffd, 0x0124}, 514 {0, 0x0031, 0x0127}, 515 {0, 0xfff8, 0x0124}, 516 {0, 0xfffd, 0x0124}, 517 {0, 0xfffa, 0x0124}, 518 {0, 0xfff9, 0x0124}, 519 {0, 0x0086, 0x0127}, 520 {0, 0xfff8, 0x0124}, 521 {0, 0xfffd, 0x0124}, 522 {0, 0x0038, 0x0127}, 523 {0, 0xfff8, 0x0124}, 524 {0, 0xfffd, 0x0124}, 525 {0, 0x0000, 0x0127}, 526 {0, 0xfff8, 0x0124}, 527 {0, 0xfffd, 0x0124}, 528 {0, 0x0000, 0x0127}, 529 {0, 0xfff8, 0x0124}, 530 {0, 0xfffd, 0x0124}, 531 {0, 0xfffa, 0x0124}, 532 {0, 0xfff9, 0x0124}, 533 {0, 0x0086, 0x0127}, 534 {0, 0xfff8, 0x0124}, 535 {0, 0xfffd, 0x0124}, 536 {0, 0x0037, 0x0127}, 537 {0, 0xfff8, 0x0124}, 538 {0, 0xfffd, 0x0124}, 539 {0, 0x0001, 0x0127}, 540 {0, 0xfff8, 0x0124}, 541 {0, 0xfffd, 0x0124}, 542 {0, 0x0040, 0x0127}, 543 {0, 0xfff8, 0x0124}, 544 {0, 0xfffd, 0x0124}, 545 {0, 0xfffa, 0x0124}, 546 {0, 0xfff9, 0x0124}, 547 {0, 0x0086, 0x0127}, 548 {0, 0xfff8, 0x0124}, 549 {0, 0xfffd, 0x0124}, 550 {0, 0x0038, 0x0127}, 551 {0, 0xfff8, 0x0124}, 552 {0, 0xfffd, 0x0124}, 553 {0, 0x0000, 0x0127}, 554 {0, 0xfff8, 0x0124}, 555 {0, 0xfffd, 0x0124}, 556 {0, 0x0040, 0x0127}, 557 {0, 0xfff8, 0x0124}, 558 {0, 0xfffd, 0x0124}, 559 {0, 0xfffa, 0x0124}, 560 {0, 0xfff9, 0x0124}, 561 {0, 0x0086, 0x0127}, 562 {0, 0xfff8, 0x0124}, 563 {0, 0xfffd, 0x0124}, 564 {0, 0x0037, 0x0127}, 565 {0, 0xfff8, 0x0124}, 566 {0, 0xfffd, 0x0124}, 567 {0, 0x0000, 0x0127}, 568 {0, 0xfff8, 0x0124}, 569 {0, 0xfffd, 0x0124}, 570 {0, 0x00dc, 0x0127}, 571 {0, 0xfff8, 0x0124}, 572 {0, 0xfffd, 0x0124}, 573 {0, 0xfffa, 0x0124}, 574 {0, 0xfff9, 0x0124}, 575 {0, 0x0086, 0x0127}, 576 {0, 0xfff8, 0x0124}, 577 {0, 0xfffd, 0x0124}, 578 {0, 0x0038, 0x0127}, 579 {0, 0xfff8, 0x0124}, 580 {0, 0xfffd, 0x0124}, 581 {0, 0x0000, 0x0127}, 582 {0, 0xfff8, 0x0124}, 583 {0, 0xfffd, 0x0124}, 584 {0, 0x0000, 0x0127}, 585 {0, 0xfff8, 0x0124}, 586 {0, 0xfffd, 0x0124}, 587 {0, 0xfffa, 0x0124}, 588 {0, 0xfff9, 0x0124}, 589 {0, 0x0086, 0x0127}, 590 {0, 0xfff8, 0x0124}, 591 {0, 0xfffd, 0x0124}, 592 {0, 0x0037, 0x0127}, 593 {0, 0xfff8, 0x0124}, 594 {0, 0xfffd, 0x0124}, 595 {0, 0x0001, 0x0127}, 596 {0, 0xfff8, 0x0124}, 597 {0, 0xfffd, 0x0124}, 598 {0, 0x0032, 0x0127}, 599 {0, 0xfff8, 0x0124}, 600 {0, 0xfffd, 0x0124}, 601 {0, 0xfffa, 0x0124}, 602 {0, 0xfff9, 0x0124}, 603 {0, 0x0086, 0x0127}, 604 {0, 0xfff8, 0x0124}, 605 {0, 0xfffd, 0x0124}, 606 {0, 0x0038, 0x0127}, 607 {0, 0xfff8, 0x0124}, 608 {0, 0xfffd, 0x0124}, 609 {0, 0x0001, 0x0127}, 610 {0, 0xfff8, 0x0124}, 611 {0, 0xfffd, 0x0124}, 612 {0, 0x0020, 0x0127}, 613 {0, 0xfff8, 0x0124}, 614 {0, 0xfffd, 0x0124}, 615 {0, 0xfffa, 0x0124}, 616 {0, 0xfff9, 0x0124}, 617 {0, 0x0086, 0x0127}, 618 {0, 0xfff8, 0x0124}, 619 {0, 0xfffd, 0x0124}, 620 {0, 0x0037, 0x0127}, 621 {0, 0xfff8, 0x0124}, 622 {0, 0xfffd, 0x0124}, 623 {0, 0x0001, 0x0127}, 624 {0, 0xfff8, 0x0124}, 625 {0, 0xfffd, 0x0124}, 626 {0, 0x0040, 0x0127}, 627 {0, 0xfff8, 0x0124}, 628 {0, 0xfffd, 0x0124}, 629 {0, 0xfffa, 0x0124}, 630 {0, 0xfff9, 0x0124}, 631 {0, 0x0086, 0x0127}, 632 {0, 0xfff8, 0x0124}, 633 {0, 0xfffd, 0x0124}, 634 {0, 0x0038, 0x0127}, 635 {0, 0xfff8, 0x0124}, 636 {0, 0xfffd, 0x0124}, 637 {0, 0x0000, 0x0127}, 638 {0, 0xfff8, 0x0124}, 639 {0, 0xfffd, 0x0124}, 640 {0, 0x0040, 0x0127}, 641 {0, 0xfff8, 0x0124}, 642 {0, 0xfffd, 0x0124}, 643 {0, 0xfffa, 0x0124}, 644 {0, 0xfff9, 0x0124}, 645 {0, 0x0086, 0x0127}, 646 {0, 0xfff8, 0x0124}, 647 {0, 0xfffd, 0x0124}, 648 {0, 0x0037, 0x0127}, 649 {0, 0xfff8, 0x0124}, 650 {0, 0xfffd, 0x0124}, 651 {0, 0x0000, 0x0127}, 652 {0, 0xfff8, 0x0124}, 653 {0, 0xfffd, 0x0124}, 654 {0, 0x0030, 0x0127}, 655 {0, 0xfff8, 0x0124}, 656 {0, 0xfffd, 0x0124}, 657 {0, 0xfffa, 0x0124}, 658 {0, 0xfff9, 0x0124}, 659 {0, 0x0086, 0x0127}, 660 {0, 0xfff8, 0x0124}, 661 {0, 0xfffd, 0x0124}, 662 {0, 0x0038, 0x0127}, 663 {0, 0xfff8, 0x0124}, 664 {0, 0xfffd, 0x0124}, 665 {0, 0x0008, 0x0127}, 666 {0, 0xfff8, 0x0124}, 667 {0, 0xfffd, 0x0124}, 668 {0, 0x0000, 0x0127}, 669 {0, 0xfff8, 0x0124}, 670 {0, 0xfffd, 0x0124}, 671 {0, 0xfffa, 0x0124}, 672 {0, 0x0003, 0x0111}, 673 }; 674 675 /* TESTME the old ibmcam driver repeats certain commands to Model1 cameras, we 676 do the same for now (testing needed to see if this is really necessary) */ 677 static const int cit_model1_ntries = 5; 678 static const int cit_model1_ntries2 = 2; 679 680 static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index) 681 { 682 struct usb_device *udev = gspca_dev->dev; 683 int err; 684 685 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 686 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 687 value, index, NULL, 0, 1000); 688 if (err < 0) 689 pr_err("Failed to write a register (index 0x%04X, value 0x%02X, error %d)\n", 690 index, value, err); 691 692 return 0; 693 } 694 695 static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index, int verbose) 696 { 697 struct usb_device *udev = gspca_dev->dev; 698 __u8 *buf = gspca_dev->usb_buf; 699 int res; 700 701 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x01, 702 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 703 0x00, index, buf, 8, 1000); 704 if (res < 0) { 705 pr_err("Failed to read a register (index 0x%04X, error %d)\n", 706 index, res); 707 return res; 708 } 709 710 if (verbose) 711 PDEBUG(D_PROBE, "Register %04x value: %02x", index, buf[0]); 712 713 return 0; 714 } 715 716 /* 717 * cit_send_FF_04_02() 718 * 719 * This procedure sends magic 3-command prefix to the camera. 720 * The purpose of this prefix is not known. 721 * 722 * History: 723 * 1/2/00 Created. 724 */ 725 static void cit_send_FF_04_02(struct gspca_dev *gspca_dev) 726 { 727 cit_write_reg(gspca_dev, 0x00FF, 0x0127); 728 cit_write_reg(gspca_dev, 0x0004, 0x0124); 729 cit_write_reg(gspca_dev, 0x0002, 0x0124); 730 } 731 732 static void cit_send_00_04_06(struct gspca_dev *gspca_dev) 733 { 734 cit_write_reg(gspca_dev, 0x0000, 0x0127); 735 cit_write_reg(gspca_dev, 0x0004, 0x0124); 736 cit_write_reg(gspca_dev, 0x0006, 0x0124); 737 } 738 739 static void cit_send_x_00(struct gspca_dev *gspca_dev, unsigned short x) 740 { 741 cit_write_reg(gspca_dev, x, 0x0127); 742 cit_write_reg(gspca_dev, 0x0000, 0x0124); 743 } 744 745 static void cit_send_x_00_05(struct gspca_dev *gspca_dev, unsigned short x) 746 { 747 cit_send_x_00(gspca_dev, x); 748 cit_write_reg(gspca_dev, 0x0005, 0x0124); 749 } 750 751 static void cit_send_x_00_05_02(struct gspca_dev *gspca_dev, unsigned short x) 752 { 753 cit_write_reg(gspca_dev, x, 0x0127); 754 cit_write_reg(gspca_dev, 0x0000, 0x0124); 755 cit_write_reg(gspca_dev, 0x0005, 0x0124); 756 cit_write_reg(gspca_dev, 0x0002, 0x0124); 757 } 758 759 static void cit_send_x_01_00_05(struct gspca_dev *gspca_dev, u16 x) 760 { 761 cit_write_reg(gspca_dev, x, 0x0127); 762 cit_write_reg(gspca_dev, 0x0001, 0x0124); 763 cit_write_reg(gspca_dev, 0x0000, 0x0124); 764 cit_write_reg(gspca_dev, 0x0005, 0x0124); 765 } 766 767 static void cit_send_x_00_05_02_01(struct gspca_dev *gspca_dev, u16 x) 768 { 769 cit_write_reg(gspca_dev, x, 0x0127); 770 cit_write_reg(gspca_dev, 0x0000, 0x0124); 771 cit_write_reg(gspca_dev, 0x0005, 0x0124); 772 cit_write_reg(gspca_dev, 0x0002, 0x0124); 773 cit_write_reg(gspca_dev, 0x0001, 0x0124); 774 } 775 776 static void cit_send_x_00_05_02_08_01(struct gspca_dev *gspca_dev, u16 x) 777 { 778 cit_write_reg(gspca_dev, x, 0x0127); 779 cit_write_reg(gspca_dev, 0x0000, 0x0124); 780 cit_write_reg(gspca_dev, 0x0005, 0x0124); 781 cit_write_reg(gspca_dev, 0x0002, 0x0124); 782 cit_write_reg(gspca_dev, 0x0008, 0x0124); 783 cit_write_reg(gspca_dev, 0x0001, 0x0124); 784 } 785 786 static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val) 787 { 788 cit_send_x_01_00_05(gspca_dev, 0x0088); 789 cit_send_x_00_05(gspca_dev, fkey); 790 cit_send_x_00_05_02_08_01(gspca_dev, val); 791 cit_send_x_00_05(gspca_dev, 0x0088); 792 cit_send_x_00_05_02_01(gspca_dev, fkey); 793 cit_send_x_00_05(gspca_dev, 0x0089); 794 cit_send_x_00(gspca_dev, fkey); 795 cit_send_00_04_06(gspca_dev); 796 cit_read_reg(gspca_dev, 0x0126, 0); 797 cit_send_FF_04_02(gspca_dev); 798 } 799 800 static void cit_PacketFormat2(struct gspca_dev *gspca_dev, u16 fkey, u16 val) 801 { 802 cit_send_x_01_00_05(gspca_dev, 0x0088); 803 cit_send_x_00_05(gspca_dev, fkey); 804 cit_send_x_00_05_02(gspca_dev, val); 805 } 806 807 static void cit_model2_Packet2(struct gspca_dev *gspca_dev) 808 { 809 cit_write_reg(gspca_dev, 0x00ff, 0x012d); 810 cit_write_reg(gspca_dev, 0xfea3, 0x0124); 811 } 812 813 static void cit_model2_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2) 814 { 815 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 816 cit_write_reg(gspca_dev, 0x00ff, 0x012e); 817 cit_write_reg(gspca_dev, v1, 0x012f); 818 cit_write_reg(gspca_dev, 0x00ff, 0x0130); 819 cit_write_reg(gspca_dev, 0xc719, 0x0124); 820 cit_write_reg(gspca_dev, v2, 0x0127); 821 822 cit_model2_Packet2(gspca_dev); 823 } 824 825 /* 826 * cit_model3_Packet1() 827 * 828 * 00_0078_012d 829 * 00_0097_012f 830 * 00_d141_0124 831 * 00_0096_0127 832 * 00_fea8_0124 833 */ 834 static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2) 835 { 836 cit_write_reg(gspca_dev, 0x0078, 0x012d); 837 cit_write_reg(gspca_dev, v1, 0x012f); 838 cit_write_reg(gspca_dev, 0xd141, 0x0124); 839 cit_write_reg(gspca_dev, v2, 0x0127); 840 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 841 } 842 843 static void cit_model4_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2) 844 { 845 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 846 cit_write_reg(gspca_dev, v1, 0x012f); 847 cit_write_reg(gspca_dev, 0xd141, 0x0124); 848 cit_write_reg(gspca_dev, v2, 0x0127); 849 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 850 } 851 852 static void cit_model4_BrightnessPacket(struct gspca_dev *gspca_dev, u16 val) 853 { 854 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 855 cit_write_reg(gspca_dev, 0x0026, 0x012f); 856 cit_write_reg(gspca_dev, 0xd141, 0x0124); 857 cit_write_reg(gspca_dev, val, 0x0127); 858 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 859 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 860 cit_write_reg(gspca_dev, 0x0038, 0x012d); 861 cit_write_reg(gspca_dev, 0x0004, 0x012f); 862 cit_write_reg(gspca_dev, 0xd145, 0x0124); 863 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 864 } 865 866 /* this function is called at probe time */ 867 static int sd_config(struct gspca_dev *gspca_dev, 868 const struct usb_device_id *id) 869 { 870 struct sd *sd = (struct sd *) gspca_dev; 871 struct cam *cam; 872 873 sd->model = id->driver_info; 874 if (sd->model == CIT_MODEL3 && ibm_netcam_pro) 875 sd->model = CIT_IBM_NETCAM_PRO; 876 877 cam = &gspca_dev->cam; 878 switch (sd->model) { 879 case CIT_MODEL0: 880 cam->cam_mode = model0_mode; 881 cam->nmodes = ARRAY_SIZE(model0_mode); 882 sd->sof_len = 4; 883 break; 884 case CIT_MODEL1: 885 cam->cam_mode = cif_yuv_mode; 886 cam->nmodes = ARRAY_SIZE(cif_yuv_mode); 887 sd->sof_len = 4; 888 break; 889 case CIT_MODEL2: 890 cam->cam_mode = model2_mode + 1; /* no 160x120 */ 891 cam->nmodes = 3; 892 break; 893 case CIT_MODEL3: 894 cam->cam_mode = vga_yuv_mode; 895 cam->nmodes = ARRAY_SIZE(vga_yuv_mode); 896 sd->stop_on_control_change = 1; 897 sd->sof_len = 4; 898 break; 899 case CIT_MODEL4: 900 cam->cam_mode = model2_mode; 901 cam->nmodes = ARRAY_SIZE(model2_mode); 902 break; 903 case CIT_IBM_NETCAM_PRO: 904 cam->cam_mode = vga_yuv_mode; 905 cam->nmodes = 2; /* no 640 x 480 */ 906 cam->input_flags = V4L2_IN_ST_VFLIP; 907 sd->stop_on_control_change = 1; 908 sd->sof_len = 4; 909 break; 910 } 911 912 return 0; 913 } 914 915 static int cit_init_model0(struct gspca_dev *gspca_dev) 916 { 917 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */ 918 cit_write_reg(gspca_dev, 0x0001, 0x0112); /* turn on autogain ? */ 919 cit_write_reg(gspca_dev, 0x0000, 0x0400); 920 cit_write_reg(gspca_dev, 0x0001, 0x0400); 921 cit_write_reg(gspca_dev, 0x0000, 0x0420); 922 cit_write_reg(gspca_dev, 0x0001, 0x0420); 923 cit_write_reg(gspca_dev, 0x000d, 0x0409); 924 cit_write_reg(gspca_dev, 0x0002, 0x040a); 925 cit_write_reg(gspca_dev, 0x0018, 0x0405); 926 cit_write_reg(gspca_dev, 0x0008, 0x0435); 927 cit_write_reg(gspca_dev, 0x0026, 0x040b); 928 cit_write_reg(gspca_dev, 0x0007, 0x0437); 929 cit_write_reg(gspca_dev, 0x0015, 0x042f); 930 cit_write_reg(gspca_dev, 0x002b, 0x0439); 931 cit_write_reg(gspca_dev, 0x0026, 0x043a); 932 cit_write_reg(gspca_dev, 0x0008, 0x0438); 933 cit_write_reg(gspca_dev, 0x001e, 0x042b); 934 cit_write_reg(gspca_dev, 0x0041, 0x042c); 935 936 return 0; 937 } 938 939 static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev) 940 { 941 cit_read_reg(gspca_dev, 0x128, 1); 942 cit_write_reg(gspca_dev, 0x0003, 0x0133); 943 cit_write_reg(gspca_dev, 0x0000, 0x0117); 944 cit_write_reg(gspca_dev, 0x0008, 0x0123); 945 cit_write_reg(gspca_dev, 0x0000, 0x0100); 946 cit_read_reg(gspca_dev, 0x0116, 0); 947 cit_write_reg(gspca_dev, 0x0060, 0x0116); 948 cit_write_reg(gspca_dev, 0x0002, 0x0112); 949 cit_write_reg(gspca_dev, 0x0000, 0x0133); 950 cit_write_reg(gspca_dev, 0x0000, 0x0123); 951 cit_write_reg(gspca_dev, 0x0001, 0x0117); 952 cit_write_reg(gspca_dev, 0x0040, 0x0108); 953 cit_write_reg(gspca_dev, 0x0019, 0x012c); 954 cit_write_reg(gspca_dev, 0x0060, 0x0116); 955 cit_write_reg(gspca_dev, 0x0002, 0x0115); 956 cit_write_reg(gspca_dev, 0x000b, 0x0115); 957 958 cit_write_reg(gspca_dev, 0x0078, 0x012d); 959 cit_write_reg(gspca_dev, 0x0001, 0x012f); 960 cit_write_reg(gspca_dev, 0xd141, 0x0124); 961 cit_write_reg(gspca_dev, 0x0079, 0x012d); 962 cit_write_reg(gspca_dev, 0x00ff, 0x0130); 963 cit_write_reg(gspca_dev, 0xcd41, 0x0124); 964 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 965 cit_read_reg(gspca_dev, 0x0126, 1); 966 967 cit_model3_Packet1(gspca_dev, 0x0000, 0x0000); 968 cit_model3_Packet1(gspca_dev, 0x0000, 0x0001); 969 cit_model3_Packet1(gspca_dev, 0x000b, 0x0000); 970 cit_model3_Packet1(gspca_dev, 0x000c, 0x0008); 971 cit_model3_Packet1(gspca_dev, 0x000d, 0x003a); 972 cit_model3_Packet1(gspca_dev, 0x000e, 0x0060); 973 cit_model3_Packet1(gspca_dev, 0x000f, 0x0060); 974 cit_model3_Packet1(gspca_dev, 0x0010, 0x0008); 975 cit_model3_Packet1(gspca_dev, 0x0011, 0x0004); 976 cit_model3_Packet1(gspca_dev, 0x0012, 0x0028); 977 cit_model3_Packet1(gspca_dev, 0x0013, 0x0002); 978 cit_model3_Packet1(gspca_dev, 0x0014, 0x0000); 979 cit_model3_Packet1(gspca_dev, 0x0015, 0x00fb); 980 cit_model3_Packet1(gspca_dev, 0x0016, 0x0002); 981 cit_model3_Packet1(gspca_dev, 0x0017, 0x0037); 982 cit_model3_Packet1(gspca_dev, 0x0018, 0x0036); 983 cit_model3_Packet1(gspca_dev, 0x001e, 0x0000); 984 cit_model3_Packet1(gspca_dev, 0x001f, 0x0008); 985 cit_model3_Packet1(gspca_dev, 0x0020, 0x00c1); 986 cit_model3_Packet1(gspca_dev, 0x0021, 0x0034); 987 cit_model3_Packet1(gspca_dev, 0x0022, 0x0034); 988 cit_model3_Packet1(gspca_dev, 0x0025, 0x0002); 989 cit_model3_Packet1(gspca_dev, 0x0028, 0x0022); 990 cit_model3_Packet1(gspca_dev, 0x0029, 0x000a); 991 cit_model3_Packet1(gspca_dev, 0x002b, 0x0000); 992 cit_model3_Packet1(gspca_dev, 0x002c, 0x0000); 993 cit_model3_Packet1(gspca_dev, 0x002d, 0x00ff); 994 cit_model3_Packet1(gspca_dev, 0x002e, 0x00ff); 995 cit_model3_Packet1(gspca_dev, 0x002f, 0x00ff); 996 cit_model3_Packet1(gspca_dev, 0x0030, 0x00ff); 997 cit_model3_Packet1(gspca_dev, 0x0031, 0x00ff); 998 cit_model3_Packet1(gspca_dev, 0x0032, 0x0007); 999 cit_model3_Packet1(gspca_dev, 0x0033, 0x0005); 1000 cit_model3_Packet1(gspca_dev, 0x0037, 0x0040); 1001 cit_model3_Packet1(gspca_dev, 0x0039, 0x0000); 1002 cit_model3_Packet1(gspca_dev, 0x003a, 0x0000); 1003 cit_model3_Packet1(gspca_dev, 0x003b, 0x0001); 1004 cit_model3_Packet1(gspca_dev, 0x003c, 0x0000); 1005 cit_model3_Packet1(gspca_dev, 0x0040, 0x000c); 1006 cit_model3_Packet1(gspca_dev, 0x0041, 0x00fb); 1007 cit_model3_Packet1(gspca_dev, 0x0042, 0x0002); 1008 cit_model3_Packet1(gspca_dev, 0x0043, 0x0000); 1009 cit_model3_Packet1(gspca_dev, 0x0045, 0x0000); 1010 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000); 1011 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000); 1012 cit_model3_Packet1(gspca_dev, 0x0048, 0x0000); 1013 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000); 1014 cit_model3_Packet1(gspca_dev, 0x004a, 0x00ff); 1015 cit_model3_Packet1(gspca_dev, 0x004b, 0x00ff); 1016 cit_model3_Packet1(gspca_dev, 0x004c, 0x00ff); 1017 cit_model3_Packet1(gspca_dev, 0x004f, 0x0000); 1018 cit_model3_Packet1(gspca_dev, 0x0050, 0x0000); 1019 cit_model3_Packet1(gspca_dev, 0x0051, 0x0002); 1020 cit_model3_Packet1(gspca_dev, 0x0055, 0x0000); 1021 cit_model3_Packet1(gspca_dev, 0x0056, 0x0000); 1022 cit_model3_Packet1(gspca_dev, 0x0057, 0x0000); 1023 cit_model3_Packet1(gspca_dev, 0x0058, 0x0002); 1024 cit_model3_Packet1(gspca_dev, 0x0059, 0x0000); 1025 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); 1026 cit_model3_Packet1(gspca_dev, 0x005d, 0x0022); 1027 cit_model3_Packet1(gspca_dev, 0x005e, 0x003c); 1028 cit_model3_Packet1(gspca_dev, 0x005f, 0x0050); 1029 cit_model3_Packet1(gspca_dev, 0x0060, 0x0044); 1030 cit_model3_Packet1(gspca_dev, 0x0061, 0x0005); 1031 cit_model3_Packet1(gspca_dev, 0x006a, 0x007e); 1032 cit_model3_Packet1(gspca_dev, 0x006f, 0x0000); 1033 cit_model3_Packet1(gspca_dev, 0x0072, 0x001b); 1034 cit_model3_Packet1(gspca_dev, 0x0073, 0x0005); 1035 cit_model3_Packet1(gspca_dev, 0x0074, 0x000a); 1036 cit_model3_Packet1(gspca_dev, 0x0075, 0x001b); 1037 cit_model3_Packet1(gspca_dev, 0x0076, 0x002a); 1038 cit_model3_Packet1(gspca_dev, 0x0077, 0x003c); 1039 cit_model3_Packet1(gspca_dev, 0x0078, 0x0050); 1040 cit_model3_Packet1(gspca_dev, 0x007b, 0x0000); 1041 cit_model3_Packet1(gspca_dev, 0x007c, 0x0011); 1042 cit_model3_Packet1(gspca_dev, 0x007d, 0x0024); 1043 cit_model3_Packet1(gspca_dev, 0x007e, 0x0043); 1044 cit_model3_Packet1(gspca_dev, 0x007f, 0x005a); 1045 cit_model3_Packet1(gspca_dev, 0x0084, 0x0020); 1046 cit_model3_Packet1(gspca_dev, 0x0085, 0x0033); 1047 cit_model3_Packet1(gspca_dev, 0x0086, 0x000a); 1048 cit_model3_Packet1(gspca_dev, 0x0087, 0x0030); 1049 cit_model3_Packet1(gspca_dev, 0x0088, 0x0070); 1050 cit_model3_Packet1(gspca_dev, 0x008b, 0x0008); 1051 cit_model3_Packet1(gspca_dev, 0x008f, 0x0000); 1052 cit_model3_Packet1(gspca_dev, 0x0090, 0x0006); 1053 cit_model3_Packet1(gspca_dev, 0x0091, 0x0028); 1054 cit_model3_Packet1(gspca_dev, 0x0092, 0x005a); 1055 cit_model3_Packet1(gspca_dev, 0x0093, 0x0082); 1056 cit_model3_Packet1(gspca_dev, 0x0096, 0x0014); 1057 cit_model3_Packet1(gspca_dev, 0x0097, 0x0020); 1058 cit_model3_Packet1(gspca_dev, 0x0098, 0x0000); 1059 cit_model3_Packet1(gspca_dev, 0x00b0, 0x0046); 1060 cit_model3_Packet1(gspca_dev, 0x00b1, 0x0000); 1061 cit_model3_Packet1(gspca_dev, 0x00b2, 0x0000); 1062 cit_model3_Packet1(gspca_dev, 0x00b3, 0x0004); 1063 cit_model3_Packet1(gspca_dev, 0x00b4, 0x0007); 1064 cit_model3_Packet1(gspca_dev, 0x00b6, 0x0002); 1065 cit_model3_Packet1(gspca_dev, 0x00b7, 0x0004); 1066 cit_model3_Packet1(gspca_dev, 0x00bb, 0x0000); 1067 cit_model3_Packet1(gspca_dev, 0x00bc, 0x0001); 1068 cit_model3_Packet1(gspca_dev, 0x00bd, 0x0000); 1069 cit_model3_Packet1(gspca_dev, 0x00bf, 0x0000); 1070 cit_model3_Packet1(gspca_dev, 0x00c0, 0x00c8); 1071 cit_model3_Packet1(gspca_dev, 0x00c1, 0x0014); 1072 cit_model3_Packet1(gspca_dev, 0x00c2, 0x0001); 1073 cit_model3_Packet1(gspca_dev, 0x00c3, 0x0000); 1074 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0004); 1075 cit_model3_Packet1(gspca_dev, 0x00cb, 0x00bf); 1076 cit_model3_Packet1(gspca_dev, 0x00cc, 0x00bf); 1077 cit_model3_Packet1(gspca_dev, 0x00cd, 0x00bf); 1078 cit_model3_Packet1(gspca_dev, 0x00ce, 0x0000); 1079 cit_model3_Packet1(gspca_dev, 0x00cf, 0x0020); 1080 cit_model3_Packet1(gspca_dev, 0x00d0, 0x0040); 1081 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf); 1082 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf); 1083 cit_model3_Packet1(gspca_dev, 0x00d2, 0x00bf); 1084 cit_model3_Packet1(gspca_dev, 0x00d3, 0x00bf); 1085 cit_model3_Packet1(gspca_dev, 0x00ea, 0x0008); 1086 cit_model3_Packet1(gspca_dev, 0x00eb, 0x0000); 1087 cit_model3_Packet1(gspca_dev, 0x00ec, 0x00e8); 1088 cit_model3_Packet1(gspca_dev, 0x00ed, 0x0001); 1089 cit_model3_Packet1(gspca_dev, 0x00ef, 0x0022); 1090 cit_model3_Packet1(gspca_dev, 0x00f0, 0x0000); 1091 cit_model3_Packet1(gspca_dev, 0x00f2, 0x0028); 1092 cit_model3_Packet1(gspca_dev, 0x00f4, 0x0002); 1093 cit_model3_Packet1(gspca_dev, 0x00f5, 0x0000); 1094 cit_model3_Packet1(gspca_dev, 0x00fa, 0x0000); 1095 cit_model3_Packet1(gspca_dev, 0x00fb, 0x0001); 1096 cit_model3_Packet1(gspca_dev, 0x00fc, 0x0000); 1097 cit_model3_Packet1(gspca_dev, 0x00fd, 0x0000); 1098 cit_model3_Packet1(gspca_dev, 0x00fe, 0x0000); 1099 cit_model3_Packet1(gspca_dev, 0x00ff, 0x0000); 1100 1101 cit_model3_Packet1(gspca_dev, 0x00be, 0x0003); 1102 cit_model3_Packet1(gspca_dev, 0x00c8, 0x0000); 1103 cit_model3_Packet1(gspca_dev, 0x00c9, 0x0020); 1104 cit_model3_Packet1(gspca_dev, 0x00ca, 0x0040); 1105 cit_model3_Packet1(gspca_dev, 0x0053, 0x0001); 1106 cit_model3_Packet1(gspca_dev, 0x0082, 0x000e); 1107 cit_model3_Packet1(gspca_dev, 0x0083, 0x0020); 1108 cit_model3_Packet1(gspca_dev, 0x0034, 0x003c); 1109 cit_model3_Packet1(gspca_dev, 0x006e, 0x0055); 1110 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); 1111 cit_model3_Packet1(gspca_dev, 0x0063, 0x0008); 1112 cit_model3_Packet1(gspca_dev, 0x0066, 0x000a); 1113 cit_model3_Packet1(gspca_dev, 0x0067, 0x0006); 1114 cit_model3_Packet1(gspca_dev, 0x006b, 0x0010); 1115 cit_model3_Packet1(gspca_dev, 0x005a, 0x0001); 1116 cit_model3_Packet1(gspca_dev, 0x005b, 0x000a); 1117 cit_model3_Packet1(gspca_dev, 0x0023, 0x0006); 1118 cit_model3_Packet1(gspca_dev, 0x0026, 0x0004); 1119 cit_model3_Packet1(gspca_dev, 0x0036, 0x0069); 1120 cit_model3_Packet1(gspca_dev, 0x0038, 0x0064); 1121 cit_model3_Packet1(gspca_dev, 0x003d, 0x0003); 1122 cit_model3_Packet1(gspca_dev, 0x003e, 0x0001); 1123 cit_model3_Packet1(gspca_dev, 0x00b8, 0x0014); 1124 cit_model3_Packet1(gspca_dev, 0x00b9, 0x0014); 1125 cit_model3_Packet1(gspca_dev, 0x00e6, 0x0004); 1126 cit_model3_Packet1(gspca_dev, 0x00e8, 0x0001); 1127 1128 return 0; 1129 } 1130 1131 /* this function is called at probe and resume time */ 1132 static int sd_init(struct gspca_dev *gspca_dev) 1133 { 1134 struct sd *sd = (struct sd *) gspca_dev; 1135 1136 switch (sd->model) { 1137 case CIT_MODEL0: 1138 cit_init_model0(gspca_dev); 1139 sd_stop0(gspca_dev); 1140 break; 1141 case CIT_MODEL1: 1142 case CIT_MODEL2: 1143 case CIT_MODEL3: 1144 case CIT_MODEL4: 1145 break; /* All is done in sd_start */ 1146 case CIT_IBM_NETCAM_PRO: 1147 cit_init_ibm_netcam_pro(gspca_dev); 1148 sd_stop0(gspca_dev); 1149 break; 1150 } 1151 return 0; 1152 } 1153 1154 static int cit_set_brightness(struct gspca_dev *gspca_dev, s32 val) 1155 { 1156 struct sd *sd = (struct sd *) gspca_dev; 1157 int i; 1158 1159 switch (sd->model) { 1160 case CIT_MODEL0: 1161 case CIT_IBM_NETCAM_PRO: 1162 /* No (known) brightness control for these */ 1163 break; 1164 case CIT_MODEL1: 1165 /* Model 1: Brightness range 0 - 63 */ 1166 cit_Packet_Format1(gspca_dev, 0x0031, val); 1167 cit_Packet_Format1(gspca_dev, 0x0032, val); 1168 cit_Packet_Format1(gspca_dev, 0x0033, val); 1169 break; 1170 case CIT_MODEL2: 1171 /* Model 2: Brightness range 0x60 - 0xee */ 1172 /* Scale 0 - 63 to 0x60 - 0xee */ 1173 i = 0x60 + val * 2254 / 1000; 1174 cit_model2_Packet1(gspca_dev, 0x001a, i); 1175 break; 1176 case CIT_MODEL3: 1177 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */ 1178 i = val; 1179 if (i < 0x0c) 1180 i = 0x0c; 1181 cit_model3_Packet1(gspca_dev, 0x0036, i); 1182 break; 1183 case CIT_MODEL4: 1184 /* Model 4: Brightness range 'i' in [0x04..0xb4] */ 1185 /* Scale 0 - 63 to 0x04 - 0xb4 */ 1186 i = 0x04 + val * 2794 / 1000; 1187 cit_model4_BrightnessPacket(gspca_dev, i); 1188 break; 1189 } 1190 1191 return 0; 1192 } 1193 1194 static int cit_set_contrast(struct gspca_dev *gspca_dev, s32 val) 1195 { 1196 struct sd *sd = (struct sd *) gspca_dev; 1197 1198 switch (sd->model) { 1199 case CIT_MODEL0: { 1200 int i; 1201 /* gain 0-15, 0-20 -> 0-15 */ 1202 i = val * 1000 / 1333; 1203 cit_write_reg(gspca_dev, i, 0x0422); 1204 /* gain 0-31, may not be lower then 0x0422, 0-20 -> 0-31 */ 1205 i = val * 2000 / 1333; 1206 cit_write_reg(gspca_dev, i, 0x0423); 1207 /* gain 0-127, may not be lower then 0x0423, 0-20 -> 0-63 */ 1208 i = val * 4000 / 1333; 1209 cit_write_reg(gspca_dev, i, 0x0424); 1210 /* gain 0-127, may not be lower then 0x0424, , 0-20 -> 0-127 */ 1211 i = val * 8000 / 1333; 1212 cit_write_reg(gspca_dev, i, 0x0425); 1213 break; 1214 } 1215 case CIT_MODEL2: 1216 case CIT_MODEL4: 1217 /* These models do not have this control. */ 1218 break; 1219 case CIT_MODEL1: 1220 { 1221 /* Scale 0 - 20 to 15 - 0 */ 1222 int i, new_contrast = (20 - val) * 1000 / 1333; 1223 for (i = 0; i < cit_model1_ntries; i++) { 1224 cit_Packet_Format1(gspca_dev, 0x0014, new_contrast); 1225 cit_send_FF_04_02(gspca_dev); 1226 } 1227 break; 1228 } 1229 case CIT_MODEL3: 1230 { /* Preset hardware values */ 1231 static const struct { 1232 unsigned short cv1; 1233 unsigned short cv2; 1234 unsigned short cv3; 1235 } cv[7] = { 1236 { 0x05, 0x05, 0x0f }, /* Minimum */ 1237 { 0x04, 0x04, 0x16 }, 1238 { 0x02, 0x03, 0x16 }, 1239 { 0x02, 0x08, 0x16 }, 1240 { 0x01, 0x0c, 0x16 }, 1241 { 0x01, 0x0e, 0x16 }, 1242 { 0x01, 0x10, 0x16 } /* Maximum */ 1243 }; 1244 int i = val / 3; 1245 cit_model3_Packet1(gspca_dev, 0x0067, cv[i].cv1); 1246 cit_model3_Packet1(gspca_dev, 0x005b, cv[i].cv2); 1247 cit_model3_Packet1(gspca_dev, 0x005c, cv[i].cv3); 1248 break; 1249 } 1250 case CIT_IBM_NETCAM_PRO: 1251 cit_model3_Packet1(gspca_dev, 0x005b, val + 1); 1252 break; 1253 } 1254 return 0; 1255 } 1256 1257 static int cit_set_hue(struct gspca_dev *gspca_dev, s32 val) 1258 { 1259 struct sd *sd = (struct sd *) gspca_dev; 1260 1261 switch (sd->model) { 1262 case CIT_MODEL0: 1263 case CIT_MODEL1: 1264 case CIT_IBM_NETCAM_PRO: 1265 /* No hue control for these models */ 1266 break; 1267 case CIT_MODEL2: 1268 cit_model2_Packet1(gspca_dev, 0x0024, val); 1269 /* cit_model2_Packet1(gspca_dev, 0x0020, sat); */ 1270 break; 1271 case CIT_MODEL3: { 1272 /* Model 3: Brightness range 'i' in [0x05..0x37] */ 1273 /* TESTME according to the ibmcam driver this does not work */ 1274 if (0) { 1275 /* Scale 0 - 127 to 0x05 - 0x37 */ 1276 int i = 0x05 + val * 1000 / 2540; 1277 cit_model3_Packet1(gspca_dev, 0x007e, i); 1278 } 1279 break; 1280 } 1281 case CIT_MODEL4: 1282 /* HDG: taken from ibmcam, setting the color gains does not 1283 * really belong here. 1284 * 1285 * I am not sure r/g/b_gain variables exactly control gain 1286 * of those channels. Most likely they subtly change some 1287 * very internal image processing settings in the camera. 1288 * In any case, here is what they do, and feel free to tweak: 1289 * 1290 * r_gain: seriously affects red gain 1291 * g_gain: seriously affects green gain 1292 * b_gain: seriously affects blue gain 1293 * hue: changes average color from violet (0) to red (0xFF) 1294 */ 1295 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 1296 cit_write_reg(gspca_dev, 0x001e, 0x012f); 1297 cit_write_reg(gspca_dev, 0xd141, 0x0124); 1298 cit_write_reg(gspca_dev, 160, 0x0127); /* Green gain */ 1299 cit_write_reg(gspca_dev, 160, 0x012e); /* Red gain */ 1300 cit_write_reg(gspca_dev, 160, 0x0130); /* Blue gain */ 1301 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 1302 cit_write_reg(gspca_dev, val, 0x012d); /* Hue */ 1303 cit_write_reg(gspca_dev, 0xf545, 0x0124); 1304 break; 1305 } 1306 return 0; 1307 } 1308 1309 static int cit_set_sharpness(struct gspca_dev *gspca_dev, s32 val) 1310 { 1311 struct sd *sd = (struct sd *) gspca_dev; 1312 1313 switch (sd->model) { 1314 case CIT_MODEL0: 1315 case CIT_MODEL2: 1316 case CIT_MODEL4: 1317 case CIT_IBM_NETCAM_PRO: 1318 /* These models do not have this control */ 1319 break; 1320 case CIT_MODEL1: { 1321 int i; 1322 const unsigned short sa[] = { 1323 0x11, 0x13, 0x16, 0x18, 0x1a, 0x8, 0x0a }; 1324 1325 for (i = 0; i < cit_model1_ntries; i++) 1326 cit_PacketFormat2(gspca_dev, 0x0013, sa[val]); 1327 break; 1328 } 1329 case CIT_MODEL3: 1330 { /* 1331 * "Use a table of magic numbers. 1332 * This setting doesn't really change much. 1333 * But that's how Windows does it." 1334 */ 1335 static const struct { 1336 unsigned short sv1; 1337 unsigned short sv2; 1338 unsigned short sv3; 1339 unsigned short sv4; 1340 } sv[7] = { 1341 { 0x00, 0x00, 0x05, 0x14 }, /* Smoothest */ 1342 { 0x01, 0x04, 0x05, 0x14 }, 1343 { 0x02, 0x04, 0x05, 0x14 }, 1344 { 0x03, 0x04, 0x05, 0x14 }, 1345 { 0x03, 0x05, 0x05, 0x14 }, 1346 { 0x03, 0x06, 0x05, 0x14 }, 1347 { 0x03, 0x07, 0x05, 0x14 } /* Sharpest */ 1348 }; 1349 cit_model3_Packet1(gspca_dev, 0x0060, sv[val].sv1); 1350 cit_model3_Packet1(gspca_dev, 0x0061, sv[val].sv2); 1351 cit_model3_Packet1(gspca_dev, 0x0062, sv[val].sv3); 1352 cit_model3_Packet1(gspca_dev, 0x0063, sv[val].sv4); 1353 break; 1354 } 1355 } 1356 return 0; 1357 } 1358 1359 /* 1360 * cit_set_lighting() 1361 * 1362 * Camera model 1: 1363 * We have 3 levels of lighting conditions: 0=Bright, 1=Medium, 2=Low. 1364 * 1365 * Camera model 2: 1366 * We have 16 levels of lighting, 0 for bright light and up to 15 for 1367 * low light. But values above 5 or so are useless because camera is 1368 * not really capable to produce anything worth viewing at such light. 1369 * This setting may be altered only in certain camera state. 1370 * 1371 * Low lighting forces slower FPS. 1372 * 1373 * History: 1374 * 1/5/00 Created. 1375 * 2/20/00 Added support for Model 2 cameras. 1376 */ 1377 static void cit_set_lighting(struct gspca_dev *gspca_dev, s32 val) 1378 { 1379 struct sd *sd = (struct sd *) gspca_dev; 1380 1381 switch (sd->model) { 1382 case CIT_MODEL0: 1383 case CIT_MODEL2: 1384 case CIT_MODEL3: 1385 case CIT_MODEL4: 1386 case CIT_IBM_NETCAM_PRO: 1387 break; 1388 case CIT_MODEL1: { 1389 int i; 1390 for (i = 0; i < cit_model1_ntries; i++) 1391 cit_Packet_Format1(gspca_dev, 0x0027, val); 1392 break; 1393 } 1394 } 1395 } 1396 1397 static void cit_set_hflip(struct gspca_dev *gspca_dev, s32 val) 1398 { 1399 struct sd *sd = (struct sd *) gspca_dev; 1400 1401 switch (sd->model) { 1402 case CIT_MODEL0: 1403 if (val) 1404 cit_write_reg(gspca_dev, 0x0020, 0x0115); 1405 else 1406 cit_write_reg(gspca_dev, 0x0040, 0x0115); 1407 break; 1408 case CIT_MODEL1: 1409 case CIT_MODEL2: 1410 case CIT_MODEL3: 1411 case CIT_MODEL4: 1412 case CIT_IBM_NETCAM_PRO: 1413 break; 1414 } 1415 } 1416 1417 static int cit_restart_stream(struct gspca_dev *gspca_dev) 1418 { 1419 struct sd *sd = (struct sd *) gspca_dev; 1420 1421 switch (sd->model) { 1422 case CIT_MODEL0: 1423 case CIT_MODEL1: 1424 cit_write_reg(gspca_dev, 0x0001, 0x0114); 1425 /* Fall through */ 1426 case CIT_MODEL2: 1427 case CIT_MODEL4: 1428 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */ 1429 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe); 1430 break; 1431 case CIT_MODEL3: 1432 case CIT_IBM_NETCAM_PRO: 1433 cit_write_reg(gspca_dev, 0x0001, 0x0114); 1434 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */ 1435 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe); 1436 /* Clear button events from while we were not streaming */ 1437 cit_write_reg(gspca_dev, 0x0001, 0x0113); 1438 break; 1439 } 1440 1441 sd->sof_read = 0; 1442 1443 return 0; 1444 } 1445 1446 static int cit_get_packet_size(struct gspca_dev *gspca_dev) 1447 { 1448 struct usb_host_interface *alt; 1449 struct usb_interface *intf; 1450 1451 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); 1452 alt = usb_altnum_to_altsetting(intf, gspca_dev->alt); 1453 if (!alt) { 1454 pr_err("Couldn't get altsetting\n"); 1455 return -EIO; 1456 } 1457 1458 return le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); 1459 } 1460 1461 /* Calculate the clockdiv giving us max fps given the available bandwidth */ 1462 static int cit_get_clock_div(struct gspca_dev *gspca_dev) 1463 { 1464 int clock_div = 7; /* 0=30 1=25 2=20 3=15 4=12 5=7.5 6=6 7=3fps ?? */ 1465 int fps[8] = { 30, 25, 20, 15, 12, 8, 6, 3 }; 1466 int packet_size; 1467 1468 packet_size = cit_get_packet_size(gspca_dev); 1469 if (packet_size < 0) 1470 return packet_size; 1471 1472 while (clock_div > 3 && 1473 1000 * packet_size > 1474 gspca_dev->pixfmt.width * gspca_dev->pixfmt.height * 1475 fps[clock_div - 1] * 3 / 2) 1476 clock_div--; 1477 1478 PDEBUG(D_PROBE, 1479 "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)", 1480 packet_size, gspca_dev->pixfmt.width, gspca_dev->pixfmt.height, 1481 clock_div, fps[clock_div]); 1482 1483 return clock_div; 1484 } 1485 1486 static int cit_start_model0(struct gspca_dev *gspca_dev) 1487 { 1488 const unsigned short compression = 0; /* 0=none, 7=best frame rate */ 1489 int clock_div; 1490 1491 clock_div = cit_get_clock_div(gspca_dev); 1492 if (clock_div < 0) 1493 return clock_div; 1494 1495 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */ 1496 cit_write_reg(gspca_dev, 0x0003, 0x0438); 1497 cit_write_reg(gspca_dev, 0x001e, 0x042b); 1498 cit_write_reg(gspca_dev, 0x0041, 0x042c); 1499 cit_write_reg(gspca_dev, 0x0008, 0x0436); 1500 cit_write_reg(gspca_dev, 0x0024, 0x0403); 1501 cit_write_reg(gspca_dev, 0x002c, 0x0404); 1502 cit_write_reg(gspca_dev, 0x0002, 0x0426); 1503 cit_write_reg(gspca_dev, 0x0014, 0x0427); 1504 1505 switch (gspca_dev->pixfmt.width) { 1506 case 160: /* 160x120 */ 1507 cit_write_reg(gspca_dev, 0x0004, 0x010b); 1508 cit_write_reg(gspca_dev, 0x0001, 0x010a); 1509 cit_write_reg(gspca_dev, 0x0010, 0x0102); 1510 cit_write_reg(gspca_dev, 0x00a0, 0x0103); 1511 cit_write_reg(gspca_dev, 0x0000, 0x0104); 1512 cit_write_reg(gspca_dev, 0x0078, 0x0105); 1513 break; 1514 1515 case 176: /* 176x144 */ 1516 cit_write_reg(gspca_dev, 0x0006, 0x010b); 1517 cit_write_reg(gspca_dev, 0x0000, 0x010a); 1518 cit_write_reg(gspca_dev, 0x0005, 0x0102); 1519 cit_write_reg(gspca_dev, 0x00b0, 0x0103); 1520 cit_write_reg(gspca_dev, 0x0000, 0x0104); 1521 cit_write_reg(gspca_dev, 0x0090, 0x0105); 1522 break; 1523 1524 case 320: /* 320x240 */ 1525 cit_write_reg(gspca_dev, 0x0008, 0x010b); 1526 cit_write_reg(gspca_dev, 0x0004, 0x010a); 1527 cit_write_reg(gspca_dev, 0x0005, 0x0102); 1528 cit_write_reg(gspca_dev, 0x00a0, 0x0103); 1529 cit_write_reg(gspca_dev, 0x0010, 0x0104); 1530 cit_write_reg(gspca_dev, 0x0078, 0x0105); 1531 break; 1532 } 1533 1534 cit_write_reg(gspca_dev, compression, 0x0109); 1535 cit_write_reg(gspca_dev, clock_div, 0x0111); 1536 1537 return 0; 1538 } 1539 1540 static int cit_start_model1(struct gspca_dev *gspca_dev) 1541 { 1542 struct sd *sd = (struct sd *) gspca_dev; 1543 int i, clock_div; 1544 1545 clock_div = cit_get_clock_div(gspca_dev); 1546 if (clock_div < 0) 1547 return clock_div; 1548 1549 cit_read_reg(gspca_dev, 0x0128, 1); 1550 cit_read_reg(gspca_dev, 0x0100, 0); 1551 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */ 1552 cit_read_reg(gspca_dev, 0x0100, 0); 1553 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */ 1554 cit_read_reg(gspca_dev, 0x0100, 0); 1555 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */ 1556 cit_write_reg(gspca_dev, 0x01, 0x0108); 1557 1558 cit_write_reg(gspca_dev, 0x03, 0x0112); 1559 cit_read_reg(gspca_dev, 0x0115, 0); 1560 cit_write_reg(gspca_dev, 0x06, 0x0115); 1561 cit_read_reg(gspca_dev, 0x0116, 0); 1562 cit_write_reg(gspca_dev, 0x44, 0x0116); 1563 cit_read_reg(gspca_dev, 0x0116, 0); 1564 cit_write_reg(gspca_dev, 0x40, 0x0116); 1565 cit_read_reg(gspca_dev, 0x0115, 0); 1566 cit_write_reg(gspca_dev, 0x0e, 0x0115); 1567 cit_write_reg(gspca_dev, 0x19, 0x012c); 1568 1569 cit_Packet_Format1(gspca_dev, 0x00, 0x1e); 1570 cit_Packet_Format1(gspca_dev, 0x39, 0x0d); 1571 cit_Packet_Format1(gspca_dev, 0x39, 0x09); 1572 cit_Packet_Format1(gspca_dev, 0x3b, 0x00); 1573 cit_Packet_Format1(gspca_dev, 0x28, 0x22); 1574 cit_Packet_Format1(gspca_dev, 0x27, 0x00); 1575 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f); 1576 cit_Packet_Format1(gspca_dev, 0x39, 0x08); 1577 1578 for (i = 0; i < cit_model1_ntries; i++) 1579 cit_Packet_Format1(gspca_dev, 0x2c, 0x00); 1580 1581 for (i = 0; i < cit_model1_ntries; i++) 1582 cit_Packet_Format1(gspca_dev, 0x30, 0x14); 1583 1584 cit_PacketFormat2(gspca_dev, 0x39, 0x02); 1585 cit_PacketFormat2(gspca_dev, 0x01, 0xe1); 1586 cit_PacketFormat2(gspca_dev, 0x02, 0xcd); 1587 cit_PacketFormat2(gspca_dev, 0x03, 0xcd); 1588 cit_PacketFormat2(gspca_dev, 0x04, 0xfa); 1589 cit_PacketFormat2(gspca_dev, 0x3f, 0xff); 1590 cit_PacketFormat2(gspca_dev, 0x39, 0x00); 1591 1592 cit_PacketFormat2(gspca_dev, 0x39, 0x02); 1593 cit_PacketFormat2(gspca_dev, 0x0a, 0x37); 1594 cit_PacketFormat2(gspca_dev, 0x0b, 0xb8); 1595 cit_PacketFormat2(gspca_dev, 0x0c, 0xf3); 1596 cit_PacketFormat2(gspca_dev, 0x0d, 0xe3); 1597 cit_PacketFormat2(gspca_dev, 0x0e, 0x0d); 1598 cit_PacketFormat2(gspca_dev, 0x0f, 0xf2); 1599 cit_PacketFormat2(gspca_dev, 0x10, 0xd5); 1600 cit_PacketFormat2(gspca_dev, 0x11, 0xba); 1601 cit_PacketFormat2(gspca_dev, 0x12, 0x53); 1602 cit_PacketFormat2(gspca_dev, 0x3f, 0xff); 1603 cit_PacketFormat2(gspca_dev, 0x39, 0x00); 1604 1605 cit_PacketFormat2(gspca_dev, 0x39, 0x02); 1606 cit_PacketFormat2(gspca_dev, 0x16, 0x00); 1607 cit_PacketFormat2(gspca_dev, 0x17, 0x28); 1608 cit_PacketFormat2(gspca_dev, 0x18, 0x7d); 1609 cit_PacketFormat2(gspca_dev, 0x19, 0xbe); 1610 cit_PacketFormat2(gspca_dev, 0x3f, 0xff); 1611 cit_PacketFormat2(gspca_dev, 0x39, 0x00); 1612 1613 for (i = 0; i < cit_model1_ntries; i++) 1614 cit_Packet_Format1(gspca_dev, 0x00, 0x18); 1615 for (i = 0; i < cit_model1_ntries; i++) 1616 cit_Packet_Format1(gspca_dev, 0x13, 0x18); 1617 for (i = 0; i < cit_model1_ntries; i++) 1618 cit_Packet_Format1(gspca_dev, 0x14, 0x06); 1619 1620 /* TESTME These are handled through controls 1621 KEEP until someone can test leaving this out is ok */ 1622 if (0) { 1623 /* This is default brightness */ 1624 for (i = 0; i < cit_model1_ntries; i++) 1625 cit_Packet_Format1(gspca_dev, 0x31, 0x37); 1626 for (i = 0; i < cit_model1_ntries; i++) 1627 cit_Packet_Format1(gspca_dev, 0x32, 0x46); 1628 for (i = 0; i < cit_model1_ntries; i++) 1629 cit_Packet_Format1(gspca_dev, 0x33, 0x55); 1630 } 1631 1632 cit_Packet_Format1(gspca_dev, 0x2e, 0x04); 1633 for (i = 0; i < cit_model1_ntries; i++) 1634 cit_Packet_Format1(gspca_dev, 0x2d, 0x04); 1635 for (i = 0; i < cit_model1_ntries; i++) 1636 cit_Packet_Format1(gspca_dev, 0x29, 0x80); 1637 cit_Packet_Format1(gspca_dev, 0x2c, 0x01); 1638 cit_Packet_Format1(gspca_dev, 0x30, 0x17); 1639 cit_Packet_Format1(gspca_dev, 0x39, 0x08); 1640 for (i = 0; i < cit_model1_ntries; i++) 1641 cit_Packet_Format1(gspca_dev, 0x34, 0x00); 1642 1643 cit_write_reg(gspca_dev, 0x00, 0x0101); 1644 cit_write_reg(gspca_dev, 0x00, 0x010a); 1645 1646 switch (gspca_dev->pixfmt.width) { 1647 case 128: /* 128x96 */ 1648 cit_write_reg(gspca_dev, 0x80, 0x0103); 1649 cit_write_reg(gspca_dev, 0x60, 0x0105); 1650 cit_write_reg(gspca_dev, 0x0c, 0x010b); 1651 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */ 1652 cit_write_reg(gspca_dev, 0x0b, 0x011d); 1653 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */ 1654 cit_write_reg(gspca_dev, 0x00, 0x0129); 1655 break; 1656 case 176: /* 176x144 */ 1657 cit_write_reg(gspca_dev, 0xb0, 0x0103); 1658 cit_write_reg(gspca_dev, 0x8f, 0x0105); 1659 cit_write_reg(gspca_dev, 0x06, 0x010b); 1660 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */ 1661 cit_write_reg(gspca_dev, 0x0d, 0x011d); 1662 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */ 1663 cit_write_reg(gspca_dev, 0x03, 0x0129); 1664 break; 1665 case 352: /* 352x288 */ 1666 cit_write_reg(gspca_dev, 0xb0, 0x0103); 1667 cit_write_reg(gspca_dev, 0x90, 0x0105); 1668 cit_write_reg(gspca_dev, 0x02, 0x010b); 1669 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */ 1670 cit_write_reg(gspca_dev, 0x05, 0x011d); 1671 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */ 1672 cit_write_reg(gspca_dev, 0x00, 0x0129); 1673 break; 1674 } 1675 1676 cit_write_reg(gspca_dev, 0xff, 0x012b); 1677 1678 /* TESTME These are handled through controls 1679 KEEP until someone can test leaving this out is ok */ 1680 if (0) { 1681 /* This is another brightness - don't know why */ 1682 for (i = 0; i < cit_model1_ntries; i++) 1683 cit_Packet_Format1(gspca_dev, 0x31, 0xc3); 1684 for (i = 0; i < cit_model1_ntries; i++) 1685 cit_Packet_Format1(gspca_dev, 0x32, 0xd2); 1686 for (i = 0; i < cit_model1_ntries; i++) 1687 cit_Packet_Format1(gspca_dev, 0x33, 0xe1); 1688 1689 /* Default contrast */ 1690 for (i = 0; i < cit_model1_ntries; i++) 1691 cit_Packet_Format1(gspca_dev, 0x14, 0x0a); 1692 1693 /* Default sharpness */ 1694 for (i = 0; i < cit_model1_ntries2; i++) 1695 cit_PacketFormat2(gspca_dev, 0x13, 0x1a); 1696 1697 /* Default lighting conditions */ 1698 cit_Packet_Format1(gspca_dev, 0x0027, 1699 v4l2_ctrl_g_ctrl(sd->lighting)); 1700 } 1701 1702 /* Assorted init */ 1703 switch (gspca_dev->pixfmt.width) { 1704 case 128: /* 128x96 */ 1705 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e); 1706 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */ 1707 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */ 1708 cit_write_reg(gspca_dev, 0x36, 0x0102); 1709 cit_write_reg(gspca_dev, 0x1a, 0x0104); 1710 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */ 1711 cit_write_reg(gspca_dev, 0x2b, 0x011c); 1712 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */ 1713 break; 1714 case 176: /* 176x144 */ 1715 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e); 1716 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */ 1717 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */ 1718 cit_write_reg(gspca_dev, 0x04, 0x0102); 1719 cit_write_reg(gspca_dev, 0x02, 0x0104); 1720 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */ 1721 cit_write_reg(gspca_dev, 0x2b, 0x011c); 1722 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */ 1723 break; 1724 case 352: /* 352x288 */ 1725 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f); 1726 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */ 1727 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */ 1728 cit_write_reg(gspca_dev, 0x08, 0x0102); 1729 cit_write_reg(gspca_dev, 0x01, 0x0104); 1730 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */ 1731 cit_write_reg(gspca_dev, 0x2f, 0x011c); 1732 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */ 1733 break; 1734 } 1735 1736 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */ 1737 cit_write_reg(gspca_dev, clock_div, 0x0111); 1738 1739 return 0; 1740 } 1741 1742 static int cit_start_model2(struct gspca_dev *gspca_dev) 1743 { 1744 struct sd *sd = (struct sd *) gspca_dev; 1745 int clock_div = 0; 1746 1747 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */ 1748 cit_read_reg(gspca_dev, 0x0116, 0); 1749 cit_write_reg(gspca_dev, 0x0060, 0x0116); 1750 cit_write_reg(gspca_dev, 0x0002, 0x0112); 1751 cit_write_reg(gspca_dev, 0x00bc, 0x012c); 1752 cit_write_reg(gspca_dev, 0x0008, 0x012b); 1753 cit_write_reg(gspca_dev, 0x0000, 0x0108); 1754 cit_write_reg(gspca_dev, 0x0001, 0x0133); 1755 cit_write_reg(gspca_dev, 0x0001, 0x0102); 1756 switch (gspca_dev->pixfmt.width) { 1757 case 176: /* 176x144 */ 1758 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */ 1759 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */ 1760 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */ 1761 cit_write_reg(gspca_dev, 0x00b9, 0x010a); /* Unique to this mode */ 1762 cit_write_reg(gspca_dev, 0x0038, 0x0119); /* Unique to this mode */ 1763 /* TESTME HDG: this does not seem right 1764 (it is 2 for all other resolutions) */ 1765 sd->sof_len = 10; 1766 break; 1767 case 320: /* 320x240 */ 1768 cit_write_reg(gspca_dev, 0x0028, 0x0103); /* Unique to this mode */ 1769 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */ 1770 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */ 1771 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */ 1772 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */ 1773 sd->sof_len = 2; 1774 break; 1775 #if 0 1776 case VIDEOSIZE_352x240: 1777 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */ 1778 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */ 1779 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */ 1780 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */ 1781 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */ 1782 sd->sof_len = 2; 1783 break; 1784 #endif 1785 case 352: /* 352x288 */ 1786 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */ 1787 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */ 1788 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */ 1789 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */ 1790 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */ 1791 sd->sof_len = 2; 1792 break; 1793 } 1794 1795 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */ 1796 1797 switch (gspca_dev->pixfmt.width) { 1798 case 176: /* 176x144 */ 1799 cit_write_reg(gspca_dev, 0x0050, 0x0111); 1800 cit_write_reg(gspca_dev, 0x00d0, 0x0111); 1801 break; 1802 case 320: /* 320x240 */ 1803 case 352: /* 352x288 */ 1804 cit_write_reg(gspca_dev, 0x0040, 0x0111); 1805 cit_write_reg(gspca_dev, 0x00c0, 0x0111); 1806 break; 1807 } 1808 cit_write_reg(gspca_dev, 0x009b, 0x010f); 1809 cit_write_reg(gspca_dev, 0x00bb, 0x010f); 1810 1811 /* 1812 * Hardware settings, may affect CMOS sensor; not user controls! 1813 * ------------------------------------------------------------- 1814 * 0x0004: no effect 1815 * 0x0006: hardware effect 1816 * 0x0008: no effect 1817 * 0x000a: stops video stream, probably important h/w setting 1818 * 0x000c: changes color in hardware manner (not user setting) 1819 * 0x0012: changes number of colors (does not affect speed) 1820 * 0x002a: no effect 1821 * 0x002c: hardware setting (related to scan lines) 1822 * 0x002e: stops video stream, probably important h/w setting 1823 */ 1824 cit_model2_Packet1(gspca_dev, 0x000a, 0x005c); 1825 cit_model2_Packet1(gspca_dev, 0x0004, 0x0000); 1826 cit_model2_Packet1(gspca_dev, 0x0006, 0x00fb); 1827 cit_model2_Packet1(gspca_dev, 0x0008, 0x0000); 1828 cit_model2_Packet1(gspca_dev, 0x000c, 0x0009); 1829 cit_model2_Packet1(gspca_dev, 0x0012, 0x000a); 1830 cit_model2_Packet1(gspca_dev, 0x002a, 0x0000); 1831 cit_model2_Packet1(gspca_dev, 0x002c, 0x0000); 1832 cit_model2_Packet1(gspca_dev, 0x002e, 0x0008); 1833 1834 /* 1835 * Function 0x0030 pops up all over the place. Apparently 1836 * it is a hardware control register, with every bit assigned to 1837 * do something. 1838 */ 1839 cit_model2_Packet1(gspca_dev, 0x0030, 0x0000); 1840 1841 /* 1842 * Magic control of CMOS sensor. Only lower values like 1843 * 0-3 work, and picture shifts left or right. Don't change. 1844 */ 1845 switch (gspca_dev->pixfmt.width) { 1846 case 176: /* 176x144 */ 1847 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002); 1848 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */ 1849 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */ 1850 clock_div = 6; 1851 break; 1852 case 320: /* 320x240 */ 1853 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); 1854 cit_model2_Packet1(gspca_dev, 0x0016, 0x0005); /* Horizontal shift */ 1855 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */ 1856 clock_div = 8; 1857 break; 1858 #if 0 1859 case VIDEOSIZE_352x240: 1860 /* This mode doesn't work as Windows programs it; changed to work */ 1861 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */ 1862 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */ 1863 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */ 1864 clock_div = 10; 1865 break; 1866 #endif 1867 case 352: /* 352x288 */ 1868 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003); 1869 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */ 1870 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */ 1871 clock_div = 16; 1872 break; 1873 } 1874 1875 /* TESTME These are handled through controls 1876 KEEP until someone can test leaving this out is ok */ 1877 if (0) 1878 cit_model2_Packet1(gspca_dev, 0x001a, 0x005a); 1879 1880 /* 1881 * We have our own frame rate setting varying from 0 (slowest) to 6 1882 * (fastest). The camera model 2 allows frame rate in range [0..0x1F] 1883 # where 0 is also the slowest setting. However for all practical 1884 # reasons high settings make no sense because USB is not fast enough 1885 # to support high FPS. Be aware that the picture datastream will be 1886 # severely disrupted if you ask for frame rate faster than allowed 1887 # for the video size - see below: 1888 * 1889 * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz): 1890 * ----------------------------------------------------------------- 1891 * 176x144: [6..31] 1892 * 320x240: [8..31] 1893 * 352x240: [10..31] 1894 * 352x288: [16..31] I have to raise lower threshold for stability... 1895 * 1896 * As usual, slower FPS provides better sensitivity. 1897 */ 1898 cit_model2_Packet1(gspca_dev, 0x001c, clock_div); 1899 1900 /* 1901 * This setting does not visibly affect pictures; left it here 1902 * because it was present in Windows USB data stream. This function 1903 * does not allow arbitrary values and apparently is a bit mask, to 1904 * be activated only at appropriate time. Don't change it randomly! 1905 */ 1906 switch (gspca_dev->pixfmt.width) { 1907 case 176: /* 176x144 */ 1908 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2); 1909 break; 1910 case 320: /* 320x240 */ 1911 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044); 1912 break; 1913 #if 0 1914 case VIDEOSIZE_352x240: 1915 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046); 1916 break; 1917 #endif 1918 case 352: /* 352x288 */ 1919 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048); 1920 break; 1921 } 1922 1923 cit_model2_Packet1(gspca_dev, 0x0028, v4l2_ctrl_g_ctrl(sd->lighting)); 1924 /* model2 cannot change the backlight compensation while streaming */ 1925 v4l2_ctrl_grab(sd->lighting, true); 1926 1927 /* color balance rg2 */ 1928 cit_model2_Packet1(gspca_dev, 0x001e, 0x002f); 1929 /* saturation */ 1930 cit_model2_Packet1(gspca_dev, 0x0020, 0x0034); 1931 /* color balance yb */ 1932 cit_model2_Packet1(gspca_dev, 0x0022, 0x00a0); 1933 1934 /* Hardware control command */ 1935 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004); 1936 1937 return 0; 1938 } 1939 1940 static int cit_start_model3(struct gspca_dev *gspca_dev) 1941 { 1942 const unsigned short compression = 0; /* 0=none, 7=best frame rate */ 1943 int i, clock_div = 0; 1944 1945 /* HDG not in ibmcam driver, added to see if it helps with 1946 auto-detecting between model3 and ibm netcamera pro */ 1947 cit_read_reg(gspca_dev, 0x128, 1); 1948 1949 cit_write_reg(gspca_dev, 0x0000, 0x0100); 1950 cit_read_reg(gspca_dev, 0x0116, 0); 1951 cit_write_reg(gspca_dev, 0x0060, 0x0116); 1952 cit_write_reg(gspca_dev, 0x0002, 0x0112); 1953 cit_write_reg(gspca_dev, 0x0000, 0x0123); 1954 cit_write_reg(gspca_dev, 0x0001, 0x0117); 1955 cit_write_reg(gspca_dev, 0x0040, 0x0108); 1956 cit_write_reg(gspca_dev, 0x0019, 0x012c); 1957 cit_write_reg(gspca_dev, 0x0060, 0x0116); 1958 cit_write_reg(gspca_dev, 0x0002, 0x0115); 1959 cit_write_reg(gspca_dev, 0x0003, 0x0115); 1960 cit_read_reg(gspca_dev, 0x0115, 0); 1961 cit_write_reg(gspca_dev, 0x000b, 0x0115); 1962 1963 /* TESTME HDG not in ibmcam driver, added to see if it helps with 1964 auto-detecting between model3 and ibm netcamera pro */ 1965 if (0) { 1966 cit_write_reg(gspca_dev, 0x0078, 0x012d); 1967 cit_write_reg(gspca_dev, 0x0001, 0x012f); 1968 cit_write_reg(gspca_dev, 0xd141, 0x0124); 1969 cit_write_reg(gspca_dev, 0x0079, 0x012d); 1970 cit_write_reg(gspca_dev, 0x00ff, 0x0130); 1971 cit_write_reg(gspca_dev, 0xcd41, 0x0124); 1972 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 1973 cit_read_reg(gspca_dev, 0x0126, 1); 1974 } 1975 1976 cit_model3_Packet1(gspca_dev, 0x000a, 0x0040); 1977 cit_model3_Packet1(gspca_dev, 0x000b, 0x00f6); 1978 cit_model3_Packet1(gspca_dev, 0x000c, 0x0002); 1979 cit_model3_Packet1(gspca_dev, 0x000d, 0x0020); 1980 cit_model3_Packet1(gspca_dev, 0x000e, 0x0033); 1981 cit_model3_Packet1(gspca_dev, 0x000f, 0x0007); 1982 cit_model3_Packet1(gspca_dev, 0x0010, 0x0000); 1983 cit_model3_Packet1(gspca_dev, 0x0011, 0x0070); 1984 cit_model3_Packet1(gspca_dev, 0x0012, 0x0030); 1985 cit_model3_Packet1(gspca_dev, 0x0013, 0x0000); 1986 cit_model3_Packet1(gspca_dev, 0x0014, 0x0001); 1987 cit_model3_Packet1(gspca_dev, 0x0015, 0x0001); 1988 cit_model3_Packet1(gspca_dev, 0x0016, 0x0001); 1989 cit_model3_Packet1(gspca_dev, 0x0017, 0x0001); 1990 cit_model3_Packet1(gspca_dev, 0x0018, 0x0000); 1991 cit_model3_Packet1(gspca_dev, 0x001e, 0x00c3); 1992 cit_model3_Packet1(gspca_dev, 0x0020, 0x0000); 1993 cit_model3_Packet1(gspca_dev, 0x0028, 0x0010); 1994 cit_model3_Packet1(gspca_dev, 0x0029, 0x0054); 1995 cit_model3_Packet1(gspca_dev, 0x002a, 0x0013); 1996 cit_model3_Packet1(gspca_dev, 0x002b, 0x0007); 1997 cit_model3_Packet1(gspca_dev, 0x002d, 0x0028); 1998 cit_model3_Packet1(gspca_dev, 0x002e, 0x0000); 1999 cit_model3_Packet1(gspca_dev, 0x0031, 0x0000); 2000 cit_model3_Packet1(gspca_dev, 0x0032, 0x0000); 2001 cit_model3_Packet1(gspca_dev, 0x0033, 0x0000); 2002 cit_model3_Packet1(gspca_dev, 0x0034, 0x0000); 2003 cit_model3_Packet1(gspca_dev, 0x0035, 0x0038); 2004 cit_model3_Packet1(gspca_dev, 0x003a, 0x0001); 2005 cit_model3_Packet1(gspca_dev, 0x003c, 0x001e); 2006 cit_model3_Packet1(gspca_dev, 0x003f, 0x000a); 2007 cit_model3_Packet1(gspca_dev, 0x0041, 0x0000); 2008 cit_model3_Packet1(gspca_dev, 0x0046, 0x003f); 2009 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000); 2010 cit_model3_Packet1(gspca_dev, 0x0050, 0x0005); 2011 cit_model3_Packet1(gspca_dev, 0x0052, 0x001a); 2012 cit_model3_Packet1(gspca_dev, 0x0053, 0x0003); 2013 cit_model3_Packet1(gspca_dev, 0x005a, 0x006b); 2014 cit_model3_Packet1(gspca_dev, 0x005d, 0x001e); 2015 cit_model3_Packet1(gspca_dev, 0x005e, 0x0030); 2016 cit_model3_Packet1(gspca_dev, 0x005f, 0x0041); 2017 cit_model3_Packet1(gspca_dev, 0x0064, 0x0008); 2018 cit_model3_Packet1(gspca_dev, 0x0065, 0x0015); 2019 cit_model3_Packet1(gspca_dev, 0x0068, 0x000f); 2020 cit_model3_Packet1(gspca_dev, 0x0079, 0x0000); 2021 cit_model3_Packet1(gspca_dev, 0x007a, 0x0000); 2022 cit_model3_Packet1(gspca_dev, 0x007c, 0x003f); 2023 cit_model3_Packet1(gspca_dev, 0x0082, 0x000f); 2024 cit_model3_Packet1(gspca_dev, 0x0085, 0x0000); 2025 cit_model3_Packet1(gspca_dev, 0x0099, 0x0000); 2026 cit_model3_Packet1(gspca_dev, 0x009b, 0x0023); 2027 cit_model3_Packet1(gspca_dev, 0x009c, 0x0022); 2028 cit_model3_Packet1(gspca_dev, 0x009d, 0x0096); 2029 cit_model3_Packet1(gspca_dev, 0x009e, 0x0096); 2030 cit_model3_Packet1(gspca_dev, 0x009f, 0x000a); 2031 2032 switch (gspca_dev->pixfmt.width) { 2033 case 160: 2034 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */ 2035 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */ 2036 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */ 2037 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ 2038 cit_write_reg(gspca_dev, 0x0024, 0x010b); /* Differs everywhere */ 2039 cit_write_reg(gspca_dev, 0x00a9, 0x0119); 2040 cit_write_reg(gspca_dev, 0x0016, 0x011b); 2041 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */ 2042 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */ 2043 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ 2044 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ 2045 cit_write_reg(gspca_dev, 0x0018, 0x0102); 2046 cit_write_reg(gspca_dev, 0x0004, 0x0104); 2047 cit_write_reg(gspca_dev, 0x0004, 0x011a); 2048 cit_write_reg(gspca_dev, 0x0028, 0x011c); 2049 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ 2050 cit_write_reg(gspca_dev, 0x0000, 0x0118); 2051 cit_write_reg(gspca_dev, 0x0000, 0x0132); 2052 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */ 2053 cit_write_reg(gspca_dev, compression, 0x0109); 2054 clock_div = 3; 2055 break; 2056 case 320: 2057 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */ 2058 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */ 2059 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */ 2060 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ 2061 cit_write_reg(gspca_dev, 0x0028, 0x010b); /* Differs everywhere */ 2062 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same */ 2063 cit_write_reg(gspca_dev, 0x0000, 0x011e); 2064 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ 2065 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ 2066 /* 4 commands from 160x120 skipped */ 2067 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ 2068 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */ 2069 cit_write_reg(gspca_dev, compression, 0x0109); 2070 cit_write_reg(gspca_dev, 0x00d9, 0x0119); 2071 cit_write_reg(gspca_dev, 0x0006, 0x011b); 2072 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */ 2073 cit_write_reg(gspca_dev, 0x0010, 0x0104); 2074 cit_write_reg(gspca_dev, 0x0004, 0x011a); 2075 cit_write_reg(gspca_dev, 0x003f, 0x011c); 2076 cit_write_reg(gspca_dev, 0x001c, 0x0118); 2077 cit_write_reg(gspca_dev, 0x0000, 0x0132); 2078 clock_div = 5; 2079 break; 2080 case 640: 2081 cit_write_reg(gspca_dev, 0x00f0, 0x0105); 2082 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ 2083 cit_write_reg(gspca_dev, 0x0038, 0x010b); /* Differs everywhere */ 2084 cit_write_reg(gspca_dev, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */ 2085 cit_write_reg(gspca_dev, 0x0006, 0x011b); /* Same on 320x240, 640x480 */ 2086 cit_write_reg(gspca_dev, 0x0004, 0x011d); /* NC */ 2087 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */ 2088 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ 2089 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ 2090 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */ 2091 cit_write_reg(gspca_dev, 0x0016, 0x0104); /* NC */ 2092 cit_write_reg(gspca_dev, 0x0004, 0x011a); /* Same on 320x240, 640x480 */ 2093 cit_write_reg(gspca_dev, 0x003f, 0x011c); /* Same on 320x240, 640x480 */ 2094 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ 2095 cit_write_reg(gspca_dev, 0x001c, 0x0118); /* Same on 320x240, 640x480 */ 2096 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */ 2097 cit_write_reg(gspca_dev, compression, 0x0109); 2098 cit_write_reg(gspca_dev, 0x0040, 0x0101); 2099 cit_write_reg(gspca_dev, 0x0040, 0x0103); 2100 cit_write_reg(gspca_dev, 0x0000, 0x0132); /* Same on 320x240, 640x480 */ 2101 clock_div = 7; 2102 break; 2103 } 2104 2105 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); /* Hue */ 2106 cit_model3_Packet1(gspca_dev, 0x0036, 0x0011); /* Brightness */ 2107 cit_model3_Packet1(gspca_dev, 0x0060, 0x0002); /* Sharpness */ 2108 cit_model3_Packet1(gspca_dev, 0x0061, 0x0004); /* Sharpness */ 2109 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); /* Sharpness */ 2110 cit_model3_Packet1(gspca_dev, 0x0063, 0x0014); /* Sharpness */ 2111 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */ 2112 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */ 2113 cit_model3_Packet1(gspca_dev, 0x0067, 0x0001); /* Contrast */ 2114 cit_model3_Packet1(gspca_dev, 0x005b, 0x000c); /* Contrast */ 2115 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); /* Contrast */ 2116 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b); 2117 cit_model3_Packet1(gspca_dev, 0x002c, 0x0003); /* Was 1, broke 640x480 */ 2118 cit_model3_Packet1(gspca_dev, 0x002f, 0x002a); 2119 cit_model3_Packet1(gspca_dev, 0x0030, 0x0029); 2120 cit_model3_Packet1(gspca_dev, 0x0037, 0x0002); 2121 cit_model3_Packet1(gspca_dev, 0x0038, 0x0059); 2122 cit_model3_Packet1(gspca_dev, 0x003d, 0x002e); 2123 cit_model3_Packet1(gspca_dev, 0x003e, 0x0028); 2124 cit_model3_Packet1(gspca_dev, 0x0078, 0x0005); 2125 cit_model3_Packet1(gspca_dev, 0x007b, 0x0011); 2126 cit_model3_Packet1(gspca_dev, 0x007d, 0x004b); 2127 cit_model3_Packet1(gspca_dev, 0x007f, 0x0022); 2128 cit_model3_Packet1(gspca_dev, 0x0080, 0x000c); 2129 cit_model3_Packet1(gspca_dev, 0x0081, 0x000b); 2130 cit_model3_Packet1(gspca_dev, 0x0083, 0x00fd); 2131 cit_model3_Packet1(gspca_dev, 0x0086, 0x000b); 2132 cit_model3_Packet1(gspca_dev, 0x0087, 0x000b); 2133 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); 2134 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */ 2135 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */ 2136 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b); 2137 2138 /* FIXME we should probably use cit_get_clock_div() here (in 2139 combination with isoc negotiation using the programmable isoc size) 2140 like with the IBM netcam pro). */ 2141 cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */ 2142 2143 switch (gspca_dev->pixfmt.width) { 2144 case 160: 2145 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */ 2146 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */ 2147 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */ 2148 cit_model3_Packet1(gspca_dev, 0x0040, 0x000a); 2149 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a); 2150 break; 2151 case 320: 2152 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */ 2153 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */ 2154 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */ 2155 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008); 2156 cit_model3_Packet1(gspca_dev, 0x0051, 0x000b); 2157 break; 2158 case 640: 2159 cit_model3_Packet1(gspca_dev, 0x001f, 0x0002); /* !Same */ 2160 cit_model3_Packet1(gspca_dev, 0x0039, 0x003e); /* !Same */ 2161 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008); 2162 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a); 2163 break; 2164 } 2165 2166 /* if (sd->input_index) { */ 2167 if (rca_input) { 2168 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) { 2169 if (rca_initdata[i][0]) 2170 cit_read_reg(gspca_dev, rca_initdata[i][2], 0); 2171 else 2172 cit_write_reg(gspca_dev, rca_initdata[i][1], 2173 rca_initdata[i][2]); 2174 } 2175 } 2176 2177 return 0; 2178 } 2179 2180 static int cit_start_model4(struct gspca_dev *gspca_dev) 2181 { 2182 struct sd *sd = (struct sd *) gspca_dev; 2183 2184 cit_write_reg(gspca_dev, 0x0000, 0x0100); 2185 cit_write_reg(gspca_dev, 0x00c0, 0x0111); 2186 cit_write_reg(gspca_dev, 0x00bc, 0x012c); 2187 cit_write_reg(gspca_dev, 0x0080, 0x012b); 2188 cit_write_reg(gspca_dev, 0x0000, 0x0108); 2189 cit_write_reg(gspca_dev, 0x0001, 0x0133); 2190 cit_write_reg(gspca_dev, 0x009b, 0x010f); 2191 cit_write_reg(gspca_dev, 0x00bb, 0x010f); 2192 cit_model4_Packet1(gspca_dev, 0x0038, 0x0000); 2193 cit_model4_Packet1(gspca_dev, 0x000a, 0x005c); 2194 2195 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2196 cit_write_reg(gspca_dev, 0x0004, 0x012f); 2197 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2198 cit_write_reg(gspca_dev, 0x0000, 0x0127); 2199 cit_write_reg(gspca_dev, 0x00fb, 0x012e); 2200 cit_write_reg(gspca_dev, 0x0000, 0x0130); 2201 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2202 cit_write_reg(gspca_dev, 0x00aa, 0x012f); 2203 cit_write_reg(gspca_dev, 0xd055, 0x0124); 2204 cit_write_reg(gspca_dev, 0x000c, 0x0127); 2205 cit_write_reg(gspca_dev, 0x0009, 0x012e); 2206 cit_write_reg(gspca_dev, 0xaa28, 0x0124); 2207 2208 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2209 cit_write_reg(gspca_dev, 0x0012, 0x012f); 2210 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2211 cit_write_reg(gspca_dev, 0x0008, 0x0127); 2212 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2213 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2214 cit_write_reg(gspca_dev, 0x002a, 0x012d); 2215 cit_write_reg(gspca_dev, 0x0000, 0x012f); 2216 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2217 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2218 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000); 2219 2220 switch (gspca_dev->pixfmt.width) { 2221 case 128: /* 128x96 */ 2222 cit_write_reg(gspca_dev, 0x0070, 0x0119); 2223 cit_write_reg(gspca_dev, 0x00d0, 0x0111); 2224 cit_write_reg(gspca_dev, 0x0039, 0x010a); 2225 cit_write_reg(gspca_dev, 0x0001, 0x0102); 2226 cit_write_reg(gspca_dev, 0x0028, 0x0103); 2227 cit_write_reg(gspca_dev, 0x0000, 0x0104); 2228 cit_write_reg(gspca_dev, 0x001e, 0x0105); 2229 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2230 cit_write_reg(gspca_dev, 0x0016, 0x012f); 2231 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2232 cit_write_reg(gspca_dev, 0x000a, 0x0127); 2233 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2234 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2235 cit_write_reg(gspca_dev, 0x0014, 0x012d); 2236 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2237 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2238 cit_write_reg(gspca_dev, 0x00aa, 0x012e); 2239 cit_write_reg(gspca_dev, 0x001a, 0x0130); 2240 cit_write_reg(gspca_dev, 0x8a0a, 0x0124); 2241 cit_write_reg(gspca_dev, 0x005a, 0x012d); 2242 cit_write_reg(gspca_dev, 0x9545, 0x0124); 2243 cit_write_reg(gspca_dev, 0x00aa, 0x0127); 2244 cit_write_reg(gspca_dev, 0x0018, 0x012e); 2245 cit_write_reg(gspca_dev, 0x0043, 0x0130); 2246 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2247 cit_write_reg(gspca_dev, 0x00aa, 0x012f); 2248 cit_write_reg(gspca_dev, 0xd055, 0x0124); 2249 cit_write_reg(gspca_dev, 0x001c, 0x0127); 2250 cit_write_reg(gspca_dev, 0x00eb, 0x012e); 2251 cit_write_reg(gspca_dev, 0xaa28, 0x0124); 2252 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2253 cit_write_reg(gspca_dev, 0x0032, 0x012f); 2254 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2255 cit_write_reg(gspca_dev, 0x0000, 0x0127); 2256 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2257 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2258 cit_write_reg(gspca_dev, 0x0036, 0x012d); 2259 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2260 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2261 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2262 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2263 cit_write_reg(gspca_dev, 0x001e, 0x012f); 2264 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2265 cit_write_reg(gspca_dev, 0x0017, 0x0127); 2266 cit_write_reg(gspca_dev, 0x0013, 0x012e); 2267 cit_write_reg(gspca_dev, 0x0031, 0x0130); 2268 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2269 cit_write_reg(gspca_dev, 0x0017, 0x012d); 2270 cit_write_reg(gspca_dev, 0x0078, 0x012f); 2271 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2272 cit_write_reg(gspca_dev, 0x0000, 0x0127); 2273 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 2274 sd->sof_len = 2; 2275 break; 2276 case 160: /* 160x120 */ 2277 cit_write_reg(gspca_dev, 0x0038, 0x0119); 2278 cit_write_reg(gspca_dev, 0x00d0, 0x0111); 2279 cit_write_reg(gspca_dev, 0x00b9, 0x010a); 2280 cit_write_reg(gspca_dev, 0x0001, 0x0102); 2281 cit_write_reg(gspca_dev, 0x0028, 0x0103); 2282 cit_write_reg(gspca_dev, 0x0000, 0x0104); 2283 cit_write_reg(gspca_dev, 0x001e, 0x0105); 2284 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2285 cit_write_reg(gspca_dev, 0x0016, 0x012f); 2286 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2287 cit_write_reg(gspca_dev, 0x000b, 0x0127); 2288 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2289 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2290 cit_write_reg(gspca_dev, 0x0014, 0x012d); 2291 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2292 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2293 cit_write_reg(gspca_dev, 0x00aa, 0x012e); 2294 cit_write_reg(gspca_dev, 0x001a, 0x0130); 2295 cit_write_reg(gspca_dev, 0x8a0a, 0x0124); 2296 cit_write_reg(gspca_dev, 0x005a, 0x012d); 2297 cit_write_reg(gspca_dev, 0x9545, 0x0124); 2298 cit_write_reg(gspca_dev, 0x00aa, 0x0127); 2299 cit_write_reg(gspca_dev, 0x0018, 0x012e); 2300 cit_write_reg(gspca_dev, 0x0043, 0x0130); 2301 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2302 cit_write_reg(gspca_dev, 0x00aa, 0x012f); 2303 cit_write_reg(gspca_dev, 0xd055, 0x0124); 2304 cit_write_reg(gspca_dev, 0x001c, 0x0127); 2305 cit_write_reg(gspca_dev, 0x00c7, 0x012e); 2306 cit_write_reg(gspca_dev, 0xaa28, 0x0124); 2307 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2308 cit_write_reg(gspca_dev, 0x0032, 0x012f); 2309 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2310 cit_write_reg(gspca_dev, 0x0025, 0x0127); 2311 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2312 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2313 cit_write_reg(gspca_dev, 0x0036, 0x012d); 2314 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2315 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2316 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2317 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2318 cit_write_reg(gspca_dev, 0x001e, 0x012f); 2319 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2320 cit_write_reg(gspca_dev, 0x0048, 0x0127); 2321 cit_write_reg(gspca_dev, 0x0035, 0x012e); 2322 cit_write_reg(gspca_dev, 0x00d0, 0x0130); 2323 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2324 cit_write_reg(gspca_dev, 0x0048, 0x012d); 2325 cit_write_reg(gspca_dev, 0x0090, 0x012f); 2326 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2327 cit_write_reg(gspca_dev, 0x0001, 0x0127); 2328 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 2329 sd->sof_len = 2; 2330 break; 2331 case 176: /* 176x144 */ 2332 cit_write_reg(gspca_dev, 0x0038, 0x0119); 2333 cit_write_reg(gspca_dev, 0x00d0, 0x0111); 2334 cit_write_reg(gspca_dev, 0x00b9, 0x010a); 2335 cit_write_reg(gspca_dev, 0x0001, 0x0102); 2336 cit_write_reg(gspca_dev, 0x002c, 0x0103); 2337 cit_write_reg(gspca_dev, 0x0000, 0x0104); 2338 cit_write_reg(gspca_dev, 0x0024, 0x0105); 2339 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2340 cit_write_reg(gspca_dev, 0x0016, 0x012f); 2341 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2342 cit_write_reg(gspca_dev, 0x0007, 0x0127); 2343 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2344 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2345 cit_write_reg(gspca_dev, 0x0014, 0x012d); 2346 cit_write_reg(gspca_dev, 0x0001, 0x012f); 2347 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2348 cit_write_reg(gspca_dev, 0x00aa, 0x012e); 2349 cit_write_reg(gspca_dev, 0x001a, 0x0130); 2350 cit_write_reg(gspca_dev, 0x8a0a, 0x0124); 2351 cit_write_reg(gspca_dev, 0x005e, 0x012d); 2352 cit_write_reg(gspca_dev, 0x9545, 0x0124); 2353 cit_write_reg(gspca_dev, 0x00aa, 0x0127); 2354 cit_write_reg(gspca_dev, 0x0018, 0x012e); 2355 cit_write_reg(gspca_dev, 0x0049, 0x0130); 2356 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2357 cit_write_reg(gspca_dev, 0x00aa, 0x012f); 2358 cit_write_reg(gspca_dev, 0xd055, 0x0124); 2359 cit_write_reg(gspca_dev, 0x001c, 0x0127); 2360 cit_write_reg(gspca_dev, 0x00c7, 0x012e); 2361 cit_write_reg(gspca_dev, 0xaa28, 0x0124); 2362 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2363 cit_write_reg(gspca_dev, 0x0032, 0x012f); 2364 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2365 cit_write_reg(gspca_dev, 0x0028, 0x0127); 2366 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2367 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2368 cit_write_reg(gspca_dev, 0x0036, 0x012d); 2369 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2370 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2371 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2372 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2373 cit_write_reg(gspca_dev, 0x001e, 0x012f); 2374 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2375 cit_write_reg(gspca_dev, 0x0010, 0x0127); 2376 cit_write_reg(gspca_dev, 0x0013, 0x012e); 2377 cit_write_reg(gspca_dev, 0x002a, 0x0130); 2378 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2379 cit_write_reg(gspca_dev, 0x0010, 0x012d); 2380 cit_write_reg(gspca_dev, 0x006d, 0x012f); 2381 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2382 cit_write_reg(gspca_dev, 0x0001, 0x0127); 2383 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 2384 /* TESTME HDG: this does not seem right 2385 (it is 2 for all other resolutions) */ 2386 sd->sof_len = 10; 2387 break; 2388 case 320: /* 320x240 */ 2389 cit_write_reg(gspca_dev, 0x0070, 0x0119); 2390 cit_write_reg(gspca_dev, 0x00d0, 0x0111); 2391 cit_write_reg(gspca_dev, 0x0039, 0x010a); 2392 cit_write_reg(gspca_dev, 0x0001, 0x0102); 2393 cit_write_reg(gspca_dev, 0x0028, 0x0103); 2394 cit_write_reg(gspca_dev, 0x0000, 0x0104); 2395 cit_write_reg(gspca_dev, 0x001e, 0x0105); 2396 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2397 cit_write_reg(gspca_dev, 0x0016, 0x012f); 2398 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2399 cit_write_reg(gspca_dev, 0x000a, 0x0127); 2400 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2401 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2402 cit_write_reg(gspca_dev, 0x0014, 0x012d); 2403 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2404 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2405 cit_write_reg(gspca_dev, 0x00aa, 0x012e); 2406 cit_write_reg(gspca_dev, 0x001a, 0x0130); 2407 cit_write_reg(gspca_dev, 0x8a0a, 0x0124); 2408 cit_write_reg(gspca_dev, 0x005a, 0x012d); 2409 cit_write_reg(gspca_dev, 0x9545, 0x0124); 2410 cit_write_reg(gspca_dev, 0x00aa, 0x0127); 2411 cit_write_reg(gspca_dev, 0x0018, 0x012e); 2412 cit_write_reg(gspca_dev, 0x0043, 0x0130); 2413 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2414 cit_write_reg(gspca_dev, 0x00aa, 0x012f); 2415 cit_write_reg(gspca_dev, 0xd055, 0x0124); 2416 cit_write_reg(gspca_dev, 0x001c, 0x0127); 2417 cit_write_reg(gspca_dev, 0x00eb, 0x012e); 2418 cit_write_reg(gspca_dev, 0xaa28, 0x0124); 2419 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2420 cit_write_reg(gspca_dev, 0x0032, 0x012f); 2421 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2422 cit_write_reg(gspca_dev, 0x0000, 0x0127); 2423 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2424 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2425 cit_write_reg(gspca_dev, 0x0036, 0x012d); 2426 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2427 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2428 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2429 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2430 cit_write_reg(gspca_dev, 0x001e, 0x012f); 2431 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2432 cit_write_reg(gspca_dev, 0x0017, 0x0127); 2433 cit_write_reg(gspca_dev, 0x0013, 0x012e); 2434 cit_write_reg(gspca_dev, 0x0031, 0x0130); 2435 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2436 cit_write_reg(gspca_dev, 0x0017, 0x012d); 2437 cit_write_reg(gspca_dev, 0x0078, 0x012f); 2438 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2439 cit_write_reg(gspca_dev, 0x0000, 0x0127); 2440 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 2441 sd->sof_len = 2; 2442 break; 2443 case 352: /* 352x288 */ 2444 cit_write_reg(gspca_dev, 0x0070, 0x0119); 2445 cit_write_reg(gspca_dev, 0x00c0, 0x0111); 2446 cit_write_reg(gspca_dev, 0x0039, 0x010a); 2447 cit_write_reg(gspca_dev, 0x0001, 0x0102); 2448 cit_write_reg(gspca_dev, 0x002c, 0x0103); 2449 cit_write_reg(gspca_dev, 0x0000, 0x0104); 2450 cit_write_reg(gspca_dev, 0x0024, 0x0105); 2451 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2452 cit_write_reg(gspca_dev, 0x0016, 0x012f); 2453 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2454 cit_write_reg(gspca_dev, 0x0006, 0x0127); 2455 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2456 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2457 cit_write_reg(gspca_dev, 0x0014, 0x012d); 2458 cit_write_reg(gspca_dev, 0x0002, 0x012f); 2459 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2460 cit_write_reg(gspca_dev, 0x00aa, 0x012e); 2461 cit_write_reg(gspca_dev, 0x001a, 0x0130); 2462 cit_write_reg(gspca_dev, 0x8a0a, 0x0124); 2463 cit_write_reg(gspca_dev, 0x005e, 0x012d); 2464 cit_write_reg(gspca_dev, 0x9545, 0x0124); 2465 cit_write_reg(gspca_dev, 0x00aa, 0x0127); 2466 cit_write_reg(gspca_dev, 0x0018, 0x012e); 2467 cit_write_reg(gspca_dev, 0x0049, 0x0130); 2468 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2469 cit_write_reg(gspca_dev, 0x00aa, 0x012f); 2470 cit_write_reg(gspca_dev, 0xd055, 0x0124); 2471 cit_write_reg(gspca_dev, 0x001c, 0x0127); 2472 cit_write_reg(gspca_dev, 0x00cf, 0x012e); 2473 cit_write_reg(gspca_dev, 0xaa28, 0x0124); 2474 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2475 cit_write_reg(gspca_dev, 0x0032, 0x012f); 2476 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2477 cit_write_reg(gspca_dev, 0x0000, 0x0127); 2478 cit_write_reg(gspca_dev, 0x00aa, 0x0130); 2479 cit_write_reg(gspca_dev, 0x82a8, 0x0124); 2480 cit_write_reg(gspca_dev, 0x0036, 0x012d); 2481 cit_write_reg(gspca_dev, 0x0008, 0x012f); 2482 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2483 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2484 cit_write_reg(gspca_dev, 0x00aa, 0x012d); 2485 cit_write_reg(gspca_dev, 0x001e, 0x012f); 2486 cit_write_reg(gspca_dev, 0xd141, 0x0124); 2487 cit_write_reg(gspca_dev, 0x0010, 0x0127); 2488 cit_write_reg(gspca_dev, 0x0013, 0x012e); 2489 cit_write_reg(gspca_dev, 0x0025, 0x0130); 2490 cit_write_reg(gspca_dev, 0x8a28, 0x0124); 2491 cit_write_reg(gspca_dev, 0x0010, 0x012d); 2492 cit_write_reg(gspca_dev, 0x0048, 0x012f); 2493 cit_write_reg(gspca_dev, 0xd145, 0x0124); 2494 cit_write_reg(gspca_dev, 0x0000, 0x0127); 2495 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 2496 sd->sof_len = 2; 2497 break; 2498 } 2499 2500 cit_model4_Packet1(gspca_dev, 0x0038, 0x0004); 2501 2502 return 0; 2503 } 2504 2505 static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev) 2506 { 2507 const unsigned short compression = 0; /* 0=none, 7=best frame rate */ 2508 int i, clock_div; 2509 2510 clock_div = cit_get_clock_div(gspca_dev); 2511 if (clock_div < 0) 2512 return clock_div; 2513 2514 cit_write_reg(gspca_dev, 0x0003, 0x0133); 2515 cit_write_reg(gspca_dev, 0x0000, 0x0117); 2516 cit_write_reg(gspca_dev, 0x0008, 0x0123); 2517 cit_write_reg(gspca_dev, 0x0000, 0x0100); 2518 cit_write_reg(gspca_dev, 0x0060, 0x0116); 2519 /* cit_write_reg(gspca_dev, 0x0002, 0x0112); see sd_stop0 */ 2520 cit_write_reg(gspca_dev, 0x0000, 0x0133); 2521 cit_write_reg(gspca_dev, 0x0000, 0x0123); 2522 cit_write_reg(gspca_dev, 0x0001, 0x0117); 2523 cit_write_reg(gspca_dev, 0x0040, 0x0108); 2524 cit_write_reg(gspca_dev, 0x0019, 0x012c); 2525 cit_write_reg(gspca_dev, 0x0060, 0x0116); 2526 /* cit_write_reg(gspca_dev, 0x000b, 0x0115); see sd_stop0 */ 2527 2528 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000); 2529 2530 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */ 2531 cit_write_reg(gspca_dev, 0x003a, 0x0102); /* Hstart */ 2532 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */ 2533 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */ 2534 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ 2535 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */ 2536 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ 2537 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ 2538 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ 2539 2540 switch (gspca_dev->pixfmt.width) { 2541 case 160: /* 160x120 */ 2542 cit_write_reg(gspca_dev, 0x0024, 0x010b); 2543 cit_write_reg(gspca_dev, 0x0089, 0x0119); 2544 cit_write_reg(gspca_dev, 0x000a, 0x011b); 2545 cit_write_reg(gspca_dev, 0x0003, 0x011e); 2546 cit_write_reg(gspca_dev, 0x0007, 0x0104); 2547 cit_write_reg(gspca_dev, 0x0009, 0x011a); 2548 cit_write_reg(gspca_dev, 0x008b, 0x011c); 2549 cit_write_reg(gspca_dev, 0x0008, 0x0118); 2550 cit_write_reg(gspca_dev, 0x0000, 0x0132); 2551 break; 2552 case 320: /* 320x240 */ 2553 cit_write_reg(gspca_dev, 0x0028, 0x010b); 2554 cit_write_reg(gspca_dev, 0x00d9, 0x0119); 2555 cit_write_reg(gspca_dev, 0x0006, 0x011b); 2556 cit_write_reg(gspca_dev, 0x0000, 0x011e); 2557 cit_write_reg(gspca_dev, 0x000e, 0x0104); 2558 cit_write_reg(gspca_dev, 0x0004, 0x011a); 2559 cit_write_reg(gspca_dev, 0x003f, 0x011c); 2560 cit_write_reg(gspca_dev, 0x000c, 0x0118); 2561 cit_write_reg(gspca_dev, 0x0000, 0x0132); 2562 break; 2563 } 2564 2565 cit_model3_Packet1(gspca_dev, 0x0019, 0x0031); 2566 cit_model3_Packet1(gspca_dev, 0x001a, 0x0003); 2567 cit_model3_Packet1(gspca_dev, 0x001b, 0x0038); 2568 cit_model3_Packet1(gspca_dev, 0x001c, 0x0000); 2569 cit_model3_Packet1(gspca_dev, 0x0024, 0x0001); 2570 cit_model3_Packet1(gspca_dev, 0x0027, 0x0001); 2571 cit_model3_Packet1(gspca_dev, 0x002a, 0x0004); 2572 cit_model3_Packet1(gspca_dev, 0x0035, 0x000b); 2573 cit_model3_Packet1(gspca_dev, 0x003f, 0x0001); 2574 cit_model3_Packet1(gspca_dev, 0x0044, 0x0000); 2575 cit_model3_Packet1(gspca_dev, 0x0054, 0x0000); 2576 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0000); 2577 cit_model3_Packet1(gspca_dev, 0x00e7, 0x0001); 2578 cit_model3_Packet1(gspca_dev, 0x00e9, 0x0001); 2579 cit_model3_Packet1(gspca_dev, 0x00ee, 0x0000); 2580 cit_model3_Packet1(gspca_dev, 0x00f3, 0x00c0); 2581 2582 cit_write_reg(gspca_dev, compression, 0x0109); 2583 cit_write_reg(gspca_dev, clock_div, 0x0111); 2584 2585 /* if (sd->input_index) { */ 2586 if (rca_input) { 2587 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) { 2588 if (rca_initdata[i][0]) 2589 cit_read_reg(gspca_dev, rca_initdata[i][2], 0); 2590 else 2591 cit_write_reg(gspca_dev, rca_initdata[i][1], 2592 rca_initdata[i][2]); 2593 } 2594 } 2595 2596 return 0; 2597 } 2598 2599 /* -- start the camera -- */ 2600 static int sd_start(struct gspca_dev *gspca_dev) 2601 { 2602 struct sd *sd = (struct sd *) gspca_dev; 2603 int packet_size; 2604 2605 packet_size = cit_get_packet_size(gspca_dev); 2606 if (packet_size < 0) 2607 return packet_size; 2608 2609 switch (sd->model) { 2610 case CIT_MODEL0: 2611 cit_start_model0(gspca_dev); 2612 break; 2613 case CIT_MODEL1: 2614 cit_start_model1(gspca_dev); 2615 break; 2616 case CIT_MODEL2: 2617 cit_start_model2(gspca_dev); 2618 break; 2619 case CIT_MODEL3: 2620 cit_start_model3(gspca_dev); 2621 break; 2622 case CIT_MODEL4: 2623 cit_start_model4(gspca_dev); 2624 break; 2625 case CIT_IBM_NETCAM_PRO: 2626 cit_start_ibm_netcam_pro(gspca_dev); 2627 break; 2628 } 2629 2630 /* Program max isoc packet size */ 2631 cit_write_reg(gspca_dev, packet_size >> 8, 0x0106); 2632 cit_write_reg(gspca_dev, packet_size & 0xff, 0x0107); 2633 2634 cit_restart_stream(gspca_dev); 2635 2636 return 0; 2637 } 2638 2639 static int sd_isoc_init(struct gspca_dev *gspca_dev) 2640 { 2641 struct usb_host_interface *alt; 2642 int max_packet_size; 2643 2644 switch (gspca_dev->pixfmt.width) { 2645 case 160: 2646 max_packet_size = 450; 2647 break; 2648 case 176: 2649 max_packet_size = 600; 2650 break; 2651 default: 2652 max_packet_size = 1022; 2653 break; 2654 } 2655 2656 /* Start isoc bandwidth "negotiation" at max isoc bandwidth */ 2657 alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1]; 2658 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(max_packet_size); 2659 2660 return 0; 2661 } 2662 2663 static int sd_isoc_nego(struct gspca_dev *gspca_dev) 2664 { 2665 int ret, packet_size, min_packet_size; 2666 struct usb_host_interface *alt; 2667 2668 switch (gspca_dev->pixfmt.width) { 2669 case 160: 2670 min_packet_size = 200; 2671 break; 2672 case 176: 2673 min_packet_size = 266; 2674 break; 2675 default: 2676 min_packet_size = 400; 2677 break; 2678 } 2679 2680 alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1]; 2681 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); 2682 if (packet_size <= min_packet_size) 2683 return -EIO; 2684 2685 packet_size -= 100; 2686 if (packet_size < min_packet_size) 2687 packet_size = min_packet_size; 2688 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size); 2689 2690 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); 2691 if (ret < 0) 2692 pr_err("set alt 1 err %d\n", ret); 2693 2694 return ret; 2695 } 2696 2697 static void sd_stopN(struct gspca_dev *gspca_dev) 2698 { 2699 cit_write_reg(gspca_dev, 0x0000, 0x010c); 2700 } 2701 2702 static void sd_stop0(struct gspca_dev *gspca_dev) 2703 { 2704 struct sd *sd = (struct sd *) gspca_dev; 2705 2706 if (!gspca_dev->present) 2707 return; 2708 2709 switch (sd->model) { 2710 case CIT_MODEL0: 2711 /* HDG windows does this, but it causes the cams autogain to 2712 restart from a gain of 0, which does not look good when 2713 changing resolutions. */ 2714 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */ 2715 cit_write_reg(gspca_dev, 0x00c0, 0x0100); /* LED Off */ 2716 break; 2717 case CIT_MODEL1: 2718 cit_send_FF_04_02(gspca_dev); 2719 cit_read_reg(gspca_dev, 0x0100, 0); 2720 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */ 2721 break; 2722 case CIT_MODEL2: 2723 v4l2_ctrl_grab(sd->lighting, false); 2724 /* Fall through! */ 2725 case CIT_MODEL4: 2726 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004); 2727 2728 cit_write_reg(gspca_dev, 0x0080, 0x0100); /* LED Off */ 2729 cit_write_reg(gspca_dev, 0x0020, 0x0111); 2730 cit_write_reg(gspca_dev, 0x00a0, 0x0111); 2731 2732 cit_model2_Packet1(gspca_dev, 0x0030, 0x0002); 2733 2734 cit_write_reg(gspca_dev, 0x0020, 0x0111); 2735 cit_write_reg(gspca_dev, 0x0000, 0x0112); 2736 break; 2737 case CIT_MODEL3: 2738 cit_write_reg(gspca_dev, 0x0006, 0x012c); 2739 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000); 2740 cit_read_reg(gspca_dev, 0x0116, 0); 2741 cit_write_reg(gspca_dev, 0x0064, 0x0116); 2742 cit_read_reg(gspca_dev, 0x0115, 0); 2743 cit_write_reg(gspca_dev, 0x0003, 0x0115); 2744 cit_write_reg(gspca_dev, 0x0008, 0x0123); 2745 cit_write_reg(gspca_dev, 0x0000, 0x0117); 2746 cit_write_reg(gspca_dev, 0x0000, 0x0112); 2747 cit_write_reg(gspca_dev, 0x0080, 0x0100); 2748 break; 2749 case CIT_IBM_NETCAM_PRO: 2750 cit_model3_Packet1(gspca_dev, 0x0049, 0x00ff); 2751 cit_write_reg(gspca_dev, 0x0006, 0x012c); 2752 cit_write_reg(gspca_dev, 0x0000, 0x0116); 2753 /* HDG windows does this, but I cannot get the camera 2754 to restart with this without redoing the entire init 2755 sequence which makes switching modes really slow */ 2756 /* cit_write_reg(gspca_dev, 0x0006, 0x0115); */ 2757 cit_write_reg(gspca_dev, 0x0008, 0x0123); 2758 cit_write_reg(gspca_dev, 0x0000, 0x0117); 2759 cit_write_reg(gspca_dev, 0x0003, 0x0133); 2760 cit_write_reg(gspca_dev, 0x0000, 0x0111); 2761 /* HDG windows does this, but I get a green picture when 2762 restarting the stream after this */ 2763 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */ 2764 cit_write_reg(gspca_dev, 0x00c0, 0x0100); 2765 break; 2766 } 2767 2768 #if IS_ENABLED(CONFIG_INPUT) 2769 /* If the last button state is pressed, release it now! */ 2770 if (sd->button_state) { 2771 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); 2772 input_sync(gspca_dev->input_dev); 2773 sd->button_state = 0; 2774 } 2775 #endif 2776 } 2777 2778 static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len) 2779 { 2780 struct sd *sd = (struct sd *) gspca_dev; 2781 u8 byte3 = 0, byte4 = 0; 2782 int i; 2783 2784 switch (sd->model) { 2785 case CIT_MODEL0: 2786 case CIT_MODEL1: 2787 case CIT_MODEL3: 2788 case CIT_IBM_NETCAM_PRO: 2789 switch (gspca_dev->pixfmt.width) { 2790 case 160: /* 160x120 */ 2791 byte3 = 0x02; 2792 byte4 = 0x0a; 2793 break; 2794 case 176: /* 176x144 */ 2795 byte3 = 0x02; 2796 byte4 = 0x0e; 2797 break; 2798 case 320: /* 320x240 */ 2799 byte3 = 0x02; 2800 byte4 = 0x08; 2801 break; 2802 case 352: /* 352x288 */ 2803 byte3 = 0x02; 2804 byte4 = 0x00; 2805 break; 2806 case 640: 2807 byte3 = 0x03; 2808 byte4 = 0x08; 2809 break; 2810 } 2811 2812 /* These have a different byte3 */ 2813 if (sd->model <= CIT_MODEL1) 2814 byte3 = 0x00; 2815 2816 for (i = 0; i < len; i++) { 2817 /* For this model the SOF always starts at offset 0 2818 so no need to search the entire frame */ 2819 if (sd->model == CIT_MODEL0 && sd->sof_read != i) 2820 break; 2821 2822 switch (sd->sof_read) { 2823 case 0: 2824 if (data[i] == 0x00) 2825 sd->sof_read++; 2826 break; 2827 case 1: 2828 if (data[i] == 0xff) 2829 sd->sof_read++; 2830 else if (data[i] == 0x00) 2831 sd->sof_read = 1; 2832 else 2833 sd->sof_read = 0; 2834 break; 2835 case 2: 2836 if (data[i] == byte3) 2837 sd->sof_read++; 2838 else if (data[i] == 0x00) 2839 sd->sof_read = 1; 2840 else 2841 sd->sof_read = 0; 2842 break; 2843 case 3: 2844 if (data[i] == byte4) { 2845 sd->sof_read = 0; 2846 return data + i + (sd->sof_len - 3); 2847 } 2848 if (byte3 == 0x00 && data[i] == 0xff) 2849 sd->sof_read = 2; 2850 else if (data[i] == 0x00) 2851 sd->sof_read = 1; 2852 else 2853 sd->sof_read = 0; 2854 break; 2855 } 2856 } 2857 break; 2858 case CIT_MODEL2: 2859 case CIT_MODEL4: 2860 /* TESTME we need to find a longer sof signature to avoid 2861 false positives */ 2862 for (i = 0; i < len; i++) { 2863 switch (sd->sof_read) { 2864 case 0: 2865 if (data[i] == 0x00) 2866 sd->sof_read++; 2867 break; 2868 case 1: 2869 sd->sof_read = 0; 2870 if (data[i] == 0xff) { 2871 if (i >= 4) 2872 PDEBUG(D_FRAM, 2873 "header found at offset: %d: %02x %02x 00 %3ph\n", 2874 i - 1, 2875 data[i - 4], 2876 data[i - 3], 2877 &data[i]); 2878 else 2879 PDEBUG(D_FRAM, 2880 "header found at offset: %d: 00 %3ph\n", 2881 i - 1, 2882 &data[i]); 2883 return data + i + (sd->sof_len - 1); 2884 } 2885 break; 2886 } 2887 } 2888 break; 2889 } 2890 return NULL; 2891 } 2892 2893 static void sd_pkt_scan(struct gspca_dev *gspca_dev, 2894 u8 *data, int len) 2895 { 2896 struct sd *sd = (struct sd *) gspca_dev; 2897 unsigned char *sof; 2898 2899 sof = cit_find_sof(gspca_dev, data, len); 2900 if (sof) { 2901 int n; 2902 2903 /* finish decoding current frame */ 2904 n = sof - data; 2905 if (n > sd->sof_len) 2906 n -= sd->sof_len; 2907 else 2908 n = 0; 2909 gspca_frame_add(gspca_dev, LAST_PACKET, 2910 data, n); 2911 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); 2912 len -= sof - data; 2913 data = sof; 2914 } 2915 2916 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 2917 } 2918 2919 #if IS_ENABLED(CONFIG_INPUT) 2920 static void cit_check_button(struct gspca_dev *gspca_dev) 2921 { 2922 int new_button_state; 2923 struct sd *sd = (struct sd *)gspca_dev; 2924 2925 switch (sd->model) { 2926 case CIT_MODEL3: 2927 case CIT_IBM_NETCAM_PRO: 2928 break; 2929 default: /* TEST ME unknown if this works on other models too */ 2930 return; 2931 } 2932 2933 /* Read the button state */ 2934 cit_read_reg(gspca_dev, 0x0113, 0); 2935 new_button_state = !gspca_dev->usb_buf[0]; 2936 2937 /* Tell the cam we've seen the button press, notice that this 2938 is a nop (iow the cam keeps reporting pressed) until the 2939 button is actually released. */ 2940 if (new_button_state) 2941 cit_write_reg(gspca_dev, 0x01, 0x0113); 2942 2943 if (sd->button_state != new_button_state) { 2944 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 2945 new_button_state); 2946 input_sync(gspca_dev->input_dev); 2947 sd->button_state = new_button_state; 2948 } 2949 } 2950 #endif 2951 2952 static int sd_s_ctrl(struct v4l2_ctrl *ctrl) 2953 { 2954 struct gspca_dev *gspca_dev = 2955 container_of(ctrl->handler, struct gspca_dev, ctrl_handler); 2956 struct sd *sd = (struct sd *)gspca_dev; 2957 2958 gspca_dev->usb_err = 0; 2959 2960 if (!gspca_dev->streaming) 2961 return 0; 2962 2963 if (sd->stop_on_control_change) 2964 sd_stopN(gspca_dev); 2965 switch (ctrl->id) { 2966 case V4L2_CID_BRIGHTNESS: 2967 cit_set_brightness(gspca_dev, ctrl->val); 2968 break; 2969 case V4L2_CID_CONTRAST: 2970 cit_set_contrast(gspca_dev, ctrl->val); 2971 break; 2972 case V4L2_CID_HUE: 2973 cit_set_hue(gspca_dev, ctrl->val); 2974 break; 2975 case V4L2_CID_HFLIP: 2976 cit_set_hflip(gspca_dev, ctrl->val); 2977 break; 2978 case V4L2_CID_SHARPNESS: 2979 cit_set_sharpness(gspca_dev, ctrl->val); 2980 break; 2981 case V4L2_CID_BACKLIGHT_COMPENSATION: 2982 cit_set_lighting(gspca_dev, ctrl->val); 2983 break; 2984 } 2985 if (sd->stop_on_control_change) 2986 cit_restart_stream(gspca_dev); 2987 return gspca_dev->usb_err; 2988 } 2989 2990 static const struct v4l2_ctrl_ops sd_ctrl_ops = { 2991 .s_ctrl = sd_s_ctrl, 2992 }; 2993 2994 static int sd_init_controls(struct gspca_dev *gspca_dev) 2995 { 2996 struct sd *sd = (struct sd *)gspca_dev; 2997 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; 2998 bool has_brightness; 2999 bool has_contrast; 3000 bool has_hue; 3001 bool has_sharpness; 3002 bool has_lighting; 3003 bool has_hflip; 3004 3005 has_brightness = has_contrast = has_hue = 3006 has_sharpness = has_hflip = has_lighting = false; 3007 switch (sd->model) { 3008 case CIT_MODEL0: 3009 has_contrast = has_hflip = true; 3010 break; 3011 case CIT_MODEL1: 3012 has_brightness = has_contrast = 3013 has_sharpness = has_lighting = true; 3014 break; 3015 case CIT_MODEL2: 3016 has_brightness = has_hue = has_lighting = true; 3017 break; 3018 case CIT_MODEL3: 3019 has_brightness = has_contrast = has_sharpness = true; 3020 break; 3021 case CIT_MODEL4: 3022 has_brightness = has_hue = true; 3023 break; 3024 case CIT_IBM_NETCAM_PRO: 3025 has_brightness = has_hue = 3026 has_sharpness = has_hflip = has_lighting = true; 3027 break; 3028 } 3029 gspca_dev->vdev.ctrl_handler = hdl; 3030 v4l2_ctrl_handler_init(hdl, 5); 3031 if (has_brightness) 3032 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 3033 V4L2_CID_BRIGHTNESS, 0, 63, 1, 32); 3034 if (has_contrast) 3035 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 3036 V4L2_CID_CONTRAST, 0, 20, 1, 10); 3037 if (has_hue) 3038 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 3039 V4L2_CID_HUE, 0, 127, 1, 63); 3040 if (has_sharpness) 3041 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 3042 V4L2_CID_SHARPNESS, 0, 6, 1, 3); 3043 if (has_lighting) 3044 sd->lighting = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 3045 V4L2_CID_BACKLIGHT_COMPENSATION, 0, 2, 1, 1); 3046 if (has_hflip) 3047 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 3048 V4L2_CID_HFLIP, 0, 1, 1, 0); 3049 3050 if (hdl->error) { 3051 pr_err("Could not initialize controls\n"); 3052 return hdl->error; 3053 } 3054 return 0; 3055 } 3056 3057 /* sub-driver description */ 3058 static const struct sd_desc sd_desc = { 3059 .name = MODULE_NAME, 3060 .config = sd_config, 3061 .init = sd_init, 3062 .init_controls = sd_init_controls, 3063 .start = sd_start, 3064 .stopN = sd_stopN, 3065 .stop0 = sd_stop0, 3066 .pkt_scan = sd_pkt_scan, 3067 #if IS_ENABLED(CONFIG_INPUT) 3068 .dq_callback = cit_check_button, 3069 .other_input = 1, 3070 #endif 3071 }; 3072 3073 static const struct sd_desc sd_desc_isoc_nego = { 3074 .name = MODULE_NAME, 3075 .config = sd_config, 3076 .init = sd_init, 3077 .init_controls = sd_init_controls, 3078 .start = sd_start, 3079 .isoc_init = sd_isoc_init, 3080 .isoc_nego = sd_isoc_nego, 3081 .stopN = sd_stopN, 3082 .stop0 = sd_stop0, 3083 .pkt_scan = sd_pkt_scan, 3084 #if IS_ENABLED(CONFIG_INPUT) 3085 .dq_callback = cit_check_button, 3086 .other_input = 1, 3087 #endif 3088 }; 3089 3090 /* -- module initialisation -- */ 3091 static const struct usb_device_id device_table[] = { 3092 { USB_DEVICE_VER(0x0545, 0x8080, 0x0001, 0x0001), .driver_info = CIT_MODEL0 }, 3093 { USB_DEVICE_VER(0x0545, 0x8080, 0x0002, 0x0002), .driver_info = CIT_MODEL1 }, 3094 { USB_DEVICE_VER(0x0545, 0x8080, 0x030a, 0x030a), .driver_info = CIT_MODEL2 }, 3095 { USB_DEVICE_VER(0x0545, 0x8080, 0x0301, 0x0301), .driver_info = CIT_MODEL3 }, 3096 { USB_DEVICE_VER(0x0545, 0x8002, 0x030a, 0x030a), .driver_info = CIT_MODEL4 }, 3097 { USB_DEVICE_VER(0x0545, 0x800c, 0x030a, 0x030a), .driver_info = CIT_MODEL2 }, 3098 { USB_DEVICE_VER(0x0545, 0x800d, 0x030a, 0x030a), .driver_info = CIT_MODEL4 }, 3099 {} 3100 }; 3101 MODULE_DEVICE_TABLE(usb, device_table); 3102 3103 /* -- device connect -- */ 3104 static int sd_probe(struct usb_interface *intf, 3105 const struct usb_device_id *id) 3106 { 3107 const struct sd_desc *desc = &sd_desc; 3108 3109 switch (id->driver_info) { 3110 case CIT_MODEL0: 3111 case CIT_MODEL1: 3112 if (intf->cur_altsetting->desc.bInterfaceNumber != 2) 3113 return -ENODEV; 3114 break; 3115 case CIT_MODEL2: 3116 case CIT_MODEL4: 3117 if (intf->cur_altsetting->desc.bInterfaceNumber != 0) 3118 return -ENODEV; 3119 break; 3120 case CIT_MODEL3: 3121 if (intf->cur_altsetting->desc.bInterfaceNumber != 0) 3122 return -ENODEV; 3123 /* FIXME this likely applies to all model3 cams and probably 3124 to other models too. */ 3125 if (ibm_netcam_pro) 3126 desc = &sd_desc_isoc_nego; 3127 break; 3128 } 3129 3130 return gspca_dev_probe2(intf, id, desc, sizeof(struct sd), THIS_MODULE); 3131 } 3132 3133 static struct usb_driver sd_driver = { 3134 .name = MODULE_NAME, 3135 .id_table = device_table, 3136 .probe = sd_probe, 3137 .disconnect = gspca_disconnect, 3138 #ifdef CONFIG_PM 3139 .suspend = gspca_suspend, 3140 .resume = gspca_resume, 3141 .reset_resume = gspca_resume, 3142 #endif 3143 }; 3144 3145 module_usb_driver(sd_driver); 3146