4 * Copyright (C) 2010 Jean-François Moine <http://moinejf.free.fr>
5 * Copyright (C) 2006 -2008 Gerard Klaver <gerard at gkall dot hobby dot nl>
6 * Copyright (C) 2007 Sam Revitch <samr7@cs.washington.edu>
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
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.
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
23 #define MODULE_NAME "sq930x"
28 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>\n"
29 "Gerard Klaver <gerard at gkall dot hobby dot nl\n"
30 "Sam Revitch <samr7@cs.washington.edu>");
31 MODULE_DESCRIPTION("GSPCA/SQ930x USB Camera Driver");
32 MODULE_LICENSE("GPL");
34 #define BULK_TRANSFER_LEN 5128
36 /* Structure to hold all of our device specific stuff */
38 struct gspca_dev gspca_dev; /* !! must be the first item */
43 u8 quality; /* webcam quality 0..3 */
62 #define Creative_live_motion 1
64 u8 jpeg_hdr[JPEG_HDR_SZ];
67 static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val);
68 static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val);
69 static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
70 static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
72 static const struct ctrl sd_ctrls[] = {
75 .id = V4L2_CID_EXPOSURE,
76 .type = V4L2_CTRL_TYPE_INTEGER,
81 #define EXPO_DEF 0x027d
82 .default_value = EXPO_DEF,
90 .type = V4L2_CTRL_TYPE_INTEGER,
96 .default_value = GAIN_DEF,
103 static struct v4l2_pix_format vga_mode[] = {
104 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
106 .sizeimage = 160 * 120 * 5 / 8 + 590,
107 .colorspace = V4L2_COLORSPACE_JPEG,
109 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
111 .sizeimage = 320 * 240 * 4 / 8 + 590,
112 .colorspace = V4L2_COLORSPACE_JPEG,
114 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
116 .sizeimage = 640 * 480 * 3 / 8 + 590,
117 .colorspace = V4L2_COLORSPACE_JPEG,
121 /* JPEG quality indexed by webcam quality */
126 static const u8 quality_tb[4] = { QUAL_0, QUAL_1, QUAL_2, QUAL_3 };
128 /* sq930x registers */
129 #define SQ930_CTRL_UCBUS_IO 0x0001
130 #define SQ930_CTRL_I2C_IO 0x0002
131 #define SQ930_CTRL_GPIO 0x0005
132 #define SQ930_CTRL_CAP_START 0x0010
133 #define SQ930_CTRL_CAP_STOP 0x0011
134 #define SQ930_CTRL_SET_EXPOSURE 0x001d
135 #define SQ930_CTRL_RESET 0x001e
136 #define SQ930_CTRL_GET_DEV_INFO 0x001f
139 #define SQ930_GPIO_DFL_I2C_SDA 0x0001
140 #define SQ930_GPIO_DFL_I2C_SCL 0x0002
141 #define SQ930_GPIO_RSTBAR 0x0004
142 #define SQ930_GPIO_EXTRA1 0x0040
143 #define SQ930_GPIO_EXTRA2 0x0080
144 /* gpio 3 (24..31) */
145 #define SQ930_GPIO_POWER 0x0200
146 #define SQ930_GPIO_DFL_LED 0x1000
148 struct ucbus_write_cmd {
152 struct i2c_write_cmd {
157 static const struct ucbus_write_cmd icx098bq_start_0[] = {
158 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xce},
159 {0xf802, 0xc1}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x0e},
160 {0xf80a, 0x01}, {0xf80b, 0xee}, {0xf807, 0x60}, {0xf80c, 0x02},
161 {0xf80d, 0xf0}, {0xf80e, 0x03}, {0xf80f, 0x0a}, {0xf81c, 0x02},
162 {0xf81d, 0xf0}, {0xf81e, 0x03}, {0xf81f, 0x0a}, {0xf83a, 0x00},
163 {0xf83b, 0x10}, {0xf83c, 0x00}, {0xf83d, 0x4e}, {0xf810, 0x04},
164 {0xf811, 0x00}, {0xf812, 0x02}, {0xf813, 0x10}, {0xf803, 0x00},
165 {0xf814, 0x01}, {0xf815, 0x18}, {0xf816, 0x00}, {0xf817, 0x48},
166 {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
167 {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
168 {0xf823, 0x07}, {0xf824, 0xff}, {0xf825, 0x03}, {0xf826, 0xff},
169 {0xf827, 0x06}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
170 {0xf82b, 0x0c}, {0xf82c, 0xfd}, {0xf82d, 0x01}, {0xf82e, 0x00},
171 {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
172 {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
173 {0xf854, 0x00}, {0xf855, 0x18}, {0xf856, 0x00}, {0xf857, 0x3c},
174 {0xf858, 0x00}, {0xf859, 0x0c}, {0xf85a, 0x00}, {0xf85b, 0x30},
175 {0xf85c, 0x00}, {0xf85d, 0x0c}, {0xf85e, 0x00}, {0xf85f, 0x30},
176 {0xf860, 0x00}, {0xf861, 0x48}, {0xf862, 0x01}, {0xf863, 0xdc},
177 {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
178 {0xf868, 0xff}, {0xf869, 0x70}, {0xf86c, 0xff}, {0xf86d, 0x00},
179 {0xf86a, 0xff}, {0xf86b, 0x48}, {0xf86e, 0xff}, {0xf86f, 0x00},
180 {0xf870, 0x01}, {0xf871, 0xdb}, {0xf872, 0x01}, {0xf873, 0xfa},
181 {0xf874, 0x01}, {0xf875, 0xdb}, {0xf876, 0x01}, {0xf877, 0xfa},
182 {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
185 static const struct ucbus_write_cmd icx098bq_start_1[] = {
186 {0xf5f0, 0x00}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
188 {0xf5f0, 0x49}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
190 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
194 static const struct ucbus_write_cmd icx098bq_start_2[] = {
195 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x82}, {0xf806, 0x00},
196 {0xf807, 0x7f}, {0xf800, 0x03},
197 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x40}, {0xf806, 0x00},
198 {0xf807, 0x7f}, {0xf800, 0x03},
199 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xcf}, {0xf806, 0xd0},
200 {0xf807, 0x7f}, {0xf800, 0x03},
201 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
202 {0xf807, 0x7f}, {0xf800, 0x03}
205 static const struct ucbus_write_cmd lz24bp_start_0[] = {
206 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xbe},
207 {0xf802, 0xc6}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x06},
208 {0xf80a, 0x01}, {0xf80b, 0xfe}, {0xf807, 0x84}, {0xf80c, 0x02},
209 {0xf80d, 0xf7}, {0xf80e, 0x03}, {0xf80f, 0x0b}, {0xf81c, 0x00},
210 {0xf81d, 0x49}, {0xf81e, 0x03}, {0xf81f, 0x0b}, {0xf83a, 0x00},
211 {0xf83b, 0x01}, {0xf83c, 0x00}, {0xf83d, 0x6b}, {0xf810, 0x03},
212 {0xf811, 0x10}, {0xf812, 0x02}, {0xf813, 0x6f}, {0xf803, 0x00},
213 {0xf814, 0x00}, {0xf815, 0x44}, {0xf816, 0x00}, {0xf817, 0x48},
214 {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
215 {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
216 {0xf823, 0x07}, {0xf824, 0xfd}, {0xf825, 0x07}, {0xf826, 0xf0},
217 {0xf827, 0x0c}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
218 {0xf82b, 0x0c}, {0xf82c, 0xfc}, {0xf82d, 0x01}, {0xf82e, 0x00},
219 {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
220 {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
221 {0xf854, 0x00}, {0xf855, 0x0c}, {0xf856, 0x00}, {0xf857, 0x30},
222 {0xf858, 0x00}, {0xf859, 0x18}, {0xf85a, 0x00}, {0xf85b, 0x3c},
223 {0xf85c, 0x00}, {0xf85d, 0x18}, {0xf85e, 0x00}, {0xf85f, 0x3c},
224 {0xf860, 0xff}, {0xf861, 0x37}, {0xf862, 0xff}, {0xf863, 0x1d},
225 {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
226 {0xf868, 0x00}, {0xf869, 0x37}, {0xf86c, 0x02}, {0xf86d, 0x1d},
227 {0xf86a, 0x00}, {0xf86b, 0x37}, {0xf86e, 0x02}, {0xf86f, 0x1d},
228 {0xf870, 0x01}, {0xf871, 0xc6}, {0xf872, 0x02}, {0xf873, 0x04},
229 {0xf874, 0x01}, {0xf875, 0xc6}, {0xf876, 0x02}, {0xf877, 0x04},
230 {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
233 static const struct ucbus_write_cmd lz24bp_start_1_gen[] = {
234 {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
236 {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
238 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
242 static const struct ucbus_write_cmd lz24bp_start_1_clm[] = {
243 {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
245 {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
247 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
251 static const struct ucbus_write_cmd lz24bp_start_2[] = {
252 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x80}, {0xf806, 0x00},
253 {0xf807, 0x7f}, {0xf800, 0x03},
254 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x4e}, {0xf806, 0x00},
255 {0xf807, 0x7f}, {0xf800, 0x03},
256 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xc0}, {0xf806, 0x48},
257 {0xf807, 0x7f}, {0xf800, 0x03},
258 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
259 {0xf807, 0x7f}, {0xf800, 0x03}
262 static const struct ucbus_write_cmd mi0360_start_0[] = {
263 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0xcc}, {0xf333, 0xcc},
264 {0xf334, 0xcc}, {0xf335, 0xcc}, {0xf33f, 0x00}
266 static const struct i2c_write_cmd mi0360_init_23[] = {
267 {0x30, 0x0040}, /* reserved - def 0x0005 */
268 {0x31, 0x0000}, /* reserved - def 0x002a */
269 {0x34, 0x0100}, /* reserved - def 0x0100 */
270 {0x3d, 0x068f}, /* reserved - def 0x068f */
272 static const struct i2c_write_cmd mi0360_init_24[] = {
273 {0x03, 0x01e5}, /* window height */
274 {0x04, 0x0285}, /* window width */
276 static const struct i2c_write_cmd mi0360_init_25[] = {
277 {0x35, 0x0020}, /* global gain */
278 {0x2b, 0x0020}, /* green1 gain */
279 {0x2c, 0x002a}, /* blue gain */
280 {0x2d, 0x0028}, /* red gain */
281 {0x2e, 0x0020}, /* green2 gain */
283 static const struct ucbus_write_cmd mi0360_start_1[] = {
284 {0xf5f0, 0x11}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
286 {0xf5f0, 0x51}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
288 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
291 static const struct i2c_write_cmd mi0360_start_2[] = {
292 {0x62, 0x041d}, /* reserved - def 0x0418 */
294 static const struct i2c_write_cmd mi0360_start_3[] = {
295 {0x05, 0x007b}, /* horiz blanking */
297 static const struct i2c_write_cmd mi0360_start_4[] = {
298 {0x05, 0x03f5}, /* horiz blanking */
301 static const struct i2c_write_cmd mt9v111_init_0[] = {
302 {0x01, 0x0001}, /* select IFP/SOC registers */
303 {0x06, 0x300c}, /* operating mode control */
304 {0x08, 0xcc00}, /* output format control (RGB) */
305 {0x01, 0x0004}, /* select core registers */
307 static const struct i2c_write_cmd mt9v111_init_1[] = {
308 {0x03, 0x01e5}, /* window height */
309 {0x04, 0x0285}, /* window width */
311 static const struct i2c_write_cmd mt9v111_init_2[] = {
314 {0x07, 0x3002}, /* output control */
315 {0x35, 0x0020}, /* global gain */
316 {0x2b, 0x0020}, /* green1 gain */
317 {0x2c, 0x0020}, /* blue gain */
318 {0x2d, 0x0020}, /* red gain */
319 {0x2e, 0x0020}, /* green2 gain */
321 static const struct ucbus_write_cmd mt9v111_start_1[] = {
322 {0xf5f0, 0x11}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
324 {0xf5f0, 0x51}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
326 {0xf5fa, 0x00}, {0xf5f6, 0x0a}, {0xf5f7, 0x0a}, {0xf5f8, 0x0a},
329 static const struct i2c_write_cmd mt9v111_init_3[] = {
332 static const struct i2c_write_cmd mt9v111_init_4[] = {
333 {0x05, 0x00ce}, /* horizontal blanking */
336 static const struct ucbus_write_cmd ov7660_start_0[] = {
337 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0xc0},
338 {0xf334, 0x39}, {0xf335, 0xe7}, {0xf33f, 0x03}
341 static const struct ucbus_write_cmd ov9630_start_0[] = {
342 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0x00},
343 {0xf334, 0x3e}, {0xf335, 0xf8}, {0xf33f, 0x03}
346 static const struct cap_s {
349 } capconfig[4][3] = {
350 [SENSOR_ICX098BQ] = {
351 {0, /* JPEG, 160x120 */
352 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
353 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
354 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41,
355 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} },
356 {2, /* JPEG, 320x240 */
357 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
358 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
359 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
360 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
361 {4, /* JPEG, 640x480 */
362 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
363 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
364 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
365 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
368 {0, /* JPEG, 160x120 */
369 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
370 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
371 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41,
372 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} },
373 {2, /* JPEG, 320x240 */
374 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee,
375 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
376 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
377 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
378 {4, /* JPEG, 640x480 */
379 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
380 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
381 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
382 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
385 {0, /* JPEG, 160x120 */
386 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b,
387 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
388 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f,
389 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} },
390 {2, /* JPEG, 320x240 */
391 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
393 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
394 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
395 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
396 {4, /* JPEG, 640x480 */
397 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe3,
398 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
399 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
400 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
403 {0, /* JPEG, 160x120 */
404 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b,
405 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
406 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f,
407 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} },
408 {2, /* JPEG, 320x240 */
409 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3,
410 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
411 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
412 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
413 {4, /* JPEG, 640x480 */
414 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3,
415 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
416 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
417 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
427 const struct ucbus_write_cmd *cmd;
430 static const struct sensor_s sensor_tb[] = {
431 [SENSOR_ICX098BQ] = {
435 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
436 SQ930_GPIO_DFL_I2C_SDA,
446 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
447 SQ930_GPIO_DFL_I2C_SDA,
457 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
458 SQ930_GPIO_DFL_I2C_SDA,
468 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
469 SQ930_GPIO_DFL_I2C_SDA,
479 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
480 SQ930_GPIO_DFL_I2C_SDA,
490 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
491 SQ930_GPIO_DFL_I2C_SDA,
499 static void reg_r(struct gspca_dev *gspca_dev,
504 if (gspca_dev->usb_err < 0)
506 ret = usb_control_msg(gspca_dev->dev,
507 usb_rcvctrlpipe(gspca_dev->dev, 0),
509 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
510 value, 0, gspca_dev->usb_buf, len,
513 PDEBUG(D_ERR, "reg_r %04x failed %d", value, ret);
514 gspca_dev->usb_err = ret;
518 static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index)
522 if (gspca_dev->usb_err < 0)
524 PDEBUG(D_USBO, "reg_w v: %04x i: %04x", value, index);
525 ret = usb_control_msg(gspca_dev->dev,
526 usb_sndctrlpipe(gspca_dev->dev, 0),
528 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
529 value, index, NULL, 0,
533 PDEBUG(D_ERR, "reg_w %04x %04x failed %d", value, index, ret);
534 gspca_dev->usb_err = ret;
538 static void reg_wb(struct gspca_dev *gspca_dev, u16 value, u16 index,
539 const u8 *data, int len)
543 if (gspca_dev->usb_err < 0)
545 PDEBUG(D_USBO, "reg_wb v: %04x i: %04x %02x...%02x",
546 value, index, *data, data[len - 1]);
547 memcpy(gspca_dev->usb_buf, data, len);
548 ret = usb_control_msg(gspca_dev->dev,
549 usb_sndctrlpipe(gspca_dev->dev, 0),
551 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
552 value, index, gspca_dev->usb_buf, len,
556 PDEBUG(D_ERR, "reg_wb %04x %04x failed %d", value, index, ret);
557 gspca_dev->usb_err = ret;
561 static void i2c_write(struct sd *sd,
562 const struct i2c_write_cmd *cmd,
565 struct gspca_dev *gspca_dev = &sd->gspca_dev;
566 const struct sensor_s *sensor;
571 if (gspca_dev->usb_err < 0)
574 sensor = &sensor_tb[sd->sensor];
576 val = (sensor->i2c_addr << 8) | SQ930_CTRL_I2C_IO;
577 idx = (cmd->val & 0xff00) | cmd->reg;
579 buf = gspca_dev->usb_buf;
580 *buf++ = sensor->i2c_dum;
583 while (--ncmds > 0) {
586 *buf++ = cmd->val >> 8;
587 *buf++ = sensor->i2c_dum;
591 PDEBUG(D_USBO, "i2c_w v: %04x i: %04x %02x...%02x",
592 val, idx, gspca_dev->usb_buf[0], buf[-1]);
593 ret = usb_control_msg(gspca_dev->dev,
594 usb_sndctrlpipe(gspca_dev->dev, 0),
596 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
598 gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
601 PDEBUG(D_ERR, "i2c_write failed %d", ret);
602 gspca_dev->usb_err = ret;
606 static void ucbus_write(struct gspca_dev *gspca_dev,
607 const struct ucbus_write_cmd *cmd,
615 if (gspca_dev->usb_err < 0)
619 if ((batchsize - 1) * 3 > USB_BUF_SZ) {
620 err("Bug: usb_buf overflow");
621 gspca_dev->usb_err = -ENOMEM;
632 val = (cmd->bw_addr << 8) | SQ930_CTRL_UCBUS_IO;
633 idx = (cmd->bw_data << 8) | (cmd->bw_addr >> 8);
635 buf = gspca_dev->usb_buf;
638 *buf++ = cmd->bw_addr;
639 *buf++ = cmd->bw_addr >> 8;
640 *buf++ = cmd->bw_data;
642 if (buf != gspca_dev->usb_buf)
643 PDEBUG(D_USBO, "ucbus v: %04x i: %04x %02x...%02x",
645 gspca_dev->usb_buf[0], buf[-1]);
647 PDEBUG(D_USBO, "ucbus v: %04x i: %04x",
649 ret = usb_control_msg(gspca_dev->dev,
650 usb_sndctrlpipe(gspca_dev->dev, 0),
652 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
654 gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
657 PDEBUG(D_ERR, "ucbus_write failed %d", ret);
658 gspca_dev->usb_err = ret;
668 static void gpio_set(struct sd *sd, u16 val, u16 mask)
670 struct gspca_dev *gspca_dev = &sd->gspca_dev;
673 sd->gpio[0] &= ~mask;
675 reg_w(gspca_dev, 0x0100 | SQ930_CTRL_GPIO,
681 sd->gpio[1] &= ~mask;
683 reg_w(gspca_dev, 0x0300 | SQ930_CTRL_GPIO,
688 static void gpio_init(struct sd *sd,
691 gpio_set(sd, *gpio++, 0x000f);
692 gpio_set(sd, *gpio++, 0x000f);
693 gpio_set(sd, *gpio++, 0x000f);
694 gpio_set(sd, *gpio++, 0x000f);
695 gpio_set(sd, *gpio, 0x000f);
698 static void bridge_init(struct sd *sd)
700 static const struct ucbus_write_cmd clkfreq_cmd = {
701 0xf031, 0 /* SQ930_CLKFREQ_60MHZ */
704 ucbus_write(&sd->gspca_dev, &clkfreq_cmd, 1, 1);
706 gpio_set(sd, SQ930_GPIO_POWER, 0xff00);
709 static void cmos_probe(struct gspca_dev *gspca_dev)
711 struct sd *sd = (struct sd *) gspca_dev;
713 const struct sensor_s *sensor;
714 static const u8 probe_order[] = {
715 /* SENSOR_LZ24BP, (tested as ccd) */
722 for (i = 0; i < ARRAY_SIZE(probe_order); i++) {
723 sensor = &sensor_tb[probe_order[i]];
724 ucbus_write(&sd->gspca_dev, sensor->cmd, sensor->cmd_len, 8);
725 gpio_init(sd, sensor->gpio);
727 reg_r(gspca_dev, (sensor->i2c_addr << 8) | 0x001c, 1);
729 if (gspca_dev->usb_buf[0] != 0)
732 if (i >= ARRAY_SIZE(probe_order))
733 PDEBUG(D_PROBE, "Unknown sensor");
735 sd->sensor = probe_order[i];
738 static void mt9v111_init(struct gspca_dev *gspca_dev)
741 static const u8 cmd_001b[] = {
742 0x00, 0x3b, 0xf6, 0x01, 0x03, 0x02, 0x00, 0x00,
745 static const u8 cmd_011b[][7] = {
746 {0x10, 0x01, 0x66, 0x08, 0x00, 0x00, 0x00},
747 {0x01, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x00},
748 {0x20, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00},
749 {0x02, 0x01, 0xae, 0x01, 0x00, 0x00, 0x00},
752 reg_wb(gspca_dev, 0x001b, 0x0000, cmd_001b, sizeof cmd_001b);
753 for (i = 0; i < ARRAY_SIZE(cmd_011b); i++) {
754 reg_wb(gspca_dev, 0x001b, 0x0000, cmd_011b[i],
755 ARRAY_SIZE(cmd_011b[0]));
759 reg_r(gspca_dev, 0x031b, 1);
760 if (gspca_dev->usb_buf[0] == 0
761 || gspca_dev->usb_err != 0)
764 PDEBUG(D_PROBE, "mt9v111_init timeout");
765 gspca_dev->usb_err = -ETIME;
773 static void global_init(struct sd *sd, int first_time)
775 switch (sd->sensor) {
776 case SENSOR_ICX098BQ:
778 ucbus_write(&sd->gspca_dev,
781 gpio_init(sd, sensor_tb[sd->sensor].gpio);
784 if (sd->type != Creative_live_motion)
785 gpio_set(sd, SQ930_GPIO_EXTRA1, 0x00ff);
787 gpio_set(sd, 0, 0x00ff);
790 ucbus_write(&sd->gspca_dev,
793 gpio_init(sd, sensor_tb[sd->sensor].gpio);
797 ucbus_write(&sd->gspca_dev,
799 ARRAY_SIZE(mi0360_start_0),
801 gpio_init(sd, sensor_tb[sd->sensor].gpio);
802 gpio_set(sd, SQ930_GPIO_EXTRA2, SQ930_GPIO_EXTRA2);
805 /* case SENSOR_MT9V111: */
807 mt9v111_init(&sd->gspca_dev);
809 gpio_init(sd, sensor_tb[sd->sensor].gpio);
814 static void lz24bp_ppl(struct sd *sd, u16 ppl)
816 struct ucbus_write_cmd cmds[2] = {
821 ucbus_write(&sd->gspca_dev, cmds, ARRAY_SIZE(cmds), 2);
824 static void setexposure(struct gspca_dev *gspca_dev)
826 struct sd *sd = (struct sd *) gspca_dev;
827 int i, integclks, intstartclk, frameclks, min_frclk;
828 const struct sensor_s *sensor;
832 integclks = sd->expo;
834 cmd = SQ930_CTRL_SET_EXPOSURE;
836 switch (sd->sensor) {
837 case SENSOR_ICX098BQ: /* ccd */
839 min_frclk = sd->sensor == SENSOR_ICX098BQ ? 0x210 : 0x26f;
840 if (integclks >= min_frclk) {
842 frameclks = integclks;
844 intstartclk = min_frclk - integclks;
845 frameclks = min_frclk;
847 buf[i++] = intstartclk >> 8;
848 buf[i++] = intstartclk;
849 buf[i++] = frameclks >> 8;
850 buf[i++] = frameclks;
854 /* case SENSOR_MI0360: */
855 /* case SENSOR_MT9V111: */
857 sensor = &sensor_tb[sd->sensor];
858 buf[i++] = sensor->i2c_addr; /* i2c_slave_addr */
859 buf[i++] = 0x08; /* 2 * ni2c */
860 buf[i++] = 0x09; /* reg = shutter width */
861 buf[i++] = integclks >> 8; /* val H */
862 buf[i++] = sensor->i2c_dum;
863 buf[i++] = integclks; /* val L */
864 buf[i++] = 0x35; /* reg = global gain */
865 buf[i++] = 0x00; /* val H */
866 buf[i++] = sensor->i2c_dum;
867 buf[i++] = sd->gain; /* val L */
875 reg_wb(gspca_dev, cmd, 0, buf, i);
878 /* This function is called at probe time just before sd_init */
879 static int sd_config(struct gspca_dev *gspca_dev,
880 const struct usb_device_id *id)
882 struct sd *sd = (struct sd *) gspca_dev;
883 struct cam *cam = &gspca_dev->cam;
885 sd->sensor = id->driver_info >> 8;
886 sd->type = id->driver_info;
888 cam->cam_mode = vga_mode;
889 cam->nmodes = ARRAY_SIZE(vga_mode);
892 cam->bulk_size = BULK_TRANSFER_LEN;
893 /* cam->bulk_nurbs = 2; fixme: if no setexpo sync */
895 sd->quality = QUALITY_DEF;
902 /* this function is called at probe and resume time */
903 static int sd_init(struct gspca_dev *gspca_dev)
905 struct sd *sd = (struct sd *) gspca_dev;
907 sd->gpio[0] = sd->gpio[1] = 0xff; /* force gpio rewrite */
909 /*fixme: is this needed for icx098bp and mi0360?
910 if (sd->sensor != SENSOR_LZ24BP)
911 reg_w(gspca_dev, SQ930_CTRL_RESET, 0x0000);
914 reg_r(gspca_dev, SQ930_CTRL_GET_DEV_INFO, 8);
916 * 03 00 12 93 0b f6 c9 00 live! ultra
917 * 03 00 07 93 0b f6 ca 00 live! ultra for notebook
918 * 03 00 12 93 0b fe c8 00 Trust WB-3500T
919 * 02 00 06 93 0b fe c8 00 Joy-IT 318S
920 * 03 00 12 93 0b f6 cf 00 icam tracer - sensor icx098bq
921 * 02 00 12 93 0b fe cf 00 ProQ Motion Webcam
924 * 0: 02 = usb 1.0 (12Mbit) / 03 = usb2.0 (480Mbit)
926 * 2: 06 / 07 / 12 = mode webcam? firmware??
927 * 3: 93 chip = 930b (930b or 930c)
929 * 5: f6 = cdd (icx098bq, lz24bp) / fe or de = cmos (i2c) (other sensors)
930 * 6: c8 / c9 / ca / cf = mode webcam?, sensor? webcam?
933 PDEBUG(D_PROBE, "info: %02x %02x %02x %02x %02x %02x %02x %02x",
934 gspca_dev->usb_buf[0],
935 gspca_dev->usb_buf[1],
936 gspca_dev->usb_buf[2],
937 gspca_dev->usb_buf[3],
938 gspca_dev->usb_buf[4],
939 gspca_dev->usb_buf[5],
940 gspca_dev->usb_buf[6],
941 gspca_dev->usb_buf[7]);
945 if (sd->sensor == SENSOR_MI0360) {
947 /* no sensor probe for icam tracer */
948 if (gspca_dev->usb_buf[5] == 0xf6) { /* if CMOS */
949 sd->sensor = SENSOR_ICX098BQ;
950 gspca_dev->cam.cam_mode = &vga_mode[1];
951 gspca_dev->cam.nmodes = 1; /* only 320x240 */
953 cmos_probe(gspca_dev);
957 PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name);
960 return gspca_dev->usb_err;
963 /* special function to create the quantization tables of the JPEG header */
964 static void sd_jpeg_set_qual(u8 *jpeg_hdr,
969 quality = quality_tb[quality]; /* convert to JPEG quality */
971 * approximative qualities for Y and U/V:
972 * quant = 0:94%/91% 1:91%/87% 2:82%/73% 3:69%/56%
974 * quant = 0:94%/91% 1:91%/87.5% 2:81.5%/72% 3:69%/54.5%
976 sc1 = 200 - quality * 2;
977 quality = quality * 7 / 5 - 40; /* UV quality */
978 sc2 = 200 - quality * 2;
979 for (i = 0; i < 64; i++) {
980 jpeg_hdr[JPEG_QT0_OFFSET + i] =
981 (jpeg_head[JPEG_QT0_OFFSET + i] * sc1 + 50) / 100;
982 jpeg_hdr[JPEG_QT1_OFFSET + i] =
983 (jpeg_head[JPEG_QT1_OFFSET + i] * sc2 + 50) / 100;
987 /* send the start/stop commands to the webcam */
988 static void send_start(struct gspca_dev *gspca_dev)
990 struct sd *sd = (struct sd *) gspca_dev;
991 const struct cap_s *cap;
994 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
995 cap = &capconfig[sd->sensor][mode];
996 quality = sd->quality;
997 reg_wb(gspca_dev, (quality << 12)
998 | 0x0a00 /* 900 for Bayer */
999 | SQ930_CTRL_CAP_START,
1000 0x0500 /* a00 for Bayer */
1004 static void send_stop(struct gspca_dev *gspca_dev)
1006 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0);
1009 /* function called at start time before URB creation */
1010 static int sd_isoc_init(struct gspca_dev *gspca_dev)
1012 struct sd *sd = (struct sd *) gspca_dev;
1014 gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */
1019 /* start the capture */
1020 static int sd_start(struct gspca_dev *gspca_dev)
1022 struct sd *sd = (struct sd *) gspca_dev;
1025 /* initialize the JPEG header */
1026 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1027 0x21); /* JPEG 422 */
1028 sd_jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1034 switch (sd->sensor) {
1035 case SENSOR_ICX098BQ:
1036 ucbus_write(gspca_dev, icx098bq_start_0,
1037 ARRAY_SIZE(icx098bq_start_0),
1039 ucbus_write(gspca_dev, icx098bq_start_1,
1040 ARRAY_SIZE(icx098bq_start_1),
1042 ucbus_write(gspca_dev, icx098bq_start_2,
1043 ARRAY_SIZE(icx098bq_start_2),
1048 send_start(gspca_dev);
1049 gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff);
1051 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000);
1052 gpio_set(sd, 0x7f, 0x00ff);
1055 send_start(gspca_dev);
1056 gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff);
1059 ucbus_write(gspca_dev, lz24bp_start_0,
1060 ARRAY_SIZE(lz24bp_start_0),
1062 if (sd->type != Creative_live_motion)
1063 ucbus_write(gspca_dev, lz24bp_start_1_gen,
1064 ARRAY_SIZE(lz24bp_start_1_gen),
1067 ucbus_write(gspca_dev, lz24bp_start_1_clm,
1068 ARRAY_SIZE(lz24bp_start_1_clm),
1070 ucbus_write(gspca_dev, lz24bp_start_2,
1071 ARRAY_SIZE(lz24bp_start_2),
1073 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1074 lz24bp_ppl(sd, mode == 2 ? 0x0564 : 0x0310);
1078 ucbus_write(gspca_dev, mi0360_start_0,
1079 ARRAY_SIZE(mi0360_start_0),
1081 i2c_write(sd, mi0360_init_23,
1082 ARRAY_SIZE(mi0360_init_23));
1083 i2c_write(sd, mi0360_init_24,
1084 ARRAY_SIZE(mi0360_init_24));
1085 i2c_write(sd, mi0360_init_25,
1086 ARRAY_SIZE(mi0360_init_25));
1087 ucbus_write(gspca_dev, mi0360_start_1,
1088 ARRAY_SIZE(mi0360_start_1),
1090 i2c_write(sd, mi0360_start_2,
1091 ARRAY_SIZE(mi0360_start_2));
1092 i2c_write(sd, mi0360_start_3,
1093 ARRAY_SIZE(mi0360_start_3));
1096 send_start(gspca_dev);
1098 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000);
1101 mi0360_start_4, ARRAY_SIZE(mi0360_start_4));
1104 /* case SENSOR_MT9V111: */
1105 ucbus_write(gspca_dev, mi0360_start_0,
1106 ARRAY_SIZE(mi0360_start_0),
1108 i2c_write(sd, mt9v111_init_0,
1109 ARRAY_SIZE(mt9v111_init_0));
1110 i2c_write(sd, mt9v111_init_1,
1111 ARRAY_SIZE(mt9v111_init_1));
1112 i2c_write(sd, mt9v111_init_2,
1113 ARRAY_SIZE(mt9v111_init_2));
1114 ucbus_write(gspca_dev, mt9v111_start_1,
1115 ARRAY_SIZE(mt9v111_start_1),
1117 i2c_write(sd, mt9v111_init_3,
1118 ARRAY_SIZE(mt9v111_init_3));
1119 i2c_write(sd, mt9v111_init_4,
1120 ARRAY_SIZE(mt9v111_init_4));
1124 send_start(gspca_dev);
1128 sd->eof_len = 0; /* init packet scan */
1130 if (sd->sensor == SENSOR_MT9V111)
1131 gpio_set(sd, SQ930_GPIO_DFL_LED, SQ930_GPIO_DFL_LED);
1133 sd->do_ctrl = 1; /* set the exposure */
1135 return gspca_dev->usb_err;
1138 static void sd_stopN(struct gspca_dev *gspca_dev)
1140 struct sd *sd = (struct sd *) gspca_dev;
1142 if (sd->sensor == SENSOR_MT9V111)
1143 gpio_set(sd, 0, SQ930_GPIO_DFL_LED);
1144 send_stop(gspca_dev);
1147 /* function called when the application gets a new frame */
1148 /* It sets the exposure if required and restart the bulk transfer. */
1149 static void sd_dq_callback(struct gspca_dev *gspca_dev)
1151 struct sd *sd = (struct sd *) gspca_dev;
1154 if (!sd->do_ctrl || gspca_dev->cam.bulk_nurbs != 0)
1158 setexposure(gspca_dev);
1160 gspca_dev->cam.bulk_nurbs = 1;
1161 ret = usb_submit_urb(gspca_dev->urb[0], GFP_ATOMIC);
1163 PDEBUG(D_ERR|D_PACK, "sd_dq_callback() err %d", ret);
1165 /* wait a little time, otherwise the webcam crashes */
1169 /* move a packet adding 0x00 after 0xff */
1170 static void add_packet(struct gspca_dev *gspca_dev,
1178 if (data[i] == 0xff) {
1179 gspca_frame_add(gspca_dev, INTER_PACKET,
1186 } while (++i < len);
1187 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1190 /* end a frame and start a new one */
1191 static void eof_sof(struct gspca_dev *gspca_dev)
1193 struct sd *sd = (struct sd *) gspca_dev;
1194 static const u8 ffd9[] = {0xff, 0xd9};
1196 /* if control set, stop bulk transfer */
1198 && gspca_dev->last_packet_type == INTER_PACKET)
1199 gspca_dev->cam.bulk_nurbs = 0;
1200 gspca_frame_add(gspca_dev, LAST_PACKET,
1202 gspca_frame_add(gspca_dev, FIRST_PACKET,
1203 sd->jpeg_hdr, JPEG_HDR_SZ);
1206 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1207 u8 *data, /* isoc packet */
1208 int len) /* iso packet length */
1210 struct sd *sd = (struct sd *) gspca_dev;
1214 len -= 8; /* ignore last 8 bytes (00 00 55 aa 55 aa 00 00) */
1217 * the end/start of frame is indicated by
1218 * 0x00 * 16 - 0xab * 8
1219 * aligned on 8 bytes boundary
1221 if (sd->eof_len != 0) { /* if 'abababab' in previous pkt */
1222 if (*((u32 *) data) == 0xabababab) {
1223 /*fixme: should remove previous 0000ababab*/
1233 if (*((u32 *) p) == 0xabababab) {
1234 if (l < 8) { /* (may be 4 only) */
1238 if (*((u32 *) p + 1) == 0xabababab) {
1239 add_packet(gspca_dev, data, p - data - 16);
1240 /* remove previous zeros */
1256 add_packet(gspca_dev, data, len);
1259 static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1261 struct sd *sd = (struct sd *) gspca_dev;
1264 if (gspca_dev->streaming)
1269 static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1271 struct sd *sd = (struct sd *) gspca_dev;
1276 static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val)
1278 struct sd *sd = (struct sd *) gspca_dev;
1281 if (gspca_dev->streaming)
1286 static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val)
1288 struct sd *sd = (struct sd *) gspca_dev;
1294 static int sd_set_jcomp(struct gspca_dev *gspca_dev,
1295 struct v4l2_jpegcompression *jcomp)
1297 struct sd *sd = (struct sd *) gspca_dev;
1300 if (jcomp->quality >= (QUAL_0 + QUAL_1) / 2)
1302 else if (jcomp->quality >= (QUAL_1 + QUAL_2) / 2)
1304 else if (jcomp->quality >= (QUAL_2 + QUAL_3) / 2)
1309 if (quality != sd->quality) {
1310 sd->quality = quality;
1311 if (gspca_dev->streaming) {
1312 send_stop(gspca_dev);
1313 sd_jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1315 send_start(gspca_dev);
1318 return gspca_dev->usb_err;
1321 static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1322 struct v4l2_jpegcompression *jcomp)
1324 struct sd *sd = (struct sd *) gspca_dev;
1326 memset(jcomp, 0, sizeof *jcomp);
1327 jcomp->quality = quality_tb[sd->quality];
1328 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
1329 | V4L2_JPEG_MARKER_DQT;
1333 /* sub-driver description */
1334 static const struct sd_desc sd_desc = {
1335 .name = MODULE_NAME,
1337 .nctrls = ARRAY_SIZE(sd_ctrls),
1338 .config = sd_config,
1340 .isoc_init = sd_isoc_init,
1343 .pkt_scan = sd_pkt_scan,
1344 .dq_callback = sd_dq_callback,
1345 .get_jcomp = sd_get_jcomp,
1346 .set_jcomp = sd_set_jcomp,
1349 /* Table of supported USB devices */
1350 #define ST(sensor, type) \
1351 .driver_info = (SENSOR_ ## sensor << 8) \
1353 static const __devinitdata struct usb_device_id device_table[] = {
1354 {USB_DEVICE(0x041e, 0x4038), ST(MI0360, 0)},
1355 {USB_DEVICE(0x041e, 0x403c), ST(LZ24BP, 0)},
1356 {USB_DEVICE(0x041e, 0x403d), ST(LZ24BP, 0)},
1357 {USB_DEVICE(0x041e, 0x4041), ST(LZ24BP, Creative_live_motion)},
1358 {USB_DEVICE(0x2770, 0x930b), ST(MI0360, 0)},
1359 {USB_DEVICE(0x2770, 0x930c), ST(MI0360, 0)},
1362 MODULE_DEVICE_TABLE(usb, device_table);
1365 /* -- device connect -- */
1366 static int sd_probe(struct usb_interface *intf,
1367 const struct usb_device_id *id)
1369 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1373 static struct usb_driver sd_driver = {
1374 .name = MODULE_NAME,
1375 .id_table = device_table,
1377 .disconnect = gspca_disconnect,
1379 .suspend = gspca_suspend,
1380 .resume = gspca_resume,
1384 /* -- module insert / remove -- */
1385 static int __init sd_mod_init(void)
1389 ret = usb_register(&sd_driver);
1395 static void __exit sd_mod_exit(void)
1397 usb_deregister(&sd_driver);
1398 info("deregistered");
1401 module_init(sd_mod_init);
1402 module_exit(sd_mod_exit);