Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1 | /* |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 2 | * ov534-ov772x gspca driver |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 3 | * |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 4 | * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it> |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 5 | * Copyright (C) 2008 Jim Paris <jim@jtan.com> |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 6 | * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 7 | * |
| 8 | * Based on a prototype written by Mark Ferrell <majortrips@gmail.com> |
| 9 | * USB protocol reverse engineered by Jim Paris <jim@jtan.com> |
| 10 | * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/ |
| 11 | * |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 12 | * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr |
Max Thrun | 6721b51 | 2010-02-27 17:20:28 -0300 | [diff] [blame] | 13 | * PS3 Eye camera - brightness, contrast, awb, agc, aec controls |
| 14 | * added by Max Thrun <bear24rw@gmail.com> |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 15 | * |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 | */ |
| 30 | |
| 31 | #define MODULE_NAME "ov534" |
| 32 | |
| 33 | #include "gspca.h" |
| 34 | |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 35 | #define OV534_REG_ADDRESS 0xf1 /* sensor address */ |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 36 | #define OV534_REG_SUBADDR 0xf2 |
| 37 | #define OV534_REG_WRITE 0xf3 |
| 38 | #define OV534_REG_READ 0xf4 |
| 39 | #define OV534_REG_OPERATION 0xf5 |
| 40 | #define OV534_REG_STATUS 0xf6 |
| 41 | |
| 42 | #define OV534_OP_WRITE_3 0x37 |
| 43 | #define OV534_OP_WRITE_2 0x33 |
| 44 | #define OV534_OP_READ_2 0xf9 |
| 45 | |
| 46 | #define CTRL_TIMEOUT 500 |
| 47 | |
| 48 | MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>"); |
| 49 | MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver"); |
| 50 | MODULE_LICENSE("GPL"); |
| 51 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 52 | /* specific webcam descriptor */ |
| 53 | struct sd { |
| 54 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Jean-Francois Moine | 8c25205 | 2008-12-04 05:06:08 -0300 | [diff] [blame] | 55 | __u32 last_pts; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 56 | u16 last_fid; |
| 57 | u8 frame_rate; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 58 | |
| 59 | u8 brightness; |
| 60 | u8 contrast; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 61 | u8 gain; |
| 62 | u8 exposure; |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 63 | u8 agc; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 64 | u8 awb; |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 65 | u8 aec; |
Jean-Francois Moine | c22c4a2 | 2009-11-24 05:22:05 -0300 | [diff] [blame] | 66 | s8 sharpness; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 67 | u8 hflip; |
| 68 | u8 vflip; |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 69 | u8 freqfltr; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* V4L2 controls supported by the driver */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 73 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); |
| 74 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); |
| 75 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); |
| 76 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 77 | static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val); |
| 78 | static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 79 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); |
| 80 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); |
| 81 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); |
| 82 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); |
| 83 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); |
| 84 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 85 | static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val); |
| 86 | static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val); |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 87 | static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val); |
| 88 | static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 89 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); |
| 90 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); |
| 91 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); |
| 92 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 93 | static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val); |
| 94 | static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val); |
| 95 | static int sd_querymenu(struct gspca_dev *gspca_dev, |
| 96 | struct v4l2_querymenu *menu); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 97 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 98 | static const struct ctrl sd_ctrls[] = { |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 99 | { /* 0 */ |
| 100 | { |
| 101 | .id = V4L2_CID_BRIGHTNESS, |
| 102 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 103 | .name = "Brightness", |
| 104 | .minimum = 0, |
| 105 | .maximum = 255, |
| 106 | .step = 1, |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 107 | #define BRIGHTNESS_DEF 0 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 108 | .default_value = BRIGHTNESS_DEF, |
| 109 | }, |
| 110 | .set = sd_setbrightness, |
| 111 | .get = sd_getbrightness, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 112 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 113 | { /* 1 */ |
| 114 | { |
| 115 | .id = V4L2_CID_CONTRAST, |
| 116 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 117 | .name = "Contrast", |
| 118 | .minimum = 0, |
| 119 | .maximum = 255, |
| 120 | .step = 1, |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 121 | #define CONTRAST_DEF 32 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 122 | .default_value = CONTRAST_DEF, |
| 123 | }, |
| 124 | .set = sd_setcontrast, |
| 125 | .get = sd_getcontrast, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 126 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 127 | { /* 2 */ |
| 128 | { |
| 129 | .id = V4L2_CID_GAIN, |
| 130 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 131 | .name = "Main Gain", |
| 132 | .minimum = 0, |
| 133 | .maximum = 63, |
| 134 | .step = 1, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 135 | #define GAIN_DEF 20 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 136 | .default_value = GAIN_DEF, |
| 137 | }, |
| 138 | .set = sd_setgain, |
| 139 | .get = sd_getgain, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 140 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 141 | { /* 3 */ |
| 142 | { |
| 143 | .id = V4L2_CID_EXPOSURE, |
| 144 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 145 | .name = "Exposure", |
| 146 | .minimum = 0, |
| 147 | .maximum = 255, |
| 148 | .step = 1, |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 149 | #define EXPO_DEF 120 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 150 | .default_value = EXPO_DEF, |
| 151 | }, |
| 152 | .set = sd_setexposure, |
| 153 | .get = sd_getexposure, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 154 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 155 | { /* 4 */ |
| 156 | { |
| 157 | .id = V4L2_CID_AUTOGAIN, |
| 158 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 159 | .name = "Auto Gain", |
| 160 | .minimum = 0, |
| 161 | .maximum = 1, |
| 162 | .step = 1, |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 163 | #define AGC_DEF 1 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 164 | .default_value = AGC_DEF, |
| 165 | }, |
| 166 | .set = sd_setagc, |
| 167 | .get = sd_getagc, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 168 | }, |
Antonio Ospite | 0c41acf | 2010-02-27 17:20:19 -0300 | [diff] [blame] | 169 | #define AWB_IDX 5 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 170 | { /* 5 */ |
| 171 | { |
| 172 | .id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 173 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 174 | .name = "Auto White Balance", |
| 175 | .minimum = 0, |
| 176 | .maximum = 1, |
| 177 | .step = 1, |
Max Thrun | 8fef9d9 | 2010-02-27 17:20:23 -0300 | [diff] [blame] | 178 | #define AWB_DEF 1 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 179 | .default_value = AWB_DEF, |
| 180 | }, |
| 181 | .set = sd_setawb, |
| 182 | .get = sd_getawb, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 183 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 184 | { /* 6 */ |
| 185 | { |
| 186 | .id = V4L2_CID_EXPOSURE_AUTO, |
| 187 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 188 | .name = "Auto Exposure", |
| 189 | .minimum = 0, |
| 190 | .maximum = 1, |
| 191 | .step = 1, |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 192 | #define AEC_DEF 1 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 193 | .default_value = AEC_DEF, |
| 194 | }, |
| 195 | .set = sd_setaec, |
| 196 | .get = sd_getaec, |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 197 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 198 | { /* 7 */ |
| 199 | { |
| 200 | .id = V4L2_CID_SHARPNESS, |
| 201 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 202 | .name = "Sharpness", |
| 203 | .minimum = 0, |
| 204 | .maximum = 63, |
| 205 | .step = 1, |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 206 | #define SHARPNESS_DEF 0 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 207 | .default_value = SHARPNESS_DEF, |
| 208 | }, |
| 209 | .set = sd_setsharpness, |
| 210 | .get = sd_getsharpness, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 211 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 212 | { /* 8 */ |
| 213 | { |
| 214 | .id = V4L2_CID_HFLIP, |
| 215 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 216 | .name = "HFlip", |
| 217 | .minimum = 0, |
| 218 | .maximum = 1, |
| 219 | .step = 1, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 220 | #define HFLIP_DEF 0 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 221 | .default_value = HFLIP_DEF, |
| 222 | }, |
| 223 | .set = sd_sethflip, |
| 224 | .get = sd_gethflip, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 225 | }, |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 226 | { /* 9 */ |
| 227 | { |
| 228 | .id = V4L2_CID_VFLIP, |
| 229 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 230 | .name = "VFlip", |
| 231 | .minimum = 0, |
| 232 | .maximum = 1, |
| 233 | .step = 1, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 234 | #define VFLIP_DEF 0 |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 235 | .default_value = VFLIP_DEF, |
| 236 | }, |
| 237 | .set = sd_setvflip, |
| 238 | .get = sd_getvflip, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 239 | }, |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 240 | { /* 10 */ |
| 241 | { |
| 242 | .id = V4L2_CID_POWER_LINE_FREQUENCY, |
| 243 | .type = V4L2_CTRL_TYPE_MENU, |
| 244 | .name = "Light Frequency Filter", |
| 245 | .minimum = 0, |
| 246 | .maximum = 1, |
| 247 | .step = 1, |
| 248 | #define FREQFLTR_DEF 0 |
| 249 | .default_value = FREQFLTR_DEF, |
| 250 | }, |
| 251 | .set = sd_setfreqfltr, |
| 252 | .get = sd_getfreqfltr, |
| 253 | }, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 254 | }; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 255 | |
Jean-Francois Moine | 569691a | 2009-11-14 09:45:38 -0300 | [diff] [blame] | 256 | static const struct v4l2_pix_format ov772x_mode[] = { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 257 | {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, |
| 258 | .bytesperline = 320 * 2, |
| 259 | .sizeimage = 320 * 240 * 2, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 260 | .colorspace = V4L2_COLORSPACE_SRGB, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 261 | .priv = 1}, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 262 | {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, |
| 263 | .bytesperline = 640 * 2, |
| 264 | .sizeimage = 640 * 480 * 2, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 265 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 266 | .priv = 0}, |
| 267 | }; |
| 268 | |
Antonio Ospite | 29b87f0 | 2010-01-17 03:27:04 -0300 | [diff] [blame] | 269 | static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30}; |
| 270 | static const u8 vga_rates[] = {60, 50, 40, 30, 15}; |
| 271 | |
| 272 | static const struct framerates ov772x_framerates[] = { |
| 273 | { /* 320x240 */ |
| 274 | .rates = qvga_rates, |
| 275 | .nrates = ARRAY_SIZE(qvga_rates), |
| 276 | }, |
| 277 | { /* 640x480 */ |
| 278 | .rates = vga_rates, |
| 279 | .nrates = ARRAY_SIZE(vga_rates), |
| 280 | }, |
| 281 | }; |
| 282 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 283 | static const u8 bridge_init[][2] = { |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 284 | { 0xc2, 0x0c }, |
| 285 | { 0x88, 0xf8 }, |
| 286 | { 0xc3, 0x69 }, |
| 287 | { 0x89, 0xff }, |
| 288 | { 0x76, 0x03 }, |
| 289 | { 0x92, 0x01 }, |
| 290 | { 0x93, 0x18 }, |
| 291 | { 0x94, 0x10 }, |
| 292 | { 0x95, 0x10 }, |
| 293 | { 0xe2, 0x00 }, |
| 294 | { 0xe7, 0x3e }, |
| 295 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 296 | { 0x96, 0x00 }, |
| 297 | |
| 298 | { 0x97, 0x20 }, |
| 299 | { 0x97, 0x20 }, |
| 300 | { 0x97, 0x20 }, |
| 301 | { 0x97, 0x0a }, |
| 302 | { 0x97, 0x3f }, |
| 303 | { 0x97, 0x4a }, |
| 304 | { 0x97, 0x20 }, |
| 305 | { 0x97, 0x15 }, |
| 306 | { 0x97, 0x0b }, |
| 307 | |
| 308 | { 0x8e, 0x40 }, |
| 309 | { 0x1f, 0x81 }, |
| 310 | { 0x34, 0x05 }, |
| 311 | { 0xe3, 0x04 }, |
| 312 | { 0x88, 0x00 }, |
| 313 | { 0x89, 0x00 }, |
| 314 | { 0x76, 0x00 }, |
| 315 | { 0xe7, 0x2e }, |
| 316 | { 0x31, 0xf9 }, |
| 317 | { 0x25, 0x42 }, |
| 318 | { 0x21, 0xf0 }, |
| 319 | |
| 320 | { 0x1c, 0x00 }, |
| 321 | { 0x1d, 0x40 }, |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 322 | { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */ |
| 323 | { 0x1d, 0x00 }, /* payload size */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 324 | |
Jim Paris | 5ea9c4d | 2008-12-04 04:36:14 -0300 | [diff] [blame] | 325 | { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */ |
| 326 | { 0x1d, 0x58 }, /* frame size */ |
| 327 | { 0x1d, 0x00 }, /* frame size */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 328 | |
Jim Paris | c06eb61 | 2008-12-10 05:47:44 -0300 | [diff] [blame] | 329 | { 0x1c, 0x0a }, |
| 330 | { 0x1d, 0x08 }, /* turn on UVC header */ |
| 331 | { 0x1d, 0x0e }, /* .. */ |
| 332 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 333 | { 0x8d, 0x1c }, |
| 334 | { 0x8e, 0x80 }, |
| 335 | { 0xe5, 0x04 }, |
| 336 | |
| 337 | { 0xc0, 0x50 }, |
| 338 | { 0xc1, 0x3c }, |
| 339 | { 0xc2, 0x0c }, |
| 340 | }; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 341 | static const u8 sensor_init[][2] = { |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 342 | { 0x12, 0x80 }, |
| 343 | { 0x11, 0x01 }, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 344 | /*fixme: better have a delay?*/ |
| 345 | { 0x11, 0x01 }, |
| 346 | { 0x11, 0x01 }, |
| 347 | { 0x11, 0x01 }, |
| 348 | { 0x11, 0x01 }, |
| 349 | { 0x11, 0x01 }, |
| 350 | { 0x11, 0x01 }, |
| 351 | { 0x11, 0x01 }, |
| 352 | { 0x11, 0x01 }, |
| 353 | { 0x11, 0x01 }, |
| 354 | { 0x11, 0x01 }, |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 355 | |
| 356 | { 0x3d, 0x03 }, |
| 357 | { 0x17, 0x26 }, |
| 358 | { 0x18, 0xa0 }, |
| 359 | { 0x19, 0x07 }, |
| 360 | { 0x1a, 0xf0 }, |
| 361 | { 0x32, 0x00 }, |
| 362 | { 0x29, 0xa0 }, |
| 363 | { 0x2c, 0xf0 }, |
| 364 | { 0x65, 0x20 }, |
| 365 | { 0x11, 0x01 }, |
| 366 | { 0x42, 0x7f }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 367 | { 0x63, 0xaa }, /* AWB - was e0 */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 368 | { 0x64, 0xff }, |
| 369 | { 0x66, 0x00 }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 370 | { 0x13, 0xf0 }, /* com8 */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 371 | { 0x0d, 0x41 }, |
| 372 | { 0x0f, 0xc5 }, |
| 373 | { 0x14, 0x11 }, |
| 374 | |
| 375 | { 0x22, 0x7f }, |
| 376 | { 0x23, 0x03 }, |
| 377 | { 0x24, 0x40 }, |
| 378 | { 0x25, 0x30 }, |
| 379 | { 0x26, 0xa1 }, |
| 380 | { 0x2a, 0x00 }, |
| 381 | { 0x2b, 0x00 }, |
| 382 | { 0x6b, 0xaa }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 383 | { 0x13, 0xff }, /* AWB */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 384 | |
| 385 | { 0x90, 0x05 }, |
| 386 | { 0x91, 0x01 }, |
| 387 | { 0x92, 0x03 }, |
| 388 | { 0x93, 0x00 }, |
| 389 | { 0x94, 0x60 }, |
| 390 | { 0x95, 0x3c }, |
| 391 | { 0x96, 0x24 }, |
| 392 | { 0x97, 0x1e }, |
| 393 | { 0x98, 0x62 }, |
| 394 | { 0x99, 0x80 }, |
| 395 | { 0x9a, 0x1e }, |
| 396 | { 0x9b, 0x08 }, |
| 397 | { 0x9c, 0x20 }, |
| 398 | { 0x9e, 0x81 }, |
| 399 | |
| 400 | { 0xa6, 0x04 }, |
| 401 | { 0x7e, 0x0c }, |
| 402 | { 0x7f, 0x16 }, |
| 403 | { 0x80, 0x2a }, |
| 404 | { 0x81, 0x4e }, |
| 405 | { 0x82, 0x61 }, |
| 406 | { 0x83, 0x6f }, |
| 407 | { 0x84, 0x7b }, |
| 408 | { 0x85, 0x86 }, |
| 409 | { 0x86, 0x8e }, |
| 410 | { 0x87, 0x97 }, |
| 411 | { 0x88, 0xa4 }, |
| 412 | { 0x89, 0xaf }, |
| 413 | { 0x8a, 0xc5 }, |
| 414 | { 0x8b, 0xd7 }, |
| 415 | { 0x8c, 0xe8 }, |
| 416 | { 0x8d, 0x20 }, |
| 417 | |
| 418 | { 0x0c, 0x90 }, |
| 419 | |
| 420 | { 0x2b, 0x00 }, |
| 421 | { 0x22, 0x7f }, |
| 422 | { 0x23, 0x03 }, |
| 423 | { 0x11, 0x01 }, |
| 424 | { 0x0c, 0xd0 }, |
| 425 | { 0x64, 0xff }, |
| 426 | { 0x0d, 0x41 }, |
| 427 | |
| 428 | { 0x14, 0x41 }, |
| 429 | { 0x0e, 0xcd }, |
| 430 | { 0xac, 0xbf }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 431 | { 0x8e, 0x00 }, /* De-noise threshold */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 432 | { 0x0c, 0xd0 } |
| 433 | }; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 434 | static const u8 bridge_start_vga[][2] = { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 435 | {0x1c, 0x00}, |
| 436 | {0x1d, 0x40}, |
| 437 | {0x1d, 0x02}, |
| 438 | {0x1d, 0x00}, |
| 439 | {0x1d, 0x02}, |
| 440 | {0x1d, 0x58}, |
| 441 | {0x1d, 0x00}, |
| 442 | {0xc0, 0x50}, |
| 443 | {0xc1, 0x3c}, |
| 444 | }; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 445 | static const u8 sensor_start_vga[][2] = { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 446 | {0x12, 0x00}, |
| 447 | {0x17, 0x26}, |
| 448 | {0x18, 0xa0}, |
| 449 | {0x19, 0x07}, |
| 450 | {0x1a, 0xf0}, |
| 451 | {0x29, 0xa0}, |
| 452 | {0x2c, 0xf0}, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 453 | {0x65, 0x20}, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 454 | }; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 455 | static const u8 bridge_start_qvga[][2] = { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 456 | {0x1c, 0x00}, |
| 457 | {0x1d, 0x40}, |
| 458 | {0x1d, 0x02}, |
| 459 | {0x1d, 0x00}, |
| 460 | {0x1d, 0x01}, |
| 461 | {0x1d, 0x4b}, |
| 462 | {0x1d, 0x00}, |
| 463 | {0xc0, 0x28}, |
| 464 | {0xc1, 0x1e}, |
| 465 | }; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 466 | static const u8 sensor_start_qvga[][2] = { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 467 | {0x12, 0x40}, |
| 468 | {0x17, 0x3f}, |
| 469 | {0x18, 0x50}, |
| 470 | {0x19, 0x03}, |
| 471 | {0x1a, 0x78}, |
| 472 | {0x29, 0x50}, |
| 473 | {0x2c, 0x78}, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 474 | {0x65, 0x2f}, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 475 | }; |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 476 | |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 477 | static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) |
| 478 | { |
| 479 | struct usb_device *udev = gspca_dev->dev; |
| 480 | int ret; |
| 481 | |
| 482 | PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val); |
| 483 | gspca_dev->usb_buf[0] = val; |
| 484 | ret = usb_control_msg(udev, |
| 485 | usb_sndctrlpipe(udev, 0), |
| 486 | 0x01, |
| 487 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 488 | 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); |
| 489 | if (ret < 0) |
| 490 | PDEBUG(D_ERR, "write failed"); |
| 491 | } |
| 492 | |
| 493 | static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg) |
| 494 | { |
| 495 | struct usb_device *udev = gspca_dev->dev; |
| 496 | int ret; |
| 497 | |
| 498 | ret = usb_control_msg(udev, |
| 499 | usb_rcvctrlpipe(udev, 0), |
| 500 | 0x01, |
| 501 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 502 | 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); |
| 503 | PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]); |
| 504 | if (ret < 0) |
| 505 | PDEBUG(D_ERR, "read failed"); |
| 506 | return gspca_dev->usb_buf[0]; |
| 507 | } |
| 508 | |
| 509 | /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7. |
| 510 | * (direction and output)? */ |
| 511 | static void ov534_set_led(struct gspca_dev *gspca_dev, int status) |
| 512 | { |
| 513 | u8 data; |
| 514 | |
| 515 | PDEBUG(D_CONF, "led status: %d", status); |
| 516 | |
| 517 | data = ov534_reg_read(gspca_dev, 0x21); |
| 518 | data |= 0x80; |
| 519 | ov534_reg_write(gspca_dev, 0x21, data); |
| 520 | |
| 521 | data = ov534_reg_read(gspca_dev, 0x23); |
| 522 | if (status) |
| 523 | data |= 0x80; |
| 524 | else |
| 525 | data &= ~0x80; |
| 526 | |
| 527 | ov534_reg_write(gspca_dev, 0x23, data); |
| 528 | |
| 529 | if (!status) { |
| 530 | data = ov534_reg_read(gspca_dev, 0x21); |
| 531 | data &= ~0x80; |
| 532 | ov534_reg_write(gspca_dev, 0x21, data); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | static int sccb_check_status(struct gspca_dev *gspca_dev) |
| 537 | { |
| 538 | u8 data; |
| 539 | int i; |
| 540 | |
| 541 | for (i = 0; i < 5; i++) { |
| 542 | data = ov534_reg_read(gspca_dev, OV534_REG_STATUS); |
| 543 | |
| 544 | switch (data) { |
| 545 | case 0x00: |
| 546 | return 1; |
| 547 | case 0x04: |
| 548 | return 0; |
| 549 | case 0x03: |
| 550 | break; |
| 551 | default: |
| 552 | PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5", |
| 553 | data, i + 1); |
| 554 | } |
| 555 | } |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val) |
| 560 | { |
| 561 | PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val); |
| 562 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); |
| 563 | ov534_reg_write(gspca_dev, OV534_REG_WRITE, val); |
| 564 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3); |
| 565 | |
| 566 | if (!sccb_check_status(gspca_dev)) |
| 567 | PDEBUG(D_ERR, "sccb_reg_write failed"); |
| 568 | } |
| 569 | |
| 570 | static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg) |
| 571 | { |
| 572 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); |
| 573 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2); |
| 574 | if (!sccb_check_status(gspca_dev)) |
| 575 | PDEBUG(D_ERR, "sccb_reg_read failed 1"); |
| 576 | |
| 577 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2); |
| 578 | if (!sccb_check_status(gspca_dev)) |
| 579 | PDEBUG(D_ERR, "sccb_reg_read failed 2"); |
| 580 | |
| 581 | return ov534_reg_read(gspca_dev, OV534_REG_READ); |
| 582 | } |
| 583 | |
| 584 | /* output a bridge sequence (reg - val) */ |
| 585 | static void reg_w_array(struct gspca_dev *gspca_dev, |
| 586 | const u8 (*data)[2], int len) |
| 587 | { |
| 588 | while (--len >= 0) { |
| 589 | ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]); |
| 590 | data++; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | /* output a sensor sequence (reg - val) */ |
| 595 | static void sccb_w_array(struct gspca_dev *gspca_dev, |
| 596 | const u8 (*data)[2], int len) |
| 597 | { |
| 598 | while (--len >= 0) { |
| 599 | if ((*data)[0] != 0xff) { |
| 600 | sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]); |
| 601 | } else { |
| 602 | sccb_reg_read(gspca_dev, (*data)[1]); |
| 603 | sccb_reg_write(gspca_dev, 0xff, 0x00); |
| 604 | } |
| 605 | data++; |
| 606 | } |
| 607 | } |
| 608 | |
Jean-Francois Moine | 69f1fe2 | 2009-11-12 06:10:36 -0300 | [diff] [blame] | 609 | /* ov772x specific controls */ |
| 610 | static void set_frame_rate(struct gspca_dev *gspca_dev) |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 611 | { |
| 612 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 613 | int i; |
| 614 | struct rate_s { |
| 615 | u8 fps; |
| 616 | u8 r11; |
| 617 | u8 r0d; |
| 618 | u8 re5; |
| 619 | }; |
| 620 | const struct rate_s *r; |
| 621 | static const struct rate_s rate_0[] = { /* 640x480 */ |
| 622 | {60, 0x01, 0xc1, 0x04}, |
| 623 | {50, 0x01, 0x41, 0x02}, |
| 624 | {40, 0x02, 0xc1, 0x04}, |
| 625 | {30, 0x04, 0x81, 0x02}, |
| 626 | {15, 0x03, 0x41, 0x04}, |
| 627 | }; |
| 628 | static const struct rate_s rate_1[] = { /* 320x240 */ |
| 629 | {125, 0x02, 0x81, 0x02}, |
| 630 | {100, 0x02, 0xc1, 0x04}, |
| 631 | {75, 0x03, 0xc1, 0x04}, |
| 632 | {60, 0x04, 0xc1, 0x04}, |
| 633 | {50, 0x02, 0x41, 0x04}, |
| 634 | {40, 0x03, 0x41, 0x04}, |
| 635 | {30, 0x04, 0x41, 0x04}, |
| 636 | }; |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 637 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 638 | if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) { |
| 639 | r = rate_0; |
| 640 | i = ARRAY_SIZE(rate_0); |
| 641 | } else { |
| 642 | r = rate_1; |
| 643 | i = ARRAY_SIZE(rate_1); |
| 644 | } |
| 645 | while (--i > 0) { |
| 646 | if (sd->frame_rate >= r->fps) |
| 647 | break; |
| 648 | r++; |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 649 | } |
| 650 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 651 | sccb_reg_write(gspca_dev, 0x11, r->r11); |
| 652 | sccb_reg_write(gspca_dev, 0x0d, r->r0d); |
| 653 | ov534_reg_write(gspca_dev, 0xe5, r->re5); |
| 654 | |
| 655 | PDEBUG(D_PROBE, "frame_rate: %d", r->fps); |
| 656 | } |
| 657 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 658 | static void setbrightness(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 659 | { |
| 660 | struct sd *sd = (struct sd *) gspca_dev; |
| 661 | |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 662 | sccb_reg_write(gspca_dev, 0x9b, sd->brightness); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 663 | } |
| 664 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 665 | static void setcontrast(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 666 | { |
| 667 | struct sd *sd = (struct sd *) gspca_dev; |
| 668 | |
Antonio Ospite | 7f9e9e8 | 2010-03-01 08:54:33 -0300 | [diff] [blame] | 669 | sccb_reg_write(gspca_dev, 0x9c, sd->contrast); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 670 | } |
| 671 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 672 | static void setgain(struct gspca_dev *gspca_dev) |
| 673 | { |
| 674 | struct sd *sd = (struct sd *) gspca_dev; |
| 675 | u8 val; |
| 676 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 677 | if (sd->agc) |
| 678 | return; |
| 679 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 680 | val = sd->gain; |
| 681 | switch (val & 0x30) { |
| 682 | case 0x00: |
| 683 | val &= 0x0f; |
| 684 | break; |
| 685 | case 0x10: |
| 686 | val &= 0x0f; |
| 687 | val |= 0x30; |
| 688 | break; |
| 689 | case 0x20: |
| 690 | val &= 0x0f; |
| 691 | val |= 0x70; |
| 692 | break; |
| 693 | default: |
| 694 | /* case 0x30: */ |
| 695 | val &= 0x0f; |
| 696 | val |= 0xf0; |
| 697 | break; |
| 698 | } |
| 699 | sccb_reg_write(gspca_dev, 0x00, val); |
| 700 | } |
| 701 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 702 | static void setexposure(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 703 | { |
| 704 | struct sd *sd = (struct sd *) gspca_dev; |
| 705 | u8 val; |
| 706 | |
Antonio Ospite | 18cf8c9 | 2010-03-01 08:53:34 -0300 | [diff] [blame] | 707 | if (sd->aec) |
| 708 | return; |
| 709 | |
| 710 | /* 'val' is one byte and represents half of the exposure value we are |
| 711 | * going to set into registers, a two bytes value: |
Mauro Carvalho Chehab | 000f64e | 2010-03-11 01:58:12 -0300 | [diff] [blame] | 712 | * |
Antonio Ospite | 18cf8c9 | 2010-03-01 08:53:34 -0300 | [diff] [blame] | 713 | * MSB: ((u16) val << 1) >> 8 == val >> 7 |
| 714 | * LSB: ((u16) val << 1) & 0xff == val << 1 |
| 715 | */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 716 | val = sd->exposure; |
| 717 | sccb_reg_write(gspca_dev, 0x08, val >> 7); |
| 718 | sccb_reg_write(gspca_dev, 0x10, val << 1); |
| 719 | } |
| 720 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 721 | static void setagc(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 722 | { |
| 723 | struct sd *sd = (struct sd *) gspca_dev; |
| 724 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 725 | if (sd->agc) { |
| 726 | sccb_reg_write(gspca_dev, 0x13, |
| 727 | sccb_reg_read(gspca_dev, 0x13) | 0x04); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 728 | sccb_reg_write(gspca_dev, 0x64, |
| 729 | sccb_reg_read(gspca_dev, 0x64) | 0x03); |
| 730 | } else { |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 731 | sccb_reg_write(gspca_dev, 0x13, |
| 732 | sccb_reg_read(gspca_dev, 0x13) & ~0x04); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 733 | sccb_reg_write(gspca_dev, 0x64, |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 734 | sccb_reg_read(gspca_dev, 0x64) & ~0x03); |
| 735 | |
| 736 | setgain(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 740 | static void setawb(struct gspca_dev *gspca_dev) |
| 741 | { |
| 742 | struct sd *sd = (struct sd *) gspca_dev; |
| 743 | |
Max Thrun | 8fef9d9 | 2010-02-27 17:20:23 -0300 | [diff] [blame] | 744 | if (sd->awb) { |
| 745 | sccb_reg_write(gspca_dev, 0x13, |
| 746 | sccb_reg_read(gspca_dev, 0x13) | 0x02); |
| 747 | sccb_reg_write(gspca_dev, 0x63, |
| 748 | sccb_reg_read(gspca_dev, 0x63) | 0xc0); |
| 749 | } else { |
| 750 | sccb_reg_write(gspca_dev, 0x13, |
| 751 | sccb_reg_read(gspca_dev, 0x13) & ~0x02); |
| 752 | sccb_reg_write(gspca_dev, 0x63, |
| 753 | sccb_reg_read(gspca_dev, 0x63) & ~0xc0); |
| 754 | } |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 755 | } |
| 756 | |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 757 | static void setaec(struct gspca_dev *gspca_dev) |
| 758 | { |
| 759 | struct sd *sd = (struct sd *) gspca_dev; |
| 760 | |
| 761 | if (sd->aec) |
| 762 | sccb_reg_write(gspca_dev, 0x13, |
| 763 | sccb_reg_read(gspca_dev, 0x13) | 0x01); |
| 764 | else { |
| 765 | sccb_reg_write(gspca_dev, 0x13, |
| 766 | sccb_reg_read(gspca_dev, 0x13) & ~0x01); |
| 767 | setexposure(gspca_dev); |
| 768 | } |
| 769 | } |
| 770 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 771 | static void setsharpness(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 772 | { |
| 773 | struct sd *sd = (struct sd *) gspca_dev; |
| 774 | u8 val; |
| 775 | |
| 776 | val = sd->sharpness; |
Max Thrun | 3149cfb | 2010-02-27 17:20:24 -0300 | [diff] [blame] | 777 | sccb_reg_write(gspca_dev, 0x91, val); /* Auto de-noise threshold */ |
| 778 | sccb_reg_write(gspca_dev, 0x8e, val); /* De-noise threshold */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static void sethflip(struct gspca_dev *gspca_dev) |
| 782 | { |
| 783 | struct sd *sd = (struct sd *) gspca_dev; |
| 784 | |
| 785 | if (sd->hflip == 0) |
| 786 | sccb_reg_write(gspca_dev, 0x0c, |
| 787 | sccb_reg_read(gspca_dev, 0x0c) | 0x40); |
| 788 | else |
| 789 | sccb_reg_write(gspca_dev, 0x0c, |
Max Thrun | eb17107 | 2010-02-27 17:20:25 -0300 | [diff] [blame] | 790 | sccb_reg_read(gspca_dev, 0x0c) & ~0x40); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static void setvflip(struct gspca_dev *gspca_dev) |
| 794 | { |
| 795 | struct sd *sd = (struct sd *) gspca_dev; |
| 796 | |
| 797 | if (sd->vflip == 0) |
| 798 | sccb_reg_write(gspca_dev, 0x0c, |
| 799 | sccb_reg_read(gspca_dev, 0x0c) | 0x80); |
| 800 | else |
| 801 | sccb_reg_write(gspca_dev, 0x0c, |
Max Thrun | eb17107 | 2010-02-27 17:20:25 -0300 | [diff] [blame] | 802 | sccb_reg_read(gspca_dev, 0x0c) & ~0x80); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 803 | } |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 804 | |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 805 | static void setfreqfltr(struct gspca_dev *gspca_dev) |
| 806 | { |
| 807 | struct sd *sd = (struct sd *) gspca_dev; |
| 808 | |
| 809 | if (sd->freqfltr == 0) |
| 810 | sccb_reg_write(gspca_dev, 0x2b, 0x00); |
| 811 | else |
| 812 | sccb_reg_write(gspca_dev, 0x2b, 0x9e); |
| 813 | } |
| 814 | |
| 815 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 816 | /* this function is called at probe time */ |
| 817 | static int sd_config(struct gspca_dev *gspca_dev, |
| 818 | const struct usb_device_id *id) |
| 819 | { |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 820 | struct sd *sd = (struct sd *) gspca_dev; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 821 | struct cam *cam; |
| 822 | |
| 823 | cam = &gspca_dev->cam; |
| 824 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 825 | cam->cam_mode = ov772x_mode; |
| 826 | cam->nmodes = ARRAY_SIZE(ov772x_mode); |
Antonio Ospite | 29b87f0 | 2010-01-17 03:27:04 -0300 | [diff] [blame] | 827 | cam->mode_framerates = ov772x_framerates; |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 828 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 829 | cam->bulk = 1; |
| 830 | cam->bulk_size = 16384; |
| 831 | cam->bulk_nurbs = 2; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 832 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 833 | sd->frame_rate = 30; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 834 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 835 | sd->brightness = BRIGHTNESS_DEF; |
| 836 | sd->contrast = CONTRAST_DEF; |
| 837 | sd->gain = GAIN_DEF; |
| 838 | sd->exposure = EXPO_DEF; |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 839 | #if AGC_DEF != 0 |
| 840 | sd->agc = AGC_DEF; |
Jean-Francois Moine | 2d19a2c | 2009-11-12 16:15:44 -0300 | [diff] [blame] | 841 | #else |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 842 | gspca_dev->ctrl_inac |= (1 << AWB_IDX); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 843 | #endif |
Max Thrun | 8fef9d9 | 2010-02-27 17:20:23 -0300 | [diff] [blame] | 844 | sd->awb = AWB_DEF; |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 845 | sd->aec = AEC_DEF; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 846 | sd->sharpness = SHARPNESS_DEF; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 847 | sd->hflip = HFLIP_DEF; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 848 | sd->vflip = VFLIP_DEF; |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 849 | sd->freqfltr = FREQFLTR_DEF; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 850 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | /* this function is called at probe and resume time */ |
| 855 | static int sd_init(struct gspca_dev *gspca_dev) |
| 856 | { |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 857 | u16 sensor_id; |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 858 | |
| 859 | /* reset bridge */ |
| 860 | ov534_reg_write(gspca_dev, 0xe7, 0x3a); |
| 861 | ov534_reg_write(gspca_dev, 0xe0, 0x08); |
| 862 | msleep(100); |
| 863 | |
| 864 | /* initialize the sensor address */ |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 865 | ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42); |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 866 | |
| 867 | /* reset sensor */ |
| 868 | sccb_reg_write(gspca_dev, 0x12, 0x80); |
| 869 | msleep(10); |
| 870 | |
| 871 | /* probe the sensor */ |
| 872 | sccb_reg_read(gspca_dev, 0x0a); |
| 873 | sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8; |
| 874 | sccb_reg_read(gspca_dev, 0x0b); |
| 875 | sensor_id |= sccb_reg_read(gspca_dev, 0x0b); |
| 876 | PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id); |
| 877 | |
| 878 | /* initialize */ |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 879 | reg_w_array(gspca_dev, bridge_init, |
| 880 | ARRAY_SIZE(bridge_init)); |
| 881 | ov534_set_led(gspca_dev, 1); |
| 882 | sccb_w_array(gspca_dev, sensor_init, |
| 883 | ARRAY_SIZE(sensor_init)); |
| 884 | ov534_reg_write(gspca_dev, 0xe0, 0x09); |
| 885 | ov534_set_led(gspca_dev, 0); |
| 886 | set_frame_rate(gspca_dev); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 891 | static int sd_start(struct gspca_dev *gspca_dev) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 892 | { |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 893 | int mode; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 894 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 895 | mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; |
| 896 | if (mode != 0) { /* 320x240 */ |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 897 | reg_w_array(gspca_dev, bridge_start_qvga, |
| 898 | ARRAY_SIZE(bridge_start_qvga)); |
| 899 | sccb_w_array(gspca_dev, sensor_start_qvga, |
| 900 | ARRAY_SIZE(sensor_start_qvga)); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 901 | } else { /* 640x480 */ |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 902 | reg_w_array(gspca_dev, bridge_start_vga, |
| 903 | ARRAY_SIZE(bridge_start_vga)); |
| 904 | sccb_w_array(gspca_dev, sensor_start_vga, |
| 905 | ARRAY_SIZE(sensor_start_vga)); |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 906 | } |
Jean-Francois Moine | 69f1fe2 | 2009-11-12 06:10:36 -0300 | [diff] [blame] | 907 | set_frame_rate(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 908 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 909 | setagc(gspca_dev); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 910 | setawb(gspca_dev); |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 911 | setaec(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 912 | setgain(gspca_dev); |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 913 | setexposure(gspca_dev); |
| 914 | setbrightness(gspca_dev); |
| 915 | setcontrast(gspca_dev); |
| 916 | setsharpness(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 917 | setvflip(gspca_dev); |
| 918 | sethflip(gspca_dev); |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 919 | setfreqfltr(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 920 | |
| 921 | ov534_set_led(gspca_dev, 1); |
| 922 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 923 | return 0; |
| 924 | } |
| 925 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 926 | static void sd_stopN(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 927 | { |
| 928 | ov534_reg_write(gspca_dev, 0xe0, 0x09); |
| 929 | ov534_set_led(gspca_dev, 0); |
| 930 | } |
| 931 | |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 932 | /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ |
| 933 | #define UVC_STREAM_EOH (1 << 7) |
| 934 | #define UVC_STREAM_ERR (1 << 6) |
| 935 | #define UVC_STREAM_STI (1 << 5) |
| 936 | #define UVC_STREAM_RES (1 << 4) |
| 937 | #define UVC_STREAM_SCR (1 << 3) |
| 938 | #define UVC_STREAM_PTS (1 << 2) |
| 939 | #define UVC_STREAM_EOF (1 << 1) |
| 940 | #define UVC_STREAM_FID (1 << 0) |
| 941 | |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 942 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 943 | u8 *data, int len) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 944 | { |
Jean-Francois Moine | 8c25205 | 2008-12-04 05:06:08 -0300 | [diff] [blame] | 945 | struct sd *sd = (struct sd *) gspca_dev; |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 946 | __u32 this_pts; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 947 | u16 this_fid; |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 948 | int remaining_len = len; |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 949 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 950 | do { |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 951 | len = min(remaining_len, 2048); |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 952 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 953 | /* Payloads are prefixed with a UVC-style header. We |
| 954 | consider a frame to start when the FID toggles, or the PTS |
| 955 | changes. A frame ends when EOF is set, and we've received |
| 956 | the correct number of bytes. */ |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 957 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 958 | /* Verify UVC header. Header length is always 12 */ |
| 959 | if (data[0] != 12 || len < 12) { |
| 960 | PDEBUG(D_PACK, "bad header"); |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 961 | goto discard; |
| 962 | } |
| 963 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 964 | /* Check errors */ |
| 965 | if (data[1] & UVC_STREAM_ERR) { |
| 966 | PDEBUG(D_PACK, "payload error"); |
| 967 | goto discard; |
Jean-Francois Moine | 3481c19 | 2009-03-19 06:05:06 -0300 | [diff] [blame] | 968 | } |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 969 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 970 | /* Extract PTS and FID */ |
| 971 | if (!(data[1] & UVC_STREAM_PTS)) { |
| 972 | PDEBUG(D_PACK, "PTS not present"); |
| 973 | goto discard; |
| 974 | } |
| 975 | this_pts = (data[5] << 24) | (data[4] << 16) |
| 976 | | (data[3] << 8) | data[2]; |
| 977 | this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0; |
| 978 | |
| 979 | /* If PTS or FID has changed, start a new frame. */ |
| 980 | if (this_pts != sd->last_pts || this_fid != sd->last_fid) { |
Jean-Francois Moine | ed47119 | 2009-04-23 13:52:27 -0300 | [diff] [blame] | 981 | if (gspca_dev->last_packet_type == INTER_PACKET) |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 982 | gspca_frame_add(gspca_dev, LAST_PACKET, |
| 983 | NULL, 0); |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 984 | sd->last_pts = this_pts; |
| 985 | sd->last_fid = this_fid; |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 986 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 987 | data + 12, len - 12); |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 988 | /* If this packet is marked as EOF, end the frame */ |
Jean-Francois Moine | ed47119 | 2009-04-23 13:52:27 -0300 | [diff] [blame] | 989 | } else if (data[1] & UVC_STREAM_EOF) { |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 990 | struct gspca_frame *frame; |
| 991 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 992 | sd->last_pts = 0; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 993 | frame = gspca_get_i_frame(gspca_dev); |
| 994 | if (frame == NULL) |
| 995 | goto discard; |
Antonio Ospite | 11edebc | 2010-01-17 03:42:14 -0300 | [diff] [blame] | 996 | if (frame->data_end - frame->data + (len - 12) != |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 997 | gspca_dev->width * gspca_dev->height * 2) { |
Antonio Ospite | 11edebc | 2010-01-17 03:42:14 -0300 | [diff] [blame] | 998 | PDEBUG(D_PACK, "wrong sized frame"); |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 999 | goto discard; |
| 1000 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1001 | gspca_frame_add(gspca_dev, LAST_PACKET, |
| 1002 | data + 12, len - 12); |
Jean-Francois Moine | ed47119 | 2009-04-23 13:52:27 -0300 | [diff] [blame] | 1003 | } else { |
| 1004 | |
| 1005 | /* Add the data from this payload */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1006 | gspca_frame_add(gspca_dev, INTER_PACKET, |
| 1007 | data + 12, len - 12); |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | /* Done this payload */ |
| 1011 | goto scan_next; |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 1012 | |
| 1013 | discard: |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1014 | /* Discard data until a new frame starts. */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1015 | gspca_dev->last_packet_type = DISCARD_PACKET; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1016 | |
| 1017 | scan_next: |
| 1018 | remaining_len -= len; |
| 1019 | data += len; |
| 1020 | } while (remaining_len > 0); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1021 | } |
| 1022 | |
Jean-Francois Moine | c22c4a2 | 2009-11-24 05:22:05 -0300 | [diff] [blame] | 1023 | /* controls */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1024 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) |
| 1025 | { |
| 1026 | struct sd *sd = (struct sd *) gspca_dev; |
| 1027 | |
| 1028 | sd->gain = val; |
| 1029 | if (gspca_dev->streaming) |
| 1030 | setgain(gspca_dev); |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) |
| 1035 | { |
| 1036 | struct sd *sd = (struct sd *) gspca_dev; |
| 1037 | |
| 1038 | *val = sd->gain; |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) |
| 1043 | { |
| 1044 | struct sd *sd = (struct sd *) gspca_dev; |
| 1045 | |
| 1046 | sd->exposure = val; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1047 | if (gspca_dev->streaming) |
| 1048 | setexposure(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) |
| 1053 | { |
| 1054 | struct sd *sd = (struct sd *) gspca_dev; |
| 1055 | |
| 1056 | *val = sd->exposure; |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 1060 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 1061 | { |
| 1062 | struct sd *sd = (struct sd *) gspca_dev; |
| 1063 | |
| 1064 | sd->brightness = val; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1065 | if (gspca_dev->streaming) |
| 1066 | setbrightness(gspca_dev); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 1071 | { |
| 1072 | struct sd *sd = (struct sd *) gspca_dev; |
| 1073 | |
| 1074 | *val = sd->brightness; |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) |
| 1079 | { |
| 1080 | struct sd *sd = (struct sd *) gspca_dev; |
| 1081 | |
| 1082 | sd->contrast = val; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1083 | if (gspca_dev->streaming) |
| 1084 | setcontrast(gspca_dev); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 1085 | return 0; |
| 1086 | } |
| 1087 | |
| 1088 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) |
| 1089 | { |
| 1090 | struct sd *sd = (struct sd *) gspca_dev; |
| 1091 | |
| 1092 | *val = sd->contrast; |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 1096 | static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val) |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1097 | { |
| 1098 | struct sd *sd = (struct sd *) gspca_dev; |
| 1099 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 1100 | sd->agc = val; |
Jean-Francois Moine | 2d19a2c | 2009-11-12 16:15:44 -0300 | [diff] [blame] | 1101 | |
Jean-Francois Moine | c22c4a2 | 2009-11-24 05:22:05 -0300 | [diff] [blame] | 1102 | if (gspca_dev->streaming) { |
Jean-Francois Moine | 2d19a2c | 2009-11-12 16:15:44 -0300 | [diff] [blame] | 1103 | |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1104 | /* the auto white balance control works only |
| 1105 | * when auto gain is set */ |
| 1106 | if (val) |
| 1107 | gspca_dev->ctrl_inac &= ~(1 << AWB_IDX); |
| 1108 | else |
| 1109 | gspca_dev->ctrl_inac |= (1 << AWB_IDX); |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 1110 | setagc(gspca_dev); |
Jean-Francois Moine | c22c4a2 | 2009-11-24 05:22:05 -0300 | [diff] [blame] | 1111 | } |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1112 | return 0; |
| 1113 | } |
| 1114 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 1115 | static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val) |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1116 | { |
| 1117 | struct sd *sd = (struct sd *) gspca_dev; |
| 1118 | |
Max Thrun | 8b7fbda | 2010-02-27 17:20:20 -0300 | [diff] [blame] | 1119 | *val = sd->agc; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1120 | return 0; |
| 1121 | } |
| 1122 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame] | 1123 | static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val) |
| 1124 | { |
| 1125 | struct sd *sd = (struct sd *) gspca_dev; |
| 1126 | |
| 1127 | sd->awb = val; |
| 1128 | if (gspca_dev->streaming) |
| 1129 | setawb(gspca_dev); |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
| 1133 | static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val) |
| 1134 | { |
| 1135 | struct sd *sd = (struct sd *) gspca_dev; |
| 1136 | |
| 1137 | *val = sd->awb; |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
Max Thrun | f293882 | 2010-02-27 17:20:21 -0300 | [diff] [blame] | 1141 | static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val) |
| 1142 | { |
| 1143 | struct sd *sd = (struct sd *) gspca_dev; |
| 1144 | |
| 1145 | sd->aec = val; |
| 1146 | if (gspca_dev->streaming) |
| 1147 | setaec(gspca_dev); |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val) |
| 1152 | { |
| 1153 | struct sd *sd = (struct sd *) gspca_dev; |
| 1154 | |
| 1155 | *val = sd->aec; |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1159 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) |
| 1160 | { |
| 1161 | struct sd *sd = (struct sd *) gspca_dev; |
| 1162 | |
| 1163 | sd->sharpness = val; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1164 | if (gspca_dev->streaming) |
| 1165 | setsharpness(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) |
| 1170 | { |
| 1171 | struct sd *sd = (struct sd *) gspca_dev; |
| 1172 | |
| 1173 | *val = sd->sharpness; |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) |
| 1178 | { |
| 1179 | struct sd *sd = (struct sd *) gspca_dev; |
| 1180 | |
| 1181 | sd->hflip = val; |
| 1182 | if (gspca_dev->streaming) |
| 1183 | sethflip(gspca_dev); |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
| 1187 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 1188 | { |
| 1189 | struct sd *sd = (struct sd *) gspca_dev; |
| 1190 | |
| 1191 | *val = sd->hflip; |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) |
| 1196 | { |
| 1197 | struct sd *sd = (struct sd *) gspca_dev; |
| 1198 | |
| 1199 | sd->vflip = val; |
| 1200 | if (gspca_dev->streaming) |
| 1201 | setvflip(gspca_dev); |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
| 1205 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 1206 | { |
| 1207 | struct sd *sd = (struct sd *) gspca_dev; |
| 1208 | |
| 1209 | *val = sd->vflip; |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 1213 | static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val) |
| 1214 | { |
| 1215 | struct sd *sd = (struct sd *) gspca_dev; |
| 1216 | |
| 1217 | sd->freqfltr = val; |
| 1218 | if (gspca_dev->streaming) |
| 1219 | setfreqfltr(gspca_dev); |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val) |
| 1224 | { |
| 1225 | struct sd *sd = (struct sd *) gspca_dev; |
| 1226 | |
| 1227 | *val = sd->freqfltr; |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | static int sd_querymenu(struct gspca_dev *gspca_dev, |
| 1232 | struct v4l2_querymenu *menu) |
| 1233 | { |
| 1234 | switch (menu->id) { |
| 1235 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 1236 | switch (menu->index) { |
| 1237 | case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ |
| 1238 | strcpy((char *) menu->name, "Disabled"); |
| 1239 | return 0; |
| 1240 | case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ |
| 1241 | strcpy((char *) menu->name, "50 Hz"); |
| 1242 | return 0; |
| 1243 | } |
| 1244 | break; |
| 1245 | } |
| 1246 | |
| 1247 | return -EINVAL; |
| 1248 | } |
| 1249 | |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1250 | /* get stream parameters (framerate) */ |
Jean-Francois Moine | 5c1a15a | 2008-12-21 15:02:54 -0300 | [diff] [blame] | 1251 | static int sd_get_streamparm(struct gspca_dev *gspca_dev, |
| 1252 | struct v4l2_streamparm *parm) |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1253 | { |
| 1254 | struct v4l2_captureparm *cp = &parm->parm.capture; |
| 1255 | struct v4l2_fract *tpf = &cp->timeperframe; |
| 1256 | struct sd *sd = (struct sd *) gspca_dev; |
| 1257 | |
| 1258 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1259 | return -EINVAL; |
| 1260 | |
| 1261 | cp->capability |= V4L2_CAP_TIMEPERFRAME; |
| 1262 | tpf->numerator = 1; |
| 1263 | tpf->denominator = sd->frame_rate; |
| 1264 | |
| 1265 | return 0; |
| 1266 | } |
| 1267 | |
| 1268 | /* set stream parameters (framerate) */ |
Jean-Francois Moine | 5c1a15a | 2008-12-21 15:02:54 -0300 | [diff] [blame] | 1269 | static int sd_set_streamparm(struct gspca_dev *gspca_dev, |
| 1270 | struct v4l2_streamparm *parm) |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1271 | { |
| 1272 | struct v4l2_captureparm *cp = &parm->parm.capture; |
| 1273 | struct v4l2_fract *tpf = &cp->timeperframe; |
| 1274 | struct sd *sd = (struct sd *) gspca_dev; |
| 1275 | |
| 1276 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1277 | return -EINVAL; |
| 1278 | |
| 1279 | /* Set requested framerate */ |
| 1280 | sd->frame_rate = tpf->denominator / tpf->numerator; |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1281 | if (gspca_dev->streaming) |
Jean-Francois Moine | 69f1fe2 | 2009-11-12 06:10:36 -0300 | [diff] [blame] | 1282 | set_frame_rate(gspca_dev); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1283 | |
| 1284 | /* Return the actual framerate */ |
| 1285 | tpf->numerator = 1; |
| 1286 | tpf->denominator = sd->frame_rate; |
| 1287 | |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1291 | /* sub-driver description */ |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1292 | static const struct sd_desc sd_desc = { |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1293 | .name = MODULE_NAME, |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1294 | .ctrls = sd_ctrls, |
| 1295 | .nctrls = ARRAY_SIZE(sd_ctrls), |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1296 | .config = sd_config, |
| 1297 | .init = sd_init, |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1298 | .start = sd_start, |
| 1299 | .stopN = sd_stopN, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1300 | .pkt_scan = sd_pkt_scan, |
Mosalam Ebrahimi | 4b78754 | 2010-03-08 13:52:17 -0300 | [diff] [blame] | 1301 | .querymenu = sd_querymenu, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1302 | .get_streamparm = sd_get_streamparm, |
| 1303 | .set_streamparm = sd_set_streamparm, |
| 1304 | }; |
| 1305 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1306 | /* -- module initialisation -- */ |
| 1307 | static const __devinitdata struct usb_device_id device_table[] = { |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1308 | {USB_DEVICE(0x1415, 0x2000)}, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1309 | {} |
| 1310 | }; |
| 1311 | |
| 1312 | MODULE_DEVICE_TABLE(usb, device_table); |
| 1313 | |
| 1314 | /* -- device connect -- */ |
| 1315 | static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 1316 | { |
Jean-Francois Moine | c52af79 | 2010-01-07 05:18:16 -0300 | [diff] [blame] | 1317 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1318 | THIS_MODULE); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | static struct usb_driver sd_driver = { |
| 1322 | .name = MODULE_NAME, |
| 1323 | .id_table = device_table, |
| 1324 | .probe = sd_probe, |
| 1325 | .disconnect = gspca_disconnect, |
| 1326 | #ifdef CONFIG_PM |
| 1327 | .suspend = gspca_suspend, |
| 1328 | .resume = gspca_resume, |
| 1329 | #endif |
| 1330 | }; |
| 1331 | |
| 1332 | /* -- module insert / remove -- */ |
| 1333 | static int __init sd_mod_init(void) |
| 1334 | { |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 1335 | int ret; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1336 | |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 1337 | ret = usb_register(&sd_driver); |
| 1338 | if (ret < 0) |
Alexey Klimov | e6b1484 | 2009-01-01 13:04:58 -0300 | [diff] [blame] | 1339 | return ret; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1340 | PDEBUG(D_PROBE, "registered"); |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | static void __exit sd_mod_exit(void) |
| 1345 | { |
| 1346 | usb_deregister(&sd_driver); |
| 1347 | PDEBUG(D_PROBE, "deregistered"); |
| 1348 | } |
| 1349 | |
| 1350 | module_init(sd_mod_init); |
| 1351 | module_exit(sd_mod_exit); |