1/* 2 * USB NB Camera driver 3 * 4 * HISTORY: 5 * 25-Dec-2002 Dmitri Removed lighting, sharpness parameters, methods. 6 */ 7 8#include <linux/kernel.h> 9#include <linux/module.h> 10#include <linux/init.h> 11 12#include "usbvideo.h" 13 14#define ULTRACAM_VENDOR_ID 0x0461 15#define ULTRACAM_PRODUCT_ID 0x0813 16 17#define MAX_CAMERAS 4 /* How many devices we allow to connect */ 18 19/* 20 * This structure lives in uvd_t->user field. 21 */ 22typedef struct { 23 int initialized; /* Had we already sent init sequence? */ 24 int camera_model; /* What type of IBM camera we got? */ 25 int has_hdr; 26} ultracam_t; 27#define ULTRACAM_T(uvd) ((ultracam_t *)((uvd)->user_data)) 28 29static struct usbvideo *cams = NULL; 30 31static int debug = 0; 32 33static int flags = 0; /* FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */ 34 35static const int min_canvasWidth = 8; 36static const int min_canvasHeight = 4; 37 38#define FRAMERATE_MIN 0 39#define FRAMERATE_MAX 6 40static int framerate = -1; 41 42/* 43 * Here we define several initialization variables. They may 44 * be used to automatically set color, hue, brightness and 45 * contrast to desired values. This is particularly useful in 46 * case of webcams (which have no controls and no on-screen 47 * output) and also when a client V4L software is used that 48 * does not have some of those controls. In any case it's 49 * good to have startup values as options. 50 * 51 * These values are all in [0..255] range. This simplifies 52 * operation. Note that actual values of V4L variables may 53 * be scaled up (as much as << 8). User can see that only 54 * on overlay output, however, or through a V4L client. 55 */ 56static int init_brightness = 128; 57static int init_contrast = 192; 58static int init_color = 128; 59static int init_hue = 128; 60static int hue_correction = 128; 61 62module_param(debug, int, S_IRUGO | S_IWUSR); 63MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)"); 64module_param(flags, int, 0); 65MODULE_PARM_DESC(flags, 66 "Bitfield: 0=VIDIOCSYNC, " 67 "1=B/W, " 68 "2=show hints, " 69 "3=show stats, " 70 "4=test pattern, " 71 "5=separate frames, " 72 "6=clean frames"); 73module_param(framerate, int, 0); 74MODULE_PARM_DESC(framerate, "Framerate setting: 0=slowest, 6=fastest (default=2)"); 75 76module_param(init_brightness, int, 0); 77MODULE_PARM_DESC(init_brightness, "Brightness preconfiguration: 0-255 (default=128)"); 78module_param(init_contrast, int, 0); 79MODULE_PARM_DESC(init_contrast, "Contrast preconfiguration: 0-255 (default=192)"); 80module_param(init_color, int, 0); 81MODULE_PARM_DESC(init_color, "Color preconfiguration: 0-255 (default=128)"); 82module_param(init_hue, int, 0); 83MODULE_PARM_DESC(init_hue, "Hue preconfiguration: 0-255 (default=128)"); 84module_param(hue_correction, int, 0); 85MODULE_PARM_DESC(hue_correction, "YUV colorspace regulation: 0-255 (default=128)"); 86 87/* 88 * ultracam_ProcessIsocData() 89 * 90 * Generic routine to parse the ring queue data. It employs either 91 * ultracam_find_header() or ultracam_parse_lines() to do most 92 * of work. 93 * 94 * 02-Nov-2000 First (mostly dummy) version. 95 * 06-Nov-2000 Rewrote to dump all data into frame. 96 */ 97static void ultracam_ProcessIsocData(struct uvd *uvd, struct usbvideo_frame *frame) 98{ 99 int n; 100 101 assert(uvd != NULL); 102 assert(frame != NULL); 103 104 /* Try to move data from queue into frame buffer */ 105 n = RingQueue_GetLength(&uvd->dp); 106 if (n > 0) { 107 int m; 108 /* See how much spare we have left */ 109 m = uvd->max_frame_size - frame->seqRead_Length; 110 if (n > m) 111 n = m; 112 /* Now move that much data into frame buffer */ 113 RingQueue_Dequeue( 114 &uvd->dp, 115 frame->data + frame->seqRead_Length, 116 m); 117 frame->seqRead_Length += m; 118 } 119 /* See if we filled the frame */ 120 if (frame->seqRead_Length >= uvd->max_frame_size) { 121 frame->frameState = FrameState_Done; 122 uvd->curframe = -1; 123 uvd->stats.frame_num++; 124 } 125} 126 127/* 128 * ultracam_veio() 129 * 130 * History: 131 * 1/27/00 Added check for dev == NULL; this happens if camera is unplugged. 132 */ 133static int ultracam_veio( 134 struct uvd *uvd, 135 unsigned char req, 136 unsigned short value, 137 unsigned short index, 138 int is_out) 139{ 140 static const char proc[] = "ultracam_veio"; 141 unsigned char cp[8] /* = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef } */; 142 int i; 143 144 if (!CAMERA_IS_OPERATIONAL(uvd)) 145 return 0; 146 147 if (!is_out) { 148 i = usb_control_msg( 149 uvd->dev, 150 usb_rcvctrlpipe(uvd->dev, 0), 151 req, 152 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 153 value, 154 index, 155 cp, 156 sizeof(cp), 157 1000); 158 info("USB => %02x%02x%02x%02x%02x%02x%02x%02x " 159 "(req=$%02x val=$%04x ind=$%04x)", 160 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7], 161 req, value, index); 162 } else { 163 i = usb_control_msg( 164 uvd->dev, 165 usb_sndctrlpipe(uvd->dev, 0), 166 req, 167 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 168 value, 169 index, 170 NULL, 171 0, 172 1000); 173 } 174 if (i < 0) { 175 err("%s: ERROR=%d. Camera stopped; Reconnect or reload driver.", 176 proc, i); 177 uvd->last_error = i; 178 } 179 return i; 180} 181 182/* 183 * ultracam_calculate_fps() 184 */ 185static int ultracam_calculate_fps(struct uvd *uvd) 186{ 187 return 3 + framerate*4 + framerate/2; 188} 189 190/* 191 * ultracam_adjust_contrast() 192 */ 193static void ultracam_adjust_contrast(struct uvd *uvd) 194{ 195} 196 197/* 198 * ultracam_set_brightness() 199 * 200 * This procedure changes brightness of the picture. 201 */ 202static void ultracam_set_brightness(struct uvd *uvd) 203{ 204} 205 206static void ultracam_set_hue(struct uvd *uvd) 207{ 208} 209 210/* 211 * ultracam_adjust_picture() 212 * 213 * This procedure gets called from V4L interface to update picture settings. 214 * Here we change brightness and contrast. 215 */ 216static void ultracam_adjust_picture(struct uvd *uvd) 217{ 218 ultracam_adjust_contrast(uvd); 219 ultracam_set_brightness(uvd); 220 ultracam_set_hue(uvd); 221} 222 223/* 224 * ultracam_video_stop() 225 * 226 * This code tells camera to stop streaming. The interface remains 227 * configured and bandwidth - claimed. 228 */ 229static void ultracam_video_stop(struct uvd *uvd) 230{ 231} 232 233/* 234 * ultracam_reinit_iso() 235 * 236 * This procedure sends couple of commands to the camera and then 237 * resets the video pipe. This sequence was observed to reinit the 238 * camera or, at least, to initiate ISO data stream. 239 */ 240static void ultracam_reinit_iso(struct uvd *uvd, int do_stop) 241{ 242} 243 244static void ultracam_video_start(struct uvd *uvd) 245{ 246 ultracam_reinit_iso(uvd, 0); 247} 248 249static int ultracam_resetPipe(struct uvd *uvd) 250{ 251 usb_clear_halt(uvd->dev, uvd->video_endp); 252 return 0; 253} 254 255static int ultracam_alternateSetting(struct uvd *uvd, int setting) 256{ 257 static const char proc[] = "ultracam_alternateSetting"; 258 int i; 259 i = usb_set_interface(uvd->dev, uvd->iface, setting); 260 if (i < 0) { 261 err("%s: usb_set_interface error", proc); 262 uvd->last_error = i; 263 return -EBUSY; 264 } 265 return 0; 266} 267 268/* 269 * Return negative code on failure, 0 on success. 270 */ 271static int ultracam_setup_on_open(struct uvd *uvd) 272{ 273 int setup_ok = 0; /* Success by default */ 274 /* Send init sequence only once, it's large! */ 275 if (!ULTRACAM_T(uvd)->initialized) { 276 ultracam_alternateSetting(uvd, 0x04); 277 ultracam_alternateSetting(uvd, 0x00); 278 ultracam_veio(uvd, 0x02, 0x0004, 0x000b, 1); 279 ultracam_veio(uvd, 0x02, 0x0001, 0x0005, 1); 280 ultracam_veio(uvd, 0x02, 0x8000, 0x0000, 1); 281 ultracam_veio(uvd, 0x00, 0x0000, 0x0000, 1); 282 ultracam_veio(uvd, 0x00, 0x00b0, 0x0001, 1); 283 ultracam_veio(uvd, 0x00, 0x0000, 0x0002, 1); 284 ultracam_veio(uvd, 0x00, 0x000c, 0x0003, 1); 285 ultracam_veio(uvd, 0x00, 0x000b, 0x0004, 1); 286 ultracam_veio(uvd, 0x00, 0x0000, 0x0005, 1); 287 ultracam_veio(uvd, 0x00, 0x0000, 0x0006, 1); 288 ultracam_veio(uvd, 0x00, 0x0079, 0x0007, 1); 289 ultracam_veio(uvd, 0x00, 0x003b, 0x0008, 1); 290 ultracam_veio(uvd, 0x00, 0x0002, 0x000f, 1); 291 ultracam_veio(uvd, 0x00, 0x0001, 0x0010, 1); 292 ultracam_veio(uvd, 0x00, 0x0000, 0x0011, 1); 293 ultracam_veio(uvd, 0x00, 0x0000, 0x00bf, 1); 294 ultracam_veio(uvd, 0x00, 0x0001, 0x00c0, 1); 295 ultracam_veio(uvd, 0x00, 0x0010, 0x00cb, 1); 296 ultracam_veio(uvd, 0x01, 0x00a4, 0x0001, 1); 297 ultracam_veio(uvd, 0x01, 0x0010, 0x0002, 1); 298 ultracam_veio(uvd, 0x01, 0x0066, 0x0007, 1); 299 ultracam_veio(uvd, 0x01, 0x000b, 0x0008, 1); 300 ultracam_veio(uvd, 0x01, 0x0034, 0x0009, 1); 301 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 1); 302 ultracam_veio(uvd, 0x01, 0x002e, 0x000b, 1); 303 ultracam_veio(uvd, 0x01, 0x00d6, 0x000c, 1); 304 ultracam_veio(uvd, 0x01, 0x00fc, 0x000d, 1); 305 ultracam_veio(uvd, 0x01, 0x00f1, 0x000e, 1); 306 ultracam_veio(uvd, 0x01, 0x00da, 0x000f, 1); 307 ultracam_veio(uvd, 0x01, 0x0036, 0x0010, 1); 308 ultracam_veio(uvd, 0x01, 0x000b, 0x0011, 1); 309 ultracam_veio(uvd, 0x01, 0x0001, 0x0012, 1); 310 ultracam_veio(uvd, 0x01, 0x0000, 0x0013, 1); 311 ultracam_veio(uvd, 0x01, 0x0000, 0x0014, 1); 312 ultracam_veio(uvd, 0x01, 0x0087, 0x0051, 1); 313 ultracam_veio(uvd, 0x01, 0x0040, 0x0052, 1); 314 ultracam_veio(uvd, 0x01, 0x0058, 0x0053, 1); 315 ultracam_veio(uvd, 0x01, 0x0040, 0x0054, 1); 316 ultracam_veio(uvd, 0x01, 0x0000, 0x0040, 1); 317 ultracam_veio(uvd, 0x01, 0x0010, 0x0041, 1); 318 ultracam_veio(uvd, 0x01, 0x0020, 0x0042, 1); 319 ultracam_veio(uvd, 0x01, 0x0030, 0x0043, 1); 320 ultracam_veio(uvd, 0x01, 0x0040, 0x0044, 1); 321 ultracam_veio(uvd, 0x01, 0x0050, 0x0045, 1); 322 ultracam_veio(uvd, 0x01, 0x0060, 0x0046, 1); 323 ultracam_veio(uvd, 0x01, 0x0070, 0x0047, 1); 324 ultracam_veio(uvd, 0x01, 0x0080, 0x0048, 1); 325 ultracam_veio(uvd, 0x01, 0x0090, 0x0049, 1); 326 ultracam_veio(uvd, 0x01, 0x00a0, 0x004a, 1); 327 ultracam_veio(uvd, 0x01, 0x00b0, 0x004b, 1); 328 ultracam_veio(uvd, 0x01, 0x00c0, 0x004c, 1); 329 ultracam_veio(uvd, 0x01, 0x00d0, 0x004d, 1); 330 ultracam_veio(uvd, 0x01, 0x00e0, 0x004e, 1); 331 ultracam_veio(uvd, 0x01, 0x00f0, 0x004f, 1); 332 ultracam_veio(uvd, 0x01, 0x00ff, 0x0050, 1); 333 ultracam_veio(uvd, 0x01, 0x0000, 0x0056, 1); 334 ultracam_veio(uvd, 0x00, 0x0080, 0x00c1, 1); 335 ultracam_veio(uvd, 0x00, 0x0000, 0x00c2, 1); 336 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1); 337 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 338 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 339 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 340 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 341 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 342 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 343 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 344 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 345 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 346 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 347 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 348 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 349 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 350 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 351 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 352 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 353 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 354 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 355 ultracam_veio(uvd, 0x00, 0x0080, 0x00c1, 1); 356 ultracam_veio(uvd, 0x00, 0x0004, 0x00c2, 1); 357 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1); 358 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 359 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 360 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 361 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 362 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 363 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 364 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 365 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 366 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 367 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 368 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 369 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 370 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 371 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 372 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 373 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 374 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 375 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 376 ultracam_veio(uvd, 0x00, 0x0002, 0x00c1, 1); 377 ultracam_veio(uvd, 0x00, 0x0020, 0x00c2, 1); 378 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1); 379 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1); 380 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1); 381 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1); 382 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1); 383 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1); 384 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1); 385 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 386 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1); 387 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1); 388 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1); 389 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1); 390 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1); 391 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1); 392 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 393 ultracam_veio(uvd, 0x00, 0x0040, 0x00c1, 1); 394 ultracam_veio(uvd, 0x00, 0x0017, 0x00c2, 1); 395 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1); 396 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1); 397 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1); 398 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1); 399 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1); 400 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1); 401 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1); 402 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 403 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1); 404 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1); 405 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1); 406 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1); 407 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1); 408 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1); 409 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1); 410 ultracam_veio(uvd, 0x00, 0x00c0, 0x00c1, 1); 411 ultracam_veio(uvd, 0x00, 0x0000, 0x00c2, 1); 412 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1); 413 ultracam_veio(uvd, 0x02, 0xc040, 0x0001, 1); 414 ultracam_veio(uvd, 0x01, 0x0000, 0x0008, 0); 415 ultracam_veio(uvd, 0x01, 0x0000, 0x0009, 0); 416 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 0); 417 ultracam_veio(uvd, 0x01, 0x0000, 0x000b, 0); 418 ultracam_veio(uvd, 0x01, 0x0000, 0x000c, 0); 419 ultracam_veio(uvd, 0x01, 0x0000, 0x000d, 0); 420 ultracam_veio(uvd, 0x01, 0x0000, 0x000e, 0); 421 ultracam_veio(uvd, 0x01, 0x0000, 0x000f, 0); 422 ultracam_veio(uvd, 0x01, 0x0000, 0x0010, 0); 423 ultracam_veio(uvd, 0x01, 0x000b, 0x0008, 1); 424 ultracam_veio(uvd, 0x01, 0x0034, 0x0009, 1); 425 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 1); 426 ultracam_veio(uvd, 0x01, 0x002e, 0x000b, 1); 427 ultracam_veio(uvd, 0x01, 0x00d6, 0x000c, 1); 428 ultracam_veio(uvd, 0x01, 0x00fc, 0x000d, 1); 429 ultracam_veio(uvd, 0x01, 0x00f1, 0x000e, 1); 430 ultracam_veio(uvd, 0x01, 0x00da, 0x000f, 1); 431 ultracam_veio(uvd, 0x01, 0x0036, 0x0010, 1); 432 ultracam_veio(uvd, 0x01, 0x0000, 0x0001, 0); 433 ultracam_veio(uvd, 0x01, 0x0064, 0x0001, 1); 434 ultracam_veio(uvd, 0x01, 0x0059, 0x0051, 1); 435 ultracam_veio(uvd, 0x01, 0x003f, 0x0052, 1); 436 ultracam_veio(uvd, 0x01, 0x0094, 0x0053, 1); 437 ultracam_veio(uvd, 0x01, 0x00ff, 0x0011, 1); 438 ultracam_veio(uvd, 0x01, 0x0003, 0x0012, 1); 439 ultracam_veio(uvd, 0x01, 0x00f7, 0x0013, 1); 440 ultracam_veio(uvd, 0x00, 0x0009, 0x0011, 1); 441 ultracam_veio(uvd, 0x00, 0x0000, 0x0001, 1); 442 ultracam_veio(uvd, 0x00, 0x0000, 0x0000, 1); 443 ultracam_veio(uvd, 0x00, 0x0020, 0x00c1, 1); 444 ultracam_veio(uvd, 0x00, 0x0010, 0x00c2, 1); 445 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1); 446 ultracam_alternateSetting(uvd, 0x04); 447 ultracam_veio(uvd, 0x02, 0x0000, 0x0001, 1); 448 ultracam_veio(uvd, 0x02, 0x0000, 0x0001, 1); 449 ultracam_veio(uvd, 0x02, 0x0000, 0x0006, 1); 450 ultracam_veio(uvd, 0x02, 0x9000, 0x0007, 1); 451 ultracam_veio(uvd, 0x02, 0x0042, 0x0001, 1); 452 ultracam_veio(uvd, 0x02, 0x0000, 0x000b, 0); 453 ultracam_resetPipe(uvd); 454 ULTRACAM_T(uvd)->initialized = (setup_ok != 0); 455 } 456 return setup_ok; 457} 458 459static void ultracam_configure_video(struct uvd *uvd) 460{ 461 if (uvd == NULL) 462 return; 463 464 RESTRICT_TO_RANGE(init_brightness, 0, 255); 465 RESTRICT_TO_RANGE(init_contrast, 0, 255); 466 RESTRICT_TO_RANGE(init_color, 0, 255); 467 RESTRICT_TO_RANGE(init_hue, 0, 255); 468 RESTRICT_TO_RANGE(hue_correction, 0, 255); 469 470 memset(&uvd->vpic, 0, sizeof(uvd->vpic)); 471 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old)); 472 473 uvd->vpic.colour = init_color << 8; 474 uvd->vpic.hue = init_hue << 8; 475 uvd->vpic.brightness = init_brightness << 8; 476 uvd->vpic.contrast = init_contrast << 8; 477 uvd->vpic.whiteness = 105 << 8; /* This one isn't used */ 478 uvd->vpic.depth = 24; 479 uvd->vpic.palette = VIDEO_PALETTE_RGB24; 480 481 memset(&uvd->vcap, 0, sizeof(uvd->vcap)); 482 strcpy(uvd->vcap.name, "IBM Ultra Camera"); 483 uvd->vcap.type = VID_TYPE_CAPTURE; 484 uvd->vcap.channels = 1; 485 uvd->vcap.audios = 0; 486 uvd->vcap.maxwidth = VIDEOSIZE_X(uvd->canvas); 487 uvd->vcap.maxheight = VIDEOSIZE_Y(uvd->canvas); 488 uvd->vcap.minwidth = min_canvasWidth; 489 uvd->vcap.minheight = min_canvasHeight; 490 491 memset(&uvd->vchan, 0, sizeof(uvd->vchan)); 492 uvd->vchan.flags = 0; 493 uvd->vchan.tuners = 0; 494 uvd->vchan.channel = 0; 495 uvd->vchan.type = VIDEO_TYPE_CAMERA; 496 strcpy(uvd->vchan.name, "Camera"); 497} 498 499/* 500 * ultracam_probe() 501 * 502 * This procedure queries device descriptor and accepts the interface 503 * if it looks like our camera. 504 * 505 * History: 506 * 12-Nov-2000 Reworked to comply with new probe() signature. 507 * 23-Jan-2001 Added compatibility with 2.2.x kernels. 508 */ 509static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id *devid) 510{ 511 struct usb_device *dev = interface_to_usbdev(intf); 512 struct uvd *uvd = NULL; 513 int ix, i, nas; 514 int actInterface=-1, inactInterface=-1, maxPS=0; 515 unsigned char video_ep = 0; 516 517 if (debug >= 1) 518 info("ultracam_probe(%p)", intf); 519 520 /* We don't handle multi-config cameras */ 521 if (dev->descriptor.bNumConfigurations != 1) 522 return -ENODEV; 523 524 info("IBM Ultra camera found (rev. 0x%04x)", 525 le16_to_cpu(dev->descriptor.bcdDevice)); 526 527 /* Validate found interface: must have one ISO endpoint */ 528 nas = intf->num_altsetting; 529 if (debug > 0) 530 info("Number of alternate settings=%d.", nas); 531 if (nas < 8) { 532 err("Too few alternate settings for this camera!"); 533 return -ENODEV; 534 } 535 /* Validate all alternate settings */ 536 for (ix=0; ix < nas; ix++) { 537 const struct usb_host_interface *interface; 538 const struct usb_endpoint_descriptor *endpoint; 539 540 interface = &intf->altsetting[ix]; 541 i = interface->desc.bAlternateSetting; 542 if (interface->desc.bNumEndpoints != 1) { 543 err("Interface %d. has %u. endpoints!", 544 interface->desc.bInterfaceNumber, 545 (unsigned)(interface->desc.bNumEndpoints)); 546 return -ENODEV; 547 } 548 endpoint = &interface->endpoint[0].desc; 549 if (video_ep == 0) 550 video_ep = endpoint->bEndpointAddress; 551 else if (video_ep != endpoint->bEndpointAddress) { 552 err("Alternate settings have different endpoint addresses!"); 553 return -ENODEV; 554 } 555 if ((endpoint->bmAttributes & 0x03) != 0x01) { 556 err("Interface %d. has non-ISO endpoint!", 557 interface->desc.bInterfaceNumber); 558 return -ENODEV; 559 } 560 if ((endpoint->bEndpointAddress & 0x80) == 0) { 561 err("Interface %d. has ISO OUT endpoint!", 562 interface->desc.bInterfaceNumber); 563 return -ENODEV; 564 } 565 if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) { 566 if (inactInterface < 0) 567 inactInterface = i; 568 else { 569 err("More than one inactive alt. setting!"); 570 return -ENODEV; 571 } 572 } else { 573 if (actInterface < 0) { 574 actInterface = i; 575 maxPS = le16_to_cpu(endpoint->wMaxPacketSize); 576 if (debug > 0) 577 info("Active setting=%d. maxPS=%d.", i, maxPS); 578 } else { 579 /* Got another active alt. setting */ 580 if (maxPS < le16_to_cpu(endpoint->wMaxPacketSize)) { 581 /* This one is better! */ 582 actInterface = i; 583 maxPS = le16_to_cpu(endpoint->wMaxPacketSize); 584 if (debug > 0) { 585 info("Even better ctive setting=%d. maxPS=%d.", 586 i, maxPS); 587 } 588 } 589 } 590 } 591 } 592 if ((maxPS <= 0) || (actInterface < 0) || (inactInterface < 0)) { 593 err("Failed to recognize the camera!"); 594 return -ENODEV; 595 } 596 597 uvd = usbvideo_AllocateDevice(cams); 598 if (uvd != NULL) { 599 /* Here uvd is a fully allocated uvd object */ 600 uvd->flags = flags; 601 uvd->debug = debug; 602 uvd->dev = dev; 603 uvd->iface = intf->altsetting->desc.bInterfaceNumber; 604 uvd->ifaceAltInactive = inactInterface; 605 uvd->ifaceAltActive = actInterface; 606 uvd->video_endp = video_ep; 607 uvd->iso_packet_len = maxPS; 608 uvd->paletteBits = 1L << VIDEO_PALETTE_RGB24; 609 uvd->defaultPalette = VIDEO_PALETTE_RGB24; 610 uvd->canvas = VIDEOSIZE(640, 480); 611 uvd->videosize = uvd->canvas; /* ultracam_size_to_videosize(size);*/ 612 613 /* Initialize ibmcam-specific data */ 614 assert(ULTRACAM_T(uvd) != NULL); 615 ULTRACAM_T(uvd)->camera_model = 0; /* Not used yet */ 616 ULTRACAM_T(uvd)->initialized = 0; 617 618 ultracam_configure_video(uvd); 619 620 i = usbvideo_RegisterVideoDevice(uvd); 621 if (i != 0) { 622 err("usbvideo_RegisterVideoDevice() failed."); 623 uvd = NULL; 624 } 625 } 626 627 if (uvd) { 628 usb_set_intfdata (intf, uvd); 629 return 0; 630 } 631 return -EIO; 632} 633 634 635static struct usb_device_id id_table[] = { 636 { USB_DEVICE(ULTRACAM_VENDOR_ID, ULTRACAM_PRODUCT_ID) }, 637 { } /* Terminating entry */ 638}; 639 640/* 641 * ultracam_init() 642 * 643 * This code is run to initialize the driver. 644 */ 645static int __init ultracam_init(void) 646{ 647 struct usbvideo_cb cbTbl; 648 memset(&cbTbl, 0, sizeof(cbTbl)); 649 cbTbl.probe = ultracam_probe; 650 cbTbl.setupOnOpen = ultracam_setup_on_open; 651 cbTbl.videoStart = ultracam_video_start; 652 cbTbl.videoStop = ultracam_video_stop; 653 cbTbl.processData = ultracam_ProcessIsocData; 654 cbTbl.postProcess = usbvideo_DeinterlaceFrame; 655 cbTbl.adjustPicture = ultracam_adjust_picture; 656 cbTbl.getFPS = ultracam_calculate_fps; 657 return usbvideo_register( 658 &cams, 659 MAX_CAMERAS, 660 sizeof(ultracam_t), 661 "ultracam", 662 &cbTbl, 663 THIS_MODULE, 664 id_table); 665} 666 667static void __exit ultracam_cleanup(void) 668{ 669 usbvideo_Deregister(&cams); 670} 671 672MODULE_DEVICE_TABLE(usb, id_table); 673MODULE_LICENSE("GPL"); 674 675module_init(ultracam_init); 676module_exit(ultracam_cleanup); 677