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