Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 1 | /* Linux driver for Philips webcam |
| 2 | USB and Video4Linux interface part. |
| 3 | (C) 1999-2004 Nemosoft Unv. |
| 4 | (C) 2004-2006 Luc Saillard (luc@saillard.org) |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 5 | (C) 2011 Hans de Goede <hdegoede@redhat.com> |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 6 | |
| 7 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx |
| 8 | driver and thus may have bugs that are not present in the original version. |
| 9 | Please send bug reports and support requests to <luc@saillard.org>. |
| 10 | The decompression routines have been implemented by reverse-engineering the |
| 11 | Nemosoft binary pwcx module. Caveat emptor. |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or modify |
| 14 | it under the terms of the GNU General Public License as published by |
| 15 | the Free Software Foundation; either version 2 of the License, or |
| 16 | (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, |
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | GNU General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | |
| 27 | */ |
| 28 | |
| 29 | #include <linux/errno.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/mm.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/poll.h> |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 34 | #include <linux/vmalloc.h> |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 35 | #include <linux/jiffies.h> |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 36 | #include <asm/io.h> |
| 37 | |
| 38 | #include "pwc.h" |
| 39 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 40 | #define PWC_CID_CUSTOM(ctrl) ((V4L2_CID_USER_BASE | 0xf000) + custom_ ## ctrl) |
| 41 | |
| 42 | static int pwc_g_volatile_ctrl(struct v4l2_ctrl *ctrl); |
| 43 | static int pwc_s_ctrl(struct v4l2_ctrl *ctrl); |
| 44 | |
| 45 | static const struct v4l2_ctrl_ops pwc_ctrl_ops = { |
| 46 | .g_volatile_ctrl = pwc_g_volatile_ctrl, |
| 47 | .s_ctrl = pwc_s_ctrl, |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 48 | }; |
| 49 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 50 | enum { awb_indoor, awb_outdoor, awb_fl, awb_manual, awb_auto }; |
| 51 | enum { custom_autocontour, custom_contour, custom_noise_reduction, |
Hans de Goede | f4af6595 | 2011-10-09 09:56:23 -0300 | [diff] [blame] | 52 | custom_awb_speed, custom_awb_delay, |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 53 | custom_save_user, custom_restore_user, custom_restore_factory }; |
| 54 | |
Hans Verkuil | 2954192 | 2014-08-20 19:28:02 -0300 | [diff] [blame] | 55 | static const char * const pwc_auto_whitebal_qmenu[] = { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 56 | "Indoor (Incandescant Lighting) Mode", |
| 57 | "Outdoor (Sunlight) Mode", |
| 58 | "Indoor (Fluorescent Lighting) Mode", |
| 59 | "Manual Mode", |
| 60 | "Auto Mode", |
| 61 | NULL |
| 62 | }; |
| 63 | |
| 64 | static const struct v4l2_ctrl_config pwc_auto_white_balance_cfg = { |
| 65 | .ops = &pwc_ctrl_ops, |
| 66 | .id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 67 | .type = V4L2_CTRL_TYPE_MENU, |
| 68 | .max = awb_auto, |
| 69 | .qmenu = pwc_auto_whitebal_qmenu, |
| 70 | }; |
| 71 | |
| 72 | static const struct v4l2_ctrl_config pwc_autocontour_cfg = { |
| 73 | .ops = &pwc_ctrl_ops, |
| 74 | .id = PWC_CID_CUSTOM(autocontour), |
| 75 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 76 | .name = "Auto contour", |
| 77 | .min = 0, |
| 78 | .max = 1, |
| 79 | .step = 1, |
| 80 | }; |
| 81 | |
| 82 | static const struct v4l2_ctrl_config pwc_contour_cfg = { |
| 83 | .ops = &pwc_ctrl_ops, |
| 84 | .id = PWC_CID_CUSTOM(contour), |
| 85 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 86 | .name = "Contour", |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 87 | .flags = V4L2_CTRL_FLAG_SLIDER, |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 88 | .min = 0, |
| 89 | .max = 63, |
| 90 | .step = 1, |
| 91 | }; |
| 92 | |
| 93 | static const struct v4l2_ctrl_config pwc_backlight_cfg = { |
| 94 | .ops = &pwc_ctrl_ops, |
| 95 | .id = V4L2_CID_BACKLIGHT_COMPENSATION, |
| 96 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 97 | .min = 0, |
| 98 | .max = 1, |
| 99 | .step = 1, |
| 100 | }; |
| 101 | |
| 102 | static const struct v4l2_ctrl_config pwc_flicker_cfg = { |
| 103 | .ops = &pwc_ctrl_ops, |
| 104 | .id = V4L2_CID_BAND_STOP_FILTER, |
| 105 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 106 | .min = 0, |
| 107 | .max = 1, |
| 108 | .step = 1, |
| 109 | }; |
| 110 | |
| 111 | static const struct v4l2_ctrl_config pwc_noise_reduction_cfg = { |
| 112 | .ops = &pwc_ctrl_ops, |
| 113 | .id = PWC_CID_CUSTOM(noise_reduction), |
| 114 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 115 | .name = "Dynamic Noise Reduction", |
| 116 | .min = 0, |
| 117 | .max = 3, |
| 118 | .step = 1, |
| 119 | }; |
| 120 | |
| 121 | static const struct v4l2_ctrl_config pwc_save_user_cfg = { |
| 122 | .ops = &pwc_ctrl_ops, |
| 123 | .id = PWC_CID_CUSTOM(save_user), |
| 124 | .type = V4L2_CTRL_TYPE_BUTTON, |
| 125 | .name = "Save User Settings", |
| 126 | }; |
| 127 | |
| 128 | static const struct v4l2_ctrl_config pwc_restore_user_cfg = { |
| 129 | .ops = &pwc_ctrl_ops, |
| 130 | .id = PWC_CID_CUSTOM(restore_user), |
| 131 | .type = V4L2_CTRL_TYPE_BUTTON, |
| 132 | .name = "Restore User Settings", |
| 133 | }; |
| 134 | |
| 135 | static const struct v4l2_ctrl_config pwc_restore_factory_cfg = { |
| 136 | .ops = &pwc_ctrl_ops, |
| 137 | .id = PWC_CID_CUSTOM(restore_factory), |
| 138 | .type = V4L2_CTRL_TYPE_BUTTON, |
| 139 | .name = "Restore Factory Settings", |
| 140 | }; |
| 141 | |
Hans de Goede | f4af6595 | 2011-10-09 09:56:23 -0300 | [diff] [blame] | 142 | static const struct v4l2_ctrl_config pwc_awb_speed_cfg = { |
| 143 | .ops = &pwc_ctrl_ops, |
| 144 | .id = PWC_CID_CUSTOM(awb_speed), |
| 145 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 146 | .name = "Auto White Balance Speed", |
| 147 | .min = 1, |
| 148 | .max = 32, |
| 149 | .step = 1, |
| 150 | }; |
| 151 | |
| 152 | static const struct v4l2_ctrl_config pwc_awb_delay_cfg = { |
| 153 | .ops = &pwc_ctrl_ops, |
| 154 | .id = PWC_CID_CUSTOM(awb_delay), |
| 155 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 156 | .name = "Auto White Balance Delay", |
| 157 | .min = 0, |
| 158 | .max = 63, |
| 159 | .step = 1, |
| 160 | }; |
| 161 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 162 | int pwc_init_controls(struct pwc_device *pdev) |
| 163 | { |
| 164 | struct v4l2_ctrl_handler *hdl; |
| 165 | struct v4l2_ctrl_config cfg; |
| 166 | int r, def; |
| 167 | |
| 168 | hdl = &pdev->ctrl_handler; |
| 169 | r = v4l2_ctrl_handler_init(hdl, 20); |
| 170 | if (r) |
| 171 | return r; |
| 172 | |
| 173 | /* Brightness, contrast, saturation, gamma */ |
| 174 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, BRIGHTNESS_FORMATTER, &def); |
| 175 | if (r || def > 127) |
| 176 | def = 63; |
| 177 | pdev->brightness = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 178 | V4L2_CID_BRIGHTNESS, 0, 127, 1, def); |
| 179 | |
| 180 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, CONTRAST_FORMATTER, &def); |
| 181 | if (r || def > 63) |
| 182 | def = 31; |
| 183 | pdev->contrast = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 184 | V4L2_CID_CONTRAST, 0, 63, 1, def); |
| 185 | |
| 186 | if (pdev->type >= 675) { |
| 187 | if (pdev->type < 730) |
| 188 | pdev->saturation_fmt = SATURATION_MODE_FORMATTER2; |
| 189 | else |
| 190 | pdev->saturation_fmt = SATURATION_MODE_FORMATTER1; |
| 191 | r = pwc_get_s8_ctrl(pdev, GET_CHROM_CTL, pdev->saturation_fmt, |
| 192 | &def); |
| 193 | if (r || def < -100 || def > 100) |
| 194 | def = 0; |
| 195 | pdev->saturation = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 196 | V4L2_CID_SATURATION, -100, 100, 1, def); |
| 197 | } |
| 198 | |
| 199 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, GAMMA_FORMATTER, &def); |
| 200 | if (r || def > 31) |
| 201 | def = 15; |
| 202 | pdev->gamma = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 203 | V4L2_CID_GAMMA, 0, 31, 1, def); |
| 204 | |
| 205 | /* auto white balance, red gain, blue gain */ |
| 206 | r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, WB_MODE_FORMATTER, &def); |
| 207 | if (r || def > awb_auto) |
| 208 | def = awb_auto; |
| 209 | cfg = pwc_auto_white_balance_cfg; |
| 210 | cfg.name = v4l2_ctrl_get_name(cfg.id); |
| 211 | cfg.def = def; |
| 212 | pdev->auto_white_balance = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 213 | /* check auto controls to avoid NULL deref in v4l2_ctrl_auto_cluster */ |
| 214 | if (!pdev->auto_white_balance) |
| 215 | return hdl->error; |
| 216 | |
| 217 | r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, |
| 218 | PRESET_MANUAL_RED_GAIN_FORMATTER, &def); |
| 219 | if (r) |
| 220 | def = 127; |
| 221 | pdev->red_balance = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 222 | V4L2_CID_RED_BALANCE, 0, 255, 1, def); |
| 223 | |
| 224 | r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, |
| 225 | PRESET_MANUAL_BLUE_GAIN_FORMATTER, &def); |
| 226 | if (r) |
| 227 | def = 127; |
| 228 | pdev->blue_balance = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 229 | V4L2_CID_BLUE_BALANCE, 0, 255, 1, def); |
| 230 | |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 231 | v4l2_ctrl_auto_cluster(3, &pdev->auto_white_balance, awb_manual, true); |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 232 | |
| 233 | /* autogain, gain */ |
| 234 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, AGC_MODE_FORMATTER, &def); |
| 235 | if (r || (def != 0 && def != 0xff)) |
| 236 | def = 0; |
| 237 | /* Note a register value if 0 means auto gain is on */ |
| 238 | pdev->autogain = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 239 | V4L2_CID_AUTOGAIN, 0, 1, 1, def == 0); |
| 240 | if (!pdev->autogain) |
| 241 | return hdl->error; |
| 242 | |
| 243 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, PRESET_AGC_FORMATTER, &def); |
| 244 | if (r || def > 63) |
| 245 | def = 31; |
| 246 | pdev->gain = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 247 | V4L2_CID_GAIN, 0, 63, 1, def); |
| 248 | |
| 249 | /* auto exposure, exposure */ |
| 250 | if (DEVICE_USE_CODEC2(pdev->type)) { |
| 251 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, SHUTTER_MODE_FORMATTER, |
| 252 | &def); |
| 253 | if (r || (def != 0 && def != 0xff)) |
| 254 | def = 0; |
| 255 | /* |
| 256 | * def = 0 auto, def = ff manual |
| 257 | * menu idx 0 = auto, idx 1 = manual |
| 258 | */ |
| 259 | pdev->exposure_auto = v4l2_ctrl_new_std_menu(hdl, |
| 260 | &pwc_ctrl_ops, |
| 261 | V4L2_CID_EXPOSURE_AUTO, |
| 262 | 1, 0, def != 0); |
| 263 | if (!pdev->exposure_auto) |
| 264 | return hdl->error; |
| 265 | |
| 266 | /* GET_LUM_CTL, PRESET_SHUTTER_FORMATTER is unreliable */ |
| 267 | r = pwc_get_u16_ctrl(pdev, GET_STATUS_CTL, |
| 268 | READ_SHUTTER_FORMATTER, &def); |
| 269 | if (r || def > 655) |
| 270 | def = 655; |
| 271 | pdev->exposure = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 272 | V4L2_CID_EXPOSURE, 0, 655, 1, def); |
| 273 | /* CODEC2: separate auto gain & auto exposure */ |
| 274 | v4l2_ctrl_auto_cluster(2, &pdev->autogain, 0, true); |
| 275 | v4l2_ctrl_auto_cluster(2, &pdev->exposure_auto, |
| 276 | V4L2_EXPOSURE_MANUAL, true); |
| 277 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
| 278 | /* GET_LUM_CTL, PRESET_SHUTTER_FORMATTER is unreliable */ |
| 279 | r = pwc_get_u16_ctrl(pdev, GET_STATUS_CTL, |
| 280 | READ_SHUTTER_FORMATTER, &def); |
| 281 | if (r || def > 255) |
| 282 | def = 255; |
| 283 | pdev->exposure = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 284 | V4L2_CID_EXPOSURE, 0, 255, 1, def); |
| 285 | /* CODEC3: both gain and exposure controlled by autogain */ |
| 286 | pdev->autogain_expo_cluster[0] = pdev->autogain; |
| 287 | pdev->autogain_expo_cluster[1] = pdev->gain; |
| 288 | pdev->autogain_expo_cluster[2] = pdev->exposure; |
| 289 | v4l2_ctrl_auto_cluster(3, pdev->autogain_expo_cluster, |
| 290 | 0, true); |
| 291 | } |
| 292 | |
| 293 | /* color / bw setting */ |
| 294 | r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, COLOUR_MODE_FORMATTER, |
| 295 | &def); |
| 296 | if (r || (def != 0 && def != 0xff)) |
| 297 | def = 0xff; |
| 298 | /* def = 0 bw, def = ff color, menu idx 0 = color, idx 1 = bw */ |
| 299 | pdev->colorfx = v4l2_ctrl_new_std_menu(hdl, &pwc_ctrl_ops, |
| 300 | V4L2_CID_COLORFX, 1, 0, def == 0); |
| 301 | |
| 302 | /* autocontour, contour */ |
| 303 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, &def); |
| 304 | if (r || (def != 0 && def != 0xff)) |
| 305 | def = 0; |
| 306 | cfg = pwc_autocontour_cfg; |
| 307 | cfg.def = def == 0; |
| 308 | pdev->autocontour = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 309 | if (!pdev->autocontour) |
| 310 | return hdl->error; |
| 311 | |
| 312 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, &def); |
| 313 | if (r || def > 63) |
| 314 | def = 31; |
| 315 | cfg = pwc_contour_cfg; |
| 316 | cfg.def = def; |
| 317 | pdev->contour = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 318 | |
| 319 | v4l2_ctrl_auto_cluster(2, &pdev->autocontour, 0, false); |
| 320 | |
| 321 | /* backlight */ |
| 322 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, |
| 323 | BACK_LIGHT_COMPENSATION_FORMATTER, &def); |
| 324 | if (r || (def != 0 && def != 0xff)) |
| 325 | def = 0; |
| 326 | cfg = pwc_backlight_cfg; |
| 327 | cfg.name = v4l2_ctrl_get_name(cfg.id); |
| 328 | cfg.def = def == 0; |
| 329 | pdev->backlight = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 330 | |
| 331 | /* flikker rediction */ |
| 332 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, |
| 333 | FLICKERLESS_MODE_FORMATTER, &def); |
| 334 | if (r || (def != 0 && def != 0xff)) |
| 335 | def = 0; |
| 336 | cfg = pwc_flicker_cfg; |
| 337 | cfg.name = v4l2_ctrl_get_name(cfg.id); |
| 338 | cfg.def = def == 0; |
| 339 | pdev->flicker = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 340 | |
| 341 | /* Dynamic noise reduction */ |
| 342 | r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, |
| 343 | DYNAMIC_NOISE_CONTROL_FORMATTER, &def); |
| 344 | if (r || def > 3) |
| 345 | def = 2; |
| 346 | cfg = pwc_noise_reduction_cfg; |
| 347 | cfg.def = def; |
| 348 | pdev->noise_reduction = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 349 | |
| 350 | /* Save / Restore User / Factory Settings */ |
| 351 | pdev->save_user = v4l2_ctrl_new_custom(hdl, &pwc_save_user_cfg, NULL); |
| 352 | pdev->restore_user = v4l2_ctrl_new_custom(hdl, &pwc_restore_user_cfg, |
| 353 | NULL); |
| 354 | if (pdev->restore_user) |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 355 | pdev->restore_user->flags |= V4L2_CTRL_FLAG_UPDATE; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 356 | pdev->restore_factory = v4l2_ctrl_new_custom(hdl, |
| 357 | &pwc_restore_factory_cfg, |
| 358 | NULL); |
| 359 | if (pdev->restore_factory) |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 360 | pdev->restore_factory->flags |= V4L2_CTRL_FLAG_UPDATE; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 361 | |
Hans de Goede | f4af6595 | 2011-10-09 09:56:23 -0300 | [diff] [blame] | 362 | /* Auto White Balance speed & delay */ |
| 363 | r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, |
| 364 | AWB_CONTROL_SPEED_FORMATTER, &def); |
| 365 | if (r || def < 1 || def > 32) |
| 366 | def = 1; |
| 367 | cfg = pwc_awb_speed_cfg; |
| 368 | cfg.def = def; |
| 369 | pdev->awb_speed = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 370 | |
| 371 | r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, |
| 372 | AWB_CONTROL_DELAY_FORMATTER, &def); |
| 373 | if (r || def > 63) |
| 374 | def = 0; |
| 375 | cfg = pwc_awb_delay_cfg; |
| 376 | cfg.def = def; |
| 377 | pdev->awb_delay = v4l2_ctrl_new_custom(hdl, &cfg, NULL); |
| 378 | |
Dan Carpenter | 4264a8b | 2011-07-23 15:53:03 -0300 | [diff] [blame] | 379 | if (!(pdev->features & FEATURE_MOTOR_PANTILT)) |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 380 | return hdl->error; |
| 381 | |
| 382 | /* Motor pan / tilt / reset */ |
| 383 | pdev->motor_pan = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 384 | V4L2_CID_PAN_RELATIVE, -4480, 4480, 64, 0); |
| 385 | if (!pdev->motor_pan) |
| 386 | return hdl->error; |
| 387 | pdev->motor_tilt = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 388 | V4L2_CID_TILT_RELATIVE, -1920, 1920, 64, 0); |
| 389 | pdev->motor_pan_reset = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 390 | V4L2_CID_PAN_RESET, 0, 0, 0, 0); |
| 391 | pdev->motor_tilt_reset = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops, |
| 392 | V4L2_CID_TILT_RESET, 0, 0, 0, 0); |
| 393 | v4l2_ctrl_cluster(4, &pdev->motor_pan); |
| 394 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 395 | return hdl->error; |
| 396 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 397 | |
Hans de Goede | 31e582e | 2012-01-04 19:46:53 -0300 | [diff] [blame] | 398 | static void pwc_vidioc_fill_fmt(struct v4l2_format *f, |
| 399 | int width, int height, u32 pixfmt) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 400 | { |
| 401 | memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format)); |
Hans de Goede | 31e582e | 2012-01-04 19:46:53 -0300 | [diff] [blame] | 402 | f->fmt.pix.width = width; |
| 403 | f->fmt.pix.height = height; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 404 | f->fmt.pix.field = V4L2_FIELD_NONE; |
Hans de Goede | 31e582e | 2012-01-04 19:46:53 -0300 | [diff] [blame] | 405 | f->fmt.pix.pixelformat = pixfmt; |
| 406 | f->fmt.pix.bytesperline = f->fmt.pix.width; |
| 407 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.width * 3 / 2; |
Hans Verkuil | 387c71b | 2012-06-10 04:34:10 -0300 | [diff] [blame] | 408 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; |
Mauro Carvalho Chehab | c91e42f | 2016-10-18 17:44:18 -0200 | [diff] [blame^] | 409 | PWC_DEBUG_IOCTL("pwc_vidioc_fill_fmt() width=%d, height=%d, bytesperline=%d, sizeimage=%d, pixelformat=%c%c%c%c\n", |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 410 | f->fmt.pix.width, |
| 411 | f->fmt.pix.height, |
| 412 | f->fmt.pix.bytesperline, |
| 413 | f->fmt.pix.sizeimage, |
| 414 | (f->fmt.pix.pixelformat)&255, |
| 415 | (f->fmt.pix.pixelformat>>8)&255, |
| 416 | (f->fmt.pix.pixelformat>>16)&255, |
| 417 | (f->fmt.pix.pixelformat>>24)&255); |
| 418 | } |
| 419 | |
| 420 | /* ioctl(VIDIOC_TRY_FMT) */ |
| 421 | static int pwc_vidioc_try_fmt(struct pwc_device *pdev, struct v4l2_format *f) |
| 422 | { |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 423 | int size; |
| 424 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 425 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 426 | PWC_DEBUG_IOCTL("Bad video type must be V4L2_BUF_TYPE_VIDEO_CAPTURE\n"); |
| 427 | return -EINVAL; |
| 428 | } |
| 429 | |
| 430 | switch (f->fmt.pix.pixelformat) { |
| 431 | case V4L2_PIX_FMT_YUV420: |
| 432 | break; |
| 433 | case V4L2_PIX_FMT_PWC1: |
| 434 | if (DEVICE_USE_CODEC23(pdev->type)) { |
| 435 | PWC_DEBUG_IOCTL("codec1 is only supported for old pwc webcam\n"); |
Hans de Goede | f192747 | 2013-01-25 06:53:07 -0300 | [diff] [blame] | 436 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 437 | } |
| 438 | break; |
| 439 | case V4L2_PIX_FMT_PWC2: |
| 440 | if (DEVICE_USE_CODEC1(pdev->type)) { |
| 441 | PWC_DEBUG_IOCTL("codec23 is only supported for new pwc webcam\n"); |
Hans de Goede | f192747 | 2013-01-25 06:53:07 -0300 | [diff] [blame] | 442 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 443 | } |
| 444 | break; |
| 445 | default: |
| 446 | PWC_DEBUG_IOCTL("Unsupported pixel format\n"); |
Hans de Goede | f192747 | 2013-01-25 06:53:07 -0300 | [diff] [blame] | 447 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 448 | } |
| 449 | |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 450 | size = pwc_get_size(pdev, f->fmt.pix.width, f->fmt.pix.height); |
Hans de Goede | 31e582e | 2012-01-04 19:46:53 -0300 | [diff] [blame] | 451 | pwc_vidioc_fill_fmt(f, |
| 452 | pwc_image_sizes[size][0], |
| 453 | pwc_image_sizes[size][1], |
| 454 | f->fmt.pix.pixelformat); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /* ioctl(VIDIOC_SET_FMT) */ |
Hans de Goede | 4fba471 | 2011-06-26 12:13:44 -0300 | [diff] [blame] | 460 | |
| 461 | static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 462 | { |
Hans de Goede | 4fba471 | 2011-06-26 12:13:44 -0300 | [diff] [blame] | 463 | struct pwc_device *pdev = video_drvdata(file); |
Hans de Goede | 5bbe18d | 2012-01-04 18:48:05 -0300 | [diff] [blame] | 464 | int ret, pixelformat, compression = 0; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 465 | |
| 466 | ret = pwc_vidioc_try_fmt(pdev, f); |
Hans de Goede | c20d78c | 2011-10-09 09:16:46 -0300 | [diff] [blame] | 467 | if (ret < 0) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 468 | return ret; |
| 469 | |
Hans Verkuil | 2e43dec | 2012-07-02 05:51:58 -0300 | [diff] [blame] | 470 | if (vb2_is_busy(&pdev->vb_queue)) |
| 471 | return -EBUSY; |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 472 | |
Hans de Goede | ceede9f | 2012-05-09 04:43:12 -0300 | [diff] [blame] | 473 | pixelformat = f->fmt.pix.pixelformat; |
| 474 | |
Mauro Carvalho Chehab | c91e42f | 2016-10-18 17:44:18 -0200 | [diff] [blame^] | 475 | PWC_DEBUG_IOCTL("Trying to set format to: width=%d height=%d fps=%d format=%c%c%c%c\n", |
Hans de Goede | 115f418 | 2011-12-31 08:47:07 -0300 | [diff] [blame] | 476 | f->fmt.pix.width, f->fmt.pix.height, pdev->vframes, |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 477 | (pixelformat)&255, |
| 478 | (pixelformat>>8)&255, |
| 479 | (pixelformat>>16)&255, |
| 480 | (pixelformat>>24)&255); |
| 481 | |
Hans de Goede | 5bbe18d | 2012-01-04 18:48:05 -0300 | [diff] [blame] | 482 | ret = pwc_set_video_mode(pdev, f->fmt.pix.width, f->fmt.pix.height, |
Hans de Goede | 938d5b9 | 2012-01-10 13:14:46 -0300 | [diff] [blame] | 483 | pixelformat, 30, &compression, 0); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 484 | |
Hans de Goede | 3751e28 | 2010-11-16 11:39:25 -0300 | [diff] [blame] | 485 | PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 486 | |
Hans de Goede | d167a85 | 2012-01-10 13:01:41 -0300 | [diff] [blame] | 487 | pwc_vidioc_fill_fmt(f, pdev->width, pdev->height, pdev->pixfmt); |
Hans de Goede | c20d78c | 2011-10-09 09:16:46 -0300 | [diff] [blame] | 488 | return ret; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 489 | } |
| 490 | |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 491 | static int pwc_querycap(struct file *file, void *fh, struct v4l2_capability *cap) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 492 | { |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 493 | struct pwc_device *pdev = video_drvdata(file); |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 494 | |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 495 | strcpy(cap->driver, PWC_NAME); |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 496 | strlcpy(cap->card, pdev->vdev.name, sizeof(cap->card)); |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 497 | usb_make_path(pdev->udev, cap->bus_info, sizeof(cap->bus_info)); |
Hans Verkuil | 387c71b | 2012-06-10 04:34:10 -0300 | [diff] [blame] | 498 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | |
| 499 | V4L2_CAP_READWRITE; |
| 500 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 504 | static int pwc_enum_input(struct file *file, void *fh, struct v4l2_input *i) |
| 505 | { |
| 506 | if (i->index) /* Only one INPUT is supported */ |
| 507 | return -EINVAL; |
| 508 | |
Hans Verkuil | 387c71b | 2012-06-10 04:34:10 -0300 | [diff] [blame] | 509 | strlcpy(i->name, "Camera", sizeof(i->name)); |
| 510 | i->type = V4L2_INPUT_TYPE_CAMERA; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static int pwc_g_input(struct file *file, void *fh, unsigned int *i) |
| 515 | { |
| 516 | *i = 0; |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static int pwc_s_input(struct file *file, void *fh, unsigned int i) |
| 521 | { |
| 522 | return i ? -EINVAL : 0; |
| 523 | } |
| 524 | |
Hans de Goede | ceede9f | 2012-05-09 04:43:12 -0300 | [diff] [blame] | 525 | static int pwc_g_volatile_ctrl(struct v4l2_ctrl *ctrl) |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 526 | { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 527 | struct pwc_device *pdev = |
| 528 | container_of(ctrl->handler, struct pwc_device, ctrl_handler); |
| 529 | int ret = 0; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 530 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 531 | switch (ctrl->id) { |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 532 | case V4L2_CID_AUTO_WHITE_BALANCE: |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 533 | if (pdev->color_bal_valid && |
| 534 | (pdev->auto_white_balance->val != awb_auto || |
| 535 | time_before(jiffies, |
| 536 | pdev->last_color_bal_update + HZ / 4))) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 537 | pdev->red_balance->val = pdev->last_red_balance; |
| 538 | pdev->blue_balance->val = pdev->last_blue_balance; |
| 539 | break; |
| 540 | } |
| 541 | ret = pwc_get_u8_ctrl(pdev, GET_STATUS_CTL, |
| 542 | READ_RED_GAIN_FORMATTER, |
| 543 | &pdev->red_balance->val); |
| 544 | if (ret) |
| 545 | break; |
| 546 | ret = pwc_get_u8_ctrl(pdev, GET_STATUS_CTL, |
| 547 | READ_BLUE_GAIN_FORMATTER, |
| 548 | &pdev->blue_balance->val); |
| 549 | if (ret) |
| 550 | break; |
| 551 | pdev->last_red_balance = pdev->red_balance->val; |
| 552 | pdev->last_blue_balance = pdev->blue_balance->val; |
| 553 | pdev->last_color_bal_update = jiffies; |
| 554 | pdev->color_bal_valid = true; |
| 555 | break; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 556 | case V4L2_CID_AUTOGAIN: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 557 | if (pdev->gain_valid && time_before(jiffies, |
| 558 | pdev->last_gain_update + HZ / 4)) { |
| 559 | pdev->gain->val = pdev->last_gain; |
| 560 | break; |
| 561 | } |
| 562 | ret = pwc_get_u8_ctrl(pdev, GET_STATUS_CTL, |
| 563 | READ_AGC_FORMATTER, &pdev->gain->val); |
| 564 | if (ret) |
| 565 | break; |
| 566 | pdev->last_gain = pdev->gain->val; |
| 567 | pdev->last_gain_update = jiffies; |
| 568 | pdev->gain_valid = true; |
| 569 | if (!DEVICE_USE_CODEC3(pdev->type)) |
| 570 | break; |
| 571 | /* Fall through for CODEC3 where autogain also controls expo */ |
| 572 | case V4L2_CID_EXPOSURE_AUTO: |
| 573 | if (pdev->exposure_valid && time_before(jiffies, |
| 574 | pdev->last_exposure_update + HZ / 4)) { |
| 575 | pdev->exposure->val = pdev->last_exposure; |
| 576 | break; |
| 577 | } |
| 578 | ret = pwc_get_u16_ctrl(pdev, GET_STATUS_CTL, |
| 579 | READ_SHUTTER_FORMATTER, |
| 580 | &pdev->exposure->val); |
| 581 | if (ret) |
| 582 | break; |
| 583 | pdev->last_exposure = pdev->exposure->val; |
| 584 | pdev->last_exposure_update = jiffies; |
| 585 | pdev->exposure_valid = true; |
| 586 | break; |
| 587 | default: |
| 588 | ret = -EINVAL; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 589 | } |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 590 | |
| 591 | if (ret) |
| 592 | PWC_ERROR("g_ctrl %s error %d\n", ctrl->name, ret); |
| 593 | |
Hans de Goede | 6807cfc | 2011-10-09 17:22:00 -0300 | [diff] [blame] | 594 | return ret; |
| 595 | } |
| 596 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 597 | static int pwc_set_awb(struct pwc_device *pdev) |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 598 | { |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 599 | int ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 600 | |
| 601 | if (pdev->auto_white_balance->is_new) { |
| 602 | ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL, |
| 603 | WB_MODE_FORMATTER, |
| 604 | pdev->auto_white_balance->val); |
| 605 | if (ret) |
| 606 | return ret; |
| 607 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 608 | if (pdev->auto_white_balance->val != awb_manual) |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 609 | pdev->color_bal_valid = false; /* Force cache update */ |
Hans de Goede | 6807cfc | 2011-10-09 17:22:00 -0300 | [diff] [blame] | 610 | |
| 611 | /* |
| 612 | * If this is a preset, update our red / blue balance values |
| 613 | * so that events get generated for the new preset values |
| 614 | */ |
| 615 | if (pdev->auto_white_balance->val == awb_indoor || |
| 616 | pdev->auto_white_balance->val == awb_outdoor || |
| 617 | pdev->auto_white_balance->val == awb_fl) |
Hans de Goede | ceede9f | 2012-05-09 04:43:12 -0300 | [diff] [blame] | 618 | pwc_g_volatile_ctrl(pdev->auto_white_balance); |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 619 | } |
| 620 | if (pdev->auto_white_balance->val != awb_manual) |
| 621 | return 0; |
| 622 | |
| 623 | if (pdev->red_balance->is_new) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 624 | ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL, |
| 625 | PRESET_MANUAL_RED_GAIN_FORMATTER, |
| 626 | pdev->red_balance->val); |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 627 | if (ret) |
| 628 | return ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 629 | } |
| 630 | |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 631 | if (pdev->blue_balance->is_new) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 632 | ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL, |
| 633 | PRESET_MANUAL_BLUE_GAIN_FORMATTER, |
| 634 | pdev->blue_balance->val); |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 635 | if (ret) |
| 636 | return ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 637 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 638 | return 0; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /* For CODEC2 models which have separate autogain and auto exposure */ |
| 642 | static int pwc_set_autogain(struct pwc_device *pdev) |
| 643 | { |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 644 | int ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 645 | |
| 646 | if (pdev->autogain->is_new) { |
| 647 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 648 | AGC_MODE_FORMATTER, |
| 649 | pdev->autogain->val ? 0 : 0xff); |
| 650 | if (ret) |
| 651 | return ret; |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 652 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 653 | if (pdev->autogain->val) |
| 654 | pdev->gain_valid = false; /* Force cache update */ |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 655 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 656 | |
| 657 | if (pdev->autogain->val) |
| 658 | return 0; |
| 659 | |
| 660 | if (pdev->gain->is_new) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 661 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 662 | PRESET_AGC_FORMATTER, |
| 663 | pdev->gain->val); |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 664 | if (ret) |
| 665 | return ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 666 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 667 | return 0; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /* For CODEC2 models which have separate autogain and auto exposure */ |
| 671 | static int pwc_set_exposure_auto(struct pwc_device *pdev) |
| 672 | { |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 673 | int ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 674 | int is_auto = pdev->exposure_auto->val == V4L2_EXPOSURE_AUTO; |
| 675 | |
| 676 | if (pdev->exposure_auto->is_new) { |
| 677 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 678 | SHUTTER_MODE_FORMATTER, |
| 679 | is_auto ? 0 : 0xff); |
| 680 | if (ret) |
| 681 | return ret; |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 682 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 683 | if (is_auto) |
| 684 | pdev->exposure_valid = false; /* Force cache update */ |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 685 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 686 | |
| 687 | if (is_auto) |
| 688 | return 0; |
| 689 | |
| 690 | if (pdev->exposure->is_new) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 691 | ret = pwc_set_u16_ctrl(pdev, SET_LUM_CTL, |
| 692 | PRESET_SHUTTER_FORMATTER, |
| 693 | pdev->exposure->val); |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 694 | if (ret) |
| 695 | return ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 696 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 697 | return 0; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /* For CODEC3 models which have autogain controlling both gain and exposure */ |
| 701 | static int pwc_set_autogain_expo(struct pwc_device *pdev) |
| 702 | { |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 703 | int ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 704 | |
| 705 | if (pdev->autogain->is_new) { |
| 706 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 707 | AGC_MODE_FORMATTER, |
| 708 | pdev->autogain->val ? 0 : 0xff); |
| 709 | if (ret) |
| 710 | return ret; |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 711 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 712 | if (pdev->autogain->val) { |
| 713 | pdev->gain_valid = false; /* Force cache update */ |
| 714 | pdev->exposure_valid = false; /* Force cache update */ |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 715 | } |
| 716 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 717 | |
| 718 | if (pdev->autogain->val) |
| 719 | return 0; |
| 720 | |
| 721 | if (pdev->gain->is_new) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 722 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 723 | PRESET_AGC_FORMATTER, |
| 724 | pdev->gain->val); |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 725 | if (ret) |
| 726 | return ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 727 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 728 | |
| 729 | if (pdev->exposure->is_new) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 730 | ret = pwc_set_u16_ctrl(pdev, SET_LUM_CTL, |
| 731 | PRESET_SHUTTER_FORMATTER, |
| 732 | pdev->exposure->val); |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 733 | if (ret) |
| 734 | return ret; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 735 | } |
Hans Verkuil | 43d23f3 | 2011-08-26 08:40:43 -0300 | [diff] [blame] | 736 | return 0; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 737 | } |
| 738 | |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 739 | static int pwc_set_motor(struct pwc_device *pdev) |
| 740 | { |
| 741 | int ret; |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 742 | |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 743 | pdev->ctrl_buf[0] = 0; |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 744 | if (pdev->motor_pan_reset->is_new) |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 745 | pdev->ctrl_buf[0] |= 0x01; |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 746 | if (pdev->motor_tilt_reset->is_new) |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 747 | pdev->ctrl_buf[0] |= 0x02; |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 748 | if (pdev->motor_pan_reset->is_new || pdev->motor_tilt_reset->is_new) { |
| 749 | ret = send_control_msg(pdev, SET_MPT_CTL, |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 750 | PT_RESET_CONTROL_FORMATTER, |
| 751 | pdev->ctrl_buf, 1); |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 752 | if (ret < 0) |
| 753 | return ret; |
| 754 | } |
| 755 | |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 756 | memset(pdev->ctrl_buf, 0, 4); |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 757 | if (pdev->motor_pan->is_new) { |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 758 | pdev->ctrl_buf[0] = pdev->motor_pan->val & 0xFF; |
| 759 | pdev->ctrl_buf[1] = (pdev->motor_pan->val >> 8); |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 760 | } |
| 761 | if (pdev->motor_tilt->is_new) { |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 762 | pdev->ctrl_buf[2] = pdev->motor_tilt->val & 0xFF; |
| 763 | pdev->ctrl_buf[3] = (pdev->motor_tilt->val >> 8); |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 764 | } |
| 765 | if (pdev->motor_pan->is_new || pdev->motor_tilt->is_new) { |
| 766 | ret = send_control_msg(pdev, SET_MPT_CTL, |
| 767 | PT_RELATIVE_CONTROL_FORMATTER, |
Hans de Goede | 24be689 | 2012-01-10 17:02:04 -0300 | [diff] [blame] | 768 | pdev->ctrl_buf, 4); |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 769 | if (ret < 0) |
| 770 | return ret; |
| 771 | } |
| 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 776 | static int pwc_s_ctrl(struct v4l2_ctrl *ctrl) |
| 777 | { |
| 778 | struct pwc_device *pdev = |
| 779 | container_of(ctrl->handler, struct pwc_device, ctrl_handler); |
| 780 | int ret = 0; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 781 | |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 782 | switch (ctrl->id) { |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 783 | case V4L2_CID_BRIGHTNESS: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 784 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 785 | BRIGHTNESS_FORMATTER, ctrl->val); |
| 786 | break; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 787 | case V4L2_CID_CONTRAST: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 788 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 789 | CONTRAST_FORMATTER, ctrl->val); |
| 790 | break; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 791 | case V4L2_CID_SATURATION: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 792 | ret = pwc_set_s8_ctrl(pdev, SET_CHROM_CTL, |
| 793 | pdev->saturation_fmt, ctrl->val); |
| 794 | break; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 795 | case V4L2_CID_GAMMA: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 796 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 797 | GAMMA_FORMATTER, ctrl->val); |
| 798 | break; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 799 | case V4L2_CID_AUTO_WHITE_BALANCE: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 800 | ret = pwc_set_awb(pdev); |
| 801 | break; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 802 | case V4L2_CID_AUTOGAIN: |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 803 | if (DEVICE_USE_CODEC2(pdev->type)) |
| 804 | ret = pwc_set_autogain(pdev); |
| 805 | else if (DEVICE_USE_CODEC3(pdev->type)) |
| 806 | ret = pwc_set_autogain_expo(pdev); |
| 807 | else |
| 808 | ret = -EINVAL; |
| 809 | break; |
| 810 | case V4L2_CID_EXPOSURE_AUTO: |
| 811 | if (DEVICE_USE_CODEC2(pdev->type)) |
| 812 | ret = pwc_set_exposure_auto(pdev); |
| 813 | else |
| 814 | ret = -EINVAL; |
| 815 | break; |
| 816 | case V4L2_CID_COLORFX: |
| 817 | ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL, |
| 818 | COLOUR_MODE_FORMATTER, |
| 819 | ctrl->val ? 0 : 0xff); |
| 820 | break; |
| 821 | case PWC_CID_CUSTOM(autocontour): |
| 822 | if (pdev->autocontour->is_new) { |
| 823 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 824 | AUTO_CONTOUR_FORMATTER, |
| 825 | pdev->autocontour->val ? 0 : 0xff); |
| 826 | } |
| 827 | if (ret == 0 && pdev->contour->is_new) { |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 828 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 829 | PRESET_CONTOUR_FORMATTER, |
| 830 | pdev->contour->val); |
| 831 | } |
| 832 | break; |
| 833 | case V4L2_CID_BACKLIGHT_COMPENSATION: |
| 834 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 835 | BACK_LIGHT_COMPENSATION_FORMATTER, |
| 836 | ctrl->val ? 0 : 0xff); |
| 837 | break; |
| 838 | case V4L2_CID_BAND_STOP_FILTER: |
| 839 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 840 | FLICKERLESS_MODE_FORMATTER, |
| 841 | ctrl->val ? 0 : 0xff); |
| 842 | break; |
| 843 | case PWC_CID_CUSTOM(noise_reduction): |
| 844 | ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL, |
| 845 | DYNAMIC_NOISE_CONTROL_FORMATTER, |
| 846 | ctrl->val); |
| 847 | break; |
| 848 | case PWC_CID_CUSTOM(save_user): |
| 849 | ret = pwc_button_ctrl(pdev, SAVE_USER_DEFAULTS_FORMATTER); |
| 850 | break; |
| 851 | case PWC_CID_CUSTOM(restore_user): |
| 852 | ret = pwc_button_ctrl(pdev, RESTORE_USER_DEFAULTS_FORMATTER); |
| 853 | break; |
| 854 | case PWC_CID_CUSTOM(restore_factory): |
| 855 | ret = pwc_button_ctrl(pdev, |
| 856 | RESTORE_FACTORY_DEFAULTS_FORMATTER); |
| 857 | break; |
Hans de Goede | f4af6595 | 2011-10-09 09:56:23 -0300 | [diff] [blame] | 858 | case PWC_CID_CUSTOM(awb_speed): |
| 859 | ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL, |
| 860 | AWB_CONTROL_SPEED_FORMATTER, |
| 861 | ctrl->val); |
| 862 | break; |
| 863 | case PWC_CID_CUSTOM(awb_delay): |
| 864 | ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL, |
| 865 | AWB_CONTROL_DELAY_FORMATTER, |
| 866 | ctrl->val); |
| 867 | break; |
Hans de Goede | 294e289 | 2011-07-03 12:23:24 -0300 | [diff] [blame] | 868 | case V4L2_CID_PAN_RELATIVE: |
| 869 | ret = pwc_set_motor(pdev); |
| 870 | break; |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 871 | default: |
| 872 | ret = -EINVAL; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 873 | } |
Hans de Goede | 6c9cac8 | 2011-06-26 12:52:01 -0300 | [diff] [blame] | 874 | |
| 875 | if (ret) |
| 876 | PWC_ERROR("s_ctrl %s error %d\n", ctrl->name, ret); |
| 877 | |
| 878 | return ret; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | static int pwc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f) |
| 882 | { |
| 883 | struct pwc_device *pdev = video_drvdata(file); |
| 884 | |
| 885 | /* We only support two format: the raw format, and YUV */ |
| 886 | switch (f->index) { |
| 887 | case 0: |
| 888 | /* RAW format */ |
| 889 | f->pixelformat = pdev->type <= 646 ? V4L2_PIX_FMT_PWC1 : V4L2_PIX_FMT_PWC2; |
| 890 | f->flags = V4L2_FMT_FLAG_COMPRESSED; |
| 891 | strlcpy(f->description, "Raw Philips Webcam", sizeof(f->description)); |
| 892 | break; |
| 893 | case 1: |
| 894 | f->pixelformat = V4L2_PIX_FMT_YUV420; |
| 895 | strlcpy(f->description, "4:2:0, planar, Y-Cb-Cr", sizeof(f->description)); |
| 896 | break; |
| 897 | default: |
| 898 | return -EINVAL; |
| 899 | } |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static int pwc_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) |
| 904 | { |
| 905 | struct pwc_device *pdev = video_drvdata(file); |
| 906 | |
Hans de Goede | 31e582e | 2012-01-04 19:46:53 -0300 | [diff] [blame] | 907 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 908 | return -EINVAL; |
| 909 | |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 910 | PWC_DEBUG_IOCTL("ioctl(VIDIOC_G_FMT) return size %dx%d\n", |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 911 | pdev->width, pdev->height); |
Hans de Goede | 31e582e | 2012-01-04 19:46:53 -0300 | [diff] [blame] | 912 | pwc_vidioc_fill_fmt(f, pdev->width, pdev->height, pdev->pixfmt); |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | static int pwc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) |
| 917 | { |
| 918 | struct pwc_device *pdev = video_drvdata(file); |
| 919 | |
| 920 | return pwc_vidioc_try_fmt(pdev, f); |
| 921 | } |
| 922 | |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 923 | static int pwc_enum_framesizes(struct file *file, void *fh, |
| 924 | struct v4l2_frmsizeenum *fsize) |
| 925 | { |
| 926 | struct pwc_device *pdev = video_drvdata(file); |
| 927 | unsigned int i = 0, index = fsize->index; |
| 928 | |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 929 | if (fsize->pixel_format == V4L2_PIX_FMT_YUV420 || |
| 930 | (fsize->pixel_format == V4L2_PIX_FMT_PWC1 && |
| 931 | DEVICE_USE_CODEC1(pdev->type)) || |
| 932 | (fsize->pixel_format == V4L2_PIX_FMT_PWC2 && |
| 933 | DEVICE_USE_CODEC23(pdev->type))) { |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 934 | for (i = 0; i < PSZ_MAX; i++) { |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 935 | if (!(pdev->image_mask & (1UL << i))) |
| 936 | continue; |
| 937 | if (!index--) { |
| 938 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
| 939 | fsize->discrete.width = pwc_image_sizes[i][0]; |
| 940 | fsize->discrete.height = pwc_image_sizes[i][1]; |
| 941 | return 0; |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 942 | } |
| 943 | } |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 944 | } |
| 945 | return -EINVAL; |
| 946 | } |
| 947 | |
| 948 | static int pwc_enum_frameintervals(struct file *file, void *fh, |
| 949 | struct v4l2_frmivalenum *fival) |
| 950 | { |
| 951 | struct pwc_device *pdev = video_drvdata(file); |
| 952 | int size = -1; |
| 953 | unsigned int i; |
| 954 | |
| 955 | for (i = 0; i < PSZ_MAX; i++) { |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 956 | if (pwc_image_sizes[i][0] == fival->width && |
| 957 | pwc_image_sizes[i][1] == fival->height) { |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 958 | size = i; |
| 959 | break; |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | /* TODO: Support raw format */ |
| 964 | if (size < 0 || fival->pixel_format != V4L2_PIX_FMT_YUV420) |
| 965 | return -EINVAL; |
| 966 | |
| 967 | i = pwc_get_fps(pdev, fival->index, size); |
| 968 | if (!i) |
| 969 | return -EINVAL; |
| 970 | |
| 971 | fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; |
| 972 | fival->discrete.numerator = 1; |
| 973 | fival->discrete.denominator = i; |
| 974 | |
| 975 | return 0; |
| 976 | } |
| 977 | |
Hans de Goede | 54d3fb3 | 2012-01-08 07:19:29 -0300 | [diff] [blame] | 978 | static int pwc_g_parm(struct file *file, void *fh, |
| 979 | struct v4l2_streamparm *parm) |
| 980 | { |
| 981 | struct pwc_device *pdev = video_drvdata(file); |
| 982 | |
| 983 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 984 | return -EINVAL; |
| 985 | |
| 986 | memset(parm, 0, sizeof(*parm)); |
| 987 | |
| 988 | parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 989 | parm->parm.capture.readbuffers = MIN_FRAMES; |
| 990 | parm->parm.capture.capability |= V4L2_CAP_TIMEPERFRAME; |
| 991 | parm->parm.capture.timeperframe.denominator = pdev->vframes; |
| 992 | parm->parm.capture.timeperframe.numerator = 1; |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static int pwc_s_parm(struct file *file, void *fh, |
| 998 | struct v4l2_streamparm *parm) |
| 999 | { |
| 1000 | struct pwc_device *pdev = video_drvdata(file); |
| 1001 | int compression = 0; |
| 1002 | int ret, fps; |
| 1003 | |
Hans Verkuil | 387c71b | 2012-06-10 04:34:10 -0300 | [diff] [blame] | 1004 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Hans de Goede | 54d3fb3 | 2012-01-08 07:19:29 -0300 | [diff] [blame] | 1005 | return -EINVAL; |
| 1006 | |
Hans Verkuil | 387c71b | 2012-06-10 04:34:10 -0300 | [diff] [blame] | 1007 | /* If timeperframe == 0, then reset the framerate to the nominal value. |
| 1008 | We pick a high framerate here, and let pwc_set_video_mode() figure |
| 1009 | out the best match. */ |
| 1010 | if (parm->parm.capture.timeperframe.numerator == 0 || |
| 1011 | parm->parm.capture.timeperframe.denominator == 0) |
| 1012 | fps = 30; |
| 1013 | else |
| 1014 | fps = parm->parm.capture.timeperframe.denominator / |
| 1015 | parm->parm.capture.timeperframe.numerator; |
Hans de Goede | 54d3fb3 | 2012-01-08 07:19:29 -0300 | [diff] [blame] | 1016 | |
Hans Verkuil | 2e43dec | 2012-07-02 05:51:58 -0300 | [diff] [blame] | 1017 | if (vb2_is_busy(&pdev->vb_queue)) |
| 1018 | return -EBUSY; |
Hans de Goede | 54d3fb3 | 2012-01-08 07:19:29 -0300 | [diff] [blame] | 1019 | |
Hans de Goede | d167a85 | 2012-01-10 13:01:41 -0300 | [diff] [blame] | 1020 | ret = pwc_set_video_mode(pdev, pdev->width, pdev->height, pdev->pixfmt, |
Hans de Goede | 938d5b9 | 2012-01-10 13:14:46 -0300 | [diff] [blame] | 1021 | fps, &compression, 0); |
Hans de Goede | 54d3fb3 | 2012-01-08 07:19:29 -0300 | [diff] [blame] | 1022 | |
| 1023 | pwc_g_parm(file, fh, parm); |
| 1024 | |
Hans de Goede | 54d3fb3 | 2012-01-08 07:19:29 -0300 | [diff] [blame] | 1025 | return ret; |
| 1026 | } |
| 1027 | |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 1028 | const struct v4l2_ioctl_ops pwc_ioctl_ops = { |
| 1029 | .vidioc_querycap = pwc_querycap, |
| 1030 | .vidioc_enum_input = pwc_enum_input, |
| 1031 | .vidioc_g_input = pwc_g_input, |
| 1032 | .vidioc_s_input = pwc_s_input, |
| 1033 | .vidioc_enum_fmt_vid_cap = pwc_enum_fmt_vid_cap, |
| 1034 | .vidioc_g_fmt_vid_cap = pwc_g_fmt_vid_cap, |
| 1035 | .vidioc_s_fmt_vid_cap = pwc_s_fmt_vid_cap, |
| 1036 | .vidioc_try_fmt_vid_cap = pwc_try_fmt_vid_cap, |
Hans Verkuil | 2e43dec | 2012-07-02 05:51:58 -0300 | [diff] [blame] | 1037 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1038 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1039 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1040 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 1041 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1042 | .vidioc_streamoff = vb2_ioctl_streamoff, |
Hans Verkuil | e2ecb25 | 2012-02-02 08:20:53 -0300 | [diff] [blame] | 1043 | .vidioc_log_status = v4l2_ctrl_log_status, |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 1044 | .vidioc_enum_framesizes = pwc_enum_framesizes, |
| 1045 | .vidioc_enum_frameintervals = pwc_enum_frameintervals, |
Hans de Goede | 54d3fb3 | 2012-01-08 07:19:29 -0300 | [diff] [blame] | 1046 | .vidioc_g_parm = pwc_g_parm, |
| 1047 | .vidioc_s_parm = pwc_s_parm, |
Hans de Goede | 3f1bfef | 2012-03-27 18:57:55 +0200 | [diff] [blame] | 1048 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1049 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Hans Verkuil | afa3852 | 2011-01-22 06:34:55 -0300 | [diff] [blame] | 1050 | }; |