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. |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 17 | */ |
| 18 | |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 21 | #define MODULE_NAME "spca561" |
| 22 | |
Hans de Goede | 436c2c5 | 2010-02-28 09:41:04 -0300 | [diff] [blame] | 23 | #include <linux/input.h> |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 24 | #include "gspca.h" |
| 25 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 26 | MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); |
| 27 | MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver"); |
| 28 | MODULE_LICENSE("GPL"); |
| 29 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 30 | #define EXPOSURE_MAX (2047 + 325) |
| 31 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 32 | /* specific webcam descriptor */ |
| 33 | struct sd { |
| 34 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 35 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 36 | struct { /* hue/contrast control cluster */ |
| 37 | struct v4l2_ctrl *contrast; |
| 38 | struct v4l2_ctrl *hue; |
| 39 | }; |
| 40 | struct v4l2_ctrl *autogain; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 41 | |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 42 | #define EXPO12A_DEF 3 |
| 43 | __u8 expo12a; /* expo/gain? for rev 12a */ |
| 44 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 45 | __u8 chip_revision; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 46 | #define Rev012A 0 |
| 47 | #define Rev072A 1 |
| 48 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 49 | signed char ag_cnt; |
| 50 | #define AG_CNT_START 13 |
| 51 | }; |
| 52 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 53 | static const struct v4l2_pix_format sif_012a_mode[] = { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 54 | {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, |
| 55 | .bytesperline = 160, |
| 56 | .sizeimage = 160 * 120, |
| 57 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 58 | .priv = 3}, |
| 59 | {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, |
| 60 | .bytesperline = 176, |
| 61 | .sizeimage = 176 * 144, |
| 62 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 63 | .priv = 2}, |
| 64 | {320, 240, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE, |
| 65 | .bytesperline = 320, |
| 66 | .sizeimage = 320 * 240 * 4 / 8, |
| 67 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 68 | .priv = 1}, |
| 69 | {352, 288, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE, |
| 70 | .bytesperline = 352, |
| 71 | .sizeimage = 352 * 288 * 4 / 8, |
| 72 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 73 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 74 | }; |
| 75 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 76 | static const struct v4l2_pix_format sif_072a_mode[] = { |
Jean-Francois Moine | b77c004 | 2008-09-04 16:22:56 -0300 | [diff] [blame] | 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_SGBRG8, V4L2_FIELD_NONE, |
| 88 | .bytesperline = 320, |
| 89 | .sizeimage = 320 * 240, |
| 90 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 91 | .priv = 1}, |
| 92 | {352, 288, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, |
| 93 | .bytesperline = 352, |
| 94 | .sizeimage = 352 * 288, |
| 95 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 96 | .priv = 0}, |
| 97 | }; |
| 98 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 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 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 121 | #define SPCA561_INDEX_I2C_BASE 0x8800 |
| 122 | #define SPCA561_SNAPBIT 0x20 |
| 123 | #define SPCA561_SNAPCTRL 0x40 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 124 | |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 125 | static const u16 rev72a_reset[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 126 | {0x0000, 0x8114}, /* Software GPIO output data */ |
| 127 | {0x0001, 0x8114}, /* Software GPIO output data */ |
| 128 | {0x0000, 0x8112}, /* Some kind of reset */ |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 129 | {} |
| 130 | }; |
| 131 | static const __u16 rev72a_init_data1[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 132 | {0x0003, 0x8701}, /* PCLK clock delay adjustment */ |
| 133 | {0x0001, 0x8703}, /* HSYNC from cmos inverted */ |
| 134 | {0x0011, 0x8118}, /* Enable and conf sensor */ |
| 135 | {0x0001, 0x8118}, /* Conf sensor */ |
| 136 | {0x0092, 0x8804}, /* I know nothing about these */ |
| 137 | {0x0010, 0x8802}, /* 0x88xx registers, so I won't */ |
Jean-Francois Moine | f8a04a6 | 2008-12-19 07:21:26 -0300 | [diff] [blame] | 138 | {} |
| 139 | }; |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 140 | static const u16 rev72a_init_sensor1[][2] = { |
| 141 | {0x0001, 0x000d}, |
| 142 | {0x0002, 0x0018}, |
| 143 | {0x0004, 0x0165}, |
| 144 | {0x0005, 0x0021}, |
| 145 | {0x0007, 0x00aa}, |
| 146 | {0x0020, 0x1504}, |
| 147 | {0x0039, 0x0002}, |
| 148 | {0x0035, 0x0010}, |
| 149 | {0x0009, 0x1049}, |
| 150 | {0x0028, 0x000b}, |
| 151 | {0x003b, 0x000f}, |
| 152 | {0x003c, 0x0000}, |
Jean-Francois Moine | f8a04a6 | 2008-12-19 07:21:26 -0300 | [diff] [blame] | 153 | {} |
| 154 | }; |
| 155 | static const __u16 rev72a_init_data2[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 156 | {0x0018, 0x8601}, /* Pixel/line selection for color separation */ |
| 157 | {0x0000, 0x8602}, /* Optical black level for user setting */ |
| 158 | {0x0060, 0x8604}, /* Optical black horizontal offset */ |
| 159 | {0x0002, 0x8605}, /* Optical black vertical offset */ |
| 160 | {0x0000, 0x8603}, /* Non-automatic optical black level */ |
| 161 | {0x0002, 0x865b}, /* Horizontal offset for valid pixels */ |
| 162 | {0x0000, 0x865f}, /* Vertical valid pixels window (x2) */ |
| 163 | {0x00b0, 0x865d}, /* Horizontal valid pixels window (x2) */ |
| 164 | {0x0090, 0x865e}, /* Vertical valid lines window (x2) */ |
| 165 | {0x00e0, 0x8406}, /* Memory buffer threshold */ |
| 166 | {0x0000, 0x8660}, /* Compensation memory stuff */ |
| 167 | {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */ |
| 168 | {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */ |
| 169 | {0x0001, 0x8200}, /* OprMode to be executed by hardware */ |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 170 | /* from ms-win */ |
| 171 | {0x0000, 0x8611}, /* R offset for white balance */ |
| 172 | {0x00fd, 0x8612}, /* Gr offset for white balance */ |
| 173 | {0x0003, 0x8613}, /* B offset for white balance */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 174 | {0x0000, 0x8614}, /* Gb offset for white balance */ |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 175 | /* from ms-win */ |
| 176 | {0x0035, 0x8651}, /* R gain for white balance */ |
| 177 | {0x0040, 0x8652}, /* Gr gain for white balance */ |
| 178 | {0x005f, 0x8653}, /* B gain for white balance */ |
| 179 | {0x0040, 0x8654}, /* Gb gain for white balance */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 180 | {0x0002, 0x8502}, /* Maximum average bit rate stuff */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 181 | {0x0011, 0x8802}, |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 182 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 183 | {0x0087, 0x8700}, /* Set master clock (96Mhz????) */ |
| 184 | {0x0081, 0x8702}, /* Master clock output enable */ |
| 185 | |
| 186 | {0x0000, 0x8500}, /* Set image type (352x288 no compression) */ |
| 187 | /* Originally was 0x0010 (352x288 compression) */ |
| 188 | |
| 189 | {0x0002, 0x865b}, /* Horizontal offset for valid pixels */ |
| 190 | {0x0003, 0x865c}, /* Vertical offset for valid lines */ |
Jean-Francois Moine | f8a04a6 | 2008-12-19 07:21:26 -0300 | [diff] [blame] | 191 | {} |
| 192 | }; |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 193 | static const u16 rev72a_init_sensor2[][2] = { |
| 194 | {0x0003, 0x0121}, |
| 195 | {0x0004, 0x0165}, |
| 196 | {0x0005, 0x002f}, /* blanking control column */ |
| 197 | {0x0006, 0x0000}, /* blanking mode row*/ |
| 198 | {0x000a, 0x0002}, |
| 199 | {0x0009, 0x1061}, /* setexposure times && pixel clock |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 200 | * 0001 0 | 000 0110 0001 */ |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 201 | {0x0035, 0x0014}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 202 | {} |
| 203 | }; |
| 204 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 205 | /******************** QC Express etch2 stuff ********************/ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 206 | static const __u16 Pb100_1map8300[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 207 | /* reg, value */ |
| 208 | {0x8320, 0x3304}, |
| 209 | |
| 210 | {0x8303, 0x0125}, /* image area */ |
| 211 | {0x8304, 0x0169}, |
| 212 | {0x8328, 0x000b}, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 213 | {0x833c, 0x0001}, /*fixme: win:07*/ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 214 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 215 | {0x832f, 0x1904}, /*fixme: was 0419*/ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 216 | {0x8307, 0x00aa}, |
| 217 | {0x8301, 0x0003}, |
| 218 | {0x8302, 0x000e}, |
| 219 | {} |
| 220 | }; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 221 | static const __u16 Pb100_2map8300[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 222 | /* reg, value */ |
| 223 | {0x8339, 0x0000}, |
| 224 | {0x8307, 0x00aa}, |
| 225 | {} |
| 226 | }; |
| 227 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 228 | static const __u16 spca561_161rev12A_data1[][2] = { |
Hans de Goede | 6b33e5e | 2010-02-27 07:18:14 -0300 | [diff] [blame] | 229 | {0x29, 0x8118}, /* Control register (various enable bits) */ |
| 230 | {0x08, 0x8114}, /* GPIO: Led off */ |
| 231 | {0x0e, 0x8112}, /* 0x0e stream off 0x3e stream on */ |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 232 | {0x00, 0x8102}, /* white balance - new */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 233 | {0x92, 0x8804}, |
| 234 | {0x04, 0x8802}, /* windows uses 08 */ |
| 235 | {} |
| 236 | }; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 237 | static const __u16 spca561_161rev12A_data2[][2] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 238 | {0x21, 0x8118}, |
| 239 | {0x10, 0x8500}, |
| 240 | {0x07, 0x8601}, |
| 241 | {0x07, 0x8602}, |
| 242 | {0x04, 0x8501}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 243 | |
| 244 | {0x07, 0x8201}, /* windows uses 02 */ |
| 245 | {0x08, 0x8200}, |
| 246 | {0x01, 0x8200}, |
| 247 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 248 | {0x90, 0x8604}, |
| 249 | {0x00, 0x8605}, |
| 250 | {0xb0, 0x8603}, |
| 251 | |
| 252 | /* sensor gains */ |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 253 | {0x07, 0x8601}, /* white balance - new */ |
| 254 | {0x07, 0x8602}, /* white balance - new */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 255 | {0x00, 0x8610}, /* *red */ |
| 256 | {0x00, 0x8611}, /* 3f *green */ |
| 257 | {0x00, 0x8612}, /* green *blue */ |
| 258 | {0x00, 0x8613}, /* blue *green */ |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 259 | {0x43, 0x8614}, /* green *red - white balance - was 0x35 */ |
| 260 | {0x40, 0x8615}, /* 40 *green - white balance - was 0x35 */ |
| 261 | {0x71, 0x8616}, /* 7a *blue - white balance - was 0x35 */ |
| 262 | {0x40, 0x8617}, /* 40 *green - white balance - was 0x35 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 263 | |
| 264 | {0x0c, 0x8620}, /* 0c */ |
| 265 | {0xc8, 0x8631}, /* c8 */ |
| 266 | {0xc8, 0x8634}, /* c8 */ |
| 267 | {0x23, 0x8635}, /* 23 */ |
| 268 | {0x1f, 0x8636}, /* 1f */ |
| 269 | {0xdd, 0x8637}, /* dd */ |
| 270 | {0xe1, 0x8638}, /* e1 */ |
| 271 | {0x1d, 0x8639}, /* 1d */ |
| 272 | {0x21, 0x863a}, /* 21 */ |
| 273 | {0xe3, 0x863b}, /* e3 */ |
| 274 | {0xdf, 0x863c}, /* df */ |
| 275 | {0xf0, 0x8505}, |
| 276 | {0x32, 0x850a}, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 277 | /* {0x99, 0x8700}, * - white balance - new (removed) */ |
Hans de Goede | 6b33e5e | 2010-02-27 07:18:14 -0300 | [diff] [blame] | 278 | /* HDG we used to do this in stop0, making the init state and the state |
| 279 | after a start / stop different, so do this here instead. */ |
| 280 | {0x29, 0x8118}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 281 | {} |
| 282 | }; |
| 283 | |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 284 | static void reg_w_val(struct gspca_dev *gspca_dev, __u16 index, __u8 value) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 285 | { |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 286 | int ret; |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 287 | struct usb_device *dev = gspca_dev->dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 288 | |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 289 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 290 | 0, /* request */ |
| 291 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 292 | value, index, NULL, 0, 500); |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 293 | gspca_dbg(gspca_dev, D_USBO, "reg write: 0x%02x:0x%02x\n", |
| 294 | index, value); |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 295 | if (ret < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 296 | pr_err("reg write: error %d\n", ret); |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static void write_vector(struct gspca_dev *gspca_dev, |
| 300 | const __u16 data[][2]) |
| 301 | { |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 302 | int i; |
| 303 | |
| 304 | i = 0; |
| 305 | while (data[i][1] != 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 306 | reg_w_val(gspca_dev, data[i][1], data[i][0]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 307 | i++; |
| 308 | } |
| 309 | } |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 310 | |
| 311 | /* read 'len' bytes to gspca_dev->usb_buf */ |
| 312 | static void reg_r(struct gspca_dev *gspca_dev, |
| 313 | __u16 index, __u16 length) |
| 314 | { |
| 315 | usb_control_msg(gspca_dev->dev, |
| 316 | usb_rcvctrlpipe(gspca_dev->dev, 0), |
| 317 | 0, /* request */ |
| 318 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 319 | 0, /* value */ |
| 320 | index, gspca_dev->usb_buf, length, 500); |
| 321 | } |
| 322 | |
| 323 | /* write 'len' bytes from gspca_dev->usb_buf */ |
| 324 | static void reg_w_buf(struct gspca_dev *gspca_dev, |
| 325 | __u16 index, __u16 len) |
| 326 | { |
| 327 | usb_control_msg(gspca_dev->dev, |
| 328 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 329 | 0, /* request */ |
| 330 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 331 | 0, /* value */ |
| 332 | index, gspca_dev->usb_buf, len, 500); |
| 333 | } |
| 334 | |
| 335 | static void i2c_write(struct gspca_dev *gspca_dev, __u16 value, __u16 reg) |
| 336 | { |
| 337 | int retry = 60; |
| 338 | |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 339 | reg_w_val(gspca_dev, 0x8801, reg); |
| 340 | reg_w_val(gspca_dev, 0x8805, value); |
| 341 | reg_w_val(gspca_dev, 0x8800, value >> 8); |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 342 | do { |
| 343 | reg_r(gspca_dev, 0x8803, 1); |
| 344 | if (!gspca_dev->usb_buf[0]) |
| 345 | return; |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 346 | msleep(10); |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 347 | } while (--retry); |
| 348 | } |
| 349 | |
| 350 | static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode) |
| 351 | { |
| 352 | int retry = 60; |
| 353 | __u8 value; |
| 354 | |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 355 | reg_w_val(gspca_dev, 0x8804, 0x92); |
| 356 | reg_w_val(gspca_dev, 0x8801, reg); |
| 357 | reg_w_val(gspca_dev, 0x8802, mode | 0x01); |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 358 | do { |
| 359 | reg_r(gspca_dev, 0x8803, 1); |
| 360 | if (!gspca_dev->usb_buf[0]) { |
| 361 | reg_r(gspca_dev, 0x8800, 1); |
| 362 | value = gspca_dev->usb_buf[0]; |
| 363 | reg_r(gspca_dev, 0x8805, 1); |
| 364 | return ((int) value << 8) | gspca_dev->usb_buf[0]; |
| 365 | } |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 366 | msleep(10); |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 367 | } while (--retry); |
| 368 | return -1; |
| 369 | } |
| 370 | |
| 371 | static void sensor_mapwrite(struct gspca_dev *gspca_dev, |
| 372 | const __u16 (*sensormap)[2]) |
| 373 | { |
| 374 | while ((*sensormap)[0]) { |
| 375 | gspca_dev->usb_buf[0] = (*sensormap)[1]; |
| 376 | gspca_dev->usb_buf[1] = (*sensormap)[1] >> 8; |
| 377 | reg_w_buf(gspca_dev, (*sensormap)[0], 2); |
| 378 | sensormap++; |
| 379 | } |
| 380 | } |
| 381 | |
Jean-Francois Moine | f8a04a6 | 2008-12-19 07:21:26 -0300 | [diff] [blame] | 382 | static void write_sensor_72a(struct gspca_dev *gspca_dev, |
| 383 | const __u16 (*sensor)[2]) |
| 384 | { |
| 385 | while ((*sensor)[0]) { |
| 386 | i2c_write(gspca_dev, (*sensor)[1], (*sensor)[0]); |
| 387 | sensor++; |
| 388 | } |
| 389 | } |
| 390 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 391 | static void init_161rev12A(struct gspca_dev *gspca_dev) |
| 392 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 393 | write_vector(gspca_dev, spca561_161rev12A_data1); |
| 394 | sensor_mapwrite(gspca_dev, Pb100_1map8300); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 395 | /*fixme: should be in sd_start*/ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 396 | write_vector(gspca_dev, spca561_161rev12A_data2); |
| 397 | sensor_mapwrite(gspca_dev, Pb100_2map8300); |
| 398 | } |
| 399 | |
| 400 | /* this function is called at probe time */ |
| 401 | static int sd_config(struct gspca_dev *gspca_dev, |
| 402 | const struct usb_device_id *id) |
| 403 | { |
| 404 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 405 | struct cam *cam; |
| 406 | __u16 vendor, product; |
| 407 | __u8 data1, data2; |
| 408 | |
| 409 | /* Read frm global register the USB product and vendor IDs, just to |
| 410 | * prove that we can communicate with the device. This works, which |
| 411 | * confirms at we are communicating properly and that the device |
| 412 | * is a 561. */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 413 | reg_r(gspca_dev, 0x8104, 1); |
| 414 | data1 = gspca_dev->usb_buf[0]; |
| 415 | reg_r(gspca_dev, 0x8105, 1); |
| 416 | data2 = gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 417 | vendor = (data2 << 8) | data1; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 418 | reg_r(gspca_dev, 0x8106, 1); |
| 419 | data1 = gspca_dev->usb_buf[0]; |
| 420 | reg_r(gspca_dev, 0x8107, 1); |
| 421 | data2 = gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 422 | product = (data2 << 8) | data1; |
| 423 | if (vendor != id->idVendor || product != id->idProduct) { |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 424 | gspca_dbg(gspca_dev, D_PROBE, "Bad vendor / product from device\n"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 425 | return -EINVAL; |
| 426 | } |
Jean-Francois Moine | 9d64fdb | 2008-07-25 08:53:03 -0300 | [diff] [blame] | 427 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 428 | cam = &gspca_dev->cam; |
Hans de Goede | eb3fb7c | 2012-01-01 16:35:01 -0300 | [diff] [blame] | 429 | cam->needs_full_bandwidth = 1; |
Jean-Francois Moine | 9d64fdb | 2008-07-25 08:53:03 -0300 | [diff] [blame] | 430 | |
| 431 | sd->chip_revision = id->driver_info; |
Jean-Francois Moine | b77c004 | 2008-09-04 16:22:56 -0300 | [diff] [blame] | 432 | if (sd->chip_revision == Rev012A) { |
| 433 | cam->cam_mode = sif_012a_mode; |
| 434 | cam->nmodes = ARRAY_SIZE(sif_012a_mode); |
| 435 | } else { |
| 436 | cam->cam_mode = sif_072a_mode; |
| 437 | cam->nmodes = ARRAY_SIZE(sif_072a_mode); |
| 438 | } |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 439 | sd->expo12a = EXPO12A_DEF; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 440 | return 0; |
| 441 | } |
| 442 | |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 443 | /* this function is called at probe and resume time */ |
| 444 | static int sd_init_12a(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 445 | { |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 446 | gspca_dbg(gspca_dev, D_STREAM, "Chip revision: 012a\n"); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 447 | init_161rev12A(gspca_dev); |
| 448 | return 0; |
| 449 | } |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 450 | static int sd_init_72a(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 451 | { |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 452 | gspca_dbg(gspca_dev, D_STREAM, "Chip revision: 072a\n"); |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 453 | write_vector(gspca_dev, rev72a_reset); |
| 454 | msleep(200); |
Jean-Francois Moine | f8a04a6 | 2008-12-19 07:21:26 -0300 | [diff] [blame] | 455 | write_vector(gspca_dev, rev72a_init_data1); |
| 456 | write_sensor_72a(gspca_dev, rev72a_init_sensor1); |
| 457 | write_vector(gspca_dev, rev72a_init_data2); |
| 458 | write_sensor_72a(gspca_dev, rev72a_init_sensor2); |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 459 | reg_w_val(gspca_dev, 0x8112, 0x30); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 463 | static void setbrightness(struct gspca_dev *gspca_dev, s32 val) |
| 464 | { |
Hans de Goede | a8931d5 | 2012-07-02 15:29:56 -0300 | [diff] [blame] | 465 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | a8931d5 | 2012-07-02 15:29:56 -0300 | [diff] [blame] | 466 | __u16 reg; |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 467 | |
Hans de Goede | a8931d5 | 2012-07-02 15:29:56 -0300 | [diff] [blame] | 468 | if (sd->chip_revision == Rev012A) |
| 469 | reg = 0x8610; |
| 470 | else |
| 471 | reg = 0x8611; |
| 472 | |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 473 | reg_w_val(gspca_dev, reg + 0, val); /* R */ |
| 474 | reg_w_val(gspca_dev, reg + 1, val); /* Gr */ |
| 475 | reg_w_val(gspca_dev, reg + 2, val); /* B */ |
| 476 | reg_w_val(gspca_dev, reg + 3, val); /* Gb */ |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static void setwhite(struct gspca_dev *gspca_dev, s32 white, s32 contrast) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 480 | { |
| 481 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 482 | __u8 blue, red; |
| 483 | __u16 reg; |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 484 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 485 | /* try to emulate MS-win as possible */ |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 486 | red = 0x20 + white * 3 / 8; |
| 487 | blue = 0x90 - white * 5 / 8; |
| 488 | if (sd->chip_revision == Rev012A) { |
| 489 | reg = 0x8614; |
| 490 | } else { |
| 491 | reg = 0x8651; |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 492 | red += contrast - 0x20; |
| 493 | blue += contrast - 0x20; |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 494 | reg_w_val(gspca_dev, 0x8652, contrast + 0x20); /* Gr */ |
| 495 | reg_w_val(gspca_dev, 0x8654, contrast + 0x20); /* Gb */ |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 496 | } |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 497 | reg_w_val(gspca_dev, reg, red); |
| 498 | reg_w_val(gspca_dev, reg + 2, blue); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* rev 12a only */ |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 502 | static void setexposure(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 503 | { |
Hans de Goede | d0848eb | 2009-05-25 15:20:16 -0300 | [diff] [blame] | 504 | int i, expo = 0; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 505 | |
Hans de Goede | 0fc23d2 | 2008-09-04 16:22:57 -0300 | [diff] [blame] | 506 | /* Register 0x8309 controls exposure for the spca561, |
| 507 | the basic exposure setting goes from 1-2047, where 1 is completely |
| 508 | dark and 2047 is very bright. It not only influences exposure but |
| 509 | also the framerate (to allow for longer exposure) from 1 - 300 it |
| 510 | only raises the exposure time then from 300 - 600 it halves the |
| 511 | framerate to be able to further raise the exposure time and for every |
| 512 | 300 more it halves the framerate again. This allows for a maximum |
| 513 | exposure time of circa 0.2 - 0.25 seconds (30 / (2000/3000) fps). |
| 514 | Sometimes this is not enough, the 1-2047 uses bits 0-10, bits 11-12 |
| 515 | configure a divider for the base framerate which us used at the |
| 516 | exposure setting of 1-300. These bits configure the base framerate |
| 517 | according to the following formula: fps = 60 / (value + 2) */ |
Hans de Goede | d0848eb | 2009-05-25 15:20:16 -0300 | [diff] [blame] | 518 | |
| 519 | /* We choose to use the high bits setting the fixed framerate divisor |
| 520 | asap, as setting high basic exposure setting without the fixed |
| 521 | divider in combination with high gains makes the cam stop */ |
| 522 | int table[] = { 0, 450, 550, 625, EXPOSURE_MAX }; |
| 523 | |
| 524 | for (i = 0; i < ARRAY_SIZE(table) - 1; i++) { |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 525 | if (val <= table[i + 1]) { |
| 526 | expo = val - table[i]; |
Hans de Goede | d0848eb | 2009-05-25 15:20:16 -0300 | [diff] [blame] | 527 | if (i) |
| 528 | expo += 300; |
| 529 | expo |= i << 11; |
| 530 | break; |
| 531 | } |
Hans de Goede | 0fc23d2 | 2008-09-04 16:22:57 -0300 | [diff] [blame] | 532 | } |
Hans de Goede | d0848eb | 2009-05-25 15:20:16 -0300 | [diff] [blame] | 533 | |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 534 | gspca_dev->usb_buf[0] = expo; |
| 535 | gspca_dev->usb_buf[1] = expo >> 8; |
| 536 | reg_w_buf(gspca_dev, 0x8309, 2); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* rev 12a only */ |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 540 | static void setgain(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 541 | { |
Hans de Goede | d0848eb | 2009-05-25 15:20:16 -0300 | [diff] [blame] | 542 | /* gain reg low 6 bits 0-63 gain, bit 6 and 7, both double the |
| 543 | sensitivity when set, so 31 + one of them set == 63, and 15 |
| 544 | with both of them set == 63 */ |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 545 | if (val < 64) |
| 546 | gspca_dev->usb_buf[0] = val; |
| 547 | else if (val < 128) |
| 548 | gspca_dev->usb_buf[0] = (val / 2) | 0x40; |
Hans de Goede | d0848eb | 2009-05-25 15:20:16 -0300 | [diff] [blame] | 549 | else |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 550 | gspca_dev->usb_buf[0] = (val / 4) | 0xc0; |
Hans de Goede | d0848eb | 2009-05-25 15:20:16 -0300 | [diff] [blame] | 551 | |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 552 | gspca_dev->usb_buf[1] = 0; |
| 553 | reg_w_buf(gspca_dev, 0x8335, 2); |
Jean-Francois Moine | 6c9d3c5 | 2008-09-03 16:47:30 -0300 | [diff] [blame] | 554 | } |
| 555 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 556 | static void setautogain(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 557 | { |
| 558 | struct sd *sd = (struct sd *) gspca_dev; |
| 559 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 560 | if (val) |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 561 | sd->ag_cnt = AG_CNT_START; |
| 562 | else |
| 563 | sd->ag_cnt = -1; |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 564 | } |
| 565 | |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 566 | static int sd_start_12a(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 567 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 568 | int mode; |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 569 | static const __u8 Reg8391[8] = |
| 570 | {0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00}; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 571 | |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 572 | 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] | 573 | if (mode <= 1) { |
| 574 | /* Use compression on 320x240 and above */ |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 575 | reg_w_val(gspca_dev, 0x8500, 0x10 | mode); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 576 | } else { |
| 577 | /* I couldn't get the compression to work below 320x240 |
| 578 | * Fortunately at these resolutions the bandwidth |
| 579 | * is sufficient to push raw frames at ~20fps */ |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 580 | reg_w_val(gspca_dev, 0x8500, mode); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 581 | } /* -- qq@kuku.eu.org */ |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 582 | |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 583 | gspca_dev->usb_buf[0] = 0xaa; |
| 584 | gspca_dev->usb_buf[1] = 0x00; |
| 585 | reg_w_buf(gspca_dev, 0x8307, 2); |
| 586 | /* clock - lower 0x8X values lead to fps > 30 */ |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 587 | reg_w_val(gspca_dev, 0x8700, 0x8a); |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 588 | /* 0x8f 0x85 0x27 clock */ |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 589 | reg_w_val(gspca_dev, 0x8112, 0x1e | 0x20); |
| 590 | reg_w_val(gspca_dev, 0x850b, 0x03); |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 591 | memcpy(gspca_dev->usb_buf, Reg8391, 8); |
| 592 | reg_w_buf(gspca_dev, 0x8391, 8); |
| 593 | reg_w_buf(gspca_dev, 0x8390, 8); |
Hans de Goede | 6b33e5e | 2010-02-27 07:18:14 -0300 | [diff] [blame] | 594 | |
| 595 | /* Led ON (bit 3 -> 0 */ |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 596 | reg_w_val(gspca_dev, 0x8114, 0x00); |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 597 | return 0; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 598 | } |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 599 | static int sd_start_72a(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 600 | { |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 601 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 602 | int Clck; |
| 603 | int mode; |
| 604 | |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 605 | write_vector(gspca_dev, rev72a_reset); |
| 606 | msleep(200); |
| 607 | write_vector(gspca_dev, rev72a_init_data1); |
| 608 | write_sensor_72a(gspca_dev, rev72a_init_sensor1); |
| 609 | |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 610 | mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; |
| 611 | switch (mode) { |
| 612 | default: |
Jean-Francois Moine | a48196a | 2009-01-18 14:24:52 -0300 | [diff] [blame] | 613 | case 0: |
| 614 | Clck = 0x27; /* ms-win 0x87 */ |
| 615 | break; |
| 616 | case 1: |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 617 | Clck = 0x25; |
| 618 | break; |
| 619 | case 2: |
| 620 | Clck = 0x22; |
| 621 | break; |
| 622 | case 3: |
| 623 | Clck = 0x21; |
| 624 | break; |
| 625 | } |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 626 | reg_w_val(gspca_dev, 0x8700, Clck); /* 0x27 clock */ |
| 627 | reg_w_val(gspca_dev, 0x8702, 0x81); |
| 628 | reg_w_val(gspca_dev, 0x8500, mode); /* mode */ |
Jean-Francois Moine | 0dbc2c1 | 2009-01-16 16:24:28 -0300 | [diff] [blame] | 629 | write_sensor_72a(gspca_dev, rev72a_init_sensor2); |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 630 | setwhite(gspca_dev, v4l2_ctrl_g_ctrl(sd->hue), |
| 631 | v4l2_ctrl_g_ctrl(sd->contrast)); |
Jean-Francois Moine | 5b7ed28 | 2008-12-18 12:38:15 -0300 | [diff] [blame] | 632 | /* setbrightness(gspca_dev); * fixme: bad values */ |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 633 | setautogain(gspca_dev, v4l2_ctrl_g_ctrl(sd->autogain)); |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 634 | reg_w_val(gspca_dev, 0x8112, 0x10 | 0x20); |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 635 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 639 | { |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 640 | struct sd *sd = (struct sd *) gspca_dev; |
| 641 | |
| 642 | if (sd->chip_revision == Rev012A) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 643 | reg_w_val(gspca_dev, 0x8112, 0x0e); |
Hans de Goede | 6b33e5e | 2010-02-27 07:18:14 -0300 | [diff] [blame] | 644 | /* Led Off (bit 3 -> 1 */ |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 645 | reg_w_val(gspca_dev, 0x8114, 0x08); |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 646 | } else { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 647 | reg_w_val(gspca_dev, 0x8112, 0x20); |
| 648 | /* reg_w_val(gspca_dev, 0x8102, 0x00); ?? */ |
Jean-Francois Moine | d698dc6 | 2008-09-03 16:47:51 -0300 | [diff] [blame] | 649 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 650 | } |
| 651 | |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 652 | static void do_autogain(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 653 | { |
| 654 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 655 | int expotimes; |
| 656 | int pixelclk; |
| 657 | int gainG; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 658 | __u8 R, Gr, Gb, B; |
| 659 | int y; |
| 660 | __u8 luma_mean = 110; |
| 661 | __u8 luma_delta = 20; |
| 662 | __u8 spring = 4; |
| 663 | |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 664 | if (sd->ag_cnt < 0) |
| 665 | return; |
| 666 | if (--sd->ag_cnt >= 0) |
| 667 | return; |
| 668 | sd->ag_cnt = AG_CNT_START; |
| 669 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 670 | switch (sd->chip_revision) { |
| 671 | case Rev072A: |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 672 | reg_r(gspca_dev, 0x8621, 1); |
| 673 | Gr = gspca_dev->usb_buf[0]; |
| 674 | reg_r(gspca_dev, 0x8622, 1); |
| 675 | R = gspca_dev->usb_buf[0]; |
| 676 | reg_r(gspca_dev, 0x8623, 1); |
| 677 | B = gspca_dev->usb_buf[0]; |
| 678 | reg_r(gspca_dev, 0x8624, 1); |
| 679 | Gb = gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 680 | y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8; |
| 681 | /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */ |
| 682 | /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 683 | |
| 684 | if (y < luma_mean - luma_delta || |
| 685 | y > luma_mean + luma_delta) { |
| 686 | expotimes = i2c_read(gspca_dev, 0x09, 0x10); |
| 687 | pixelclk = 0x0800; |
| 688 | expotimes = expotimes & 0x07ff; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 689 | gainG = i2c_read(gspca_dev, 0x35, 0x10); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 690 | |
| 691 | expotimes += (luma_mean - y) >> spring; |
| 692 | gainG += (luma_mean - y) / 50; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 693 | |
| 694 | if (gainG > 0x3f) |
| 695 | gainG = 0x3f; |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 696 | else if (gainG < 3) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 697 | gainG = 3; |
| 698 | i2c_write(gspca_dev, gainG, 0x35); |
| 699 | |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 700 | if (expotimes > 0x0256) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 701 | expotimes = 0x0256; |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 702 | else if (expotimes < 3) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 703 | expotimes = 3; |
| 704 | i2c_write(gspca_dev, expotimes | pixelclk, 0x09); |
| 705 | } |
| 706 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
| 710 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 711 | u8 *data, /* isoc packet */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 712 | int len) /* iso packet length */ |
| 713 | { |
Hans de Goede | 0fc23d2 | 2008-09-04 16:22:57 -0300 | [diff] [blame] | 714 | struct sd *sd = (struct sd *) gspca_dev; |
| 715 | |
Jean-Francois Moine | 576ed7b | 2009-01-16 08:57:28 -0300 | [diff] [blame] | 716 | len--; |
| 717 | switch (*data++) { /* sequence number */ |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 718 | case 0: /* start of frame */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 719 | gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); |
Hans de Goede | 436c2c5 | 2010-02-28 09:41:04 -0300 | [diff] [blame] | 720 | |
| 721 | /* This should never happen */ |
| 722 | if (len < 2) { |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 723 | gspca_err(gspca_dev, "Short SOF packet, ignoring\n\n\n\n\n"); |
Hans de Goede | 436c2c5 | 2010-02-28 09:41:04 -0300 | [diff] [blame] | 724 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 725 | return; |
| 726 | } |
| 727 | |
Peter Senna Tschudin | 60d2156 | 2013-01-24 19:29:09 -0300 | [diff] [blame] | 728 | #if IS_ENABLED(CONFIG_INPUT) |
Hans de Goede | 436c2c5 | 2010-02-28 09:41:04 -0300 | [diff] [blame] | 729 | if (data[0] & 0x20) { |
| 730 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); |
| 731 | input_sync(gspca_dev->input_dev); |
| 732 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); |
| 733 | input_sync(gspca_dev->input_dev); |
| 734 | } |
| 735 | #endif |
| 736 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 737 | if (data[1] & 0x10) { |
| 738 | /* compressed bayer */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 739 | gspca_frame_add(gspca_dev, FIRST_PACKET, data, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 740 | } else { |
Hans de Goede | 54ab92c | 2008-07-03 11:20:58 -0300 | [diff] [blame] | 741 | /* raw bayer (with a header, which we skip) */ |
Hans de Goede | 0fc23d2 | 2008-09-04 16:22:57 -0300 | [diff] [blame] | 742 | if (sd->chip_revision == Rev012A) { |
| 743 | data += 20; |
| 744 | len -= 20; |
| 745 | } else { |
| 746 | data += 16; |
| 747 | len -= 16; |
| 748 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 749 | gspca_frame_add(gspca_dev, FIRST_PACKET, data, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 750 | } |
| 751 | return; |
Jean-Francois Moine | 35dc1b4 | 2008-12-17 14:34:53 -0300 | [diff] [blame] | 752 | case 0xff: /* drop (empty mpackets) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 753 | return; |
| 754 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 755 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 756 | } |
| 757 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 758 | static int sd_s_ctrl(struct v4l2_ctrl *ctrl) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 759 | { |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 760 | struct gspca_dev *gspca_dev = |
| 761 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); |
| 762 | struct sd *sd = (struct sd *)gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 763 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 764 | gspca_dev->usb_err = 0; |
| 765 | |
| 766 | if (!gspca_dev->streaming) |
| 767 | return 0; |
| 768 | |
| 769 | switch (ctrl->id) { |
| 770 | case V4L2_CID_BRIGHTNESS: |
| 771 | setbrightness(gspca_dev, ctrl->val); |
| 772 | break; |
| 773 | case V4L2_CID_CONTRAST: |
| 774 | /* hue/contrast control cluster for 72a */ |
| 775 | setwhite(gspca_dev, sd->hue->val, ctrl->val); |
| 776 | break; |
| 777 | case V4L2_CID_HUE: |
| 778 | /* just plain hue control for 12a */ |
| 779 | setwhite(gspca_dev, ctrl->val, 0); |
| 780 | break; |
| 781 | case V4L2_CID_EXPOSURE: |
| 782 | setexposure(gspca_dev, ctrl->val); |
| 783 | break; |
| 784 | case V4L2_CID_GAIN: |
| 785 | setgain(gspca_dev, ctrl->val); |
| 786 | break; |
| 787 | case V4L2_CID_AUTOGAIN: |
| 788 | setautogain(gspca_dev, ctrl->val); |
| 789 | break; |
| 790 | } |
| 791 | return gspca_dev->usb_err; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 792 | } |
| 793 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 794 | static const struct v4l2_ctrl_ops sd_ctrl_ops = { |
| 795 | .s_ctrl = sd_s_ctrl, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 796 | }; |
| 797 | |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 798 | static int sd_init_controls_12a(struct gspca_dev *gspca_dev) |
| 799 | { |
| 800 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
| 801 | |
| 802 | gspca_dev->vdev.ctrl_handler = hdl; |
| 803 | v4l2_ctrl_handler_init(hdl, 3); |
| 804 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 805 | V4L2_CID_HUE, 1, 0x7f, 1, 0x40); |
| 806 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
Hans de Goede | a8931d5 | 2012-07-02 15:29:56 -0300 | [diff] [blame] | 807 | V4L2_CID_BRIGHTNESS, -128, 127, 1, 0); |
| 808 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 809 | V4L2_CID_EXPOSURE, 1, EXPOSURE_MAX, 1, 700); |
| 810 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 811 | V4L2_CID_GAIN, 0, 255, 1, 63); |
| 812 | |
| 813 | if (hdl->error) { |
| 814 | pr_err("Could not initialize controls\n"); |
| 815 | return hdl->error; |
| 816 | } |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | static int sd_init_controls_72a(struct gspca_dev *gspca_dev) |
| 821 | { |
| 822 | struct sd *sd = (struct sd *)gspca_dev; |
| 823 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
| 824 | |
| 825 | gspca_dev->vdev.ctrl_handler = hdl; |
| 826 | v4l2_ctrl_handler_init(hdl, 4); |
| 827 | sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 828 | V4L2_CID_CONTRAST, 0, 0x3f, 1, 0x20); |
| 829 | sd->hue = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 830 | V4L2_CID_HUE, 1, 0x7f, 1, 0x40); |
| 831 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 832 | V4L2_CID_BRIGHTNESS, 0, 0x3f, 1, 0x20); |
| 833 | sd->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 834 | V4L2_CID_AUTOGAIN, 0, 1, 1, 1); |
| 835 | |
| 836 | if (hdl->error) { |
| 837 | pr_err("Could not initialize controls\n"); |
| 838 | return hdl->error; |
| 839 | } |
| 840 | v4l2_ctrl_cluster(2, &sd->contrast); |
| 841 | return 0; |
| 842 | } |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 843 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 844 | /* sub-driver description */ |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 845 | static const struct sd_desc sd_desc_12a = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 846 | .name = MODULE_NAME, |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 847 | .init_controls = sd_init_controls_12a, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 848 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 849 | .init = sd_init_12a, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 850 | .start = sd_start_12a, |
| 851 | .stopN = sd_stopN, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 852 | .pkt_scan = sd_pkt_scan, |
Peter Senna Tschudin | 60d2156 | 2013-01-24 19:29:09 -0300 | [diff] [blame] | 853 | #if IS_ENABLED(CONFIG_INPUT) |
Hans de Goede | 436c2c5 | 2010-02-28 09:41:04 -0300 | [diff] [blame] | 854 | .other_input = 1, |
| 855 | #endif |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 856 | }; |
| 857 | static const struct sd_desc sd_desc_72a = { |
| 858 | .name = MODULE_NAME, |
Hans Verkuil | 3fa24bf | 2012-05-16 08:20:44 -0300 | [diff] [blame] | 859 | .init_controls = sd_init_controls_72a, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 860 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 861 | .init = sd_init_72a, |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 862 | .start = sd_start_72a, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 863 | .stopN = sd_stopN, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 864 | .pkt_scan = sd_pkt_scan, |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 865 | .dq_callback = do_autogain, |
Peter Senna Tschudin | 60d2156 | 2013-01-24 19:29:09 -0300 | [diff] [blame] | 866 | #if IS_ENABLED(CONFIG_INPUT) |
Hans de Goede | 436c2c5 | 2010-02-28 09:41:04 -0300 | [diff] [blame] | 867 | .other_input = 1, |
| 868 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 869 | }; |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 870 | static const struct sd_desc *sd_desc[2] = { |
| 871 | &sd_desc_12a, |
| 872 | &sd_desc_72a |
| 873 | }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 874 | |
| 875 | /* -- module initialisation -- */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 876 | static const struct usb_device_id device_table[] = { |
Jean-Francois Moine | 87581aa | 2008-07-26 14:30:01 -0300 | [diff] [blame] | 877 | {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A}, |
| 878 | {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A}, |
| 879 | {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A}, |
John Ellson | f8f73d0 | 2010-03-17 10:22:58 -0300 | [diff] [blame] | 880 | {USB_DEVICE(0x0461, 0x0815), .driver_info = Rev072A}, |
Jean-Francois Moine | 87581aa | 2008-07-26 14:30:01 -0300 | [diff] [blame] | 881 | {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A}, |
| 882 | {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A}, |
| 883 | {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A}, |
| 884 | {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A}, |
| 885 | {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A}, |
| 886 | {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A}, |
| 887 | {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A}, |
| 888 | {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A}, |
| 889 | {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A}, |
| 890 | {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A}, |
| 891 | {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A}, |
| 892 | {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 893 | {} |
| 894 | }; |
| 895 | |
| 896 | MODULE_DEVICE_TABLE(usb, device_table); |
| 897 | |
| 898 | /* -- device connect -- */ |
| 899 | static int sd_probe(struct usb_interface *intf, |
| 900 | const struct usb_device_id *id) |
| 901 | { |
Jean-Francois Moine | 7879d45 | 2008-09-03 16:47:32 -0300 | [diff] [blame] | 902 | return gspca_dev_probe(intf, id, |
| 903 | sd_desc[id->driver_info], |
| 904 | sizeof(struct sd), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 905 | THIS_MODULE); |
| 906 | } |
| 907 | |
| 908 | static struct usb_driver sd_driver = { |
| 909 | .name = MODULE_NAME, |
| 910 | .id_table = device_table, |
| 911 | .probe = sd_probe, |
| 912 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 913 | #ifdef CONFIG_PM |
| 914 | .suspend = gspca_suspend, |
| 915 | .resume = gspca_resume, |
Hans de Goede | 8bb5896 | 2012-06-30 06:44:47 -0300 | [diff] [blame] | 916 | .reset_resume = gspca_resume, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 917 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 918 | }; |
| 919 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 920 | module_usb_driver(sd_driver); |