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 | |
| 786 | /* POWER */ |
| 787 | |
| 788 | int pwc_camera_power(struct pwc_device *pdev, int power) |
| 789 | { |
| 790 | char buf; |
| 791 | |
| 792 | if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6)) |
| 793 | return 0; /* Not supported by Nala or Timon < release 6 */ |
| 794 | |
| 795 | if (power) |
| 796 | buf = 0x00; /* active */ |
| 797 | else |
| 798 | buf = 0xFF; /* power save */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 799 | return send_control_msg(pdev, |
| 800 | SET_STATUS_CTL, SET_POWER_SAVE_MODE_FORMATTER, |
| 801 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | |
| 805 | |
| 806 | /* private calls */ |
| 807 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 808 | int pwc_restore_user(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 810 | return send_control_msg(pdev, |
| 811 | SET_STATUS_CTL, RESTORE_USER_DEFAULTS_FORMATTER, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 814 | int pwc_save_user(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 816 | return send_control_msg(pdev, |
| 817 | SET_STATUS_CTL, SAVE_USER_DEFAULTS_FORMATTER, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 820 | int pwc_restore_factory(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 822 | return send_control_msg(pdev, |
| 823 | SET_STATUS_CTL, RESTORE_FACTORY_DEFAULTS_FORMATTER, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /* ************************************************* */ |
| 827 | /* Patch by Alvarado: (not in the original version */ |
| 828 | |
| 829 | /* |
| 830 | * the camera recognizes modes from 0 to 4: |
| 831 | * |
| 832 | * 00: indoor (incandescant lighting) |
| 833 | * 01: outdoor (sunlight) |
| 834 | * 02: fluorescent lighting |
| 835 | * 03: manual |
| 836 | * 04: auto |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 837 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 838 | int pwc_set_awb(struct pwc_device *pdev, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
| 840 | char buf; |
| 841 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | if (mode < 0) |
| 844 | mode = 0; |
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 > 4) |
| 847 | mode = 4; |
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 | buf = mode & 0x07; /* just the lowest three bits */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 850 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 851 | ret = send_control_msg(pdev, |
| 852 | SET_CHROM_CTL, WB_MODE_FORMATTER, &buf, sizeof(buf)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | if (ret < 0) |
| 855 | return ret; |
| 856 | return 0; |
| 857 | } |
| 858 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 859 | int pwc_get_awb(struct pwc_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | { |
| 861 | unsigned char buf; |
| 862 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 863 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 864 | ret = recv_control_msg(pdev, |
| 865 | GET_CHROM_CTL, WB_MODE_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 867 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | return ret; |
| 869 | return buf; |
| 870 | } |
| 871 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 872 | int pwc_set_red_gain(struct pwc_device *pdev, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 874 | unsigned char buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
| 876 | if (value < 0) |
| 877 | value = 0; |
| 878 | if (value > 0xffff) |
| 879 | value = 0xffff; |
| 880 | /* only the msb is considered */ |
| 881 | buf = value >> 8; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 882 | return send_control_msg(pdev, |
| 883 | SET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, |
| 884 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 887 | int pwc_get_red_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
| 889 | unsigned char buf; |
| 890 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 891 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 892 | ret = recv_control_msg(pdev, |
| 893 | GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, |
| 894 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | if (ret < 0) |
| 896 | return ret; |
| 897 | *value = buf << 8; |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 902 | int pwc_set_blue_gain(struct pwc_device *pdev, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
| 904 | unsigned char buf; |
| 905 | |
| 906 | if (value < 0) |
| 907 | value = 0; |
| 908 | if (value > 0xffff) |
| 909 | value = 0xffff; |
| 910 | /* only the msb is considered */ |
| 911 | buf = value >> 8; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 912 | return send_control_msg(pdev, |
| 913 | SET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, |
| 914 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 917 | int pwc_get_blue_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | { |
| 919 | unsigned char buf; |
| 920 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 921 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 922 | ret = recv_control_msg(pdev, |
| 923 | GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, |
| 924 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | if (ret < 0) |
| 926 | return ret; |
| 927 | *value = buf << 8; |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | |
| 932 | /* The following two functions are different, since they only read the |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 933 | internal red/blue gains, which may be different from the manual |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | gains set or read above. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 935 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 936 | static int pwc_read_red_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | { |
| 938 | unsigned char buf; |
| 939 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 940 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 941 | ret = recv_control_msg(pdev, |
| 942 | GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | if (ret < 0) |
| 944 | return ret; |
| 945 | *value = buf << 8; |
| 946 | return 0; |
| 947 | } |
| 948 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 949 | static int pwc_read_blue_gain(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { |
| 951 | unsigned char buf; |
| 952 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 953 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 954 | ret = recv_control_msg(pdev, |
| 955 | GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | if (ret < 0) |
| 957 | return ret; |
| 958 | *value = buf << 8; |
| 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 963 | static int pwc_set_wb_speed(struct pwc_device *pdev, int speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
| 965 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | /* useful range is 0x01..0x20 */ |
| 968 | buf = speed / 0x7f0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 969 | return send_control_msg(pdev, |
| 970 | SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 973 | static int pwc_get_wb_speed(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | { |
| 975 | unsigned char buf; |
| 976 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 977 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 978 | ret = recv_control_msg(pdev, |
| 979 | GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | if (ret < 0) |
| 981 | return ret; |
| 982 | *value = buf * 0x7f0; |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 987 | static int pwc_set_wb_delay(struct pwc_device *pdev, int delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | { |
| 989 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | /* useful range is 0x01..0x3F */ |
| 992 | buf = (delay >> 10); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 993 | return send_control_msg(pdev, |
| 994 | SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 997 | static int pwc_get_wb_delay(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | { |
| 999 | unsigned char buf; |
| 1000 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1001 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1002 | ret = recv_control_msg(pdev, |
| 1003 | GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | if (ret < 0) |
| 1005 | return ret; |
| 1006 | *value = buf << 10; |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value) |
| 1012 | { |
| 1013 | unsigned char buf[2]; |
| 1014 | |
| 1015 | if (pdev->type < 730) |
| 1016 | return 0; |
| 1017 | on_value /= 100; |
| 1018 | off_value /= 100; |
| 1019 | if (on_value < 0) |
| 1020 | on_value = 0; |
| 1021 | if (on_value > 0xff) |
| 1022 | on_value = 0xff; |
| 1023 | if (off_value < 0) |
| 1024 | off_value = 0; |
| 1025 | if (off_value > 0xff) |
| 1026 | off_value = 0xff; |
| 1027 | |
| 1028 | buf[0] = on_value; |
| 1029 | buf[1] = off_value; |
| 1030 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1031 | return send_control_msg(pdev, |
| 1032 | SET_STATUS_CTL, LED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Adrian Bunk | b20c3cf | 2006-06-23 06:49:34 -0300 | [diff] [blame] | 1035 | 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] | 1036 | { |
| 1037 | unsigned char buf[2]; |
| 1038 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | if (pdev->type < 730) { |
| 1041 | *on_value = -1; |
| 1042 | *off_value = -1; |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1046 | ret = recv_control_msg(pdev, |
| 1047 | GET_STATUS_CTL, LED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | if (ret < 0) |
| 1049 | return ret; |
| 1050 | *on_value = buf[0] * 100; |
| 1051 | *off_value = buf[1] * 100; |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1055 | int pwc_set_contour(struct pwc_device *pdev, int contour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | { |
| 1057 | unsigned char buf; |
| 1058 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | if (contour < 0) |
| 1061 | buf = 0xff; /* auto contour on */ |
| 1062 | else |
| 1063 | buf = 0x0; /* auto contour off */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1064 | ret = send_control_msg(pdev, |
| 1065 | SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | if (ret < 0) |
| 1067 | return ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | if (contour < 0) |
| 1070 | return 0; |
| 1071 | if (contour > 0xffff) |
| 1072 | contour = 0xffff; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | buf = (contour >> 10); /* contour preset is [0..3f] */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1075 | ret = send_control_msg(pdev, |
| 1076 | SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, &buf, sizeof(buf)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1077 | if (ret < 0) |
| 1078 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | return 0; |
| 1080 | } |
| 1081 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1082 | int pwc_get_contour(struct pwc_device *pdev, int *contour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | { |
| 1084 | unsigned char buf; |
| 1085 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1086 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1087 | ret = recv_control_msg(pdev, |
| 1088 | GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | if (ret < 0) |
| 1090 | return ret; |
| 1091 | |
| 1092 | if (buf == 0) { |
| 1093 | /* auto mode off, query current preset value */ |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1094 | ret = recv_control_msg(pdev, |
| 1095 | GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, |
| 1096 | &buf, sizeof(buf)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1097 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | return ret; |
| 1099 | *contour = buf << 10; |
| 1100 | } |
| 1101 | else |
| 1102 | *contour = -1; |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1107 | int pwc_set_backlight(struct pwc_device *pdev, int backlight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | { |
| 1109 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | if (backlight) |
| 1112 | buf = 0xff; |
| 1113 | else |
| 1114 | buf = 0x0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1115 | return send_control_msg(pdev, |
| 1116 | SET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, |
| 1117 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1120 | int pwc_get_backlight(struct pwc_device *pdev, int *backlight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | { |
| 1122 | int ret; |
| 1123 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1124 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1125 | ret = recv_control_msg(pdev, |
| 1126 | GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, |
| 1127 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | if (ret < 0) |
| 1129 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1130 | *backlight = !!buf; |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
| 1134 | int pwc_set_colour_mode(struct pwc_device *pdev, int colour) |
| 1135 | { |
| 1136 | unsigned char buf; |
| 1137 | |
| 1138 | if (colour) |
| 1139 | buf = 0xff; |
| 1140 | else |
| 1141 | buf = 0x0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1142 | return send_control_msg(pdev, |
| 1143 | SET_CHROM_CTL, COLOUR_MODE_FORMATTER, &buf, sizeof(buf)); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | int pwc_get_colour_mode(struct pwc_device *pdev, int *colour) |
| 1147 | { |
| 1148 | int ret; |
| 1149 | unsigned char buf; |
| 1150 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1151 | ret = recv_control_msg(pdev, |
| 1152 | GET_CHROM_CTL, COLOUR_MODE_FORMATTER, &buf, sizeof(buf)); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1153 | if (ret < 0) |
| 1154 | return ret; |
| 1155 | *colour = !!buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | return 0; |
| 1157 | } |
| 1158 | |
| 1159 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1160 | int pwc_set_flicker(struct pwc_device *pdev, int flicker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | { |
| 1162 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | if (flicker) |
| 1165 | buf = 0xff; |
| 1166 | else |
| 1167 | buf = 0x0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1168 | return send_control_msg(pdev, |
| 1169 | SET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1172 | int pwc_get_flicker(struct pwc_device *pdev, int *flicker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | { |
| 1174 | int ret; |
| 1175 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1176 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1177 | ret = recv_control_msg(pdev, |
| 1178 | GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | if (ret < 0) |
| 1180 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1181 | *flicker = !!buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1185 | int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | { |
| 1187 | unsigned char buf; |
| 1188 | |
| 1189 | if (noise < 0) |
| 1190 | noise = 0; |
| 1191 | if (noise > 3) |
| 1192 | noise = 3; |
| 1193 | buf = noise; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1194 | return send_control_msg(pdev, |
| 1195 | SET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, |
| 1196 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1199 | int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | { |
| 1201 | int ret; |
| 1202 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1203 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1204 | ret = recv_control_msg(pdev, |
| 1205 | GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, |
| 1206 | &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | if (ret < 0) |
| 1208 | return ret; |
| 1209 | *noise = buf; |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1213 | static int _pwc_mpt_reset(struct pwc_device *pdev, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | { |
| 1215 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | buf = flags & 0x03; // only lower two bits are currently used |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1218 | return send_control_msg(pdev, |
| 1219 | SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1222 | int pwc_mpt_reset(struct pwc_device *pdev, int flags) |
| 1223 | { |
| 1224 | int ret; |
| 1225 | ret = _pwc_mpt_reset(pdev, flags); |
| 1226 | if (ret >= 0) { |
| 1227 | pdev->pan_angle = 0; |
| 1228 | pdev->tilt_angle = 0; |
| 1229 | } |
| 1230 | return ret; |
| 1231 | } |
| 1232 | |
| 1233 | 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] | 1234 | { |
| 1235 | unsigned char buf[4]; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | /* set new relative angle; angles are expressed in degrees * 100, |
Steven Cole | 093cf72 | 2005-05-03 19:07:24 -0600 | [diff] [blame] | 1238 | but cam as .5 degree resolution, hence divide by 200. Also |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | the angle must be multiplied by 64 before it's send to |
| 1240 | the cam (??) |
| 1241 | */ |
| 1242 | pan = 64 * pan / 100; |
| 1243 | tilt = -64 * tilt / 100; /* positive tilt is down, which is not what the user would expect */ |
| 1244 | buf[0] = pan & 0xFF; |
| 1245 | buf[1] = (pan >> 8) & 0xFF; |
| 1246 | buf[2] = tilt & 0xFF; |
| 1247 | buf[3] = (tilt >> 8) & 0xFF; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1248 | return send_control_msg(pdev, |
| 1249 | SET_MPT_CTL, PT_RELATIVE_CONTROL_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1252 | int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt) |
| 1253 | { |
| 1254 | int ret; |
| 1255 | |
| 1256 | /* check absolute ranges */ |
| 1257 | if (pan < pdev->angle_range.pan_min || |
| 1258 | pan > pdev->angle_range.pan_max || |
| 1259 | tilt < pdev->angle_range.tilt_min || |
| 1260 | tilt > pdev->angle_range.tilt_max) |
| 1261 | return -ERANGE; |
| 1262 | |
| 1263 | /* go to relative range, check again */ |
| 1264 | pan -= pdev->pan_angle; |
| 1265 | tilt -= pdev->tilt_angle; |
| 1266 | /* angles are specified in degrees * 100, thus the limit = 36000 */ |
| 1267 | if (pan < -36000 || pan > 36000 || tilt < -36000 || tilt > 36000) |
| 1268 | return -ERANGE; |
| 1269 | |
| 1270 | ret = _pwc_mpt_set_angle(pdev, pan, tilt); |
| 1271 | if (ret >= 0) { |
| 1272 | pdev->pan_angle += pan; |
| 1273 | pdev->tilt_angle += tilt; |
| 1274 | } |
| 1275 | if (ret == -EPIPE) /* stall -> out of range */ |
| 1276 | ret = -ERANGE; |
| 1277 | return ret; |
| 1278 | } |
| 1279 | |
| 1280 | 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] | 1281 | { |
| 1282 | int ret; |
| 1283 | unsigned char buf[5]; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1284 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1285 | ret = recv_control_msg(pdev, |
| 1286 | GET_MPT_CTL, PT_STATUS_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | if (ret < 0) |
| 1288 | return ret; |
| 1289 | status->status = buf[0] & 0x7; // 3 bits are used for reporting |
| 1290 | status->time_pan = (buf[1] << 8) + buf[2]; |
| 1291 | status->time_tilt = (buf[3] << 8) + buf[4]; |
| 1292 | return 0; |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor) |
| 1297 | { |
| 1298 | unsigned char buf; |
| 1299 | int ret = -1, request; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | if (pdev->type < 675) |
| 1302 | request = SENSOR_TYPE_FORMATTER1; |
| 1303 | else if (pdev->type < 730) |
| 1304 | return -1; /* The Vesta series doesn't have this call */ |
| 1305 | else |
| 1306 | request = SENSOR_TYPE_FORMATTER2; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1307 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 1308 | ret = recv_control_msg(pdev, |
| 1309 | GET_STATUS_CTL, request, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | if (ret < 0) |
| 1311 | return ret; |
| 1312 | if (pdev->type < 675) |
| 1313 | *sensor = buf | 0x100; |
| 1314 | else |
| 1315 | *sensor = buf; |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | /* End of Add-Ons */ |
| 1321 | /* ************************************************* */ |
| 1322 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1323 | /* Linux 2.5.something and 2.6 pass direct pointers to arguments of |
| 1324 | ioctl() calls. With 2.4, you have to do tedious copy_from_user() |
| 1325 | and copy_to_user() calls. With these macros we circumvent this, |
| 1326 | and let me maintain only one source file. The functionality is |
| 1327 | exactly the same otherwise. |
| 1328 | */ |
| 1329 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1330 | /* define local variable for arg */ |
| 1331 | #define ARG_DEF(ARG_type, ARG_name)\ |
| 1332 | ARG_type *ARG_name = arg; |
| 1333 | /* copy arg to local variable */ |
| 1334 | #define ARG_IN(ARG_name) /* nothing */ |
| 1335 | /* argument itself (referenced) */ |
| 1336 | #define ARGR(ARG_name) (*ARG_name) |
| 1337 | /* argument address */ |
| 1338 | #define ARGA(ARG_name) ARG_name |
| 1339 | /* copy local variable to arg */ |
| 1340 | #define ARG_OUT(ARG_name) /* nothing */ |
| 1341 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1342 | long pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1344 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
| 1346 | switch(cmd) { |
| 1347 | case VIDIOCPWCRUSER: |
| 1348 | { |
| 1349 | if (pwc_restore_user(pdev)) |
| 1350 | ret = -EINVAL; |
| 1351 | break; |
| 1352 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | case VIDIOCPWCSUSER: |
| 1355 | { |
| 1356 | if (pwc_save_user(pdev)) |
| 1357 | ret = -EINVAL; |
| 1358 | break; |
| 1359 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | case VIDIOCPWCFACTORY: |
| 1362 | { |
| 1363 | if (pwc_restore_factory(pdev)) |
| 1364 | ret = -EINVAL; |
| 1365 | break; |
| 1366 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | case VIDIOCPWCSCQUAL: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1369 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1370 | ARG_DEF(int, qual) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 1372 | if (pdev->iso_init) { |
| 1373 | ret = -EBUSY; |
| 1374 | break; |
| 1375 | } |
| 1376 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1377 | ARG_IN(qual) |
| 1378 | if (ARGR(qual) < 0 || ARGR(qual) > 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | ret = -EINVAL; |
| 1380 | else |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 1381 | 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] | 1382 | if (ret >= 0) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1383 | pdev->vcompression = ARGR(qual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | break; |
| 1385 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | case VIDIOCPWCGCQUAL: |
| 1388 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1389 | ARG_DEF(int, qual) |
| 1390 | |
| 1391 | ARGR(qual) = pdev->vcompression; |
| 1392 | ARG_OUT(qual) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | case VIDIOCPWCPROBE: |
| 1397 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1398 | ARG_DEF(struct pwc_probe, probe) |
| 1399 | |
Hans de Goede | 9a7b2d1 | 2011-06-06 14:43:39 -0300 | [diff] [blame] | 1400 | strcpy(ARGR(probe).name, pdev->vdev.name); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1401 | ARGR(probe).type = pdev->type; |
| 1402 | ARG_OUT(probe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | break; |
| 1404 | } |
| 1405 | |
| 1406 | case VIDIOCPWCGSERIAL: |
| 1407 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1408 | ARG_DEF(struct pwc_serial, serial) |
| 1409 | |
| 1410 | strcpy(ARGR(serial).serial, pdev->serial); |
| 1411 | ARG_OUT(serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | break; |
| 1413 | } |
| 1414 | |
| 1415 | case VIDIOCPWCSAGC: |
| 1416 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1417 | ARG_DEF(int, agc) |
| 1418 | |
| 1419 | ARG_IN(agc) |
| 1420 | if (pwc_set_agc(pdev, ARGR(agc) < 0 ? 1 : 0, ARGR(agc))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | ret = -EINVAL; |
| 1422 | break; |
| 1423 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | case VIDIOCPWCGAGC: |
| 1426 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1427 | ARG_DEF(int, agc) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1428 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1429 | if (pwc_get_agc(pdev, ARGA(agc))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | ret = -EINVAL; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1431 | ARG_OUT(agc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | break; |
| 1433 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | case VIDIOCPWCSSHUTTER: |
| 1436 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1437 | ARG_DEF(int, shutter_speed) |
| 1438 | |
| 1439 | ARG_IN(shutter_speed) |
| 1440 | 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] | 1441 | break; |
| 1442 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1443 | |
| 1444 | case VIDIOCPWCSAWB: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1446 | ARG_DEF(struct pwc_whitebalance, wb) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1447 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1448 | ARG_IN(wb) |
| 1449 | ret = pwc_set_awb(pdev, ARGR(wb).mode); |
| 1450 | if (ret >= 0 && ARGR(wb).mode == PWC_WB_MANUAL) { |
| 1451 | pwc_set_red_gain(pdev, ARGR(wb).manual_red); |
| 1452 | pwc_set_blue_gain(pdev, ARGR(wb).manual_blue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | } |
| 1454 | break; |
| 1455 | } |
| 1456 | |
| 1457 | case VIDIOCPWCGAWB: |
| 1458 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1459 | ARG_DEF(struct pwc_whitebalance, wb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1461 | memset(ARGA(wb), 0, sizeof(struct pwc_whitebalance)); |
| 1462 | ARGR(wb).mode = pwc_get_awb(pdev); |
| 1463 | if (ARGR(wb).mode < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | ret = -EINVAL; |
| 1465 | else { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1466 | if (ARGR(wb).mode == PWC_WB_MANUAL) { |
| 1467 | ret = pwc_get_red_gain(pdev, &ARGR(wb).manual_red); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | if (ret < 0) |
| 1469 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1470 | ret = pwc_get_blue_gain(pdev, &ARGR(wb).manual_blue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | if (ret < 0) |
| 1472 | break; |
| 1473 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1474 | if (ARGR(wb).mode == PWC_WB_AUTO) { |
| 1475 | ret = pwc_read_red_gain(pdev, &ARGR(wb).read_red); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | if (ret < 0) |
| 1477 | break; |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 1478 | ret = pwc_read_blue_gain(pdev, &ARGR(wb).read_blue); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1479 | if (ret < 0) |
| 1480 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | } |
| 1482 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1483 | ARG_OUT(wb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | break; |
| 1485 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | case VIDIOCPWCSAWBSPEED: |
| 1488 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1489 | ARG_DEF(struct pwc_wb_speed, wbs) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1490 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1491 | if (ARGR(wbs).control_speed > 0) { |
| 1492 | ret = pwc_set_wb_speed(pdev, ARGR(wbs).control_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1494 | if (ARGR(wbs).control_delay > 0) { |
| 1495 | ret = pwc_set_wb_delay(pdev, ARGR(wbs).control_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | break; |
| 1498 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | case VIDIOCPWCGAWBSPEED: |
| 1501 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1502 | ARG_DEF(struct pwc_wb_speed, wbs) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1503 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1504 | ret = pwc_get_wb_speed(pdev, &ARGR(wbs).control_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | if (ret < 0) |
| 1506 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1507 | ret = pwc_get_wb_delay(pdev, &ARGR(wbs).control_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | if (ret < 0) |
| 1509 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1510 | ARG_OUT(wbs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | break; |
| 1512 | } |
| 1513 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1514 | case VIDIOCPWCSLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1516 | ARG_DEF(struct pwc_leds, leds) |
| 1517 | |
| 1518 | ARG_IN(leds) |
| 1519 | 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] | 1520 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | |
| 1524 | case VIDIOCPWCGLED: |
| 1525 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1526 | ARG_DEF(struct pwc_leds, leds) |
| 1527 | |
| 1528 | ret = pwc_get_leds(pdev, &ARGR(leds).led_on, &ARGR(leds).led_off); |
| 1529 | ARG_OUT(leds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | break; |
| 1531 | } |
| 1532 | |
| 1533 | case VIDIOCPWCSCONTOUR: |
| 1534 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1535 | ARG_DEF(int, contour) |
| 1536 | |
| 1537 | ARG_IN(contour) |
| 1538 | ret = pwc_set_contour(pdev, ARGR(contour)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | break; |
| 1540 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | case VIDIOCPWCGCONTOUR: |
| 1543 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1544 | ARG_DEF(int, contour) |
| 1545 | |
| 1546 | ret = pwc_get_contour(pdev, ARGA(contour)); |
| 1547 | ARG_OUT(contour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | break; |
| 1549 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | case VIDIOCPWCSBACKLIGHT: |
| 1552 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1553 | ARG_DEF(int, backlight) |
| 1554 | |
| 1555 | ARG_IN(backlight) |
| 1556 | ret = pwc_set_backlight(pdev, ARGR(backlight)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | break; |
| 1558 | } |
| 1559 | |
| 1560 | case VIDIOCPWCGBACKLIGHT: |
| 1561 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1562 | ARG_DEF(int, backlight) |
| 1563 | |
| 1564 | ret = pwc_get_backlight(pdev, ARGA(backlight)); |
| 1565 | ARG_OUT(backlight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | break; |
| 1567 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | case VIDIOCPWCSFLICKER: |
| 1570 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1571 | ARG_DEF(int, flicker) |
| 1572 | |
| 1573 | ARG_IN(flicker) |
| 1574 | ret = pwc_set_flicker(pdev, ARGR(flicker)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | break; |
| 1576 | } |
| 1577 | |
| 1578 | case VIDIOCPWCGFLICKER: |
| 1579 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1580 | ARG_DEF(int, flicker) |
| 1581 | |
| 1582 | ret = pwc_get_flicker(pdev, ARGA(flicker)); |
| 1583 | ARG_OUT(flicker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | break; |
| 1585 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | case VIDIOCPWCSDYNNOISE: |
| 1588 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1589 | ARG_DEF(int, dynnoise) |
| 1590 | |
| 1591 | ARG_IN(dynnoise) |
| 1592 | ret = pwc_set_dynamic_noise(pdev, ARGR(dynnoise)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | break; |
| 1594 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | case VIDIOCPWCGDYNNOISE: |
| 1597 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1598 | ARG_DEF(int, dynnoise) |
| 1599 | |
| 1600 | ret = pwc_get_dynamic_noise(pdev, ARGA(dynnoise)); |
| 1601 | ARG_OUT(dynnoise); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | break; |
| 1603 | } |
| 1604 | |
| 1605 | case VIDIOCPWCGREALSIZE: |
| 1606 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1607 | ARG_DEF(struct pwc_imagesize, size) |
| 1608 | |
| 1609 | ARGR(size).width = pdev->image.x; |
| 1610 | ARGR(size).height = pdev->image.y; |
| 1611 | ARG_OUT(size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | case VIDIOCPWCMPTRESET: |
| 1616 | { |
| 1617 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1618 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1619 | ARG_DEF(int, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1621 | ARG_IN(flags) |
| 1622 | ret = pwc_mpt_reset(pdev, ARGR(flags)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1623 | } |
| 1624 | else |
| 1625 | { |
| 1626 | ret = -ENXIO; |
| 1627 | } |
| 1628 | break; |
| 1629 | } |
| 1630 | |
| 1631 | case VIDIOCPWCMPTGRANGE: |
| 1632 | { |
| 1633 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1634 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1635 | ARG_DEF(struct pwc_mpt_range, range) |
| 1636 | |
| 1637 | ARGR(range) = pdev->angle_range; |
| 1638 | ARG_OUT(range) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1639 | } |
| 1640 | else |
| 1641 | { |
| 1642 | ret = -ENXIO; |
| 1643 | } |
| 1644 | break; |
| 1645 | } |
| 1646 | |
| 1647 | case VIDIOCPWCMPTSANGLE: |
| 1648 | { |
| 1649 | int new_pan, new_tilt; |
| 1650 | |
| 1651 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1652 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1653 | ARG_DEF(struct pwc_mpt_angles, angles) |
| 1654 | |
| 1655 | ARG_IN(angles) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | /* The camera can only set relative angles, so |
| 1657 | do some calculations when getting an absolute angle . |
| 1658 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1659 | if (ARGR(angles).absolute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1661 | new_pan = ARGR(angles).pan; |
| 1662 | new_tilt = ARGR(angles).tilt; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1663 | } |
| 1664 | else |
| 1665 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1666 | new_pan = pdev->pan_angle + ARGR(angles).pan; |
| 1667 | new_tilt = pdev->tilt_angle + ARGR(angles).tilt; |
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 | ret = pwc_mpt_set_angle(pdev, new_pan, new_tilt); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1670 | } |
| 1671 | else |
| 1672 | { |
| 1673 | ret = -ENXIO; |
| 1674 | } |
| 1675 | break; |
| 1676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1678 | case VIDIOCPWCMPTGANGLE: |
| 1679 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1681 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1682 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1683 | ARG_DEF(struct pwc_mpt_angles, angles) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1684 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1685 | ARGR(angles).absolute = 1; |
| 1686 | ARGR(angles).pan = pdev->pan_angle; |
| 1687 | ARGR(angles).tilt = pdev->tilt_angle; |
| 1688 | ARG_OUT(angles) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1689 | } |
| 1690 | else |
| 1691 | { |
| 1692 | ret = -ENXIO; |
| 1693 | } |
| 1694 | break; |
| 1695 | } |
| 1696 | |
| 1697 | case VIDIOCPWCMPTSTATUS: |
| 1698 | { |
| 1699 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1700 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1701 | ARG_DEF(struct pwc_mpt_status, status) |
| 1702 | |
| 1703 | ret = pwc_mpt_get_status(pdev, ARGA(status)); |
| 1704 | ARG_OUT(status) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1705 | } |
| 1706 | else |
| 1707 | { |
| 1708 | ret = -ENXIO; |
| 1709 | } |
| 1710 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | case VIDIOCPWCGVIDCMD: |
| 1714 | { |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1715 | ARG_DEF(struct pwc_video_command, vcmd); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1716 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1717 | ARGR(vcmd).type = pdev->type; |
| 1718 | ARGR(vcmd).release = pdev->release; |
| 1719 | ARGR(vcmd).command_len = pdev->cmd_len; |
| 1720 | memcpy(&ARGR(vcmd).command_buf, pdev->cmd_buf, pdev->cmd_len); |
| 1721 | ARGR(vcmd).bandlength = pdev->vbandlength; |
| 1722 | ARGR(vcmd).frame_size = pdev->frame_size; |
| 1723 | ARG_OUT(vcmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | break; |
| 1725 | } |
Michael Krufky | b930e1d | 2007-08-27 18:16:54 -0300 | [diff] [blame] | 1726 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | case VIDIOCPWCGVIDTABLE: |
| 1728 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1729 | ARG_DEF(struct pwc_table_init_buffer, table); |
| 1730 | ARGR(table).len = pdev->cmd_len; |
| 1731 | memcpy(&ARGR(table).buffer, pdev->decompress_data, pdev->decompressor->table_size); |
| 1732 | ARG_OUT(table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | break; |
| 1734 | } |
| 1735 | */ |
| 1736 | |
| 1737 | default: |
| 1738 | ret = -ENOIOCTLCMD; |
| 1739 | break; |
| 1740 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | if (ret > 0) |
| 1743 | return 0; |
| 1744 | return ret; |
| 1745 | } |
| 1746 | |
| 1747 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1748 | /* vim: set cinoptions= formatoptions=croql cindent shiftwidth=8 tabstop=8: */ |