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 */
54 #define Creative_live_motion 1
65 static int sd_setexpo(struct gspca_dev
*gspca_dev
, __s32 val
);
66 static int sd_getexpo(struct gspca_dev
*gspca_dev
, __s32
*val
);
67 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
);
68 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
);
70 static const struct ctrl sd_ctrls
[] = {
73 .id
= V4L2_CID_EXPOSURE
,
74 .type
= V4L2_CTRL_TYPE_INTEGER
,
79 #define EXPO_DEF 0x0356
80 .default_value
= EXPO_DEF
,
88 .type
= V4L2_CTRL_TYPE_INTEGER
,
94 .default_value
= GAIN_DEF
,
101 static struct v4l2_pix_format vga_mode
[] = {
102 {160, 120, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
104 .sizeimage
= 160 * 120 * 5 / 8 + 590,
105 .colorspace
= V4L2_COLORSPACE_JPEG
,
107 {320, 240, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
109 .sizeimage
= 320 * 240 * 4 / 8 + 590,
110 .colorspace
= V4L2_COLORSPACE_JPEG
,
112 {640, 480, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
114 .sizeimage
= 640 * 480 * 3 / 8 + 590,
115 .colorspace
= V4L2_COLORSPACE_JPEG
,
119 /* JPEG quality indexed by webcam quality */
124 static const u8 quality_tb
[4] = { QUAL_0
, QUAL_1
, QUAL_2
, QUAL_3
};
126 /* sq930x registers */
127 #define SQ930_CTRL_UCBUS_IO 0x0001
128 #define SQ930_CTRL_I2C_IO 0x0002
129 #define SQ930_CTRL_GPIO 0x0005
130 #define SQ930_CTRL_CAP_START 0x0010
131 #define SQ930_CTRL_CAP_STOP 0x0011
132 #define SQ930_CTRL_SET_EXPOSURE 0x001d
133 #define SQ930_CTRL_RESET 0x001e
134 #define SQ930_CTRL_GET_DEV_INFO 0x001f
137 #define SQ930_GPIO_DFL_I2C_SDA 0x0001
138 #define SQ930_GPIO_DFL_I2C_SCL 0x0002
139 #define SQ930_GPIO_RSTBAR 0x0004
140 #define SQ930_GPIO_EXTRA1 0x0040
141 #define SQ930_GPIO_EXTRA2 0x0080
142 /* gpio 3 (24..31) */
143 #define SQ930_GPIO_POWER 0x0200
144 #define SQ930_GPIO_DFL_LED 0x1000
146 struct ucbus_write_cmd
{
150 struct i2c_write_cmd
{
155 static const struct ucbus_write_cmd icx098bq_start_0
[] = {
156 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xce},
157 {0xf802, 0xc1}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x0e},
158 {0xf80a, 0x01}, {0xf80b, 0xee}, {0xf807, 0x60}, {0xf80c, 0x02},
159 {0xf80d, 0xf0}, {0xf80e, 0x03}, {0xf80f, 0x0a}, {0xf81c, 0x02},
160 {0xf81d, 0xf0}, {0xf81e, 0x03}, {0xf81f, 0x0a}, {0xf83a, 0x00},
161 {0xf83b, 0x10}, {0xf83c, 0x00}, {0xf83d, 0x4e}, {0xf810, 0x04},
162 {0xf811, 0x00}, {0xf812, 0x02}, {0xf813, 0x10}, {0xf803, 0x00},
163 {0xf814, 0x01}, {0xf815, 0x18}, {0xf816, 0x00}, {0xf817, 0x48},
164 {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
165 {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
166 {0xf823, 0x07}, {0xf824, 0xff}, {0xf825, 0x03}, {0xf826, 0xff},
167 {0xf827, 0x06}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
168 {0xf82b, 0x0c}, {0xf82c, 0xfd}, {0xf82d, 0x01}, {0xf82e, 0x00},
169 {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
170 {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
171 {0xf854, 0x00}, {0xf855, 0x18}, {0xf856, 0x00}, {0xf857, 0x3c},
172 {0xf858, 0x00}, {0xf859, 0x0c}, {0xf85a, 0x00}, {0xf85b, 0x30},
173 {0xf85c, 0x00}, {0xf85d, 0x0c}, {0xf85e, 0x00}, {0xf85f, 0x30},
174 {0xf860, 0x00}, {0xf861, 0x48}, {0xf862, 0x01}, {0xf863, 0xdc},
175 {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
176 {0xf868, 0xff}, {0xf869, 0x70}, {0xf86c, 0xff}, {0xf86d, 0x00},
177 {0xf86a, 0xff}, {0xf86b, 0x48}, {0xf86e, 0xff}, {0xf86f, 0x00},
178 {0xf870, 0x01}, {0xf871, 0xdb}, {0xf872, 0x01}, {0xf873, 0xfa},
179 {0xf874, 0x01}, {0xf875, 0xdb}, {0xf876, 0x01}, {0xf877, 0xfa},
180 {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
183 static const struct ucbus_write_cmd icx098bq_start_1
[] = {
184 {0xf5f0, 0x00}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
186 {0xf5f0, 0x49}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
188 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
192 static const struct ucbus_write_cmd icx098bq_start_2
[] = {
193 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x82}, {0xf806, 0x00},
194 {0xf807, 0x7f}, {0xf800, 0x03},
195 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x40}, {0xf806, 0x00},
196 {0xf807, 0x7f}, {0xf800, 0x03},
197 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xcf}, {0xf806, 0xd0},
198 {0xf807, 0x7f}, {0xf800, 0x03},
199 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
200 {0xf807, 0x7f}, {0xf800, 0x03}
203 static const struct ucbus_write_cmd lz24bp_start_0
[] = {
204 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xbe},
205 {0xf802, 0xc6}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x06},
206 {0xf80a, 0x01}, {0xf80b, 0xfe}, {0xf807, 0x84}, {0xf80c, 0x02},
207 {0xf80d, 0xf7}, {0xf80e, 0x03}, {0xf80f, 0x0b}, {0xf81c, 0x00},
208 {0xf81d, 0x49}, {0xf81e, 0x03}, {0xf81f, 0x0b}, {0xf83a, 0x00},
209 {0xf83b, 0x01}, {0xf83c, 0x00}, {0xf83d, 0x6b}, {0xf810, 0x03},
210 {0xf811, 0x10}, {0xf812, 0x02}, {0xf813, 0x6f}, {0xf803, 0x00},
211 {0xf814, 0x00}, {0xf815, 0x44}, {0xf816, 0x00}, {0xf817, 0x48},
212 {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
213 {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
214 {0xf823, 0x07}, {0xf824, 0xfd}, {0xf825, 0x07}, {0xf826, 0xf0},
215 {0xf827, 0x0c}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
216 {0xf82b, 0x0c}, {0xf82c, 0xfc}, {0xf82d, 0x01}, {0xf82e, 0x00},
217 {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
218 {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
219 {0xf854, 0x00}, {0xf855, 0x0c}, {0xf856, 0x00}, {0xf857, 0x30},
220 {0xf858, 0x00}, {0xf859, 0x18}, {0xf85a, 0x00}, {0xf85b, 0x3c},
221 {0xf85c, 0x00}, {0xf85d, 0x18}, {0xf85e, 0x00}, {0xf85f, 0x3c},
222 {0xf860, 0xff}, {0xf861, 0x37}, {0xf862, 0xff}, {0xf863, 0x1d},
223 {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
224 {0xf868, 0x00}, {0xf869, 0x37}, {0xf86c, 0x02}, {0xf86d, 0x1d},
225 {0xf86a, 0x00}, {0xf86b, 0x37}, {0xf86e, 0x02}, {0xf86f, 0x1d},
226 {0xf870, 0x01}, {0xf871, 0xc6}, {0xf872, 0x02}, {0xf873, 0x04},
227 {0xf874, 0x01}, {0xf875, 0xc6}, {0xf876, 0x02}, {0xf877, 0x04},
228 {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
231 static const struct ucbus_write_cmd lz24bp_start_1_gen
[] = {
232 {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
234 {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
236 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
240 static const struct ucbus_write_cmd lz24bp_start_1_clm
[] = {
241 {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
243 {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
245 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
249 static const struct ucbus_write_cmd lz24bp_start_2
[] = {
250 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x80}, {0xf806, 0x00},
251 {0xf807, 0x7f}, {0xf800, 0x03},
252 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x4e}, {0xf806, 0x00},
253 {0xf807, 0x7f}, {0xf800, 0x03},
254 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xc0}, {0xf806, 0x48},
255 {0xf807, 0x7f}, {0xf800, 0x03},
256 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
257 {0xf807, 0x7f}, {0xf800, 0x03}
260 static const struct ucbus_write_cmd mi0360_start_0
[] = {
261 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0xcc}, {0xf333, 0xcc},
262 {0xf334, 0xcc}, {0xf335, 0xcc}, {0xf33f, 0x00}
264 static const struct i2c_write_cmd mi0360_init_23
[] = {
265 {0x30, 0x0040}, /* reserved - def 0x0005 */
266 {0x31, 0x0000}, /* reserved - def 0x002a */
267 {0x34, 0x0100}, /* reserved - def 0x0100 */
268 {0x3d, 0x068f}, /* reserved - def 0x068f */
270 static const struct i2c_write_cmd mi0360_init_24
[] = {
271 {0x03, 0x01e5}, /* window height */
272 {0x04, 0x0285}, /* window width */
274 static const struct i2c_write_cmd mi0360_init_25
[] = {
275 {0x35, 0x0020}, /* global gain */
276 {0x2b, 0x0020}, /* green1 gain */
277 {0x2c, 0x002a}, /* blue gain */
278 {0x2d, 0x0028}, /* red gain */
279 {0x2e, 0x0020}, /* green2 gain */
281 static const struct ucbus_write_cmd mi0360_start_1
[] = {
282 {0xf5f0, 0x11}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
284 {0xf5f0, 0x51}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
286 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
289 static const struct i2c_write_cmd mi0360_start_2
[] = {
290 {0x62, 0x041d}, /* reserved - def 0x0418 */
292 static const struct i2c_write_cmd mi0360_start_3
[] = {
293 {0x05, 0x007b}, /* horiz blanking */
295 static const struct i2c_write_cmd mi0360_start_4
[] = {
296 {0x05, 0x03f5}, /* horiz blanking */
299 static const struct i2c_write_cmd mt9v111_init_0
[] = {
300 {0x01, 0x0001}, /* select IFP/SOC registers */
301 {0x06, 0x300c}, /* operating mode control */
302 {0x08, 0xcc00}, /* output format control (RGB) */
303 {0x01, 0x0004}, /* select core registers */
305 static const struct i2c_write_cmd mt9v111_init_1
[] = {
306 {0x03, 0x01e5}, /* window height */
307 {0x04, 0x0285}, /* window width */
309 static const struct i2c_write_cmd mt9v111_init_2
[] = {
312 {0x07, 0x3002}, /* output control */
313 {0x35, 0x0020}, /* global gain */
314 {0x2b, 0x0020}, /* green1 gain */
315 {0x2c, 0x0020}, /* blue gain */
316 {0x2d, 0x0020}, /* red gain */
317 {0x2e, 0x0020}, /* green2 gain */
319 static const struct ucbus_write_cmd mt9v111_start_1
[] = {
320 {0xf5f0, 0x11}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
322 {0xf5f0, 0x51}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
324 {0xf5fa, 0x00}, {0xf5f6, 0x0a}, {0xf5f7, 0x0a}, {0xf5f8, 0x0a},
327 static const struct i2c_write_cmd mt9v111_init_3
[] = {
330 static const struct i2c_write_cmd mt9v111_init_4
[] = {
331 {0x05, 0x00ce}, /* horizontal blanking */
334 static const struct ucbus_write_cmd ov7660_start_0
[] = {
335 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0xc0},
336 {0xf334, 0x39}, {0xf335, 0xe7}, {0xf33f, 0x03}
339 static const struct ucbus_write_cmd ov9630_start_0
[] = {
340 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0x00},
341 {0xf334, 0x3e}, {0xf335, 0xf8}, {0xf33f, 0x03}
344 static const struct cap_s
{
347 } capconfig
[4][3] = {
348 [SENSOR_ICX098BQ
] = {
349 {0, /* JPEG, 160x120 */
350 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
351 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
352 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41,
353 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} },
354 {2, /* JPEG, 320x240 */
355 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
356 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
357 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
358 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
359 {4, /* JPEG, 640x480 */
360 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
361 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
362 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
363 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
366 {0, /* JPEG, 160x120 */
367 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
368 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
369 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41,
370 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} },
371 {2, /* JPEG, 320x240 */
372 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee,
373 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
374 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
375 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
376 {4, /* JPEG, 640x480 */
377 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
378 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
379 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
380 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
383 {0, /* JPEG, 160x120 */
384 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b,
385 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
386 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f,
387 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} },
388 {2, /* JPEG, 320x240 */
389 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
391 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
392 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
393 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
394 {4, /* JPEG, 640x480 */
395 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe3,
396 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
397 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
398 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
401 {0, /* JPEG, 160x120 */
402 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b,
403 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
404 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f,
405 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} },
406 {2, /* JPEG, 320x240 */
407 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3,
408 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
409 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
410 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
411 {4, /* JPEG, 640x480 */
412 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3,
413 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
414 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
415 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
425 const struct ucbus_write_cmd
*cmd
;
428 static const struct sensor_s sensor_tb
[] = {
429 [SENSOR_ICX098BQ
] = {
433 SQ930_GPIO_DFL_I2C_SDA
| SQ930_GPIO_DFL_I2C_SCL
,
434 SQ930_GPIO_DFL_I2C_SDA
,
444 SQ930_GPIO_DFL_I2C_SDA
| SQ930_GPIO_DFL_I2C_SCL
,
445 SQ930_GPIO_DFL_I2C_SDA
,
455 SQ930_GPIO_DFL_I2C_SDA
| SQ930_GPIO_DFL_I2C_SCL
,
456 SQ930_GPIO_DFL_I2C_SDA
,
466 SQ930_GPIO_DFL_I2C_SDA
| SQ930_GPIO_DFL_I2C_SCL
,
467 SQ930_GPIO_DFL_I2C_SDA
,
477 SQ930_GPIO_DFL_I2C_SDA
| SQ930_GPIO_DFL_I2C_SCL
,
478 SQ930_GPIO_DFL_I2C_SDA
,
488 SQ930_GPIO_DFL_I2C_SDA
| SQ930_GPIO_DFL_I2C_SCL
,
489 SQ930_GPIO_DFL_I2C_SDA
,
497 static void reg_r(struct gspca_dev
*gspca_dev
,
502 if (gspca_dev
->usb_err
< 0)
504 ret
= usb_control_msg(gspca_dev
->dev
,
505 usb_rcvctrlpipe(gspca_dev
->dev
, 0),
507 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
508 value
, 0, gspca_dev
->usb_buf
, len
,
511 PDEBUG(D_ERR
, "reg_r %04x failed %d", value
, ret
);
512 gspca_dev
->usb_err
= ret
;
516 static void reg_w(struct gspca_dev
*gspca_dev
, u16 value
, u16 index
)
520 if (gspca_dev
->usb_err
< 0)
522 PDEBUG(D_USBO
, "reg_w v: %04x i: %04x", value
, index
);
523 ret
= usb_control_msg(gspca_dev
->dev
,
524 usb_sndctrlpipe(gspca_dev
->dev
, 0),
526 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
527 value
, index
, NULL
, 0,
531 PDEBUG(D_ERR
, "reg_w %04x %04x failed %d", value
, index
, ret
);
532 gspca_dev
->usb_err
= ret
;
536 static void reg_wb(struct gspca_dev
*gspca_dev
, u16 value
, u16 index
,
537 const u8
*data
, int len
)
541 if (gspca_dev
->usb_err
< 0)
543 PDEBUG(D_USBO
, "reg_wb v: %04x i: %04x %02x...%02x",
544 value
, index
, *data
, data
[len
- 1]);
545 memcpy(gspca_dev
->usb_buf
, data
, len
);
546 ret
= usb_control_msg(gspca_dev
->dev
,
547 usb_sndctrlpipe(gspca_dev
->dev
, 0),
549 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
550 value
, index
, gspca_dev
->usb_buf
, len
,
554 PDEBUG(D_ERR
, "reg_wb %04x %04x failed %d", value
, index
, ret
);
555 gspca_dev
->usb_err
= ret
;
559 static void i2c_write(struct sd
*sd
,
560 const struct i2c_write_cmd
*cmd
,
563 struct gspca_dev
*gspca_dev
= &sd
->gspca_dev
;
564 const struct sensor_s
*sensor
;
569 if (gspca_dev
->usb_err
< 0)
572 sensor
= &sensor_tb
[sd
->sensor
];
574 val
= (sensor
->i2c_addr
<< 8) | SQ930_CTRL_I2C_IO
;
575 idx
= (cmd
->val
& 0xff00) | cmd
->reg
;
577 buf
= gspca_dev
->usb_buf
;
578 *buf
++ = sensor
->i2c_dum
;
581 while (--ncmds
> 0) {
584 *buf
++ = cmd
->val
>> 8;
585 *buf
++ = sensor
->i2c_dum
;
589 PDEBUG(D_USBO
, "i2c_w v: %04x i: %04x %02x...%02x",
590 val
, idx
, gspca_dev
->usb_buf
[0], buf
[-1]);
591 ret
= usb_control_msg(gspca_dev
->dev
,
592 usb_sndctrlpipe(gspca_dev
->dev
, 0),
594 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
596 gspca_dev
->usb_buf
, buf
- gspca_dev
->usb_buf
,
599 PDEBUG(D_ERR
, "i2c_write failed %d", ret
);
600 gspca_dev
->usb_err
= ret
;
604 static void ucbus_write(struct gspca_dev
*gspca_dev
,
605 const struct ucbus_write_cmd
*cmd
,
613 if (gspca_dev
->usb_err
< 0)
617 if ((batchsize
- 1) * 3 > USB_BUF_SZ
) {
618 err("Bug: usb_buf overflow");
619 gspca_dev
->usb_err
= -ENOMEM
;
630 val
= (cmd
->bw_addr
<< 8) | SQ930_CTRL_UCBUS_IO
;
631 idx
= (cmd
->bw_data
<< 8) | (cmd
->bw_addr
>> 8);
633 buf
= gspca_dev
->usb_buf
;
636 *buf
++ = cmd
->bw_addr
;
637 *buf
++ = cmd
->bw_addr
>> 8;
638 *buf
++ = cmd
->bw_data
;
640 if (buf
!= gspca_dev
->usb_buf
)
641 PDEBUG(D_USBO
, "ucbus v: %04x i: %04x %02x...%02x",
643 gspca_dev
->usb_buf
[0], buf
[-1]);
645 PDEBUG(D_USBO
, "ucbus v: %04x i: %04x",
647 ret
= usb_control_msg(gspca_dev
->dev
,
648 usb_sndctrlpipe(gspca_dev
->dev
, 0),
650 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
652 gspca_dev
->usb_buf
, buf
- gspca_dev
->usb_buf
,
655 PDEBUG(D_ERR
, "ucbus_write failed %d", ret
);
656 gspca_dev
->usb_err
= ret
;
666 static void gpio_set(struct sd
*sd
, u16 val
, u16 mask
)
668 struct gspca_dev
*gspca_dev
= &sd
->gspca_dev
;
671 sd
->gpio
[0] &= ~mask
;
673 reg_w(gspca_dev
, 0x0100 | SQ930_CTRL_GPIO
,
679 sd
->gpio
[1] &= ~mask
;
681 reg_w(gspca_dev
, 0x0300 | SQ930_CTRL_GPIO
,
686 static void gpio_init(struct sd
*sd
,
689 gpio_set(sd
, *gpio
++, 0x000f);
690 gpio_set(sd
, *gpio
++, 0x000f);
691 gpio_set(sd
, *gpio
++, 0x000f);
692 gpio_set(sd
, *gpio
++, 0x000f);
693 gpio_set(sd
, *gpio
, 0x000f);
696 static void bridge_init(struct sd
*sd
)
698 static const struct ucbus_write_cmd clkfreq_cmd
= {
699 0xf031, 0 /* SQ930_CLKFREQ_60MHZ */
702 ucbus_write(&sd
->gspca_dev
, &clkfreq_cmd
, 1, 1);
704 gpio_set(sd
, SQ930_GPIO_POWER
, 0xff00);
707 static void cmos_probe(struct gspca_dev
*gspca_dev
)
709 struct sd
*sd
= (struct sd
*) gspca_dev
;
711 const struct sensor_s
*sensor
;
712 static const u8 probe_order
[] = {
713 /* SENSOR_LZ24BP, (tested as ccd) */
720 for (i
= 0; i
< ARRAY_SIZE(probe_order
); i
++) {
721 sensor
= &sensor_tb
[probe_order
[i
]];
722 ucbus_write(&sd
->gspca_dev
, sensor
->cmd
, sensor
->cmd_len
, 8);
723 gpio_init(sd
, sensor
->gpio
);
725 reg_r(gspca_dev
, (sensor
->i2c_addr
<< 8) | 0x001c, 1);
727 if (gspca_dev
->usb_buf
[0] != 0)
730 if (i
>= ARRAY_SIZE(probe_order
))
731 PDEBUG(D_PROBE
, "Unknown sensor");
733 sd
->sensor
= probe_order
[i
];
736 static void mt9v111_init(struct gspca_dev
*gspca_dev
)
739 static const u8 cmd_001b
[] = {
740 0x00, 0x3b, 0xf6, 0x01, 0x03, 0x02, 0x00, 0x00,
743 static const u8 cmd_011b
[][7] = {
744 {0x10, 0x01, 0x66, 0x08, 0x00, 0x00, 0x00},
745 {0x01, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x00},
746 {0x20, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00},
747 {0x02, 0x01, 0xae, 0x01, 0x00, 0x00, 0x00},
750 reg_wb(gspca_dev
, 0x001b, 0x0000, cmd_001b
, sizeof cmd_001b
);
751 for (i
= 0; i
< ARRAY_SIZE(cmd_011b
); i
++) {
752 reg_wb(gspca_dev
, 0x001b, 0x0000, cmd_011b
[i
],
753 ARRAY_SIZE(cmd_011b
[0]));
757 reg_r(gspca_dev
, 0x031b, 1);
758 if (gspca_dev
->usb_buf
[0] == 0
759 || gspca_dev
->usb_err
!= 0)
762 PDEBUG(D_PROBE
, "mt9v111_init timeout");
763 gspca_dev
->usb_err
= -ETIME
;
771 static void global_init(struct sd
*sd
, int first_time
)
773 switch (sd
->sensor
) {
774 case SENSOR_ICX098BQ
:
776 ucbus_write(&sd
->gspca_dev
,
779 gpio_init(sd
, sensor_tb
[sd
->sensor
].gpio
);
782 if (sd
->type
!= Creative_live_motion
)
783 gpio_set(sd
, SQ930_GPIO_EXTRA1
, 0x00ff);
785 gpio_set(sd
, 0, 0x00ff);
788 ucbus_write(&sd
->gspca_dev
,
791 gpio_init(sd
, sensor_tb
[sd
->sensor
].gpio
);
795 ucbus_write(&sd
->gspca_dev
,
797 ARRAY_SIZE(mi0360_start_0
),
799 gpio_init(sd
, sensor_tb
[sd
->sensor
].gpio
);
800 gpio_set(sd
, SQ930_GPIO_EXTRA2
, SQ930_GPIO_EXTRA2
);
803 /* case SENSOR_MT9V111: */
805 mt9v111_init(&sd
->gspca_dev
);
807 gpio_init(sd
, sensor_tb
[sd
->sensor
].gpio
);
812 static void lz24bp_ppl(struct sd
*sd
, u16 ppl
)
814 struct ucbus_write_cmd cmds
[2] = {
819 ucbus_write(&sd
->gspca_dev
, cmds
, ARRAY_SIZE(cmds
), 2);
822 static void setexposure(struct gspca_dev
*gspca_dev
)
824 struct sd
*sd
= (struct sd
*) gspca_dev
;
825 int i
, integclks
, intstartclk
, frameclks
, min_frclk
;
826 const struct sensor_s
*sensor
;
830 integclks
= sd
->expo
;
832 cmd
= SQ930_CTRL_SET_EXPOSURE
;
834 switch (sd
->sensor
) {
835 case SENSOR_ICX098BQ
: /* ccd */
837 min_frclk
= sd
->sensor
== SENSOR_ICX098BQ
? 0x210 : 0x26f;
838 if (integclks
>= min_frclk
) {
840 frameclks
= integclks
;
842 intstartclk
= min_frclk
- integclks
;
843 frameclks
= min_frclk
;
845 buf
[i
++] = intstartclk
>> 8;
846 buf
[i
++] = intstartclk
;
847 buf
[i
++] = frameclks
>> 8;
848 buf
[i
++] = frameclks
;
852 /* case SENSOR_MI0360: */
853 /* case SENSOR_MT9V111: */
855 sensor
= &sensor_tb
[sd
->sensor
];
856 buf
[i
++] = sensor
->i2c_addr
; /* i2c_slave_addr */
857 buf
[i
++] = 0x08; /* 2 * ni2c */
858 buf
[i
++] = 0x09; /* reg = shutter width */
859 buf
[i
++] = integclks
>> 8; /* val H */
860 buf
[i
++] = sensor
->i2c_dum
;
861 buf
[i
++] = integclks
; /* val L */
862 buf
[i
++] = 0x35; /* reg = global gain */
863 buf
[i
++] = 0x00; /* val H */
864 buf
[i
++] = sensor
->i2c_dum
;
865 buf
[i
++] = 0x80 + sd
->gain
/ 2; /* val L */
873 reg_wb(gspca_dev
, cmd
, 0, buf
, i
);
876 /* This function is called at probe time just before sd_init */
877 static int sd_config(struct gspca_dev
*gspca_dev
,
878 const struct usb_device_id
*id
)
880 struct sd
*sd
= (struct sd
*) gspca_dev
;
881 struct cam
*cam
= &gspca_dev
->cam
;
883 sd
->sensor
= id
->driver_info
>> 8;
884 sd
->type
= id
->driver_info
;
886 cam
->cam_mode
= vga_mode
;
887 cam
->nmodes
= ARRAY_SIZE(vga_mode
);
890 cam
->bulk_size
= BULK_TRANSFER_LEN
;
891 /* cam->bulk_nurbs = 2; fixme: if no setexpo sync */
893 sd
->quality
= QUALITY_DEF
;
900 /* this function is called at probe and resume time */
901 static int sd_init(struct gspca_dev
*gspca_dev
)
903 struct sd
*sd
= (struct sd
*) gspca_dev
;
905 sd
->gpio
[0] = sd
->gpio
[1] = 0xff; /* force gpio rewrite */
907 /*fixme: is this needed for icx098bp and mi0360?
908 if (sd->sensor != SENSOR_LZ24BP)
909 reg_w(gspca_dev, SQ930_CTRL_RESET, 0x0000);
912 reg_r(gspca_dev
, SQ930_CTRL_GET_DEV_INFO
, 8);
914 * 03 00 12 93 0b f6 c9 00 live! ultra
915 * 03 00 07 93 0b f6 ca 00 live! ultra for notebook
916 * 03 00 12 93 0b fe c8 00 Trust WB-3500T
917 * 02 00 06 93 0b fe c8 00 Joy-IT 318S
918 * 03 00 12 93 0b f6 cf 00 icam tracer - sensor icx098bq
919 * 02 00 12 93 0b fe cf 00 ProQ Motion Webcam
922 * 0: 02 = usb 1.0 (12Mbit) / 03 = usb2.0 (480Mbit)
924 * 2: 06 / 07 / 12 = mode webcam? firmware??
925 * 3: 93 chip = 930b (930b or 930c)
927 * 5: f6 = cdd (icx098bq, lz24bp) / fe or de = cmos (i2c) (other sensors)
928 * 6: c8 / c9 / ca / cf = mode webcam?, sensor? webcam?
931 PDEBUG(D_PROBE
, "info: %02x %02x %02x %02x %02x %02x %02x %02x",
932 gspca_dev
->usb_buf
[0],
933 gspca_dev
->usb_buf
[1],
934 gspca_dev
->usb_buf
[2],
935 gspca_dev
->usb_buf
[3],
936 gspca_dev
->usb_buf
[4],
937 gspca_dev
->usb_buf
[5],
938 gspca_dev
->usb_buf
[6],
939 gspca_dev
->usb_buf
[7]);
943 if (sd
->sensor
== SENSOR_MI0360
) {
945 /* no sensor probe for icam tracer */
946 if (gspca_dev
->usb_buf
[5] == 0xf6) { /* if CMOS */
947 sd
->sensor
= SENSOR_ICX098BQ
;
948 gspca_dev
->cam
.cam_mode
= &vga_mode
[1];
949 gspca_dev
->cam
.nmodes
= 1; /* only 320x240 */
951 cmos_probe(gspca_dev
);
955 PDEBUG(D_PROBE
, "Sensor %s", sensor_tb
[sd
->sensor
].name
);
958 return gspca_dev
->usb_err
;
961 /* special function to create the quantization tables of the JPEG header */
962 static void sd_jpeg_set_qual(u8
*jpeg_hdr
,
967 quality
= quality_tb
[quality
]; /* convert to JPEG quality */
969 * approximative qualities for Y and U/V:
970 * quant = 0:94%/91% 1:91%/87% 2:82%/73% 3:69%/56%
972 * quant = 0:94%/91% 1:91%/87.5% 2:81.5%/72% 3:69%/54.5%
974 sc1
= 200 - quality
* 2;
975 quality
= quality
* 7 / 5 - 40; /* UV quality */
976 sc2
= 200 - quality
* 2;
977 for (i
= 0; i
< 64; i
++) {
978 jpeg_hdr
[JPEG_QT0_OFFSET
+ i
] =
979 (jpeg_head
[JPEG_QT0_OFFSET
+ i
] * sc1
+ 50) / 100;
980 jpeg_hdr
[JPEG_QT1_OFFSET
+ i
] =
981 (jpeg_head
[JPEG_QT1_OFFSET
+ i
] * sc2
+ 50) / 100;
985 /* send the start/stop commands to the webcam */
986 static void send_start(struct gspca_dev
*gspca_dev
)
988 struct sd
*sd
= (struct sd
*) gspca_dev
;
989 const struct cap_s
*cap
;
992 mode
= gspca_dev
->cam
.cam_mode
[gspca_dev
->curr_mode
].priv
;
993 cap
= &capconfig
[sd
->sensor
][mode
];
994 quality
= sd
->quality
;
995 reg_wb(gspca_dev
, (quality
<< 12)
996 | 0x0a00 /* 900 for Bayer */
997 | SQ930_CTRL_CAP_START
,
998 0x0500 /* a00 for Bayer */
1002 static void send_stop(struct gspca_dev
*gspca_dev
)
1004 reg_w(gspca_dev
, SQ930_CTRL_CAP_STOP
, 0);
1007 /* function called at start time before URB creation */
1008 static int sd_isoc_init(struct gspca_dev
*gspca_dev
)
1010 struct sd
*sd
= (struct sd
*) gspca_dev
;
1012 gspca_dev
->cam
.bulk_nurbs
= 1; /* there must be one URB only */
1017 /* start the capture */
1018 static int sd_start(struct gspca_dev
*gspca_dev
)
1020 struct sd
*sd
= (struct sd
*) gspca_dev
;
1023 /* initialize the JPEG header */
1024 jpeg_define(sd
->jpeg_hdr
, gspca_dev
->height
, gspca_dev
->width
,
1025 0x21); /* JPEG 422 */
1026 sd_jpeg_set_qual(sd
->jpeg_hdr
, sd
->quality
);
1032 switch (sd
->sensor
) {
1033 case SENSOR_ICX098BQ
:
1034 ucbus_write(gspca_dev
, icx098bq_start_0
,
1035 ARRAY_SIZE(icx098bq_start_0
),
1037 ucbus_write(gspca_dev
, icx098bq_start_1
,
1038 ARRAY_SIZE(icx098bq_start_1
),
1040 ucbus_write(gspca_dev
, icx098bq_start_2
,
1041 ARRAY_SIZE(icx098bq_start_2
),
1046 send_start(gspca_dev
);
1047 gpio_set(sd
, SQ930_GPIO_EXTRA2
| SQ930_GPIO_RSTBAR
, 0x00ff);
1049 reg_w(gspca_dev
, SQ930_CTRL_CAP_STOP
, 0x0000);
1050 gpio_set(sd
, 0x7f, 0x00ff);
1053 send_start(gspca_dev
);
1054 gpio_set(sd
, SQ930_GPIO_EXTRA2
| SQ930_GPIO_RSTBAR
, 0x00ff);
1057 ucbus_write(gspca_dev
, lz24bp_start_0
,
1058 ARRAY_SIZE(lz24bp_start_0
),
1060 if (sd
->type
!= Creative_live_motion
)
1061 ucbus_write(gspca_dev
, lz24bp_start_1_gen
,
1062 ARRAY_SIZE(lz24bp_start_1_gen
),
1065 ucbus_write(gspca_dev
, lz24bp_start_1_clm
,
1066 ARRAY_SIZE(lz24bp_start_1_clm
),
1068 ucbus_write(gspca_dev
, lz24bp_start_2
,
1069 ARRAY_SIZE(lz24bp_start_2
),
1071 mode
= gspca_dev
->cam
.cam_mode
[gspca_dev
->curr_mode
].priv
;
1072 lz24bp_ppl(sd
, mode
== 2 ? 0x0564 : 0x0310);
1076 ucbus_write(gspca_dev
, mi0360_start_0
,
1077 ARRAY_SIZE(mi0360_start_0
),
1079 i2c_write(sd
, mi0360_init_23
,
1080 ARRAY_SIZE(mi0360_init_23
));
1081 i2c_write(sd
, mi0360_init_24
,
1082 ARRAY_SIZE(mi0360_init_24
));
1083 i2c_write(sd
, mi0360_init_25
,
1084 ARRAY_SIZE(mi0360_init_25
));
1085 ucbus_write(gspca_dev
, mi0360_start_1
,
1086 ARRAY_SIZE(mi0360_start_1
),
1088 i2c_write(sd
, mi0360_start_2
,
1089 ARRAY_SIZE(mi0360_start_2
));
1090 i2c_write(sd
, mi0360_start_3
,
1091 ARRAY_SIZE(mi0360_start_3
));
1094 send_start(gspca_dev
);
1096 reg_w(gspca_dev
, SQ930_CTRL_CAP_STOP
, 0x0000);
1099 mi0360_start_4
, ARRAY_SIZE(mi0360_start_4
));
1102 /* case SENSOR_MT9V111: */
1103 ucbus_write(gspca_dev
, mi0360_start_0
,
1104 ARRAY_SIZE(mi0360_start_0
),
1106 i2c_write(sd
, mt9v111_init_0
,
1107 ARRAY_SIZE(mt9v111_init_0
));
1108 i2c_write(sd
, mt9v111_init_1
,
1109 ARRAY_SIZE(mt9v111_init_1
));
1110 i2c_write(sd
, mt9v111_init_2
,
1111 ARRAY_SIZE(mt9v111_init_2
));
1112 ucbus_write(gspca_dev
, mt9v111_start_1
,
1113 ARRAY_SIZE(mt9v111_start_1
),
1115 i2c_write(sd
, mt9v111_init_3
,
1116 ARRAY_SIZE(mt9v111_init_3
));
1117 i2c_write(sd
, mt9v111_init_4
,
1118 ARRAY_SIZE(mt9v111_init_4
));
1122 send_start(gspca_dev
);
1126 sd
->eof_len
= 0; /* init packet scan */
1128 if (sd
->sensor
== SENSOR_MT9V111
)
1129 gpio_set(sd
, SQ930_GPIO_DFL_LED
, SQ930_GPIO_DFL_LED
);
1131 sd
->do_ctrl
= 1; /* set the exposure */
1133 return gspca_dev
->usb_err
;
1136 static void sd_stopN(struct gspca_dev
*gspca_dev
)
1138 struct sd
*sd
= (struct sd
*) gspca_dev
;
1140 if (sd
->sensor
== SENSOR_MT9V111
)
1141 gpio_set(sd
, 0, SQ930_GPIO_DFL_LED
);
1142 send_stop(gspca_dev
);
1145 /* function called when the application gets a new frame */
1146 /* It sets the exposure if required and restart the bulk transfer. */
1147 static void sd_dq_callback(struct gspca_dev
*gspca_dev
)
1149 struct sd
*sd
= (struct sd
*) gspca_dev
;
1152 if (!sd
->do_ctrl
|| gspca_dev
->cam
.bulk_nurbs
!= 0)
1156 setexposure(gspca_dev
);
1158 gspca_dev
->cam
.bulk_nurbs
= 1;
1159 ret
= usb_submit_urb(gspca_dev
->urb
[0], GFP_ATOMIC
);
1161 PDEBUG(D_ERR
|D_PACK
, "sd_dq_callback() err %d", ret
);
1163 /* wait a little time, otherwise the webcam crashes */
1167 /* move a packet adding 0x00 after 0xff */
1168 static void add_packet(struct gspca_dev
*gspca_dev
,
1176 if (data
[i
] == 0xff) {
1177 gspca_frame_add(gspca_dev
, INTER_PACKET
,
1184 } while (++i
< len
);
1185 gspca_frame_add(gspca_dev
, INTER_PACKET
, data
, len
);
1188 /* end a frame and start a new one */
1189 static void eof_sof(struct gspca_dev
*gspca_dev
)
1191 struct sd
*sd
= (struct sd
*) gspca_dev
;
1192 static const u8 ffd9
[] = {0xff, 0xd9};
1194 /* if control set, stop bulk transfer */
1196 && gspca_dev
->last_packet_type
== INTER_PACKET
)
1197 gspca_dev
->cam
.bulk_nurbs
= 0;
1198 gspca_frame_add(gspca_dev
, LAST_PACKET
,
1200 gspca_frame_add(gspca_dev
, FIRST_PACKET
,
1201 sd
->jpeg_hdr
, JPEG_HDR_SZ
);
1204 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
1205 u8
*data
, /* isoc packet */
1206 int len
) /* iso packet length */
1208 struct sd
*sd
= (struct sd
*) gspca_dev
;
1212 len
-= 8; /* ignore last 8 bytes (00 00 55 aa 55 aa 00 00) */
1215 * the end/start of frame is indicated by
1216 * 0x00 * 16 - 0xab * 8
1217 * aligned on 8 bytes boundary
1219 if (sd
->eof_len
!= 0) { /* if 'abababab' in previous pkt */
1220 if (*((u32
*) data
) == 0xabababab) {
1221 /*fixme: should remove previous 0000ababab*/
1231 if (*((u32
*) p
) == 0xabababab) {
1232 if (l
< 8) { /* (may be 4 only) */
1236 if (*((u32
*) p
+ 1) == 0xabababab) {
1237 add_packet(gspca_dev
, data
, p
- data
- 16);
1238 /* remove previous zeros */
1254 add_packet(gspca_dev
, data
, len
);
1257 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
)
1259 struct sd
*sd
= (struct sd
*) gspca_dev
;
1262 if (gspca_dev
->streaming
)
1267 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
)
1269 struct sd
*sd
= (struct sd
*) gspca_dev
;
1274 static int sd_setexpo(struct gspca_dev
*gspca_dev
, __s32 val
)
1276 struct sd
*sd
= (struct sd
*) gspca_dev
;
1279 if (gspca_dev
->streaming
)
1284 static int sd_getexpo(struct gspca_dev
*gspca_dev
, __s32
*val
)
1286 struct sd
*sd
= (struct sd
*) gspca_dev
;
1292 static int sd_set_jcomp(struct gspca_dev
*gspca_dev
,
1293 struct v4l2_jpegcompression
*jcomp
)
1295 struct sd
*sd
= (struct sd
*) gspca_dev
;
1298 if (jcomp
->quality
>= (QUAL_0
+ QUAL_1
) / 2)
1300 else if (jcomp
->quality
>= (QUAL_1
+ QUAL_2
) / 2)
1302 else if (jcomp
->quality
>= (QUAL_2
+ QUAL_3
) / 2)
1307 if (quality
!= sd
->quality
) {
1308 sd
->quality
= quality
;
1309 if (gspca_dev
->streaming
) {
1310 send_stop(gspca_dev
);
1311 sd_jpeg_set_qual(sd
->jpeg_hdr
, sd
->quality
);
1313 send_start(gspca_dev
);
1316 return gspca_dev
->usb_err
;
1319 static int sd_get_jcomp(struct gspca_dev
*gspca_dev
,
1320 struct v4l2_jpegcompression
*jcomp
)
1322 struct sd
*sd
= (struct sd
*) gspca_dev
;
1324 memset(jcomp
, 0, sizeof *jcomp
);
1325 jcomp
->quality
= quality_tb
[sd
->quality
];
1326 jcomp
->jpeg_markers
= V4L2_JPEG_MARKER_DHT
1327 | V4L2_JPEG_MARKER_DQT
;
1331 /* sub-driver description */
1332 static const struct sd_desc sd_desc
= {
1333 .name
= MODULE_NAME
,
1335 .nctrls
= ARRAY_SIZE(sd_ctrls
),
1336 .config
= sd_config
,
1338 .isoc_init
= sd_isoc_init
,
1341 .pkt_scan
= sd_pkt_scan
,
1342 .dq_callback
= sd_dq_callback
,
1343 .get_jcomp
= sd_get_jcomp
,
1344 .set_jcomp
= sd_set_jcomp
,
1347 /* Table of supported USB devices */
1348 #define ST(sensor, type) \
1349 .driver_info = (SENSOR_ ## sensor << 8) \
1351 static const __devinitdata
struct usb_device_id device_table
[] = {
1352 {USB_DEVICE(0x041e, 0x4038), ST(MI0360
, 0)},
1353 {USB_DEVICE(0x041e, 0x403c), ST(LZ24BP
, 0)},
1354 {USB_DEVICE(0x041e, 0x403d), ST(LZ24BP
, 0)},
1355 {USB_DEVICE(0x041e, 0x4041), ST(LZ24BP
, Creative_live_motion
)},
1356 {USB_DEVICE(0x2770, 0x930b), ST(MI0360
, 0)},
1357 {USB_DEVICE(0x2770, 0x930c), ST(MI0360
, 0)},
1360 MODULE_DEVICE_TABLE(usb
, device_table
);
1363 /* -- device connect -- */
1364 static int sd_probe(struct usb_interface
*intf
,
1365 const struct usb_device_id
*id
)
1367 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
1371 static struct usb_driver sd_driver
= {
1372 .name
= MODULE_NAME
,
1373 .id_table
= device_table
,
1375 .disconnect
= gspca_disconnect
,
1377 .suspend
= gspca_suspend
,
1378 .resume
= gspca_resume
,
1382 /* -- module insert / remove -- */
1383 static int __init
sd_mod_init(void)
1387 ret
= usb_register(&sd_driver
);
1393 static void __exit
sd_mod_exit(void)
1395 usb_deregister(&sd_driver
);
1396 info("deregistered");
1399 module_init(sd_mod_init
);
1400 module_exit(sd_mod_exit
);