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) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 6 | (C) 2011 Hans de Goede <hdegoede@redhat.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
| 8 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx |
| 9 | driver and thus may have bugs that are not present in the original version. |
| 10 | Please send bug reports and support requests to <luc@saillard.org>. |
| 11 | |
| 12 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx |
| 13 | driver and thus may have bugs that are not present in the original version. |
| 14 | Please send bug reports and support requests to <luc@saillard.org>. |
| 15 | The decompression routines have been implemented by reverse-engineering the |
| 16 | Nemosoft binary pwcx module. Caveat emptor. |
| 17 | |
| 18 | This program is free software; you can redistribute it and/or modify |
| 19 | it under the terms of the GNU General Public License as published by |
| 20 | the Free Software Foundation; either version 2 of the License, or |
| 21 | (at your option) any later version. |
| 22 | |
| 23 | This program is distributed in the hope that it will be useful, |
| 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | GNU General Public License for more details. |
| 27 | |
| 28 | You should have received a copy of the GNU General Public License |
| 29 | along with this program; if not, write to the Free Software |
| 30 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 31 | */ |
| 32 | |
| 33 | /* |
| 34 | Changes |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 35 | 2001/08/03 Alvarado Added methods for changing white balance and |
| 36 | red/green gains |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | /* Control functions for the cam; brightness, contrast, video mode, etc. */ |
| 40 | |
| 41 | #ifdef __KERNEL__ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 42 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #endif |
| 44 | #include <asm/errno.h> |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include "pwc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 52 | /* Selectors for status controls used only in this file */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 53 | #define GET_STATUS_B00 0x0B00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define SENSOR_TYPE_FORMATTER1 0x0C00 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 55 | #define GET_STATUS_3000 0x3000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define READ_RAW_Y_MEAN_FORMATTER 0x3100 |
| 57 | #define SET_POWER_SAVE_MODE_FORMATTER 0x3200 |
| 58 | #define MIRROR_IMAGE_FORMATTER 0x3300 |
| 59 | #define LED_FORMATTER 0x3400 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 60 | #define LOWLIGHT 0x3500 |
| 61 | #define GET_STATUS_3600 0x3600 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define SENSOR_TYPE_FORMATTER2 0x3700 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 63 | #define GET_STATUS_3800 0x3800 |
| 64 | #define GET_STATUS_4000 0x4000 |
| 65 | #define GET_STATUS_4100 0x4100 /* Get */ |
| 66 | #define CTL_STATUS_4200 0x4200 /* [GS] 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | /* Formatters for the Video Endpoint controls [GS]ET_EP_STREAM_CTL */ |
| 69 | #define VIDEO_OUTPUT_CONTROL_FORMATTER 0x0100 |
| 70 | |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 71 | static const char *size2name[PSZ_MAX] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
| 73 | "subQCIF", |
| 74 | "QSIF", |
| 75 | "QCIF", |
| 76 | "SIF", |
| 77 | "CIF", |
| 78 | "VGA", |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 79 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /********/ |
| 82 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 83 | /* 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] | 84 | preferences, so you either get compressed or non-compressed streams. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | An alternate value of 0 means this mode is not available at all. |
| 87 | */ |
| 88 | |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 89 | #define PWC_FPS_MAX_NALA 8 |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | struct Nala_table_entry { |
| 92 | char alternate; /* USB alternate setting */ |
| 93 | int compressed; /* Compressed yes/no */ |
| 94 | |
| 95 | unsigned char mode[3]; /* precomputed mode table */ |
| 96 | }; |
| 97 | |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 98 | static unsigned int Nala_fps_vector[PWC_FPS_MAX_NALA] = { 4, 5, 7, 10, 12, 15, 20, 24 }; |
| 99 | |
| 100 | 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] | 101 | { |
| 102 | #include "pwc-nala.h" |
| 103 | }; |
| 104 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 105 | static void pwc_set_image_buffer_size(struct pwc_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /****************************************************************************/ |
| 108 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 109 | static int _send_control_msg(struct pwc_device *pdev, |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 110 | u8 request, u16 value, int index, void *buf, int buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 112 | int rc; |
| 113 | void *kbuf = NULL; |
| 114 | |
| 115 | if (buflen) { |
| 116 | kbuf = kmalloc(buflen, GFP_KERNEL); /* not allowed on stack */ |
| 117 | if (kbuf == NULL) |
| 118 | return -ENOMEM; |
| 119 | memcpy(kbuf, buf, buflen); |
| 120 | } |
| 121 | |
| 122 | rc = usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0), |
| 123 | request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 125 | value, |
| 126 | index, |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 127 | kbuf, buflen, USB_CTRL_SET_TIMEOUT); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 128 | |
| 129 | kfree(kbuf); |
| 130 | return rc; |
| 131 | } |
| 132 | |
| 133 | static int recv_control_msg(struct pwc_device *pdev, |
| 134 | u8 request, u16 value, void *buf, int buflen) |
| 135 | { |
| 136 | int rc; |
| 137 | void *kbuf = kmalloc(buflen, GFP_KERNEL); /* not allowed on stack */ |
| 138 | |
| 139 | if (kbuf == NULL) |
| 140 | return -ENOMEM; |
| 141 | |
| 142 | rc = usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0), |
| 143 | request, |
| 144 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 145 | value, |
| 146 | pdev->vcinterface, |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 147 | kbuf, buflen, USB_CTRL_GET_TIMEOUT); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 148 | memcpy(buf, kbuf, buflen); |
| 149 | kfree(kbuf); |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 150 | |
| 151 | if (rc < 0) |
| 152 | PWC_ERROR("recv_control_msg error %d req %02x val %04x\n", |
| 153 | rc, request, value); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 154 | return rc; |
| 155 | } |
| 156 | |
| 157 | static inline int send_video_command(struct pwc_device *pdev, |
| 158 | int index, void *buf, int buflen) |
| 159 | { |
| 160 | return _send_control_msg(pdev, |
| 161 | SET_EP_STREAM_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | VIDEO_OUTPUT_CONTROL_FORMATTER, |
| 163 | index, |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 164 | buf, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 167 | int send_control_msg(struct pwc_device *pdev, |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 168 | u8 request, u16 value, void *buf, int buflen) |
| 169 | { |
| 170 | return _send_control_msg(pdev, |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 171 | request, value, pdev->vcinterface, buf, buflen); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 174 | 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] | 175 | { |
| 176 | unsigned char buf[3]; |
| 177 | int ret, fps; |
| 178 | struct Nala_table_entry *pEntry; |
| 179 | int frames2frames[31] = |
| 180 | { /* closest match of framerate */ |
| 181 | 0, 0, 0, 0, 4, /* 0-4 */ |
| 182 | 5, 5, 7, 7, 10, /* 5-9 */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 183 | 10, 10, 12, 12, 15, /* 10-14 */ |
| 184 | 15, 15, 15, 20, 20, /* 15-19 */ |
| 185 | 20, 20, 20, 24, 24, /* 20-24 */ |
| 186 | 24, 24, 24, 24, 24, /* 25-29 */ |
| 187 | 24 /* 30 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | }; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 189 | int frames2table[31] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { 0, 0, 0, 0, 0, /* 0-4 */ |
| 191 | 1, 1, 1, 2, 2, /* 5-9 */ |
| 192 | 3, 3, 4, 4, 4, /* 10-14 */ |
| 193 | 5, 5, 5, 5, 5, /* 15-19 */ |
| 194 | 6, 6, 6, 6, 7, /* 20-24 */ |
| 195 | 7, 7, 7, 7, 7, /* 25-29 */ |
| 196 | 7 /* 30 */ |
| 197 | }; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25) |
| 200 | return -EINVAL; |
| 201 | frames = frames2frames[frames]; |
| 202 | fps = frames2table[frames]; |
| 203 | pEntry = &Nala_table[size][fps]; |
| 204 | if (pEntry->alternate == 0) |
| 205 | return -EINVAL; |
| 206 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 207 | memcpy(buf, pEntry->mode, 3); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 208 | ret = send_video_command(pdev, pdev->vendpoint, buf, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (ret < 0) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 210 | PWC_DEBUG_MODULE("Failed to send video command... %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | return ret; |
| 212 | } |
Hans de Goede | 6eba935 | 2011-06-26 06:49:59 -0300 | [diff] [blame] | 213 | if (pEntry->compressed && pdev->pixfmt == V4L2_PIX_FMT_YUV420) { |
| 214 | ret = pwc_dec1_init(pdev, pdev->type, pdev->release, buf); |
| 215 | if (ret < 0) |
| 216 | return ret; |
| 217 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | pdev->cmd_len = 3; |
| 220 | memcpy(pdev->cmd_buf, buf, 3); |
| 221 | |
| 222 | /* Set various parameters */ |
| 223 | pdev->vframes = frames; |
| 224 | pdev->vsize = size; |
| 225 | pdev->valternate = pEntry->alternate; |
| 226 | pdev->image = pwc_image_sizes[size]; |
| 227 | pdev->frame_size = (pdev->image.x * pdev->image.y * 3) / 2; |
| 228 | if (pEntry->compressed) { |
| 229 | if (pdev->release < 5) { /* 4 fold compression */ |
| 230 | pdev->vbandlength = 528; |
| 231 | pdev->frame_size /= 4; |
| 232 | } |
| 233 | else { |
| 234 | pdev->vbandlength = 704; |
| 235 | pdev->frame_size /= 3; |
| 236 | } |
| 237 | } |
| 238 | else |
| 239 | pdev->vbandlength = 0; |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 244 | 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] | 245 | { |
| 246 | unsigned char buf[13]; |
| 247 | const struct Timon_table_entry *pChoose; |
| 248 | int ret, fps; |
| 249 | |
| 250 | if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) |
| 251 | return -EINVAL; |
| 252 | if (size == PSZ_VGA && frames > 15) |
| 253 | return -EINVAL; |
| 254 | fps = (frames / 5) - 1; |
| 255 | |
| 256 | /* Find a supported framerate with progressively higher compression ratios |
| 257 | if the preferred ratio is not available. |
| 258 | */ |
| 259 | pChoose = NULL; |
| 260 | while (compression <= 3) { |
| 261 | pChoose = &Timon_table[size][fps][compression]; |
| 262 | if (pChoose->alternate != 0) |
| 263 | break; |
| 264 | compression++; |
| 265 | } |
| 266 | if (pChoose == NULL || pChoose->alternate == 0) |
| 267 | return -ENOENT; /* Not supported. */ |
| 268 | |
| 269 | memcpy(buf, pChoose->mode, 13); |
| 270 | if (snapshot) |
| 271 | buf[0] |= 0x80; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 272 | ret = send_video_command(pdev, pdev->vendpoint, buf, 13); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (ret < 0) |
| 274 | return ret; |
| 275 | |
Hans de Goede | 6eba935 | 2011-06-26 06:49:59 -0300 | [diff] [blame] | 276 | if (pChoose->bandlength > 0 && pdev->pixfmt == V4L2_PIX_FMT_YUV420) { |
| 277 | ret = pwc_dec23_init(pdev, pdev->type, buf); |
| 278 | if (ret < 0) |
| 279 | return ret; |
| 280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | pdev->cmd_len = 13; |
| 283 | memcpy(pdev->cmd_buf, buf, 13); |
| 284 | |
| 285 | /* Set various parameters */ |
| 286 | pdev->vframes = frames; |
| 287 | pdev->vsize = size; |
| 288 | pdev->vsnapshot = snapshot; |
| 289 | pdev->valternate = pChoose->alternate; |
| 290 | pdev->image = pwc_image_sizes[size]; |
| 291 | pdev->vbandlength = pChoose->bandlength; |
| 292 | if (pChoose->bandlength > 0) |
| 293 | pdev->frame_size = (pChoose->bandlength * pdev->image.y) / 4; |
| 294 | else |
| 295 | pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8; |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 300 | 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] | 301 | { |
| 302 | const struct Kiara_table_entry *pChoose = NULL; |
| 303 | int fps, ret; |
| 304 | unsigned char buf[12]; |
| 305 | struct Kiara_table_entry RawEntry = {6, 773, 1272, {0xAD, 0xF4, 0x10, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}}; |
| 306 | |
| 307 | if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) |
| 308 | return -EINVAL; |
| 309 | if (size == PSZ_VGA && frames > 15) |
| 310 | return -EINVAL; |
| 311 | fps = (frames / 5) - 1; |
| 312 | |
| 313 | /* special case: VGA @ 5 fps and snapshot is raw bayer mode */ |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 314 | 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] | 315 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 316 | /* Only available in case the raw palette is selected or |
| 317 | we have the decompressor available. This mode is |
| 318 | only available in compressed form |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 320 | PWC_DEBUG_SIZE("Choosing VGA/5 BAYER mode.\n"); |
| 321 | pChoose = &RawEntry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | else |
| 324 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 325 | /* Find a supported framerate with progressively higher compression ratios |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if the preferred ratio is not available. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 327 | Skip this step when using RAW modes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 329 | snapshot = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | while (compression <= 3) { |
| 331 | pChoose = &Kiara_table[size][fps][compression]; |
| 332 | if (pChoose->alternate != 0) |
| 333 | break; |
| 334 | compression++; |
| 335 | } |
| 336 | } |
| 337 | if (pChoose == NULL || pChoose->alternate == 0) |
| 338 | return -ENOENT; /* Not supported. */ |
| 339 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 340 | PWC_TRACE("Using alternate setting %d.\n", pChoose->alternate); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /* usb_control_msg won't take staticly allocated arrays as argument?? */ |
| 343 | memcpy(buf, pChoose->mode, 12); |
| 344 | if (snapshot) |
| 345 | buf[0] |= 0x80; |
| 346 | |
| 347 | /* 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] | 348 | ret = send_video_command(pdev, 4 /* pdev->vendpoint */, buf, 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | if (ret < 0) |
| 350 | return ret; |
| 351 | |
Hans de Goede | 6eba935 | 2011-06-26 06:49:59 -0300 | [diff] [blame] | 352 | if (pChoose->bandlength > 0 && pdev->pixfmt == V4L2_PIX_FMT_YUV420) { |
| 353 | ret = pwc_dec23_init(pdev, pdev->type, buf); |
| 354 | if (ret < 0) |
| 355 | return ret; |
| 356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
| 358 | pdev->cmd_len = 12; |
| 359 | memcpy(pdev->cmd_buf, buf, 12); |
| 360 | /* All set and go */ |
| 361 | pdev->vframes = frames; |
| 362 | pdev->vsize = size; |
| 363 | pdev->vsnapshot = snapshot; |
| 364 | pdev->valternate = pChoose->alternate; |
| 365 | pdev->image = pwc_image_sizes[size]; |
| 366 | pdev->vbandlength = pChoose->bandlength; |
| 367 | if (pdev->vbandlength > 0) |
| 368 | pdev->frame_size = (pdev->vbandlength * pdev->image.y) / 4; |
| 369 | else |
| 370 | pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 371 | PWC_TRACE("frame_size=%d, vframes=%d, vsize=%d, vsnapshot=%d, vbandlength=%d\n", |
| 372 | pdev->frame_size,pdev->vframes,pdev->vsize,pdev->vsnapshot,pdev->vbandlength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | |
| 378 | /** |
| 379 | @pdev: device structure |
| 380 | @width: viewport width |
| 381 | @height: viewport height |
| 382 | @frame: framerate, in fps |
| 383 | @compression: preferred compression ratio |
| 384 | @snapshot: snapshot mode or streaming |
| 385 | */ |
| 386 | int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot) |
| 387 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 388 | int ret, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 390 | 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] | 391 | size = pwc_decode_size(pdev, width, height); |
| 392 | if (size < 0) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 393 | PWC_DEBUG_MODULE("Could not find suitable size.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | return -ERANGE; |
| 395 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 396 | PWC_TRACE("decode_size = %d.\n", size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 398 | if (DEVICE_USE_CODEC1(pdev->type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | ret = set_video_mode_Nala(pdev, size, frames); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 401 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | ret = set_video_mode_Kiara(pdev, size, frames, compression, snapshot); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 403 | |
| 404 | } else { |
| 405 | ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | if (ret < 0) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 408 | 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] | 409 | return ret; |
| 410 | } |
| 411 | pdev->view.x = width; |
| 412 | pdev->view.y = height; |
Hans de Goede | 6eba935 | 2011-06-26 06:49:59 -0300 | [diff] [blame] | 413 | pdev->vcompression = compression; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | pdev->frame_total_size = pdev->frame_size + pdev->frame_header_size + pdev->frame_trailer_size; |
| 415 | pwc_set_image_buffer_size(pdev); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 416 | 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] | 417 | return 0; |
| 418 | } |
| 419 | |
Luc Saillard | 9ee6d78 | 2007-04-22 23:54:36 -0300 | [diff] [blame] | 420 | static unsigned int pwc_get_fps_Nala(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 421 | { |
| 422 | unsigned int i; |
| 423 | |
| 424 | for (i = 0; i < PWC_FPS_MAX_NALA; i++) { |
| 425 | if (Nala_table[size][i].alternate) { |
| 426 | if (index--==0) return Nala_fps_vector[i]; |
| 427 | } |
| 428 | } |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static unsigned int pwc_get_fps_Kiara(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 433 | { |
| 434 | unsigned int i; |
| 435 | |
| 436 | for (i = 0; i < PWC_FPS_MAX_KIARA; i++) { |
| 437 | if (Kiara_table[size][i][3].alternate) { |
| 438 | if (index--==0) return Kiara_fps_vector[i]; |
| 439 | } |
| 440 | } |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | static unsigned int pwc_get_fps_Timon(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 445 | { |
| 446 | unsigned int i; |
| 447 | |
| 448 | for (i=0; i < PWC_FPS_MAX_TIMON; i++) { |
| 449 | if (Timon_table[size][i][3].alternate) { |
| 450 | if (index--==0) return Timon_fps_vector[i]; |
| 451 | } |
| 452 | } |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | unsigned int pwc_get_fps(struct pwc_device *pdev, unsigned int index, unsigned int size) |
| 457 | { |
| 458 | unsigned int ret; |
| 459 | |
| 460 | if (DEVICE_USE_CODEC1(pdev->type)) { |
| 461 | ret = pwc_get_fps_Nala(pdev, index, size); |
| 462 | |
| 463 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
| 464 | ret = pwc_get_fps_Kiara(pdev, index, size); |
| 465 | |
| 466 | } else { |
| 467 | ret = pwc_get_fps_Timon(pdev, index, size); |
| 468 | } |
| 469 | |
| 470 | return ret; |
| 471 | } |
| 472 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 473 | static void pwc_set_image_buffer_size(struct pwc_device *pdev) |
| 474 | { |
Hans de Goede | 885fe18 | 2011-06-06 15:33:44 -0300 | [diff] [blame] | 475 | int factor = 0; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 476 | |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 477 | /* for V4L2_PIX_FMT_YUV420 */ |
| 478 | switch (pdev->pixfmt) { |
| 479 | case V4L2_PIX_FMT_YUV420: |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 480 | factor = 6; |
| 481 | break; |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 482 | case V4L2_PIX_FMT_PWC1: |
| 483 | case V4L2_PIX_FMT_PWC2: |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 484 | factor = 6; /* can be uncompressed YUV420P */ |
| 485 | break; |
| 486 | } |
| 487 | |
| 488 | /* Set sizes in bytes */ |
| 489 | pdev->image.size = pdev->image.x * pdev->image.y * factor / 4; |
| 490 | pdev->view.size = pdev->view.x * pdev->view.y * factor / 4; |
| 491 | |
| 492 | /* Align offset, or you'll get some very weird results in |
| 493 | YUV420 mode... x must be multiple of 4 (to get the Y's in |
| 494 | place), and y even (or you'll mixup U & V). This is less of a |
| 495 | problem for YUV420P. |
| 496 | */ |
| 497 | pdev->offset.x = ((pdev->view.x - pdev->image.x) / 2) & 0xFFFC; |
| 498 | pdev->offset.y = ((pdev->view.y - pdev->image.y) / 2) & 0xFFFE; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 499 | } |
| 500 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 501 | int pwc_get_u8_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | int ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 504 | u8 buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 506 | ret = recv_control_msg(pdev, request, value, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | if (ret < 0) |
| 508 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 510 | *data = buf; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 514 | int pwc_set_u8_ctrl(struct pwc_device *pdev, u8 request, u16 value, u8 data) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 515 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 517 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 518 | ret = send_control_msg(pdev, request, value, &data, sizeof(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (ret < 0) |
| 520 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 525 | int pwc_get_s8_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 527 | int ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 528 | s8 buf; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 529 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 530 | ret = recv_control_msg(pdev, request, value, &buf, sizeof(buf)); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 531 | if (ret < 0) |
| 532 | return ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 533 | |
| 534 | *data = buf; |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | int pwc_get_u16_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *data) |
| 539 | { |
| 540 | int ret; |
| 541 | u8 buf[2]; |
| 542 | |
| 543 | ret = recv_control_msg(pdev, request, value, buf, sizeof(buf)); |
| 544 | if (ret < 0) |
| 545 | return ret; |
| 546 | |
| 547 | *data = (buf[1] << 8) | buf[0]; |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | int pwc_set_u16_ctrl(struct pwc_device *pdev, u8 request, u16 value, u16 data) |
| 552 | { |
| 553 | int ret; |
| 554 | u8 buf[2]; |
| 555 | |
| 556 | buf[0] = data & 0xff; |
| 557 | buf[1] = data >> 8; |
| 558 | ret = send_control_msg(pdev, request, value, buf, sizeof(buf)); |
| 559 | if (ret < 0) |
| 560 | return ret; |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | int pwc_button_ctrl(struct pwc_device *pdev, u16 value) |
| 566 | { |
| 567 | int ret; |
| 568 | |
| 569 | ret = send_control_msg(pdev, SET_STATUS_CTL, value, NULL, 0); |
| 570 | if (ret < 0) |
| 571 | return ret; |
| 572 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 573 | return 0; |
| 574 | } |
| 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | /* POWER */ |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 577 | void pwc_camera_power(struct pwc_device *pdev, int power) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
| 579 | char buf; |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 580 | int r; |
| 581 | |
| 582 | if (!pdev->power_save) |
| 583 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
| 585 | if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6)) |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 586 | return; /* Not supported by Nala or Timon < release 6 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | if (power) |
| 589 | buf = 0x00; /* active */ |
| 590 | else |
| 591 | buf = 0xFF; /* power save */ |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 592 | r = send_control_msg(pdev, |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 593 | SET_STATUS_CTL, SET_POWER_SAVE_MODE_FORMATTER, |
| 594 | &buf, sizeof(buf)); |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 595 | |
| 596 | if (r < 0) |
| 597 | PWC_ERROR("Failed to power %s camera (%d)\n", |
| 598 | power ? "on" : "off", r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 601 | static int pwc_set_wb_speed(struct pwc_device *pdev, int speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
| 603 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | /* useful range is 0x01..0x20 */ |
| 606 | buf = speed / 0x7f0; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 607 | return send_control_msg(pdev, |
| 608 | SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 611 | static int pwc_get_wb_speed(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
| 613 | unsigned char buf; |
| 614 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 615 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 616 | ret = recv_control_msg(pdev, |
| 617 | GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | if (ret < 0) |
| 619 | return ret; |
| 620 | *value = buf * 0x7f0; |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 625 | static int pwc_set_wb_delay(struct pwc_device *pdev, int delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | { |
| 627 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | /* useful range is 0x01..0x3F */ |
| 630 | buf = (delay >> 10); |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 631 | return send_control_msg(pdev, |
| 632 | SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 635 | static int pwc_get_wb_delay(struct pwc_device *pdev, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
| 637 | unsigned char buf; |
| 638 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 639 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 640 | ret = recv_control_msg(pdev, |
| 641 | GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if (ret < 0) |
| 643 | return ret; |
| 644 | *value = buf << 10; |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | |
| 649 | int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value) |
| 650 | { |
| 651 | unsigned char buf[2]; |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 652 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | if (pdev->type < 730) |
| 655 | return 0; |
| 656 | on_value /= 100; |
| 657 | off_value /= 100; |
| 658 | if (on_value < 0) |
| 659 | on_value = 0; |
| 660 | if (on_value > 0xff) |
| 661 | on_value = 0xff; |
| 662 | if (off_value < 0) |
| 663 | off_value = 0; |
| 664 | if (off_value > 0xff) |
| 665 | off_value = 0xff; |
| 666 | |
| 667 | buf[0] = on_value; |
| 668 | buf[1] = off_value; |
| 669 | |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 670 | r = send_control_msg(pdev, |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 671 | SET_STATUS_CTL, LED_FORMATTER, &buf, sizeof(buf)); |
Hans de Goede | 3b4d0ec | 2011-06-26 03:51:19 -0300 | [diff] [blame] | 672 | if (r < 0) |
| 673 | PWC_ERROR("Failed to set LED on/off time (%d)\n", r); |
| 674 | |
| 675 | return r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Adrian Bunk | b20c3cf | 2006-06-23 06:49:34 -0300 | [diff] [blame] | 678 | 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] | 679 | { |
| 680 | unsigned char buf[2]; |
| 681 | int ret; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if (pdev->type < 730) { |
| 684 | *on_value = -1; |
| 685 | *off_value = -1; |
| 686 | return 0; |
| 687 | } |
| 688 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 689 | ret = recv_control_msg(pdev, |
| 690 | GET_STATUS_CTL, LED_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (ret < 0) |
| 692 | return ret; |
| 693 | *on_value = buf[0] * 100; |
| 694 | *off_value = buf[1] * 100; |
| 695 | return 0; |
| 696 | } |
| 697 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 698 | static int _pwc_mpt_reset(struct pwc_device *pdev, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
| 700 | unsigned char buf; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | buf = flags & 0x03; // only lower two bits are currently used |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 703 | return send_control_msg(pdev, |
| 704 | SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 707 | int pwc_mpt_reset(struct pwc_device *pdev, int flags) |
| 708 | { |
| 709 | int ret; |
| 710 | ret = _pwc_mpt_reset(pdev, flags); |
| 711 | if (ret >= 0) { |
| 712 | pdev->pan_angle = 0; |
| 713 | pdev->tilt_angle = 0; |
| 714 | } |
| 715 | return ret; |
| 716 | } |
| 717 | |
| 718 | 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] | 719 | { |
| 720 | unsigned char buf[4]; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | /* set new relative angle; angles are expressed in degrees * 100, |
Steven Cole | 093cf72 | 2005-05-03 19:07:24 -0600 | [diff] [blame] | 723 | but cam as .5 degree resolution, hence divide by 200. Also |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | the angle must be multiplied by 64 before it's send to |
| 725 | the cam (??) |
| 726 | */ |
| 727 | pan = 64 * pan / 100; |
| 728 | tilt = -64 * tilt / 100; /* positive tilt is down, which is not what the user would expect */ |
| 729 | buf[0] = pan & 0xFF; |
| 730 | buf[1] = (pan >> 8) & 0xFF; |
| 731 | buf[2] = tilt & 0xFF; |
| 732 | buf[3] = (tilt >> 8) & 0xFF; |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 733 | return send_control_msg(pdev, |
| 734 | SET_MPT_CTL, PT_RELATIVE_CONTROL_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 737 | int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt) |
| 738 | { |
| 739 | int ret; |
| 740 | |
| 741 | /* check absolute ranges */ |
| 742 | if (pan < pdev->angle_range.pan_min || |
| 743 | pan > pdev->angle_range.pan_max || |
| 744 | tilt < pdev->angle_range.tilt_min || |
| 745 | tilt > pdev->angle_range.tilt_max) |
| 746 | return -ERANGE; |
| 747 | |
| 748 | /* go to relative range, check again */ |
| 749 | pan -= pdev->pan_angle; |
| 750 | tilt -= pdev->tilt_angle; |
| 751 | /* angles are specified in degrees * 100, thus the limit = 36000 */ |
| 752 | if (pan < -36000 || pan > 36000 || tilt < -36000 || tilt > 36000) |
| 753 | return -ERANGE; |
| 754 | |
| 755 | ret = _pwc_mpt_set_angle(pdev, pan, tilt); |
| 756 | if (ret >= 0) { |
| 757 | pdev->pan_angle += pan; |
| 758 | pdev->tilt_angle += tilt; |
| 759 | } |
| 760 | if (ret == -EPIPE) /* stall -> out of range */ |
| 761 | ret = -ERANGE; |
| 762 | return ret; |
| 763 | } |
| 764 | |
| 765 | 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] | 766 | { |
| 767 | int ret; |
| 768 | unsigned char buf[5]; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 769 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 770 | ret = recv_control_msg(pdev, |
| 771 | GET_MPT_CTL, PT_STATUS_FORMATTER, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | if (ret < 0) |
| 773 | return ret; |
| 774 | status->status = buf[0] & 0x7; // 3 bits are used for reporting |
| 775 | status->time_pan = (buf[1] << 8) + buf[2]; |
| 776 | status->time_tilt = (buf[3] << 8) + buf[4]; |
| 777 | return 0; |
| 778 | } |
| 779 | |
Hans de Goede | 6eba935 | 2011-06-26 06:49:59 -0300 | [diff] [blame] | 780 | #ifdef CONFIG_USB_PWC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor) |
| 782 | { |
| 783 | unsigned char buf; |
| 784 | int ret = -1, request; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | if (pdev->type < 675) |
| 787 | request = SENSOR_TYPE_FORMATTER1; |
| 788 | else if (pdev->type < 730) |
| 789 | return -1; /* The Vesta series doesn't have this call */ |
| 790 | else |
| 791 | request = SENSOR_TYPE_FORMATTER2; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 792 | |
Martin Fuzzey | 6b35ca0 | 2009-04-21 21:48:09 +0200 | [diff] [blame] | 793 | ret = recv_control_msg(pdev, |
| 794 | GET_STATUS_CTL, request, &buf, sizeof(buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | if (ret < 0) |
| 796 | return ret; |
| 797 | if (pdev->type < 675) |
| 798 | *sensor = buf | 0x100; |
| 799 | else |
| 800 | *sensor = buf; |
| 801 | return 0; |
| 802 | } |
Hans de Goede | 6eba935 | 2011-06-26 06:49:59 -0300 | [diff] [blame] | 803 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
| 805 | /* End of Add-Ons */ |
| 806 | /* ************************************************* */ |
| 807 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 808 | /* Linux 2.5.something and 2.6 pass direct pointers to arguments of |
| 809 | ioctl() calls. With 2.4, you have to do tedious copy_from_user() |
| 810 | and copy_to_user() calls. With these macros we circumvent this, |
| 811 | and let me maintain only one source file. The functionality is |
| 812 | exactly the same otherwise. |
| 813 | */ |
| 814 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 815 | /* define local variable for arg */ |
| 816 | #define ARG_DEF(ARG_type, ARG_name)\ |
| 817 | ARG_type *ARG_name = arg; |
| 818 | /* copy arg to local variable */ |
| 819 | #define ARG_IN(ARG_name) /* nothing */ |
| 820 | /* argument itself (referenced) */ |
| 821 | #define ARGR(ARG_name) (*ARG_name) |
| 822 | /* argument address */ |
| 823 | #define ARGA(ARG_name) ARG_name |
| 824 | /* copy local variable to arg */ |
| 825 | #define ARG_OUT(ARG_name) /* nothing */ |
| 826 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 827 | /* |
| 828 | * Our ctrls use native values, but the old custom pwc ioctl interface expects |
| 829 | * values from 0 - 65535, define 2 helper functions to scale things. */ |
| 830 | static int pwc_ioctl_g_ctrl(struct v4l2_ctrl *ctrl) |
| 831 | { |
| 832 | return v4l2_ctrl_g_ctrl(ctrl) * 65535 / ctrl->maximum; |
| 833 | } |
| 834 | |
| 835 | static int pwc_ioctl_s_ctrl(struct v4l2_ctrl *ctrl, int val) |
| 836 | { |
| 837 | return v4l2_ctrl_s_ctrl(ctrl, val * ctrl->maximum / 65535); |
| 838 | } |
| 839 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 840 | long pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 842 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | switch(cmd) { |
| 845 | case VIDIOCPWCRUSER: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 846 | ret = pwc_button_ctrl(pdev, RESTORE_USER_DEFAULTS_FORMATTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | break; |
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 | case VIDIOCPWCSUSER: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 850 | ret = pwc_button_ctrl(pdev, SAVE_USER_DEFAULTS_FORMATTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | case VIDIOCPWCFACTORY: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 854 | ret = pwc_button_ctrl(pdev, RESTORE_FACTORY_DEFAULTS_FORMATTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | case VIDIOCPWCSCQUAL: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 858 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 859 | ARG_DEF(int, qual) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 861 | if (vb2_is_streaming(&pdev->vb_queue)) { |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 862 | ret = -EBUSY; |
| 863 | break; |
| 864 | } |
| 865 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 866 | ARG_IN(qual) |
| 867 | if (ARGR(qual) < 0 || ARGR(qual) > 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | ret = -EINVAL; |
| 869 | else |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 870 | 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] | 871 | break; |
| 872 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | case VIDIOCPWCGCQUAL: |
| 875 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 876 | ARG_DEF(int, qual) |
| 877 | |
| 878 | ARGR(qual) = pdev->vcompression; |
| 879 | ARG_OUT(qual) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | break; |
| 881 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | case VIDIOCPWCPROBE: |
| 884 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 885 | ARG_DEF(struct pwc_probe, probe) |
| 886 | |
Hans de Goede | 9a7b2d1 | 2011-06-06 14:43:39 -0300 | [diff] [blame] | 887 | strcpy(ARGR(probe).name, pdev->vdev.name); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 888 | ARGR(probe).type = pdev->type; |
| 889 | ARG_OUT(probe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | break; |
| 891 | } |
| 892 | |
| 893 | case VIDIOCPWCGSERIAL: |
| 894 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 895 | ARG_DEF(struct pwc_serial, serial) |
| 896 | |
| 897 | strcpy(ARGR(serial).serial, pdev->serial); |
| 898 | ARG_OUT(serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | break; |
| 900 | } |
| 901 | |
| 902 | case VIDIOCPWCSAGC: |
| 903 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 904 | ARG_DEF(int, agc) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 905 | ARG_IN(agc) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 906 | ret = v4l2_ctrl_s_ctrl(pdev->autogain, ARGR(agc) < 0); |
| 907 | if (ret == 0 && ARGR(agc) >= 0) |
| 908 | ret = pwc_ioctl_s_ctrl(pdev->gain, ARGR(agc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | break; |
| 910 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | case VIDIOCPWCGAGC: |
| 913 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 914 | ARG_DEF(int, agc) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 915 | if (v4l2_ctrl_g_ctrl(pdev->autogain)) |
| 916 | ARGR(agc) = -1; |
| 917 | else |
| 918 | ARGR(agc) = pwc_ioctl_g_ctrl(pdev->gain); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 919 | ARG_OUT(agc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | break; |
| 921 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | case VIDIOCPWCSSHUTTER: |
| 924 | { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 925 | ARG_DEF(int, shutter) |
| 926 | ARG_IN(shutter) |
| 927 | ret = v4l2_ctrl_s_ctrl(pdev->exposure_auto, |
| 928 | /* Menu idx 0 = auto, idx 1 = manual */ |
| 929 | ARGR(shutter) >= 0); |
| 930 | if (ret == 0 && ARGR(shutter) >= 0) |
| 931 | ret = pwc_ioctl_s_ctrl(pdev->exposure, ARGR(shutter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | break; |
| 933 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 934 | |
| 935 | case VIDIOCPWCSAWB: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 937 | ARG_DEF(struct pwc_whitebalance, wb) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 938 | ARG_IN(wb) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 939 | ret = v4l2_ctrl_s_ctrl(pdev->auto_white_balance, |
| 940 | ARGR(wb).mode); |
| 941 | if (ret == 0 && ARGR(wb).mode == PWC_WB_MANUAL) |
| 942 | ret = pwc_ioctl_s_ctrl(pdev->red_balance, |
| 943 | ARGR(wb).manual_red); |
| 944 | if (ret == 0 && ARGR(wb).mode == PWC_WB_MANUAL) |
| 945 | ret = pwc_ioctl_s_ctrl(pdev->blue_balance, |
| 946 | ARGR(wb).manual_blue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | break; |
| 948 | } |
| 949 | |
| 950 | case VIDIOCPWCGAWB: |
| 951 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 952 | ARG_DEF(struct pwc_whitebalance, wb) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 953 | ARGR(wb).mode = v4l2_ctrl_g_ctrl(pdev->auto_white_balance); |
| 954 | ARGR(wb).manual_red = ARGR(wb).read_red = |
| 955 | pwc_ioctl_g_ctrl(pdev->red_balance); |
| 956 | ARGR(wb).manual_blue = ARGR(wb).read_blue = |
| 957 | pwc_ioctl_g_ctrl(pdev->blue_balance); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 958 | ARG_OUT(wb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | break; |
| 960 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | case VIDIOCPWCSAWBSPEED: |
| 963 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 964 | ARG_DEF(struct pwc_wb_speed, wbs) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 965 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 966 | if (ARGR(wbs).control_speed > 0) { |
| 967 | ret = pwc_set_wb_speed(pdev, ARGR(wbs).control_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 969 | if (ARGR(wbs).control_delay > 0) { |
| 970 | ret = pwc_set_wb_delay(pdev, ARGR(wbs).control_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | break; |
| 973 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | case VIDIOCPWCGAWBSPEED: |
| 976 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 977 | ARG_DEF(struct pwc_wb_speed, wbs) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 978 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 979 | ret = pwc_get_wb_speed(pdev, &ARGR(wbs).control_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | if (ret < 0) |
| 981 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 982 | ret = pwc_get_wb_delay(pdev, &ARGR(wbs).control_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | if (ret < 0) |
| 984 | break; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 985 | ARG_OUT(wbs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | break; |
| 987 | } |
| 988 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 989 | case VIDIOCPWCSLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 991 | ARG_DEF(struct pwc_leds, leds) |
| 992 | |
| 993 | ARG_IN(leds) |
| 994 | 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] | 995 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | |
| 999 | case VIDIOCPWCGLED: |
| 1000 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1001 | ARG_DEF(struct pwc_leds, leds) |
| 1002 | |
| 1003 | ret = pwc_get_leds(pdev, &ARGR(leds).led_on, &ARGR(leds).led_off); |
| 1004 | ARG_OUT(leds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | break; |
| 1006 | } |
| 1007 | |
| 1008 | case VIDIOCPWCSCONTOUR: |
| 1009 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1010 | ARG_DEF(int, contour) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1011 | ARG_IN(contour) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1012 | ret = v4l2_ctrl_s_ctrl(pdev->autocontour, ARGR(contour) < 0); |
| 1013 | if (ret == 0 && ARGR(contour) >= 0) |
| 1014 | ret = pwc_ioctl_s_ctrl(pdev->contour, ARGR(contour)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | break; |
| 1016 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | case VIDIOCPWCGCONTOUR: |
| 1019 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1020 | ARG_DEF(int, contour) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1021 | if (v4l2_ctrl_g_ctrl(pdev->autocontour)) |
| 1022 | ARGR(contour) = -1; |
| 1023 | else |
| 1024 | ARGR(contour) = pwc_ioctl_g_ctrl(pdev->contour); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1025 | ARG_OUT(contour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | break; |
| 1027 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | case VIDIOCPWCSBACKLIGHT: |
| 1030 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1031 | ARG_DEF(int, backlight) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1032 | ARG_IN(backlight) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1033 | ret = v4l2_ctrl_s_ctrl(pdev->backlight, ARGR(backlight)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | case VIDIOCPWCGBACKLIGHT: |
| 1038 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1039 | ARG_DEF(int, backlight) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1040 | ARGR(backlight) = v4l2_ctrl_g_ctrl(pdev->backlight); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1041 | ARG_OUT(backlight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | break; |
| 1043 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | case VIDIOCPWCSFLICKER: |
| 1046 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1047 | ARG_DEF(int, flicker) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1048 | ARG_IN(flicker) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1049 | ret = v4l2_ctrl_s_ctrl(pdev->flicker, ARGR(flicker)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | break; |
| 1051 | } |
| 1052 | |
| 1053 | case VIDIOCPWCGFLICKER: |
| 1054 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1055 | ARG_DEF(int, flicker) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1056 | ARGR(flicker) = v4l2_ctrl_g_ctrl(pdev->flicker); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1057 | ARG_OUT(flicker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | break; |
| 1059 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | case VIDIOCPWCSDYNNOISE: |
| 1062 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1063 | ARG_DEF(int, dynnoise) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1064 | ARG_IN(dynnoise) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1065 | ret = v4l2_ctrl_s_ctrl(pdev->noise_reduction, ARGR(dynnoise)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | break; |
| 1067 | } |
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 | case VIDIOCPWCGDYNNOISE: |
| 1070 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1071 | ARG_DEF(int, dynnoise) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 1072 | ARGR(dynnoise) = v4l2_ctrl_g_ctrl(pdev->noise_reduction); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1073 | ARG_OUT(dynnoise); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | break; |
| 1075 | } |
| 1076 | |
| 1077 | case VIDIOCPWCGREALSIZE: |
| 1078 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1079 | ARG_DEF(struct pwc_imagesize, size) |
| 1080 | |
| 1081 | ARGR(size).width = pdev->image.x; |
| 1082 | ARGR(size).height = pdev->image.y; |
| 1083 | ARG_OUT(size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | case VIDIOCPWCMPTRESET: |
| 1088 | { |
| 1089 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1090 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1091 | ARG_DEF(int, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1093 | ARG_IN(flags) |
| 1094 | ret = pwc_mpt_reset(pdev, ARGR(flags)); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1095 | } |
| 1096 | else |
| 1097 | { |
| 1098 | ret = -ENXIO; |
| 1099 | } |
| 1100 | break; |
| 1101 | } |
| 1102 | |
| 1103 | case VIDIOCPWCMPTGRANGE: |
| 1104 | { |
| 1105 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1106 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1107 | ARG_DEF(struct pwc_mpt_range, range) |
| 1108 | |
| 1109 | ARGR(range) = pdev->angle_range; |
| 1110 | ARG_OUT(range) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1111 | } |
| 1112 | else |
| 1113 | { |
| 1114 | ret = -ENXIO; |
| 1115 | } |
| 1116 | break; |
| 1117 | } |
| 1118 | |
| 1119 | case VIDIOCPWCMPTSANGLE: |
| 1120 | { |
| 1121 | int new_pan, new_tilt; |
| 1122 | |
| 1123 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1124 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1125 | ARG_DEF(struct pwc_mpt_angles, angles) |
| 1126 | |
| 1127 | ARG_IN(angles) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | /* The camera can only set relative angles, so |
| 1129 | do some calculations when getting an absolute angle . |
| 1130 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1131 | if (ARGR(angles).absolute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1133 | new_pan = ARGR(angles).pan; |
| 1134 | new_tilt = ARGR(angles).tilt; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1135 | } |
| 1136 | else |
| 1137 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1138 | new_pan = pdev->pan_angle + ARGR(angles).pan; |
| 1139 | new_tilt = pdev->tilt_angle + ARGR(angles).tilt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1141 | ret = pwc_mpt_set_angle(pdev, new_pan, new_tilt); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | ret = -ENXIO; |
| 1146 | } |
| 1147 | break; |
| 1148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1150 | case VIDIOCPWCMPTGANGLE: |
| 1151 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1153 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1154 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1155 | ARG_DEF(struct pwc_mpt_angles, angles) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1156 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1157 | ARGR(angles).absolute = 1; |
| 1158 | ARGR(angles).pan = pdev->pan_angle; |
| 1159 | ARGR(angles).tilt = pdev->tilt_angle; |
| 1160 | ARG_OUT(angles) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | ret = -ENXIO; |
| 1165 | } |
| 1166 | break; |
| 1167 | } |
| 1168 | |
| 1169 | case VIDIOCPWCMPTSTATUS: |
| 1170 | { |
| 1171 | if (pdev->features & FEATURE_MOTOR_PANTILT) |
| 1172 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1173 | ARG_DEF(struct pwc_mpt_status, status) |
| 1174 | |
| 1175 | ret = pwc_mpt_get_status(pdev, ARGA(status)); |
| 1176 | ARG_OUT(status) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1177 | } |
| 1178 | else |
| 1179 | { |
| 1180 | ret = -ENXIO; |
| 1181 | } |
| 1182 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | case VIDIOCPWCGVIDCMD: |
| 1186 | { |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1187 | ARG_DEF(struct pwc_video_command, vcmd); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1188 | |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1189 | ARGR(vcmd).type = pdev->type; |
| 1190 | ARGR(vcmd).release = pdev->release; |
| 1191 | ARGR(vcmd).command_len = pdev->cmd_len; |
| 1192 | memcpy(&ARGR(vcmd).command_buf, pdev->cmd_buf, pdev->cmd_len); |
| 1193 | ARGR(vcmd).bandlength = pdev->vbandlength; |
| 1194 | ARGR(vcmd).frame_size = pdev->frame_size; |
| 1195 | ARG_OUT(vcmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | break; |
| 1197 | } |
Michael Krufky | b930e1d | 2007-08-27 18:16:54 -0300 | [diff] [blame] | 1198 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | case VIDIOCPWCGVIDTABLE: |
| 1200 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1201 | ARG_DEF(struct pwc_table_init_buffer, table); |
| 1202 | ARGR(table).len = pdev->cmd_len; |
| 1203 | memcpy(&ARGR(table).buffer, pdev->decompress_data, pdev->decompressor->table_size); |
| 1204 | ARG_OUT(table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | break; |
| 1206 | } |
| 1207 | */ |
| 1208 | |
| 1209 | default: |
| 1210 | ret = -ENOIOCTLCMD; |
| 1211 | break; |
| 1212 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | if (ret > 0) |
| 1215 | return 0; |
| 1216 | return ret; |
| 1217 | } |
| 1218 | |
| 1219 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1220 | /* vim: set cinoptions= formatoptions=croql cindent shiftwidth=8 tabstop=8: */ |