aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/cpia.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2006-03-25 07:19:53 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2006-03-25 07:29:23 -0500
commitd56410e0a594150c5ca06319da7bc8901c4d455e (patch)
treef1462651ac1bcc5cec48219dbb422ac615231423 /drivers/media/video/cpia.c
parent9f6933be665ce3b049c274c99810ac754edabf19 (diff)
V4L/DVB (3599b): Whitespace cleanups under drivers/media
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/cpia.c')
-rw-r--r--drivers/media/video/cpia.c656
1 files changed, 328 insertions, 328 deletions
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 3cebfa91ca14..2227c5640c12 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */ 26/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
27/* #define _CPIA_DEBUG_ 1 */ 27/* #define _CPIA_DEBUG_ 1 */
28 28
29#include <linux/config.h> 29#include <linux/config.h>
30 30
@@ -67,11 +67,11 @@ MODULE_SUPPORTED_DEVICE("video");
67static unsigned short colorspace_conv = 0; 67static unsigned short colorspace_conv = 0;
68module_param(colorspace_conv, ushort, 0444); 68module_param(colorspace_conv, ushort, 0444);
69MODULE_PARM_DESC(colorspace_conv, 69MODULE_PARM_DESC(colorspace_conv,
70 "\n<n> Colorspace conversion:" 70 "\n<n> Colorspace conversion:"
71 "\n0 = disable" 71 "\n0 = disable"
72 "\n1 = enable" 72 "\n1 = enable"
73 "\nDefault value is 0" 73 "\nDefault value is 0"
74 "\n"); 74 "\n");
75 75
76#define ABOUT "V4L-Driver for Vision CPiA based cameras" 76#define ABOUT "V4L-Driver for Vision CPiA based cameras"
77 77
@@ -189,8 +189,8 @@ enum {
189#define TC 94 189#define TC 94
190#define EXP_ACC_DARK 50 190#define EXP_ACC_DARK 50
191#define EXP_ACC_LIGHT 90 191#define EXP_ACC_LIGHT 90
192#define HIGH_COMP_102 160 192#define HIGH_COMP_102 160
193#define MAX_COMP 239 193#define MAX_COMP 239
194#define DARK_TIME 3 194#define DARK_TIME 3
195#define LIGHT_TIME 3 195#define LIGHT_TIME 3
196 196
@@ -208,7 +208,7 @@ static u8 flicker_jumps[2][2][4] =
208static void reset_camera_struct(struct cam_data *cam); 208static void reset_camera_struct(struct cam_data *cam);
209static int find_over_exposure(int brightness); 209static int find_over_exposure(int brightness);
210static void set_flicker(struct cam_params *params, volatile u32 *command_flags, 210static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
211 int on); 211 int on);
212 212
213 213
214/********************************************************************** 214/**********************************************************************
@@ -262,7 +262,7 @@ static void rvfree(void *mem, unsigned long size)
262static struct proc_dir_entry *cpia_proc_root=NULL; 262static struct proc_dir_entry *cpia_proc_root=NULL;
263 263
264static int cpia_read_proc(char *page, char **start, off_t off, 264static int cpia_read_proc(char *page, char **start, off_t off,
265 int count, int *eof, void *data) 265 int count, int *eof, void *data)
266{ 266{
267 char *out = page; 267 char *out = page;
268 int len, tmp; 268 int len, tmp;
@@ -276,58 +276,58 @@ static int cpia_read_proc(char *page, char **start, off_t off,
276 out += sprintf(out, "V4L Driver version: %d.%d.%d\n", 276 out += sprintf(out, "V4L Driver version: %d.%d.%d\n",
277 CPIA_MAJ_VER, CPIA_MIN_VER, CPIA_PATCH_VER); 277 CPIA_MAJ_VER, CPIA_MIN_VER, CPIA_PATCH_VER);
278 out += sprintf(out, "CPIA Version: %d.%02d (%d.%d)\n", 278 out += sprintf(out, "CPIA Version: %d.%02d (%d.%d)\n",
279 cam->params.version.firmwareVersion, 279 cam->params.version.firmwareVersion,
280 cam->params.version.firmwareRevision, 280 cam->params.version.firmwareRevision,
281 cam->params.version.vcVersion, 281 cam->params.version.vcVersion,
282 cam->params.version.vcRevision); 282 cam->params.version.vcRevision);
283 out += sprintf(out, "CPIA PnP-ID: %04x:%04x:%04x\n", 283 out += sprintf(out, "CPIA PnP-ID: %04x:%04x:%04x\n",
284 cam->params.pnpID.vendor, cam->params.pnpID.product, 284 cam->params.pnpID.vendor, cam->params.pnpID.product,
285 cam->params.pnpID.deviceRevision); 285 cam->params.pnpID.deviceRevision);
286 out += sprintf(out, "VP-Version: %d.%d %04x\n", 286 out += sprintf(out, "VP-Version: %d.%d %04x\n",
287 cam->params.vpVersion.vpVersion, 287 cam->params.vpVersion.vpVersion,
288 cam->params.vpVersion.vpRevision, 288 cam->params.vpVersion.vpRevision,
289 cam->params.vpVersion.cameraHeadID); 289 cam->params.vpVersion.cameraHeadID);
290 290
291 out += sprintf(out, "system_state: %#04x\n", 291 out += sprintf(out, "system_state: %#04x\n",
292 cam->params.status.systemState); 292 cam->params.status.systemState);
293 out += sprintf(out, "grab_state: %#04x\n", 293 out += sprintf(out, "grab_state: %#04x\n",
294 cam->params.status.grabState); 294 cam->params.status.grabState);
295 out += sprintf(out, "stream_state: %#04x\n", 295 out += sprintf(out, "stream_state: %#04x\n",
296 cam->params.status.streamState); 296 cam->params.status.streamState);
297 out += sprintf(out, "fatal_error: %#04x\n", 297 out += sprintf(out, "fatal_error: %#04x\n",
298 cam->params.status.fatalError); 298 cam->params.status.fatalError);
299 out += sprintf(out, "cmd_error: %#04x\n", 299 out += sprintf(out, "cmd_error: %#04x\n",
300 cam->params.status.cmdError); 300 cam->params.status.cmdError);
301 out += sprintf(out, "debug_flags: %#04x\n", 301 out += sprintf(out, "debug_flags: %#04x\n",
302 cam->params.status.debugFlags); 302 cam->params.status.debugFlags);
303 out += sprintf(out, "vp_status: %#04x\n", 303 out += sprintf(out, "vp_status: %#04x\n",
304 cam->params.status.vpStatus); 304 cam->params.status.vpStatus);
305 out += sprintf(out, "error_code: %#04x\n", 305 out += sprintf(out, "error_code: %#04x\n",
306 cam->params.status.errorCode); 306 cam->params.status.errorCode);
307 /* QX3 specific entries */ 307 /* QX3 specific entries */
308 if (cam->params.qx3.qx3_detected) { 308 if (cam->params.qx3.qx3_detected) {
309 out += sprintf(out, "button: %4d\n", 309 out += sprintf(out, "button: %4d\n",
310 cam->params.qx3.button); 310 cam->params.qx3.button);
311 out += sprintf(out, "cradled: %4d\n", 311 out += sprintf(out, "cradled: %4d\n",
312 cam->params.qx3.cradled); 312 cam->params.qx3.cradled);
313 } 313 }
314 out += sprintf(out, "video_size: %s\n", 314 out += sprintf(out, "video_size: %s\n",
315 cam->params.format.videoSize == VIDEOSIZE_CIF ? 315 cam->params.format.videoSize == VIDEOSIZE_CIF ?
316 "CIF " : "QCIF"); 316 "CIF " : "QCIF");
317 out += sprintf(out, "roi: (%3d, %3d) to (%3d, %3d)\n", 317 out += sprintf(out, "roi: (%3d, %3d) to (%3d, %3d)\n",
318 cam->params.roi.colStart*8, 318 cam->params.roi.colStart*8,
319 cam->params.roi.rowStart*4, 319 cam->params.roi.rowStart*4,
320 cam->params.roi.colEnd*8, 320 cam->params.roi.colEnd*8,
321 cam->params.roi.rowEnd*4); 321 cam->params.roi.rowEnd*4);
322 out += sprintf(out, "actual_fps: %3d\n", cam->fps); 322 out += sprintf(out, "actual_fps: %3d\n", cam->fps);
323 out += sprintf(out, "transfer_rate: %4dkB/s\n", 323 out += sprintf(out, "transfer_rate: %4dkB/s\n",
324 cam->transfer_rate); 324 cam->transfer_rate);
325 325
326 out += sprintf(out, "\nread-write\n"); 326 out += sprintf(out, "\nread-write\n");
327 out += sprintf(out, "----------------------- current min" 327 out += sprintf(out, "----------------------- current min"
328 " max default comment\n"); 328 " max default comment\n");
329 out += sprintf(out, "brightness: %8d %8d %8d %8d\n", 329 out += sprintf(out, "brightness: %8d %8d %8d %8d\n",
330 cam->params.colourParams.brightness, 0, 100, 50); 330 cam->params.colourParams.brightness, 0, 100, 50);
331 if (cam->params.version.firmwareVersion == 1 && 331 if (cam->params.version.firmwareVersion == 1 &&
332 cam->params.version.firmwareRevision == 2) 332 cam->params.version.firmwareRevision == 2)
333 /* 1-02 firmware limits contrast to 80 */ 333 /* 1-02 firmware limits contrast to 80 */
@@ -336,26 +336,26 @@ static int cpia_read_proc(char *page, char **start, off_t off,
336 tmp = 96; 336 tmp = 96;
337 337
338 out += sprintf(out, "contrast: %8d %8d %8d %8d" 338 out += sprintf(out, "contrast: %8d %8d %8d %8d"
339 " steps of 8\n", 339 " steps of 8\n",
340 cam->params.colourParams.contrast, 0, tmp, 48); 340 cam->params.colourParams.contrast, 0, tmp, 48);
341 out += sprintf(out, "saturation: %8d %8d %8d %8d\n", 341 out += sprintf(out, "saturation: %8d %8d %8d %8d\n",
342 cam->params.colourParams.saturation, 0, 100, 50); 342 cam->params.colourParams.saturation, 0, 100, 50);
343 tmp = (25000+5000*cam->params.sensorFps.baserate)/ 343 tmp = (25000+5000*cam->params.sensorFps.baserate)/
344 (1<<cam->params.sensorFps.divisor); 344 (1<<cam->params.sensorFps.divisor);
345 out += sprintf(out, "sensor_fps: %4d.%03d %8d %8d %8d\n", 345 out += sprintf(out, "sensor_fps: %4d.%03d %8d %8d %8d\n",
346 tmp/1000, tmp%1000, 3, 30, 15); 346 tmp/1000, tmp%1000, 3, 30, 15);
347 out += sprintf(out, "stream_start_line: %8d %8d %8d %8d\n", 347 out += sprintf(out, "stream_start_line: %8d %8d %8d %8d\n",
348 2*cam->params.streamStartLine, 0, 348 2*cam->params.streamStartLine, 0,
349 cam->params.format.videoSize == VIDEOSIZE_CIF ? 288:144, 349 cam->params.format.videoSize == VIDEOSIZE_CIF ? 288:144,
350 cam->params.format.videoSize == VIDEOSIZE_CIF ? 240:120); 350 cam->params.format.videoSize == VIDEOSIZE_CIF ? 240:120);
351 out += sprintf(out, "sub_sample: %8s %8s %8s %8s\n", 351 out += sprintf(out, "sub_sample: %8s %8s %8s %8s\n",
352 cam->params.format.subSample == SUBSAMPLE_420 ? 352 cam->params.format.subSample == SUBSAMPLE_420 ?
353 "420" : "422", "420", "422", "422"); 353 "420" : "422", "420", "422", "422");
354 out += sprintf(out, "yuv_order: %8s %8s %8s %8s\n", 354 out += sprintf(out, "yuv_order: %8s %8s %8s %8s\n",
355 cam->params.format.yuvOrder == YUVORDER_YUYV ? 355 cam->params.format.yuvOrder == YUVORDER_YUYV ?
356 "YUYV" : "UYVY", "YUYV" , "UYVY", "YUYV"); 356 "YUYV" : "UYVY", "YUYV" , "UYVY", "YUYV");
357 out += sprintf(out, "ecp_timing: %8s %8s %8s %8s\n", 357 out += sprintf(out, "ecp_timing: %8s %8s %8s %8s\n",
358 cam->params.ecpTiming ? "slow" : "normal", "slow", 358 cam->params.ecpTiming ? "slow" : "normal", "slow",
359 "normal", "normal"); 359 "normal", "normal");
360 360
361 if (cam->params.colourBalance.balanceMode == 2) { 361 if (cam->params.colourBalance.balanceMode == 2) {
@@ -366,11 +366,11 @@ static int cpia_read_proc(char *page, char **start, off_t off,
366 out += sprintf(out, "color_balance_mode: %8s %8s %8s" 366 out += sprintf(out, "color_balance_mode: %8s %8s %8s"
367 " %8s\n", tmpstr, "manual", "auto", "auto"); 367 " %8s\n", tmpstr, "manual", "auto", "auto");
368 out += sprintf(out, "red_gain: %8d %8d %8d %8d\n", 368 out += sprintf(out, "red_gain: %8d %8d %8d %8d\n",
369 cam->params.colourBalance.redGain, 0, 212, 32); 369 cam->params.colourBalance.redGain, 0, 212, 32);
370 out += sprintf(out, "green_gain: %8d %8d %8d %8d\n", 370 out += sprintf(out, "green_gain: %8d %8d %8d %8d\n",
371 cam->params.colourBalance.greenGain, 0, 212, 6); 371 cam->params.colourBalance.greenGain, 0, 212, 6);
372 out += sprintf(out, "blue_gain: %8d %8d %8d %8d\n", 372 out += sprintf(out, "blue_gain: %8d %8d %8d %8d\n",
373 cam->params.colourBalance.blueGain, 0, 212, 92); 373 cam->params.colourBalance.blueGain, 0, 212, 92);
374 374
375 if (cam->params.version.firmwareVersion == 1 && 375 if (cam->params.version.firmwareVersion == 1 &&
376 cam->params.version.firmwareRevision == 2) 376 cam->params.version.firmwareRevision == 2)
@@ -381,11 +381,11 @@ static int cpia_read_proc(char *page, char **start, off_t off,
381 381
382 if (cam->params.exposure.gainMode == 0) 382 if (cam->params.exposure.gainMode == 0)
383 out += sprintf(out, "max_gain: unknown %28s" 383 out += sprintf(out, "max_gain: unknown %28s"
384 " powers of 2\n", tmpstr); 384 " powers of 2\n", tmpstr);
385 else 385 else
386 out += sprintf(out, "max_gain: %8d %28s" 386 out += sprintf(out, "max_gain: %8d %28s"
387 " 1,2,4 or 8 \n", 387 " 1,2,4 or 8 \n",
388 1<<(cam->params.exposure.gainMode-1), tmpstr); 388 1<<(cam->params.exposure.gainMode-1), tmpstr);
389 389
390 switch(cam->params.exposure.expMode) { 390 switch(cam->params.exposure.expMode) {
391 case 1: 391 case 1:
@@ -402,10 +402,10 @@ static int cpia_read_proc(char *page, char **start, off_t off,
402 out += sprintf(out, "exposure_mode: %8s %8s %8s" 402 out += sprintf(out, "exposure_mode: %8s %8s %8s"
403 " %8s\n", tmpstr, "manual", "auto", "auto"); 403 " %8s\n", tmpstr, "manual", "auto", "auto");
404 out += sprintf(out, "centre_weight: %8s %8s %8s %8s\n", 404 out += sprintf(out, "centre_weight: %8s %8s %8s %8s\n",
405 (2-cam->params.exposure.centreWeight) ? "on" : "off", 405 (2-cam->params.exposure.centreWeight) ? "on" : "off",
406 "off", "on", "on"); 406 "off", "on", "on");
407 out += sprintf(out, "gain: %8d %8d max_gain %8d 1,2,4,8 possible\n", 407 out += sprintf(out, "gain: %8d %8d max_gain %8d 1,2,4,8 possible\n",
408 1<<cam->params.exposure.gain, 1, 1); 408 1<<cam->params.exposure.gain, 1, 1);
409 if (cam->params.version.firmwareVersion == 1 && 409 if (cam->params.version.firmwareVersion == 1 &&
410 cam->params.version.firmwareRevision == 2) 410 cam->params.version.firmwareRevision == 2)
411 /* 1-02 firmware limits fineExp/2 to 127 */ 411 /* 1-02 firmware limits fineExp/2 to 127 */
@@ -414,7 +414,7 @@ static int cpia_read_proc(char *page, char **start, off_t off,
414 tmp = 510; 414 tmp = 510;
415 415
416 out += sprintf(out, "fine_exp: %8d %8d %8d %8d\n", 416 out += sprintf(out, "fine_exp: %8d %8d %8d %8d\n",
417 cam->params.exposure.fineExp*2, 0, tmp, 0); 417 cam->params.exposure.fineExp*2, 0, tmp, 0);
418 if (cam->params.version.firmwareVersion == 1 && 418 if (cam->params.version.firmwareVersion == 1 &&
419 cam->params.version.firmwareRevision == 2) 419 cam->params.version.firmwareRevision == 2)
420 /* 1-02 firmware limits coarseExpHi to 0 */ 420 /* 1-02 firmware limits coarseExpHi to 0 */
@@ -426,46 +426,46 @@ static int cpia_read_proc(char *page, char **start, off_t off,
426 " %8d\n", cam->params.exposure.coarseExpLo+ 426 " %8d\n", cam->params.exposure.coarseExpLo+
427 256*cam->params.exposure.coarseExpHi, 0, tmp, 185); 427 256*cam->params.exposure.coarseExpHi, 0, tmp, 185);
428 out += sprintf(out, "red_comp: %8d %8d %8d %8d\n", 428 out += sprintf(out, "red_comp: %8d %8d %8d %8d\n",
429 cam->params.exposure.redComp, COMP_RED, 255, COMP_RED); 429 cam->params.exposure.redComp, COMP_RED, 255, COMP_RED);
430 out += sprintf(out, "green1_comp: %8d %8d %8d %8d\n", 430 out += sprintf(out, "green1_comp: %8d %8d %8d %8d\n",
431 cam->params.exposure.green1Comp, COMP_GREEN1, 255, 431 cam->params.exposure.green1Comp, COMP_GREEN1, 255,
432 COMP_GREEN1); 432 COMP_GREEN1);
433 out += sprintf(out, "green2_comp: %8d %8d %8d %8d\n", 433 out += sprintf(out, "green2_comp: %8d %8d %8d %8d\n",
434 cam->params.exposure.green2Comp, COMP_GREEN2, 255, 434 cam->params.exposure.green2Comp, COMP_GREEN2, 255,
435 COMP_GREEN2); 435 COMP_GREEN2);
436 out += sprintf(out, "blue_comp: %8d %8d %8d %8d\n", 436 out += sprintf(out, "blue_comp: %8d %8d %8d %8d\n",
437 cam->params.exposure.blueComp, COMP_BLUE, 255, COMP_BLUE); 437 cam->params.exposure.blueComp, COMP_BLUE, 255, COMP_BLUE);
438 438
439 out += sprintf(out, "apcor_gain1: %#8x %#8x %#8x %#8x\n", 439 out += sprintf(out, "apcor_gain1: %#8x %#8x %#8x %#8x\n",
440 cam->params.apcor.gain1, 0, 0xff, 0x1c); 440 cam->params.apcor.gain1, 0, 0xff, 0x1c);
441 out += sprintf(out, "apcor_gain2: %#8x %#8x %#8x %#8x\n", 441 out += sprintf(out, "apcor_gain2: %#8x %#8x %#8x %#8x\n",
442 cam->params.apcor.gain2, 0, 0xff, 0x1a); 442 cam->params.apcor.gain2, 0, 0xff, 0x1a);
443 out += sprintf(out, "apcor_gain4: %#8x %#8x %#8x %#8x\n", 443 out += sprintf(out, "apcor_gain4: %#8x %#8x %#8x %#8x\n",
444 cam->params.apcor.gain4, 0, 0xff, 0x2d); 444 cam->params.apcor.gain4, 0, 0xff, 0x2d);
445 out += sprintf(out, "apcor_gain8: %#8x %#8x %#8x %#8x\n", 445 out += sprintf(out, "apcor_gain8: %#8x %#8x %#8x %#8x\n",
446 cam->params.apcor.gain8, 0, 0xff, 0x2a); 446 cam->params.apcor.gain8, 0, 0xff, 0x2a);
447 out += sprintf(out, "vl_offset_gain1: %8d %8d %8d %8d\n", 447 out += sprintf(out, "vl_offset_gain1: %8d %8d %8d %8d\n",
448 cam->params.vlOffset.gain1, 0, 255, 24); 448 cam->params.vlOffset.gain1, 0, 255, 24);
449 out += sprintf(out, "vl_offset_gain2: %8d %8d %8d %8d\n", 449 out += sprintf(out, "vl_offset_gain2: %8d %8d %8d %8d\n",
450 cam->params.vlOffset.gain2, 0, 255, 28); 450 cam->params.vlOffset.gain2, 0, 255, 28);
451 out += sprintf(out, "vl_offset_gain4: %8d %8d %8d %8d\n", 451 out += sprintf(out, "vl_offset_gain4: %8d %8d %8d %8d\n",
452 cam->params.vlOffset.gain4, 0, 255, 30); 452 cam->params.vlOffset.gain4, 0, 255, 30);
453 out += sprintf(out, "vl_offset_gain8: %8d %8d %8d %8d\n", 453 out += sprintf(out, "vl_offset_gain8: %8d %8d %8d %8d\n",
454 cam->params.vlOffset.gain8, 0, 255, 30); 454 cam->params.vlOffset.gain8, 0, 255, 30);
455 out += sprintf(out, "flicker_control: %8s %8s %8s %8s\n", 455 out += sprintf(out, "flicker_control: %8s %8s %8s %8s\n",
456 cam->params.flickerControl.flickerMode ? "on" : "off", 456 cam->params.flickerControl.flickerMode ? "on" : "off",
457 "off", "on", "off"); 457 "off", "on", "off");
458 out += sprintf(out, "mains_frequency: %8d %8d %8d %8d" 458 out += sprintf(out, "mains_frequency: %8d %8d %8d %8d"
459 " only 50/60\n", 459 " only 50/60\n",
460 cam->mainsFreq ? 60 : 50, 50, 60, 50); 460 cam->mainsFreq ? 60 : 50, 50, 60, 50);
461 if(cam->params.flickerControl.allowableOverExposure < 0) 461 if(cam->params.flickerControl.allowableOverExposure < 0)
462 out += sprintf(out, "allowable_overexposure: %4dauto auto %8d auto\n", 462 out += sprintf(out, "allowable_overexposure: %4dauto auto %8d auto\n",
463 -cam->params.flickerControl.allowableOverExposure, 463 -cam->params.flickerControl.allowableOverExposure,
464 255); 464 255);
465 else 465 else
466 out += sprintf(out, "allowable_overexposure: %8d auto %8d auto\n", 466 out += sprintf(out, "allowable_overexposure: %8d auto %8d auto\n",
467 cam->params.flickerControl.allowableOverExposure, 467 cam->params.flickerControl.allowableOverExposure,
468 255); 468 255);
469 out += sprintf(out, "compression_mode: "); 469 out += sprintf(out, "compression_mode: ");
470 switch(cam->params.compression.mode) { 470 switch(cam->params.compression.mode) {
471 case CPIA_COMPRESSION_NONE: 471 case CPIA_COMPRESSION_NONE:
@@ -483,52 +483,52 @@ static int cpia_read_proc(char *page, char **start, off_t off,
483 } 483 }
484 out += sprintf(out, " none,auto,manual auto\n"); 484 out += sprintf(out, " none,auto,manual auto\n");
485 out += sprintf(out, "decimation_enable: %8s %8s %8s %8s\n", 485 out += sprintf(out, "decimation_enable: %8s %8s %8s %8s\n",
486 cam->params.compression.decimation == 486 cam->params.compression.decimation ==
487 DECIMATION_ENAB ? "on":"off", "off", "on", 487 DECIMATION_ENAB ? "on":"off", "off", "on",
488 "off"); 488 "off");
489 out += sprintf(out, "compression_target: %9s %9s %9s %9s\n", 489 out += sprintf(out, "compression_target: %9s %9s %9s %9s\n",
490 cam->params.compressionTarget.frTargeting == 490 cam->params.compressionTarget.frTargeting ==
491 CPIA_COMPRESSION_TARGET_FRAMERATE ? 491 CPIA_COMPRESSION_TARGET_FRAMERATE ?
492 "framerate":"quality", 492 "framerate":"quality",
493 "framerate", "quality", "quality"); 493 "framerate", "quality", "quality");
494 out += sprintf(out, "target_framerate: %8d %8d %8d %8d\n", 494 out += sprintf(out, "target_framerate: %8d %8d %8d %8d\n",
495 cam->params.compressionTarget.targetFR, 1, 30, 15); 495 cam->params.compressionTarget.targetFR, 1, 30, 15);
496 out += sprintf(out, "target_quality: %8d %8d %8d %8d\n", 496 out += sprintf(out, "target_quality: %8d %8d %8d %8d\n",
497 cam->params.compressionTarget.targetQ, 1, 64, 5); 497 cam->params.compressionTarget.targetQ, 1, 64, 5);
498 out += sprintf(out, "y_threshold: %8d %8d %8d %8d\n", 498 out += sprintf(out, "y_threshold: %8d %8d %8d %8d\n",
499 cam->params.yuvThreshold.yThreshold, 0, 31, 6); 499 cam->params.yuvThreshold.yThreshold, 0, 31, 6);
500 out += sprintf(out, "uv_threshold: %8d %8d %8d %8d\n", 500 out += sprintf(out, "uv_threshold: %8d %8d %8d %8d\n",
501 cam->params.yuvThreshold.uvThreshold, 0, 31, 6); 501 cam->params.yuvThreshold.uvThreshold, 0, 31, 6);
502 out += sprintf(out, "hysteresis: %8d %8d %8d %8d\n", 502 out += sprintf(out, "hysteresis: %8d %8d %8d %8d\n",
503 cam->params.compressionParams.hysteresis, 0, 255, 3); 503 cam->params.compressionParams.hysteresis, 0, 255, 3);
504 out += sprintf(out, "threshold_max: %8d %8d %8d %8d\n", 504 out += sprintf(out, "threshold_max: %8d %8d %8d %8d\n",
505 cam->params.compressionParams.threshMax, 0, 255, 11); 505 cam->params.compressionParams.threshMax, 0, 255, 11);
506 out += sprintf(out, "small_step: %8d %8d %8d %8d\n", 506 out += sprintf(out, "small_step: %8d %8d %8d %8d\n",
507 cam->params.compressionParams.smallStep, 0, 255, 1); 507 cam->params.compressionParams.smallStep, 0, 255, 1);
508 out += sprintf(out, "large_step: %8d %8d %8d %8d\n", 508 out += sprintf(out, "large_step: %8d %8d %8d %8d\n",
509 cam->params.compressionParams.largeStep, 0, 255, 3); 509 cam->params.compressionParams.largeStep, 0, 255, 3);
510 out += sprintf(out, "decimation_hysteresis: %8d %8d %8d %8d\n", 510 out += sprintf(out, "decimation_hysteresis: %8d %8d %8d %8d\n",
511 cam->params.compressionParams.decimationHysteresis, 511 cam->params.compressionParams.decimationHysteresis,
512 0, 255, 2); 512 0, 255, 2);
513 out += sprintf(out, "fr_diff_step_thresh: %8d %8d %8d %8d\n", 513 out += sprintf(out, "fr_diff_step_thresh: %8d %8d %8d %8d\n",
514 cam->params.compressionParams.frDiffStepThresh, 514 cam->params.compressionParams.frDiffStepThresh,
515 0, 255, 5); 515 0, 255, 5);
516 out += sprintf(out, "q_diff_step_thresh: %8d %8d %8d %8d\n", 516 out += sprintf(out, "q_diff_step_thresh: %8d %8d %8d %8d\n",
517 cam->params.compressionParams.qDiffStepThresh, 517 cam->params.compressionParams.qDiffStepThresh,
518 0, 255, 3); 518 0, 255, 3);
519 out += sprintf(out, "decimation_thresh_mod: %8d %8d %8d %8d\n", 519 out += sprintf(out, "decimation_thresh_mod: %8d %8d %8d %8d\n",
520 cam->params.compressionParams.decimationThreshMod, 520 cam->params.compressionParams.decimationThreshMod,
521 0, 255, 2); 521 0, 255, 2);
522 /* QX3 specific entries */ 522 /* QX3 specific entries */
523 if (cam->params.qx3.qx3_detected) { 523 if (cam->params.qx3.qx3_detected) {
524 out += sprintf(out, "toplight: %8s %8s %8s %8s\n", 524 out += sprintf(out, "toplight: %8s %8s %8s %8s\n",
525 cam->params.qx3.toplight ? "on" : "off", 525 cam->params.qx3.toplight ? "on" : "off",
526 "off", "on", "off"); 526 "off", "on", "off");
527 out += sprintf(out, "bottomlight: %8s %8s %8s %8s\n", 527 out += sprintf(out, "bottomlight: %8s %8s %8s %8s\n",
528 cam->params.qx3.bottomlight ? "on" : "off", 528 cam->params.qx3.bottomlight ? "on" : "off",
529 "off", "on", "off"); 529 "off", "on", "off");
530 } 530 }
531 531
532 len = out - page; 532 len = out - page;
533 len -= off; 533 len -= off;
534 if (len < count) { 534 if (len < count) {
@@ -543,7 +543,7 @@ static int cpia_read_proc(char *page, char **start, off_t off,
543 543
544 544
545static int match(char *checkstr, char **buffer, unsigned long *count, 545static int match(char *checkstr, char **buffer, unsigned long *count,
546 int *find_colon, int *err) 546 int *find_colon, int *err)
547{ 547{
548 int ret, colon_found = 1; 548 int ret, colon_found = 1;
549 int len = strlen(checkstr); 549 int len = strlen(checkstr);
@@ -583,7 +583,7 @@ static unsigned long int value(char **buffer, unsigned long *count, int *err)
583} 583}
584 584
585static int cpia_write_proc(struct file *file, const char __user *buf, 585static int cpia_write_proc(struct file *file, const char __user *buf,
586 unsigned long count, void *data) 586 unsigned long count, void *data)
587{ 587{
588 struct cam_data *cam = data; 588 struct cam_data *cam = data;
589 struct cam_params new_params; 589 struct cam_params new_params;
@@ -619,12 +619,12 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
619 retval = -EINVAL; 619 retval = -EINVAL;
620 goto out; 620 goto out;
621 } 621 }
622 622
623 buffer = page; 623 buffer = page;
624 624
625 if (mutex_lock_interruptible(&cam->param_lock)) 625 if (mutex_lock_interruptible(&cam->param_lock))
626 return -ERESTARTSYS; 626 return -ERESTARTSYS;
627 627
628 /* 628 /*
629 * Skip over leading whitespace 629 * Skip over leading whitespace
630 */ 630 */
@@ -632,15 +632,15 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
632 --count; 632 --count;
633 ++buffer; 633 ++buffer;
634 } 634 }
635 635
636 memcpy(&new_params, &cam->params, sizeof(struct cam_params)); 636 memcpy(&new_params, &cam->params, sizeof(struct cam_params));
637 new_mains = cam->mainsFreq; 637 new_mains = cam->mainsFreq;
638 638
639#define MATCH(x) (match(x, &buffer, &count, &find_colon, &retval)) 639#define MATCH(x) (match(x, &buffer, &count, &find_colon, &retval))
640#define VALUE (value(&buffer,&count, &retval)) 640#define VALUE (value(&buffer,&count, &retval))
641#define FIRMWARE_VERSION(x,y) (new_params.version.firmwareVersion == (x) && \ 641#define FIRMWARE_VERSION(x,y) (new_params.version.firmwareVersion == (x) && \
642 new_params.version.firmwareRevision == (y)) 642 new_params.version.firmwareRevision == (y))
643 643
644 retval = 0; 644 retval = 0;
645 while (count && !retval) { 645 while (count && !retval) {
646 find_colon = 1; 646 find_colon = 1;
@@ -656,7 +656,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
656 } 656 }
657 command_flags |= COMMAND_SETCOLOURPARAMS; 657 command_flags |= COMMAND_SETCOLOURPARAMS;
658 if(new_params.flickerControl.allowableOverExposure < 0) 658 if(new_params.flickerControl.allowableOverExposure < 0)
659 new_params.flickerControl.allowableOverExposure = 659 new_params.flickerControl.allowableOverExposure =
660 -find_over_exposure(new_params.colourParams.brightness); 660 -find_over_exposure(new_params.colourParams.brightness);
661 if(new_params.flickerControl.flickerMode != 0) 661 if(new_params.flickerControl.flickerMode != 0)
662 command_flags |= COMMAND_SETFLICKERCTRL; 662 command_flags |= COMMAND_SETFLICKERCTRL;
@@ -721,7 +721,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
721 /* Either base rate would work here */ 721 /* Either base rate would work here */
722 new_params.sensorFps.baserate = 1; 722 new_params.sensorFps.baserate = 1;
723 } 723 }
724 new_params.flickerControl.coarseJump = 724 new_params.flickerControl.coarseJump =
725 flicker_jumps[new_mains] 725 flicker_jumps[new_mains]
726 [new_params.sensorFps.baserate] 726 [new_params.sensorFps.baserate]
727 [new_params.sensorFps.divisor]; 727 [new_params.sensorFps.divisor];
@@ -1085,7 +1085,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1085 } else if (MATCH("mains_frequency")) { 1085 } else if (MATCH("mains_frequency")) {
1086 if (!retval && MATCH("50")) { 1086 if (!retval && MATCH("50")) {
1087 new_mains = 0; 1087 new_mains = 0;
1088 new_params.flickerControl.coarseJump = 1088 new_params.flickerControl.coarseJump =
1089 flicker_jumps[new_mains] 1089 flicker_jumps[new_mains]
1090 [new_params.sensorFps.baserate] 1090 [new_params.sensorFps.baserate]
1091 [new_params.sensorFps.divisor]; 1091 [new_params.sensorFps.divisor];
@@ -1093,7 +1093,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1093 command_flags |= COMMAND_SETFLICKERCTRL; 1093 command_flags |= COMMAND_SETFLICKERCTRL;
1094 } else if (!retval && MATCH("60")) { 1094 } else if (!retval && MATCH("60")) {
1095 new_mains = 1; 1095 new_mains = 1;
1096 new_params.flickerControl.coarseJump = 1096 new_params.flickerControl.coarseJump =
1097 flicker_jumps[new_mains] 1097 flicker_jumps[new_mains]
1098 [new_params.sensorFps.baserate] 1098 [new_params.sensorFps.baserate]
1099 [new_params.sensorFps.divisor]; 1099 [new_params.sensorFps.divisor];
@@ -1103,7 +1103,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1103 retval = -EINVAL; 1103 retval = -EINVAL;
1104 } else if (MATCH("allowable_overexposure")) { 1104 } else if (MATCH("allowable_overexposure")) {
1105 if (!retval && MATCH("auto")) { 1105 if (!retval && MATCH("auto")) {
1106 new_params.flickerControl.allowableOverExposure = 1106 new_params.flickerControl.allowableOverExposure =
1107 -find_over_exposure(new_params.colourParams.brightness); 1107 -find_over_exposure(new_params.colourParams.brightness);
1108 if(new_params.flickerControl.flickerMode != 0) 1108 if(new_params.flickerControl.flickerMode != 0)
1109 command_flags |= COMMAND_SETFLICKERCTRL; 1109 command_flags |= COMMAND_SETFLICKERCTRL;
@@ -1146,10 +1146,10 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1146 command_flags |= COMMAND_SETCOMPRESSION; 1146 command_flags |= COMMAND_SETCOMPRESSION;
1147 } else if (MATCH("compression_target")) { 1147 } else if (MATCH("compression_target")) {
1148 if (!retval && MATCH("quality")) 1148 if (!retval && MATCH("quality"))
1149 new_params.compressionTarget.frTargeting = 1149 new_params.compressionTarget.frTargeting =
1150 CPIA_COMPRESSION_TARGET_QUALITY; 1150 CPIA_COMPRESSION_TARGET_QUALITY;
1151 else if (!retval && MATCH("framerate")) 1151 else if (!retval && MATCH("framerate"))
1152 new_params.compressionTarget.frTargeting = 1152 new_params.compressionTarget.frTargeting =
1153 CPIA_COMPRESSION_TARGET_FRAMERATE; 1153 CPIA_COMPRESSION_TARGET_FRAMERATE;
1154 else 1154 else
1155 retval = -EINVAL; 1155 retval = -EINVAL;
@@ -1173,7 +1173,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1173 if (!retval) { 1173 if (!retval) {
1174 if(val > 0 && val <= 64) 1174 if(val > 0 && val <= 64)
1175 new_params.compressionTarget.targetQ = val; 1175 new_params.compressionTarget.targetQ = val;
1176 else 1176 else
1177 retval = -EINVAL; 1177 retval = -EINVAL;
1178 } 1178 }
1179 command_flags |= COMMAND_SETCOMPRESSIONTARGET; 1179 command_flags |= COMMAND_SETCOMPRESSIONTARGET;
@@ -1288,19 +1288,19 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1288 } 1288 }
1289 command_flags |= COMMAND_SETCOMPRESSIONPARAMS; 1289 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1290 } else if (MATCH("toplight")) { 1290 } else if (MATCH("toplight")) {
1291 if (!retval && MATCH("on")) 1291 if (!retval && MATCH("on"))
1292 new_params.qx3.toplight = 1; 1292 new_params.qx3.toplight = 1;
1293 else if (!retval && MATCH("off")) 1293 else if (!retval && MATCH("off"))
1294 new_params.qx3.toplight = 0; 1294 new_params.qx3.toplight = 0;
1295 else 1295 else
1296 retval = -EINVAL; 1296 retval = -EINVAL;
1297 command_flags |= COMMAND_SETLIGHTS; 1297 command_flags |= COMMAND_SETLIGHTS;
1298 } else if (MATCH("bottomlight")) { 1298 } else if (MATCH("bottomlight")) {
1299 if (!retval && MATCH("on")) 1299 if (!retval && MATCH("on"))
1300 new_params.qx3.bottomlight = 1; 1300 new_params.qx3.bottomlight = 1;
1301 else if (!retval && MATCH("off")) 1301 else if (!retval && MATCH("off"))
1302 new_params.qx3.bottomlight = 0; 1302 new_params.qx3.bottomlight = 0;
1303 else 1303 else
1304 retval = -EINVAL; 1304 retval = -EINVAL;
1305 command_flags |= COMMAND_SETLIGHTS; 1305 command_flags |= COMMAND_SETLIGHTS;
1306 } else { 1306 } else {
@@ -1326,7 +1326,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1326 } 1326 }
1327 } 1327 }
1328 } 1328 }
1329#undef MATCH 1329#undef MATCH
1330#undef VALUE 1330#undef VALUE
1331#undef FIRMWARE_VERSION 1331#undef FIRMWARE_VERSION
1332 if (!retval) { 1332 if (!retval) {
@@ -1349,24 +1349,24 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1349 retval = size; 1349 retval = size;
1350 } else 1350 } else
1351 DBG("error: %d\n", retval); 1351 DBG("error: %d\n", retval);
1352 1352
1353 mutex_unlock(&cam->param_lock); 1353 mutex_unlock(&cam->param_lock);
1354 1354
1355out: 1355out:
1356 free_page((unsigned long)page); 1356 free_page((unsigned long)page);
1357 return retval; 1357 return retval;
1358} 1358}
1359 1359
1360static void create_proc_cpia_cam(struct cam_data *cam) 1360static void create_proc_cpia_cam(struct cam_data *cam)
1361{ 1361{
1362 char name[7]; 1362 char name[7];
1363 struct proc_dir_entry *ent; 1363 struct proc_dir_entry *ent;
1364 1364
1365 if (!cpia_proc_root || !cam) 1365 if (!cpia_proc_root || !cam)
1366 return; 1366 return;
1367 1367
1368 sprintf(name, "video%d", cam->vdev.minor); 1368 sprintf(name, "video%d", cam->vdev.minor);
1369 1369
1370 ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, cpia_proc_root); 1370 ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, cpia_proc_root);
1371 if (!ent) 1371 if (!ent)
1372 return; 1372 return;
@@ -1374,9 +1374,9 @@ static void create_proc_cpia_cam(struct cam_data *cam)
1374 ent->data = cam; 1374 ent->data = cam;
1375 ent->read_proc = cpia_read_proc; 1375 ent->read_proc = cpia_read_proc;
1376 ent->write_proc = cpia_write_proc; 1376 ent->write_proc = cpia_write_proc;
1377 /* 1377 /*
1378 size of the proc entry is 3736 bytes for the standard webcam; 1378 size of the proc entry is 3736 bytes for the standard webcam;
1379 the extra features of the QX3 microscope add 189 bytes. 1379 the extra features of the QX3 microscope add 189 bytes.
1380 (we have not yet probed the camera to see which type it is). 1380 (we have not yet probed the camera to see which type it is).
1381 */ 1381 */
1382 ent->size = 3736 + 189; 1382 ent->size = 3736 + 189;
@@ -1386,10 +1386,10 @@ static void create_proc_cpia_cam(struct cam_data *cam)
1386static void destroy_proc_cpia_cam(struct cam_data *cam) 1386static void destroy_proc_cpia_cam(struct cam_data *cam)
1387{ 1387{
1388 char name[7]; 1388 char name[7];
1389 1389
1390 if (!cam || !cam->proc_entry) 1390 if (!cam || !cam->proc_entry)
1391 return; 1391 return;
1392 1392
1393 sprintf(name, "video%d", cam->vdev.minor); 1393 sprintf(name, "video%d", cam->vdev.minor);
1394 remove_proc_entry(name, cpia_proc_root); 1394 remove_proc_entry(name, cpia_proc_root);
1395 cam->proc_entry = NULL; 1395 cam->proc_entry = NULL;
@@ -1596,13 +1596,13 @@ static void set_vw_size(struct cam_data *cam)
1596 cam->vc.width = cam->vw.width; 1596 cam->vc.width = cam->vw.width;
1597 if(cam->vc.height == 0) 1597 if(cam->vc.height == 0)
1598 cam->vc.height = cam->vw.height; 1598 cam->vc.height = cam->vw.height;
1599 1599
1600 cam->params.roi.colStart += cam->vc.x >> 3; 1600 cam->params.roi.colStart += cam->vc.x >> 3;
1601 cam->params.roi.colEnd = cam->params.roi.colStart + 1601 cam->params.roi.colEnd = cam->params.roi.colStart +
1602 (cam->vc.width >> 3); 1602 (cam->vc.width >> 3);
1603 cam->params.roi.rowStart += cam->vc.y >> 2; 1603 cam->params.roi.rowStart += cam->vc.y >> 2;
1604 cam->params.roi.rowEnd = cam->params.roi.rowStart + 1604 cam->params.roi.rowEnd = cam->params.roi.rowStart +
1605 (cam->vc.height >> 2); 1605 (cam->vc.height >> 2);
1606 1606
1607 return; 1607 return;
1608} 1608}
@@ -1624,7 +1624,7 @@ static int allocate_frame_buf(struct cam_data *cam)
1624static int free_frame_buf(struct cam_data *cam) 1624static int free_frame_buf(struct cam_data *cam)
1625{ 1625{
1626 int i; 1626 int i;
1627 1627
1628 rvfree(cam->frame_buf, FRAME_NUM*CPIA_MAX_FRAME_SIZE); 1628 rvfree(cam->frame_buf, FRAME_NUM*CPIA_MAX_FRAME_SIZE);
1629 cam->frame_buf = NULL; 1629 cam->frame_buf = NULL;
1630 for (i=0; i < FRAME_NUM; i++) 1630 for (i=0; i < FRAME_NUM; i++)
@@ -1667,7 +1667,7 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1667 mutex_lock(&cam->param_lock); 1667 mutex_lock(&cam->param_lock);
1668 datasize=8; 1668 datasize=8;
1669 break; 1669 break;
1670 case CPIA_COMMAND_ReadMCPorts: 1670 case CPIA_COMMAND_ReadMCPorts:
1671 case CPIA_COMMAND_ReadVCRegs: 1671 case CPIA_COMMAND_ReadVCRegs:
1672 datasize = 4; 1672 datasize = 4;
1673 break; 1673 break;
@@ -1746,10 +1746,10 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1746 mutex_unlock(&cam->param_lock); 1746 mutex_unlock(&cam->param_lock);
1747 break; 1747 break;
1748 1748
1749 case CPIA_COMMAND_ReadMCPorts: 1749 case CPIA_COMMAND_ReadMCPorts:
1750 if (!cam->params.qx3.qx3_detected) 1750 if (!cam->params.qx3.qx3_detected)
1751 break; 1751 break;
1752 /* test button press */ 1752 /* test button press */
1753 cam->params.qx3.button = ((data[1] & 0x02) == 0); 1753 cam->params.qx3.button = ((data[1] & 0x02) == 0);
1754 if (cam->params.qx3.button) { 1754 if (cam->params.qx3.button) {
1755 /* button pressed - unlock the latch */ 1755 /* button pressed - unlock the latch */
@@ -1770,9 +1770,9 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1770 1770
1771/* send a command to the camera with an additional data transaction */ 1771/* send a command to the camera with an additional data transaction */
1772static int do_command_extended(struct cam_data *cam, u16 command, 1772static int do_command_extended(struct cam_data *cam, u16 command,
1773 u8 a, u8 b, u8 c, u8 d, 1773 u8 a, u8 b, u8 c, u8 d,
1774 u8 e, u8 f, u8 g, u8 h, 1774 u8 e, u8 f, u8 g, u8 h,
1775 u8 i, u8 j, u8 k, u8 l) 1775 u8 i, u8 j, u8 k, u8 l)
1776{ 1776{
1777 int retval; 1777 int retval;
1778 u8 cmd[8], data[8]; 1778 u8 cmd[8], data[8];
@@ -1809,10 +1809,10 @@ static int do_command_extended(struct cam_data *cam, u16 command,
1809#define LIMIT(x) ((((x)>0xffffff)?0xff0000:(((x)<=0xffff)?0:(x)&0xff0000))>>16) 1809#define LIMIT(x) ((((x)>0xffffff)?0xff0000:(((x)<=0xffff)?0:(x)&0xff0000))>>16)
1810 1810
1811static int convert420(unsigned char *yuv, unsigned char *rgb, int out_fmt, 1811static int convert420(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1812 int linesize, int mmap_kludge) 1812 int linesize, int mmap_kludge)
1813{ 1813{
1814 int y, u, v, r, g, b, y1; 1814 int y, u, v, r, g, b, y1;
1815 1815
1816 /* Odd lines use the same u and v as the previous line. 1816 /* Odd lines use the same u and v as the previous line.
1817 * Because of compression, it is necessary to get this 1817 * Because of compression, it is necessary to get this
1818 * information from the decoded image. */ 1818 * information from the decoded image. */
@@ -1925,7 +1925,7 @@ static int convert420(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1925 1925
1926 1926
1927static int yuvconvert(unsigned char *yuv, unsigned char *rgb, int out_fmt, 1927static int yuvconvert(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1928 int in_uyvy, int mmap_kludge) 1928 int in_uyvy, int mmap_kludge)
1929{ 1929{
1930 int y, u, v, r, g, b, y1; 1930 int y, u, v, r, g, b, y1;
1931 1931
@@ -2078,21 +2078,21 @@ static int parse_picture(struct cam_data *cam, int size)
2078 mutex_unlock(&cam->param_lock); 2078 mutex_unlock(&cam->param_lock);
2079 return -1; 2079 return -1;
2080 } 2080 }
2081 2081
2082 if (ibuf[17] != SUBSAMPLE_420 && ibuf[17] != SUBSAMPLE_422) { 2082 if (ibuf[17] != SUBSAMPLE_420 && ibuf[17] != SUBSAMPLE_422) {
2083 LOG("illegal subtype %d\n",ibuf[17]); 2083 LOG("illegal subtype %d\n",ibuf[17]);
2084 mutex_unlock(&cam->param_lock); 2084 mutex_unlock(&cam->param_lock);
2085 return -1; 2085 return -1;
2086 } 2086 }
2087 subsample_422 = ibuf[17] == SUBSAMPLE_422; 2087 subsample_422 = ibuf[17] == SUBSAMPLE_422;
2088 2088
2089 if (ibuf[18] != YUVORDER_YUYV && ibuf[18] != YUVORDER_UYVY) { 2089 if (ibuf[18] != YUVORDER_YUYV && ibuf[18] != YUVORDER_UYVY) {
2090 LOG("illegal yuvorder %d\n",ibuf[18]); 2090 LOG("illegal yuvorder %d\n",ibuf[18]);
2091 mutex_unlock(&cam->param_lock); 2091 mutex_unlock(&cam->param_lock);
2092 return -1; 2092 return -1;
2093 } 2093 }
2094 in_uyvy = ibuf[18] == YUVORDER_UYVY; 2094 in_uyvy = ibuf[18] == YUVORDER_UYVY;
2095 2095
2096 if ((ibuf[24] != cam->params.roi.colStart) || 2096 if ((ibuf[24] != cam->params.roi.colStart) ||
2097 (ibuf[25] != cam->params.roi.colEnd) || 2097 (ibuf[25] != cam->params.roi.colEnd) ||
2098 (ibuf[26] != cam->params.roi.rowStart) || 2098 (ibuf[26] != cam->params.roi.rowStart) ||
@@ -2104,20 +2104,20 @@ static int parse_picture(struct cam_data *cam, int size)
2104 cols = 8*(ibuf[25] - ibuf[24]); 2104 cols = 8*(ibuf[25] - ibuf[24]);
2105 rows = 4*(ibuf[27] - ibuf[26]); 2105 rows = 4*(ibuf[27] - ibuf[26]);
2106 2106
2107 2107
2108 if ((ibuf[28] != NOT_COMPRESSED) && (ibuf[28] != COMPRESSED)) { 2108 if ((ibuf[28] != NOT_COMPRESSED) && (ibuf[28] != COMPRESSED)) {
2109 LOG("illegal compression %d\n",ibuf[28]); 2109 LOG("illegal compression %d\n",ibuf[28]);
2110 mutex_unlock(&cam->param_lock); 2110 mutex_unlock(&cam->param_lock);
2111 return -1; 2111 return -1;
2112 } 2112 }
2113 compressed = (ibuf[28] == COMPRESSED); 2113 compressed = (ibuf[28] == COMPRESSED);
2114 2114
2115 if (ibuf[29] != NO_DECIMATION && ibuf[29] != DECIMATION_ENAB) { 2115 if (ibuf[29] != NO_DECIMATION && ibuf[29] != DECIMATION_ENAB) {
2116 LOG("illegal decimation %d\n",ibuf[29]); 2116 LOG("illegal decimation %d\n",ibuf[29]);
2117 mutex_unlock(&cam->param_lock); 2117 mutex_unlock(&cam->param_lock);
2118 return -1; 2118 return -1;
2119 } 2119 }
2120 decimation = (ibuf[29] == DECIMATION_ENAB); 2120 decimation = (ibuf[29] == DECIMATION_ENAB);
2121 2121
2122 cam->params.yuvThreshold.yThreshold = ibuf[30]; 2122 cam->params.yuvThreshold.yThreshold = ibuf[30];
2123 cam->params.yuvThreshold.uvThreshold = ibuf[31]; 2123 cam->params.yuvThreshold.uvThreshold = ibuf[31];
@@ -2131,7 +2131,7 @@ static int parse_picture(struct cam_data *cam, int size)
2131 cam->params.status.errorCode = ibuf[39]; 2131 cam->params.status.errorCode = ibuf[39];
2132 cam->fps = ibuf[41]; 2132 cam->fps = ibuf[41];
2133 mutex_unlock(&cam->param_lock); 2133 mutex_unlock(&cam->param_lock);
2134 2134
2135 linesize = skipcount(cols, out_fmt); 2135 linesize = skipcount(cols, out_fmt);
2136 ibuf += FRAME_HEADER_SIZE; 2136 ibuf += FRAME_HEADER_SIZE;
2137 size -= FRAME_HEADER_SIZE; 2137 size -= FRAME_HEADER_SIZE;
@@ -2150,14 +2150,14 @@ static int parse_picture(struct cam_data *cam, int size)
2150 if (!compressed || (compressed && !(*ibuf & 1))) { 2150 if (!compressed || (compressed && !(*ibuf & 1))) {
2151 if(subsample_422 || even_line) { 2151 if(subsample_422 || even_line) {
2152 obuf += yuvconvert(ibuf, obuf, out_fmt, 2152 obuf += yuvconvert(ibuf, obuf, out_fmt,
2153 in_uyvy, cam->mmap_kludge); 2153 in_uyvy, cam->mmap_kludge);
2154 ibuf += 4; 2154 ibuf += 4;
2155 ll -= 4; 2155 ll -= 4;
2156 } else { 2156 } else {
2157 /* SUBSAMPLE_420 on an odd line */ 2157 /* SUBSAMPLE_420 on an odd line */
2158 obuf += convert420(ibuf, obuf, 2158 obuf += convert420(ibuf, obuf,
2159 out_fmt, linesize, 2159 out_fmt, linesize,
2160 cam->mmap_kludge); 2160 cam->mmap_kludge);
2161 ibuf += 2; 2161 ibuf += 2;
2162 ll -= 2; 2162 ll -= 2;
2163 } 2163 }
@@ -2183,7 +2183,7 @@ static int parse_picture(struct cam_data *cam, int size)
2183 2183
2184 if ((size > 3) && (ibuf[0] == EOI) && (ibuf[1] == EOI) && 2184 if ((size > 3) && (ibuf[0] == EOI) && (ibuf[1] == EOI) &&
2185 (ibuf[2] == EOI) && (ibuf[3] == EOI)) { 2185 (ibuf[2] == EOI) && (ibuf[3] == EOI)) {
2186 size -= 4; 2186 size -= 4;
2187 break; 2187 break;
2188 } 2188 }
2189 2189
@@ -2204,7 +2204,7 @@ static int parse_picture(struct cam_data *cam, int size)
2204 return -1; 2204 return -1;
2205 } 2205 }
2206 } 2206 }
2207 2207
2208 if(decimation) { 2208 if(decimation) {
2209 /* interpolate odd rows */ 2209 /* interpolate odd rows */
2210 int i, j; 2210 int i, j;
@@ -2233,7 +2233,7 @@ static int parse_picture(struct cam_data *cam, int size)
2233static inline int init_stream_cap(struct cam_data *cam) 2233static inline int init_stream_cap(struct cam_data *cam)
2234{ 2234{
2235 return do_command(cam, CPIA_COMMAND_InitStreamCap, 2235 return do_command(cam, CPIA_COMMAND_InitStreamCap,
2236 0, cam->params.streamStartLine, 0, 0); 2236 0, cam->params.streamStartLine, 0, 0);
2237} 2237}
2238 2238
2239 2239
@@ -2254,7 +2254,7 @@ static int find_over_exposure(int brightness)
2254 int MaxAllowableOverExposure, OverExposure; 2254 int MaxAllowableOverExposure, OverExposure;
2255 2255
2256 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness - 2256 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness -
2257 FLICKER_BRIGHTNESS_CONSTANT; 2257 FLICKER_BRIGHTNESS_CONSTANT;
2258 2258
2259 if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE) { 2259 if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE) {
2260 OverExposure = MaxAllowableOverExposure; 2260 OverExposure = MaxAllowableOverExposure;
@@ -2280,62 +2280,62 @@ static void dispatch_commands(struct cam_data *cam)
2280 DEB_BYTE(cam->cmd_queue>>8); 2280 DEB_BYTE(cam->cmd_queue>>8);
2281 if (cam->cmd_queue & COMMAND_SETFORMAT) { 2281 if (cam->cmd_queue & COMMAND_SETFORMAT) {
2282 do_command(cam, CPIA_COMMAND_SetFormat, 2282 do_command(cam, CPIA_COMMAND_SetFormat,
2283 cam->params.format.videoSize, 2283 cam->params.format.videoSize,
2284 cam->params.format.subSample, 2284 cam->params.format.subSample,
2285 cam->params.format.yuvOrder, 0); 2285 cam->params.format.yuvOrder, 0);
2286 do_command(cam, CPIA_COMMAND_SetROI, 2286 do_command(cam, CPIA_COMMAND_SetROI,
2287 cam->params.roi.colStart, cam->params.roi.colEnd, 2287 cam->params.roi.colStart, cam->params.roi.colEnd,
2288 cam->params.roi.rowStart, cam->params.roi.rowEnd); 2288 cam->params.roi.rowStart, cam->params.roi.rowEnd);
2289 cam->first_frame = 1; 2289 cam->first_frame = 1;
2290 } 2290 }
2291 2291
2292 if (cam->cmd_queue & COMMAND_SETCOLOURPARAMS) 2292 if (cam->cmd_queue & COMMAND_SETCOLOURPARAMS)
2293 do_command(cam, CPIA_COMMAND_SetColourParams, 2293 do_command(cam, CPIA_COMMAND_SetColourParams,
2294 cam->params.colourParams.brightness, 2294 cam->params.colourParams.brightness,
2295 cam->params.colourParams.contrast, 2295 cam->params.colourParams.contrast,
2296 cam->params.colourParams.saturation, 0); 2296 cam->params.colourParams.saturation, 0);
2297 2297
2298 if (cam->cmd_queue & COMMAND_SETAPCOR) 2298 if (cam->cmd_queue & COMMAND_SETAPCOR)
2299 do_command(cam, CPIA_COMMAND_SetApcor, 2299 do_command(cam, CPIA_COMMAND_SetApcor,
2300 cam->params.apcor.gain1, 2300 cam->params.apcor.gain1,
2301 cam->params.apcor.gain2, 2301 cam->params.apcor.gain2,
2302 cam->params.apcor.gain4, 2302 cam->params.apcor.gain4,
2303 cam->params.apcor.gain8); 2303 cam->params.apcor.gain8);
2304 2304
2305 if (cam->cmd_queue & COMMAND_SETVLOFFSET) 2305 if (cam->cmd_queue & COMMAND_SETVLOFFSET)
2306 do_command(cam, CPIA_COMMAND_SetVLOffset, 2306 do_command(cam, CPIA_COMMAND_SetVLOffset,
2307 cam->params.vlOffset.gain1, 2307 cam->params.vlOffset.gain1,
2308 cam->params.vlOffset.gain2, 2308 cam->params.vlOffset.gain2,
2309 cam->params.vlOffset.gain4, 2309 cam->params.vlOffset.gain4,
2310 cam->params.vlOffset.gain8); 2310 cam->params.vlOffset.gain8);
2311 2311
2312 if (cam->cmd_queue & COMMAND_SETEXPOSURE) { 2312 if (cam->cmd_queue & COMMAND_SETEXPOSURE) {
2313 do_command_extended(cam, CPIA_COMMAND_SetExposure, 2313 do_command_extended(cam, CPIA_COMMAND_SetExposure,
2314 cam->params.exposure.gainMode, 2314 cam->params.exposure.gainMode,
2315 1, 2315 1,
2316 cam->params.exposure.compMode, 2316 cam->params.exposure.compMode,
2317 cam->params.exposure.centreWeight, 2317 cam->params.exposure.centreWeight,
2318 cam->params.exposure.gain, 2318 cam->params.exposure.gain,
2319 cam->params.exposure.fineExp, 2319 cam->params.exposure.fineExp,
2320 cam->params.exposure.coarseExpLo, 2320 cam->params.exposure.coarseExpLo,
2321 cam->params.exposure.coarseExpHi, 2321 cam->params.exposure.coarseExpHi,
2322 cam->params.exposure.redComp, 2322 cam->params.exposure.redComp,
2323 cam->params.exposure.green1Comp, 2323 cam->params.exposure.green1Comp,
2324 cam->params.exposure.green2Comp, 2324 cam->params.exposure.green2Comp,
2325 cam->params.exposure.blueComp); 2325 cam->params.exposure.blueComp);
2326 if(cam->params.exposure.expMode != 1) { 2326 if(cam->params.exposure.expMode != 1) {
2327 do_command_extended(cam, CPIA_COMMAND_SetExposure, 2327 do_command_extended(cam, CPIA_COMMAND_SetExposure,
2328 0, 2328 0,
2329 cam->params.exposure.expMode, 2329 cam->params.exposure.expMode,
2330 0, 0, 2330 0, 0,
2331 cam->params.exposure.gain, 2331 cam->params.exposure.gain,
2332 cam->params.exposure.fineExp, 2332 cam->params.exposure.fineExp,
2333 cam->params.exposure.coarseExpLo, 2333 cam->params.exposure.coarseExpLo,
2334 cam->params.exposure.coarseExpHi, 2334 cam->params.exposure.coarseExpHi,
2335 0, 0, 0, 0); 2335 0, 0, 0, 0);
2336 } 2336 }
2337 } 2337 }
2338 2338
2339 if (cam->cmd_queue & COMMAND_SETCOLOURBALANCE) { 2339 if (cam->cmd_queue & COMMAND_SETCOLOURBALANCE) {
2340 if (cam->params.colourBalance.balanceMode == 1) { 2340 if (cam->params.colourBalance.balanceMode == 1) {
2341 do_command(cam, CPIA_COMMAND_SetColourBalance, 2341 do_command(cam, CPIA_COMMAND_SetColourBalance,
@@ -2358,47 +2358,47 @@ static void dispatch_commands(struct cam_data *cam)
2358 2358
2359 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONTARGET) 2359 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONTARGET)
2360 do_command(cam, CPIA_COMMAND_SetCompressionTarget, 2360 do_command(cam, CPIA_COMMAND_SetCompressionTarget,
2361 cam->params.compressionTarget.frTargeting, 2361 cam->params.compressionTarget.frTargeting,
2362 cam->params.compressionTarget.targetFR, 2362 cam->params.compressionTarget.targetFR,
2363 cam->params.compressionTarget.targetQ, 0); 2363 cam->params.compressionTarget.targetQ, 0);
2364 2364
2365 if (cam->cmd_queue & COMMAND_SETYUVTHRESH) 2365 if (cam->cmd_queue & COMMAND_SETYUVTHRESH)
2366 do_command(cam, CPIA_COMMAND_SetYUVThresh, 2366 do_command(cam, CPIA_COMMAND_SetYUVThresh,
2367 cam->params.yuvThreshold.yThreshold, 2367 cam->params.yuvThreshold.yThreshold,
2368 cam->params.yuvThreshold.uvThreshold, 0, 0); 2368 cam->params.yuvThreshold.uvThreshold, 0, 0);
2369 2369
2370 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONPARAMS) 2370 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONPARAMS)
2371 do_command_extended(cam, CPIA_COMMAND_SetCompressionParams, 2371 do_command_extended(cam, CPIA_COMMAND_SetCompressionParams,
2372 0, 0, 0, 0, 2372 0, 0, 0, 0,
2373 cam->params.compressionParams.hysteresis, 2373 cam->params.compressionParams.hysteresis,
2374 cam->params.compressionParams.threshMax, 2374 cam->params.compressionParams.threshMax,
2375 cam->params.compressionParams.smallStep, 2375 cam->params.compressionParams.smallStep,
2376 cam->params.compressionParams.largeStep, 2376 cam->params.compressionParams.largeStep,
2377 cam->params.compressionParams.decimationHysteresis, 2377 cam->params.compressionParams.decimationHysteresis,
2378 cam->params.compressionParams.frDiffStepThresh, 2378 cam->params.compressionParams.frDiffStepThresh,
2379 cam->params.compressionParams.qDiffStepThresh, 2379 cam->params.compressionParams.qDiffStepThresh,
2380 cam->params.compressionParams.decimationThreshMod); 2380 cam->params.compressionParams.decimationThreshMod);
2381 2381
2382 if (cam->cmd_queue & COMMAND_SETCOMPRESSION) 2382 if (cam->cmd_queue & COMMAND_SETCOMPRESSION)
2383 do_command(cam, CPIA_COMMAND_SetCompression, 2383 do_command(cam, CPIA_COMMAND_SetCompression,
2384 cam->params.compression.mode, 2384 cam->params.compression.mode,
2385 cam->params.compression.decimation, 0, 0); 2385 cam->params.compression.decimation, 0, 0);
2386 2386
2387 if (cam->cmd_queue & COMMAND_SETSENSORFPS) 2387 if (cam->cmd_queue & COMMAND_SETSENSORFPS)
2388 do_command(cam, CPIA_COMMAND_SetSensorFPS, 2388 do_command(cam, CPIA_COMMAND_SetSensorFPS,
2389 cam->params.sensorFps.divisor, 2389 cam->params.sensorFps.divisor,
2390 cam->params.sensorFps.baserate, 0, 0); 2390 cam->params.sensorFps.baserate, 0, 0);
2391 2391
2392 if (cam->cmd_queue & COMMAND_SETFLICKERCTRL) 2392 if (cam->cmd_queue & COMMAND_SETFLICKERCTRL)
2393 do_command(cam, CPIA_COMMAND_SetFlickerCtrl, 2393 do_command(cam, CPIA_COMMAND_SetFlickerCtrl,
2394 cam->params.flickerControl.flickerMode, 2394 cam->params.flickerControl.flickerMode,
2395 cam->params.flickerControl.coarseJump, 2395 cam->params.flickerControl.coarseJump,
2396 abs(cam->params.flickerControl.allowableOverExposure), 2396 abs(cam->params.flickerControl.allowableOverExposure),
2397 0); 2397 0);
2398 2398
2399 if (cam->cmd_queue & COMMAND_SETECPTIMING) 2399 if (cam->cmd_queue & COMMAND_SETECPTIMING)
2400 do_command(cam, CPIA_COMMAND_SetECPTiming, 2400 do_command(cam, CPIA_COMMAND_SetECPTiming,
2401 cam->params.ecpTiming, 0, 0, 0); 2401 cam->params.ecpTiming, 0, 0, 0);
2402 2402
2403 if (cam->cmd_queue & COMMAND_PAUSE) 2403 if (cam->cmd_queue & COMMAND_PAUSE)
2404 do_command(cam, CPIA_COMMAND_EndStreamCap, 0, 0, 0, 0); 2404 do_command(cam, CPIA_COMMAND_EndStreamCap, 0, 0, 0, 0);
@@ -2409,9 +2409,9 @@ static void dispatch_commands(struct cam_data *cam)
2409 if (cam->cmd_queue & COMMAND_SETLIGHTS && cam->params.qx3.qx3_detected) 2409 if (cam->cmd_queue & COMMAND_SETLIGHTS && cam->params.qx3.qx3_detected)
2410 { 2410 {
2411 int p1 = (cam->params.qx3.bottomlight == 0) << 1; 2411 int p1 = (cam->params.qx3.bottomlight == 0) << 1;
2412 int p2 = (cam->params.qx3.toplight == 0) << 3; 2412 int p2 = (cam->params.qx3.toplight == 0) << 3;
2413 do_command(cam, CPIA_COMMAND_WriteVCReg, 0x90, 0x8F, 0x50, 0); 2413 do_command(cam, CPIA_COMMAND_WriteVCReg, 0x90, 0x8F, 0x50, 0);
2414 do_command(cam, CPIA_COMMAND_WriteMCPort, 2, 0, (p1|p2|0xE0), 0); 2414 do_command(cam, CPIA_COMMAND_WriteMCPort, 2, 0, (p1|p2|0xE0), 0);
2415 } 2415 }
2416 2416
2417 cam->cmd_queue = COMMAND_NONE; 2417 cam->cmd_queue = COMMAND_NONE;
@@ -2422,11 +2422,11 @@ static void dispatch_commands(struct cam_data *cam)
2422 2422
2423 2423
2424static void set_flicker(struct cam_params *params, volatile u32 *command_flags, 2424static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2425 int on) 2425 int on)
2426{ 2426{
2427 /* Everything in here is from the Windows driver */ 2427 /* Everything in here is from the Windows driver */
2428#define FIRMWARE_VERSION(x,y) (params->version.firmwareVersion == (x) && \ 2428#define FIRMWARE_VERSION(x,y) (params->version.firmwareVersion == (x) && \
2429 params->version.firmwareRevision == (y)) 2429 params->version.firmwareRevision == (y))
2430/* define for compgain calculation */ 2430/* define for compgain calculation */
2431#if 0 2431#if 0
2432#define COMPGAIN(base, curexp, newexp) \ 2432#define COMPGAIN(base, curexp, newexp) \
@@ -2441,7 +2441,7 @@ static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2441 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128))) 2441 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128)))
2442#endif 2442#endif
2443 2443
2444 2444
2445 int currentexp = params->exposure.coarseExpLo + 2445 int currentexp = params->exposure.coarseExpLo +
2446 params->exposure.coarseExpHi*256; 2446 params->exposure.coarseExpHi*256;
2447 int startexp; 2447 int startexp;
@@ -2482,7 +2482,7 @@ static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2482 } 2482 }
2483 if(FIRMWARE_VERSION(1,2)) 2483 if(FIRMWARE_VERSION(1,2))
2484 params->exposure.compMode = 0; 2484 params->exposure.compMode = 0;
2485 else 2485 else
2486 params->exposure.compMode = 1; 2486 params->exposure.compMode = 1;
2487 2487
2488 params->apcor.gain1 = 0x18; 2488 params->apcor.gain1 = 0x18;
@@ -2533,14 +2533,14 @@ static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2533} 2533}
2534 2534
2535#define FIRMWARE_VERSION(x,y) (cam->params.version.firmwareVersion == (x) && \ 2535#define FIRMWARE_VERSION(x,y) (cam->params.version.firmwareVersion == (x) && \
2536 cam->params.version.firmwareRevision == (y)) 2536 cam->params.version.firmwareRevision == (y))
2537/* monitor the exposure and adjust the sensor frame rate if needed */ 2537/* monitor the exposure and adjust the sensor frame rate if needed */
2538static void monitor_exposure(struct cam_data *cam) 2538static void monitor_exposure(struct cam_data *cam)
2539{ 2539{
2540 u8 exp_acc, bcomp, gain, coarseL, cmd[8], data[8]; 2540 u8 exp_acc, bcomp, gain, coarseL, cmd[8], data[8];
2541 int retval, light_exp, dark_exp, very_dark_exp; 2541 int retval, light_exp, dark_exp, very_dark_exp;
2542 int old_exposure, new_exposure, framerate; 2542 int old_exposure, new_exposure, framerate;
2543 2543
2544 /* get necessary stats and register settings from camera */ 2544 /* get necessary stats and register settings from camera */
2545 /* do_command can't handle this, so do it ourselves */ 2545 /* do_command can't handle this, so do it ourselves */
2546 cmd[0] = CPIA_COMMAND_ReadVPRegs>>8; 2546 cmd[0] = CPIA_COMMAND_ReadVPRegs>>8;
@@ -2564,17 +2564,17 @@ static void monitor_exposure(struct cam_data *cam)
2564 2564
2565 mutex_lock(&cam->param_lock); 2565 mutex_lock(&cam->param_lock);
2566 light_exp = cam->params.colourParams.brightness + 2566 light_exp = cam->params.colourParams.brightness +
2567 TC - 50 + EXP_ACC_LIGHT; 2567 TC - 50 + EXP_ACC_LIGHT;
2568 if(light_exp > 255) 2568 if(light_exp > 255)
2569 light_exp = 255; 2569 light_exp = 255;
2570 dark_exp = cam->params.colourParams.brightness + 2570 dark_exp = cam->params.colourParams.brightness +
2571 TC - 50 - EXP_ACC_DARK; 2571 TC - 50 - EXP_ACC_DARK;
2572 if(dark_exp < 0) 2572 if(dark_exp < 0)
2573 dark_exp = 0; 2573 dark_exp = 0;
2574 very_dark_exp = dark_exp/2; 2574 very_dark_exp = dark_exp/2;
2575 2575
2576 old_exposure = cam->params.exposure.coarseExpHi * 256 + 2576 old_exposure = cam->params.exposure.coarseExpHi * 256 +
2577 cam->params.exposure.coarseExpLo; 2577 cam->params.exposure.coarseExpLo;
2578 2578
2579 if(!cam->params.flickerControl.disabled) { 2579 if(!cam->params.flickerControl.disabled) {
2580 /* Flicker control on */ 2580 /* Flicker control on */
@@ -2667,11 +2667,11 @@ static void monitor_exposure(struct cam_data *cam)
2667 cam->exposure_status = EXPOSURE_NORMAL; 2667 cam->exposure_status = EXPOSURE_NORMAL;
2668 } 2668 }
2669 } 2669 }
2670 2670
2671 framerate = cam->fps; 2671 framerate = cam->fps;
2672 if(framerate > 30 || framerate < 1) 2672 if(framerate > 30 || framerate < 1)
2673 framerate = 1; 2673 framerate = 1;
2674 2674
2675 if(!cam->params.flickerControl.disabled) { 2675 if(!cam->params.flickerControl.disabled) {
2676 /* Flicker control on */ 2676 /* Flicker control on */
2677 if((cam->exposure_status == EXPOSURE_VERY_DARK || 2677 if((cam->exposure_status == EXPOSURE_VERY_DARK ||
@@ -2683,10 +2683,10 @@ static void monitor_exposure(struct cam_data *cam)
2683 ++cam->params.sensorFps.divisor; 2683 ++cam->params.sensorFps.divisor;
2684 cam->cmd_queue |= COMMAND_SETSENSORFPS; 2684 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2685 2685
2686 cam->params.flickerControl.coarseJump = 2686 cam->params.flickerControl.coarseJump =
2687 flicker_jumps[cam->mainsFreq] 2687 flicker_jumps[cam->mainsFreq]
2688 [cam->params.sensorFps.baserate] 2688 [cam->params.sensorFps.baserate]
2689 [cam->params.sensorFps.divisor]; 2689 [cam->params.sensorFps.divisor];
2690 cam->cmd_queue |= COMMAND_SETFLICKERCTRL; 2690 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
2691 2691
2692 new_exposure = cam->params.flickerControl.coarseJump-1; 2692 new_exposure = cam->params.flickerControl.coarseJump-1;
@@ -2704,15 +2704,15 @@ static void monitor_exposure(struct cam_data *cam)
2704 cam->params.sensorFps.divisor > 0) { 2704 cam->params.sensorFps.divisor > 0) {
2705 2705
2706 /* light for too long */ 2706 /* light for too long */
2707 int max_exp = FIRMWARE_VERSION(1,2) ? MAX_EXP_102 : MAX_EXP ; 2707 int max_exp = FIRMWARE_VERSION(1,2) ? MAX_EXP_102 : MAX_EXP ;
2708 2708
2709 --cam->params.sensorFps.divisor; 2709 --cam->params.sensorFps.divisor;
2710 cam->cmd_queue |= COMMAND_SETSENSORFPS; 2710 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2711 2711
2712 cam->params.flickerControl.coarseJump = 2712 cam->params.flickerControl.coarseJump =
2713 flicker_jumps[cam->mainsFreq] 2713 flicker_jumps[cam->mainsFreq]
2714 [cam->params.sensorFps.baserate] 2714 [cam->params.sensorFps.baserate]
2715 [cam->params.sensorFps.divisor]; 2715 [cam->params.sensorFps.divisor];
2716 cam->cmd_queue |= COMMAND_SETFLICKERCTRL; 2716 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
2717 2717
2718 new_exposure = cam->params.flickerControl.coarseJump-1; 2718 new_exposure = cam->params.flickerControl.coarseJump-1;
@@ -2772,7 +2772,7 @@ static void monitor_exposure(struct cam_data *cam)
2772 2772
2773 It also adjust the colour balance when an exposure step is detected - as 2773 It also adjust the colour balance when an exposure step is detected - as
2774 long as flicker is running 2774 long as flicker is running
2775*/ 2775*/
2776static void restart_flicker(struct cam_data *cam) 2776static void restart_flicker(struct cam_data *cam)
2777{ 2777{
2778 int cam_exposure, old_exp; 2778 int cam_exposure, old_exp;
@@ -2786,22 +2786,22 @@ static void restart_flicker(struct cam_data *cam)
2786 } 2786 }
2787 cam_exposure = cam->raw_image[39]*2; 2787 cam_exposure = cam->raw_image[39]*2;
2788 old_exp = cam->params.exposure.coarseExpLo + 2788 old_exp = cam->params.exposure.coarseExpLo +
2789 cam->params.exposure.coarseExpHi*256; 2789 cam->params.exposure.coarseExpHi*256;
2790 /* 2790 /*
2791 see how far away camera exposure is from a valid 2791 see how far away camera exposure is from a valid
2792 flicker exposure value 2792 flicker exposure value
2793 */ 2793 */
2794 cam_exposure %= cam->params.flickerControl.coarseJump; 2794 cam_exposure %= cam->params.flickerControl.coarseJump;
2795 if(!cam->params.flickerControl.disabled && 2795 if(!cam->params.flickerControl.disabled &&
2796 cam_exposure <= cam->params.flickerControl.coarseJump - 3) { 2796 cam_exposure <= cam->params.flickerControl.coarseJump - 3) {
2797 /* Flicker control auto-disabled */ 2797 /* Flicker control auto-disabled */
2798 cam->params.flickerControl.disabled = 1; 2798 cam->params.flickerControl.disabled = 1;
2799 } 2799 }
2800 2800
2801 if(cam->params.flickerControl.disabled && 2801 if(cam->params.flickerControl.disabled &&
2802 cam->params.flickerControl.flickerMode && 2802 cam->params.flickerControl.flickerMode &&
2803 old_exp > cam->params.flickerControl.coarseJump + 2803 old_exp > cam->params.flickerControl.coarseJump +
2804 ROUND_UP_EXP_FOR_FLICKER) { 2804 ROUND_UP_EXP_FOR_FLICKER) {
2805 /* exposure is now high enough to switch 2805 /* exposure is now high enough to switch
2806 flicker control back on */ 2806 flicker control back on */
2807 set_flicker(&cam->params, &cam->cmd_queue, 1); 2807 set_flicker(&cam->params, &cam->cmd_queue, 1);
@@ -2818,7 +2818,7 @@ static int clear_stall(struct cam_data *cam)
2818{ 2818{
2819 /* FIXME: Does this actually work? */ 2819 /* FIXME: Does this actually work? */
2820 LOG("Clearing stall\n"); 2820 LOG("Clearing stall\n");
2821 2821
2822 cam->ops->streamRead(cam->lowlevel_data, cam->raw_image, 0); 2822 cam->ops->streamRead(cam->lowlevel_data, cam->raw_image, 0);
2823 do_command(cam, CPIA_COMMAND_GetCameraStatus,0,0,0,0); 2823 do_command(cam, CPIA_COMMAND_GetCameraStatus,0,0,0,0);
2824 return cam->params.status.streamState != STREAM_PAUSED; 2824 return cam->params.status.streamState != STREAM_PAUSED;
@@ -2878,7 +2878,7 @@ static int fetch_frame(void *data)
2878 return -EINTR; 2878 return -EINTR;
2879 2879
2880 do_command(cam, CPIA_COMMAND_GetCameraStatus, 2880 do_command(cam, CPIA_COMMAND_GetCameraStatus,
2881 0, 0, 0, 0); 2881 0, 0, 0, 0);
2882 } 2882 }
2883 if(cam->params.status.streamState != STREAM_READY) { 2883 if(cam->params.status.streamState != STREAM_READY) {
2884 continue; 2884 continue;
@@ -2903,18 +2903,18 @@ static int fetch_frame(void *data)
2903 2903
2904 /* Switch flicker control back on if it got turned off */ 2904 /* Switch flicker control back on if it got turned off */
2905 restart_flicker(cam); 2905 restart_flicker(cam);
2906 2906
2907 /* If AEC is enabled, monitor the exposure and 2907 /* If AEC is enabled, monitor the exposure and
2908 adjust the sensor frame rate if needed */ 2908 adjust the sensor frame rate if needed */
2909 if(cam->params.exposure.expMode == 2) 2909 if(cam->params.exposure.expMode == 2)
2910 monitor_exposure(cam); 2910 monitor_exposure(cam);
2911 2911
2912 /* camera idle now so dispatch queued commands */ 2912 /* camera idle now so dispatch queued commands */
2913 dispatch_commands(cam); 2913 dispatch_commands(cam);
2914 2914
2915 /* Update our knowledge of the camera state */ 2915 /* Update our knowledge of the camera state */
2916 do_command(cam, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0); 2916 do_command(cam, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0);
2917 do_command(cam, CPIA_COMMAND_GetExposure, 0, 0, 0, 0); 2917 do_command(cam, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
2918 do_command(cam, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0); 2918 do_command(cam, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0);
2919 2919
2920 /* decompress and convert image to by copying it from 2920 /* decompress and convert image to by copying it from
@@ -2933,7 +2933,7 @@ static int fetch_frame(void *data)
2933 uncompressed. */ 2933 uncompressed. */
2934 cam->first_frame = 1; 2934 cam->first_frame = 1;
2935 do_command(cam, CPIA_COMMAND_SetGrabMode, 2935 do_command(cam, CPIA_COMMAND_SetGrabMode,
2936 CPIA_GRAB_SINGLE, 0, 0, 0); 2936 CPIA_GRAB_SINGLE, 0, 0, 0);
2937 /* FIXME: Trial & error - need up to 70ms for 2937 /* FIXME: Trial & error - need up to 70ms for
2938 the grab mode change to complete ? */ 2938 the grab mode change to complete ? */
2939 msleep_interruptible(70); 2939 msleep_interruptible(70);
@@ -2957,12 +2957,12 @@ static int fetch_frame(void *data)
2957 if (cam->first_frame) { 2957 if (cam->first_frame) {
2958 cam->first_frame = 0; 2958 cam->first_frame = 0;
2959 do_command(cam, CPIA_COMMAND_SetCompression, 2959 do_command(cam, CPIA_COMMAND_SetCompression,
2960 cam->params.compression.mode, 2960 cam->params.compression.mode,
2961 cam->params.compression.decimation, 0, 0); 2961 cam->params.compression.decimation, 0, 0);
2962 2962
2963 /* Switch from single-grab to continuous grab */ 2963 /* Switch from single-grab to continuous grab */
2964 do_command(cam, CPIA_COMMAND_SetGrabMode, 2964 do_command(cam, CPIA_COMMAND_SetGrabMode,
2965 CPIA_GRAB_CONTINUOUS, 0, 0, 0); 2965 CPIA_GRAB_CONTINUOUS, 0, 0, 0);
2966 } 2966 }
2967 return 0; 2967 return 0;
2968 } 2968 }
@@ -2977,12 +2977,12 @@ static int capture_frame(struct cam_data *cam, struct video_mmap *vm)
2977 if ((err = allocate_frame_buf(cam))) 2977 if ((err = allocate_frame_buf(cam)))
2978 return err; 2978 return err;
2979 } 2979 }
2980 2980
2981 cam->curframe = vm->frame; 2981 cam->curframe = vm->frame;
2982 cam->frame[cam->curframe].state = FRAME_READY; 2982 cam->frame[cam->curframe].state = FRAME_READY;
2983 return fetch_frame(cam); 2983 return fetch_frame(cam);
2984} 2984}
2985 2985
2986static int goto_high_power(struct cam_data *cam) 2986static int goto_high_power(struct cam_data *cam)
2987{ 2987{
2988 if (do_command(cam, CPIA_COMMAND_GotoHiPower, 0, 0, 0, 0)) 2988 if (do_command(cam, CPIA_COMMAND_GotoHiPower, 0, 0, 0, 0))
@@ -3039,22 +3039,22 @@ static void save_camera_state(struct cam_data *cam)
3039static int set_camera_state(struct cam_data *cam) 3039static int set_camera_state(struct cam_data *cam)
3040{ 3040{
3041 cam->cmd_queue = COMMAND_SETCOMPRESSION | 3041 cam->cmd_queue = COMMAND_SETCOMPRESSION |
3042 COMMAND_SETCOMPRESSIONTARGET | 3042 COMMAND_SETCOMPRESSIONTARGET |
3043 COMMAND_SETCOLOURPARAMS | 3043 COMMAND_SETCOLOURPARAMS |
3044 COMMAND_SETFORMAT | 3044 COMMAND_SETFORMAT |
3045 COMMAND_SETYUVTHRESH | 3045 COMMAND_SETYUVTHRESH |
3046 COMMAND_SETECPTIMING | 3046 COMMAND_SETECPTIMING |
3047 COMMAND_SETCOMPRESSIONPARAMS | 3047 COMMAND_SETCOMPRESSIONPARAMS |
3048 COMMAND_SETEXPOSURE | 3048 COMMAND_SETEXPOSURE |
3049 COMMAND_SETCOLOURBALANCE | 3049 COMMAND_SETCOLOURBALANCE |
3050 COMMAND_SETSENSORFPS | 3050 COMMAND_SETSENSORFPS |
3051 COMMAND_SETAPCOR | 3051 COMMAND_SETAPCOR |
3052 COMMAND_SETFLICKERCTRL | 3052 COMMAND_SETFLICKERCTRL |
3053 COMMAND_SETVLOFFSET; 3053 COMMAND_SETVLOFFSET;
3054 3054
3055 do_command(cam, CPIA_COMMAND_SetGrabMode, CPIA_GRAB_SINGLE,0,0,0); 3055 do_command(cam, CPIA_COMMAND_SetGrabMode, CPIA_GRAB_SINGLE,0,0,0);
3056 dispatch_commands(cam); 3056 dispatch_commands(cam);
3057 3057
3058 /* Wait 6 frames for the sensor to get all settings and 3058 /* Wait 6 frames for the sensor to get all settings and
3059 AEC/ACB to settle */ 3059 AEC/ACB to settle */
3060 msleep_interruptible(6*(cam->params.sensorFps.baserate ? 33 : 40) * 3060 msleep_interruptible(6*(cam->params.sensorFps.baserate ? 33 : 40) *
@@ -3062,7 +3062,7 @@ static int set_camera_state(struct cam_data *cam)
3062 3062
3063 if(signal_pending(current)) 3063 if(signal_pending(current))
3064 return -EINTR; 3064 return -EINTR;
3065 3065
3066 save_camera_state(cam); 3066 save_camera_state(cam);
3067 3067
3068 return 0; 3068 return 0;
@@ -3094,9 +3094,9 @@ static int reset_camera(struct cam_data *cam)
3094 if (goto_low_power(cam)) 3094 if (goto_low_power(cam))
3095 return -ENODEV; 3095 return -ENODEV;
3096 } 3096 }
3097 3097
3098 /* procedure described in developer's guide p3-28 */ 3098 /* procedure described in developer's guide p3-28 */
3099 3099
3100 /* Check the firmware version. */ 3100 /* Check the firmware version. */
3101 cam->params.version.firmwareVersion = 0; 3101 cam->params.version.firmwareVersion = 0;
3102 get_version_information(cam); 3102 get_version_information(cam);
@@ -3113,14 +3113,14 @@ static int reset_camera(struct cam_data *cam)
3113 cam->params.qx3.qx3_detected = (cam->params.pnpID.vendor == 0x0813 && 3113 cam->params.qx3.qx3_detected = (cam->params.pnpID.vendor == 0x0813 &&
3114 cam->params.pnpID.product == 0x0001); 3114 cam->params.pnpID.product == 0x0001);
3115 3115
3116 /* The fatal error checking should be done after 3116 /* The fatal error checking should be done after
3117 * the camera powers up (developer's guide p 3-38) */ 3117 * the camera powers up (developer's guide p 3-38) */
3118 3118
3119 /* Set streamState before transition to high power to avoid bug 3119 /* Set streamState before transition to high power to avoid bug
3120 * in firmware 1-02 */ 3120 * in firmware 1-02 */
3121 do_command(cam, CPIA_COMMAND_ModifyCameraStatus, STREAMSTATE, 0, 3121 do_command(cam, CPIA_COMMAND_ModifyCameraStatus, STREAMSTATE, 0,
3122 STREAM_NOT_READY, 0); 3122 STREAM_NOT_READY, 0);
3123 3123
3124 /* GotoHiPower */ 3124 /* GotoHiPower */
3125 err = goto_high_power(cam); 3125 err = goto_high_power(cam);
3126 if (err) 3126 if (err)
@@ -3142,16 +3142,16 @@ static int reset_camera(struct cam_data *cam)
3142 /* Firmware 1-02 may do this for parallel port cameras, 3142 /* Firmware 1-02 may do this for parallel port cameras,
3143 * just clear the flags (developer's guide p 3-38) */ 3143 * just clear the flags (developer's guide p 3-38) */
3144 do_command(cam, CPIA_COMMAND_ModifyCameraStatus, 3144 do_command(cam, CPIA_COMMAND_ModifyCameraStatus,
3145 FATALERROR, ~(COM_FLAG|CPIA_FLAG), 0, 0); 3145 FATALERROR, ~(COM_FLAG|CPIA_FLAG), 0, 0);
3146 } 3146 }
3147 } 3147 }
3148 3148
3149 /* Check the camera status again */ 3149 /* Check the camera status again */
3150 if (cam->params.status.fatalError) { 3150 if (cam->params.status.fatalError) {
3151 if (cam->params.status.fatalError) 3151 if (cam->params.status.fatalError)
3152 return -EIO; 3152 return -EIO;
3153 } 3153 }
3154 3154
3155 /* VPVersion can't be retrieved before the camera is in HiPower, 3155 /* VPVersion can't be retrieved before the camera is in HiPower,
3156 * so get it here instead of in get_version_information. */ 3156 * so get it here instead of in get_version_information. */
3157 do_command(cam, CPIA_COMMAND_GetVPVersion, 0, 0, 0, 0); 3157 do_command(cam, CPIA_COMMAND_GetVPVersion, 0, 0, 0, 0);
@@ -3193,24 +3193,24 @@ static int cpia_open(struct inode *inode, struct file *file)
3193 if (!cam->raw_image) 3193 if (!cam->raw_image)
3194 goto oops; 3194 goto oops;
3195 } 3195 }
3196 3196
3197 if (!cam->decompressed_frame.data) { 3197 if (!cam->decompressed_frame.data) {
3198 cam->decompressed_frame.data = rvmalloc(CPIA_MAX_FRAME_SIZE); 3198 cam->decompressed_frame.data = rvmalloc(CPIA_MAX_FRAME_SIZE);
3199 if (!cam->decompressed_frame.data) 3199 if (!cam->decompressed_frame.data)
3200 goto oops; 3200 goto oops;
3201 } 3201 }
3202 3202
3203 /* open cpia */ 3203 /* open cpia */
3204 err = -ENODEV; 3204 err = -ENODEV;
3205 if (cam->ops->open(cam->lowlevel_data)) 3205 if (cam->ops->open(cam->lowlevel_data))
3206 goto oops; 3206 goto oops;
3207 3207
3208 /* reset the camera */ 3208 /* reset the camera */
3209 if ((err = reset_camera(cam)) != 0) { 3209 if ((err = reset_camera(cam)) != 0) {
3210 cam->ops->close(cam->lowlevel_data); 3210 cam->ops->close(cam->lowlevel_data);
3211 goto oops; 3211 goto oops;
3212 } 3212 }
3213 3213
3214 err = -EINTR; 3214 err = -EINTR;
3215 if(signal_pending(current)) 3215 if(signal_pending(current))
3216 goto oops; 3216 goto oops;
@@ -3224,7 +3224,7 @@ static int cpia_open(struct inode *inode, struct file *file)
3224 3224
3225 /* init it to something */ 3225 /* init it to something */
3226 cam->mmap_kludge = 0; 3226 cam->mmap_kludge = 0;
3227 3227
3228 ++cam->open_count; 3228 ++cam->open_count;
3229 file->private_data = dev; 3229 file->private_data = dev;
3230 mutex_unlock(&cam->busy_lock); 3230 mutex_unlock(&cam->busy_lock);
@@ -3250,10 +3250,10 @@ static int cpia_close(struct inode *inode, struct file *file)
3250 struct cam_data *cam = dev->priv; 3250 struct cam_data *cam = dev->priv;
3251 3251
3252 if (cam->ops) { 3252 if (cam->ops) {
3253 /* Return ownership of /proc/cpia/videoX to root */ 3253 /* Return ownership of /proc/cpia/videoX to root */
3254 if(cam->proc_entry) 3254 if(cam->proc_entry)
3255 cam->proc_entry->uid = 0; 3255 cam->proc_entry->uid = 0;
3256 3256
3257 /* save camera state for later open (developers guide ch 3.5.3) */ 3257 /* save camera state for later open (developers guide ch 3.5.3) */
3258 save_camera_state(cam); 3258 save_camera_state(cam);
3259 3259
@@ -3342,7 +3342,7 @@ static ssize_t cpia_read(struct file *file, char __user *buf,
3342 return -EFAULT; 3342 return -EFAULT;
3343 } 3343 }
3344 if (copy_to_user(buf, cam->decompressed_frame.data, 3344 if (copy_to_user(buf, cam->decompressed_frame.data,
3345 cam->decompressed_frame.count)) { 3345 cam->decompressed_frame.count)) {
3346 DBG("copy_to_user failed\n"); 3346 DBG("copy_to_user failed\n");
3347 mutex_unlock(&cam->busy_lock); 3347 mutex_unlock(&cam->busy_lock);
3348 return -EFAULT; 3348 return -EFAULT;
@@ -3361,7 +3361,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3361 3361
3362 if (!cam || !cam->ops) 3362 if (!cam || !cam->ops)
3363 return -ENODEV; 3363 return -ENODEV;
3364 3364
3365 /* make this _really_ smp-safe */ 3365 /* make this _really_ smp-safe */
3366 if (mutex_lock_interruptible(&cam->busy_lock)) 3366 if (mutex_lock_interruptible(&cam->busy_lock))
3367 return -EINTR; 3367 return -EINTR;
@@ -3405,7 +3405,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3405 v->norm = 0; 3405 v->norm = 0;
3406 break; 3406 break;
3407 } 3407 }
3408 3408
3409 case VIDIOCSCHAN: 3409 case VIDIOCSCHAN:
3410 { 3410 {
3411 struct video_channel *v = arg; 3411 struct video_channel *v = arg;
@@ -3424,7 +3424,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3424 *pic = cam->vp; 3424 *pic = cam->vp;
3425 break; 3425 break;
3426 } 3426 }
3427 3427
3428 case VIDIOCSPICT: 3428 case VIDIOCSPICT:
3429 { 3429 {
3430 struct video_picture *vp = arg; 3430 struct video_picture *vp = arg;
@@ -3458,11 +3458,11 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3458 3458
3459 /* Adjust flicker control if necessary */ 3459 /* Adjust flicker control if necessary */
3460 if(cam->params.flickerControl.allowableOverExposure < 0) 3460 if(cam->params.flickerControl.allowableOverExposure < 0)
3461 cam->params.flickerControl.allowableOverExposure = 3461 cam->params.flickerControl.allowableOverExposure =
3462 -find_over_exposure(cam->params.colourParams.brightness); 3462 -find_over_exposure(cam->params.colourParams.brightness);
3463 if(cam->params.flickerControl.flickerMode != 0) 3463 if(cam->params.flickerControl.flickerMode != 0)
3464 cam->cmd_queue |= COMMAND_SETFLICKERCTRL; 3464 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
3465 3465
3466 3466
3467 /* queue command to update camera */ 3467 /* queue command to update camera */
3468 cam->cmd_queue |= COMMAND_SETCOLOURPARAMS; 3468 cam->cmd_queue |= COMMAND_SETCOLOURPARAMS;
@@ -3482,7 +3482,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3482 *vw = cam->vw; 3482 *vw = cam->vw;
3483 break; 3483 break;
3484 } 3484 }
3485 3485
3486 case VIDIOCSWIN: 3486 case VIDIOCSWIN:
3487 { 3487 {
3488 /* copy_from_user, check validity, copy to internal structure */ 3488 /* copy_from_user, check validity, copy to internal structure */
@@ -3514,7 +3514,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3514 3514
3515 /* video size is changing, reset the subcapture area */ 3515 /* video size is changing, reset the subcapture area */
3516 memset(&cam->vc, 0, sizeof(cam->vc)); 3516 memset(&cam->vc, 0, sizeof(cam->vc));
3517 3517
3518 set_vw_size(cam); 3518 set_vw_size(cam);
3519 DBG("%d / %d\n", cam->vw.width, cam->vw.height); 3519 DBG("%d / %d\n", cam->vw.width, cam->vw.height);
3520 cam->cmd_queue |= COMMAND_SETFORMAT; 3520 cam->cmd_queue |= COMMAND_SETFORMAT;
@@ -3547,7 +3547,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3547 vm->offsets[i] = CPIA_MAX_FRAME_SIZE * i; 3547 vm->offsets[i] = CPIA_MAX_FRAME_SIZE * i;
3548 break; 3548 break;
3549 } 3549 }
3550 3550
3551 case VIDIOCMCAPTURE: 3551 case VIDIOCMCAPTURE:
3552 { 3552 {
3553 struct video_mmap *vm = arg; 3553 struct video_mmap *vm = arg;
@@ -3597,7 +3597,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3597 3597
3598 /* video size is changing, reset the subcapture area */ 3598 /* video size is changing, reset the subcapture area */
3599 memset(&cam->vc, 0, sizeof(cam->vc)); 3599 memset(&cam->vc, 0, sizeof(cam->vc));
3600 3600
3601 set_vw_size(cam); 3601 set_vw_size(cam);
3602 cam->cmd_queue |= COMMAND_SETFORMAT; 3602 cam->cmd_queue |= COMMAND_SETFORMAT;
3603 dispatch_commands(cam); 3603 dispatch_commands(cam);
@@ -3608,7 +3608,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3608 3608
3609 break; 3609 break;
3610 } 3610 }
3611 3611
3612 case VIDIOCSYNC: 3612 case VIDIOCSYNC:
3613 { 3613 {
3614 int *frame = arg; 3614 int *frame = arg;
@@ -3649,7 +3649,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3649 *vc = cam->vc; 3649 *vc = cam->vc;
3650 3650
3651 break; 3651 break;
3652 } 3652 }
3653 3653
3654 case VIDIOCSCAPTURE: 3654 case VIDIOCSCAPTURE:
3655 { 3655 {
@@ -3665,7 +3665,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3665 retval = -EINVAL; 3665 retval = -EINVAL;
3666 break; 3666 break;
3667 } 3667 }
3668 3668
3669 /* Clip to the resolution we can set for the ROI 3669 /* Clip to the resolution we can set for the ROI
3670 (every 8 columns and 4 rows) */ 3670 (every 8 columns and 4 rows) */
3671 vc->x = vc->x & ~(__u32)7; 3671 vc->x = vc->x & ~(__u32)7;
@@ -3681,14 +3681,14 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3681 } 3681 }
3682 3682
3683 DBG("%d,%d/%dx%d\n", vc->x,vc->y,vc->width, vc->height); 3683 DBG("%d,%d/%dx%d\n", vc->x,vc->y,vc->width, vc->height);
3684 3684
3685 mutex_lock(&cam->param_lock); 3685 mutex_lock(&cam->param_lock);
3686 3686
3687 cam->vc.x = vc->x; 3687 cam->vc.x = vc->x;
3688 cam->vc.y = vc->y; 3688 cam->vc.y = vc->y;
3689 cam->vc.width = vc->width; 3689 cam->vc.width = vc->width;
3690 cam->vc.height = vc->height; 3690 cam->vc.height = vc->height;
3691 3691
3692 set_vw_size(cam); 3692 set_vw_size(cam);
3693 cam->cmd_queue |= COMMAND_SETFORMAT; 3693 cam->cmd_queue |= COMMAND_SETFORMAT;
3694 3694
@@ -3699,7 +3699,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3699 dispatch_commands(cam); 3699 dispatch_commands(cam);
3700 break; 3700 break;
3701 } 3701 }
3702 3702
3703 case VIDIOCGUNIT: 3703 case VIDIOCGUNIT:
3704 { 3704 {
3705 struct video_unit *vu = arg; 3705 struct video_unit *vu = arg;
@@ -3715,7 +3715,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3715 break; 3715 break;
3716 } 3716 }
3717 3717
3718 3718
3719 /* pointless to implement overlay with this camera */ 3719 /* pointless to implement overlay with this camera */
3720 case VIDIOCCAPTURE: 3720 case VIDIOCCAPTURE:
3721 case VIDIOCGFBUF: 3721 case VIDIOCGFBUF:
@@ -3738,7 +3738,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3738 3738
3739 mutex_unlock(&cam->busy_lock); 3739 mutex_unlock(&cam->busy_lock);
3740 return retval; 3740 return retval;
3741} 3741}
3742 3742
3743static int cpia_ioctl(struct inode *inode, struct file *file, 3743static int cpia_ioctl(struct inode *inode, struct file *file,
3744 unsigned int cmd, unsigned long arg) 3744 unsigned int cmd, unsigned long arg)
@@ -3759,7 +3759,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3759 3759
3760 if (!cam || !cam->ops) 3760 if (!cam || !cam->ops)
3761 return -ENODEV; 3761 return -ENODEV;
3762 3762
3763 DBG("cpia_mmap: %ld\n", size); 3763 DBG("cpia_mmap: %ld\n", size);
3764 3764
3765 if (size > FRAME_NUM*CPIA_MAX_FRAME_SIZE) 3765 if (size > FRAME_NUM*CPIA_MAX_FRAME_SIZE)
@@ -3767,7 +3767,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3767 3767
3768 if (!cam || !cam->ops) 3768 if (!cam || !cam->ops)
3769 return -ENODEV; 3769 return -ENODEV;
3770 3770
3771 /* make this _really_ smp-safe */ 3771 /* make this _really_ smp-safe */
3772 if (mutex_lock_interruptible(&cam->busy_lock)) 3772 if (mutex_lock_interruptible(&cam->busy_lock))
3773 return -EINTR; 3773 return -EINTR;
@@ -3851,11 +3851,11 @@ static void reset_camera_struct(struct cam_data *cam)
3851 cam->params.flickerControl.flickerMode = 0; 3851 cam->params.flickerControl.flickerMode = 0;
3852 cam->params.flickerControl.disabled = 1; 3852 cam->params.flickerControl.disabled = 1;
3853 3853
3854 cam->params.flickerControl.coarseJump = 3854 cam->params.flickerControl.coarseJump =
3855 flicker_jumps[cam->mainsFreq] 3855 flicker_jumps[cam->mainsFreq]
3856 [cam->params.sensorFps.baserate] 3856 [cam->params.sensorFps.baserate]
3857 [cam->params.sensorFps.divisor]; 3857 [cam->params.sensorFps.divisor];
3858 cam->params.flickerControl.allowableOverExposure = 3858 cam->params.flickerControl.allowableOverExposure =
3859 -find_over_exposure(cam->params.colourParams.brightness); 3859 -find_over_exposure(cam->params.colourParams.brightness);
3860 cam->params.vlOffset.gain1 = 20; 3860 cam->params.vlOffset.gain1 = 20;
3861 cam->params.vlOffset.gain2 = 24; 3861 cam->params.vlOffset.gain2 = 24;
@@ -3870,21 +3870,21 @@ static void reset_camera_struct(struct cam_data *cam)
3870 cam->params.compressionParams.qDiffStepThresh = 3; 3870 cam->params.compressionParams.qDiffStepThresh = 3;
3871 cam->params.compressionParams.decimationThreshMod = 2; 3871 cam->params.compressionParams.decimationThreshMod = 2;
3872 /* End of default values from Software Developer's Guide */ 3872 /* End of default values from Software Developer's Guide */
3873 3873
3874 cam->transfer_rate = 0; 3874 cam->transfer_rate = 0;
3875 cam->exposure_status = EXPOSURE_NORMAL; 3875 cam->exposure_status = EXPOSURE_NORMAL;
3876 3876
3877 /* Set Sensor FPS to 15fps. This seems better than 30fps 3877 /* Set Sensor FPS to 15fps. This seems better than 30fps
3878 * for indoor lighting. */ 3878 * for indoor lighting. */
3879 cam->params.sensorFps.divisor = 1; 3879 cam->params.sensorFps.divisor = 1;
3880 cam->params.sensorFps.baserate = 1; 3880 cam->params.sensorFps.baserate = 1;
3881 3881
3882 cam->params.yuvThreshold.yThreshold = 6; /* From windows driver */ 3882 cam->params.yuvThreshold.yThreshold = 6; /* From windows driver */
3883 cam->params.yuvThreshold.uvThreshold = 6; /* From windows driver */ 3883 cam->params.yuvThreshold.uvThreshold = 6; /* From windows driver */
3884 3884
3885 cam->params.format.subSample = SUBSAMPLE_422; 3885 cam->params.format.subSample = SUBSAMPLE_422;
3886 cam->params.format.yuvOrder = YUVORDER_YUYV; 3886 cam->params.format.yuvOrder = YUVORDER_YUYV;
3887 3887
3888 cam->params.compression.mode = CPIA_COMPRESSION_AUTO; 3888 cam->params.compression.mode = CPIA_COMPRESSION_AUTO;
3889 cam->params.compressionTarget.frTargeting = 3889 cam->params.compressionTarget.frTargeting =
3890 CPIA_COMPRESSION_TARGET_QUALITY; 3890 CPIA_COMPRESSION_TARGET_QUALITY;
@@ -3898,7 +3898,7 @@ static void reset_camera_struct(struct cam_data *cam)
3898 cam->params.qx3.cradled = 0; 3898 cam->params.qx3.cradled = 0;
3899 3899
3900 cam->video_size = VIDEOSIZE_CIF; 3900 cam->video_size = VIDEOSIZE_CIF;
3901 3901
3902 cam->vp.colour = 32768; /* 50% */ 3902 cam->vp.colour = 32768; /* 50% */
3903 cam->vp.hue = 32768; /* 50% */ 3903 cam->vp.hue = 32768; /* 50% */
3904 cam->vp.brightness = 32768; /* 50% */ 3904 cam->vp.brightness = 32768; /* 50% */
@@ -3911,7 +3911,7 @@ static void reset_camera_struct(struct cam_data *cam)
3911 cam->vc.y = 0; 3911 cam->vc.y = 0;
3912 cam->vc.width = 0; 3912 cam->vc.width = 0;
3913 cam->vc.height = 0; 3913 cam->vc.height = 0;
3914 3914
3915 cam->vw.x = 0; 3915 cam->vw.x = 0;
3916 cam->vw.y = 0; 3916 cam->vw.y = 0;
3917 set_vw_size(cam); 3917 set_vw_size(cam);
@@ -3928,7 +3928,7 @@ static void reset_camera_struct(struct cam_data *cam)
3928 3928
3929/* initialize cam_data structure */ 3929/* initialize cam_data structure */
3930static void init_camera_struct(struct cam_data *cam, 3930static void init_camera_struct(struct cam_data *cam,
3931 struct cpia_camera_ops *ops ) 3931 struct cpia_camera_ops *ops )
3932{ 3932{
3933 int i; 3933 int i;
3934 3934
@@ -3945,7 +3945,7 @@ static void init_camera_struct(struct cam_data *cam,
3945 3945
3946 memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template)); 3946 memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template));
3947 cam->vdev.priv = cam; 3947 cam->vdev.priv = cam;
3948 3948
3949 cam->curframe = 0; 3949 cam->curframe = 0;
3950 for (i = 0; i < FRAME_NUM; i++) { 3950 for (i = 0; i < FRAME_NUM; i++) {
3951 cam->frame[i].width = 0; 3951 cam->frame[i].width = 0;
@@ -3961,15 +3961,15 @@ static void init_camera_struct(struct cam_data *cam,
3961 3961
3962struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel) 3962struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel)
3963{ 3963{
3964 struct cam_data *camera; 3964 struct cam_data *camera;
3965 3965
3966 if ((camera = kmalloc(sizeof(struct cam_data), GFP_KERNEL)) == NULL) 3966 if ((camera = kmalloc(sizeof(struct cam_data), GFP_KERNEL)) == NULL)
3967 return NULL; 3967 return NULL;
3968 3968
3969 3969
3970 init_camera_struct( camera, ops ); 3970 init_camera_struct( camera, ops );
3971 camera->lowlevel_data = lowlevel; 3971 camera->lowlevel_data = lowlevel;
3972 3972
3973 /* register v4l device */ 3973 /* register v4l device */
3974 if (video_register_device(&camera->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 3974 if (video_register_device(&camera->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
3975 kfree(camera); 3975 kfree(camera);
@@ -3982,7 +3982,7 @@ struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowleve
3982 /* open cpia */ 3982 /* open cpia */
3983 if (camera->ops->open(camera->lowlevel_data)) 3983 if (camera->ops->open(camera->lowlevel_data))
3984 return camera; 3984 return camera;
3985 3985
3986 /* reset the camera */ 3986 /* reset the camera */
3987 if (reset_camera(camera) != 0) { 3987 if (reset_camera(camera) != 0) {
3988 camera->ops->close(camera->lowlevel_data); 3988 camera->ops->close(camera->lowlevel_data);
@@ -4022,11 +4022,11 @@ void cpia_unregister_camera(struct cam_data *cam)
4022 DBG("camera open -- setting ops to NULL\n"); 4022 DBG("camera open -- setting ops to NULL\n");
4023 cam->ops = NULL; 4023 cam->ops = NULL;
4024 } 4024 }
4025 4025
4026#ifdef CONFIG_PROC_FS 4026#ifdef CONFIG_PROC_FS
4027 DBG("destroying /proc/cpia/video%d\n", cam->vdev.minor); 4027 DBG("destroying /proc/cpia/video%d\n", cam->vdev.minor);
4028 destroy_proc_cpia_cam(cam); 4028 destroy_proc_cpia_cam(cam);
4029#endif 4029#endif
4030 if (!cam->open_count) { 4030 if (!cam->open_count) {
4031 DBG("freeing camera\n"); 4031 DBG("freeing camera\n");
4032 kfree(cam); 4032 kfree(cam);