Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Mars MR97310A library |
| 3 | * |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 4 | * The original mr97310a driver, which supported the Aiptek Pencam VGA+, is |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 5 | * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com> |
| 6 | * |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 7 | * Support for the MR97310A cameras in addition to the Aiptek Pencam VGA+ |
| 8 | * and for the routines for detecting and classifying these various cameras, |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 9 | * is Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu> |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 10 | * |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 11 | * Support for the control settings for the CIF cameras is |
Hans de Goede | 1fddcf0 | 2010-09-05 07:06:04 -0300 | [diff] [blame] | 12 | * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com> and |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 13 | * Thomas Kaiser <thomas@kaiser-linux.li> |
| 14 | * |
| 15 | * Support for the control settings for the VGA cameras is |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 16 | * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu> |
| 17 | * |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 18 | * Several previously unsupported cameras are owned and have been tested by |
Hans de Goede | 1fddcf0 | 2010-09-05 07:06:04 -0300 | [diff] [blame] | 19 | * Hans de Goede <hdegoede@redhat.com> and |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 20 | * Thomas Kaiser <thomas@kaiser-linux.li> and |
Theodore Kilgore | 1160a38 | 2009-10-30 04:29:56 -0300 | [diff] [blame] | 21 | * Theodore Kilgore <kilgota@auburn.edu> and |
| 22 | * Edmond Rodriguez <erodrig_97@yahoo.com> and |
| 23 | * Aurelien Jacobs <aurel@gnuage.org> |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 24 | * |
| 25 | * The MR97311A support in gspca/mars.c has been helpful in understanding some |
| 26 | * of the registers in these cameras. |
| 27 | * |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 28 | * This program is free software; you can redistribute it and/or modify |
| 29 | * it under the terms of the GNU General Public License as published by |
| 30 | * the Free Software Foundation; either version 2 of the License, or |
| 31 | * any later version. |
| 32 | * |
| 33 | * This program is distributed in the hope that it will be useful, |
| 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 36 | * GNU General Public License for more details. |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 37 | */ |
| 38 | |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 39 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 40 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 41 | #define MODULE_NAME "mr97310a" |
| 42 | |
| 43 | #include "gspca.h" |
| 44 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 45 | #define CAM_TYPE_CIF 0 |
| 46 | #define CAM_TYPE_VGA 1 |
| 47 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 48 | #define MR97310A_BRIGHTNESS_DEFAULT 0 |
| 49 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 50 | #define MR97310A_EXPOSURE_MIN 0 |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 51 | #define MR97310A_EXPOSURE_MAX 4095 |
| 52 | #define MR97310A_EXPOSURE_DEFAULT 1000 |
| 53 | |
| 54 | #define MR97310A_GAIN_MIN 0 |
| 55 | #define MR97310A_GAIN_MAX 31 |
| 56 | #define MR97310A_GAIN_DEFAULT 25 |
| 57 | |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 58 | #define MR97310A_CONTRAST_MIN 0 |
| 59 | #define MR97310A_CONTRAST_MAX 31 |
| 60 | #define MR97310A_CONTRAST_DEFAULT 23 |
| 61 | |
| 62 | #define MR97310A_CS_GAIN_MIN 0 |
| 63 | #define MR97310A_CS_GAIN_MAX 0x7ff |
| 64 | #define MR97310A_CS_GAIN_DEFAULT 0x110 |
| 65 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 66 | #define MR97310A_CID_CLOCKDIV (V4L2_CTRL_CLASS_USER + 0x1000) |
Hans de Goede | 065b6f7 | 2009-10-29 07:42:30 -0300 | [diff] [blame] | 67 | #define MR97310A_MIN_CLOCKDIV_MIN 3 |
| 68 | #define MR97310A_MIN_CLOCKDIV_MAX 8 |
| 69 | #define MR97310A_MIN_CLOCKDIV_DEFAULT 3 |
| 70 | |
Mauro Carvalho Chehab | 1ddc9f7 | 2016-10-18 17:44:16 -0200 | [diff] [blame] | 71 | MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>,Theodore Kilgore <kilgota@auburn.edu>"); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 72 | MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver"); |
| 73 | MODULE_LICENSE("GPL"); |
| 74 | |
Hans de Goede | 7802870 | 2009-09-02 09:55:16 -0300 | [diff] [blame] | 75 | /* global parameters */ |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 76 | static int force_sensor_type = -1; |
Hans de Goede | 7802870 | 2009-09-02 09:55:16 -0300 | [diff] [blame] | 77 | module_param(force_sensor_type, int, 0644); |
| 78 | MODULE_PARM_DESC(force_sensor_type, "Force sensor type (-1 (auto), 0 or 1)"); |
| 79 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 80 | /* specific webcam descriptor */ |
| 81 | struct sd { |
| 82 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 83 | struct { /* exposure/min_clockdiv control cluster */ |
| 84 | struct v4l2_ctrl *exposure; |
| 85 | struct v4l2_ctrl *min_clockdiv; |
| 86 | }; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 87 | u8 sof_read; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 88 | u8 cam_type; /* 0 is CIF and 1 is VGA */ |
| 89 | u8 sensor_type; /* We use 0 and 1 here, too. */ |
| 90 | u8 do_lcd_stop; |
Theodore Kilgore | 64f4d9a | 2009-10-30 04:43:39 -0300 | [diff] [blame] | 91 | u8 adj_colors; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 92 | }; |
| 93 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 94 | struct sensor_w_data { |
| 95 | u8 reg; |
| 96 | u8 flags; |
| 97 | u8 data[16]; |
| 98 | int len; |
| 99 | }; |
| 100 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 101 | static void sd_stopN(struct gspca_dev *gspca_dev); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 102 | |
| 103 | static const struct v4l2_pix_format vga_mode[] = { |
| 104 | {160, 120, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 105 | .bytesperline = 160, |
| 106 | .sizeimage = 160 * 120, |
| 107 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 108 | .priv = 4}, |
| 109 | {176, 144, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 110 | .bytesperline = 176, |
| 111 | .sizeimage = 176 * 144, |
| 112 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 113 | .priv = 3}, |
| 114 | {320, 240, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 115 | .bytesperline = 320, |
| 116 | .sizeimage = 320 * 240, |
| 117 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 118 | .priv = 2}, |
| 119 | {352, 288, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 120 | .bytesperline = 352, |
| 121 | .sizeimage = 352 * 288, |
| 122 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 123 | .priv = 1}, |
| 124 | {640, 480, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE, |
| 125 | .bytesperline = 640, |
| 126 | .sizeimage = 640 * 480, |
| 127 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 128 | .priv = 0}, |
| 129 | }; |
| 130 | |
| 131 | /* the bytes to write are in gspca_dev->usb_buf */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 132 | static int mr_write(struct gspca_dev *gspca_dev, int len) |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 133 | { |
| 134 | int rc; |
| 135 | |
| 136 | rc = usb_bulk_msg(gspca_dev->dev, |
| 137 | usb_sndbulkpipe(gspca_dev->dev, 4), |
Jean-Francois Moine | 92e8c91 | 2009-02-02 16:25:38 -0300 | [diff] [blame] | 138 | gspca_dev->usb_buf, len, NULL, 500); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 139 | if (rc < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 140 | pr_err("reg write [%02x] error %d\n", |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 141 | gspca_dev->usb_buf[0], rc); |
| 142 | return rc; |
| 143 | } |
| 144 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 145 | /* the bytes are read into gspca_dev->usb_buf */ |
| 146 | static int mr_read(struct gspca_dev *gspca_dev, int len) |
| 147 | { |
| 148 | int rc; |
| 149 | |
| 150 | rc = usb_bulk_msg(gspca_dev->dev, |
| 151 | usb_rcvbulkpipe(gspca_dev->dev, 3), |
| 152 | gspca_dev->usb_buf, len, NULL, 500); |
| 153 | if (rc < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 154 | pr_err("reg read [%02x] error %d\n", |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 155 | gspca_dev->usb_buf[0], rc); |
| 156 | return rc; |
| 157 | } |
| 158 | |
| 159 | static int sensor_write_reg(struct gspca_dev *gspca_dev, u8 reg, u8 flags, |
| 160 | const u8 *data, int len) |
| 161 | { |
| 162 | gspca_dev->usb_buf[0] = 0x1f; |
| 163 | gspca_dev->usb_buf[1] = flags; |
| 164 | gspca_dev->usb_buf[2] = reg; |
| 165 | memcpy(gspca_dev->usb_buf + 3, data, len); |
| 166 | |
| 167 | return mr_write(gspca_dev, len + 3); |
| 168 | } |
| 169 | |
| 170 | static int sensor_write_regs(struct gspca_dev *gspca_dev, |
| 171 | const struct sensor_w_data *data, int len) |
| 172 | { |
| 173 | int i, rc; |
| 174 | |
| 175 | for (i = 0; i < len; i++) { |
| 176 | rc = sensor_write_reg(gspca_dev, data[i].reg, data[i].flags, |
| 177 | data[i].data, data[i].len); |
| 178 | if (rc < 0) |
| 179 | return rc; |
| 180 | } |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static int sensor_write1(struct gspca_dev *gspca_dev, u8 reg, u8 data) |
| 186 | { |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 187 | struct sd *sd = (struct sd *) gspca_dev; |
| 188 | u8 buf, confirm_reg; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 189 | int rc; |
| 190 | |
| 191 | buf = data; |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 192 | if (sd->cam_type == CAM_TYPE_CIF) { |
| 193 | rc = sensor_write_reg(gspca_dev, reg, 0x01, &buf, 1); |
| 194 | confirm_reg = sd->sensor_type ? 0x13 : 0x11; |
| 195 | } else { |
| 196 | rc = sensor_write_reg(gspca_dev, reg, 0x00, &buf, 1); |
| 197 | confirm_reg = 0x11; |
| 198 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 199 | if (rc < 0) |
| 200 | return rc; |
| 201 | |
| 202 | buf = 0x01; |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 203 | rc = sensor_write_reg(gspca_dev, confirm_reg, 0x00, &buf, 1); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 204 | if (rc < 0) |
| 205 | return rc; |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 210 | static int cam_get_response16(struct gspca_dev *gspca_dev, u8 reg, int verbose) |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 211 | { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 212 | int err_code; |
| 213 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 214 | gspca_dev->usb_buf[0] = reg; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 215 | err_code = mr_write(gspca_dev, 1); |
| 216 | if (err_code < 0) |
| 217 | return err_code; |
| 218 | |
| 219 | err_code = mr_read(gspca_dev, 16); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 220 | if (err_code < 0) |
| 221 | return err_code; |
| 222 | |
| 223 | if (verbose) |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 224 | gspca_dbg(gspca_dev, D_PROBE, "Register: %02x reads %02x%02x%02x\n", |
| 225 | reg, |
| 226 | gspca_dev->usb_buf[0], |
| 227 | gspca_dev->usb_buf[1], |
| 228 | gspca_dev->usb_buf[2]); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 229 | |
| 230 | return 0; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static int zero_the_pointer(struct gspca_dev *gspca_dev) |
| 234 | { |
| 235 | __u8 *data = gspca_dev->usb_buf; |
| 236 | int err_code; |
| 237 | u8 status = 0; |
| 238 | int tries = 0; |
| 239 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 240 | err_code = cam_get_response16(gspca_dev, 0x21, 0); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 241 | if (err_code < 0) |
| 242 | return err_code; |
| 243 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 244 | data[0] = 0x19; |
| 245 | data[1] = 0x51; |
| 246 | err_code = mr_write(gspca_dev, 2); |
| 247 | if (err_code < 0) |
| 248 | return err_code; |
| 249 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 250 | err_code = cam_get_response16(gspca_dev, 0x21, 0); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 251 | if (err_code < 0) |
| 252 | return err_code; |
| 253 | |
| 254 | data[0] = 0x19; |
| 255 | data[1] = 0xba; |
| 256 | err_code = mr_write(gspca_dev, 2); |
| 257 | if (err_code < 0) |
| 258 | return err_code; |
| 259 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 260 | err_code = cam_get_response16(gspca_dev, 0x21, 0); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 261 | if (err_code < 0) |
| 262 | return err_code; |
| 263 | |
| 264 | data[0] = 0x19; |
| 265 | data[1] = 0x00; |
| 266 | err_code = mr_write(gspca_dev, 2); |
| 267 | if (err_code < 0) |
| 268 | return err_code; |
| 269 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 270 | err_code = cam_get_response16(gspca_dev, 0x21, 0); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 271 | if (err_code < 0) |
| 272 | return err_code; |
| 273 | |
| 274 | data[0] = 0x19; |
| 275 | data[1] = 0x00; |
| 276 | err_code = mr_write(gspca_dev, 2); |
| 277 | if (err_code < 0) |
| 278 | return err_code; |
| 279 | |
| 280 | while (status != 0x0a && tries < 256) { |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 281 | err_code = cam_get_response16(gspca_dev, 0x21, 0); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 282 | status = data[0]; |
| 283 | tries++; |
| 284 | if (err_code < 0) |
| 285 | return err_code; |
| 286 | } |
Hans de Goede | 5494378 | 2009-08-14 11:05:38 -0300 | [diff] [blame] | 287 | if (status != 0x0a) |
Joe Perches | 52173c5f | 2017-09-22 14:33:35 -0400 | [diff] [blame] | 288 | gspca_err(gspca_dev, "status is %02x\n", status); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 289 | |
| 290 | tries = 0; |
| 291 | while (tries < 4) { |
| 292 | data[0] = 0x19; |
| 293 | data[1] = 0x00; |
| 294 | err_code = mr_write(gspca_dev, 2); |
| 295 | if (err_code < 0) |
| 296 | return err_code; |
| 297 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 298 | err_code = cam_get_response16(gspca_dev, 0x21, 0); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 299 | status = data[0]; |
| 300 | tries++; |
| 301 | if (err_code < 0) |
| 302 | return err_code; |
| 303 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 304 | |
| 305 | data[0] = 0x19; |
| 306 | err_code = mr_write(gspca_dev, 1); |
| 307 | if (err_code < 0) |
| 308 | return err_code; |
| 309 | |
| 310 | err_code = mr_read(gspca_dev, 16); |
| 311 | if (err_code < 0) |
| 312 | return err_code; |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 317 | static int stream_start(struct gspca_dev *gspca_dev) |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 318 | { |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 319 | gspca_dev->usb_buf[0] = 0x01; |
| 320 | gspca_dev->usb_buf[1] = 0x01; |
| 321 | return mr_write(gspca_dev, 2); |
| 322 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 323 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 324 | static void stream_stop(struct gspca_dev *gspca_dev) |
| 325 | { |
| 326 | gspca_dev->usb_buf[0] = 0x01; |
| 327 | gspca_dev->usb_buf[1] = 0x00; |
| 328 | if (mr_write(gspca_dev, 2) < 0) |
Joe Perches | 52173c5f | 2017-09-22 14:33:35 -0400 | [diff] [blame] | 329 | gspca_err(gspca_dev, "Stream Stop failed\n"); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 330 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 331 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 332 | static void lcd_stop(struct gspca_dev *gspca_dev) |
| 333 | { |
| 334 | gspca_dev->usb_buf[0] = 0x19; |
| 335 | gspca_dev->usb_buf[1] = 0x54; |
| 336 | if (mr_write(gspca_dev, 2) < 0) |
Joe Perches | 52173c5f | 2017-09-22 14:33:35 -0400 | [diff] [blame] | 337 | gspca_err(gspca_dev, "LCD Stop failed\n"); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 338 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 339 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 340 | static int isoc_enable(struct gspca_dev *gspca_dev) |
| 341 | { |
| 342 | gspca_dev->usb_buf[0] = 0x00; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 343 | gspca_dev->usb_buf[1] = 0x4d; /* ISOC transferring enable... */ |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 344 | return mr_write(gspca_dev, 2); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 345 | } |
| 346 | |
Theodore Kilgore | 1160a38 | 2009-10-30 04:29:56 -0300 | [diff] [blame] | 347 | /* This function is called at probe time */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 348 | static int sd_config(struct gspca_dev *gspca_dev, |
| 349 | const struct usb_device_id *id) |
| 350 | { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 351 | struct sd *sd = (struct sd *) gspca_dev; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 352 | struct cam *cam; |
Hans de Goede | 5f5e26b | 2009-08-14 10:40:26 -0300 | [diff] [blame] | 353 | int err_code; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 354 | |
| 355 | cam = &gspca_dev->cam; |
| 356 | cam->cam_mode = vga_mode; |
| 357 | cam->nmodes = ARRAY_SIZE(vga_mode); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 358 | sd->do_lcd_stop = 0; |
| 359 | |
Theodore Kilgore | 1160a38 | 2009-10-30 04:29:56 -0300 | [diff] [blame] | 360 | /* Several of the supported CIF cameras share the same USB ID but |
| 361 | * require different initializations and different control settings. |
| 362 | * The same is true of the VGA cameras. Therefore, we are forced |
| 363 | * to start the initialization process in order to determine which |
| 364 | * camera is present. Some of the supported cameras require the |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 365 | * memory pointer to be set to 0 as the very first item of business |
| 366 | * or else they will not stream. So we do that immediately. |
| 367 | */ |
| 368 | err_code = zero_the_pointer(gspca_dev); |
| 369 | if (err_code < 0) |
| 370 | return err_code; |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 371 | |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 372 | err_code = stream_start(gspca_dev); |
| 373 | if (err_code < 0) |
| 374 | return err_code; |
| 375 | |
Theodore Kilgore | c260fe9 | 2010-01-15 05:54:36 -0300 | [diff] [blame] | 376 | /* Now, the query for sensor type. */ |
| 377 | err_code = cam_get_response16(gspca_dev, 0x07, 1); |
| 378 | if (err_code < 0) |
| 379 | return err_code; |
| 380 | |
Aurelien Jacobs | 8ac246c | 2009-10-29 07:45:24 -0300 | [diff] [blame] | 381 | if (id->idProduct == 0x0110 || id->idProduct == 0x010e) { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 382 | sd->cam_type = CAM_TYPE_CIF; |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 383 | cam->nmodes--; |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 384 | /* |
Theodore Kilgore | 1160a38 | 2009-10-30 04:29:56 -0300 | [diff] [blame] | 385 | * All but one of the known CIF cameras share the same USB ID, |
| 386 | * but two different init routines are in use, and the control |
| 387 | * settings are different, too. We need to detect which camera |
| 388 | * of the two known varieties is connected! |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 389 | * |
| 390 | * A list of known CIF cameras follows. They all report either |
Theodore Kilgore | c260fe9 | 2010-01-15 05:54:36 -0300 | [diff] [blame] | 391 | * 0200 for type 0 or 0300 for type 1. |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 392 | * If you have another to report, please do |
| 393 | * |
| 394 | * Name sd->sensor_type reported by |
| 395 | * |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 396 | * Sakar 56379 Spy-shot 0 T. Kilgore |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 397 | * Innovage 0 T. Kilgore |
| 398 | * Vivitar Mini 0 H. De Goede |
| 399 | * Vivitar Mini 0 E. Rodriguez |
| 400 | * Vivitar Mini 1 T. Kilgore |
| 401 | * Elta-Media 8212dc 1 T. Kaiser |
| 402 | * Philips dig. keych. 1 T. Kilgore |
Theodore Kilgore | 1160a38 | 2009-10-30 04:29:56 -0300 | [diff] [blame] | 403 | * Trust Spyc@m 100 1 A. Jacobs |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 404 | */ |
Theodore Kilgore | c260fe9 | 2010-01-15 05:54:36 -0300 | [diff] [blame] | 405 | switch (gspca_dev->usb_buf[0]) { |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 406 | case 2: |
| 407 | sd->sensor_type = 0; |
| 408 | break; |
| 409 | case 3: |
| 410 | sd->sensor_type = 1; |
| 411 | break; |
| 412 | default: |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 413 | pr_err("Unknown CIF Sensor id : %02x\n", |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 414 | gspca_dev->usb_buf[1]); |
| 415 | return -ENODEV; |
| 416 | } |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 417 | gspca_dbg(gspca_dev, D_PROBE, "MR97310A CIF camera detected, sensor: %d\n", |
| 418 | sd->sensor_type); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 419 | } else { |
| 420 | sd->cam_type = CAM_TYPE_VGA; |
Hans de Goede | 5f5e26b | 2009-08-14 10:40:26 -0300 | [diff] [blame] | 421 | |
Hans de Goede | 5f5e26b | 2009-08-14 10:40:26 -0300 | [diff] [blame] | 422 | /* |
Theodore Kilgore | c260fe9 | 2010-01-15 05:54:36 -0300 | [diff] [blame] | 423 | * Here is a table of the responses to the query for sensor |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 424 | * type, from the known MR97310A VGA cameras. Six different |
| 425 | * cameras of which five share the same USB ID. |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 426 | * |
| 427 | * Name gspca_dev->usb_buf[] sd->sensor_type |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 428 | * sd->do_lcd_stop |
| 429 | * Aiptek Pencam VGA+ 0300 0 1 |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 430 | * ION digital 0300 0 1 |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 431 | * Argus DC-1620 0450 1 0 |
| 432 | * Argus QuickClix 0420 1 1 |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 433 | * Sakar 77379 Digital 0350 0 1 |
| 434 | * Sakar 1638x CyberPix 0120 0 2 |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 435 | * |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 436 | * Based upon these results, we assume default settings |
| 437 | * and then correct as necessary, as follows. |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 438 | * |
Hans de Goede | 5f5e26b | 2009-08-14 10:40:26 -0300 | [diff] [blame] | 439 | */ |
Hans de Goede | 5f5e26b | 2009-08-14 10:40:26 -0300 | [diff] [blame] | 440 | |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 441 | sd->sensor_type = 1; |
| 442 | sd->do_lcd_stop = 0; |
Theodore Kilgore | 64f4d9a | 2009-10-30 04:43:39 -0300 | [diff] [blame] | 443 | sd->adj_colors = 0; |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 444 | if (gspca_dev->usb_buf[0] == 0x01) { |
| 445 | sd->sensor_type = 2; |
| 446 | } else if ((gspca_dev->usb_buf[0] != 0x03) && |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 447 | (gspca_dev->usb_buf[0] != 0x04)) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 448 | pr_err("Unknown VGA Sensor id Byte 0: %02x\n", |
| 449 | gspca_dev->usb_buf[0]); |
| 450 | pr_err("Defaults assumed, may not work\n"); |
| 451 | pr_err("Please report this\n"); |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 452 | } |
Theodore Kilgore | 64f4d9a | 2009-10-30 04:43:39 -0300 | [diff] [blame] | 453 | /* Sakar Digital color needs to be adjusted. */ |
| 454 | if ((gspca_dev->usb_buf[0] == 0x03) && |
| 455 | (gspca_dev->usb_buf[1] == 0x50)) |
| 456 | sd->adj_colors = 1; |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 457 | if (gspca_dev->usb_buf[0] == 0x04) { |
| 458 | sd->do_lcd_stop = 1; |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 459 | switch (gspca_dev->usb_buf[1]) { |
| 460 | case 0x50: |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 461 | sd->sensor_type = 0; |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 462 | gspca_dbg(gspca_dev, D_PROBE, "sensor_type corrected to 0\n"); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 463 | break; |
| 464 | case 0x20: |
Theodore Kilgore | b3e440e | 2009-10-09 03:54:49 -0300 | [diff] [blame] | 465 | /* Nothing to do here. */ |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 466 | break; |
| 467 | default: |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 468 | pr_err("Unknown VGA Sensor id Byte 1: %02x\n", |
| 469 | gspca_dev->usb_buf[1]); |
| 470 | pr_err("Defaults assumed, may not work\n"); |
| 471 | pr_err("Please report this\n"); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 472 | } |
Hans de Goede | 7802870 | 2009-09-02 09:55:16 -0300 | [diff] [blame] | 473 | } |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 474 | gspca_dbg(gspca_dev, D_PROBE, "MR97310A VGA camera detected, sensor: %d\n", |
| 475 | sd->sensor_type); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 476 | } |
Theodore Kilgore | c260fe9 | 2010-01-15 05:54:36 -0300 | [diff] [blame] | 477 | /* Stop streaming as we've started it only to probe the sensor type. */ |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 478 | sd_stopN(gspca_dev); |
Hans de Goede | 7802870 | 2009-09-02 09:55:16 -0300 | [diff] [blame] | 479 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 480 | if (force_sensor_type != -1) { |
| 481 | sd->sensor_type = !!force_sensor_type; |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 482 | gspca_dbg(gspca_dev, D_PROBE, "Forcing sensor type to: %d\n", |
| 483 | sd->sensor_type); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 484 | } |
| 485 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | /* this function is called at probe and resume time */ |
| 490 | static int sd_init(struct gspca_dev *gspca_dev) |
| 491 | { |
| 492 | return 0; |
| 493 | } |
| 494 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 495 | static int start_cif_cam(struct gspca_dev *gspca_dev) |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 496 | { |
| 497 | struct sd *sd = (struct sd *) gspca_dev; |
| 498 | __u8 *data = gspca_dev->usb_buf; |
| 499 | int err_code; |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 500 | static const __u8 startup_string[] = { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 501 | 0x00, |
| 502 | 0x0d, |
| 503 | 0x01, |
| 504 | 0x00, /* Hsize/8 for 352 or 320 */ |
| 505 | 0x00, /* Vsize/4 for 288 or 240 */ |
| 506 | 0x13, /* or 0xbb, depends on sensor */ |
| 507 | 0x00, /* Hstart, depends on res. */ |
| 508 | 0x00, /* reserved ? */ |
| 509 | 0x00, /* Vstart, depends on res. and sensor */ |
| 510 | 0x50, /* 0x54 to get 176 or 160 */ |
| 511 | 0xc0 |
| 512 | }; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 513 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 514 | /* Note: Some of the above descriptions guessed from MR97113A driver */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 515 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 516 | memcpy(data, startup_string, 11); |
| 517 | if (sd->sensor_type) |
| 518 | data[5] = 0xbb; |
| 519 | |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 520 | switch (gspca_dev->pixfmt.width) { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 521 | case 160: |
| 522 | data[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */ |
Mauro Carvalho Chehab | 3e4d8f4 | 2019-02-18 14:29:03 -0500 | [diff] [blame] | 523 | /* fall through */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 524 | case 320: |
| 525 | default: |
| 526 | data[3] = 0x28; /* reg 2, H size/8 */ |
| 527 | data[4] = 0x3c; /* reg 3, V size/4 */ |
| 528 | data[6] = 0x14; /* reg 5, H start */ |
| 529 | data[8] = 0x1a + sd->sensor_type; /* reg 7, V start */ |
| 530 | break; |
| 531 | case 176: |
| 532 | data[9] |= 0x04; /* reg 8, 2:1 scale down from 352 */ |
Mauro Carvalho Chehab | 3e4d8f4 | 2019-02-18 14:29:03 -0500 | [diff] [blame] | 533 | /* fall through */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 534 | case 352: |
| 535 | data[3] = 0x2c; /* reg 2, H size/8 */ |
| 536 | data[4] = 0x48; /* reg 3, V size/4 */ |
| 537 | data[6] = 0x06; /* reg 5, H start */ |
Theodore Kilgore | 32345b0 | 2009-11-01 12:59:42 -0300 | [diff] [blame] | 538 | data[8] = 0x06 - sd->sensor_type; /* reg 7, V start */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 539 | break; |
| 540 | } |
| 541 | err_code = mr_write(gspca_dev, 11); |
| 542 | if (err_code < 0) |
| 543 | return err_code; |
| 544 | |
| 545 | if (!sd->sensor_type) { |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 546 | static const struct sensor_w_data cif_sensor0_init_data[] = { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 547 | {0x02, 0x00, {0x03, 0x5a, 0xb5, 0x01, |
| 548 | 0x0f, 0x14, 0x0f, 0x10}, 8}, |
| 549 | {0x0c, 0x00, {0x04, 0x01, 0x01, 0x00, 0x1f}, 5}, |
| 550 | {0x12, 0x00, {0x07}, 1}, |
| 551 | {0x1f, 0x00, {0x06}, 1}, |
| 552 | {0x27, 0x00, {0x04}, 1}, |
| 553 | {0x29, 0x00, {0x0c}, 1}, |
| 554 | {0x40, 0x00, {0x40, 0x00, 0x04}, 3}, |
| 555 | {0x50, 0x00, {0x60}, 1}, |
| 556 | {0x60, 0x00, {0x06}, 1}, |
| 557 | {0x6b, 0x00, {0x85, 0x85, 0xc8, 0xc8, 0xc8, 0xc8}, 6}, |
| 558 | {0x72, 0x00, {0x1e, 0x56}, 2}, |
| 559 | {0x75, 0x00, {0x58, 0x40, 0xa2, 0x02, 0x31, 0x02, |
| 560 | 0x31, 0x80, 0x00}, 9}, |
| 561 | {0x11, 0x00, {0x01}, 1}, |
| 562 | {0, 0, {0}, 0} |
| 563 | }; |
| 564 | err_code = sensor_write_regs(gspca_dev, cif_sensor0_init_data, |
| 565 | ARRAY_SIZE(cif_sensor0_init_data)); |
| 566 | } else { /* sd->sensor_type = 1 */ |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 567 | static const struct sensor_w_data cif_sensor1_init_data[] = { |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 568 | /* Reg 3,4, 7,8 get set by the controls */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 569 | {0x02, 0x00, {0x10}, 1}, |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 570 | {0x05, 0x01, {0x22}, 1}, /* 5/6 also seen as 65h/32h */ |
| 571 | {0x06, 0x01, {0x00}, 1}, |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 572 | {0x09, 0x02, {0x0e}, 1}, |
| 573 | {0x0a, 0x02, {0x05}, 1}, |
| 574 | {0x0b, 0x02, {0x05}, 1}, |
| 575 | {0x0c, 0x02, {0x0f}, 1}, |
Hans de Goede | 9ac6978 | 2009-08-14 10:15:52 -0300 | [diff] [blame] | 576 | {0x0d, 0x02, {0x07}, 1}, |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 577 | {0x0e, 0x02, {0x0c}, 1}, |
| 578 | {0x0f, 0x00, {0x00}, 1}, |
| 579 | {0x10, 0x00, {0x06}, 1}, |
| 580 | {0x11, 0x00, {0x07}, 1}, |
| 581 | {0x12, 0x00, {0x00}, 1}, |
| 582 | {0x13, 0x00, {0x01}, 1}, |
| 583 | {0, 0, {0}, 0} |
| 584 | }; |
Theodore Kilgore | 7013608 | 2009-12-25 05:15:10 -0300 | [diff] [blame] | 585 | /* Without this command the cam won't work with USB-UHCI */ |
| 586 | gspca_dev->usb_buf[0] = 0x0a; |
| 587 | gspca_dev->usb_buf[1] = 0x00; |
| 588 | err_code = mr_write(gspca_dev, 2); |
| 589 | if (err_code < 0) |
| 590 | return err_code; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 591 | err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data, |
| 592 | ARRAY_SIZE(cif_sensor1_init_data)); |
| 593 | } |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 594 | return err_code; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | static int start_vga_cam(struct gspca_dev *gspca_dev) |
| 598 | { |
| 599 | struct sd *sd = (struct sd *) gspca_dev; |
| 600 | __u8 *data = gspca_dev->usb_buf; |
| 601 | int err_code; |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 602 | static const __u8 startup_string[] = |
| 603 | {0x00, 0x0d, 0x01, 0x00, 0x00, 0x2b, 0x00, 0x00, |
| 604 | 0x00, 0x50, 0xc0}; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 605 | /* What some of these mean is explained in start_cif_cam(), above */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 606 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 607 | memcpy(data, startup_string, 11); |
| 608 | if (!sd->sensor_type) { |
| 609 | data[5] = 0x00; |
| 610 | data[10] = 0x91; |
| 611 | } |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 612 | if (sd->sensor_type == 2) { |
| 613 | data[5] = 0x00; |
| 614 | data[10] = 0x18; |
| 615 | } |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 616 | |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 617 | switch (gspca_dev->pixfmt.width) { |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 618 | case 160: |
| 619 | data[9] |= 0x0c; /* reg 8, 4:1 scale down */ |
Mauro Carvalho Chehab | 3e4d8f4 | 2019-02-18 14:29:03 -0500 | [diff] [blame] | 620 | /* fall through */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 621 | case 320: |
| 622 | data[9] |= 0x04; /* reg 8, 2:1 scale down */ |
Mauro Carvalho Chehab | 3e4d8f4 | 2019-02-18 14:29:03 -0500 | [diff] [blame] | 623 | /* fall through */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 624 | case 640: |
| 625 | default: |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 626 | data[3] = 0x50; /* reg 2, H size/8 */ |
| 627 | data[4] = 0x78; /* reg 3, V size/4 */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 628 | data[6] = 0x04; /* reg 5, H start */ |
| 629 | data[8] = 0x03; /* reg 7, V start */ |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 630 | if (sd->sensor_type == 2) { |
| 631 | data[6] = 2; |
| 632 | data[8] = 1; |
| 633 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 634 | if (sd->do_lcd_stop) |
| 635 | data[8] = 0x04; /* Bayer tile shifted */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case 176: |
| 639 | data[9] |= 0x04; /* reg 8, 2:1 scale down */ |
Mauro Carvalho Chehab | 3e4d8f4 | 2019-02-18 14:29:03 -0500 | [diff] [blame] | 640 | /* fall through */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 641 | case 352: |
| 642 | data[3] = 0x2c; /* reg 2, H size */ |
| 643 | data[4] = 0x48; /* reg 3, V size */ |
| 644 | data[6] = 0x94; /* reg 5, H start */ |
| 645 | data[8] = 0x63; /* reg 7, V start */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 646 | if (sd->do_lcd_stop) |
| 647 | data[8] = 0x64; /* Bayer tile shifted */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 648 | break; |
| 649 | } |
| 650 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 651 | err_code = mr_write(gspca_dev, 11); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 652 | if (err_code < 0) |
| 653 | return err_code; |
| 654 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 655 | if (!sd->sensor_type) { |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 656 | static const struct sensor_w_data vga_sensor0_init_data[] = { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 657 | {0x01, 0x00, {0x0c, 0x00, 0x04}, 3}, |
| 658 | {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4}, |
| 659 | {0x20, 0x00, {0x00, 0x80, 0x00, 0x08}, 4}, |
| 660 | {0x25, 0x00, {0x03, 0xa9, 0x80}, 3}, |
| 661 | {0x30, 0x00, {0x30, 0x18, 0x10, 0x18}, 4}, |
| 662 | {0, 0, {0}, 0} |
| 663 | }; |
| 664 | err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data, |
| 665 | ARRAY_SIZE(vga_sensor0_init_data)); |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 666 | } else if (sd->sensor_type == 1) { |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 667 | static const struct sensor_w_data color_adj[] = { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 668 | {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00, |
Theodore Kilgore | 64f4d9a | 2009-10-30 04:43:39 -0300 | [diff] [blame] | 669 | /* adjusted blue, green, red gain correct |
| 670 | too much blue from the Sakar Digital */ |
Theodore Kilgore | b31210d | 2009-11-01 13:02:59 -0300 | [diff] [blame] | 671 | 0x05, 0x01, 0x04}, 8} |
Theodore Kilgore | 64f4d9a | 2009-10-30 04:43:39 -0300 | [diff] [blame] | 672 | }; |
| 673 | |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 674 | static const struct sensor_w_data color_no_adj[] = { |
Theodore Kilgore | 64f4d9a | 2009-10-30 04:43:39 -0300 | [diff] [blame] | 675 | {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00, |
| 676 | /* default blue, green, red gain settings */ |
| 677 | 0x07, 0x00, 0x01}, 8} |
| 678 | }; |
| 679 | |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 680 | static const struct sensor_w_data vga_sensor1_init_data[] = { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 681 | {0x11, 0x04, {0x01}, 1}, |
Theodore Kilgore | 542821d | 2009-11-01 13:09:15 -0300 | [diff] [blame] | 682 | {0x0a, 0x00, {0x00, 0x01, 0x00, 0x00, 0x01, |
| 683 | /* These settings may be better for some cameras */ |
| 684 | /* {0x0a, 0x00, {0x01, 0x06, 0x00, 0x00, 0x01, */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 685 | 0x00, 0x0a}, 7}, |
| 686 | {0x11, 0x04, {0x01}, 1}, |
| 687 | {0x12, 0x00, {0x00, 0x63, 0x00, 0x70, 0x00, 0x00}, 6}, |
| 688 | {0x11, 0x04, {0x01}, 1}, |
| 689 | {0, 0, {0}, 0} |
| 690 | }; |
Theodore Kilgore | 64f4d9a | 2009-10-30 04:43:39 -0300 | [diff] [blame] | 691 | |
| 692 | if (sd->adj_colors) |
| 693 | err_code = sensor_write_regs(gspca_dev, color_adj, |
| 694 | ARRAY_SIZE(color_adj)); |
| 695 | else |
| 696 | err_code = sensor_write_regs(gspca_dev, color_no_adj, |
| 697 | ARRAY_SIZE(color_no_adj)); |
| 698 | |
| 699 | if (err_code < 0) |
| 700 | return err_code; |
| 701 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 702 | err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data, |
| 703 | ARRAY_SIZE(vga_sensor1_init_data)); |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 704 | } else { /* sensor type == 2 */ |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 705 | static const struct sensor_w_data vga_sensor2_init_data[] = { |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 706 | |
| 707 | {0x01, 0x00, {0x48}, 1}, |
| 708 | {0x02, 0x00, {0x22}, 1}, |
| 709 | /* Reg 3 msb and 4 is lsb of the exposure setting*/ |
| 710 | {0x05, 0x00, {0x10}, 1}, |
| 711 | {0x06, 0x00, {0x00}, 1}, |
| 712 | {0x07, 0x00, {0x00}, 1}, |
| 713 | {0x08, 0x00, {0x00}, 1}, |
| 714 | {0x09, 0x00, {0x00}, 1}, |
| 715 | /* The following are used in the gain control |
| 716 | * which is BTW completely borked in the OEM driver |
| 717 | * The values for each color go from 0 to 0x7ff |
| 718 | *{0x0a, 0x00, {0x01}, 1}, green1 gain msb |
| 719 | *{0x0b, 0x00, {0x10}, 1}, green1 gain lsb |
| 720 | *{0x0c, 0x00, {0x01}, 1}, red gain msb |
| 721 | *{0x0d, 0x00, {0x10}, 1}, red gain lsb |
| 722 | *{0x0e, 0x00, {0x01}, 1}, blue gain msb |
| 723 | *{0x0f, 0x00, {0x10}, 1}, blue gain lsb |
| 724 | *{0x10, 0x00, {0x01}, 1}, green2 gain msb |
| 725 | *{0x11, 0x00, {0x10}, 1}, green2 gain lsb |
| 726 | */ |
| 727 | {0x12, 0x00, {0x00}, 1}, |
| 728 | {0x13, 0x00, {0x04}, 1}, /* weird effect on colors */ |
| 729 | {0x14, 0x00, {0x00}, 1}, |
| 730 | {0x15, 0x00, {0x06}, 1}, |
| 731 | {0x16, 0x00, {0x01}, 1}, |
| 732 | {0x17, 0x00, {0xe2}, 1}, /* vertical alignment */ |
| 733 | {0x18, 0x00, {0x02}, 1}, |
| 734 | {0x19, 0x00, {0x82}, 1}, /* don't mess with */ |
| 735 | {0x1a, 0x00, {0x00}, 1}, |
| 736 | {0x1b, 0x00, {0x20}, 1}, |
| 737 | /* {0x1c, 0x00, {0x17}, 1}, contrast control */ |
| 738 | {0x1d, 0x00, {0x80}, 1}, /* moving causes a mess */ |
| 739 | {0x1e, 0x00, {0x08}, 1}, /* moving jams the camera */ |
| 740 | {0x1f, 0x00, {0x0c}, 1}, |
| 741 | {0x20, 0x00, {0x00}, 1}, |
| 742 | {0, 0, {0}, 0} |
| 743 | }; |
| 744 | err_code = sensor_write_regs(gspca_dev, vga_sensor2_init_data, |
| 745 | ARRAY_SIZE(vga_sensor2_init_data)); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 746 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 747 | return err_code; |
| 748 | } |
| 749 | |
| 750 | static int sd_start(struct gspca_dev *gspca_dev) |
| 751 | { |
| 752 | struct sd *sd = (struct sd *) gspca_dev; |
| 753 | int err_code; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 754 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 755 | sd->sof_read = 0; |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 756 | |
| 757 | /* Some of the VGA cameras require the memory pointer |
| 758 | * to be set to 0 again. We have been forced to start the |
Theodore Kilgore | b4b84de | 2009-11-01 13:07:08 -0300 | [diff] [blame] | 759 | * stream in sd_config() to detect the hardware, and closed it. |
| 760 | * Thus, we need here to do a completely fresh and clean start. */ |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 761 | err_code = zero_the_pointer(gspca_dev); |
| 762 | if (err_code < 0) |
| 763 | return err_code; |
| 764 | |
| 765 | err_code = stream_start(gspca_dev); |
| 766 | if (err_code < 0) |
| 767 | return err_code; |
| 768 | |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 769 | if (sd->cam_type == CAM_TYPE_CIF) { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 770 | err_code = start_cif_cam(gspca_dev); |
| 771 | } else { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 772 | err_code = start_vga_cam(gspca_dev); |
| 773 | } |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 774 | if (err_code < 0) |
| 775 | return err_code; |
| 776 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 777 | return isoc_enable(gspca_dev); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 781 | { |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 782 | struct sd *sd = (struct sd *) gspca_dev; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 783 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 784 | stream_stop(gspca_dev); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 785 | /* Not all the cams need this, but even if not, probably a good idea */ |
| 786 | zero_the_pointer(gspca_dev); |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 787 | if (sd->do_lcd_stop) |
| 788 | lcd_stop(gspca_dev); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 789 | } |
| 790 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 791 | static void setbrightness(struct gspca_dev *gspca_dev, s32 val) |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 792 | { |
| 793 | struct sd *sd = (struct sd *) gspca_dev; |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 794 | u8 sign_reg = 7; /* This reg and the next one used on CIF cams. */ |
| 795 | u8 value_reg = 8; /* VGA cams seem to use regs 0x0b and 0x0c */ |
Jean-François Moine | 294d8b4 | 2010-10-01 07:37:15 -0300 | [diff] [blame] | 796 | static const u8 quick_clix_table[] = |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 797 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ |
| 798 | { 0, 4, 8, 12, 1, 2, 3, 5, 6, 9, 7, 10, 13, 11, 14, 15}; |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 799 | if (sd->cam_type == CAM_TYPE_VGA) { |
| 800 | sign_reg += 4; |
| 801 | value_reg += 4; |
| 802 | } |
| 803 | |
Theodore Kilgore | b4b84de | 2009-11-01 13:07:08 -0300 | [diff] [blame] | 804 | /* Note register 7 is also seen as 0x8x or 0xCx in some dumps */ |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 805 | if (val > 0) { |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 806 | sensor_write1(gspca_dev, sign_reg, 0x00); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 807 | } else { |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 808 | sensor_write1(gspca_dev, sign_reg, 0x01); |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 809 | val = 257 - val; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 810 | } |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 811 | /* Use lookup table for funky Argus QuickClix brightness */ |
| 812 | if (sd->do_lcd_stop) |
| 813 | val = quick_clix_table[val]; |
| 814 | |
| 815 | sensor_write1(gspca_dev, value_reg, val); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 816 | } |
| 817 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 818 | static void setexposure(struct gspca_dev *gspca_dev, s32 expo, s32 min_clockdiv) |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 819 | { |
| 820 | struct sd *sd = (struct sd *) gspca_dev; |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 821 | int exposure = MR97310A_EXPOSURE_DEFAULT; |
Hans de Goede | 065b6f7 | 2009-10-29 07:42:30 -0300 | [diff] [blame] | 822 | u8 buf[2]; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 823 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 824 | if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1) { |
Theodore Kilgore | b4b84de | 2009-11-01 13:07:08 -0300 | [diff] [blame] | 825 | /* This cam does not like exposure settings < 300, |
Hans de Goede | d76f975 | 2009-10-11 05:22:29 -0300 | [diff] [blame] | 826 | so scale 0 - 4095 to 300 - 4095 */ |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 827 | exposure = (expo * 9267) / 10000 + 300; |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 828 | sensor_write1(gspca_dev, 3, exposure >> 4); |
| 829 | sensor_write1(gspca_dev, 4, exposure & 0x0f); |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 830 | } else if (sd->sensor_type == 2) { |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 831 | exposure = expo; |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 832 | exposure >>= 3; |
| 833 | sensor_write1(gspca_dev, 3, exposure >> 8); |
| 834 | sensor_write1(gspca_dev, 4, exposure & 0xff); |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 835 | } else { |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 836 | /* We have both a clock divider and an exposure register. |
| 837 | We first calculate the clock divider, as that determines |
Theodore Kilgore | b4b84de | 2009-11-01 13:07:08 -0300 | [diff] [blame] | 838 | the maximum exposure and then we calculate the exposure |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 839 | register setting (which goes from 0 - 511). |
| 840 | |
| 841 | Note our 0 - 4095 exposure is mapped to 0 - 511 |
| 842 | milliseconds exposure time */ |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 843 | u8 clockdiv = (60 * expo + 7999) / 8000; |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 844 | |
| 845 | /* Limit framerate to not exceed usb bandwidth */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 846 | if (clockdiv < min_clockdiv && gspca_dev->pixfmt.width >= 320) |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 847 | clockdiv = min_clockdiv; |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 848 | else if (clockdiv < 2) |
| 849 | clockdiv = 2; |
| 850 | |
Theodore Kilgore | 930bf78 | 2009-10-05 05:11:35 -0300 | [diff] [blame] | 851 | if (sd->cam_type == CAM_TYPE_VGA && clockdiv < 4) |
| 852 | clockdiv = 4; |
| 853 | |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 854 | /* Frame exposure time in ms = 1000 * clockdiv / 60 -> |
| 855 | exposure = (sd->exposure / 8) * 511 / (1000 * clockdiv / 60) */ |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 856 | exposure = (60 * 511 * expo) / (8000 * clockdiv); |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 857 | if (exposure > 511) |
| 858 | exposure = 511; |
| 859 | |
| 860 | /* exposure register value is reversed! */ |
| 861 | exposure = 511 - exposure; |
| 862 | |
Hans de Goede | 065b6f7 | 2009-10-29 07:42:30 -0300 | [diff] [blame] | 863 | buf[0] = exposure & 0xff; |
| 864 | buf[1] = exposure >> 8; |
| 865 | sensor_write_reg(gspca_dev, 0x0e, 0, buf, 2); |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 866 | sensor_write1(gspca_dev, 0x02, clockdiv); |
Hans de Goede | a2e081b | 2009-08-14 17:11:36 -0300 | [diff] [blame] | 867 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 868 | } |
| 869 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 870 | static void setgain(struct gspca_dev *gspca_dev, s32 val) |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 871 | { |
| 872 | struct sd *sd = (struct sd *) gspca_dev; |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 873 | u8 gainreg; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 874 | |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 875 | if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1) |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 876 | sensor_write1(gspca_dev, 0x0e, val); |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 877 | else if (sd->cam_type == CAM_TYPE_VGA && sd->sensor_type == 2) |
| 878 | for (gainreg = 0x0a; gainreg < 0x11; gainreg += 2) { |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 879 | sensor_write1(gspca_dev, gainreg, val >> 8); |
| 880 | sensor_write1(gspca_dev, gainreg + 1, val & 0xff); |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 881 | } |
| 882 | else |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 883 | sensor_write1(gspca_dev, 0x10, val); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 884 | } |
| 885 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 886 | static void setcontrast(struct gspca_dev *gspca_dev, s32 val) |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 887 | { |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 888 | sensor_write1(gspca_dev, 0x1c, val); |
Theodore Kilgore | 9d3103d | 2010-02-09 18:05:25 -0300 | [diff] [blame] | 889 | } |
| 890 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 891 | static int sd_s_ctrl(struct v4l2_ctrl *ctrl) |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 892 | { |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 893 | struct gspca_dev *gspca_dev = |
| 894 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); |
| 895 | struct sd *sd = (struct sd *)gspca_dev; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 896 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 897 | gspca_dev->usb_err = 0; |
| 898 | |
| 899 | if (!gspca_dev->streaming) |
| 900 | return 0; |
| 901 | |
| 902 | switch (ctrl->id) { |
| 903 | case V4L2_CID_BRIGHTNESS: |
| 904 | setbrightness(gspca_dev, ctrl->val); |
| 905 | break; |
| 906 | case V4L2_CID_CONTRAST: |
| 907 | setcontrast(gspca_dev, ctrl->val); |
| 908 | break; |
| 909 | case V4L2_CID_EXPOSURE: |
| 910 | setexposure(gspca_dev, sd->exposure->val, |
| 911 | sd->min_clockdiv ? sd->min_clockdiv->val : 0); |
| 912 | break; |
| 913 | case V4L2_CID_GAIN: |
| 914 | setgain(gspca_dev, ctrl->val); |
| 915 | break; |
| 916 | } |
| 917 | return gspca_dev->usb_err; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 918 | } |
| 919 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 920 | static const struct v4l2_ctrl_ops sd_ctrl_ops = { |
| 921 | .s_ctrl = sd_s_ctrl, |
| 922 | }; |
| 923 | |
| 924 | static int sd_init_controls(struct gspca_dev *gspca_dev) |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 925 | { |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 926 | struct sd *sd = (struct sd *)gspca_dev; |
| 927 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
| 928 | static const struct v4l2_ctrl_config clockdiv = { |
| 929 | .ops = &sd_ctrl_ops, |
| 930 | .id = MR97310A_CID_CLOCKDIV, |
| 931 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 932 | .name = "Minimum Clock Divider", |
| 933 | .min = MR97310A_MIN_CLOCKDIV_MIN, |
| 934 | .max = MR97310A_MIN_CLOCKDIV_MAX, |
| 935 | .step = 1, |
| 936 | .def = MR97310A_MIN_CLOCKDIV_DEFAULT, |
| 937 | }; |
| 938 | bool has_brightness = false; |
| 939 | bool has_argus_brightness = false; |
| 940 | bool has_contrast = false; |
| 941 | bool has_gain = false; |
| 942 | bool has_cs_gain = false; |
| 943 | bool has_exposure = false; |
| 944 | bool has_clockdiv = false; |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 945 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 946 | gspca_dev->vdev.ctrl_handler = hdl; |
| 947 | v4l2_ctrl_handler_init(hdl, 4); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 948 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 949 | /* Setup controls depending on camera type */ |
| 950 | if (sd->cam_type == CAM_TYPE_CIF) { |
| 951 | /* No brightness for sensor_type 0 */ |
| 952 | if (sd->sensor_type == 0) |
| 953 | has_exposure = has_gain = has_clockdiv = true; |
| 954 | else |
| 955 | has_exposure = has_gain = has_brightness = true; |
| 956 | } else { |
| 957 | /* All controls need to be disabled if VGA sensor_type is 0 */ |
| 958 | if (sd->sensor_type == 0) |
| 959 | ; /* no controls! */ |
| 960 | else if (sd->sensor_type == 2) |
| 961 | has_exposure = has_cs_gain = has_contrast = true; |
| 962 | else if (sd->do_lcd_stop) |
| 963 | has_exposure = has_gain = has_argus_brightness = |
| 964 | has_clockdiv = true; |
| 965 | else |
| 966 | has_exposure = has_gain = has_brightness = |
| 967 | has_clockdiv = true; |
| 968 | } |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 969 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 970 | /* Separate brightness control description for Argus QuickClix as it has |
| 971 | * different limits from the other mr97310a cameras, and separate gain |
| 972 | * control for Sakar CyberPix camera. */ |
| 973 | /* |
| 974 | * This control is disabled for CIF type 1 and VGA type 0 cameras. |
| 975 | * It does not quite act linearly for the Argus QuickClix camera, |
| 976 | * but it does control brightness. The values are 0 - 15 only, and |
| 977 | * the table above makes them act consecutively. |
| 978 | */ |
| 979 | if (has_brightness) |
| 980 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 981 | V4L2_CID_BRIGHTNESS, -254, 255, 1, |
| 982 | MR97310A_BRIGHTNESS_DEFAULT); |
| 983 | else if (has_argus_brightness) |
| 984 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 985 | V4L2_CID_BRIGHTNESS, 0, 15, 1, |
| 986 | MR97310A_BRIGHTNESS_DEFAULT); |
| 987 | if (has_contrast) |
| 988 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 989 | V4L2_CID_CONTRAST, MR97310A_CONTRAST_MIN, |
| 990 | MR97310A_CONTRAST_MAX, 1, MR97310A_CONTRAST_DEFAULT); |
| 991 | if (has_gain) |
| 992 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 993 | V4L2_CID_GAIN, MR97310A_GAIN_MIN, MR97310A_GAIN_MAX, |
| 994 | 1, MR97310A_GAIN_DEFAULT); |
| 995 | else if (has_cs_gain) |
| 996 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_GAIN, |
| 997 | MR97310A_CS_GAIN_MIN, MR97310A_CS_GAIN_MAX, |
| 998 | 1, MR97310A_CS_GAIN_DEFAULT); |
| 999 | if (has_exposure) |
| 1000 | sd->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1001 | V4L2_CID_EXPOSURE, MR97310A_EXPOSURE_MIN, |
| 1002 | MR97310A_EXPOSURE_MAX, 1, MR97310A_EXPOSURE_DEFAULT); |
| 1003 | if (has_clockdiv) |
| 1004 | sd->min_clockdiv = v4l2_ctrl_new_custom(hdl, &clockdiv, NULL); |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 1005 | |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 1006 | if (hdl->error) { |
| 1007 | pr_err("Could not initialize controls\n"); |
| 1008 | return hdl->error; |
| 1009 | } |
| 1010 | if (has_exposure && has_clockdiv) |
| 1011 | v4l2_ctrl_cluster(2, &sd->exposure); |
Hans de Goede | 065b6f7 | 2009-10-29 07:42:30 -0300 | [diff] [blame] | 1012 | return 0; |
| 1013 | } |
| 1014 | |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1015 | /* Include pac common sof detection functions */ |
| 1016 | #include "pac_common.h" |
| 1017 | |
| 1018 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1019 | u8 *data, /* isoc packet */ |
| 1020 | int len) /* iso packet length */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1021 | { |
Marton Nemeth | a6b69e4 | 2009-11-02 08:05:51 -0300 | [diff] [blame] | 1022 | struct sd *sd = (struct sd *) gspca_dev; |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1023 | unsigned char *sof; |
| 1024 | |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 1025 | sof = pac_find_sof(gspca_dev, &sd->sof_read, data, len); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1026 | if (sof) { |
| 1027 | int n; |
| 1028 | |
| 1029 | /* finish decoding current frame */ |
| 1030 | n = sof - data; |
| 1031 | if (n > sizeof pac_sof_marker) |
| 1032 | n -= sizeof pac_sof_marker; |
| 1033 | else |
| 1034 | n = 0; |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1035 | gspca_frame_add(gspca_dev, LAST_PACKET, |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1036 | data, n); |
Theodore Kilgore | 9832d76 | 2009-03-13 13:04:31 -0300 | [diff] [blame] | 1037 | /* Start next frame. */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1038 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Theodore Kilgore | 9832d76 | 2009-03-13 13:04:31 -0300 | [diff] [blame] | 1039 | pac_sof_marker, sizeof pac_sof_marker); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1040 | len -= sof - data; |
| 1041 | data = sof; |
| 1042 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1043 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /* sub-driver description */ |
| 1047 | static const struct sd_desc sd_desc = { |
| 1048 | .name = MODULE_NAME, |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1049 | .config = sd_config, |
| 1050 | .init = sd_init, |
Hans Verkuil | 3e0ed00 | 2012-05-14 09:45:06 -0300 | [diff] [blame] | 1051 | .init_controls = sd_init_controls, |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1052 | .start = sd_start, |
| 1053 | .stopN = sd_stopN, |
| 1054 | .pkt_scan = sd_pkt_scan, |
| 1055 | }; |
| 1056 | |
| 1057 | /* -- module initialisation -- */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 1058 | static const struct usb_device_id device_table[] = { |
Aurelien Jacobs | 8ac246c | 2009-10-29 07:45:24 -0300 | [diff] [blame] | 1059 | {USB_DEVICE(0x08ca, 0x0110)}, /* Trust Spyc@m 100 */ |
Theodore Kilgore | 89f0863 | 2009-08-14 06:51:52 -0300 | [diff] [blame] | 1060 | {USB_DEVICE(0x08ca, 0x0111)}, /* Aiptek Pencam VGA+ */ |
| 1061 | {USB_DEVICE(0x093a, 0x010f)}, /* All other known MR97310A VGA cams */ |
| 1062 | {USB_DEVICE(0x093a, 0x010e)}, /* All known MR97310A CIF cams */ |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1063 | {} |
| 1064 | }; |
| 1065 | MODULE_DEVICE_TABLE(usb, device_table); |
| 1066 | |
| 1067 | /* -- device connect -- */ |
| 1068 | static int sd_probe(struct usb_interface *intf, |
| 1069 | const struct usb_device_id *id) |
| 1070 | { |
| 1071 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 1072 | THIS_MODULE); |
| 1073 | } |
| 1074 | |
| 1075 | static struct usb_driver sd_driver = { |
| 1076 | .name = MODULE_NAME, |
| 1077 | .id_table = device_table, |
| 1078 | .probe = sd_probe, |
| 1079 | .disconnect = gspca_disconnect, |
| 1080 | #ifdef CONFIG_PM |
| 1081 | .suspend = gspca_suspend, |
| 1082 | .resume = gspca_resume, |
Hans de Goede | 8bb5896 | 2012-06-30 06:44:47 -0300 | [diff] [blame] | 1083 | .reset_resume = gspca_resume, |
Kyle Guinn | d661e62 | 2009-01-16 05:36:14 -0300 | [diff] [blame] | 1084 | #endif |
| 1085 | }; |
| 1086 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 1087 | module_usb_driver(sd_driver); |