Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Mars MR97310A library |
| 3 | * |
| 4 | * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com> |
| 5 | * |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 6 | * Support for the MR97310A cameras in addition to the Aiptek Pencam VGA+ |
| 7 | * and for the routines for detecting and classifying these various cameras, |
| 8 | * |
| 9 | * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu> |
| 10 | * |
| 11 | * Acknowledgements: |
| 12 | * |
| 13 | * The MR97311A support in gspca/mars.c has been helpful in understanding some |
| 14 | * of the registers in these cameras. |
| 15 | * |
| 16 | * Hans de Goede <hdgoede@redhat.com> and |
| 17 | * Thomas Kaiser <thomas@kaiser-linux.li> |
| 18 | * have assisted with their experience. Each of them has also helped by |
| 19 | * testing a previously unsupported camera. |
| 20 | * |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 21 | * This program is free software; you can redistribute it and/or modify |
| 22 | * it under the terms of the GNU General Public License as published by |
| 23 | * the Free Software Foundation; either version 2 of the License, or |
| 24 | * any later version. |
| 25 | * |
| 26 | * This program is distributed in the hope that it will be useful, |
| 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 | * GNU General Public License for more details. |
| 30 | * |
| 31 | * You should have received a copy of the GNU General Public License |
| 32 | * along with this program; if not, write to the Free Software |
| 33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 34 | */ |
| 35 | |
| 36 | #define MODULE_NAME "mr97310a" |
| 37 | |
| 38 | #include "gspca.h" |
| 39 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 40 | #define CAM_TYPE_CIF 0 |
| 41 | #define CAM_TYPE_VGA 1 |
| 42 | |
| 43 | #define MR97310A_BRIGHTNESS_MIN -254 |
| 44 | #define MR97310A_BRIGHTNESS_MAX 255 |
| 45 | #define MR97310A_BRIGHTNESS_DEFAULT 0 |
| 46 | |
| 47 | #define MR97310A_EXPOSURE_MIN 300 |
| 48 | #define MR97310A_EXPOSURE_MAX 4095 |
| 49 | #define MR97310A_EXPOSURE_DEFAULT 1000 |
| 50 | |
| 51 | #define MR97310A_GAIN_MIN 0 |
| 52 | #define MR97310A_GAIN_MAX 31 |
| 53 | #define MR97310A_GAIN_DEFAULT 25 |
| 54 | |
| 55 | MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>," |
| 56 | "Theodore Kilgore <kilgota@auburn.edu>"); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 57 | MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver"); |
| 58 | MODULE_LICENSE("GPL"); |
| 59 | |
| 60 | /* specific webcam descriptor */ |
| 61 | struct sd { |
| 62 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 63 | u8 sof_read; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 64 | u8 cam_type; /* 0 is CIF and 1 is VGA */ |
| 65 | u8 sensor_type; /* We use 0 and 1 here, too. */ |
| 66 | u8 do_lcd_stop; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 67 | |
| 68 | int brightness; |
| 69 | u16 exposure; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 70 | u8 gain; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 71 | }; |
| 72 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 73 | struct sensor_w_data { |
| 74 | u8 reg; |
| 75 | u8 flags; |
| 76 | u8 data[16]; |
| 77 | int len; |
| 78 | }; |
| 79 | |
| 80 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); |
| 81 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); |
| 82 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); |
| 83 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); |
| 84 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); |
| 85 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 86 | static void setbrightness(struct gspca_dev *gspca_dev); |
| 87 | static void setexposure(struct gspca_dev *gspca_dev); |
| 88 | static void setgain(struct gspca_dev *gspca_dev); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 89 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 90 | /* V4L2 controls supported by the driver */ |
| 91 | static struct ctrl sd_ctrls[] = { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 92 | { |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 93 | #define BRIGHTNESS_IDX 0 |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 94 | { |
| 95 | .id = V4L2_CID_BRIGHTNESS, |
| 96 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 97 | .name = "Brightness", |
| 98 | .minimum = MR97310A_BRIGHTNESS_MIN, |
| 99 | .maximum = MR97310A_BRIGHTNESS_MAX, |
| 100 | .step = 1, |
| 101 | .default_value = MR97310A_BRIGHTNESS_DEFAULT, |
| 102 | .flags = 0, |
| 103 | }, |
| 104 | .set = sd_setbrightness, |
| 105 | .get = sd_getbrightness, |
| 106 | }, |
| 107 | { |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 108 | #define EXPOSURE_IDX 1 |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 109 | { |
| 110 | .id = V4L2_CID_EXPOSURE, |
| 111 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 112 | .name = "Exposure", |
| 113 | .minimum = MR97310A_EXPOSURE_MIN, |
| 114 | .maximum = MR97310A_EXPOSURE_MAX, |
| 115 | .step = 1, |
| 116 | .default_value = MR97310A_EXPOSURE_DEFAULT, |
| 117 | .flags = 0, |
| 118 | }, |
| 119 | .set = sd_setexposure, |
| 120 | .get = sd_getexposure, |
| 121 | }, |
| 122 | { |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 123 | #define GAIN_IDX 2 |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 124 | { |
| 125 | .id = V4L2_CID_GAIN, |
| 126 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 127 | .name = "Gain", |
| 128 | .minimum = MR97310A_GAIN_MIN, |
| 129 | .maximum = MR97310A_GAIN_MAX, |
| 130 | .step = 1, |
| 131 | .default_value = MR97310A_GAIN_DEFAULT, |
| 132 | .flags = 0, |
| 133 | }, |
| 134 | .set = sd_setgain, |
| 135 | .get = sd_getgain, |
| 136 | }, |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | static const struct v4l2_pix_format vga_mode[] = { |
| 140 | {160, 120, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 141 | .bytesperline = 160, |
| 142 | .sizeimage = 160 * 120, |
| 143 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 144 | .priv = 4}, |
| 145 | {176, 144, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 146 | .bytesperline = 176, |
| 147 | .sizeimage = 176 * 144, |
| 148 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 149 | .priv = 3}, |
| 150 | {320, 240, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 151 | .bytesperline = 320, |
| 152 | .sizeimage = 320 * 240, |
| 153 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 154 | .priv = 2}, |
| 155 | {352, 288, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 156 | .bytesperline = 352, |
| 157 | .sizeimage = 352 * 288, |
| 158 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 159 | .priv = 1}, |
| 160 | {640, 480, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 161 | .bytesperline = 640, |
| 162 | .sizeimage = 640 * 480, |
| 163 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 164 | .priv = 0}, |
| 165 | }; |
| 166 | |
| 167 | /* the bytes to write are in gspca_dev->usb_buf */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 168 | static int mr_write(struct gspca_dev *gspca_dev, int len) |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 169 | { |
| 170 | int rc; |
| 171 | |
| 172 | rc = usb_bulk_msg(gspca_dev->dev, |
| 173 | usb_sndbulkpipe(gspca_dev->dev, 4), |
Jean-Francois Moine | 92e8c91 | 2009-02-02 16:25:38 -0300 | [diff] [blame] | 174 | gspca_dev->usb_buf, len, NULL, 500); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 175 | if (rc < 0) |
| 176 | PDEBUG(D_ERR, "reg write [%02x] error %d", |
| 177 | gspca_dev->usb_buf[0], rc); |
| 178 | return rc; |
| 179 | } |
| 180 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 181 | /* the bytes are read into gspca_dev->usb_buf */ |
| 182 | static int mr_read(struct gspca_dev *gspca_dev, int len) |
| 183 | { |
| 184 | int rc; |
| 185 | |
| 186 | rc = usb_bulk_msg(gspca_dev->dev, |
| 187 | usb_rcvbulkpipe(gspca_dev->dev, 3), |
| 188 | gspca_dev->usb_buf, len, NULL, 500); |
| 189 | if (rc < 0) |
| 190 | PDEBUG(D_ERR, "reg read [%02x] error %d", |
| 191 | gspca_dev->usb_buf[0], rc); |
| 192 | return rc; |
| 193 | } |
| 194 | |
| 195 | static int sensor_write_reg(struct gspca_dev *gspca_dev, u8 reg, u8 flags, |
| 196 | const u8 *data, int len) |
| 197 | { |
| 198 | gspca_dev->usb_buf[0] = 0x1f; |
| 199 | gspca_dev->usb_buf[1] = flags; |
| 200 | gspca_dev->usb_buf[2] = reg; |
| 201 | memcpy(gspca_dev->usb_buf + 3, data, len); |
| 202 | |
| 203 | return mr_write(gspca_dev, len + 3); |
| 204 | } |
| 205 | |
| 206 | static int sensor_write_regs(struct gspca_dev *gspca_dev, |
| 207 | const struct sensor_w_data *data, int len) |
| 208 | { |
| 209 | int i, rc; |
| 210 | |
| 211 | for (i = 0; i < len; i++) { |
| 212 | rc = sensor_write_reg(gspca_dev, data[i].reg, data[i].flags, |
| 213 | data[i].data, data[i].len); |
| 214 | if (rc < 0) |
| 215 | return rc; |
| 216 | } |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int sensor_write1(struct gspca_dev *gspca_dev, u8 reg, u8 data) |
| 222 | { |
| 223 | u8 buf; |
| 224 | int rc; |
| 225 | |
| 226 | buf = data; |
| 227 | rc = sensor_write_reg(gspca_dev, reg, 0x01, &buf, 1); |
| 228 | if (rc < 0) |
| 229 | return rc; |
| 230 | |
| 231 | buf = 0x01; |
| 232 | rc = sensor_write_reg(gspca_dev, 0x13, 0x00, &buf, 1); |
| 233 | if (rc < 0) |
| 234 | return rc; |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static int cam_get_response16(struct gspca_dev *gspca_dev) |
| 240 | { |
| 241 | __u8 *data = gspca_dev->usb_buf; |
| 242 | int err_code; |
| 243 | |
| 244 | data[0] = 0x21; |
| 245 | err_code = mr_write(gspca_dev, 1); |
| 246 | if (err_code < 0) |
| 247 | return err_code; |
| 248 | |
| 249 | err_code = mr_read(gspca_dev, 16); |
| 250 | return err_code; |
| 251 | } |
| 252 | |
| 253 | static int zero_the_pointer(struct gspca_dev *gspca_dev) |
| 254 | { |
| 255 | __u8 *data = gspca_dev->usb_buf; |
| 256 | int err_code; |
| 257 | u8 status = 0; |
| 258 | int tries = 0; |
| 259 | |
| 260 | err_code = cam_get_response16(gspca_dev); |
| 261 | if (err_code < 0) |
| 262 | return err_code; |
| 263 | |
| 264 | err_code = mr_write(gspca_dev, 1); |
| 265 | data[0] = 0x19; |
| 266 | data[1] = 0x51; |
| 267 | err_code = mr_write(gspca_dev, 2); |
| 268 | if (err_code < 0) |
| 269 | return err_code; |
| 270 | |
| 271 | err_code = cam_get_response16(gspca_dev); |
| 272 | if (err_code < 0) |
| 273 | return err_code; |
| 274 | |
| 275 | data[0] = 0x19; |
| 276 | data[1] = 0xba; |
| 277 | err_code = mr_write(gspca_dev, 2); |
| 278 | if (err_code < 0) |
| 279 | return err_code; |
| 280 | |
| 281 | err_code = cam_get_response16(gspca_dev); |
| 282 | if (err_code < 0) |
| 283 | return err_code; |
| 284 | |
| 285 | data[0] = 0x19; |
| 286 | data[1] = 0x00; |
| 287 | err_code = mr_write(gspca_dev, 2); |
| 288 | if (err_code < 0) |
| 289 | return err_code; |
| 290 | |
| 291 | err_code = cam_get_response16(gspca_dev); |
| 292 | if (err_code < 0) |
| 293 | return err_code; |
| 294 | |
| 295 | data[0] = 0x19; |
| 296 | data[1] = 0x00; |
| 297 | err_code = mr_write(gspca_dev, 2); |
| 298 | if (err_code < 0) |
| 299 | return err_code; |
| 300 | |
| 301 | while (status != 0x0a && tries < 256) { |
| 302 | err_code = cam_get_response16(gspca_dev); |
| 303 | status = data[0]; |
| 304 | tries++; |
| 305 | if (err_code < 0) |
| 306 | return err_code; |
| 307 | } |
| 308 | PDEBUG(D_ERR, "status is %02x", status); |
| 309 | |
| 310 | tries = 0; |
| 311 | while (tries < 4) { |
| 312 | data[0] = 0x19; |
| 313 | data[1] = 0x00; |
| 314 | err_code = mr_write(gspca_dev, 2); |
| 315 | if (err_code < 0) |
| 316 | return err_code; |
| 317 | |
| 318 | err_code = cam_get_response16(gspca_dev); |
| 319 | status = data[0]; |
| 320 | tries++; |
| 321 | if (err_code < 0) |
| 322 | return err_code; |
| 323 | } |
| 324 | PDEBUG(D_ERR, "Read 16 bytes from camera"); |
| 325 | |
| 326 | data[0] = 0x19; |
| 327 | err_code = mr_write(gspca_dev, 1); |
| 328 | if (err_code < 0) |
| 329 | return err_code; |
| 330 | |
| 331 | err_code = mr_read(gspca_dev, 16); |
| 332 | if (err_code < 0) |
| 333 | return err_code; |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | static u8 get_sensor_id(struct gspca_dev *gspca_dev) |
| 339 | { |
| 340 | int err_code; |
| 341 | |
| 342 | gspca_dev->usb_buf[0] = 0x1e; |
| 343 | err_code = mr_write(gspca_dev, 1); |
| 344 | if (err_code < 0) |
| 345 | return err_code; |
| 346 | |
| 347 | err_code = mr_read(gspca_dev, 16); |
| 348 | if (err_code < 0) |
| 349 | return err_code; |
| 350 | |
| 351 | PDEBUG(D_ERR, "Read 16 bytes from camera"); |
| 352 | PDEBUG(D_ERR, "Byte zero reported is %01x", gspca_dev->usb_buf[0]); |
| 353 | |
| 354 | return gspca_dev->usb_buf[0]; |
| 355 | } |
| 356 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 357 | /* this function is called at probe time */ |
| 358 | static int sd_config(struct gspca_dev *gspca_dev, |
| 359 | const struct usb_device_id *id) |
| 360 | { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 361 | struct sd *sd = (struct sd *) gspca_dev; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 362 | struct cam *cam; |
Hans de Goede | 5f5e26b | 2009-08-14 10:40:26 -0300 | [diff] [blame^] | 363 | __u8 *data = gspca_dev->usb_buf; |
| 364 | int err_code; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 365 | |
| 366 | cam = &gspca_dev->cam; |
| 367 | cam->cam_mode = vga_mode; |
| 368 | cam->nmodes = ARRAY_SIZE(vga_mode); |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 369 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 370 | PDEBUG(D_PROBE, |
| 371 | "MR97310A camera detected" |
| 372 | " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 373 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 374 | if (id->idProduct == 0x010e) { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 375 | sd->cam_type = CAM_TYPE_CIF; |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 376 | cam->nmodes--; |
Hans de Goede | 5f5e26b | 2009-08-14 10:40:26 -0300 | [diff] [blame^] | 377 | |
| 378 | data[0] = 0x01; |
| 379 | data[1] = 0x01; |
| 380 | err_code = mr_write(gspca_dev, 2); |
| 381 | if (err_code < 0) |
| 382 | return err_code; |
| 383 | |
| 384 | msleep(200); |
| 385 | data[0] = get_sensor_id(gspca_dev); |
| 386 | /* |
| 387 | * Known CIF cameras. If you have another to report, please do |
| 388 | * |
| 389 | * Name byte just read sd->sensor_type |
| 390 | * reported by |
| 391 | * Sakar Spy-shot 0x28 T. Kilgore 0 |
| 392 | * Innovage 0xf5 (unstable) T. Kilgore 0 |
| 393 | * Vivitar Mini 0x53 H. De Goede 0 |
| 394 | * Vivitar Mini 0x08 T. Kilgore 1 |
| 395 | * Elta-Media 8212dc 0x23 T. Kaiser 1 |
| 396 | * Philips dig. keych. 0x37 T. Kilgore 1 |
| 397 | */ |
| 398 | if ((data[0] & 0x78) == 8 || |
| 399 | ((data[0] & 0x2) == 0x2 && data[0] != 0x53)) |
| 400 | sd->sensor_type = 1; |
| 401 | else |
| 402 | sd->sensor_type = 0; |
| 403 | |
| 404 | PDEBUG(D_ERR, "Sensor type is %01x", sd->sensor_type); |
| 405 | |
| 406 | if (sd->sensor_type == 0) |
| 407 | gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX) | |
| 408 | (1 << EXPOSURE_IDX) | (1 << GAIN_IDX); |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 409 | } else { |
| 410 | sd->cam_type = CAM_TYPE_VGA; |
| 411 | gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX) | |
| 412 | (1 << EXPOSURE_IDX) | (1 << GAIN_IDX); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 413 | } |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 414 | |
| 415 | sd->brightness = MR97310A_BRIGHTNESS_DEFAULT; |
| 416 | sd->exposure = MR97310A_EXPOSURE_DEFAULT; |
| 417 | sd->gain = MR97310A_GAIN_DEFAULT; |
| 418 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | /* this function is called at probe and resume time */ |
| 423 | static int sd_init(struct gspca_dev *gspca_dev) |
| 424 | { |
| 425 | return 0; |
| 426 | } |
| 427 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 428 | static int start_cif_cam(struct gspca_dev *gspca_dev) |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 429 | { |
| 430 | struct sd *sd = (struct sd *) gspca_dev; |
| 431 | __u8 *data = gspca_dev->usb_buf; |
| 432 | int err_code; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 433 | const __u8 startup_string[] = { |
| 434 | 0x00, |
| 435 | 0x0d, |
| 436 | 0x01, |
| 437 | 0x00, /* Hsize/8 for 352 or 320 */ |
| 438 | 0x00, /* Vsize/4 for 288 or 240 */ |
| 439 | 0x13, /* or 0xbb, depends on sensor */ |
| 440 | 0x00, /* Hstart, depends on res. */ |
| 441 | 0x00, /* reserved ? */ |
| 442 | 0x00, /* Vstart, depends on res. and sensor */ |
| 443 | 0x50, /* 0x54 to get 176 or 160 */ |
| 444 | 0xc0 |
| 445 | }; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 446 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 447 | /* Note: Some of the above descriptions guessed from MR97113A driver */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 448 | data[0] = 0x01; |
| 449 | data[1] = 0x01; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 450 | err_code = mr_write(gspca_dev, 2); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 451 | if (err_code < 0) |
| 452 | return err_code; |
| 453 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 454 | memcpy(data, startup_string, 11); |
| 455 | if (sd->sensor_type) |
| 456 | data[5] = 0xbb; |
| 457 | |
| 458 | switch (gspca_dev->width) { |
| 459 | case 160: |
| 460 | data[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */ |
| 461 | /* fall thru */ |
| 462 | case 320: |
| 463 | default: |
| 464 | data[3] = 0x28; /* reg 2, H size/8 */ |
| 465 | data[4] = 0x3c; /* reg 3, V size/4 */ |
| 466 | data[6] = 0x14; /* reg 5, H start */ |
| 467 | data[8] = 0x1a + sd->sensor_type; /* reg 7, V start */ |
| 468 | break; |
| 469 | case 176: |
| 470 | data[9] |= 0x04; /* reg 8, 2:1 scale down from 352 */ |
| 471 | /* fall thru */ |
| 472 | case 352: |
| 473 | data[3] = 0x2c; /* reg 2, H size/8 */ |
| 474 | data[4] = 0x48; /* reg 3, V size/4 */ |
| 475 | data[6] = 0x06; /* reg 5, H start */ |
| 476 | data[8] = 0x06 + sd->sensor_type; /* reg 7, V start */ |
| 477 | break; |
| 478 | } |
| 479 | err_code = mr_write(gspca_dev, 11); |
| 480 | if (err_code < 0) |
| 481 | return err_code; |
| 482 | |
| 483 | if (!sd->sensor_type) { |
| 484 | const struct sensor_w_data cif_sensor0_init_data[] = { |
| 485 | {0x02, 0x00, {0x03, 0x5a, 0xb5, 0x01, |
| 486 | 0x0f, 0x14, 0x0f, 0x10}, 8}, |
| 487 | {0x0c, 0x00, {0x04, 0x01, 0x01, 0x00, 0x1f}, 5}, |
| 488 | {0x12, 0x00, {0x07}, 1}, |
| 489 | {0x1f, 0x00, {0x06}, 1}, |
| 490 | {0x27, 0x00, {0x04}, 1}, |
| 491 | {0x29, 0x00, {0x0c}, 1}, |
| 492 | {0x40, 0x00, {0x40, 0x00, 0x04}, 3}, |
| 493 | {0x50, 0x00, {0x60}, 1}, |
| 494 | {0x60, 0x00, {0x06}, 1}, |
| 495 | {0x6b, 0x00, {0x85, 0x85, 0xc8, 0xc8, 0xc8, 0xc8}, 6}, |
| 496 | {0x72, 0x00, {0x1e, 0x56}, 2}, |
| 497 | {0x75, 0x00, {0x58, 0x40, 0xa2, 0x02, 0x31, 0x02, |
| 498 | 0x31, 0x80, 0x00}, 9}, |
| 499 | {0x11, 0x00, {0x01}, 1}, |
| 500 | {0, 0, {0}, 0} |
| 501 | }; |
| 502 | err_code = sensor_write_regs(gspca_dev, cif_sensor0_init_data, |
| 503 | ARRAY_SIZE(cif_sensor0_init_data)); |
| 504 | } else { /* sd->sensor_type = 1 */ |
| 505 | const struct sensor_w_data cif_sensor1_init_data[] = { |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 506 | /* Reg 3,4, 7,8 get set by the controls */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 507 | {0x02, 0x00, {0x10}, 1}, |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 508 | {0x05, 0x01, {0x22}, 1}, /* 5/6 also seen as 65h/32h */ |
| 509 | {0x06, 0x01, {0x00}, 1}, |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 510 | {0x09, 0x02, {0x0e}, 1}, |
| 511 | {0x0a, 0x02, {0x05}, 1}, |
| 512 | {0x0b, 0x02, {0x05}, 1}, |
| 513 | {0x0c, 0x02, {0x0f}, 1}, |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 514 | {0x0d, 0x02, {0x07}, 1}, |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 515 | {0x0e, 0x02, {0x0c}, 1}, |
| 516 | {0x0f, 0x00, {0x00}, 1}, |
| 517 | {0x10, 0x00, {0x06}, 1}, |
| 518 | {0x11, 0x00, {0x07}, 1}, |
| 519 | {0x12, 0x00, {0x00}, 1}, |
| 520 | {0x13, 0x00, {0x01}, 1}, |
| 521 | {0, 0, {0}, 0} |
| 522 | }; |
| 523 | err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data, |
| 524 | ARRAY_SIZE(cif_sensor1_init_data)); |
| 525 | } |
| 526 | if (err_code < 0) |
| 527 | return err_code; |
| 528 | |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 529 | setbrightness(gspca_dev); |
| 530 | setexposure(gspca_dev); |
| 531 | setgain(gspca_dev); |
| 532 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 533 | msleep(200); |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 534 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 535 | data[0] = 0x00; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 536 | data[1] = 0x4d; /* ISOC transfering enable... */ |
| 537 | err_code = mr_write(gspca_dev, 2); |
| 538 | if (err_code < 0) |
| 539 | return err_code; |
| 540 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static int start_vga_cam(struct gspca_dev *gspca_dev) |
| 545 | { |
| 546 | struct sd *sd = (struct sd *) gspca_dev; |
| 547 | __u8 *data = gspca_dev->usb_buf; |
| 548 | int err_code; |
| 549 | const __u8 startup_string[] = {0x00, 0x0d, 0x01, 0x00, 0x00, 0x2b, |
| 550 | 0x00, 0x00, 0x00, 0x50, 0xc0}; |
| 551 | |
| 552 | /* What some of these mean is explained in start_cif_cam(), above */ |
| 553 | sd->sof_read = 0; |
| 554 | |
| 555 | /* |
| 556 | * We have to know which camera we have, because the register writes |
| 557 | * depend upon the camera. This test, run before we actually enter |
| 558 | * the initialization routine, distinguishes most of the cameras, If |
| 559 | * needed, another routine is done later, too. |
| 560 | */ |
| 561 | memset(data, 0, 16); |
| 562 | data[0] = 0x20; |
| 563 | err_code = mr_write(gspca_dev, 1); |
| 564 | if (err_code < 0) |
| 565 | return err_code; |
| 566 | |
| 567 | err_code = mr_read(gspca_dev, 16); |
| 568 | if (err_code < 0) |
| 569 | return err_code; |
| 570 | |
| 571 | PDEBUG(D_ERR, "Read 16 bytes from camera"); |
| 572 | PDEBUG(D_ERR, "Byte reported is %02x", data[0]); |
| 573 | |
| 574 | msleep(200); |
| 575 | /* |
| 576 | * Known VGA cameras. If you have another to report, please do |
| 577 | * |
| 578 | * Name byte just read sd->sensor_type |
| 579 | * sd->do_lcd_stop |
| 580 | * Aiptek Pencam VGA+ 0x31 0 1 |
| 581 | * ION digital 0x31 0 1 |
| 582 | * Argus DC-1620 0x30 1 0 |
| 583 | * Argus QuickClix 0x30 1 1 (not caught here) |
| 584 | */ |
| 585 | sd->sensor_type = data[0] & 1; |
| 586 | sd->do_lcd_stop = (~data[0]) & 1; |
| 587 | |
| 588 | |
| 589 | |
| 590 | /* Streaming setup begins here. */ |
| 591 | |
| 592 | |
| 593 | data[0] = 0x01; |
| 594 | data[1] = 0x01; |
| 595 | err_code = mr_write(gspca_dev, 2); |
| 596 | if (err_code < 0) |
| 597 | return err_code; |
| 598 | |
| 599 | /* |
| 600 | * A second test can now resolve any remaining ambiguity in the |
| 601 | * identification of the camera type, |
| 602 | */ |
| 603 | if (!sd->sensor_type) { |
| 604 | data[0] = get_sensor_id(gspca_dev); |
| 605 | if (data[0] == 0x7f) { |
| 606 | sd->sensor_type = 1; |
| 607 | PDEBUG(D_ERR, "sensor_type corrected to 1"); |
| 608 | } |
| 609 | msleep(200); |
| 610 | } |
| 611 | |
| 612 | /* |
| 613 | * Known VGA cameras. |
| 614 | * This test is only run if the previous test returned 0x30, but |
| 615 | * here is the information for all others, too, just for reference. |
| 616 | * |
| 617 | * Name byte just read sd->sensor_type |
| 618 | * |
| 619 | * Aiptek Pencam VGA+ 0xfb (this test not run) 1 |
| 620 | * ION digital 0xbd (this test not run) 1 |
| 621 | * Argus DC-1620 0xe5 (no change) 0 |
| 622 | * Argus QuickClix 0x7f (reclassified) 1 |
| 623 | */ |
| 624 | memcpy(data, startup_string, 11); |
| 625 | if (!sd->sensor_type) { |
| 626 | data[5] = 0x00; |
| 627 | data[10] = 0x91; |
| 628 | } |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 629 | |
| 630 | switch (gspca_dev->width) { |
| 631 | case 160: |
| 632 | data[9] |= 0x0c; /* reg 8, 4:1 scale down */ |
| 633 | /* fall thru */ |
| 634 | case 320: |
| 635 | data[9] |= 0x04; /* reg 8, 2:1 scale down */ |
| 636 | /* fall thru */ |
| 637 | case 640: |
| 638 | default: |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 639 | data[3] = 0x50; /* reg 2, H size/8 */ |
| 640 | data[4] = 0x78; /* reg 3, V size/4 */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 641 | data[6] = 0x04; /* reg 5, H start */ |
| 642 | data[8] = 0x03; /* reg 7, V start */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 643 | if (sd->do_lcd_stop) |
| 644 | data[8] = 0x04; /* Bayer tile shifted */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 645 | break; |
| 646 | |
| 647 | case 176: |
| 648 | data[9] |= 0x04; /* reg 8, 2:1 scale down */ |
| 649 | /* fall thru */ |
| 650 | case 352: |
| 651 | data[3] = 0x2c; /* reg 2, H size */ |
| 652 | data[4] = 0x48; /* reg 3, V size */ |
| 653 | data[6] = 0x94; /* reg 5, H start */ |
| 654 | data[8] = 0x63; /* reg 7, V start */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 655 | if (sd->do_lcd_stop) |
| 656 | data[8] = 0x64; /* Bayer tile shifted */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 657 | break; |
| 658 | } |
| 659 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 660 | err_code = mr_write(gspca_dev, 11); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 661 | if (err_code < 0) |
| 662 | return err_code; |
| 663 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 664 | if (!sd->sensor_type) { |
| 665 | /* The only known sensor_type 0 cam is the Argus DC-1620 */ |
| 666 | const struct sensor_w_data vga_sensor0_init_data[] = { |
| 667 | {0x01, 0x00, {0x0c, 0x00, 0x04}, 3}, |
| 668 | {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4}, |
| 669 | {0x20, 0x00, {0x00, 0x80, 0x00, 0x08}, 4}, |
| 670 | {0x25, 0x00, {0x03, 0xa9, 0x80}, 3}, |
| 671 | {0x30, 0x00, {0x30, 0x18, 0x10, 0x18}, 4}, |
| 672 | {0, 0, {0}, 0} |
| 673 | }; |
| 674 | err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data, |
| 675 | ARRAY_SIZE(vga_sensor0_init_data)); |
| 676 | } else { /* sd->sensor_type = 1 */ |
| 677 | const struct sensor_w_data vga_sensor1_init_data[] = { |
| 678 | {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00, |
| 679 | 0x07, 0x00, 0x01}, 8}, |
| 680 | {0x11, 0x04, {0x01}, 1}, |
| 681 | /*{0x0a, 0x00, {0x00, 0x01, 0x00, 0x00, 0x01, */ |
| 682 | {0x0a, 0x00, {0x01, 0x06, 0x00, 0x00, 0x01, |
| 683 | 0x00, 0x0a}, 7}, |
| 684 | {0x11, 0x04, {0x01}, 1}, |
| 685 | {0x12, 0x00, {0x00, 0x63, 0x00, 0x70, 0x00, 0x00}, 6}, |
| 686 | {0x11, 0x04, {0x01}, 1}, |
| 687 | {0, 0, {0}, 0} |
| 688 | }; |
| 689 | err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data, |
| 690 | ARRAY_SIZE(vga_sensor1_init_data)); |
| 691 | } |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 692 | if (err_code < 0) |
| 693 | return err_code; |
| 694 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 695 | msleep(200); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 696 | data[0] = 0x00; |
| 697 | data[1] = 0x4d; /* ISOC transfering enable... */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 698 | err_code = mr_write(gspca_dev, 2); |
| 699 | |
| 700 | return err_code; |
| 701 | } |
| 702 | |
| 703 | static int sd_start(struct gspca_dev *gspca_dev) |
| 704 | { |
| 705 | struct sd *sd = (struct sd *) gspca_dev; |
| 706 | int err_code; |
| 707 | struct cam *cam; |
| 708 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 709 | cam = &gspca_dev->cam; |
| 710 | sd->sof_read = 0; |
| 711 | /* |
| 712 | * Some of the supported cameras require the memory pointer to be |
| 713 | * set to 0, or else they will not stream. |
| 714 | */ |
| 715 | zero_the_pointer(gspca_dev); |
| 716 | msleep(200); |
| 717 | if (sd->cam_type == CAM_TYPE_CIF) { |
| 718 | PDEBUG(D_ERR, "CIF camera"); |
| 719 | err_code = start_cif_cam(gspca_dev); |
| 720 | } else { |
| 721 | PDEBUG(D_ERR, "VGA camera"); |
| 722 | err_code = start_vga_cam(gspca_dev); |
| 723 | } |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 724 | return err_code; |
| 725 | } |
| 726 | |
| 727 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 728 | { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 729 | struct sd *sd = (struct sd *) gspca_dev; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 730 | int result; |
| 731 | |
| 732 | gspca_dev->usb_buf[0] = 1; |
| 733 | gspca_dev->usb_buf[1] = 0; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 734 | result = mr_write(gspca_dev, 2); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 735 | if (result < 0) |
| 736 | PDEBUG(D_ERR, "Camera Stop failed"); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 737 | |
| 738 | /* Not all the cams need this, but even if not, probably a good idea */ |
| 739 | zero_the_pointer(gspca_dev); |
| 740 | if (sd->do_lcd_stop) { |
| 741 | gspca_dev->usb_buf[0] = 0x19; |
| 742 | gspca_dev->usb_buf[1] = 0x54; |
| 743 | result = mr_write(gspca_dev, 2); |
| 744 | if (result < 0) |
| 745 | PDEBUG(D_ERR, "Camera Stop failed"); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | static void setbrightness(struct gspca_dev *gspca_dev) |
| 750 | { |
| 751 | struct sd *sd = (struct sd *) gspca_dev; |
| 752 | u8 val; |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 753 | |
| 754 | if (gspca_dev->ctrl_dis & (1 << BRIGHTNESS_IDX)) |
| 755 | return; |
| 756 | |
| 757 | /* Note register 7 is also seen as 0x8x or 0xCx in dumps */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 758 | if (sd->brightness > 0) { |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 759 | sensor_write1(gspca_dev, 7, 0x00); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 760 | val = sd->brightness; |
| 761 | } else { |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 762 | sensor_write1(gspca_dev, 7, 0x01); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 763 | val = 257 - sd->brightness; |
| 764 | } |
| 765 | sensor_write1(gspca_dev, 8, val); |
| 766 | } |
| 767 | |
| 768 | static void setexposure(struct gspca_dev *gspca_dev) |
| 769 | { |
| 770 | struct sd *sd = (struct sd *) gspca_dev; |
| 771 | u8 val; |
| 772 | |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 773 | if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX)) |
| 774 | return; |
| 775 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 776 | val = sd->exposure >> 4; |
| 777 | sensor_write1(gspca_dev, 3, val); |
| 778 | val = sd->exposure & 0xf; |
| 779 | sensor_write1(gspca_dev, 4, val); |
| 780 | } |
| 781 | |
| 782 | static void setgain(struct gspca_dev *gspca_dev) |
| 783 | { |
| 784 | struct sd *sd = (struct sd *) gspca_dev; |
| 785 | |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 786 | if (gspca_dev->ctrl_dis & (1 << GAIN_IDX)) |
| 787 | return; |
| 788 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 789 | sensor_write1(gspca_dev, 3, sd->gain); |
| 790 | } |
| 791 | |
| 792 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 793 | { |
| 794 | struct sd *sd = (struct sd *) gspca_dev; |
| 795 | |
| 796 | sd->brightness = val; |
| 797 | if (gspca_dev->streaming) |
| 798 | setbrightness(gspca_dev); |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 803 | { |
| 804 | struct sd *sd = (struct sd *) gspca_dev; |
| 805 | |
| 806 | *val = sd->brightness; |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) |
| 811 | { |
| 812 | struct sd *sd = (struct sd *) gspca_dev; |
| 813 | |
| 814 | sd->exposure = val; |
| 815 | if (gspca_dev->streaming) |
| 816 | setexposure(gspca_dev); |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) |
| 821 | { |
| 822 | struct sd *sd = (struct sd *) gspca_dev; |
| 823 | |
| 824 | *val = sd->exposure; |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) |
| 829 | { |
| 830 | struct sd *sd = (struct sd *) gspca_dev; |
| 831 | |
| 832 | sd->gain = val; |
| 833 | if (gspca_dev->streaming) |
| 834 | setgain(gspca_dev); |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) |
| 839 | { |
| 840 | struct sd *sd = (struct sd *) gspca_dev; |
| 841 | |
| 842 | *val = sd->gain; |
| 843 | return 0; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | /* Include pac common sof detection functions */ |
| 847 | #include "pac_common.h" |
| 848 | |
| 849 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 850 | struct gspca_frame *frame, /* target */ |
| 851 | __u8 *data, /* isoc packet */ |
| 852 | int len) /* iso packet length */ |
| 853 | { |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 854 | unsigned char *sof; |
| 855 | |
| 856 | sof = pac_find_sof(gspca_dev, data, len); |
| 857 | if (sof) { |
| 858 | int n; |
| 859 | |
| 860 | /* finish decoding current frame */ |
| 861 | n = sof - data; |
| 862 | if (n > sizeof pac_sof_marker) |
| 863 | n -= sizeof pac_sof_marker; |
| 864 | else |
| 865 | n = 0; |
| 866 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, |
| 867 | data, n); |
Theodore Kilgore | 9832d76 | 2009-03-13 13:04:31 -0300 | [diff] [blame] | 868 | /* Start next frame. */ |
| 869 | gspca_frame_add(gspca_dev, FIRST_PACKET, frame, |
| 870 | pac_sof_marker, sizeof pac_sof_marker); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 871 | len -= sof - data; |
| 872 | data = sof; |
| 873 | } |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 874 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); |
| 875 | } |
| 876 | |
| 877 | /* sub-driver description */ |
| 878 | static const struct sd_desc sd_desc = { |
| 879 | .name = MODULE_NAME, |
| 880 | .ctrls = sd_ctrls, |
| 881 | .nctrls = ARRAY_SIZE(sd_ctrls), |
| 882 | .config = sd_config, |
| 883 | .init = sd_init, |
| 884 | .start = sd_start, |
| 885 | .stopN = sd_stopN, |
| 886 | .pkt_scan = sd_pkt_scan, |
| 887 | }; |
| 888 | |
| 889 | /* -- module initialisation -- */ |
| 890 | static const __devinitdata struct usb_device_id device_table[] = { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 891 | {USB_DEVICE(0x08ca, 0x0111)}, /* Aiptek Pencam VGA+ */ |
| 892 | {USB_DEVICE(0x093a, 0x010f)}, /* All other known MR97310A VGA cams */ |
| 893 | {USB_DEVICE(0x093a, 0x010e)}, /* All known MR97310A CIF cams */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 894 | {} |
| 895 | }; |
| 896 | MODULE_DEVICE_TABLE(usb, device_table); |
| 897 | |
| 898 | /* -- device connect -- */ |
| 899 | static int sd_probe(struct usb_interface *intf, |
| 900 | const struct usb_device_id *id) |
| 901 | { |
| 902 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 903 | THIS_MODULE); |
| 904 | } |
| 905 | |
| 906 | static struct usb_driver sd_driver = { |
| 907 | .name = MODULE_NAME, |
| 908 | .id_table = device_table, |
| 909 | .probe = sd_probe, |
| 910 | .disconnect = gspca_disconnect, |
| 911 | #ifdef CONFIG_PM |
| 912 | .suspend = gspca_suspend, |
| 913 | .resume = gspca_resume, |
| 914 | #endif |
| 915 | }; |
| 916 | |
| 917 | /* -- module insert / remove -- */ |
| 918 | static int __init sd_mod_init(void) |
| 919 | { |
Alexey Klimov | 5d3fa30 | 2009-03-27 15:57:46 -0300 | [diff] [blame] | 920 | int ret; |
| 921 | |
| 922 | ret = usb_register(&sd_driver); |
| 923 | if (ret < 0) |
| 924 | return ret; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 925 | PDEBUG(D_PROBE, "registered"); |
| 926 | return 0; |
| 927 | } |
| 928 | static void __exit sd_mod_exit(void) |
| 929 | { |
| 930 | usb_deregister(&sd_driver); |
| 931 | PDEBUG(D_PROBE, "deregistered"); |
| 932 | } |
| 933 | |
| 934 | module_init(sd_mod_init); |
| 935 | module_exit(sd_mod_exit); |