Merge ../ntfs-2.6-devel
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / usb / media / pwc / pwc-ctrl.c
1 /* Driver for Philips webcam
2 Functions that send various control messages to the webcam, including
3 video modes.
4 (C) 1999-2003 Nemosoft Unv.
5 (C) 2004 Luc Saillard (luc@saillard.org)
6
7 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
8 driver and thus may have bugs that are not present in the original version.
9 Please send bug reports and support requests to <luc@saillard.org>.
10
11 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
12 driver and thus may have bugs that are not present in the original version.
13 Please send bug reports and support requests to <luc@saillard.org>.
14 The decompression routines have been implemented by reverse-engineering the
15 Nemosoft binary pwcx module. Caveat emptor.
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31
32 /*
33 Changes
34 2001/08/03 Alvarado Added methods for changing white balance and
35 red/green gains
36 */
37
38 /* Control functions for the cam; brightness, contrast, video mode, etc. */
39
40 #ifdef __KERNEL__
41 #include <asm/uaccess.h>
42 #endif
43 #include <asm/errno.h>
44 #include <linux/version.h>
45
46 #include "pwc.h"
47 #include "pwc-ioctl.h"
48 #include "pwc-uncompress.h"
49 #include "pwc-kiara.h"
50 #include "pwc-timon.h"
51
52 /* Request types: video */
53 #define SET_LUM_CTL 0x01
54 #define GET_LUM_CTL 0x02
55 #define SET_CHROM_CTL 0x03
56 #define GET_CHROM_CTL 0x04
57 #define SET_STATUS_CTL 0x05
58 #define GET_STATUS_CTL 0x06
59 #define SET_EP_STREAM_CTL 0x07
60 #define GET_EP_STREAM_CTL 0x08
61 #define SET_MPT_CTL 0x0D
62 #define GET_MPT_CTL 0x0E
63
64 /* Selectors for the Luminance controls [GS]ET_LUM_CTL */
65 #define AGC_MODE_FORMATTER 0x2000
66 #define PRESET_AGC_FORMATTER 0x2100
67 #define SHUTTER_MODE_FORMATTER 0x2200
68 #define PRESET_SHUTTER_FORMATTER 0x2300
69 #define PRESET_CONTOUR_FORMATTER 0x2400
70 #define AUTO_CONTOUR_FORMATTER 0x2500
71 #define BACK_LIGHT_COMPENSATION_FORMATTER 0x2600
72 #define CONTRAST_FORMATTER 0x2700
73 #define DYNAMIC_NOISE_CONTROL_FORMATTER 0x2800
74 #define FLICKERLESS_MODE_FORMATTER 0x2900
75 #define AE_CONTROL_SPEED 0x2A00
76 #define BRIGHTNESS_FORMATTER 0x2B00
77 #define GAMMA_FORMATTER 0x2C00
78
79 /* Selectors for the Chrominance controls [GS]ET_CHROM_CTL */
80 #define WB_MODE_FORMATTER 0x1000
81 #define AWB_CONTROL_SPEED_FORMATTER 0x1100
82 #define AWB_CONTROL_DELAY_FORMATTER 0x1200
83 #define PRESET_MANUAL_RED_GAIN_FORMATTER 0x1300
84 #define PRESET_MANUAL_BLUE_GAIN_FORMATTER 0x1400
85 #define COLOUR_MODE_FORMATTER 0x1500
86 #define SATURATION_MODE_FORMATTER1 0x1600
87 #define SATURATION_MODE_FORMATTER2 0x1700
88
89 /* Selectors for the Status controls [GS]ET_STATUS_CTL */
90 #define SAVE_USER_DEFAULTS_FORMATTER 0x0200
91 #define RESTORE_USER_DEFAULTS_FORMATTER 0x0300
92 #define RESTORE_FACTORY_DEFAULTS_FORMATTER 0x0400
93 #define READ_AGC_FORMATTER 0x0500
94 #define READ_SHUTTER_FORMATTER 0x0600
95 #define READ_RED_GAIN_FORMATTER 0x0700
96 #define READ_BLUE_GAIN_FORMATTER 0x0800
97 #define SENSOR_TYPE_FORMATTER1 0x0C00
98 #define READ_RAW_Y_MEAN_FORMATTER 0x3100
99 #define SET_POWER_SAVE_MODE_FORMATTER 0x3200
100 #define MIRROR_IMAGE_FORMATTER 0x3300
101 #define LED_FORMATTER 0x3400
102 #define SENSOR_TYPE_FORMATTER2 0x3700
103
104 /* Formatters for the Video Endpoint controls [GS]ET_EP_STREAM_CTL */
105 #define VIDEO_OUTPUT_CONTROL_FORMATTER 0x0100
106
107 /* Formatters for the motorized pan & tilt [GS]ET_MPT_CTL */
108 #define PT_RELATIVE_CONTROL_FORMATTER 0x01
109 #define PT_RESET_CONTROL_FORMATTER 0x02
110 #define PT_STATUS_FORMATTER 0x03
111
112 static const char *size2name[PSZ_MAX] =
113 {
114 "subQCIF",
115 "QSIF",
116 "QCIF",
117 "SIF",
118 "CIF",
119 "VGA",
120 };
121
122 /********/
123
124 /* Entries for the Nala (645/646) camera; the Nala doesn't have compression
125 preferences, so you either get compressed or non-compressed streams.
126
127 An alternate value of 0 means this mode is not available at all.
128 */
129
130 struct Nala_table_entry {
131 char alternate; /* USB alternate setting */
132 int compressed; /* Compressed yes/no */
133
134 unsigned char mode[3]; /* precomputed mode table */
135 };
136
137 static struct Nala_table_entry Nala_table[PSZ_MAX][8] =
138 {
139 #include "pwc-nala.h"
140 };
141
142
143 /****************************************************************************/
144
145
146 #define SendControlMsg(request, value, buflen) \
147 usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0), \
148 request, \
149 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \
150 value, \
151 pdev->vcinterface, \
152 &buf, buflen, 500)
153
154 #define RecvControlMsg(request, value, buflen) \
155 usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0), \
156 request, \
157 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \
158 value, \
159 pdev->vcinterface, \
160 &buf, buflen, 500)
161
162
163 #if PWC_DEBUG
164 void pwc_hexdump(void *p, int len)
165 {
166 int i;
167 unsigned char *s;
168 char buf[100], *d;
169
170 s = (unsigned char *)p;
171 d = buf;
172 *d = '\0';
173 Debug("Doing hexdump @ %p, %d bytes.\n", p, len);
174 for (i = 0; i < len; i++) {
175 d += sprintf(d, "%02X ", *s++);
176 if ((i & 0xF) == 0xF) {
177 Debug("%s\n", buf);
178 d = buf;
179 *d = '\0';
180 }
181 }
182 if ((i & 0xF) != 0)
183 Debug("%s\n", buf);
184 }
185 #endif
186
187 static inline int send_video_command(struct usb_device *udev, int index, void *buf, int buflen)
188 {
189 return usb_control_msg(udev,
190 usb_sndctrlpipe(udev, 0),
191 SET_EP_STREAM_CTL,
192 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
193 VIDEO_OUTPUT_CONTROL_FORMATTER,
194 index,
195 buf, buflen, 1000);
196 }
197
198
199
200 static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames)
201 {
202 unsigned char buf[3];
203 int ret, fps;
204 struct Nala_table_entry *pEntry;
205 int frames2frames[31] =
206 { /* closest match of framerate */
207 0, 0, 0, 0, 4, /* 0-4 */
208 5, 5, 7, 7, 10, /* 5-9 */
209 10, 10, 12, 12, 15, /* 10-14 */
210 15, 15, 15, 20, 20, /* 15-19 */
211 20, 20, 20, 24, 24, /* 20-24 */
212 24, 24, 24, 24, 24, /* 25-29 */
213 24 /* 30 */
214 };
215 int frames2table[31] =
216 { 0, 0, 0, 0, 0, /* 0-4 */
217 1, 1, 1, 2, 2, /* 5-9 */
218 3, 3, 4, 4, 4, /* 10-14 */
219 5, 5, 5, 5, 5, /* 15-19 */
220 6, 6, 6, 6, 7, /* 20-24 */
221 7, 7, 7, 7, 7, /* 25-29 */
222 7 /* 30 */
223 };
224
225 if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25)
226 return -EINVAL;
227 frames = frames2frames[frames];
228 fps = frames2table[frames];
229 pEntry = &Nala_table[size][fps];
230 if (pEntry->alternate == 0)
231 return -EINVAL;
232
233 if (pEntry->compressed)
234 return -ENOENT; /* Not supported. */
235
236 memcpy(buf, pEntry->mode, 3);
237 ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 3);
238 if (ret < 0) {
239 Debug("Failed to send video command... %d\n", ret);
240 return ret;
241 }
242 if (pEntry->compressed && pdev->vpalette != VIDEO_PALETTE_RAW)
243 {
244 switch(pdev->type) {
245 case 645:
246 case 646:
247 /* pwc_dec1_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
248 break;
249
250 case 675:
251 case 680:
252 case 690:
253 case 720:
254 case 730:
255 case 740:
256 case 750:
257 /* pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
258 break;
259 }
260 }
261
262 pdev->cmd_len = 3;
263 memcpy(pdev->cmd_buf, buf, 3);
264
265 /* Set various parameters */
266 pdev->vframes = frames;
267 pdev->vsize = size;
268 pdev->valternate = pEntry->alternate;
269 pdev->image = pwc_image_sizes[size];
270 pdev->frame_size = (pdev->image.x * pdev->image.y * 3) / 2;
271 if (pEntry->compressed) {
272 if (pdev->release < 5) { /* 4 fold compression */
273 pdev->vbandlength = 528;
274 pdev->frame_size /= 4;
275 }
276 else {
277 pdev->vbandlength = 704;
278 pdev->frame_size /= 3;
279 }
280 }
281 else
282 pdev->vbandlength = 0;
283 return 0;
284 }
285
286
287 static inline int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames, int compression, int snapshot)
288 {
289 unsigned char buf[13];
290 const struct Timon_table_entry *pChoose;
291 int ret, fps;
292
293 if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3)
294 return -EINVAL;
295 if (size == PSZ_VGA && frames > 15)
296 return -EINVAL;
297 fps = (frames / 5) - 1;
298
299 /* Find a supported framerate with progressively higher compression ratios
300 if the preferred ratio is not available.
301 */
302 pChoose = NULL;
303 while (compression <= 3) {
304 pChoose = &Timon_table[size][fps][compression];
305 if (pChoose->alternate != 0)
306 break;
307 compression++;
308 }
309 if (pChoose == NULL || pChoose->alternate == 0)
310 return -ENOENT; /* Not supported. */
311
312 memcpy(buf, pChoose->mode, 13);
313 if (snapshot)
314 buf[0] |= 0x80;
315 ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 13);
316 if (ret < 0)
317 return ret;
318
319 /* if (pChoose->bandlength > 0 && pdev->vpalette != VIDEO_PALETTE_RAW)
320 pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
321
322 pdev->cmd_len = 13;
323 memcpy(pdev->cmd_buf, buf, 13);
324
325 /* Set various parameters */
326 pdev->vframes = frames;
327 pdev->vsize = size;
328 pdev->vsnapshot = snapshot;
329 pdev->valternate = pChoose->alternate;
330 pdev->image = pwc_image_sizes[size];
331 pdev->vbandlength = pChoose->bandlength;
332 if (pChoose->bandlength > 0)
333 pdev->frame_size = (pChoose->bandlength * pdev->image.y) / 4;
334 else
335 pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8;
336 return 0;
337 }
338
339
340 static inline int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames, int compression, int snapshot)
341 {
342 const struct Kiara_table_entry *pChoose = NULL;
343 int fps, ret;
344 unsigned char buf[12];
345 struct Kiara_table_entry RawEntry = {6, 773, 1272, {0xAD, 0xF4, 0x10, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}};
346
347 if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3)
348 return -EINVAL;
349 if (size == PSZ_VGA && frames > 15)
350 return -EINVAL;
351 fps = (frames / 5) - 1;
352
353 /* special case: VGA @ 5 fps and snapshot is raw bayer mode */
354 if (size == PSZ_VGA && frames == 5 && snapshot)
355 {
356 /* Only available in case the raw palette is selected or
357 we have the decompressor available. This mode is
358 only available in compressed form
359 */
360 if (pdev->vpalette == VIDEO_PALETTE_RAW)
361 {
362 Info("Choosing VGA/5 BAYER mode (%d).\n", pdev->vpalette);
363 pChoose = &RawEntry;
364 }
365 else
366 {
367 Info("VGA/5 BAYER mode _must_ have a decompressor available, or use RAW palette.\n");
368 }
369 }
370 else
371 {
372 /* Find a supported framerate with progressively higher compression ratios
373 if the preferred ratio is not available.
374 Skip this step when using RAW modes.
375 */
376 while (compression <= 3) {
377 pChoose = &Kiara_table[size][fps][compression];
378 if (pChoose->alternate != 0)
379 break;
380 compression++;
381 }
382 }
383 if (pChoose == NULL || pChoose->alternate == 0)
384 return -ENOENT; /* Not supported. */
385
386 Debug("Using alternate setting %d.\n", pChoose->alternate);
387
388 /* usb_control_msg won't take staticly allocated arrays as argument?? */
389 memcpy(buf, pChoose->mode, 12);
390 if (snapshot)
391 buf[0] |= 0x80;
392
393 /* Firmware bug: video endpoint is 5, but commands are sent to endpoint 4 */
394 ret = send_video_command(pdev->udev, 4 /* pdev->vendpoint */, buf, 12);
395 if (ret < 0)
396 return ret;
397
398 /* if (pChoose->bandlength > 0 && pdev->vpalette != VIDEO_PALETTE_RAW)
399 pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
400
401 pdev->cmd_len = 12;
402 memcpy(pdev->cmd_buf, buf, 12);
403 /* All set and go */
404 pdev->vframes = frames;
405 pdev->vsize = size;
406 pdev->vsnapshot = snapshot;
407 pdev->valternate = pChoose->alternate;
408 pdev->image = pwc_image_sizes[size];
409 pdev->vbandlength = pChoose->bandlength;
410 if (pdev->vbandlength > 0)
411 pdev->frame_size = (pdev->vbandlength * pdev->image.y) / 4;
412 else
413 pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8;
414 return 0;
415 }
416
417
418
419 static void pwc_set_image_buffer_size(struct pwc_device *pdev)
420 {
421 int i, factor = 0, filler = 0;
422
423 /* for PALETTE_YUV420P */
424 switch(pdev->vpalette)
425 {
426 case VIDEO_PALETTE_YUV420P:
427 factor = 6;
428 filler = 128;
429 break;
430 case VIDEO_PALETTE_RAW:
431 factor = 6; /* can be uncompressed YUV420P */
432 filler = 0;
433 break;
434 }
435
436 /* Set sizes in bytes */
437 pdev->image.size = pdev->image.x * pdev->image.y * factor / 4;
438 pdev->view.size = pdev->view.x * pdev->view.y * factor / 4;
439
440 /* Align offset, or you'll get some very weird results in
441 YUV420 mode... x must be multiple of 4 (to get the Y's in
442 place), and y even (or you'll mixup U & V). This is less of a
443 problem for YUV420P.
444 */
445 pdev->offset.x = ((pdev->view.x - pdev->image.x) / 2) & 0xFFFC;
446 pdev->offset.y = ((pdev->view.y - pdev->image.y) / 2) & 0xFFFE;
447
448 /* Fill buffers with gray or black */
449 for (i = 0; i < MAX_IMAGES; i++) {
450 if (pdev->image_ptr[i] != NULL)
451 memset(pdev->image_ptr[i], filler, pdev->view.size);
452 }
453 }
454
455
456
457 /**
458 @pdev: device structure
459 @width: viewport width
460 @height: viewport height
461 @frame: framerate, in fps
462 @compression: preferred compression ratio
463 @snapshot: snapshot mode or streaming
464 */
465 int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot)
466 {
467 int ret, size;
468
469 Trace(TRACE_FLOW, "set_video_mode(%dx%d @ %d, palette %d).\n", width, height, frames, pdev->vpalette);
470 size = pwc_decode_size(pdev, width, height);
471 if (size < 0) {
472 Debug("Could not find suitable size.\n");
473 return -ERANGE;
474 }
475 Debug("decode_size = %d.\n", size);
476
477 ret = -EINVAL;
478 switch(pdev->type) {
479 case 645:
480 case 646:
481 ret = set_video_mode_Nala(pdev, size, frames);
482 break;
483
484 case 675:
485 case 680:
486 case 690:
487 ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot);
488 break;
489
490 case 720:
491 case 730:
492 case 740:
493 case 750:
494 ret = set_video_mode_Kiara(pdev, size, frames, compression, snapshot);
495 break;
496 }
497 if (ret < 0) {
498 if (ret == -ENOENT)
499 Info("Video mode %s@%d fps is only supported with the decompressor module (pwcx).\n", size2name[size], frames);
500 else {
501 Err("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret);
502 }
503 return ret;
504 }
505 pdev->view.x = width;
506 pdev->view.y = height;
507 pdev->frame_total_size = pdev->frame_size + pdev->frame_header_size + pdev->frame_trailer_size;
508 pwc_set_image_buffer_size(pdev);
509 Trace(TRACE_SIZE, "Set viewport to %dx%d, image size is %dx%d.\n", width, height, pwc_image_sizes[size].x, pwc_image_sizes[size].y);
510 return 0;
511 }
512
513
514 /* BRIGHTNESS */
515
516 int pwc_get_brightness(struct pwc_device *pdev)
517 {
518 char buf;
519 int ret;
520
521 ret = RecvControlMsg(GET_LUM_CTL, BRIGHTNESS_FORMATTER, 1);
522 if (ret < 0)
523 return ret;
524 return buf << 9;
525 }
526
527 int pwc_set_brightness(struct pwc_device *pdev, int value)
528 {
529 char buf;
530
531 if (value < 0)
532 value = 0;
533 if (value > 0xffff)
534 value = 0xffff;
535 buf = (value >> 9) & 0x7f;
536 return SendControlMsg(SET_LUM_CTL, BRIGHTNESS_FORMATTER, 1);
537 }
538
539 /* CONTRAST */
540
541 int pwc_get_contrast(struct pwc_device *pdev)
542 {
543 char buf;
544 int ret;
545
546 ret = RecvControlMsg(GET_LUM_CTL, CONTRAST_FORMATTER, 1);
547 if (ret < 0)
548 return ret;
549 return buf << 10;
550 }
551
552 int pwc_set_contrast(struct pwc_device *pdev, int value)
553 {
554 char buf;
555
556 if (value < 0)
557 value = 0;
558 if (value > 0xffff)
559 value = 0xffff;
560 buf = (value >> 10) & 0x3f;
561 return SendControlMsg(SET_LUM_CTL, CONTRAST_FORMATTER, 1);
562 }
563
564 /* GAMMA */
565
566 int pwc_get_gamma(struct pwc_device *pdev)
567 {
568 char buf;
569 int ret;
570
571 ret = RecvControlMsg(GET_LUM_CTL, GAMMA_FORMATTER, 1);
572 if (ret < 0)
573 return ret;
574 return buf << 11;
575 }
576
577 int pwc_set_gamma(struct pwc_device *pdev, int value)
578 {
579 char buf;
580
581 if (value < 0)
582 value = 0;
583 if (value > 0xffff)
584 value = 0xffff;
585 buf = (value >> 11) & 0x1f;
586 return SendControlMsg(SET_LUM_CTL, GAMMA_FORMATTER, 1);
587 }
588
589
590 /* SATURATION */
591
592 int pwc_get_saturation(struct pwc_device *pdev)
593 {
594 char buf;
595 int ret;
596
597 if (pdev->type < 675)
598 return -1;
599 ret = RecvControlMsg(GET_CHROM_CTL, pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1, 1);
600 if (ret < 0)
601 return ret;
602 return 32768 + buf * 327;
603 }
604
605 int pwc_set_saturation(struct pwc_device *pdev, int value)
606 {
607 char buf;
608
609 if (pdev->type < 675)
610 return -EINVAL;
611 if (value < 0)
612 value = 0;
613 if (value > 0xffff)
614 value = 0xffff;
615 /* saturation ranges from -100 to +100 */
616 buf = (value - 32768) / 327;
617 return SendControlMsg(SET_CHROM_CTL, pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1, 1);
618 }
619
620 /* AGC */
621
622 static inline int pwc_set_agc(struct pwc_device *pdev, int mode, int value)
623 {
624 char buf;
625 int ret;
626
627 if (mode)
628 buf = 0x0; /* auto */
629 else
630 buf = 0xff; /* fixed */
631
632 ret = SendControlMsg(SET_LUM_CTL, AGC_MODE_FORMATTER, 1);
633
634 if (!mode && ret >= 0) {
635 if (value < 0)
636 value = 0;
637 if (value > 0xffff)
638 value = 0xffff;
639 buf = (value >> 10) & 0x3F;
640 ret = SendControlMsg(SET_LUM_CTL, PRESET_AGC_FORMATTER, 1);
641 }
642 if (ret < 0)
643 return ret;
644 return 0;
645 }
646
647 static inline int pwc_get_agc(struct pwc_device *pdev, int *value)
648 {
649 unsigned char buf;
650 int ret;
651
652 ret = RecvControlMsg(GET_LUM_CTL, AGC_MODE_FORMATTER, 1);
653 if (ret < 0)
654 return ret;
655
656 if (buf != 0) { /* fixed */
657 ret = RecvControlMsg(GET_LUM_CTL, PRESET_AGC_FORMATTER, 1);
658 if (ret < 0)
659 return ret;
660 if (buf > 0x3F)
661 buf = 0x3F;
662 *value = (buf << 10);
663 }
664 else { /* auto */
665 ret = RecvControlMsg(GET_STATUS_CTL, READ_AGC_FORMATTER, 1);
666 if (ret < 0)
667 return ret;
668 /* Gah... this value ranges from 0x00 ... 0x9F */
669 if (buf > 0x9F)
670 buf = 0x9F;
671 *value = -(48 + buf * 409);
672 }
673
674 return 0;
675 }
676
677 static inline int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value)
678 {
679 char buf[2];
680 int speed, ret;
681
682
683 if (mode)
684 buf[0] = 0x0; /* auto */
685 else
686 buf[0] = 0xff; /* fixed */
687
688 ret = SendControlMsg(SET_LUM_CTL, SHUTTER_MODE_FORMATTER, 1);
689
690 if (!mode && ret >= 0) {
691 if (value < 0)
692 value = 0;
693 if (value > 0xffff)
694 value = 0xffff;
695 switch(pdev->type) {
696 case 675:
697 case 680:
698 case 690:
699 /* speed ranges from 0x0 to 0x290 (656) */
700 speed = (value / 100);
701 buf[1] = speed >> 8;
702 buf[0] = speed & 0xff;
703 break;
704 case 720:
705 case 730:
706 case 740:
707 case 750:
708 /* speed seems to range from 0x0 to 0xff */
709 buf[1] = 0;
710 buf[0] = value >> 8;
711 break;
712 }
713
714 ret = SendControlMsg(SET_LUM_CTL, PRESET_SHUTTER_FORMATTER, 2);
715 }
716 return ret;
717 }
718
719
720 /* POWER */
721
722 int pwc_camera_power(struct pwc_device *pdev, int power)
723 {
724 char buf;
725
726 if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6))
727 return 0; /* Not supported by Nala or Timon < release 6 */
728
729 if (power)
730 buf = 0x00; /* active */
731 else
732 buf = 0xFF; /* power save */
733 return SendControlMsg(SET_STATUS_CTL, SET_POWER_SAVE_MODE_FORMATTER, 1);
734 }
735
736
737
738 /* private calls */
739
740 static inline int pwc_restore_user(struct pwc_device *pdev)
741 {
742 char buf; /* dummy */
743 return SendControlMsg(SET_STATUS_CTL, RESTORE_USER_DEFAULTS_FORMATTER, 0);
744 }
745
746 static inline int pwc_save_user(struct pwc_device *pdev)
747 {
748 char buf; /* dummy */
749 return SendControlMsg(SET_STATUS_CTL, SAVE_USER_DEFAULTS_FORMATTER, 0);
750 }
751
752 static inline int pwc_restore_factory(struct pwc_device *pdev)
753 {
754 char buf; /* dummy */
755 return SendControlMsg(SET_STATUS_CTL, RESTORE_FACTORY_DEFAULTS_FORMATTER, 0);
756 }
757
758 /* ************************************************* */
759 /* Patch by Alvarado: (not in the original version */
760
761 /*
762 * the camera recognizes modes from 0 to 4:
763 *
764 * 00: indoor (incandescant lighting)
765 * 01: outdoor (sunlight)
766 * 02: fluorescent lighting
767 * 03: manual
768 * 04: auto
769 */
770 static inline int pwc_set_awb(struct pwc_device *pdev, int mode)
771 {
772 char buf;
773 int ret;
774
775 if (mode < 0)
776 mode = 0;
777
778 if (mode > 4)
779 mode = 4;
780
781 buf = mode & 0x07; /* just the lowest three bits */
782
783 ret = SendControlMsg(SET_CHROM_CTL, WB_MODE_FORMATTER, 1);
784
785 if (ret < 0)
786 return ret;
787 return 0;
788 }
789
790 static inline int pwc_get_awb(struct pwc_device *pdev)
791 {
792 unsigned char buf;
793 int ret;
794
795 ret = RecvControlMsg(GET_CHROM_CTL, WB_MODE_FORMATTER, 1);
796
797 if (ret < 0)
798 return ret;
799 return buf;
800 }
801
802 static inline int pwc_set_red_gain(struct pwc_device *pdev, int value)
803 {
804 unsigned char buf;
805
806 if (value < 0)
807 value = 0;
808 if (value > 0xffff)
809 value = 0xffff;
810 /* only the msb is considered */
811 buf = value >> 8;
812 return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1);
813 }
814
815 static inline int pwc_get_red_gain(struct pwc_device *pdev, int *value)
816 {
817 unsigned char buf;
818 int ret;
819
820 ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1);
821 if (ret < 0)
822 return ret;
823 *value = buf << 8;
824 return 0;
825 }
826
827
828 static inline int pwc_set_blue_gain(struct pwc_device *pdev, int value)
829 {
830 unsigned char buf;
831
832 if (value < 0)
833 value = 0;
834 if (value > 0xffff)
835 value = 0xffff;
836 /* only the msb is considered */
837 buf = value >> 8;
838 return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1);
839 }
840
841 static inline int pwc_get_blue_gain(struct pwc_device *pdev, int *value)
842 {
843 unsigned char buf;
844 int ret;
845
846 ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1);
847 if (ret < 0)
848 return ret;
849 *value = buf << 8;
850 return 0;
851 }
852
853
854 /* The following two functions are different, since they only read the
855 internal red/blue gains, which may be different from the manual
856 gains set or read above.
857 */
858 static inline int pwc_read_red_gain(struct pwc_device *pdev, int *value)
859 {
860 unsigned char buf;
861 int ret;
862
863 ret = RecvControlMsg(GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, 1);
864 if (ret < 0)
865 return ret;
866 *value = buf << 8;
867 return 0;
868 }
869
870 static inline int pwc_read_blue_gain(struct pwc_device *pdev, int *value)
871 {
872 unsigned char buf;
873 int ret;
874
875 ret = RecvControlMsg(GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, 1);
876 if (ret < 0)
877 return ret;
878 *value = buf << 8;
879 return 0;
880 }
881
882
883 static inline int pwc_set_wb_speed(struct pwc_device *pdev, int speed)
884 {
885 unsigned char buf;
886
887 /* useful range is 0x01..0x20 */
888 buf = speed / 0x7f0;
889 return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1);
890 }
891
892 static inline int pwc_get_wb_speed(struct pwc_device *pdev, int *value)
893 {
894 unsigned char buf;
895 int ret;
896
897 ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1);
898 if (ret < 0)
899 return ret;
900 *value = buf * 0x7f0;
901 return 0;
902 }
903
904
905 static inline int pwc_set_wb_delay(struct pwc_device *pdev, int delay)
906 {
907 unsigned char buf;
908
909 /* useful range is 0x01..0x3F */
910 buf = (delay >> 10);
911 return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1);
912 }
913
914 static inline int pwc_get_wb_delay(struct pwc_device *pdev, int *value)
915 {
916 unsigned char buf;
917 int ret;
918
919 ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1);
920 if (ret < 0)
921 return ret;
922 *value = buf << 10;
923 return 0;
924 }
925
926
927 int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value)
928 {
929 unsigned char buf[2];
930
931 if (pdev->type < 730)
932 return 0;
933 on_value /= 100;
934 off_value /= 100;
935 if (on_value < 0)
936 on_value = 0;
937 if (on_value > 0xff)
938 on_value = 0xff;
939 if (off_value < 0)
940 off_value = 0;
941 if (off_value > 0xff)
942 off_value = 0xff;
943
944 buf[0] = on_value;
945 buf[1] = off_value;
946
947 return SendControlMsg(SET_STATUS_CTL, LED_FORMATTER, 2);
948 }
949
950 static int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value)
951 {
952 unsigned char buf[2];
953 int ret;
954
955 if (pdev->type < 730) {
956 *on_value = -1;
957 *off_value = -1;
958 return 0;
959 }
960
961 ret = RecvControlMsg(GET_STATUS_CTL, LED_FORMATTER, 2);
962 if (ret < 0)
963 return ret;
964 *on_value = buf[0] * 100;
965 *off_value = buf[1] * 100;
966 return 0;
967 }
968
969 static inline int pwc_set_contour(struct pwc_device *pdev, int contour)
970 {
971 unsigned char buf;
972 int ret;
973
974 if (contour < 0)
975 buf = 0xff; /* auto contour on */
976 else
977 buf = 0x0; /* auto contour off */
978 ret = SendControlMsg(SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1);
979 if (ret < 0)
980 return ret;
981
982 if (contour < 0)
983 return 0;
984 if (contour > 0xffff)
985 contour = 0xffff;
986
987 buf = (contour >> 10); /* contour preset is [0..3f] */
988 ret = SendControlMsg(SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1);
989 if (ret < 0)
990 return ret;
991 return 0;
992 }
993
994 static inline int pwc_get_contour(struct pwc_device *pdev, int *contour)
995 {
996 unsigned char buf;
997 int ret;
998
999 ret = RecvControlMsg(GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1);
1000 if (ret < 0)
1001 return ret;
1002
1003 if (buf == 0) {
1004 /* auto mode off, query current preset value */
1005 ret = RecvControlMsg(GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1);
1006 if (ret < 0)
1007 return ret;
1008 *contour = buf << 10;
1009 }
1010 else
1011 *contour = -1;
1012 return 0;
1013 }
1014
1015
1016 static inline int pwc_set_backlight(struct pwc_device *pdev, int backlight)
1017 {
1018 unsigned char buf;
1019
1020 if (backlight)
1021 buf = 0xff;
1022 else
1023 buf = 0x0;
1024 return SendControlMsg(SET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1);
1025 }
1026
1027 static inline int pwc_get_backlight(struct pwc_device *pdev, int *backlight)
1028 {
1029 int ret;
1030 unsigned char buf;
1031
1032 ret = RecvControlMsg(GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1);
1033 if (ret < 0)
1034 return ret;
1035 *backlight = buf;
1036 return 0;
1037 }
1038
1039
1040 static inline int pwc_set_flicker(struct pwc_device *pdev, int flicker)
1041 {
1042 unsigned char buf;
1043
1044 if (flicker)
1045 buf = 0xff;
1046 else
1047 buf = 0x0;
1048 return SendControlMsg(SET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);
1049 }
1050
1051 static inline int pwc_get_flicker(struct pwc_device *pdev, int *flicker)
1052 {
1053 int ret;
1054 unsigned char buf;
1055
1056 ret = RecvControlMsg(GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);
1057 if (ret < 0)
1058 return ret;
1059 *flicker = buf;
1060 return 0;
1061 }
1062
1063
1064 static inline int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise)
1065 {
1066 unsigned char buf;
1067
1068 if (noise < 0)
1069 noise = 0;
1070 if (noise > 3)
1071 noise = 3;
1072 buf = noise;
1073 return SendControlMsg(SET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);
1074 }
1075
1076 static inline int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise)
1077 {
1078 int ret;
1079 unsigned char buf;
1080
1081 ret = RecvControlMsg(GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);
1082 if (ret < 0)
1083 return ret;
1084 *noise = buf;
1085 return 0;
1086 }
1087
1088 static int pwc_mpt_reset(struct pwc_device *pdev, int flags)
1089 {
1090 unsigned char buf;
1091
1092 buf = flags & 0x03; // only lower two bits are currently used
1093 return SendControlMsg(SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, 1);
1094 }
1095
1096 static inline int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt)
1097 {
1098 unsigned char buf[4];
1099
1100 /* set new relative angle; angles are expressed in degrees * 100,
1101 but cam as .5 degree resolution, hence divide by 200. Also
1102 the angle must be multiplied by 64 before it's send to
1103 the cam (??)
1104 */
1105 pan = 64 * pan / 100;
1106 tilt = -64 * tilt / 100; /* positive tilt is down, which is not what the user would expect */
1107 buf[0] = pan & 0xFF;
1108 buf[1] = (pan >> 8) & 0xFF;
1109 buf[2] = tilt & 0xFF;
1110 buf[3] = (tilt >> 8) & 0xFF;
1111 return SendControlMsg(SET_MPT_CTL, PT_RELATIVE_CONTROL_FORMATTER, 4);
1112 }
1113
1114 static inline int pwc_mpt_get_status(struct pwc_device *pdev, struct pwc_mpt_status *status)
1115 {
1116 int ret;
1117 unsigned char buf[5];
1118
1119 ret = RecvControlMsg(GET_MPT_CTL, PT_STATUS_FORMATTER, 5);
1120 if (ret < 0)
1121 return ret;
1122 status->status = buf[0] & 0x7; // 3 bits are used for reporting
1123 status->time_pan = (buf[1] << 8) + buf[2];
1124 status->time_tilt = (buf[3] << 8) + buf[4];
1125 return 0;
1126 }
1127
1128
1129 int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor)
1130 {
1131 unsigned char buf;
1132 int ret = -1, request;
1133
1134 if (pdev->type < 675)
1135 request = SENSOR_TYPE_FORMATTER1;
1136 else if (pdev->type < 730)
1137 return -1; /* The Vesta series doesn't have this call */
1138 else
1139 request = SENSOR_TYPE_FORMATTER2;
1140
1141 ret = RecvControlMsg(GET_STATUS_CTL, request, 1);
1142 if (ret < 0)
1143 return ret;
1144 if (pdev->type < 675)
1145 *sensor = buf | 0x100;
1146 else
1147 *sensor = buf;
1148 return 0;
1149 }
1150
1151
1152 /* End of Add-Ons */
1153 /* ************************************************* */
1154
1155
1156 int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1157 {
1158 int ret = 0;
1159
1160 switch(cmd) {
1161 case VIDIOCPWCRUSER:
1162 {
1163 if (pwc_restore_user(pdev))
1164 ret = -EINVAL;
1165 break;
1166 }
1167
1168 case VIDIOCPWCSUSER:
1169 {
1170 if (pwc_save_user(pdev))
1171 ret = -EINVAL;
1172 break;
1173 }
1174
1175 case VIDIOCPWCFACTORY:
1176 {
1177 if (pwc_restore_factory(pdev))
1178 ret = -EINVAL;
1179 break;
1180 }
1181
1182 case VIDIOCPWCSCQUAL:
1183 {
1184 int *qual = arg;
1185
1186 if (*qual < 0 || *qual > 3)
1187 ret = -EINVAL;
1188 else
1189 ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, *qual, pdev->vsnapshot);
1190 if (ret >= 0)
1191 pdev->vcompression = *qual;
1192 break;
1193 }
1194
1195 case VIDIOCPWCGCQUAL:
1196 {
1197 int *qual = arg;
1198 *qual = pdev->vcompression;
1199 break;
1200 }
1201
1202 case VIDIOCPWCPROBE:
1203 {
1204 struct pwc_probe *probe = arg;
1205 strcpy(probe->name, pdev->vdev->name);
1206 probe->type = pdev->type;
1207 break;
1208 }
1209
1210 case VIDIOCPWCGSERIAL:
1211 {
1212 struct pwc_serial *serial = arg;
1213 strcpy(serial->serial, pdev->serial);
1214 break;
1215 }
1216
1217 case VIDIOCPWCSAGC:
1218 {
1219 int *agc = arg;
1220 if (pwc_set_agc(pdev, *agc < 0 ? 1 : 0, *agc))
1221 ret = -EINVAL;
1222 break;
1223 }
1224
1225 case VIDIOCPWCGAGC:
1226 {
1227 int *agc = arg;
1228
1229 if (pwc_get_agc(pdev, agc))
1230 ret = -EINVAL;
1231 break;
1232 }
1233
1234 case VIDIOCPWCSSHUTTER:
1235 {
1236 int *shutter_speed = arg;
1237 ret = pwc_set_shutter_speed(pdev, *shutter_speed < 0 ? 1 : 0, *shutter_speed);
1238 break;
1239 }
1240
1241 case VIDIOCPWCSAWB:
1242 {
1243 struct pwc_whitebalance *wb = arg;
1244
1245 ret = pwc_set_awb(pdev, wb->mode);
1246 if (ret >= 0 && wb->mode == PWC_WB_MANUAL) {
1247 pwc_set_red_gain(pdev, wb->manual_red);
1248 pwc_set_blue_gain(pdev, wb->manual_blue);
1249 }
1250 break;
1251 }
1252
1253 case VIDIOCPWCGAWB:
1254 {
1255 struct pwc_whitebalance *wb = arg;
1256
1257 memset(wb, 0, sizeof(struct pwc_whitebalance));
1258 wb->mode = pwc_get_awb(pdev);
1259 if (wb->mode < 0)
1260 ret = -EINVAL;
1261 else {
1262 if (wb->mode == PWC_WB_MANUAL) {
1263 ret = pwc_get_red_gain(pdev, &wb->manual_red);
1264 if (ret < 0)
1265 break;
1266 ret = pwc_get_blue_gain(pdev, &wb->manual_blue);
1267 if (ret < 0)
1268 break;
1269 }
1270 if (wb->mode == PWC_WB_AUTO) {
1271 ret = pwc_read_red_gain(pdev, &wb->read_red);
1272 if (ret < 0)
1273 break;
1274 ret = pwc_read_blue_gain(pdev, &wb->read_blue);
1275 if (ret < 0)
1276 break;
1277 }
1278 }
1279 break;
1280 }
1281
1282 case VIDIOCPWCSAWBSPEED:
1283 {
1284 struct pwc_wb_speed *wbs = arg;
1285
1286 if (wbs->control_speed > 0) {
1287 ret = pwc_set_wb_speed(pdev, wbs->control_speed);
1288 }
1289 if (wbs->control_delay > 0) {
1290 ret = pwc_set_wb_delay(pdev, wbs->control_delay);
1291 }
1292 break;
1293 }
1294
1295 case VIDIOCPWCGAWBSPEED:
1296 {
1297 struct pwc_wb_speed *wbs = arg;
1298
1299 ret = pwc_get_wb_speed(pdev, &wbs->control_speed);
1300 if (ret < 0)
1301 break;
1302 ret = pwc_get_wb_delay(pdev, &wbs->control_delay);
1303 if (ret < 0)
1304 break;
1305 break;
1306 }
1307
1308 case VIDIOCPWCSLED:
1309 {
1310 struct pwc_leds *leds = arg;
1311 ret = pwc_set_leds(pdev, leds->led_on, leds->led_off);
1312 break;
1313 }
1314
1315
1316 case VIDIOCPWCGLED:
1317 {
1318 struct pwc_leds *leds = arg;
1319 ret = pwc_get_leds(pdev, &leds->led_on, &leds->led_off);
1320 break;
1321 }
1322
1323 case VIDIOCPWCSCONTOUR:
1324 {
1325 int *contour = arg;
1326 ret = pwc_set_contour(pdev, *contour);
1327 break;
1328 }
1329
1330 case VIDIOCPWCGCONTOUR:
1331 {
1332 int *contour = arg;
1333 ret = pwc_get_contour(pdev, contour);
1334 break;
1335 }
1336
1337 case VIDIOCPWCSBACKLIGHT:
1338 {
1339 int *backlight = arg;
1340 ret = pwc_set_backlight(pdev, *backlight);
1341 break;
1342 }
1343
1344 case VIDIOCPWCGBACKLIGHT:
1345 {
1346 int *backlight = arg;
1347 ret = pwc_get_backlight(pdev, backlight);
1348 break;
1349 }
1350
1351 case VIDIOCPWCSFLICKER:
1352 {
1353 int *flicker = arg;
1354 ret = pwc_set_flicker(pdev, *flicker);
1355 break;
1356 }
1357
1358 case VIDIOCPWCGFLICKER:
1359 {
1360 int *flicker = arg;
1361 ret = pwc_get_flicker(pdev, flicker);
1362 break;
1363 }
1364
1365 case VIDIOCPWCSDYNNOISE:
1366 {
1367 int *dynnoise = arg;
1368 ret = pwc_set_dynamic_noise(pdev, *dynnoise);
1369 break;
1370 }
1371
1372 case VIDIOCPWCGDYNNOISE:
1373 {
1374 int *dynnoise = arg;
1375 ret = pwc_get_dynamic_noise(pdev, dynnoise);
1376 break;
1377 }
1378
1379 case VIDIOCPWCGREALSIZE:
1380 {
1381 struct pwc_imagesize *size = arg;
1382 size->width = pdev->image.x;
1383 size->height = pdev->image.y;
1384 break;
1385 }
1386
1387 case VIDIOCPWCMPTRESET:
1388 {
1389 if (pdev->features & FEATURE_MOTOR_PANTILT)
1390 {
1391 int *flags = arg;
1392
1393 ret = pwc_mpt_reset(pdev, *flags);
1394 if (ret >= 0)
1395 {
1396 pdev->pan_angle = 0;
1397 pdev->tilt_angle = 0;
1398 }
1399 }
1400 else
1401 {
1402 ret = -ENXIO;
1403 }
1404 break;
1405 }
1406
1407 case VIDIOCPWCMPTGRANGE:
1408 {
1409 if (pdev->features & FEATURE_MOTOR_PANTILT)
1410 {
1411 struct pwc_mpt_range *range = arg;
1412 *range = pdev->angle_range;
1413 }
1414 else
1415 {
1416 ret = -ENXIO;
1417 }
1418 break;
1419 }
1420
1421 case VIDIOCPWCMPTSANGLE:
1422 {
1423 int new_pan, new_tilt;
1424
1425 if (pdev->features & FEATURE_MOTOR_PANTILT)
1426 {
1427 struct pwc_mpt_angles *angles = arg;
1428 /* The camera can only set relative angles, so
1429 do some calculations when getting an absolute angle .
1430 */
1431 if (angles->absolute)
1432 {
1433 new_pan = angles->pan;
1434 new_tilt = angles->tilt;
1435 }
1436 else
1437 {
1438 new_pan = pdev->pan_angle + angles->pan;
1439 new_tilt = pdev->tilt_angle + angles->tilt;
1440 }
1441 /* check absolute ranges */
1442 if (new_pan < pdev->angle_range.pan_min ||
1443 new_pan > pdev->angle_range.pan_max ||
1444 new_tilt < pdev->angle_range.tilt_min ||
1445 new_tilt > pdev->angle_range.tilt_max)
1446 {
1447 ret = -ERANGE;
1448 }
1449 else
1450 {
1451 /* go to relative range, check again */
1452 new_pan -= pdev->pan_angle;
1453 new_tilt -= pdev->tilt_angle;
1454 /* angles are specified in degrees * 100, thus the limit = 36000 */
1455 if (new_pan < -36000 || new_pan > 36000 || new_tilt < -36000 || new_tilt > 36000)
1456 ret = -ERANGE;
1457 }
1458 if (ret == 0) /* no errors so far */
1459 {
1460 ret = pwc_mpt_set_angle(pdev, new_pan, new_tilt);
1461 if (ret >= 0)
1462 {
1463 pdev->pan_angle += new_pan;
1464 pdev->tilt_angle += new_tilt;
1465 }
1466 if (ret == -EPIPE) /* stall -> out of range */
1467 ret = -ERANGE;
1468 }
1469 }
1470 else
1471 {
1472 ret = -ENXIO;
1473 }
1474 break;
1475 }
1476
1477 case VIDIOCPWCMPTGANGLE:
1478 {
1479
1480 if (pdev->features & FEATURE_MOTOR_PANTILT)
1481 {
1482 struct pwc_mpt_angles *angles = arg;
1483
1484 angles->absolute = 1;
1485 angles->pan = pdev->pan_angle;
1486 angles->tilt = pdev->tilt_angle;
1487 }
1488 else
1489 {
1490 ret = -ENXIO;
1491 }
1492 break;
1493 }
1494
1495 case VIDIOCPWCMPTSTATUS:
1496 {
1497 if (pdev->features & FEATURE_MOTOR_PANTILT)
1498 {
1499 struct pwc_mpt_status *status = arg;
1500 ret = pwc_mpt_get_status(pdev, status);
1501 }
1502 else
1503 {
1504 ret = -ENXIO;
1505 }
1506 break;
1507 }
1508
1509 case VIDIOCPWCGVIDCMD:
1510 {
1511 struct pwc_video_command *cmd = arg;
1512
1513 cmd->type = pdev->type;
1514 cmd->release = pdev->release;
1515 cmd->command_len = pdev->cmd_len;
1516 memcpy(&cmd->command_buf, pdev->cmd_buf, pdev->cmd_len);
1517 cmd->bandlength = pdev->vbandlength;
1518 cmd->frame_size = pdev->frame_size;
1519 break;
1520 }
1521 /*
1522 case VIDIOCPWCGVIDTABLE:
1523 {
1524 struct pwc_table_init_buffer *table = arg;
1525 table->len = pdev->cmd_len;
1526 memcpy(&table->buffer, pdev->decompress_data, pdev->decompressor->table_size);
1527 break;
1528 }
1529 */
1530
1531 default:
1532 ret = -ENOIOCTLCMD;
1533 break;
1534 }
1535
1536 if (ret > 0)
1537 return 0;
1538 return ret;
1539 }
1540
1541
1542