Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 5 | (C) 2004-2006 Luc Saillard (luc@saillard.org) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 34 | 2001/08/03 Alvarado Added methods for changing white balance and |
| 35 | red/green gains |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
| 37 | |
| 38 | /* Control functions for the cam; brightness, contrast, video mode, etc. */ |
| 39 | |
| 40 | #ifdef __KERNEL__ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 41 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #endif |
| 43 | #include <asm/errno.h> |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include "pwc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include "pwc-uncompress.h" |
| 47 | #include "pwc-kiara.h" |
| 48 | #include "pwc-timon.h" |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 49 | #include "pwc-dec1.h" |
| 50 | #include "pwc-dec23.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 61 | #define GET_XX_CTL 0x09 |
| 62 | #define SET_XX_CTL 0x0A |
| 63 | #define GET_XY_CTL 0x0B |
| 64 | #define SET_XY_CTL 0x0C |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define SET_MPT_CTL 0x0D |
| 66 | #define GET_MPT_CTL 0x0E |
| 67 | |
| 68 | /* Selectors for the Luminance controls [GS]ET_LUM_CTL */ |
| 69 | #define AGC_MODE_FORMATTER 0x2000 |
| 70 | #define PRESET_AGC_FORMATTER 0x2100 |
| 71 | #define SHUTTER_MODE_FORMATTER 0x2200 |
| 72 | #define PRESET_SHUTTER_FORMATTER 0x2300 |
| 73 | #define PRESET_CONTOUR_FORMATTER 0x2400 |
| 74 | #define AUTO_CONTOUR_FORMATTER 0x2500 |
| 75 | #define BACK_LIGHT_COMPENSATION_FORMATTER 0x2600 |
| 76 | #define CONTRAST_FORMATTER 0x2700 |
| 77 | #define DYNAMIC_NOISE_CONTROL_FORMATTER 0x2800 |
| 78 | #define FLICKERLESS_MODE_FORMATTER 0x2900 |
| 79 | #define AE_CONTROL_SPEED 0x2A00 |
| 80 | #define BRIGHTNESS_FORMATTER 0x2B00 |
| 81 | #define GAMMA_FORMATTER 0x2C00 |
| 82 | |
| 83 | /* Selectors for the Chrominance controls [GS]ET_CHROM_CTL */ |
| 84 | #define WB_MODE_FORMATTER 0x1000 |
| 85 | #define AWB_CONTROL_SPEED_FORMATTER 0x1100 |
| 86 | #define AWB_CONTROL_DELAY_FORMATTER 0x1200 |
| 87 | #define PRESET_MANUAL_RED_GAIN_FORMATTER 0x1300 |
| 88 | #define PRESET_MANUAL_BLUE_GAIN_FORMATTER 0x1400 |
| 89 | #define COLOUR_MODE_FORMATTER 0x1500 |
| 90 | #define SATURATION_MODE_FORMATTER1 0x1600 |
| 91 | #define SATURATION_MODE_FORMATTER2 0x1700 |
| 92 | |
| 93 | /* Selectors for the Status controls [GS]ET_STATUS_CTL */ |
| 94 | #define SAVE_USER_DEFAULTS_FORMATTER 0x0200 |
| 95 | #define RESTORE_USER_DEFAULTS_FORMATTER 0x0300 |
| 96 | #define RESTORE_FACTORY_DEFAULTS_FORMATTER 0x0400 |
| 97 | #define READ_AGC_FORMATTER 0x0500 |
| 98 | #define READ_SHUTTER_FORMATTER 0x0600 |
| 99 | #define READ_RED_GAIN_FORMATTER 0x0700 |
| 100 | #define READ_BLUE_GAIN_FORMATTER 0x0800 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 101 | #define GET_STATUS_B00 0x0B00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #define SENSOR_TYPE_FORMATTER1 0x0C00 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 103 | #define GET_STATUS_3000 0x3000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | #define READ_RAW_Y_MEAN_FORMATTER 0x3100 |
| 105 | #define SET_POWER_SAVE_MODE_FORMATTER 0x3200 |
| 106 | #define MIRROR_IMAGE_FORMATTER 0x3300 |
| 107 | #define LED_FORMATTER 0x3400 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 108 | #define LOWLIGHT 0x3500 |
| 109 | #define GET_STATUS_3600 0x3600 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #define SENSOR_TYPE_FORMATTER2 0x3700 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 111 | #define GET_STATUS_3800 0x3800 |
| 112 | #define GET_STATUS_4000 0x4000 |
| 113 | #define GET_STATUS_4100 0x4100 /* Get */ |
| 114 | #define CTL_STATUS_4200 0x4200 /* [GS] 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | /* Formatters for the Video Endpoint controls [GS]ET_EP_STREAM_CTL */ |
| 117 | #define VIDEO_OUTPUT_CONTROL_FORMATTER 0x0100 |
| 118 | |
| 119 | /* Formatters for the motorized pan & tilt [GS]ET_MPT_CTL */ |
| 120 | #define PT_RELATIVE_CONTROL_FORMATTER 0x01 |
| 121 | #define PT_RESET_CONTROL_FORMATTER 0x02 |
| 122 | #define PT_STATUS_FORMATTER 0x03 |
| 123 | |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 124 | static const char *size2name[PSZ_MAX] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
| 126 | "subQCIF", |
| 127 | "QSIF", |
| 128 | "QCIF", |
| 129 | "SIF", |
| 130 | "CIF", |
| 131 | "VGA", |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 132 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /********/ |
| 135 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 136 | /* Entries for the Nala (645/646) camera; the Nala doesn't have compression |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | preferences, so you either get compressed or non-compressed streams. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | An alternate value of 0 means this mode is not available at all. |
| 140 | */ |
| 141 | |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 142 | #define PWC_FPS_MAX_NALA 8 |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | struct Nala_table_entry { |
| 145 | char alternate; /* USB alternate setting */ |
| 146 | int compressed; /* Compressed yes/no */ |
| 147 | |
| 148 | unsigned char mode[3]; /* precomputed mode table */ |
| 149 | }; |
| 150 | |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 151 | static unsigned int Nala_fps_vector[PWC_FPS_MAX_NALA] = { 4, 5, 7, 10, 12, 15, 20, 24 }; |
| 152 | |
| 153 | static struct Nala_table_entry Nala_table[PSZ_MAX][PWC_FPS_MAX_NALA] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | #include "pwc-nala.h" |
| 156 | }; |
| 157 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 158 | static void pwc_set_image_buffer_size(struct pwc_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | /****************************************************************************/ |
| 161 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 162 | static int _send_control_msg(struct pwc_device *pdev, |
| 163 | u8 request, u16 value, int index, void *buf, int buflen, int timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 165 | int rc; |
| 166 | void *kbuf = NULL; |
| 167 | |
| 168 | if (buflen) { |
| 169 | kbuf = kmalloc(buflen, GFP_KERNEL); /* not allowed on stack */ |
| 170 | if (kbuf == NULL) |
| 171 | return -ENOMEM; |
| 172 | memcpy(kbuf, buf, buflen); |
| 173 | } |
| 174 | |
| 175 | rc = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0), |
| 176 | request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 178 | value, |
| 179 | index, |
| 180 | kbuf, buflen, timeout); |
| 181 | |
| 182 | kfree(kbuf); |
| 183 | return rc; |
| 184 | } |
| 185 | |
| 186 | static int recv_control_msg(struct pwc_device *pdev, |
| 187 | u8 request, u16 value, void *buf, int buflen) |
| 188 | { |
| 189 | int rc; |
| 190 | void *kbuf = kmalloc(buflen, GFP_KERNEL); /* not allowed on stack */ |
| 191 | |
| 192 | if (kbuf == NULL) |
| 193 | return -ENOMEM; |
| 194 | |
| 195 | rc = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0), |
| 196 | request, |
| 197 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 198 | value, |
| 199 | pdev->vcinterface, |
| 200 | kbuf, buflen, 500); |
| 201 | memcpy(buf, kbuf, buflen); |
| 202 | kfree(kbuf); |
| 203 | return rc; |
| 204 | } |
| 205 | |
| 206 | static inline int send_video_command(struct pwc_device *pdev, |
| 207 | int index, void *buf, int buflen) |
| 208 | { |
| 209 | return _send_control_msg(pdev, |
| 210 | SET_EP_STREAM_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | VIDEO_OUTPUT_CONTROL_FORMATTER, |
| 212 | index, |
| 213 | buf, buflen, 1000); |
| 214 | } |
| 215 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 216 | static inline int send_control_msg(struct pwc_device *pdev, |
| 217 | u8 request, u16 value, void *buf, int buflen) |
| 218 | { |
| 219 | return _send_control_msg(pdev, |
| 220 | request, value, pdev->vcinterface, buf, buflen, 500); |
| 221 | } |
| 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 225 | static int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | unsigned char buf[3]; |
| 228 | int ret, fps; |
| 229 | struct Nala_table_entry *pEntry; |
| 230 | int frames2frames[31] = |
| 231 | { /* closest match of framerate */ |
| 232 | 0, 0, 0, 0, 4, /* 0-4 */ |
| 233 | 5, 5, 7, 7, 10, /* 5-9 */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 234 | 10, 10, 12, 12, 15, /* 10-14 */ |
| 235 | 15, 15, 15, 20, 20, /* 15-19 */ |
| 236 | 20, 20, 20, 24, 24, /* 20-24 */ |
| 237 | 24, 24, 24, 24, 24, /* 25-29 */ |
| 238 | 24 /* 30 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | }; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 240 | int frames2table[31] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { 0, 0, 0, 0, 0, /* 0-4 */ |
| 242 | 1, 1, 1, 2, 2, /* 5-9 */ |
| 243 | 3, 3, 4, 4, 4, /* 10-14 */ |
| 244 | 5, 5, 5, 5, 5, /* 15-19 */ |
| 245 | 6, 6, 6, 6, 7, /* 20-24 */ |
| 246 | 7, 7, 7, 7, 7, /* 25-29 */ |
| 247 | 7 /* 30 */ |
| 248 | }; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25) |
| 251 | return -EINVAL; |
| 252 | frames = frames2frames[frames]; |
| 253 | fps = frames2table[frames]; |
| 254 | pEntry = &Nala_table[size][fps]; |
| 255 | if (pEntry->alternate == 0) |
| 256 | return -EINVAL; |
| 257 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 258 | memcpy(buf, pEntry->mode, 3); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 259 | ret = send_video_command(pdev, pdev->vendpoint, buf, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (ret < 0) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 261 | PWC_DEBUG_MODULE("Failed to send video command... %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return ret; |
| 263 | } |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 264 | if (pEntry->compressed && pdev->pixfmt == V4L2_PIX_FMT_YUV420) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 265 | pwc_dec1_init(pdev->type, pdev->release, buf, pdev->decompress_data); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | pdev->cmd_len = 3; |
| 268 | memcpy(pdev->cmd_buf, buf, 3); |
| 269 | |
| 270 | /* Set various parameters */ |
| 271 | pdev->vframes = frames; |
| 272 | pdev->vsize = size; |
| 273 | pdev->valternate = pEntry->alternate; |
| 274 | pdev->image = pwc_image_sizes[size]; |
| 275 | pdev->frame_size = (pdev->image.x * pdev->image.y * 3) / 2; |
| 276 | if (pEntry->compressed) { |
| 277 | if (pdev->release < 5) { /* 4 fold compression */ |
| 278 | pdev->vbandlength = 528; |
| 279 | pdev->frame_size /= 4; |
| 280 | } |
| 281 | else { |
| 282 | pdev->vbandlength = 704; |
| 283 | pdev->frame_size /= 3; |
| 284 | } |
| 285 | } |
| 286 | else |
| 287 | pdev->vbandlength = 0; |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 292 | static int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames, int compression, int snapshot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
| 294 | unsigned char buf[13]; |
| 295 | const struct Timon_table_entry *pChoose; |
| 296 | int ret, fps; |
| 297 | |
| 298 | if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) |
| 299 | return -EINVAL; |
| 300 | if (size == PSZ_VGA && frames > 15) |
| 301 | return -EINVAL; |
| 302 | fps = (frames / 5) - 1; |
| 303 | |
| 304 | /* Find a supported framerate with progressively higher compression ratios |
| 305 | if the preferred ratio is not available. |
| 306 | */ |
| 307 | pChoose = NULL; |
| 308 | while (compression <= 3) { |
| 309 | pChoose = &Timon_table[size][fps][compression]; |
| 310 | if (pChoose->alternate != 0) |
| 311 | break; |
| 312 | compression++; |
| 313 | } |
| 314 | if (pChoose == NULL || pChoose->alternate == 0) |
| 315 | return -ENOENT; /* Not supported. */ |
| 316 | |
| 317 | memcpy(buf, pChoose->mode, 13); |
| 318 | if (snapshot) |
| 319 | buf[0] |= 0x80; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 320 | ret = send_video_command(pdev, pdev->vendpoint, buf, 13); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | if (ret < 0) |
| 322 | return ret; |
| 323 | |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 324 | if (pChoose->bandlength > 0 && pdev->pixfmt == V4L2_PIX_FMT_YUV420) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 325 | pwc_dec23_init(pdev, pdev->type, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | pdev->cmd_len = 13; |
| 328 | memcpy(pdev->cmd_buf, buf, 13); |
| 329 | |
| 330 | /* Set various parameters */ |
| 331 | pdev->vframes = frames; |
| 332 | pdev->vsize = size; |
| 333 | pdev->vsnapshot = snapshot; |
| 334 | pdev->valternate = pChoose->alternate; |
| 335 | pdev->image = pwc_image_sizes[size]; |
| 336 | pdev->vbandlength = pChoose->bandlength; |
| 337 | if (pChoose->bandlength > 0) |
| 338 | pdev->frame_size = (pChoose->bandlength * pdev->image.y) / 4; |
| 339 | else |
| 340 | pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8; |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 345 | static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames, int compression, int snapshot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
| 347 | const struct Kiara_table_entry *pChoose = NULL; |
| 348 | int fps, ret; |
| 349 | unsigned char buf[12]; |
| 350 | struct Kiara_table_entry RawEntry = {6, 773, 1272, {0xAD, 0xF4, 0x10, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}}; |
| 351 | |
| 352 | if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) |
| 353 | return -EINVAL; |
| 354 | if (size == PSZ_VGA && frames > 15) |
| 355 | return -EINVAL; |
| 356 | fps = (frames / 5) - 1; |
| 357 | |
| 358 | /* special case: VGA @ 5 fps and snapshot is raw bayer mode */ |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 359 | if (size == PSZ_VGA && frames == 5 && snapshot && pdev->pixfmt != V4L2_PIX_FMT_YUV420) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 361 | /* Only available in case the raw palette is selected or |
| 362 | we have the decompressor available. This mode is |
| 363 | only available in compressed form |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 365 | PWC_DEBUG_SIZE("Choosing VGA/5 BAYER mode.\n"); |
| 366 | pChoose = &RawEntry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | else |
| 369 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 370 | /* Find a supported framerate with progressively higher compression ratios |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if the preferred ratio is not available. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 372 | Skip this step when using RAW modes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 374 | snapshot = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | while (compression <= 3) { |
| 376 | pChoose = &Kiara_table[size][fps][compression]; |
| 377 | if (pChoose->alternate != 0) |
| 378 | break; |
| 379 | compression++; |
| 380 | } |
| 381 | } |
| 382 | if (pChoose == NULL || pChoose->alternate == 0) |
| 383 | return -ENOENT; /* Not supported. */ |
| 384 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 385 | PWC_TRACE("Using alternate setting %d.\n", pChoose->alternate); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* usb_control_msg won't take staticly allocated arrays as argument?? */ |
| 388 | memcpy(buf, pChoose->mode, 12); |
| 389 | if (snapshot) |
| 390 | buf[0] |= 0x80; |
| 391 | |
| 392 | /* Firmware bug: video endpoint is 5, but commands are sent to endpoint 4 */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 393 | ret = send_video_command(pdev, 4 /* pdev->vendpoint */, buf, 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | if (ret < 0) |
| 395 | return ret; |
| 396 | |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 397 | if (pChoose->bandlength > 0 && pdev->pixfmt == V4L2_PIX_FMT_YUV420) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 398 | pwc_dec23_init(pdev, pdev->type, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | pdev->cmd_len = 12; |
| 401 | memcpy(pdev->cmd_buf, buf, 12); |
| 402 | /* All set and go */ |
| 403 | pdev->vframes = frames; |
| 404 | pdev->vsize = size; |
| 405 | pdev->vsnapshot = snapshot; |
| 406 | pdev->valternate = pChoose->alternate; |
| 407 | pdev->image = pwc_image_sizes[size]; |
| 408 | pdev->vbandlength = pChoose->bandlength; |
| 409 | if (pdev->vbandlength > 0) |
| 410 | pdev->frame_size = (pdev->vbandlength * pdev->image.y) / 4; |
| 411 | else |
| 412 | pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 413 | PWC_TRACE("frame_size=%d, vframes=%d, vsize=%d, vsnapshot=%d, vbandlength=%d\n", |
| 414 | pdev->frame_size,pdev->vframes,pdev->vsize,pdev->vsnapshot,pdev->vbandlength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | |
| 419 | |
| 420 | /** |
| 421 | @pdev: device structure |
| 422 | @width: viewport width |
| 423 | @height: viewport height |
| 424 | @frame: framerate, in fps |
| 425 | @compression: preferred compression ratio |
| 426 | @snapshot: snapshot mode or streaming |
| 427 | */ |
| 428 | int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot) |
| 429 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 430 | int ret, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 432 | PWC_DEBUG_FLOW("set_video_mode(%dx%d @ %d, pixfmt %08x).\n", width, height, frames, pdev->pixfmt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | size = pwc_decode_size(pdev, width, height); |
| 434 | if (size < 0) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 435 | PWC_DEBUG_MODULE("Could not find suitable size.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | return -ERANGE; |
| 437 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 438 | PWC_TRACE("decode_size = %d.\n", size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 440 | if (DEVICE_USE_CODEC1(pdev->type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | ret = set_video_mode_Nala(pdev, size, frames); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 443 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | ret = set_video_mode_Kiara(pdev, size, frames, compression, snapshot); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 445 | |
| 446 | } else { |
| 447 | ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | if (ret < 0) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 450 | PWC_ERROR("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return ret; |
| 452 | } |
| 453 | pdev->view.x = width; |
| 454 | pdev->view.y = height; |
| 455 | pdev->frame_total_size = pdev->frame_size + pdev->frame_header_size + pdev->frame_trailer_size; |
| 456 | pwc_set_image_buffer_size(pdev); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 457 | PWC_DEBUG_SIZE("Set viewport to %dx%d, image size is %dx%d.\n", width, height, pwc_image_sizes[size].x, pwc_image_sizes[size].y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 461 | static unsigned int pwc_get_fps_Nala(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 462 | { |
| 463 | unsigned int i; |
| 464 | |
| 465 | for (i = 0; i < PWC_FPS_MAX_NALA; i++) { |
| 466 | if (Nala_table[size][i].alternate) { |
| 467 | if (index--==0) return Nala_fps_vector[i]; |
| 468 | } |
| 469 | } |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static unsigned int pwc_get_fps_Kiara(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 474 | { |
| 475 | unsigned int i; |
| 476 | |
| 477 | for (i = 0; i < PWC_FPS_MAX_KIARA; i++) { |
| 478 | if (Kiara_table[size][i][3].alternate) { |
| 479 | if (index--==0) return Kiara_fps_vector[i]; |
| 480 | } |
| 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static unsigned int pwc_get_fps_Timon(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 486 | { |
| 487 | unsigned int i; |
| 488 | |
| 489 | for (i=0; i < PWC_FPS_MAX_TIMON; i++) { |
| 490 | if (Timon_table[size][i][3].alternate) { |
| 491 | if (index--==0) return Timon_fps_vector[i]; |
| 492 | } |
| 493 | } |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | unsigned int pwc_get_fps(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 498 | { |
| 499 | unsigned int ret; |
| 500 | |
| 501 | if (DEVICE_USE_CODEC1(pdev->type)) { |
| 502 | ret = pwc_get_fps_Nala(pdev, index, size); |
| 503 | |
| 504 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
| 505 | ret = pwc_get_fps_Kiara(pdev, index, size); |
| 506 | |
| 507 | } else { |
| 508 | ret = pwc_get_fps_Timon(pdev, index, size); |
| 509 | } |
| 510 | |
| 511 | return ret; |
| 512 | } |
| 513 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 514 | static void pwc_set_image_buffer_size(struct pwc_device *pdev) |
| 515 | { |
Hans de Goede | 885fe18 | 2011-06-06 15:33:44 -0300 | [diff] [blame] | 516 | int factor = 0; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 517 | |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 518 | /* for V4L2_PIX_FMT_YUV420 */ |
| 519 | switch (pdev->pixfmt) { |
| 520 | case V4L2_PIX_FMT_YUV420: |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 521 | factor = 6; |
| 522 | break; |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 523 | case V4L2_PIX_FMT_PWC1: |
| 524 | case V4L2_PIX_FMT_PWC2: |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 525 | factor = 6; /* can be uncompressed YUV420P */ |
| 526 | break; |
| 527 | } |
| 528 | |
| 529 | /* Set sizes in bytes */ |
| 530 | pdev->image.size = pdev->image.x * pdev->image.y * factor / 4; |
| 531 | pdev->view.size = pdev->view.x * pdev->view.y * factor / 4; |
| 532 | |
| 533 | /* Align offset, or you'll get some very weird results in |
| 534 | YUV420 mode... x must be multiple of 4 (to get the Y's in |
| 535 | place), and y even (or you'll mixup U & V). This is less of a |
| 536 | problem for YUV420P. |
| 537 | */ |
| 538 | pdev->offset.x = ((pdev->view.x - pdev->image.x) / 2) & 0xFFFC; |
| 539 | pdev->offset.y = ((pdev->view.y - pdev->image.y) / 2) & 0xFFFE; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 540 | } |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* BRIGHTNESS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | int pwc_get_brightness(struct pwc_device *pdev) |
| 544 | { |
| 545 | char buf; |
| 546 | int ret; |
| 547 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 548 | ret = recv_control_msg(pdev, |
| 549 | GET_LUM_CTL, BRIGHTNESS_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | if (ret < 0) |
| 551 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 552 | return buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | int pwc_set_brightness(struct pwc_device *pdev, int value) |
| 556 | { |
| 557 | char buf; |
| 558 | |
| 559 | if (value < 0) |
| 560 | value = 0; |
| 561 | if (value > 0xffff) |
| 562 | value = 0xffff; |
| 563 | buf = (value >> 9) & 0x7f; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 564 | return send_control_msg(pdev, |
| 565 | SET_LUM_CTL, BRIGHTNESS_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* CONTRAST */ |
| 569 | |
| 570 | int pwc_get_contrast(struct pwc_device *pdev) |
| 571 | { |
| 572 | char buf; |
| 573 | int ret; |
| 574 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 575 | ret = recv_control_msg(pdev, |
| 576 | GET_LUM_CTL, CONTRAST_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | if (ret < 0) |
| 578 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 579 | return buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | int pwc_set_contrast(struct pwc_device *pdev, int value) |
| 583 | { |
| 584 | char buf; |
| 585 | |
| 586 | if (value < 0) |
| 587 | value = 0; |
| 588 | if (value > 0xffff) |
| 589 | value = 0xffff; |
| 590 | buf = (value >> 10) & 0x3f; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 591 | return send_control_msg(pdev, |
| 592 | SET_LUM_CTL, CONTRAST_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* GAMMA */ |
| 596 | |
| 597 | int pwc_get_gamma(struct pwc_device *pdev) |
| 598 | { |
| 599 | char buf; |
| 600 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 601 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 602 | ret = recv_control_msg(pdev, |
| 603 | GET_LUM_CTL, GAMMA_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | if (ret < 0) |
| 605 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 606 | return buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | int pwc_set_gamma(struct pwc_device *pdev, int value) |
| 610 | { |
| 611 | char buf; |
| 612 | |
| 613 | if (value < 0) |
| 614 | value = 0; |
| 615 | if (value > 0xffff) |
| 616 | value = 0xffff; |
| 617 | buf = (value >> 11) & 0x1f; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 618 | return send_control_msg(pdev, |
| 619 | SET_LUM_CTL, GAMMA_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | |
| 623 | /* SATURATION */ |
| 624 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 625 | /* return a value between [-100 , 100] */ |
| 626 | int pwc_get_saturation(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
| 628 | char buf; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 629 | int ret, saturation_register; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | if (pdev->type < 675) |
| 632 | return -EINVAL; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 633 | if (pdev->type < 730) |
| 634 | saturation_register = SATURATION_MODE_FORMATTER2; |
| 635 | else |
| 636 | saturation_register = SATURATION_MODE_FORMATTER1; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 637 | ret = recv_control_msg(pdev, |
| 638 | GET_CHROM_CTL, saturation_register, &buf, sizeof(buf)); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 639 | if (ret < 0) |
| 640 | return ret; |
| 641 | *value = (signed)buf; |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | /* @param value saturation color between [-100 , 100] */ |
| 646 | int pwc_set_saturation(struct pwc_device *pdev, int value) |
| 647 | { |
| 648 | char buf; |
| 649 | int saturation_register; |
| 650 | |
| 651 | if (pdev->type < 675) |
| 652 | return -EINVAL; |
| 653 | if (value < -100) |
| 654 | value = -100; |
| 655 | if (value > 100) |
| 656 | value = 100; |
| 657 | if (pdev->type < 730) |
| 658 | saturation_register = SATURATION_MODE_FORMATTER2; |
| 659 | else |
| 660 | saturation_register = SATURATION_MODE_FORMATTER1; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 661 | return send_control_msg(pdev, |
| 662 | SET_CHROM_CTL, saturation_register, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | /* AGC */ |
| 666 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 667 | int pwc_set_agc(struct pwc_device *pdev, int mode, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
| 669 | char buf; |
| 670 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | if (mode) |
| 673 | buf = 0x0; /* auto */ |
| 674 | else |
| 675 | buf = 0xff; /* fixed */ |
| 676 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 677 | ret = send_control_msg(pdev, |
| 678 | SET_LUM_CTL, AGC_MODE_FORMATTER, &buf, sizeof(buf)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | if (!mode && ret >= 0) { |
| 681 | if (value < 0) |
| 682 | value = 0; |
| 683 | if (value > 0xffff) |
| 684 | value = 0xffff; |
| 685 | buf = (value >> 10) & 0x3F; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 686 | ret = send_control_msg(pdev, |
| 687 | SET_LUM_CTL, PRESET_AGC_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | if (ret < 0) |
| 690 | return ret; |
| 691 | return 0; |
| 692 | } |
| 693 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 694 | int pwc_get_agc(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | { |
| 696 | unsigned char buf; |
| 697 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 698 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 699 | ret = recv_control_msg(pdev, |
| 700 | GET_LUM_CTL, AGC_MODE_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | if (ret < 0) |
| 702 | return ret; |
| 703 | |
| 704 | if (buf != 0) { /* fixed */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 705 | ret = recv_control_msg(pdev, |
| 706 | GET_LUM_CTL, PRESET_AGC_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | if (ret < 0) |
| 708 | return ret; |
| 709 | if (buf > 0x3F) |
| 710 | buf = 0x3F; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 711 | *value = (buf << 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | else { /* auto */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 714 | ret = recv_control_msg(pdev, |
| 715 | GET_STATUS_CTL, READ_AGC_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | if (ret < 0) |
| 717 | return ret; |
| 718 | /* Gah... this value ranges from 0x00 ... 0x9F */ |
| 719 | if (buf > 0x9F) |
| 720 | buf = 0x9F; |
| 721 | *value = -(48 + buf * 409); |
| 722 | } |
| 723 | |
| 724 | return 0; |
| 725 | } |
| 726 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 727 | int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
| 729 | char buf[2]; |
| 730 | int speed, ret; |
| 731 | |
| 732 | |
| 733 | if (mode) |
| 734 | buf[0] = 0x0; /* auto */ |
| 735 | else |
| 736 | buf[0] = 0xff; /* fixed */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 737 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 738 | ret = send_control_msg(pdev, |
Martin Fuzzey | 53f6860 | 2010-02-11 10:50:31 -0300 | [diff] [blame] | 739 | SET_LUM_CTL, SHUTTER_MODE_FORMATTER, &buf, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | if (!mode && ret >= 0) { |
| 742 | if (value < 0) |
| 743 | value = 0; |
| 744 | if (value > 0xffff) |
| 745 | value = 0xffff; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 746 | |
| 747 | if (DEVICE_USE_CODEC2(pdev->type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | /* speed ranges from 0x0 to 0x290 (656) */ |
| 749 | speed = (value / 100); |
| 750 | buf[1] = speed >> 8; |
| 751 | buf[0] = speed & 0xff; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 752 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | /* speed seems to range from 0x0 to 0xff */ |
| 754 | buf[1] = 0; |
| 755 | buf[0] = value >> 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 758 | ret = send_control_msg(pdev, |
| 759 | SET_LUM_CTL, PRESET_SHUTTER_FORMATTER, |
| 760 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | return ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 765 | /* This function is not exported to v4l1, so output values between 0 -> 256 */ |
| 766 | int pwc_get_shutter_speed(struct pwc_device *pdev, int *value) |
| 767 | { |
| 768 | unsigned char buf[2]; |
| 769 | int ret; |
| 770 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 771 | ret = recv_control_msg(pdev, |
| 772 | GET_STATUS_CTL, READ_SHUTTER_FORMATTER, &buf, sizeof(buf)); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 773 | if (ret < 0) |
| 774 | return ret; |
| 775 | *value = buf[0] + (buf[1] << 8); |
| 776 | if (DEVICE_USE_CODEC2(pdev->type)) { |
| 777 | /* speed ranges from 0x0 to 0x290 (656) */ |
| 778 | *value *= 256/656; |
| 779 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
| 780 | /* speed seems to range from 0x0 to 0xff */ |
| 781 | } |
| 782 | return 0; |
| 783 | } |
| 784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | /* POWER */ |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 786 | void pwc_camera_power(struct pwc_device *pdev, int power) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | { |
| 788 | char buf; |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 789 | int r; |
| 790 | |
| 791 | if (!pdev->power_save) |
| 792 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6)) |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 795 | return; /* Not supported by Nala or Timon < release 6 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
| 797 | if (power) |
| 798 | buf = 0x00; /* active */ |
| 799 | else |
| 800 | buf = 0xFF; /* power save */ |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 801 | r = send_control_msg(pdev, |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 802 | SET_STATUS_CTL, SET_POWER_SAVE_MODE_FORMATTER, |
| 803 | &buf, sizeof(buf)); |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 804 | |
| 805 | if (r < 0) |
| 806 | PWC_ERROR("Failed to power %s camera (%d)\n", |
| 807 | power ? "on" : "off", r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | /* private calls */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 811 | int pwc_restore_user(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 813 | return send_control_msg(pdev, |
| 814 | SET_STATUS_CTL, RESTORE_USER_DEFAULTS_FORMATTER, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 817 | int pwc_save_user(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 819 | return send_control_msg(pdev, |
| 820 | SET_STATUS_CTL, SAVE_USER_DEFAULTS_FORMATTER, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 823 | int pwc_restore_factory(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 825 | return send_control_msg(pdev, |
| 826 | SET_STATUS_CTL, RESTORE_FACTORY_DEFAULTS_FORMATTER, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /* ************************************************* */ |
| 830 | /* Patch by Alvarado: (not in the original version */ |
| 831 | |
| 832 | /* |
| 833 | * the camera recognizes modes from 0 to 4: |
| 834 | * |
| 835 | * 00: indoor (incandescant lighting) |
| 836 | * 01: outdoor (sunlight) |
| 837 | * 02: fluorescent lighting |
| 838 | * 03: manual |
| 839 | * 04: auto |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 840 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 841 | int pwc_set_awb(struct pwc_device *pdev, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
| 843 | char buf; |
| 844 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | if (mode < 0) |
| 847 | mode = 0; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | if (mode > 4) |
| 850 | mode = 4; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | buf = mode & 0x07; /* just the lowest three bits */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 853 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 854 | ret = send_control_msg(pdev, |
| 855 | SET_CHROM_CTL, WB_MODE_FORMATTER, &buf, sizeof(buf)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | if (ret < 0) |
| 858 | return ret; |
| 859 | return 0; |
| 860 | } |
| 861 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 862 | int pwc_get_awb(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | { |
| 864 | unsigned char buf; |
| 865 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 866 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 867 | ret = recv_control_msg(pdev, |
| 868 | GET_CHROM_CTL, WB_MODE_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 870 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | return ret; |
| 872 | return buf; |
| 873 | } |
| 874 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 875 | int pwc_set_red_gain(struct pwc_device *pdev, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 877 | unsigned char buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
| 879 | if (value < 0) |
| 880 | value = 0; |
| 881 | if (value > 0xffff) |
| 882 | value = 0xffff; |
| 883 | /* only the msb is considered */ |
| 884 | buf = value >> 8; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 885 | return send_control_msg(pdev, |
| 886 | SET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, |
| 887 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 890 | int pwc_get_red_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { |
| 892 | unsigned char buf; |
| 893 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 894 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 895 | ret = recv_control_msg(pdev, |
| 896 | GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, |
| 897 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | if (ret < 0) |
| 899 | return ret; |
| 900 | *value = buf << 8; |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 905 | int pwc_set_blue_gain(struct pwc_device *pdev, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
| 907 | unsigned char buf; |
| 908 | |
| 909 | if (value < 0) |
| 910 | value = 0; |
| 911 | if (value > 0xffff) |
| 912 | value = 0xffff; |
| 913 | /* only the msb is considered */ |
| 914 | buf = value >> 8; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 915 | return send_control_msg(pdev, |
| 916 | SET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, |
| 917 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 920 | int pwc_get_blue_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | { |
| 922 | unsigned char buf; |
| 923 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 924 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 925 | ret = recv_control_msg(pdev, |
| 926 | GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, |
| 927 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | if (ret < 0) |
| 929 | return ret; |
| 930 | *value = buf << 8; |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | |
| 935 | /* The following two functions are different, since they only read the |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 936 | internal red/blue gains, which may be different from the manual |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | gains set or read above. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 938 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 939 | static int pwc_read_red_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
| 941 | unsigned char buf; |
| 942 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 943 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 944 | ret = recv_control_msg(pdev, |
| 945 | GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | if (ret < 0) |
| 947 | return ret; |
| 948 | *value = buf << 8; |
| 949 | return 0; |
| 950 | } |
| 951 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 952 | static int pwc_read_blue_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | { |
| 954 | unsigned char buf; |
| 955 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 956 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 957 | ret = recv_control_msg(pdev, |
| 958 | GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | if (ret < 0) |
| 960 | return ret; |
| 961 | *value = buf << 8; |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 966 | static int pwc_set_wb_speed(struct pwc_device *pdev, int speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | { |
| 968 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | /* useful range is 0x01..0x20 */ |
| 971 | buf = speed / 0x7f0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 972 | return send_control_msg(pdev, |
| 973 | SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 976 | static int pwc_get_wb_speed(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | { |
| 978 | unsigned char buf; |
| 979 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 980 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 981 | ret = recv_control_msg(pdev, |
| 982 | GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | if (ret < 0) |
| 984 | return ret; |
| 985 | *value = buf * 0x7f0; |
| 986 | return 0; |
| 987 | } |
| 988 | |
| 989 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 990 | static int pwc_set_wb_delay(struct pwc_device *pdev, int delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | { |
| 992 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | /* useful range is 0x01..0x3F */ |
| 995 | buf = (delay >> 10); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 996 | return send_control_msg(pdev, |
| 997 | SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1000 | static int pwc_get_wb_delay(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | { |
| 1002 | unsigned char buf; |
| 1003 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1004 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1005 | ret = recv_control_msg(pdev, |
| 1006 | GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | if (ret < 0) |
| 1008 | return ret; |
| 1009 | *value = buf << 10; |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | |
| 1014 | int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value) |
| 1015 | { |
| 1016 | unsigned char buf[2]; |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 1017 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
| 1019 | if (pdev->type < 730) |
| 1020 | return 0; |
| 1021 | on_value /= 100; |
| 1022 | off_value /= 100; |
| 1023 | if (on_value < 0) |
| 1024 | on_value = 0; |
| 1025 | if (on_value > 0xff) |
| 1026 | on_value = 0xff; |
| 1027 | if (off_value < 0) |
| 1028 | off_value = 0; |
| 1029 | if (off_value > 0xff) |
| 1030 | off_value = 0xff; |
| 1031 | |
| 1032 | buf[0] = on_value; |
| 1033 | buf[1] = off_value; |
| 1034 | |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 1035 | r = send_control_msg(pdev, |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1036 | SET_STATUS_CTL, LED_FORMATTER, &buf, sizeof(buf)); |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame^] | 1037 | if (r < 0) |
| 1038 | PWC_ERROR("Failed to set LED on/off time (%d)\n", r); |
| 1039 | |
| 1040 | return r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Adrian Bunk | b20c3cf | 2006-06-23 06:49:34 -0300 | [diff] [blame] | 1043 | static int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
| 1045 | unsigned char buf[2]; |
| 1046 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | if (pdev->type < 730) { |
| 1049 | *on_value = -1; |
| 1050 | *off_value = -1; |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1054 | ret = recv_control_msg(pdev, |
| 1055 | GET_STATUS_CTL, LED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | if (ret < 0) |
| 1057 | return ret; |
| 1058 | *on_value = buf[0] * 100; |
| 1059 | *off_value = buf[1] * 100; |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1063 | int pwc_set_contour(struct pwc_device *pdev, int contour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | { |
| 1065 | unsigned char buf; |
| 1066 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | if (contour < 0) |
| 1069 | buf = 0xff; /* auto contour on */ |
| 1070 | else |
| 1071 | buf = 0x0; /* auto contour off */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1072 | ret = send_control_msg(pdev, |
| 1073 | SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | if (ret < 0) |
| 1075 | return ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | if (contour < 0) |
| 1078 | return 0; |
| 1079 | if (contour > 0xffff) |
| 1080 | contour = 0xffff; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | buf = (contour >> 10); /* contour preset is [0..3f] */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1083 | ret = send_control_msg(pdev, |
| 1084 | SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, &buf, sizeof(buf)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1085 | if (ret < 0) |
| 1086 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |
| 1089 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1090 | int pwc_get_contour(struct pwc_device *pdev, int *contour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | { |
| 1092 | unsigned char buf; |
| 1093 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1094 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1095 | ret = recv_control_msg(pdev, |
| 1096 | GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | if (ret < 0) |
| 1098 | return ret; |
| 1099 | |
| 1100 | if (buf == 0) { |
| 1101 | /* auto mode off, query current preset value */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1102 | ret = recv_control_msg(pdev, |
| 1103 | GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, |
| 1104 | &buf, sizeof(buf)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1105 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | return ret; |
| 1107 | *contour = buf << 10; |
| 1108 | } |
| 1109 | else |
| 1110 | *contour = -1; |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1115 | int pwc_set_backlight(struct pwc_device *pdev, int backlight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | { |
| 1117 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | if (backlight) |
| 1120 | buf = 0xff; |
| 1121 | else |
| 1122 | buf = 0x0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1123 | return send_control_msg(pdev, |
| 1124 | SET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, |
| 1125 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1128 | int pwc_get_backlight(struct pwc_device *pdev, int *backlight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | { |
| 1130 | int ret; |
| 1131 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1132 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1133 | ret = recv_control_msg(pdev, |
| 1134 | GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, |
| 1135 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | if (ret < 0) |
| 1137 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1138 | *backlight = !!buf; |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | int pwc_set_colour_mode(struct pwc_device *pdev, int colour) |
| 1143 | { |
| 1144 | unsigned char buf; |
| 1145 | |
| 1146 | if (colour) |
| 1147 | buf = 0xff; |
| 1148 | else |
| 1149 | buf = 0x0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1150 | return send_control_msg(pdev, |
| 1151 | SET_CHROM_CTL, COLOUR_MODE_FORMATTER, &buf, sizeof(buf)); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | int pwc_get_colour_mode(struct pwc_device *pdev, int *colour) |
| 1155 | { |
| 1156 | int ret; |
| 1157 | unsigned char buf; |
| 1158 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1159 | ret = recv_control_msg(pdev, |
| 1160 | GET_CHROM_CTL, COLOUR_MODE_FORMATTER, &buf, sizeof(buf)); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1161 | if (ret < 0) |
| 1162 | return ret; |
| 1163 | *colour = !!buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1168 | int pwc_set_flicker(struct pwc_device *pdev, int flicker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | { |
| 1170 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | if (flicker) |
| 1173 | buf = 0xff; |
| 1174 | else |
| 1175 | buf = 0x0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1176 | return send_control_msg(pdev, |
| 1177 | SET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1180 | int pwc_get_flicker(struct pwc_device *pdev, int *flicker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | { |
| 1182 | int ret; |
| 1183 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1184 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1185 | ret = recv_control_msg(pdev, |
| 1186 | GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | if (ret < 0) |
| 1188 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1189 | *flicker = !!buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | return 0; |
| 1191 | } |
| 1192 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1193 | int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | { |
| 1195 | unsigned char buf; |
| 1196 | |
| 1197 | if (noise < 0) |
| 1198 | noise = 0; |
| 1199 | if (noise > 3) |
| 1200 | noise = 3; |
| 1201 | buf = noise; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1202 | return send_control_msg(pdev, |
| 1203 | SET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, |
| 1204 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1207 | int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | { |
| 1209 | int ret; |
| 1210 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1211 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1212 | ret = recv_control_msg(pdev, |
| 1213 | GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, |
| 1214 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | if (ret < 0) |
| 1216 | return ret; |
| 1217 | *noise = buf; |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1221 | static int _pwc_mpt_reset(struct pwc_device *pdev, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | { |
| 1223 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | buf = flags & 0x03; // only lower two bits are currently used |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1226 | return send_control_msg(pdev, |
| 1227 | SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1230 | int pwc_mpt_reset(struct pwc_device *pdev, int flags) |
| 1231 | { |
| 1232 | int ret; |
| 1233 | ret = _pwc_mpt_reset(pdev, flags); |
| 1234 | if (ret >= 0) { |
| 1235 | pdev->pan_angle = 0; |
| 1236 | pdev->tilt_angle = 0; |
| 1237 | } |
| 1238 | return ret; |
| 1239 | } |
| 1240 | |
| 1241 | static int _pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | { |
| 1243 | unsigned char buf[4]; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | /* set new relative angle; angles are expressed in degrees * 100, |
Steven Cole | 093cf72 | 2005-05-03 19:07:24 -0600 | [diff] [blame] | 1246 | but cam as .5 degree resolution, hence divide by 200. Also |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | the angle must be multiplied by 64 before it's send to |
| 1248 | the cam (??) |
| 1249 | */ |
| 1250 | pan = 64 * pan / 100; |
| 1251 | tilt = -64 * tilt / 100; /* positive tilt is down, which is not what the user would expect */ |
| 1252 | buf[0] = pan & 0xFF; |
| 1253 | buf[1] = (pan >> 8) & 0xFF; |
| 1254 | buf[2] = tilt & 0xFF; |
| 1255 | buf[3] = (tilt >> 8) & 0xFF; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1256 | return send_control_msg(pdev, |
| 1257 | SET_MPT_CTL, PT_RELATIVE_CONTROL_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1260 | int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt) |
| 1261 | { |
| 1262 | int ret; |
| 1263 | |
| 1264 | /* check absolute ranges */ |
| 1265 | if (pan < pdev->angle_range.pan_min || |
| 1266 | pan > pdev->angle_range.pan_max || |
| 1267 | tilt < pdev->angle_range.tilt_min || |
| 1268 | tilt > pdev->angle_range.tilt_max) |
| 1269 | return -ERANGE; |
| 1270 | |
| 1271 | /* go to relative range, check again */ |
| 1272 | pan -= pdev->pan_angle; |
| 1273 | tilt -= pdev->tilt_angle; |
| 1274 | /* angles are specified in degrees * 100, thus the limit = 36000 */ |
| 1275 | if (pan < -36000 || pan > 36000 || tilt < -36000 || tilt > 36000) |
| 1276 | return -ERANGE; |
| 1277 | |
| 1278 | ret = _pwc_mpt_set_angle(pdev, pan, tilt); |
| 1279 | if (ret >= 0) { |
| 1280 | pdev->pan_angle += pan; |
| 1281 | pdev->tilt_angle += tilt; |
| 1282 | } |
| 1283 | if (ret == -EPIPE) /* stall -> out of range */ |
| 1284 | ret = -ERANGE; |
| 1285 | return ret; |
| 1286 | } |
| 1287 | |
| 1288 | static int pwc_mpt_get_status(struct pwc_device *pdev, struct pwc_mpt_status *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | { |
| 1290 | int ret; |
| 1291 | unsigned char buf[5]; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1292 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1293 | ret = recv_control_msg(pdev, |
| 1294 | GET_MPT_CTL, PT_STATUS_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | if (ret < 0) |
| 1296 | return ret; |
| 1297 | status->status = buf[0] & 0x7; // 3 bits are used for reporting |
| 1298 | status->time_pan = (buf[1] << 8) + buf[2]; |
| 1299 | status->time_tilt = (buf[3] << 8) + buf[4]; |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor) |
| 1305 | { |
| 1306 | unsigned char buf; |
| 1307 | int ret = -1, request; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | if (pdev->type < 675) |
| 1310 | request = SENSOR_TYPE_FORMATTER1; |
| 1311 | else if (pdev->type < 730) |
| 1312 | return -1; /* The Vesta series doesn't have this call */ |
| 1313 | else |
| 1314 | request = SENSOR_TYPE_FORMATTER2; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1315 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1316 | ret = recv_control_msg(pdev, |
| 1317 | GET_STATUS_CTL, request, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | if (ret < 0) |
| 1319 | return ret; |
| 1320 | if (pdev->type < 675) |
| 1321 | *sensor = buf | 0x100; |
| 1322 | else |
| 1323 | *sensor = buf; |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | /* End of Add-Ons */ |
| 1329 | /* ************************************************* */ |
| 1330 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1331 | /* Linux 2.5.something and 2.6 pass direct pointers to arguments of |
| 1332 | ioctl() calls. With 2.4, you have to do tedious copy_from_user() |
| 1333 | and copy_to_user() calls. With these macros we circumvent this, |
| 1334 | and let me maintain only one source file. The functionality is |
| 1335 | exactly the same otherwise. |
| 1336 | */ |
| 1337 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1338 | /* define local variable for arg */ |
| 1339 | #define ARG_DEF(ARG_type, ARG_name)\ |
| 1340 | ARG_type *ARG_name = arg; |
| 1341 | /* copy arg to local variable */ |
| 1342 | #define ARG_IN(ARG_name) /* nothing */ |
| 1343 | /* argument itself (referenced) */ |
| 1344 | #define ARGR(ARG_name) (*ARG_name) |
| 1345 | /* argument address */ |
| 1346 | #define ARGA(ARG_name) ARG_name |
| 1347 | /* copy local variable to arg */ |
| 1348 | #define ARG_OUT(ARG_name) /* nothing */ |
| 1349 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1350 | long pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1352 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
| 1354 | switch(cmd) { |
| 1355 | case VIDIOCPWCRUSER: |
| 1356 | { |
| 1357 | if (pwc_restore_user(pdev)) |
| 1358 | ret = -EINVAL; |
| 1359 | break; |
| 1360 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | case VIDIOCPWCSUSER: |
| 1363 | { |
| 1364 | if (pwc_save_user(pdev)) |
| 1365 | ret = -EINVAL; |
| 1366 | break; |
| 1367 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | case VIDIOCPWCFACTORY: |
| 1370 | { |
| 1371 | if (pwc_restore_factory(pdev)) |
| 1372 | ret = -EINVAL; |
| 1373 | break; |
| 1374 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | case VIDIOCPWCSCQUAL: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1377 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1378 | ARG_DEF(int, qual) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 1380 | if (pdev->iso_init) { |
| 1381 | ret = -EBUSY; |
| 1382 | break; |
| 1383 | } |
| 1384 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1385 | ARG_IN(qual) |
| 1386 | if (ARGR(qual) < 0 || ARGR(qual) > 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | ret = -EINVAL; |
| 1388 | else |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 1389 | ret = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, ARGR(qual), pdev->vsnapshot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | if (ret >= 0) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1391 | pdev->vcompression = ARGR(qual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | break; |
| 1393 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | case VIDIOCPWCGCQUAL: |
| 1396 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1397 | ARG_DEF(int, qual) |
| 1398 | |
| 1399 | ARGR(qual) = pdev->vcompression; |
| 1400 | ARG_OUT(qual) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | break; |
| 1402 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | case VIDIOCPWCPROBE: |
| 1405 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1406 | ARG_DEF(struct pwc_probe, probe) |
| 1407 | |
Hans de Goede | 9a7b2d1 | 2011-06-06 14:43:39 -0300 | [diff] [blame] | 1408 | strcpy(ARGR(probe).name, pdev->vdev.name); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1409 | ARGR(probe).type = pdev->type; |
| 1410 | ARG_OUT(probe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | break; |
| 1412 | } |
| 1413 | |
| 1414 | case VIDIOCPWCGSERIAL: |
| 1415 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1416 | ARG_DEF(struct pwc_serial, serial) |
| 1417 | |
| 1418 | strcpy(ARGR(serial).serial, pdev->serial); |
| 1419 | ARG_OUT(serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | } |
| 1422 | |
| 1423 | case VIDIOCPWCSAGC: |
| 1424 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1425 | ARG_DEF(int, agc) |
| 1426 | |
| 1427 | ARG_IN(agc) |
| 1428 | if (pwc_set_agc(pdev, ARGR(agc) < 0 ? 1 : 0, ARGR(agc))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | ret = -EINVAL; |
| 1430 | break; |
| 1431 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | case VIDIOCPWCGAGC: |
| 1434 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1435 | ARG_DEF(int, agc) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1436 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1437 | if (pwc_get_agc(pdev, ARGA(agc))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | ret = -EINVAL; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1439 | ARG_OUT(agc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | break; |
| 1441 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | case VIDIOCPWCSSHUTTER: |
| 1444 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1445 | ARG_DEF(int, shutter_speed) |
| 1446 | |
| 1447 | ARG_IN(shutter_speed) |
| 1448 | ret = pwc_set_shutter_speed(pdev, ARGR(shutter_speed) < 0 ? 1 : 0, ARGR(shutter_speed)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | break; |
| 1450 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1451 | |
| 1452 | case VIDIOCPWCSAWB: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1454 | ARG_DEF(struct pwc_whitebalance, wb) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1455 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1456 | ARG_IN(wb) |
| 1457 | ret = pwc_set_awb(pdev, ARGR(wb).mode); |
| 1458 | if (ret >= 0 && ARGR(wb).mode == PWC_WB_MANUAL) { |
| 1459 | pwc_set_red_gain(pdev, ARGR(wb).manual_red); |
| 1460 | pwc_set_blue_gain(pdev, ARGR(wb).manual_blue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | } |
| 1462 | break; |
| 1463 | } |
| 1464 | |
| 1465 | case VIDIOCPWCGAWB: |
| 1466 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1467 | ARG_DEF(struct pwc_whitebalance, wb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1469 | memset(ARGA(wb), 0, sizeof(struct pwc_whitebalance)); |
| 1470 | ARGR(wb).mode = pwc_get_awb(pdev); |
| 1471 | if (ARGR(wb).mode < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | ret = -EINVAL; |
| 1473 | else { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1474 | if (ARGR(wb).mode == PWC_WB_MANUAL) { |
| 1475 | ret = pwc_get_red_gain(pdev, &ARGR(wb).manual_red); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | if (ret < 0) |
| 1477 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1478 | ret = pwc_get_blue_gain(pdev, &ARGR(wb).manual_blue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | if (ret < 0) |
| 1480 | break; |
| 1481 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1482 | if (ARGR(wb).mode == PWC_WB_AUTO) { |
| 1483 | ret = pwc_read_red_gain(pdev, &ARGR(wb).read_red); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | if (ret < 0) |
| 1485 | break; |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 1486 | ret = pwc_read_blue_gain(pdev, &ARGR(wb).read_blue); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1487 | if (ret < 0) |
| 1488 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | } |
| 1490 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1491 | ARG_OUT(wb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | break; |
| 1493 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | case VIDIOCPWCSAWBSPEED: |
| 1496 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1497 | ARG_DEF(struct pwc_wb_speed, wbs) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1498 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1499 | if (ARGR(wbs).control_speed > 0) { |
| 1500 | ret = pwc_set_wb_speed(pdev, ARGR(wbs).control_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1502 | if (ARGR(wbs).control_delay > 0) { |
| 1503 | ret = pwc_set_wb_delay(pdev, ARGR(wbs).control_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | } |
| 1505 | break; |
| 1506 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | case VIDIOCPWCGAWBSPEED: |
| 1509 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1510 | ARG_DEF(struct pwc_wb_speed, wbs) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1511 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1512 | ret = pwc_get_wb_speed(pdev, &ARGR(wbs).control_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | if (ret < 0) |
| 1514 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1515 | ret = pwc_get_wb_delay(pdev, &ARGR(wbs).control_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | if (ret < 0) |
| 1517 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1518 | ARG_OUT(wbs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | break; |
| 1520 | } |
| 1521 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1522 | case VIDIOCPWCSLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1524 | ARG_DEF(struct pwc_leds, leds) |
| 1525 | |
| 1526 | ARG_IN(leds) |
| 1527 | ret = pwc_set_leds(pdev, ARGR(leds).led_on, ARGR(leds).led_off); |
Trent Piepho | 657de3c | 2006-06-20 00:30:57 -0300 | [diff] [blame] | 1528 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | case VIDIOCPWCGLED: |
| 1533 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1534 | ARG_DEF(struct pwc_leds, leds) |
| 1535 | |
| 1536 | ret = pwc_get_leds(pdev, &ARGR(leds).led_on, &ARGR(leds).led_off); |
| 1537 | ARG_OUT(leds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | break; |
| 1539 | } |
| 1540 | |
| 1541 | case VIDIOCPWCSCONTOUR: |
| 1542 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1543 | ARG_DEF(int, contour) |
| 1544 | |
| 1545 | ARG_IN(contour) |
| 1546 | ret = pwc_set_contour(pdev, ARGR(contour)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | break; |
| 1548 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | case VIDIOCPWCGCONTOUR: |
| 1551 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1552 | ARG_DEF(int, contour) |
| 1553 | |
| 1554 | ret = pwc_get_contour(pdev, ARGA(contour)); |
| 1555 | ARG_OUT(contour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | break; |
| 1557 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | case VIDIOCPWCSBACKLIGHT: |
| 1560 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1561 | ARG_DEF(int, backlight) |
| 1562 | |
| 1563 | ARG_IN(backlight) |
| 1564 | ret = pwc_set_backlight(pdev, ARGR(backlight)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | break; |
| 1566 | } |
| 1567 | |
| 1568 | case VIDIOCPWCGBACKLIGHT: |
| 1569 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1570 | ARG_DEF(int, backlight) |
| 1571 | |
| 1572 | ret = pwc_get_backlight(pdev, ARGA(backlight)); |
| 1573 | ARG_OUT(backlight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | break; |
| 1575 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | case VIDIOCPWCSFLICKER: |
| 1578 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1579 | ARG_DEF(int, flicker) |
| 1580 | |
| 1581 | ARG_IN(flicker) |
| 1582 | ret = pwc_set_flicker(pdev, ARGR(flicker)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | break; |
| 1584 | } |
| 1585 | |
| 1586 | case VIDIOCPWCGFLICKER: |
| 1587 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1588 | ARG_DEF(int, flicker) |
| 1589 | |
| 1590 | ret = pwc_get_flicker(pdev, ARGA(flicker)); |
| 1591 | ARG_OUT(flicker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | break; |
| 1593 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | case VIDIOCPWCSDYNNOISE: |
| 1596 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1597 | ARG_DEF(int, dynnoise) |
| 1598 | |
| 1599 | ARG_IN(dynnoise) |
| 1600 | ret = pwc_set_dynamic_noise(pdev, ARGR(dynnoise)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | break; |
| 1602 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | case VIDIOCPWCGDYNNOISE: |
| 1605 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1606 | ARG_DEF(int, dynnoise) |
| 1607 | |
| 1608 | ret = pwc_get_dynamic_noise(pdev, ARGA(dynnoise)); |
| 1609 | ARG_OUT(dynnoise); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | break; |
| 1611 | } |
| 1612 | |
| 1613 | case VIDIOCPWCGREALSIZE: |
| 1614 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1615 | ARG_DEF(struct pwc_imagesize, size) |
| 1616 | |
| 1617 | ARGR(size).width = pdev->image.x; |
| 1618 | ARGR(size).height = pdev->image.y; |
| 1619 | ARG_OUT(size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | case VIDIOCPWCMPTRESET: |
| 1624 | { |
| 1625 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1626 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1627 | ARG_DEF(int, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1629 | ARG_IN(flags) |
| 1630 | ret = pwc_mpt_reset(pdev, ARGR(flags)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1631 | } |
| 1632 | else |
| 1633 | { |
| 1634 | ret = -ENXIO; |
| 1635 | } |
| 1636 | break; |
| 1637 | } |
| 1638 | |
| 1639 | case VIDIOCPWCMPTGRANGE: |
| 1640 | { |
| 1641 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1642 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1643 | ARG_DEF(struct pwc_mpt_range, range) |
| 1644 | |
| 1645 | ARGR(range) = pdev->angle_range; |
| 1646 | ARG_OUT(range) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1647 | } |
| 1648 | else |
| 1649 | { |
| 1650 | ret = -ENXIO; |
| 1651 | } |
| 1652 | break; |
| 1653 | } |
| 1654 | |
| 1655 | case VIDIOCPWCMPTSANGLE: |
| 1656 | { |
| 1657 | int new_pan, new_tilt; |
| 1658 | |
| 1659 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1660 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1661 | ARG_DEF(struct pwc_mpt_angles, angles) |
| 1662 | |
| 1663 | ARG_IN(angles) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | /* The camera can only set relative angles, so |
| 1665 | do some calculations when getting an absolute angle . |
| 1666 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1667 | if (ARGR(angles).absolute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1669 | new_pan = ARGR(angles).pan; |
| 1670 | new_tilt = ARGR(angles).tilt; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1671 | } |
| 1672 | else |
| 1673 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1674 | new_pan = pdev->pan_angle + ARGR(angles).pan; |
| 1675 | new_tilt = pdev->tilt_angle + ARGR(angles).tilt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1677 | ret = pwc_mpt_set_angle(pdev, new_pan, new_tilt); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1678 | } |
| 1679 | else |
| 1680 | { |
| 1681 | ret = -ENXIO; |
| 1682 | } |
| 1683 | break; |
| 1684 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1686 | case VIDIOCPWCMPTGANGLE: |
| 1687 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1689 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1690 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1691 | ARG_DEF(struct pwc_mpt_angles, angles) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1692 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1693 | ARGR(angles).absolute = 1; |
| 1694 | ARGR(angles).pan = pdev->pan_angle; |
| 1695 | ARGR(angles).tilt = pdev->tilt_angle; |
| 1696 | ARG_OUT(angles) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1697 | } |
| 1698 | else |
| 1699 | { |
| 1700 | ret = -ENXIO; |
| 1701 | } |
| 1702 | break; |
| 1703 | } |
| 1704 | |
| 1705 | case VIDIOCPWCMPTSTATUS: |
| 1706 | { |
| 1707 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1708 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1709 | ARG_DEF(struct pwc_mpt_status, status) |
| 1710 | |
| 1711 | ret = pwc_mpt_get_status(pdev, ARGA(status)); |
| 1712 | ARG_OUT(status) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1713 | } |
| 1714 | else |
| 1715 | { |
| 1716 | ret = -ENXIO; |
| 1717 | } |
| 1718 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | case VIDIOCPWCGVIDCMD: |
| 1722 | { |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1723 | ARG_DEF(struct pwc_video_command, vcmd); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1724 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1725 | ARGR(vcmd).type = pdev->type; |
| 1726 | ARGR(vcmd).release = pdev->release; |
| 1727 | ARGR(vcmd).command_len = pdev->cmd_len; |
| 1728 | memcpy(&ARGR(vcmd).command_buf, pdev->cmd_buf, pdev->cmd_len); |
| 1729 | ARGR(vcmd).bandlength = pdev->vbandlength; |
| 1730 | ARGR(vcmd).frame_size = pdev->frame_size; |
| 1731 | ARG_OUT(vcmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | break; |
| 1733 | } |
Michael Krufky | b930e1d | 2007-08-27 18:16:54 -0300 | [diff] [blame] | 1734 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | case VIDIOCPWCGVIDTABLE: |
| 1736 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1737 | ARG_DEF(struct pwc_table_init_buffer, table); |
| 1738 | ARGR(table).len = pdev->cmd_len; |
| 1739 | memcpy(&ARGR(table).buffer, pdev->decompress_data, pdev->decompressor->table_size); |
| 1740 | ARG_OUT(table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | break; |
| 1742 | } |
| 1743 | */ |
| 1744 | |
| 1745 | default: |
| 1746 | ret = -ENOIOCTLCMD; |
| 1747 | break; |
| 1748 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | if (ret > 0) |
| 1751 | return 0; |
| 1752 | return ret; |
| 1753 | } |
| 1754 | |
| 1755 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1756 | /* vim: set cinoptions= formatoptions=croql cindent shiftwidth=8 tabstop=8: */ |