1 /* Driver for Philips webcam
2 Functions that send various control messages to the webcam, including
4 (C) 1999-2003 Nemosoft Unv. (webcam@smcc.demon.nl)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 2001/08/03 Alvarado Added methods for changing white balance and
27 /* Control functions for the cam; brightness, contrast, video mode, etc. */
30 #include <asm/uaccess.h>
32 #include <asm/errno.h>
35 #include "pwc-ioctl.h"
36 #include "pwc-uncompress.h"
38 /* Request types: video */
39 #define SET_LUM_CTL 0x01
40 #define GET_LUM_CTL 0x02
41 #define SET_CHROM_CTL 0x03
42 #define GET_CHROM_CTL 0x04
43 #define SET_STATUS_CTL 0x05
44 #define GET_STATUS_CTL 0x06
45 #define SET_EP_STREAM_CTL 0x07
46 #define GET_EP_STREAM_CTL 0x08
48 /* Selectors for the Luminance controls [GS]ET_LUM_CTL */
49 #define AGC_MODE_FORMATTER 0x2000
50 #define PRESET_AGC_FORMATTER 0x2100
51 #define SHUTTER_MODE_FORMATTER 0x2200
52 #define PRESET_SHUTTER_FORMATTER 0x2300
53 #define PRESET_CONTOUR_FORMATTER 0x2400
54 #define AUTO_CONTOUR_FORMATTER 0x2500
55 #define BACK_LIGHT_COMPENSATION_FORMATTER 0x2600
56 #define CONTRAST_FORMATTER 0x2700
57 #define DYNAMIC_NOISE_CONTROL_FORMATTER 0x2800
58 #define FLICKERLESS_MODE_FORMATTER 0x2900
59 #define AE_CONTROL_SPEED 0x2A00
60 #define BRIGHTNESS_FORMATTER 0x2B00
61 #define GAMMA_FORMATTER 0x2C00
63 /* Selectors for the Chrominance controls [GS]ET_CHROM_CTL */
64 #define WB_MODE_FORMATTER 0x1000
65 #define AWB_CONTROL_SPEED_FORMATTER 0x1100
66 #define AWB_CONTROL_DELAY_FORMATTER 0x1200
67 #define PRESET_MANUAL_RED_GAIN_FORMATTER 0x1300
68 #define PRESET_MANUAL_BLUE_GAIN_FORMATTER 0x1400
69 #define COLOUR_MODE_FORMATTER 0x1500
70 #define SATURATION_MODE_FORMATTER1 0x1600
71 #define SATURATION_MODE_FORMATTER2 0x1700
73 /* Selectors for the Status controls [GS]ET_STATUS_CTL */
74 #define SAVE_USER_DEFAULTS_FORMATTER 0x0200
75 #define RESTORE_USER_DEFAULTS_FORMATTER 0x0300
76 #define RESTORE_FACTORY_DEFAULTS_FORMATTER 0x0400
77 #define READ_AGC_FORMATTER 0x0500
78 #define READ_SHUTTER_FORMATTER 0x0600
79 #define READ_RED_GAIN_FORMATTER 0x0700
80 #define READ_BLUE_GAIN_FORMATTER 0x0800
81 #define SENSOR_TYPE_FORMATTER1 0x0C00
82 #define READ_RAW_Y_MEAN_FORMATTER 0x3100
83 #define SET_POWER_SAVE_MODE_FORMATTER 0x3200
84 #define MIRROR_IMAGE_FORMATTER 0x3300
85 #define LED_FORMATTER 0x3400
86 #define SENSOR_TYPE_FORMATTER2 0x3700
88 /* Formatters for the Video Endpoint controls [GS]ET_EP_STREAM_CTL */
89 #define VIDEO_OUTPUT_CONTROL_FORMATTER 0x0100
91 static char *size2name[PSZ_MAX] =
103 /* Entries for the Nala (645/646) camera; the Nala doesn't have compression
104 preferences, so you either get compressed or non-compressed streams.
106 An alternate value of 0 means this mode is not available at all.
109 struct Nala_table_entry {
110 char alternate; /* USB alternate setting */
111 int compressed; /* Compressed yes/no */
113 unsigned char mode[3]; /* precomputed mode table */
116 static struct Nala_table_entry Nala_table[PSZ_MAX][8] =
118 #include "pwc_nala.h"
121 /* This tables contains entries for the 675/680/690 (Timon) camera, with
122 4 different qualities (no compression, low, medium, high).
123 It lists the bandwidth requirements for said mode by its alternate interface
124 number. An alternate of 0 means that the mode is unavailable.
126 There are 6 * 4 * 4 entries:
127 6 different resolutions subqcif, qsif, qcif, sif, cif, vga
128 6 framerates: 5, 10, 15, 20, 25, 30
129 4 compression modi: none, low, medium, high
131 When an uncompressed mode is not available, the next available compressed mode
132 will be chosen (unless the decompressor is absent). Sometimes there are only
133 1 or 2 compressed modes available; in that case entries are duplicated.
135 struct Timon_table_entry
137 char alternate; /* USB alternate interface */
138 unsigned short packetsize; /* Normal packet size */
139 unsigned short bandlength; /* Bandlength when decompressing */
140 unsigned char mode[13]; /* precomputed mode settings for cam */
143 static struct Timon_table_entry Timon_table[PSZ_MAX][6][4] =
145 #include "pwc_timon.h"
148 /* Entries for the Kiara (730/740/750) camera */
150 struct Kiara_table_entry
152 char alternate; /* USB alternate interface */
153 unsigned short packetsize; /* Normal packet size */
154 unsigned short bandlength; /* Bandlength when decompressing */
155 unsigned char mode[12]; /* precomputed mode settings for cam */
158 static struct Kiara_table_entry Kiara_table[PSZ_MAX][6][4] =
160 #include "pwc_kiara.h"
164 /****************************************************************************/
167 #define SendControlMsg(request, value, buflen) \
168 usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0), \
170 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \
173 &buf, buflen, HZ / 2)
175 #define RecvControlMsg(request, value, buflen) \
176 usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0), \
178 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \
181 &buf, buflen, HZ / 2)
185 void pwc_hexdump(void *p, int len)
191 s = (unsigned char *)p;
194 Debug("Doing hexdump @ %p, %d bytes.\n", p, len);
195 for (i = 0; i < len; i++) {
196 d += sprintf(d, "%02X ", *s++);
197 if ((i & 0xF) == 0xF) {
208 static inline int send_video_command(struct usb_device *udev, int index, void *buf, int buflen)
210 return usb_control_msg(udev,
211 usb_sndctrlpipe(udev, 0),
213 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
214 VIDEO_OUTPUT_CONTROL_FORMATTER,
221 static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames)
223 unsigned char buf[3];
225 struct Nala_table_entry *pEntry;
226 int frames2frames[31] =
227 { /* closest match of framerate */
228 0, 0, 0, 0, 4, /* 0-4 */
229 5, 5, 7, 7, 10, /* 5-9 */
230 10, 10, 12, 12, 15, /* 10-14 */
231 15, 15, 15, 20, 20, /* 15-19 */
232 20, 20, 20, 24, 24, /* 20-24 */
233 24, 24, 24, 24, 24, /* 25-29 */
236 int frames2table[31] =
237 { 0, 0, 0, 0, 0, /* 0-4 */
238 1, 1, 1, 2, 2, /* 5-9 */
239 3, 3, 4, 4, 4, /* 10-14 */
240 5, 5, 5, 5, 5, /* 15-19 */
241 6, 6, 6, 6, 7, /* 20-24 */
242 7, 7, 7, 7, 7, /* 25-29 */
246 if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25)
248 frames = frames2frames[frames];
249 fps = frames2table[frames];
250 pEntry = &Nala_table[size][fps];
251 if (pEntry->alternate == 0)
254 if (pEntry->compressed && pdev->decompressor == NULL)
255 return -ENOENT; /* Not supported. */
257 memcpy(buf, pEntry->mode, 3);
258 ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 3);
260 Debug("Failed to send video command... %d\n", ret);
263 if (pEntry->compressed && pdev->decompressor != NULL)
264 pdev->decompressor->init(pdev->release, buf, pdev->decompress_data);
266 /* Set various parameters */
267 pdev->vframes = frames;
269 pdev->valternate = pEntry->alternate;
270 pdev->image = pwc_image_sizes[size];
271 pdev->frame_size = (pdev->image.x * pdev->image.y * 3) / 2;
272 if (pEntry->compressed) {
273 if (pdev->release < 5) { /* 4 fold compression */
274 pdev->vbandlength = 528;
275 pdev->frame_size /= 4;
278 pdev->vbandlength = 704;
279 pdev->frame_size /= 3;
283 pdev->vbandlength = 0;
288 static inline int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames, int compression, int snapshot)
290 unsigned char buf[13];
291 struct Timon_table_entry *pChoose;
294 if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3)
296 if (size == PSZ_VGA && frames > 15)
298 fps = (frames / 5) - 1;
300 /* Find a supported framerate with progressively higher compression ratios
301 if the preferred ratio is not available.
304 if (pdev->decompressor == NULL) {
306 Debug("Trying to find uncompressed mode.\n");
308 pChoose = &Timon_table[size][fps][0];
311 while (compression <= 3) {
312 pChoose = &Timon_table[size][fps][compression];
313 if (pChoose->alternate != 0)
318 if (pChoose == NULL || pChoose->alternate == 0)
319 return -ENOENT; /* Not supported. */
321 memcpy(buf, pChoose->mode, 13);
324 ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 13);
328 if (pChoose->bandlength > 0)
329 pdev->decompressor->init(pdev->release, buf, pdev->decompress_data);
331 /* Set various parameters */
332 pdev->vframes = frames;
334 pdev->vsnapshot = snapshot;
335 pdev->valternate = pChoose->alternate;
336 pdev->image = pwc_image_sizes[size];
337 pdev->vbandlength = pChoose->bandlength;
338 if (pChoose->bandlength > 0)
339 pdev->frame_size = (pChoose->bandlength * pdev->image.y) / 4;
341 pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8;
346 static inline int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames, int compression, int snapshot)
348 struct Kiara_table_entry *pChoose;
350 unsigned char buf[12];
352 if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3)
354 if (size == PSZ_VGA && frames > 15)
356 fps = (frames / 5) - 1;
358 /* Find a supported framerate with progressively higher compression ratios
359 if the preferred ratio is not available.
362 if (pdev->decompressor == NULL) {
364 Debug("Trying to find uncompressed mode.\n");
366 pChoose = &Kiara_table[size][fps][0];
369 while (compression <= 3) {
370 pChoose = &Kiara_table[size][fps][compression];
371 if (pChoose->alternate != 0)
376 if (pChoose == NULL || pChoose->alternate == 0)
377 return -ENOENT; /* Not supported. */
379 /* usb_control_msg won't take staticly allocated arrays as argument?? */
380 memcpy(buf, pChoose->mode, 12);
384 /* Firmware bug: video endpoint is 5, but commands are sent to endpoint 4 */
385 ret = send_video_command(pdev->udev, 4 /* pdev->vendpoint */, buf, 12);
389 if (pChoose->bandlength > 0)
390 pdev->decompressor->init(pdev->release, buf, pdev->decompress_data);
393 pdev->vframes = frames;
395 pdev->vsnapshot = snapshot;
396 pdev->valternate = pChoose->alternate;
397 pdev->image = pwc_image_sizes[size];
398 pdev->vbandlength = pChoose->bandlength;
399 if (pChoose->bandlength > 0)
400 pdev->frame_size = (pChoose->bandlength * pdev->image.y) / 4;
402 pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8;
403 pdev->frame_size += (pdev->frame_header_size + pdev->frame_trailer_size);
409 @pdev: device structure
410 @width: viewport width
411 @height: viewport height
412 @frame: framerate, in fps
413 @compression: preferred compression ratio
414 @snapshot: snapshot mode or streaming
416 int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot)
420 size = pwc_decode_size(pdev, width, height);
422 Debug("Could not find suitable size.\n");
429 ret = set_video_mode_Nala(pdev, size, frames);
435 ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot);
441 ret = set_video_mode_Kiara(pdev, size, frames, compression, snapshot);
446 Info("Video mode %s@%d fps is only supported with the decompressor module (pwcx).\n", size2name[size], frames);
448 Err("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret);
452 pdev->view.x = width;
453 pdev->view.y = height;
454 pwc_set_image_buffer_size(pdev);
455 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);
460 void pwc_set_image_buffer_size(struct pwc_device *pdev)
462 int factor, i, filler = 0;
467 /* Set sizes in bytes */
468 pdev->image.size = pdev->image.x * pdev->image.y * factor / 4;
469 pdev->view.size = pdev->view.x * pdev->view.y * factor / 4;
471 /* Align offset, or you'll get some very weird results in
472 YUV420 mode... x must be multiple of 4 (to get the Y's in
473 place), and y even (or you'll mixup U & V). This is less of a
476 pdev->offset.x = ((pdev->view.x - pdev->image.x) / 2) & 0xFFFC;
477 pdev->offset.y = ((pdev->view.y - pdev->image.y) / 2) & 0xFFFE;
479 /* Fill buffers with gray or black */
480 for (i = 0; i < MAX_IMAGES; i++) {
481 if (pdev->image_ptr[i] != NULL)
482 memset(pdev->image_ptr[i], filler, pdev->view.size);
490 int pwc_get_brightness(struct pwc_device *pdev)
495 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
497 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
498 BRIGHTNESS_FORMATTER,
506 int pwc_set_brightness(struct pwc_device *pdev, int value)
514 buf = (value >> 9) & 0x7f;
515 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
517 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
518 BRIGHTNESS_FORMATTER,
525 int pwc_get_contrast(struct pwc_device *pdev)
530 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
532 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
541 int pwc_set_contrast(struct pwc_device *pdev, int value)
549 buf = (value >> 10) & 0x3f;
550 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
552 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
560 int pwc_get_gamma(struct pwc_device *pdev)
565 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
567 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
576 int pwc_set_gamma(struct pwc_device *pdev, int value)
584 buf = (value >> 11) & 0x1f;
585 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
587 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
596 int pwc_get_saturation(struct pwc_device *pdev)
601 if (pdev->type < 675)
603 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
605 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
606 pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1,
611 return 32768 + buf * 327;
614 int pwc_set_saturation(struct pwc_device *pdev, int value)
618 if (pdev->type < 675)
624 /* saturation ranges from -100 to +100 */
625 buf = (value - 32768) / 327;
626 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
628 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
629 pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1,
636 static inline int pwc_set_agc(struct pwc_device *pdev, int mode, int value)
642 buf = 0x0; /* auto */
644 buf = 0xff; /* fixed */
646 ret = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
648 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
653 if (!mode && ret >= 0) {
658 buf = (value >> 10) & 0x3F;
659 ret = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
661 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
662 PRESET_AGC_FORMATTER,
671 static inline int pwc_get_agc(struct pwc_device *pdev, int *value)
676 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
678 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
685 if (buf != 0) { /* fixed */
686 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
688 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
689 PRESET_AGC_FORMATTER,
696 *value = (buf << 10);
699 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
701 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
707 /* Gah... this value ranges from 0x00 ... 0x9F */
710 *value = -(48 + buf * 409);
716 static inline int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value)
723 buf[0] = 0x0; /* auto */
725 buf[0] = 0xff; /* fixed */
727 ret = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
729 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
730 SHUTTER_MODE_FORMATTER,
734 if (!mode && ret >= 0) {
743 /* speed ranges from 0x0 to 0x290 (656) */
744 speed = (value / 100);
746 buf[0] = speed & 0xff;
751 /* speed seems to range from 0x0 to 0xff */
757 ret = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
759 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
760 PRESET_SHUTTER_FORMATTER,
770 int pwc_camera_power(struct pwc_device *pdev, int power)
774 if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6))
775 return 0; /* Not supported by Nala or Timon < release 6 */
778 buf = 0x00; /* active */
780 buf = 0xFF; /* power save */
781 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
783 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
784 SET_POWER_SAVE_MODE_FORMATTER,
793 static inline int pwc_restore_user(struct pwc_device *pdev)
795 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
797 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
798 RESTORE_USER_DEFAULTS_FORMATTER,
803 static inline int pwc_save_user(struct pwc_device *pdev)
805 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
807 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
808 SAVE_USER_DEFAULTS_FORMATTER,
813 static inline int pwc_restore_factory(struct pwc_device *pdev)
815 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
817 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
818 RESTORE_FACTORY_DEFAULTS_FORMATTER,
823 /* ************************************************* */
824 /* Patch by Alvarado: (not in the original version */
827 * the camera recognizes modes from 0 to 4:
829 * 00: indoor (incandescant lighting)
830 * 01: outdoor (sunlight)
831 * 02: fluorescent lighting
835 static inline int pwc_set_awb(struct pwc_device *pdev, int mode)
846 buf = mode & 0x07; /* just the lowest three bits */
848 ret = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
850 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
860 static inline int pwc_get_awb(struct pwc_device *pdev)
865 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
867 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
877 static inline int pwc_set_red_gain(struct pwc_device *pdev, int value)
886 /* only the msb are considered */
889 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
891 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
892 PRESET_MANUAL_RED_GAIN_FORMATTER,
897 static inline int pwc_get_red_gain(struct pwc_device *pdev)
902 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
904 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
905 PRESET_MANUAL_RED_GAIN_FORMATTER,
916 static inline int pwc_set_blue_gain(struct pwc_device *pdev, int value)
925 /* linear mapping of 0..0xffff to -0x80..0x7f */
928 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
930 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
931 PRESET_MANUAL_BLUE_GAIN_FORMATTER,
936 static inline int pwc_get_blue_gain(struct pwc_device *pdev)
941 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
943 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
944 PRESET_MANUAL_BLUE_GAIN_FORMATTER,
955 /* The following two functions are different, since they only read the
956 internal red/blue gains, which may be different from the manual
957 gains set or read above.
959 static inline int pwc_read_red_gain(struct pwc_device *pdev)
964 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
966 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
967 READ_RED_GAIN_FORMATTER,
977 static inline int pwc_read_blue_gain(struct pwc_device *pdev)
982 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
984 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
985 READ_BLUE_GAIN_FORMATTER,
996 static inline int pwc_set_wb_speed(struct pwc_device *pdev, int speed)
1000 /* useful range is 0x01..0x20 */
1001 buf = speed / 0x7f0;
1002 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
1004 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1005 AWB_CONTROL_SPEED_FORMATTER,
1010 static inline int pwc_get_wb_speed(struct pwc_device *pdev)
1015 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
1017 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1018 AWB_CONTROL_SPEED_FORMATTER,
1023 return (buf * 0x7f0);
1027 static inline int pwc_set_wb_delay(struct pwc_device *pdev, int delay)
1031 /* useful range is 0x01..0x3F */
1032 buf = (delay >> 10);
1033 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
1035 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1036 AWB_CONTROL_DELAY_FORMATTER,
1041 static inline int pwc_get_wb_delay(struct pwc_device *pdev)
1046 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
1048 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1049 AWB_CONTROL_DELAY_FORMATTER,
1058 int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value)
1060 unsigned char buf[2];
1062 if (pdev->type < 730)
1068 if (on_value > 0xff)
1072 if (off_value > 0xff)
1078 return SendControlMsg(SET_STATUS_CTL, LED_FORMATTER, 2);
1081 int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value)
1083 unsigned char buf[2];
1086 if (pdev->type < 730) {
1092 ret = RecvControlMsg(GET_STATUS_CTL, LED_FORMATTER, 2);
1095 *on_value = buf[0] * 100;
1096 *off_value = buf[1] * 100;
1100 static inline int pwc_set_contour(struct pwc_device *pdev, int contour)
1106 buf = 0xff; /* auto contour on */
1108 buf = 0x0; /* auto contour off */
1109 ret = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
1111 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1112 AUTO_CONTOUR_FORMATTER,
1120 if (contour > 0xffff)
1123 buf = (contour >> 10); /* contour preset is [0..3f] */
1124 ret = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
1126 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1127 PRESET_CONTOUR_FORMATTER,
1135 static inline int pwc_get_contour(struct pwc_device *pdev, int *contour)
1140 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
1142 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1143 AUTO_CONTOUR_FORMATTER,
1150 /* auto mode off, query current preset value */
1151 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
1153 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1154 PRESET_CONTOUR_FORMATTER,
1159 *contour = (buf << 10);
1167 static inline int pwc_set_backlight(struct pwc_device *pdev, int backlight)
1175 return usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0),
1177 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1178 BACK_LIGHT_COMPENSATION_FORMATTER,
1183 static inline int pwc_get_backlight(struct pwc_device *pdev)
1188 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
1190 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1191 BACK_LIGHT_COMPENSATION_FORMATTER,
1200 static inline int pwc_set_flicker(struct pwc_device *pdev, int flicker)
1208 return SendControlMsg(SET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);
1211 static inline int pwc_get_flicker(struct pwc_device *pdev)
1216 ret = RecvControlMsg(GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);
1223 static inline int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise)
1232 return SendControlMsg(SET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);
1235 static inline int pwc_get_dynamic_noise(struct pwc_device *pdev)
1240 ret = RecvControlMsg(GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);
1247 int pwc_get_cmos_sensor(struct pwc_device *pdev)
1250 int ret = -1, request;
1252 if (pdev->type < 675)
1253 request = SENSOR_TYPE_FORMATTER1;
1254 else if (pdev->type < 730)
1255 return -1; /* The Vesta series doesn't have this call */
1257 request = SENSOR_TYPE_FORMATTER2;
1259 ret = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0),
1261 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1267 if (pdev->type < 675)
1274 /* End of Add-Ons */
1275 /* ************************************************* */
1277 int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1282 case VIDIOCPWCRUSER:
1284 if (pwc_restore_user(pdev))
1289 case VIDIOCPWCSUSER:
1291 if (pwc_save_user(pdev))
1296 case VIDIOCPWCFACTORY:
1298 if (pwc_restore_factory(pdev))
1303 case VIDIOCPWCSCQUAL:
1307 if (*qual < 0 || *qual > 3)
1310 ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, *qual, pdev->vsnapshot);
1312 pdev->vcompression = *qual;
1316 case VIDIOCPWCGCQUAL:
1320 *qual = pdev->vcompression;
1324 case VIDIOCPWCPROBE:
1326 struct pwc_probe *probe = arg;
1328 strcpy(probe->name, pdev->vdev.name);
1329 probe->type = pdev->type;
1337 if (pwc_set_agc(pdev, *agc < 0 ? 1 : 0, *agc))
1346 if (pwc_get_agc(pdev, agc))
1351 case VIDIOCPWCSSHUTTER:
1353 int *shutter_speed = arg;
1355 ret = pwc_set_shutter_speed(pdev, *shutter_speed < 0 ? 1 : 0, *shutter_speed);
1361 struct pwc_whitebalance *wb = arg;
1363 ret = pwc_set_awb(pdev, wb->mode);
1364 if (ret >= 0 && wb->mode == PWC_WB_MANUAL) {
1365 pwc_set_red_gain(pdev, wb->manual_red);
1366 pwc_set_blue_gain(pdev, wb->manual_blue);
1373 struct pwc_whitebalance *wb = arg;
1375 memset(wb, 0, sizeof(*wb));
1376 wb->mode = pwc_get_awb(pdev);
1380 if (wb->mode == PWC_WB_MANUAL) {
1381 wb->manual_red = pwc_get_red_gain(pdev);
1382 wb->manual_blue = pwc_get_blue_gain(pdev);
1384 if (wb->mode == PWC_WB_AUTO) {
1385 wb->read_red = pwc_read_red_gain(pdev);
1386 wb->read_blue = pwc_read_blue_gain(pdev);
1392 case VIDIOCPWCSAWBSPEED:
1394 struct pwc_wb_speed *wbs = arg;
1396 if (wbs->control_speed > 0) {
1397 ret = pwc_set_wb_speed(pdev, wbs->control_speed);
1399 if (wbs->control_delay > 0) {
1400 ret = pwc_set_wb_delay(pdev, wbs->control_delay);
1405 case VIDIOCPWCGAWBSPEED:
1407 struct pwc_wb_speed *wbs = arg;
1409 ret = pwc_get_wb_speed(pdev);
1412 wbs->control_speed = ret;
1413 ret = pwc_get_wb_delay(pdev);
1416 wbs->control_delay = ret;
1422 struct pwc_leds *leds = arg;
1424 ret = pwc_set_leds(pdev, leds->led_on, leds->led_off);
1431 struct pwc_leds *leds = arg;
1433 ret = pwc_get_leds(pdev, &leds->led_on, &leds->led_off);
1437 case VIDIOCPWCSCONTOUR:
1441 ret = pwc_set_contour(pdev, *contour);
1445 case VIDIOCPWCGCONTOUR:
1449 ret = pwc_get_contour(pdev, contour);
1453 case VIDIOCPWCSBACKLIGHT:
1455 int *backlight = arg;
1457 ret = pwc_set_backlight(pdev, *backlight);
1461 case VIDIOCPWCGBACKLIGHT:
1463 int *backlight = arg;
1465 ret = pwc_get_backlight(pdev);
1471 case VIDIOCPWCSFLICKER:
1475 ret = pwc_set_flicker(pdev, *flicker);
1479 case VIDIOCPWCGFLICKER:
1483 ret = pwc_get_flicker(pdev);
1489 case VIDIOCPWCSDYNNOISE:
1491 int *dynnoise = arg;
1493 ret = pwc_set_dynamic_noise(pdev, *dynnoise);
1497 case VIDIOCPWCGDYNNOISE:
1499 int *dynnoise = arg;
1501 ret = pwc_get_dynamic_noise(pdev);
1508 case VIDIOCPWCGREALSIZE:
1510 struct pwc_imagesize *size = arg;
1512 size->width = pdev->image.x;
1513 size->height = pdev->image.y;