Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Sunplus spca561 subdriver |
| 3 | * |
| 4 | * Copyright (C) 2004 Michel Xhaard mxhaard@magic.fr |
| 5 | * |
| 6 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #define MODULE_NAME "spca561" |
| 24 | |
| 25 | #include "gspca.h" |
| 26 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 27 | MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); |
| 28 | MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver"); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
| 31 | /* specific webcam descriptor */ |
| 32 | struct sd { |
| 33 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 34 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 35 | __u16 contrast; /* rev72a only */ |
| 36 | #define CONTRAST_MIN 0x0000 |
| 37 | #define CONTRAST_DEF 0x2000 |
| 38 | #define CONTRAST_MAX 0x3fff |
| 39 | |
| 40 | __u16 exposure; /* rev12a only */ |
Jean-Francois Moine | 3a1ea70 | 2008-09-03 16:47:55 -0300 | [diff] [blame] | 41 | #define EXPOSURE_MIN 0 |
| 42 | #define EXPOSURE_DEF 200 |
| 43 | #define EXPOSURE_MAX 762 |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 44 | |
| 45 | __u8 brightness; /* rev72a only */ |
| 46 | #define BRIGHTNESS_MIN 0 |
| 47 | #define BRIGHTNESS_DEF 32 |
| 48 | #define BRIGHTNESS_MAX 63 |
| 49 | |
| 50 | __u8 white; /* rev12a only */ |
Jean-Francois Moine | 3a1ea70 | 2008-09-03 16:47:55 -0300 | [diff] [blame] | 51 | #define WHITE_MIN 1 |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 52 | #define WHITE_DEF 0x40 |
| 53 | #define WHITE_MAX 0x7f |
| 54 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 55 | __u8 autogain; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 56 | #define AUTOGAIN_MIN 0 |
| 57 | #define AUTOGAIN_DEF 1 |
| 58 | #define AUTOGAIN_MAX 1 |
| 59 | |
| 60 | __u8 gain; /* rev12a only */ |
| 61 | #define GAIN_MIN 0x0 |
| 62 | #define GAIN_DEF 0x24 |
| 63 | #define GAIN_MAX 0x24 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 64 | |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 65 | #define EXPO12A_DEF 3 |
| 66 | __u8 expo12a; /* expo/gain? for rev 12a */ |
| 67 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 68 | __u8 chip_revision; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 69 | #define Rev012A 0 |
| 70 | #define Rev072A 1 |
| 71 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 72 | signed char ag_cnt; |
| 73 | #define AG_CNT_START 13 |
| 74 | }; |
| 75 | |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 76 | static struct v4l2_pix_format sif_mode[] = { |
| 77 | {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, |
| 78 | .bytesperline = 160, |
| 79 | .sizeimage = 160 * 120, |
| 80 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 81 | .priv = 3}, |
| 82 | {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, |
| 83 | .bytesperline = 176, |
| 84 | .sizeimage = 176 * 144, |
| 85 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 86 | .priv = 2}, |
| 87 | {320, 240, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE, |
| 88 | .bytesperline = 320, |
| 89 | .sizeimage = 320 * 240 * 4 / 8, |
| 90 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 91 | .priv = 1}, |
| 92 | {352, 288, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE, |
| 93 | .bytesperline = 352, |
| 94 | .sizeimage = 352 * 288 * 4 / 8, |
| 95 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 96 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | /* |
| 100 | * Initialization data |
| 101 | * I'm not very sure how to split initialization from open data |
| 102 | * chunks. For now, we'll consider everything as initialization |
| 103 | */ |
| 104 | /* Frame packet header offsets for the spca561 */ |
| 105 | #define SPCA561_OFFSET_SNAP 1 |
| 106 | #define SPCA561_OFFSET_TYPE 2 |
| 107 | #define SPCA561_OFFSET_COMPRESS 3 |
| 108 | #define SPCA561_OFFSET_FRAMSEQ 4 |
| 109 | #define SPCA561_OFFSET_GPIO 5 |
| 110 | #define SPCA561_OFFSET_USBBUFF 6 |
| 111 | #define SPCA561_OFFSET_WIN2GRAVE 7 |
| 112 | #define SPCA561_OFFSET_WIN2RAVE 8 |
| 113 | #define SPCA561_OFFSET_WIN2BAVE 9 |
| 114 | #define SPCA561_OFFSET_WIN2GBAVE 10 |
| 115 | #define SPCA561_OFFSET_WIN1GRAVE 11 |
| 116 | #define SPCA561_OFFSET_WIN1RAVE 12 |
| 117 | #define SPCA561_OFFSET_WIN1BAVE 13 |
| 118 | #define SPCA561_OFFSET_WIN1GBAVE 14 |
| 119 | #define SPCA561_OFFSET_FREQ 15 |
| 120 | #define SPCA561_OFFSET_VSYNC 16 |
| 121 | #define SPCA561_OFFSET_DATA 1 |
| 122 | #define SPCA561_INDEX_I2C_BASE 0x8800 |
| 123 | #define SPCA561_SNAPBIT 0x20 |
| 124 | #define SPCA561_SNAPCTRL 0x40 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 125 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 126 | static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 127 | { |
| 128 | int ret; |
| 129 | |
| 130 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 131 | 0, /* request */ |
| 132 | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 133 | value, index, NULL, 0, 500); |
| 134 | PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value); |
| 135 | if (ret < 0) |
| 136 | PDEBUG(D_ERR, "reg write: error %d", ret); |
| 137 | } |
| 138 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 139 | static void write_vector(struct gspca_dev *gspca_dev, |
| 140 | const __u16 data[][2]) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 141 | { |
| 142 | struct usb_device *dev = gspca_dev->dev; |
| 143 | int i; |
| 144 | |
| 145 | i = 0; |
| 146 | while (data[i][1] != 0) { |
| 147 | reg_w_val(dev, data[i][1], data[i][0]); |
| 148 | i++; |
| 149 | } |
| 150 | } |
| 151 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 152 | /* read 'len' bytes to gspca_dev->usb_buf */ |
| 153 | static void reg_r(struct gspca_dev *gspca_dev, |
| 154 | __u16 index, __u16 length) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 155 | { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 156 | usb_control_msg(gspca_dev->dev, |
| 157 | usb_rcvctrlpipe(gspca_dev->dev, 0), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 158 | 0, /* request */ |
| 159 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 160 | 0, /* value */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 161 | index, gspca_dev->usb_buf, length, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 162 | } |
| 163 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 164 | static void reg_w_buf(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 165 | __u16 index, const __u8 *buffer, __u16 len) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 166 | { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 167 | memcpy(gspca_dev->usb_buf, buffer, len); |
| 168 | usb_control_msg(gspca_dev->dev, |
| 169 | usb_sndctrlpipe(gspca_dev->dev, 0), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 170 | 0, /* request */ |
| 171 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 172 | 0, /* value */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 173 | index, gspca_dev->usb_buf, len, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 174 | } |
| 175 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 176 | static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg) |
| 177 | { |
| 178 | int retry = 60; |
| 179 | __u8 DataLow; |
| 180 | __u8 DataHight; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 181 | |
| 182 | DataLow = valeur; |
| 183 | DataHight = valeur >> 8; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 184 | reg_w_val(gspca_dev->dev, 0x8801, reg); |
| 185 | reg_w_val(gspca_dev->dev, 0x8805, DataLow); |
| 186 | reg_w_val(gspca_dev->dev, 0x8800, DataHight); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 187 | while (retry--) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 188 | reg_r(gspca_dev, 0x8803, 1); |
| 189 | if (!gspca_dev->usb_buf[0]) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode) |
| 195 | { |
| 196 | int retry = 60; |
| 197 | __u8 value; |
| 198 | __u8 vallsb; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 199 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 200 | reg_w_val(gspca_dev->dev, 0x8804, 0x92); |
| 201 | reg_w_val(gspca_dev->dev, 0x8801, reg); |
| 202 | reg_w_val(gspca_dev->dev, 0x8802, (mode | 0x01)); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 203 | while (retry--) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 204 | reg_r(gspca_dev, 0x8803, 1); |
| 205 | if (!gspca_dev->usb_buf) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 206 | break; |
| 207 | } |
| 208 | if (retry == 0) |
| 209 | return -1; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 210 | reg_r(gspca_dev, 0x8800, 1); |
| 211 | value = gspca_dev->usb_buf[0]; |
| 212 | reg_r(gspca_dev, 0x8805, 1); |
| 213 | vallsb = gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 214 | return ((int) value << 8) | vallsb; |
| 215 | } |
| 216 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 217 | static const __u16 spca561_init_data[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 218 | {0x0000, 0x8114}, /* Software GPIO output data */ |
| 219 | {0x0001, 0x8114}, /* Software GPIO output data */ |
| 220 | {0x0000, 0x8112}, /* Some kind of reset */ |
| 221 | {0x0003, 0x8701}, /* PCLK clock delay adjustment */ |
| 222 | {0x0001, 0x8703}, /* HSYNC from cmos inverted */ |
| 223 | {0x0011, 0x8118}, /* Enable and conf sensor */ |
| 224 | {0x0001, 0x8118}, /* Conf sensor */ |
| 225 | {0x0092, 0x8804}, /* I know nothing about these */ |
| 226 | {0x0010, 0x8802}, /* 0x88xx registers, so I won't */ |
| 227 | /***************/ |
| 228 | {0x000d, 0x8805}, /* sensor default setting */ |
| 229 | {0x0001, 0x8801}, /* 1 <- 0x0d */ |
| 230 | {0x0000, 0x8800}, |
| 231 | {0x0018, 0x8805}, |
| 232 | {0x0002, 0x8801}, /* 2 <- 0x18 */ |
| 233 | {0x0000, 0x8800}, |
| 234 | {0x0065, 0x8805}, |
| 235 | {0x0004, 0x8801}, /* 4 <- 0x01 0x65 */ |
| 236 | {0x0001, 0x8800}, |
| 237 | {0x0021, 0x8805}, |
| 238 | {0x0005, 0x8801}, /* 5 <- 0x21 */ |
| 239 | {0x0000, 0x8800}, |
| 240 | {0x00aa, 0x8805}, |
| 241 | {0x0007, 0x8801}, /* 7 <- 0xaa */ |
| 242 | {0x0000, 0x8800}, |
| 243 | {0x0004, 0x8805}, |
| 244 | {0x0020, 0x8801}, /* 0x20 <- 0x15 0x04 */ |
| 245 | {0x0015, 0x8800}, |
| 246 | {0x0002, 0x8805}, |
| 247 | {0x0039, 0x8801}, /* 0x39 <- 0x02 */ |
| 248 | {0x0000, 0x8800}, |
| 249 | {0x0010, 0x8805}, |
| 250 | {0x0035, 0x8801}, /* 0x35 <- 0x10 */ |
| 251 | {0x0000, 0x8800}, |
| 252 | {0x0049, 0x8805}, |
| 253 | {0x0009, 0x8801}, /* 0x09 <- 0x10 0x49 */ |
| 254 | {0x0010, 0x8800}, |
| 255 | {0x000b, 0x8805}, |
| 256 | {0x0028, 0x8801}, /* 0x28 <- 0x0b */ |
| 257 | {0x0000, 0x8800}, |
| 258 | {0x000f, 0x8805}, |
| 259 | {0x003b, 0x8801}, /* 0x3b <- 0x0f */ |
| 260 | {0x0000, 0x8800}, |
| 261 | {0x0000, 0x8805}, |
| 262 | {0x003c, 0x8801}, /* 0x3c <- 0x00 */ |
| 263 | {0x0000, 0x8800}, |
| 264 | /***************/ |
| 265 | {0x0018, 0x8601}, /* Pixel/line selection for color separation */ |
| 266 | {0x0000, 0x8602}, /* Optical black level for user setting */ |
| 267 | {0x0060, 0x8604}, /* Optical black horizontal offset */ |
| 268 | {0x0002, 0x8605}, /* Optical black vertical offset */ |
| 269 | {0x0000, 0x8603}, /* Non-automatic optical black level */ |
| 270 | {0x0002, 0x865b}, /* Horizontal offset for valid pixels */ |
| 271 | {0x0000, 0x865f}, /* Vertical valid pixels window (x2) */ |
| 272 | {0x00b0, 0x865d}, /* Horizontal valid pixels window (x2) */ |
| 273 | {0x0090, 0x865e}, /* Vertical valid lines window (x2) */ |
| 274 | {0x00e0, 0x8406}, /* Memory buffer threshold */ |
| 275 | {0x0000, 0x8660}, /* Compensation memory stuff */ |
| 276 | {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */ |
| 277 | {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */ |
| 278 | {0x0001, 0x8200}, /* OprMode to be executed by hardware */ |
| 279 | {0x0007, 0x8201}, /* Output address for r/w serial EEPROM */ |
| 280 | {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */ |
| 281 | {0x0001, 0x8200}, /* OprMode to be executed by hardware */ |
| 282 | {0x0010, 0x8660}, /* Compensation memory stuff */ |
| 283 | {0x0018, 0x8660}, /* Compensation memory stuff */ |
| 284 | |
| 285 | {0x0004, 0x8611}, /* R offset for white balance */ |
| 286 | {0x0004, 0x8612}, /* Gr offset for white balance */ |
| 287 | {0x0007, 0x8613}, /* B offset for white balance */ |
| 288 | {0x0000, 0x8614}, /* Gb offset for white balance */ |
| 289 | {0x008c, 0x8651}, /* R gain for white balance */ |
| 290 | {0x008c, 0x8652}, /* Gr gain for white balance */ |
| 291 | {0x00b5, 0x8653}, /* B gain for white balance */ |
| 292 | {0x008c, 0x8654}, /* Gb gain for white balance */ |
| 293 | {0x0002, 0x8502}, /* Maximum average bit rate stuff */ |
| 294 | |
| 295 | {0x0011, 0x8802}, |
| 296 | {0x0087, 0x8700}, /* Set master clock (96Mhz????) */ |
| 297 | {0x0081, 0x8702}, /* Master clock output enable */ |
| 298 | |
| 299 | {0x0000, 0x8500}, /* Set image type (352x288 no compression) */ |
| 300 | /* Originally was 0x0010 (352x288 compression) */ |
| 301 | |
| 302 | {0x0002, 0x865b}, /* Horizontal offset for valid pixels */ |
| 303 | {0x0003, 0x865c}, /* Vertical offset for valid lines */ |
| 304 | /***************//* sensor active */ |
| 305 | {0x0003, 0x8801}, /* 0x03 <- 0x01 0x21 //289 */ |
| 306 | {0x0021, 0x8805}, |
| 307 | {0x0001, 0x8800}, |
| 308 | {0x0004, 0x8801}, /* 0x04 <- 0x01 0x65 //357 */ |
| 309 | {0x0065, 0x8805}, |
| 310 | {0x0001, 0x8800}, |
| 311 | {0x0005, 0x8801}, /* 0x05 <- 0x2f */ |
| 312 | {0x002f, 0x8805}, |
| 313 | {0x0000, 0x8800}, |
| 314 | {0x0006, 0x8801}, /* 0x06 <- 0 */ |
| 315 | {0x0000, 0x8805}, |
| 316 | {0x0000, 0x8800}, |
| 317 | {0x000a, 0x8801}, /* 0x0a <- 2 */ |
| 318 | {0x0002, 0x8805}, |
| 319 | {0x0000, 0x8800}, |
| 320 | {0x0009, 0x8801}, /* 0x09 <- 0x1061 */ |
| 321 | {0x0061, 0x8805}, |
| 322 | {0x0010, 0x8800}, |
| 323 | {0x0035, 0x8801}, /* 0x35 <-0x14 */ |
| 324 | {0x0014, 0x8805}, |
| 325 | {0x0000, 0x8800}, |
| 326 | {0x0030, 0x8112}, /* ISO and drop packet enable */ |
| 327 | {0x0000, 0x8112}, /* Some kind of reset ???? */ |
| 328 | {0x0009, 0x8118}, /* Enable sensor and set standby */ |
| 329 | {0x0000, 0x8114}, /* Software GPIO output data */ |
| 330 | {0x0000, 0x8114}, /* Software GPIO output data */ |
| 331 | {0x0001, 0x8114}, /* Software GPIO output data */ |
| 332 | {0x0000, 0x8112}, /* Some kind of reset ??? */ |
| 333 | {0x0003, 0x8701}, |
| 334 | {0x0001, 0x8703}, |
| 335 | {0x0011, 0x8118}, |
| 336 | {0x0001, 0x8118}, |
| 337 | /***************/ |
| 338 | {0x0092, 0x8804}, |
| 339 | {0x0010, 0x8802}, |
| 340 | {0x000d, 0x8805}, |
| 341 | {0x0001, 0x8801}, |
| 342 | {0x0000, 0x8800}, |
| 343 | {0x0018, 0x8805}, |
| 344 | {0x0002, 0x8801}, |
| 345 | {0x0000, 0x8800}, |
| 346 | {0x0065, 0x8805}, |
| 347 | {0x0004, 0x8801}, |
| 348 | {0x0001, 0x8800}, |
| 349 | {0x0021, 0x8805}, |
| 350 | {0x0005, 0x8801}, |
| 351 | {0x0000, 0x8800}, |
| 352 | {0x00aa, 0x8805}, |
| 353 | {0x0007, 0x8801}, /* mode 0xaa */ |
| 354 | {0x0000, 0x8800}, |
| 355 | {0x0004, 0x8805}, |
| 356 | {0x0020, 0x8801}, |
| 357 | {0x0015, 0x8800}, /* mode 0x0415 */ |
| 358 | {0x0002, 0x8805}, |
| 359 | {0x0039, 0x8801}, |
| 360 | {0x0000, 0x8800}, |
| 361 | {0x0010, 0x8805}, |
| 362 | {0x0035, 0x8801}, |
| 363 | {0x0000, 0x8800}, |
| 364 | {0x0049, 0x8805}, |
| 365 | {0x0009, 0x8801}, |
| 366 | {0x0010, 0x8800}, |
| 367 | {0x000b, 0x8805}, |
| 368 | {0x0028, 0x8801}, |
| 369 | {0x0000, 0x8800}, |
| 370 | {0x000f, 0x8805}, |
| 371 | {0x003b, 0x8801}, |
| 372 | {0x0000, 0x8800}, |
| 373 | {0x0000, 0x8805}, |
| 374 | {0x003c, 0x8801}, |
| 375 | {0x0000, 0x8800}, |
| 376 | {0x0002, 0x8502}, |
| 377 | {0x0039, 0x8801}, |
| 378 | {0x0000, 0x8805}, |
| 379 | {0x0000, 0x8800}, |
| 380 | |
| 381 | {0x0087, 0x8700}, /* overwrite by start */ |
| 382 | {0x0081, 0x8702}, |
| 383 | {0x0000, 0x8500}, |
| 384 | /* {0x0010, 0x8500}, -- Previous line was this */ |
| 385 | {0x0002, 0x865b}, |
| 386 | {0x0003, 0x865c}, |
| 387 | /***************/ |
| 388 | {0x0003, 0x8801}, /* 0x121-> 289 */ |
| 389 | {0x0021, 0x8805}, |
| 390 | {0x0001, 0x8800}, |
| 391 | {0x0004, 0x8801}, /* 0x165 -> 357 */ |
| 392 | {0x0065, 0x8805}, |
| 393 | {0x0001, 0x8800}, |
| 394 | {0x0005, 0x8801}, /* 0x2f //blanking control colonne */ |
| 395 | {0x002f, 0x8805}, |
| 396 | {0x0000, 0x8800}, |
| 397 | {0x0006, 0x8801}, /* 0x00 //blanking mode row */ |
| 398 | {0x0000, 0x8805}, |
| 399 | {0x0000, 0x8800}, |
| 400 | {0x000a, 0x8801}, /* 0x01 //0x02 */ |
| 401 | {0x0001, 0x8805}, |
| 402 | {0x0000, 0x8800}, |
| 403 | {0x0009, 0x8801}, /* 0x1061 - setexposure times && pixel clock |
| 404 | * 0001 0 | 000 0110 0001 */ |
| 405 | {0x0061, 0x8805}, /* 61 31 */ |
| 406 | {0x0008, 0x8800}, /* 08 */ |
| 407 | {0x0035, 0x8801}, /* 0x14 - set gain general */ |
| 408 | {0x001f, 0x8805}, /* 0x14 */ |
| 409 | {0x0000, 0x8800}, |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 410 | {0x000e, 0x8112}, /* white balance - was 30 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 411 | {} |
| 412 | }; |
| 413 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 414 | |
| 415 | /******************** QC Express etch2 stuff ********************/ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 416 | static const __u16 Pb100_1map8300[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 417 | /* reg, value */ |
| 418 | {0x8320, 0x3304}, |
| 419 | |
| 420 | {0x8303, 0x0125}, /* image area */ |
| 421 | {0x8304, 0x0169}, |
| 422 | {0x8328, 0x000b}, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 423 | {0x833c, 0x0001}, /*fixme: win:07*/ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 424 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 425 | {0x832f, 0x1904}, /*fixme: was 0419*/ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 426 | {0x8307, 0x00aa}, |
| 427 | {0x8301, 0x0003}, |
| 428 | {0x8302, 0x000e}, |
| 429 | {} |
| 430 | }; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 431 | static const __u16 Pb100_2map8300[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 432 | /* reg, value */ |
| 433 | {0x8339, 0x0000}, |
| 434 | {0x8307, 0x00aa}, |
| 435 | {} |
| 436 | }; |
| 437 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 438 | static const __u16 spca561_161rev12A_data1[][2] = { |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 439 | {0x29, 0x8118}, /* white balance - was 21 */ |
| 440 | {0x08, 0x8114}, /* white balance - was 01 */ |
| 441 | {0x0e, 0x8112}, /* white balance - was 00 */ |
| 442 | {0x00, 0x8102}, /* white balance - new */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 443 | {0x92, 0x8804}, |
| 444 | {0x04, 0x8802}, /* windows uses 08 */ |
| 445 | {} |
| 446 | }; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 447 | static const __u16 spca561_161rev12A_data2[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 448 | {0x21, 0x8118}, |
| 449 | {0x10, 0x8500}, |
| 450 | {0x07, 0x8601}, |
| 451 | {0x07, 0x8602}, |
| 452 | {0x04, 0x8501}, |
| 453 | {0x21, 0x8118}, |
| 454 | |
| 455 | {0x07, 0x8201}, /* windows uses 02 */ |
| 456 | {0x08, 0x8200}, |
| 457 | {0x01, 0x8200}, |
| 458 | |
| 459 | {0x00, 0x8114}, |
| 460 | {0x01, 0x8114}, /* windows uses 00 */ |
| 461 | |
| 462 | {0x90, 0x8604}, |
| 463 | {0x00, 0x8605}, |
| 464 | {0xb0, 0x8603}, |
| 465 | |
| 466 | /* sensor gains */ |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 467 | {0x07, 0x8601}, /* white balance - new */ |
| 468 | {0x07, 0x8602}, /* white balance - new */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 469 | {0x00, 0x8610}, /* *red */ |
| 470 | {0x00, 0x8611}, /* 3f *green */ |
| 471 | {0x00, 0x8612}, /* green *blue */ |
| 472 | {0x00, 0x8613}, /* blue *green */ |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 473 | {0x43, 0x8614}, /* green *red - white balance - was 0x35 */ |
| 474 | {0x40, 0x8615}, /* 40 *green - white balance - was 0x35 */ |
| 475 | {0x71, 0x8616}, /* 7a *blue - white balance - was 0x35 */ |
| 476 | {0x40, 0x8617}, /* 40 *green - white balance - was 0x35 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 477 | |
| 478 | {0x0c, 0x8620}, /* 0c */ |
| 479 | {0xc8, 0x8631}, /* c8 */ |
| 480 | {0xc8, 0x8634}, /* c8 */ |
| 481 | {0x23, 0x8635}, /* 23 */ |
| 482 | {0x1f, 0x8636}, /* 1f */ |
| 483 | {0xdd, 0x8637}, /* dd */ |
| 484 | {0xe1, 0x8638}, /* e1 */ |
| 485 | {0x1d, 0x8639}, /* 1d */ |
| 486 | {0x21, 0x863a}, /* 21 */ |
| 487 | {0xe3, 0x863b}, /* e3 */ |
| 488 | {0xdf, 0x863c}, /* df */ |
| 489 | {0xf0, 0x8505}, |
| 490 | {0x32, 0x850a}, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 491 | /* {0x99, 0x8700}, * - white balance - new (removed) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 492 | {} |
| 493 | }; |
| 494 | |
| 495 | static void sensor_mapwrite(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 496 | const __u16 sensormap[][2]) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 497 | { |
| 498 | int i = 0; |
| 499 | __u8 usbval[2]; |
| 500 | |
| 501 | while (sensormap[i][0]) { |
| 502 | usbval[0] = sensormap[i][1]; |
| 503 | usbval[1] = sensormap[i][1] >> 8; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 504 | reg_w_buf(gspca_dev, sensormap[i][0], usbval, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 505 | i++; |
| 506 | } |
| 507 | } |
| 508 | static void init_161rev12A(struct gspca_dev *gspca_dev) |
| 509 | { |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 510 | /* sensor_reset(gspca_dev); (not in win) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 511 | write_vector(gspca_dev, spca561_161rev12A_data1); |
| 512 | sensor_mapwrite(gspca_dev, Pb100_1map8300); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 513 | /*fixme: should be in sd_start*/ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 514 | write_vector(gspca_dev, spca561_161rev12A_data2); |
| 515 | sensor_mapwrite(gspca_dev, Pb100_2map8300); |
| 516 | } |
| 517 | |
| 518 | /* this function is called at probe time */ |
| 519 | static int sd_config(struct gspca_dev *gspca_dev, |
| 520 | const struct usb_device_id *id) |
| 521 | { |
| 522 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 523 | struct cam *cam; |
| 524 | __u16 vendor, product; |
| 525 | __u8 data1, data2; |
| 526 | |
| 527 | /* Read frm global register the USB product and vendor IDs, just to |
| 528 | * prove that we can communicate with the device. This works, which |
| 529 | * confirms at we are communicating properly and that the device |
| 530 | * is a 561. */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 531 | reg_r(gspca_dev, 0x8104, 1); |
| 532 | data1 = gspca_dev->usb_buf[0]; |
| 533 | reg_r(gspca_dev, 0x8105, 1); |
| 534 | data2 = gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 535 | vendor = (data2 << 8) | data1; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 536 | reg_r(gspca_dev, 0x8106, 1); |
| 537 | data1 = gspca_dev->usb_buf[0]; |
| 538 | reg_r(gspca_dev, 0x8107, 1); |
| 539 | data2 = gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 540 | product = (data2 << 8) | data1; |
| 541 | if (vendor != id->idVendor || product != id->idProduct) { |
| 542 | PDEBUG(D_PROBE, "Bad vendor / product from device"); |
| 543 | return -EINVAL; |
| 544 | } |
Jean-Francois Moine | 9d64fdb | 2008-07-25 08:53:03 -0300 | [diff] [blame] | 545 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 546 | cam = &gspca_dev->cam; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 547 | cam->epaddr = 0x01; |
| 548 | gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */ |
| 549 | cam->cam_mode = sif_mode; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 550 | cam->nmodes = ARRAY_SIZE(sif_mode); |
Jean-Francois Moine | 9d64fdb | 2008-07-25 08:53:03 -0300 | [diff] [blame] | 551 | |
| 552 | sd->chip_revision = id->driver_info; |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 553 | sd->brightness = BRIGHTNESS_DEF; |
| 554 | sd->contrast = CONTRAST_DEF; |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 555 | sd->white = WHITE_DEF; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 556 | sd->exposure = EXPOSURE_DEF; |
| 557 | sd->autogain = AUTOGAIN_DEF; |
| 558 | sd->gain = GAIN_DEF; |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 559 | sd->expo12a = EXPO12A_DEF; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | /* this function is called at open time */ |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 564 | static int sd_open_12a(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 565 | { |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 566 | PDEBUG(D_STREAM, "Chip revision: 012a"); |
| 567 | init_161rev12A(gspca_dev); |
| 568 | return 0; |
| 569 | } |
| 570 | static int sd_open_72a(struct gspca_dev *gspca_dev) |
| 571 | { |
| 572 | PDEBUG(D_STREAM, "Chip revision: 072a"); |
| 573 | write_vector(gspca_dev, spca561_init_data); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static void setcontrast(struct gspca_dev *gspca_dev) |
| 578 | { |
| 579 | struct sd *sd = (struct sd *) gspca_dev; |
| 580 | struct usb_device *dev = gspca_dev->dev; |
| 581 | __u8 lowb; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 582 | |
| 583 | switch (sd->chip_revision) { |
| 584 | case Rev072A: |
| 585 | lowb = sd->contrast >> 8; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 586 | reg_w_val(dev, 0x8651, lowb); |
| 587 | reg_w_val(dev, 0x8652, lowb); |
| 588 | reg_w_val(dev, 0x8653, lowb); |
| 589 | reg_w_val(dev, 0x8654, lowb); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 590 | break; |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 591 | default: { |
| 592 | /* case Rev012A: { */ |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 593 | static const __u8 Reg8391[] = |
| 594 | { 0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00 }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 595 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 596 | reg_w_buf(gspca_dev, 0x8391, Reg8391, 8); |
| 597 | reg_w_buf(gspca_dev, 0x8390, Reg8391, 8); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 598 | break; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 603 | /* rev12a only */ |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 604 | static void setwhite(struct gspca_dev *gspca_dev) |
| 605 | { |
| 606 | struct sd *sd = (struct sd *) gspca_dev; |
| 607 | __u16 white; |
| 608 | __u8 reg8614, reg8616; |
| 609 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 610 | white = sd->white; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 611 | /* try to emulate MS-win as possible */ |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 612 | reg8616 = 0x90 - white * 5 / 8; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 613 | reg_w_val(gspca_dev->dev, 0x8616, reg8616); |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 614 | reg8614 = 0x20 + white * 3 / 8; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 615 | reg_w_val(gspca_dev->dev, 0x8614, reg8614); |
| 616 | } |
| 617 | |
| 618 | /* rev 12a only */ |
| 619 | static void setexposure(struct gspca_dev *gspca_dev) |
| 620 | { |
| 621 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 3a1ea70 | 2008-09-03 16:47:55 -0300 | [diff] [blame] | 622 | int expo; |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 623 | __u8 data[2]; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 624 | |
Jean-Francois Moine | 3a1ea70 | 2008-09-03 16:47:55 -0300 | [diff] [blame] | 625 | expo = sd->exposure + 0x20a8; /* from test */ |
| 626 | data[0] = expo; |
| 627 | data[1] = expo >> 8; |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 628 | reg_w_buf(gspca_dev, 0x8309, data, 2); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | /* rev 12a only */ |
| 632 | static void setgain(struct gspca_dev *gspca_dev) |
| 633 | { |
| 634 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 635 | __u8 data[2]; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 636 | |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 637 | data[0] = sd->gain; |
| 638 | data[1] = 0; |
| 639 | reg_w_buf(gspca_dev, 0x8335, data, 2); |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 640 | } |
| 641 | |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 642 | static void setautogain(struct gspca_dev *gspca_dev) |
| 643 | { |
| 644 | struct sd *sd = (struct sd *) gspca_dev; |
| 645 | |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 646 | if (sd->autogain) |
| 647 | sd->ag_cnt = AG_CNT_START; |
| 648 | else |
| 649 | sd->ag_cnt = -1; |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 650 | } |
| 651 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 652 | static void sd_start_12a(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 653 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 654 | struct usb_device *dev = gspca_dev->dev; |
| 655 | int Clck; |
| 656 | __u8 Reg8307[] = { 0xaa, 0x00 }; |
| 657 | int mode; |
| 658 | |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 659 | mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 660 | switch (mode) { |
| 661 | case 0: |
| 662 | case 1: |
| 663 | Clck = 0x8a; |
| 664 | break; |
| 665 | case 2: |
| 666 | Clck = 0x85; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 667 | break; |
| 668 | default: |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 669 | Clck = 0x83; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 670 | break; |
| 671 | } |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 672 | if (mode <= 1) { |
| 673 | /* Use compression on 320x240 and above */ |
| 674 | reg_w_val(dev, 0x8500, 0x10 | mode); |
| 675 | } else { |
| 676 | /* I couldn't get the compression to work below 320x240 |
| 677 | * Fortunately at these resolutions the bandwidth |
| 678 | * is sufficient to push raw frames at ~20fps */ |
| 679 | reg_w_val(dev, 0x8500, mode); |
| 680 | } /* -- qq@kuku.eu.org */ |
| 681 | reg_w_buf(gspca_dev, 0x8307, Reg8307, 2); |
| 682 | reg_w_val(gspca_dev->dev, 0x8700, Clck); |
| 683 | /* 0x8f 0x85 0x27 clock */ |
| 684 | reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20); |
| 685 | reg_w_val(gspca_dev->dev, 0x850b, 0x03); |
| 686 | setcontrast(gspca_dev); |
| 687 | setwhite(gspca_dev); |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 688 | setautogain(gspca_dev); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 689 | } |
| 690 | static void sd_start_72a(struct gspca_dev *gspca_dev) |
| 691 | { |
| 692 | struct usb_device *dev = gspca_dev->dev; |
| 693 | int Clck; |
| 694 | int mode; |
| 695 | |
| 696 | mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; |
| 697 | switch (mode) { |
| 698 | default: |
| 699 | /* case 0: |
| 700 | case 1: */ |
| 701 | Clck = 0x25; |
| 702 | break; |
| 703 | case 2: |
| 704 | Clck = 0x22; |
| 705 | break; |
| 706 | case 3: |
| 707 | Clck = 0x21; |
| 708 | break; |
| 709 | } |
| 710 | reg_w_val(dev, 0x8500, mode); /* mode */ |
| 711 | reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */ |
| 712 | reg_w_val(dev, 0x8112, 0x10 | 0x20); |
| 713 | setautogain(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 717 | { |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 718 | struct sd *sd = (struct sd *) gspca_dev; |
| 719 | |
| 720 | if (sd->chip_revision == Rev012A) { |
| 721 | reg_w_val(gspca_dev->dev, 0x8112, 0x0e); |
| 722 | } else { |
| 723 | reg_w_val(gspca_dev->dev, 0x8112, 0x20); |
| 724 | /* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */ |
| 725 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | static void sd_stop0(struct gspca_dev *gspca_dev) |
| 729 | { |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 730 | struct sd *sd = (struct sd *) gspca_dev; |
| 731 | |
| 732 | if (sd->chip_revision == Rev012A) { |
| 733 | reg_w_val(gspca_dev->dev, 0x8118, 0x29); |
| 734 | reg_w_val(gspca_dev->dev, 0x8114, 0x08); |
| 735 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /* this function is called at close time */ |
| 739 | static void sd_close(struct gspca_dev *gspca_dev) |
| 740 | { |
| 741 | reg_w_val(gspca_dev->dev, 0x8114, 0); |
| 742 | } |
| 743 | |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 744 | static void do_autogain(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 745 | { |
| 746 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 747 | int expotimes; |
| 748 | int pixelclk; |
| 749 | int gainG; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 750 | __u8 R, Gr, Gb, B; |
| 751 | int y; |
| 752 | __u8 luma_mean = 110; |
| 753 | __u8 luma_delta = 20; |
| 754 | __u8 spring = 4; |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 755 | __u8 reg8339[2]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 756 | |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 757 | if (sd->ag_cnt < 0) |
| 758 | return; |
| 759 | if (--sd->ag_cnt >= 0) |
| 760 | return; |
| 761 | sd->ag_cnt = AG_CNT_START; |
| 762 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 763 | switch (sd->chip_revision) { |
| 764 | case Rev072A: |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 765 | reg_r(gspca_dev, 0x8621, 1); |
| 766 | Gr = gspca_dev->usb_buf[0]; |
| 767 | reg_r(gspca_dev, 0x8622, 1); |
| 768 | R = gspca_dev->usb_buf[0]; |
| 769 | reg_r(gspca_dev, 0x8623, 1); |
| 770 | B = gspca_dev->usb_buf[0]; |
| 771 | reg_r(gspca_dev, 0x8624, 1); |
| 772 | Gb = gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 773 | y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8; |
| 774 | /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */ |
| 775 | /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */ |
| 776 | /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */ |
| 777 | |
| 778 | if (y < luma_mean - luma_delta || |
| 779 | y > luma_mean + luma_delta) { |
| 780 | expotimes = i2c_read(gspca_dev, 0x09, 0x10); |
| 781 | pixelclk = 0x0800; |
| 782 | expotimes = expotimes & 0x07ff; |
| 783 | /* PDEBUG(D_PACK, |
| 784 | "Exposition Times 0x%03X Clock 0x%04X ", |
| 785 | expotimes,pixelclk); */ |
| 786 | gainG = i2c_read(gspca_dev, 0x35, 0x10); |
| 787 | /* PDEBUG(D_PACK, |
| 788 | "reading Gain register %d", gainG); */ |
| 789 | |
| 790 | expotimes += (luma_mean - y) >> spring; |
| 791 | gainG += (luma_mean - y) / 50; |
| 792 | /* PDEBUG(D_PACK, |
| 793 | "compute expotimes %d gain %d", |
| 794 | expotimes,gainG); */ |
| 795 | |
| 796 | if (gainG > 0x3f) |
| 797 | gainG = 0x3f; |
| 798 | else if (gainG < 4) |
| 799 | gainG = 3; |
| 800 | i2c_write(gspca_dev, gainG, 0x35); |
| 801 | |
| 802 | if (expotimes >= 0x0256) |
| 803 | expotimes = 0x0256; |
| 804 | else if (expotimes < 4) |
| 805 | expotimes = 3; |
| 806 | i2c_write(gspca_dev, expotimes | pixelclk, 0x09); |
| 807 | } |
| 808 | break; |
| 809 | case Rev012A: |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 810 | reg_r(gspca_dev, 0x8330, 2); |
| 811 | if (gspca_dev->usb_buf[1] > 0x08) { |
| 812 | reg8339[0] = ++sd->expo12a; |
| 813 | reg8339[1] = 0; |
| 814 | reg_w_buf(gspca_dev, 0x8339, reg8339, 2); |
| 815 | } else if (gspca_dev->usb_buf[1] < 0x02) { |
| 816 | reg8339[0] = --sd->expo12a; |
| 817 | reg8339[1] = 0; |
| 818 | reg_w_buf(gspca_dev, 0x8339, reg8339, 2); |
| 819 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 820 | break; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 825 | struct gspca_frame *frame, /* target */ |
| 826 | __u8 *data, /* isoc packet */ |
| 827 | int len) /* iso packet length */ |
| 828 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 829 | switch (data[0]) { |
| 830 | case 0: /* start of frame */ |
| 831 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, |
| 832 | data, 0); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 833 | data += SPCA561_OFFSET_DATA; |
| 834 | len -= SPCA561_OFFSET_DATA; |
| 835 | if (data[1] & 0x10) { |
| 836 | /* compressed bayer */ |
| 837 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
| 838 | frame, data, len); |
| 839 | } else { |
Hans de Goede | 54ab92c | 2008-07-03 11:20:58 -0300 | [diff] [blame] | 840 | /* raw bayer (with a header, which we skip) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 841 | data += 20; |
| 842 | len -= 20; |
| 843 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
| 844 | frame, data, len); |
| 845 | } |
| 846 | return; |
| 847 | case 0xff: /* drop */ |
| 848 | /* gspca_dev->last_packet_type = DISCARD_PACKET; */ |
| 849 | return; |
| 850 | } |
| 851 | data++; |
| 852 | len--; |
| 853 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); |
| 854 | } |
| 855 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 856 | /* rev 72a only */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 857 | static void setbrightness(struct gspca_dev *gspca_dev) |
| 858 | { |
| 859 | struct sd *sd = (struct sd *) gspca_dev; |
| 860 | __u8 value; |
| 861 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 862 | value = sd->brightness; |
| 863 | reg_w_val(gspca_dev->dev, 0x8611, value); |
| 864 | reg_w_val(gspca_dev->dev, 0x8612, value); |
| 865 | reg_w_val(gspca_dev->dev, 0x8613, value); |
| 866 | reg_w_val(gspca_dev->dev, 0x8614, value); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static void getbrightness(struct gspca_dev *gspca_dev) |
| 870 | { |
| 871 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 872 | __u16 tot; |
| 873 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 874 | tot = 0; |
| 875 | reg_r(gspca_dev, 0x8611, 1); |
| 876 | tot += gspca_dev->usb_buf[0]; |
| 877 | reg_r(gspca_dev, 0x8612, 1); |
| 878 | tot += gspca_dev->usb_buf[0]; |
| 879 | reg_r(gspca_dev, 0x8613, 1); |
| 880 | tot += gspca_dev->usb_buf[0]; |
| 881 | reg_r(gspca_dev, 0x8614, 1); |
| 882 | tot += gspca_dev->usb_buf[0]; |
| 883 | sd->brightness = tot >> 2; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 884 | } |
| 885 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 886 | /* rev72a only */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 887 | static void getcontrast(struct gspca_dev *gspca_dev) |
| 888 | { |
| 889 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 890 | __u16 tot; |
| 891 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 892 | tot = 0; |
| 893 | reg_r(gspca_dev, 0x8651, 1); |
| 894 | tot += gspca_dev->usb_buf[0]; |
| 895 | reg_r(gspca_dev, 0x8652, 1); |
| 896 | tot += gspca_dev->usb_buf[0]; |
| 897 | reg_r(gspca_dev, 0x8653, 1); |
| 898 | tot += gspca_dev->usb_buf[0]; |
| 899 | reg_r(gspca_dev, 0x8654, 1); |
| 900 | tot += gspca_dev->usb_buf[0]; |
| 901 | sd->contrast = tot << 6; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 902 | PDEBUG(D_CONF, "get contrast %d", sd->contrast); |
| 903 | } |
| 904 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 905 | /* rev 72a only */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 906 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 907 | { |
| 908 | struct sd *sd = (struct sd *) gspca_dev; |
| 909 | |
| 910 | sd->brightness = val; |
| 911 | if (gspca_dev->streaming) |
| 912 | setbrightness(gspca_dev); |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 917 | { |
| 918 | struct sd *sd = (struct sd *) gspca_dev; |
| 919 | |
| 920 | getbrightness(gspca_dev); |
| 921 | *val = sd->brightness; |
| 922 | return 0; |
| 923 | } |
| 924 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 925 | /* rev 72a only */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 926 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) |
| 927 | { |
| 928 | struct sd *sd = (struct sd *) gspca_dev; |
| 929 | |
| 930 | sd->contrast = val; |
| 931 | if (gspca_dev->streaming) |
| 932 | setcontrast(gspca_dev); |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) |
| 937 | { |
| 938 | struct sd *sd = (struct sd *) gspca_dev; |
| 939 | |
| 940 | getcontrast(gspca_dev); |
| 941 | *val = sd->contrast; |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) |
| 946 | { |
| 947 | struct sd *sd = (struct sd *) gspca_dev; |
| 948 | |
| 949 | sd->autogain = val; |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 950 | if (gspca_dev->streaming) |
| 951 | setautogain(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) |
| 956 | { |
| 957 | struct sd *sd = (struct sd *) gspca_dev; |
| 958 | |
| 959 | *val = sd->autogain; |
| 960 | return 0; |
| 961 | } |
| 962 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 963 | /* rev12a only */ |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 964 | static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val) |
| 965 | { |
| 966 | struct sd *sd = (struct sd *) gspca_dev; |
| 967 | |
| 968 | sd->white = val; |
| 969 | if (gspca_dev->streaming) |
| 970 | setwhite(gspca_dev); |
| 971 | return 0; |
| 972 | } |
| 973 | |
| 974 | static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val) |
| 975 | { |
| 976 | struct sd *sd = (struct sd *) gspca_dev; |
| 977 | |
| 978 | *val = sd->white; |
| 979 | return 0; |
| 980 | } |
| 981 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 982 | /* rev12a only */ |
| 983 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) |
| 984 | { |
| 985 | struct sd *sd = (struct sd *) gspca_dev; |
| 986 | |
| 987 | sd->exposure = val; |
| 988 | if (gspca_dev->streaming) |
| 989 | setexposure(gspca_dev); |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) |
| 994 | { |
| 995 | struct sd *sd = (struct sd *) gspca_dev; |
| 996 | |
| 997 | *val = sd->exposure; |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | /* rev12a only */ |
| 1002 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) |
| 1003 | { |
| 1004 | struct sd *sd = (struct sd *) gspca_dev; |
| 1005 | |
| 1006 | sd->gain = val; |
| 1007 | if (gspca_dev->streaming) |
| 1008 | setgain(gspca_dev); |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) |
| 1013 | { |
| 1014 | struct sd *sd = (struct sd *) gspca_dev; |
| 1015 | |
| 1016 | *val = sd->gain; |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | /* control tables */ |
| 1021 | static struct ctrl sd_ctrls_12a[] = { |
| 1022 | { |
| 1023 | { |
| 1024 | .id = V4L2_CID_DO_WHITE_BALANCE, |
| 1025 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1026 | .name = "While Balance", |
| 1027 | .minimum = WHITE_MIN, |
| 1028 | .maximum = WHITE_MAX, |
| 1029 | .step = 1, |
| 1030 | .default_value = WHITE_DEF, |
| 1031 | }, |
| 1032 | .set = sd_setwhite, |
| 1033 | .get = sd_getwhite, |
| 1034 | }, |
| 1035 | { |
| 1036 | { |
| 1037 | .id = V4L2_CID_EXPOSURE, |
| 1038 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1039 | .name = "Exposure", |
| 1040 | .minimum = EXPOSURE_MIN, |
| 1041 | .maximum = EXPOSURE_MAX, |
| 1042 | .step = 1, |
| 1043 | .default_value = EXPOSURE_DEF, |
| 1044 | }, |
| 1045 | .set = sd_setexposure, |
| 1046 | .get = sd_getexposure, |
| 1047 | }, |
| 1048 | { |
| 1049 | { |
| 1050 | .id = V4L2_CID_AUTOGAIN, |
| 1051 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 1052 | .name = "Auto Gain", |
| 1053 | .minimum = AUTOGAIN_MIN, |
| 1054 | .maximum = AUTOGAIN_MAX, |
| 1055 | .step = 1, |
| 1056 | .default_value = AUTOGAIN_DEF, |
| 1057 | }, |
| 1058 | .set = sd_setautogain, |
| 1059 | .get = sd_getautogain, |
| 1060 | }, |
| 1061 | { |
| 1062 | { |
| 1063 | .id = V4L2_CID_GAIN, |
| 1064 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1065 | .name = "Gain", |
| 1066 | .minimum = GAIN_MIN, |
| 1067 | .maximum = GAIN_MAX, |
| 1068 | .step = 1, |
| 1069 | .default_value = GAIN_DEF, |
| 1070 | }, |
| 1071 | .set = sd_setgain, |
| 1072 | .get = sd_getgain, |
| 1073 | }, |
| 1074 | }; |
| 1075 | |
| 1076 | static struct ctrl sd_ctrls_72a[] = { |
| 1077 | { |
| 1078 | { |
| 1079 | .id = V4L2_CID_BRIGHTNESS, |
| 1080 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1081 | .name = "Brightness", |
| 1082 | .minimum = BRIGHTNESS_MIN, |
| 1083 | .maximum = BRIGHTNESS_MAX, |
| 1084 | .step = 1, |
| 1085 | .default_value = BRIGHTNESS_DEF, |
| 1086 | }, |
| 1087 | .set = sd_setbrightness, |
| 1088 | .get = sd_getbrightness, |
| 1089 | }, |
| 1090 | { |
| 1091 | { |
| 1092 | .id = V4L2_CID_CONTRAST, |
| 1093 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1094 | .name = "Contrast", |
| 1095 | .minimum = CONTRAST_MIN, |
| 1096 | .maximum = CONTRAST_MAX, |
| 1097 | .step = 1, |
| 1098 | .default_value = CONTRAST_DEF, |
| 1099 | }, |
| 1100 | .set = sd_setcontrast, |
| 1101 | .get = sd_getcontrast, |
| 1102 | }, |
| 1103 | { |
| 1104 | { |
| 1105 | .id = V4L2_CID_AUTOGAIN, |
| 1106 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 1107 | .name = "Auto Gain", |
| 1108 | .minimum = AUTOGAIN_MIN, |
| 1109 | .maximum = AUTOGAIN_MAX, |
| 1110 | .step = 1, |
| 1111 | .default_value = AUTOGAIN_DEF, |
| 1112 | }, |
| 1113 | .set = sd_setautogain, |
| 1114 | .get = sd_getautogain, |
| 1115 | }, |
| 1116 | }; |
| 1117 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1118 | /* sub-driver description */ |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 1119 | static const struct sd_desc sd_desc_12a = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1120 | .name = MODULE_NAME, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 1121 | .ctrls = sd_ctrls_12a, |
| 1122 | .nctrls = ARRAY_SIZE(sd_ctrls_12a), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1123 | .config = sd_config, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 1124 | .open = sd_open_12a, |
| 1125 | .start = sd_start_12a, |
| 1126 | .stopN = sd_stopN, |
| 1127 | .stop0 = sd_stop0, |
| 1128 | .close = sd_close, |
| 1129 | .pkt_scan = sd_pkt_scan, |
| 1130 | /* .dq_callback = do_autogain, * fixme */ |
| 1131 | }; |
| 1132 | static const struct sd_desc sd_desc_72a = { |
| 1133 | .name = MODULE_NAME, |
| 1134 | .ctrls = sd_ctrls_72a, |
| 1135 | .nctrls = ARRAY_SIZE(sd_ctrls_72a), |
| 1136 | .config = sd_config, |
| 1137 | .open = sd_open_72a, |
| 1138 | .start = sd_start_72a, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1139 | .stopN = sd_stopN, |
| 1140 | .stop0 = sd_stop0, |
| 1141 | .close = sd_close, |
| 1142 | .pkt_scan = sd_pkt_scan, |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 1143 | .dq_callback = do_autogain, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1144 | }; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 1145 | static const struct sd_desc *sd_desc[2] = { |
| 1146 | &sd_desc_12a, |
| 1147 | &sd_desc_72a |
| 1148 | }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1149 | |
| 1150 | /* -- module initialisation -- */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1151 | static const __devinitdata struct usb_device_id device_table[] = { |
Jean-Francois Moine | 87581aa | 2008-07-26 14:30:01 -0300 | [diff] [blame] | 1152 | {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A}, |
| 1153 | {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A}, |
| 1154 | {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A}, |
| 1155 | {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A}, |
| 1156 | {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A}, |
| 1157 | {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A}, |
| 1158 | {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A}, |
| 1159 | {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A}, |
| 1160 | {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A}, |
| 1161 | {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A}, |
| 1162 | {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A}, |
| 1163 | {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A}, |
| 1164 | {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A}, |
| 1165 | {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A}, |
| 1166 | {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1167 | {} |
| 1168 | }; |
| 1169 | |
| 1170 | MODULE_DEVICE_TABLE(usb, device_table); |
| 1171 | |
| 1172 | /* -- device connect -- */ |
| 1173 | static int sd_probe(struct usb_interface *intf, |
| 1174 | const struct usb_device_id *id) |
| 1175 | { |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 1176 | return gspca_dev_probe(intf, id, |
| 1177 | sd_desc[id->driver_info], |
| 1178 | sizeof(struct sd), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1179 | THIS_MODULE); |
| 1180 | } |
| 1181 | |
| 1182 | static struct usb_driver sd_driver = { |
| 1183 | .name = MODULE_NAME, |
| 1184 | .id_table = device_table, |
| 1185 | .probe = sd_probe, |
| 1186 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame^] | 1187 | #ifdef CONFIG_PM |
| 1188 | .suspend = gspca_suspend, |
| 1189 | .resume = gspca_resume, |
| 1190 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1191 | }; |
| 1192 | |
| 1193 | /* -- module insert / remove -- */ |
| 1194 | static int __init sd_mod_init(void) |
| 1195 | { |
| 1196 | if (usb_register(&sd_driver) < 0) |
| 1197 | return -1; |
Jean-Francois Moine | 10b0e96 | 2008-07-22 05:35:10 -0300 | [diff] [blame] | 1198 | PDEBUG(D_PROBE, "registered"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1199 | return 0; |
| 1200 | } |
| 1201 | static void __exit sd_mod_exit(void) |
| 1202 | { |
| 1203 | usb_deregister(&sd_driver); |
| 1204 | PDEBUG(D_PROBE, "deregistered"); |
| 1205 | } |
| 1206 | |
| 1207 | module_init(sd_mod_init); |
| 1208 | module_exit(sd_mod_exit); |