aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/etoms.c
diff options
context:
space:
mode:
authorJean-Francois Moine <moinejf@free.fr>2008-07-14 08:38:29 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-07-20 06:26:14 -0400
commit739570bb218bb4607df1f197282561e97a98e54a (patch)
tree25555dfe5ac873bc96866c486d6f6c1dcabf24f4 /drivers/media/video/gspca/etoms.c
parent5b77ae7776183d733ec86727bcc34c52a336afd6 (diff)
V4L/DVB (8352): gspca: Buffers for USB exchanges cannot be in the stack.
gspca: Protect dq_callback() against simultaneous USB exchanges. Temporary buffer for USB exchanges added in the device struct. (all) Use a temporary buffer for all USB exchanges. Signed-off-by: Jean-Francois Moine <moinejf@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/gspca/etoms.c')
-rw-r--r--drivers/media/video/gspca/etoms.c443
1 files changed, 222 insertions, 221 deletions
diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c
index 1da6a182561f..5bb8dc1adbb7 100644
--- a/drivers/media/video/gspca/etoms.c
+++ b/drivers/media/video/gspca/etoms.c
@@ -22,8 +22,8 @@
22 22
23#include "gspca.h" 23#include "gspca.h"
24 24
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
26static const char version[] = "2.1.5"; 26static const char version[] = "2.1.7";
27 27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("Etoms USB Camera Driver"); 29MODULE_DESCRIPTION("Etoms USB Camera Driver");
@@ -229,201 +229,215 @@ static const __u8 I2c3[] = { 0x12, 0x05 };
229 229
230static const __u8 I2c4[] = { 0x41, 0x08 }; 230static const __u8 I2c4[] = { 0x41, 0x08 };
231 231
232static void reg_r(struct usb_device *dev, 232/* read 'len' bytes to gspca_dev->usb_buf */
233 __u16 index, __u8 *buffer, int len) 233static void reg_r(struct gspca_dev *gspca_dev,
234 __u16 index,
235 __u16 len)
234{ 236{
237 struct usb_device *dev = gspca_dev->dev;
238
239#ifdef CONFIG_VIDEO_ADV_DEBUG
240 if (len > sizeof gspca_dev->usb_buf) {
241 err("reg_r: buffer overflow");
242 return;
243 }
244#endif
235 usb_control_msg(dev, 245 usb_control_msg(dev,
236 usb_rcvctrlpipe(dev, 0), 246 usb_rcvctrlpipe(dev, 0),
237 0, 247 0,
238 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 248 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
239 0, index, buffer, len, 500); 249 0,
250 index, gspca_dev->usb_buf, len, 500);
251 PDEBUG(D_USBI, "reg read [%02x] -> %02x ..",
252 index, gspca_dev->usb_buf[0]);
240} 253}
241 254
242static void reg_w_val(struct usb_device *dev, 255static void reg_w_val(struct gspca_dev *gspca_dev,
243 __u16 index, __u8 val) 256 __u16 index,
257 __u8 val)
244{ 258{
245 __u8 data; 259 struct usb_device *dev = gspca_dev->dev;
246 260
247 data = val; 261 gspca_dev->usb_buf[0] = val;
248 usb_control_msg(dev, 262 usb_control_msg(dev,
249 usb_sndctrlpipe(dev, 0), 263 usb_sndctrlpipe(dev, 0),
250 0, 264 0,
251 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 265 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
252 0, index, &data, 1, 500); 266 0,
267 index, gspca_dev->usb_buf, 1, 500);
253} 268}
254 269
255static void reg_w(struct usb_device *dev, 270static void reg_w(struct gspca_dev *gspca_dev,
256 __u16 index, const __u8 *buffer, __u16 len) 271 __u16 index,
272 const __u8 *buffer,
273 __u16 len)
257{ 274{
258 __u8 tmpbuf[8]; 275 struct usb_device *dev = gspca_dev->dev;
259 276
260 memcpy(tmpbuf, buffer, len); 277#ifdef CONFIG_VIDEO_ADV_DEBUG
278 if (len > sizeof gspca_dev->usb_buf) {
279 err("reg_w: buffer overflow");
280 return;
281 }
282 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
283#endif
284 memcpy(gspca_dev->usb_buf, buffer, len);
261 usb_control_msg(dev, 285 usb_control_msg(dev,
262 usb_sndctrlpipe(dev, 0), 286 usb_sndctrlpipe(dev, 0),
263 0, 287 0,
264 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 288 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
265 0, index, tmpbuf, len, 500); 289 0, index, gspca_dev->usb_buf, len, 500);
266} 290}
267 291
268static int Et_i2cwrite(struct usb_device *dev, __u8 reg, 292static int i2c_w(struct gspca_dev *gspca_dev,
269 const __u8 *buffer, 293 __u8 reg,
270 __u16 len, __u8 mode) 294 const __u8 *buffer,
295 __u16 len, __u8 mode)
271{ 296{
272 /* buffer should be [D0..D7] */ 297 /* buffer should be [D0..D7] */
273 __u8 ptchcount; 298 __u8 ptchcount;
274 299
275 /* set the base address */ 300 /* set the base address */
276 reg_w_val(dev, ET_I2C_BASE, 0x40); /* sensor base for the pas106 */ 301 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
302 /* sensor base for the pas106 */
277 /* set count and prefetch */ 303 /* set count and prefetch */
278 ptchcount = ((len & 0x07) << 4) | (mode & 0x03); 304 ptchcount = ((len & 0x07) << 4) | (mode & 0x03);
279 reg_w_val(dev, ET_I2C_COUNT, ptchcount); 305 reg_w_val(gspca_dev, ET_I2C_COUNT, ptchcount);
280 /* set the register base */ 306 /* set the register base */
281 reg_w_val(dev, ET_I2C_REG, reg); 307 reg_w_val(gspca_dev, ET_I2C_REG, reg);
282 while (--len >= 0) 308 while (--len >= 0)
283 reg_w_val(dev, ET_I2C_DATA0 + len, buffer[len]); 309 reg_w_val(gspca_dev, ET_I2C_DATA0 + len, buffer[len]);
284 return 0; 310 return 0;
285} 311}
286 312
287static int Et_i2cread(struct usb_device *dev, __u8 reg, 313static int i2c_r(struct gspca_dev *gspca_dev,
288 __u8 *buffer, 314 __u8 reg)
289 __u16 length, __u8 mode)
290{ 315{
291 /* buffer should be [D0..D7] */
292 int i, j;
293 __u8 ptchcount;
294
295 /* set the base address */ 316 /* set the base address */
296 reg_w_val(dev, ET_I2C_BASE, 0x40); /* sensor base for the pas106 */ 317 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
297 /* set count and prefetch */ 318 /* sensor base for the pas106 */
298 ptchcount = ((length & 0x07) << 4) | (mode & 0x03); 319 /* set count and prefetch (cnd: 4 bits - mode: 4 bits) */
299 reg_w_val(dev, ET_I2C_COUNT, ptchcount); 320 reg_w_val(gspca_dev, ET_I2C_COUNT, 0x11);
300 /* set the register base */ 321 reg_w_val(gspca_dev, ET_I2C_REG, reg); /* set the register base */
301 reg_w_val(dev, ET_I2C_REG, reg); 322 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x02); /* prefetch */
302 reg_w_val(dev, ET_I2C_PREFETCH, 0x02); /* prefetch */ 323 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x00);
303 reg_w_val(dev, ET_I2C_PREFETCH, 0); 324 reg_r(gspca_dev, ET_I2C_DATA0, 1); /* read one byte */
304 j = length - 1;
305 for (i = 0; i < length; i++) {
306 reg_r(dev, (ET_I2C_DATA0 + j), &buffer[j], 1);
307 j--;
308 }
309 return 0; 325 return 0;
310} 326}
311 327
312static int Et_WaitStatus(struct usb_device *dev) 328static int Et_WaitStatus(struct gspca_dev *gspca_dev)
313{ 329{
314 __u8 bytereceived;
315 int retry = 10; 330 int retry = 10;
316 331
317 while (retry--) { 332 while (retry--) {
318 reg_r(dev, ET_ClCK, &bytereceived, 1); 333 reg_r(gspca_dev, ET_ClCK, 1);
319 if (bytereceived != 0) 334 if (gspca_dev->usb_buf[0] != 0)
320 return 1; 335 return 1;
321 } 336 }
322 return 0; 337 return 0;
323} 338}
324 339
325static int et_video(struct usb_device *dev, int on) 340static int et_video(struct gspca_dev *gspca_dev,
341 int on)
326{ 342{
327 int err; 343 int ret;
328 344
329 reg_w_val(dev, ET_GPIO_OUT, on 345 reg_w_val(gspca_dev, ET_GPIO_OUT,
330 ? 0x10 /* startvideo - set Bit5 */ 346 on ? 0x10 /* startvideo - set Bit5 */
331 : 0); /* stopvideo */ 347 : 0); /* stopvideo */
332 err = Et_WaitStatus(dev); 348 ret = Et_WaitStatus(gspca_dev);
333 if (!err) 349 if (ret != 0)
334 PDEBUG(D_ERR, "timeout video on/off"); 350 PDEBUG(D_ERR, "timeout video on/off");
335 return err; 351 return ret;
336} 352}
337 353
338static void Et_init2(struct gspca_dev *gspca_dev) 354static void Et_init2(struct gspca_dev *gspca_dev)
339{ 355{
340 struct usb_device *dev = gspca_dev->dev;
341 __u8 value; 356 __u8 value;
342 __u8 received;
343 static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 }; 357 static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 };
344 358
345 PDEBUG(D_STREAM, "Open Init2 ET"); 359 PDEBUG(D_STREAM, "Open Init2 ET");
346 reg_w_val(dev, ET_GPIO_DIR_CTRL, 0x2f); 360 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 0x2f);
347 reg_w_val(dev, ET_GPIO_OUT, 0x10); 361 reg_w_val(gspca_dev, ET_GPIO_OUT, 0x10);
348 reg_r(dev, ET_GPIO_IN, &received, 1); 362 reg_r(gspca_dev, ET_GPIO_IN, 1);
349 reg_w_val(dev, ET_ClCK, 0x14); /* 0x14 // 0x16 enabled pattern */ 363 reg_w_val(gspca_dev, ET_ClCK, 0x14); /* 0x14 // 0x16 enabled pattern */
350 reg_w_val(dev, ET_CTRL, 0x1b); 364 reg_w_val(gspca_dev, ET_CTRL, 0x1b);
351 365
352 /* compression et subsampling */ 366 /* compression et subsampling */
353 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) 367 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
354 value = ET_COMP_VAL1; /* 320 */ 368 value = ET_COMP_VAL1; /* 320 */
355 else 369 else
356 value = ET_COMP_VAL0; /* 640 */ 370 value = ET_COMP_VAL0; /* 640 */
357 reg_w_val(dev, ET_COMP, value); 371 reg_w_val(gspca_dev, ET_COMP, value);
358 reg_w_val(dev, ET_MAXQt, 0x1f); 372 reg_w_val(gspca_dev, ET_MAXQt, 0x1f);
359 reg_w_val(dev, ET_MINQt, 0x04); 373 reg_w_val(gspca_dev, ET_MINQt, 0x04);
360 /* undocumented registers */ 374 /* undocumented registers */
361 reg_w_val(dev, ET_REG1d, 0xff); 375 reg_w_val(gspca_dev, ET_REG1d, 0xff);
362 reg_w_val(dev, ET_REG1e, 0xff); 376 reg_w_val(gspca_dev, ET_REG1e, 0xff);
363 reg_w_val(dev, ET_REG1f, 0xff); 377 reg_w_val(gspca_dev, ET_REG1f, 0xff);
364 reg_w_val(dev, ET_REG20, 0x35); 378 reg_w_val(gspca_dev, ET_REG20, 0x35);
365 reg_w_val(dev, ET_REG21, 0x01); 379 reg_w_val(gspca_dev, ET_REG21, 0x01);
366 reg_w_val(dev, ET_REG22, 0x00); 380 reg_w_val(gspca_dev, ET_REG22, 0x00);
367 reg_w_val(dev, ET_REG23, 0xff); 381 reg_w_val(gspca_dev, ET_REG23, 0xff);
368 reg_w_val(dev, ET_REG24, 0xff); 382 reg_w_val(gspca_dev, ET_REG24, 0xff);
369 reg_w_val(dev, ET_REG25, 0x0f); 383 reg_w_val(gspca_dev, ET_REG25, 0x0f);
370 /* colors setting */ 384 /* colors setting */
371 reg_w_val(dev, 0x30, 0x11); /* 0x30 */ 385 reg_w_val(gspca_dev, 0x30, 0x11); /* 0x30 */
372 reg_w_val(dev, 0x31, 0x40); 386 reg_w_val(gspca_dev, 0x31, 0x40);
373 reg_w_val(dev, 0x32, 0x00); 387 reg_w_val(gspca_dev, 0x32, 0x00);
374 reg_w_val(dev, ET_O_RED, 0x00); /* 0x34 */ 388 reg_w_val(gspca_dev, ET_O_RED, 0x00); /* 0x34 */
375 reg_w_val(dev, ET_O_GREEN1, 0x00); 389 reg_w_val(gspca_dev, ET_O_GREEN1, 0x00);
376 reg_w_val(dev, ET_O_BLUE, 0x00); 390 reg_w_val(gspca_dev, ET_O_BLUE, 0x00);
377 reg_w_val(dev, ET_O_GREEN2, 0x00); 391 reg_w_val(gspca_dev, ET_O_GREEN2, 0x00);
378 /*************/ 392 /*************/
379 reg_w_val(dev, ET_G_RED, 0x80); /* 0x4d */ 393 reg_w_val(gspca_dev, ET_G_RED, 0x80); /* 0x4d */
380 reg_w_val(dev, ET_G_GREEN1, 0x80); 394 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
381 reg_w_val(dev, ET_G_BLUE, 0x80); 395 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
382 reg_w_val(dev, ET_G_GREEN2, 0x80); 396 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
383 reg_w_val(dev, ET_G_GR_H, 0x00); 397 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
384 reg_w_val(dev, ET_G_GB_H, 0x00); /* 0x52 */ 398 reg_w_val(gspca_dev, ET_G_GB_H, 0x00); /* 0x52 */
385 /* Window control registers */ 399 /* Window control registers */
386 reg_w_val(dev, 0x61, 0x80); /* use cmc_out */ 400 reg_w_val(gspca_dev, 0x61, 0x80); /* use cmc_out */
387 reg_w_val(dev, 0x62, 0x02); 401 reg_w_val(gspca_dev, 0x62, 0x02);
388 reg_w_val(dev, 0x63, 0x03); 402 reg_w_val(gspca_dev, 0x63, 0x03);
389 reg_w_val(dev, 0x64, 0x14); 403 reg_w_val(gspca_dev, 0x64, 0x14);
390 reg_w_val(dev, 0x65, 0x0e); 404 reg_w_val(gspca_dev, 0x65, 0x0e);
391 reg_w_val(dev, 0x66, 0x02); 405 reg_w_val(gspca_dev, 0x66, 0x02);
392 reg_w_val(dev, 0x67, 0x02); 406 reg_w_val(gspca_dev, 0x67, 0x02);
393 407
394 /**************************************/ 408 /**************************************/
395 reg_w_val(dev, ET_SYNCHRO, 0x8f); /* 0x68 */ 409 reg_w_val(gspca_dev, ET_SYNCHRO, 0x8f); /* 0x68 */
396 reg_w_val(dev, ET_STARTX, 0x69); /* 0x6a //0x69 */ 410 reg_w_val(gspca_dev, ET_STARTX, 0x69); /* 0x6a //0x69 */
397 reg_w_val(dev, ET_STARTY, 0x0d); /* 0x0d //0x0c */ 411 reg_w_val(gspca_dev, ET_STARTY, 0x0d); /* 0x0d //0x0c */
398 reg_w_val(dev, ET_WIDTH_LOW, 0x80); 412 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x80);
399 reg_w_val(dev, ET_HEIGTH_LOW, 0xe0); 413 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0xe0);
400 reg_w_val(dev, ET_W_H_HEIGTH, 0x60); /* 6d */ 414 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x60); /* 6d */
401 reg_w_val(dev, ET_REG6e, 0x86); 415 reg_w_val(gspca_dev, ET_REG6e, 0x86);
402 reg_w_val(dev, ET_REG6f, 0x01); 416 reg_w_val(gspca_dev, ET_REG6f, 0x01);
403 reg_w_val(dev, ET_REG70, 0x26); 417 reg_w_val(gspca_dev, ET_REG70, 0x26);
404 reg_w_val(dev, ET_REG71, 0x7a); 418 reg_w_val(gspca_dev, ET_REG71, 0x7a);
405 reg_w_val(dev, ET_REG72, 0x01); 419 reg_w_val(gspca_dev, ET_REG72, 0x01);
406 /* Clock Pattern registers ***************** */ 420 /* Clock Pattern registers ***************** */
407 reg_w_val(dev, ET_REG73, 0x00); 421 reg_w_val(gspca_dev, ET_REG73, 0x00);
408 reg_w_val(dev, ET_REG74, 0x18); /* 0x28 */ 422 reg_w_val(gspca_dev, ET_REG74, 0x18); /* 0x28 */
409 reg_w_val(dev, ET_REG75, 0x0f); /* 0x01 */ 423 reg_w_val(gspca_dev, ET_REG75, 0x0f); /* 0x01 */
410 /**********************************************/ 424 /**********************************************/
411 reg_w_val(dev, 0x8a, 0x20); 425 reg_w_val(gspca_dev, 0x8a, 0x20);
412 reg_w_val(dev, 0x8d, 0x0f); 426 reg_w_val(gspca_dev, 0x8d, 0x0f);
413 reg_w_val(dev, 0x8e, 0x08); 427 reg_w_val(gspca_dev, 0x8e, 0x08);
414 /**************************************/ 428 /**************************************/
415 reg_w_val(dev, 0x03, 0x08); 429 reg_w_val(gspca_dev, 0x03, 0x08);
416 reg_w_val(dev, ET_PXL_CLK, 0x03); 430 reg_w_val(gspca_dev, ET_PXL_CLK, 0x03);
417 reg_w_val(dev, 0x81, 0xff); 431 reg_w_val(gspca_dev, 0x81, 0xff);
418 reg_w_val(dev, 0x80, 0x00); 432 reg_w_val(gspca_dev, 0x80, 0x00);
419 reg_w_val(dev, 0x81, 0xff); 433 reg_w_val(gspca_dev, 0x81, 0xff);
420 reg_w_val(dev, 0x80, 0x20); 434 reg_w_val(gspca_dev, 0x80, 0x20);
421 reg_w_val(dev, 0x03, 0x01); 435 reg_w_val(gspca_dev, 0x03, 0x01);
422 reg_w_val(dev, 0x03, 0x00); 436 reg_w_val(gspca_dev, 0x03, 0x00);
423 reg_w_val(dev, 0x03, 0x08); 437 reg_w_val(gspca_dev, 0x03, 0x08);
424 /********************************************/ 438 /********************************************/
425 439
426/* reg_r(dev, ET_I2C_BASE, &received, 1); 440/* reg_r(gspca_dev, ET_I2C_BASE, 1);
427 always 0x40 as the pas106 ??? */ 441 always 0x40 as the pas106 ??? */
428 /* set the sensor */ 442 /* set the sensor */
429 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) 443 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
@@ -435,25 +449,24 @@ static void Et_init2(struct gspca_dev *gspca_dev)
435 * 0x0b -> 24/(11+1) = 2 Mhz 449 * 0x0b -> 24/(11+1) = 2 Mhz
436 * 0x17 -> 24/(23+1) = 1 Mhz 450 * 0x17 -> 24/(23+1) = 1 Mhz
437 */ 451 */
438 reg_w_val(dev, ET_PXL_CLK, value); 452 reg_w_val(gspca_dev, ET_PXL_CLK, value);
439 /* now set by fifo the FormatLine setting */ 453 /* now set by fifo the FormatLine setting */
440 reg_w(dev, 0x62, FormLine, 6); 454 reg_w(gspca_dev, 0x62, FormLine, 6);
441 455
442 /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */ 456 /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */
443 reg_w_val(dev, 0x81, 0x47); /* 0x47; */ 457 reg_w_val(gspca_dev, 0x81, 0x47); /* 0x47; */
444 reg_w_val(dev, 0x80, 0x40); /* 0x40; */ 458 reg_w_val(gspca_dev, 0x80, 0x40); /* 0x40; */
445 /* Pedro change */ 459 /* Pedro change */
446 /* Brightness change Brith+ decrease value */ 460 /* Brightness change Brith+ decrease value */
447 /* Brigth- increase value */ 461 /* Brigth- increase value */
448 /* original value = 0x70; */ 462 /* original value = 0x70; */
449 reg_w_val(dev, 0x81, 0x30); /* 0x20; - set brightness */ 463 reg_w_val(gspca_dev, 0x81, 0x30); /* 0x20; - set brightness */
450 reg_w_val(dev, 0x80, 0x20); /* 0x20; */ 464 reg_w_val(gspca_dev, 0x80, 0x20); /* 0x20; */
451} 465}
452 466
453static void setcolors(struct gspca_dev *gspca_dev) 467static void setcolors(struct gspca_dev *gspca_dev)
454{ 468{
455 struct sd *sd = (struct sd *) gspca_dev; 469 struct sd *sd = (struct sd *) gspca_dev;
456 struct usb_device *dev = gspca_dev->dev;
457 __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d }; 470 __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d };
458 __u8 i2cflags = 0x01; 471 __u8 i2cflags = 0x01;
459 /* __u8 green = 0; */ 472 /* __u8 green = 0; */
@@ -464,8 +477,8 @@ static void setcolors(struct gspca_dev *gspca_dev)
464 /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */ 477 /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */
465 /* I2cc[1] = I2cc[2] = green; */ 478 /* I2cc[1] = I2cc[2] = green; */
466 if (sd->sensor == SENSOR_PAS106) { 479 if (sd->sensor == SENSOR_PAS106) {
467 Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3); 480 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
468 Et_i2cwrite(dev, PAS106_REG9, I2cc, sizeof I2cc, 1); 481 i2c_w(gspca_dev, PAS106_REG9, I2cc, sizeof I2cc, 1);
469 } 482 }
470/* PDEBUG(D_CONF , "Etoms red %d blue %d green %d", 483/* PDEBUG(D_CONF , "Etoms red %d blue %d green %d",
471 I2cc[3], I2cc[0], green); */ 484 I2cc[3], I2cc[0], green); */
@@ -474,21 +487,17 @@ static void setcolors(struct gspca_dev *gspca_dev)
474static void getcolors(struct gspca_dev *gspca_dev) 487static void getcolors(struct gspca_dev *gspca_dev)
475{ 488{
476 struct sd *sd = (struct sd *) gspca_dev; 489 struct sd *sd = (struct sd *) gspca_dev;
477/* __u8 valblue; */
478 __u8 valred;
479 490
480 if (sd->sensor == SENSOR_PAS106) { 491 if (sd->sensor == SENSOR_PAS106) {
481/* Et_i2cread(gspca_dev->dev, PAS106_REG9, &valblue, 1, 1); */ 492/* i2c_r(gspca_dev, PAS106_REG9); * blue */
482 Et_i2cread(gspca_dev->dev, PAS106_REG9 + 3, &valred, 1, 1); 493 i2c_r(gspca_dev, PAS106_REG9 + 3); /* red */
483 sd->colors = valred & 0x0f; 494 sd->colors = gspca_dev->usb_buf[0] & 0x0f;
484 } 495 }
485} 496}
486 497
487static void Et_init1(struct gspca_dev *gspca_dev) 498static void Et_init1(struct gspca_dev *gspca_dev)
488{ 499{
489 struct usb_device *dev = gspca_dev->dev;
490 __u8 value; 500 __u8 value;
491 __u8 received;
492/* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0x22, 0xac, 0x00, 0x01, 0x00}; */ 501/* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0x22, 0xac, 0x00, 0x01, 0x00}; */
493 __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 }; 502 __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 };
494 /* try 1/120 0x6d 0xcd 0x40 */ 503 /* try 1/120 0x6d 0xcd 0x40 */
@@ -496,12 +505,12 @@ static void Et_init1(struct gspca_dev *gspca_dev)
496 * 1/60000 hmm ?? */ 505 * 1/60000 hmm ?? */
497 506
498 PDEBUG(D_STREAM, "Open Init1 ET"); 507 PDEBUG(D_STREAM, "Open Init1 ET");
499 reg_w_val(dev, ET_GPIO_DIR_CTRL, 7); 508 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 7);
500 reg_r(dev, ET_GPIO_IN, &received, 1); 509 reg_r(gspca_dev, ET_GPIO_IN, 1);
501 reg_w_val(dev, ET_RESET_ALL, 1); 510 reg_w_val(gspca_dev, ET_RESET_ALL, 1);
502 reg_w_val(dev, ET_RESET_ALL, 0); 511 reg_w_val(gspca_dev, ET_RESET_ALL, 0);
503 reg_w_val(dev, ET_ClCK, 0x10); 512 reg_w_val(gspca_dev, ET_ClCK, 0x10);
504 reg_w_val(dev, ET_CTRL, 0x19); 513 reg_w_val(gspca_dev, ET_CTRL, 0x19);
505 /* compression et subsampling */ 514 /* compression et subsampling */
506 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) 515 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
507 value = ET_COMP_VAL1; 516 value = ET_COMP_VAL1;
@@ -510,80 +519,79 @@ static void Et_init1(struct gspca_dev *gspca_dev)
510 PDEBUG(D_STREAM, "Open mode %d Compression %d", 519 PDEBUG(D_STREAM, "Open mode %d Compression %d",
511 gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv, 520 gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv,
512 value); 521 value);
513 reg_w_val(dev, ET_COMP, value); 522 reg_w_val(gspca_dev, ET_COMP, value);
514 reg_w_val(dev, ET_MAXQt, 0x1d); 523 reg_w_val(gspca_dev, ET_MAXQt, 0x1d);
515 reg_w_val(dev, ET_MINQt, 0x02); 524 reg_w_val(gspca_dev, ET_MINQt, 0x02);
516 /* undocumented registers */ 525 /* undocumented registers */
517 reg_w_val(dev, ET_REG1d, 0xff); 526 reg_w_val(gspca_dev, ET_REG1d, 0xff);
518 reg_w_val(dev, ET_REG1e, 0xff); 527 reg_w_val(gspca_dev, ET_REG1e, 0xff);
519 reg_w_val(dev, ET_REG1f, 0xff); 528 reg_w_val(gspca_dev, ET_REG1f, 0xff);
520 reg_w_val(dev, ET_REG20, 0x35); 529 reg_w_val(gspca_dev, ET_REG20, 0x35);
521 reg_w_val(dev, ET_REG21, 0x01); 530 reg_w_val(gspca_dev, ET_REG21, 0x01);
522 reg_w_val(dev, ET_REG22, 0x00); 531 reg_w_val(gspca_dev, ET_REG22, 0x00);
523 reg_w_val(dev, ET_REG23, 0xf7); 532 reg_w_val(gspca_dev, ET_REG23, 0xf7);
524 reg_w_val(dev, ET_REG24, 0xff); 533 reg_w_val(gspca_dev, ET_REG24, 0xff);
525 reg_w_val(dev, ET_REG25, 0x07); 534 reg_w_val(gspca_dev, ET_REG25, 0x07);
526 /* colors setting */ 535 /* colors setting */
527 reg_w_val(dev, ET_G_RED, 0x80); 536 reg_w_val(gspca_dev, ET_G_RED, 0x80);
528 reg_w_val(dev, ET_G_GREEN1, 0x80); 537 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
529 reg_w_val(dev, ET_G_BLUE, 0x80); 538 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
530 reg_w_val(dev, ET_G_GREEN2, 0x80); 539 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
531 reg_w_val(dev, ET_G_GR_H, 0x00); 540 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
532 reg_w_val(dev, ET_G_GB_H, 0x00); 541 reg_w_val(gspca_dev, ET_G_GB_H, 0x00);
533 /* Window control registers */ 542 /* Window control registers */
534 reg_w_val(dev, ET_SYNCHRO, 0xf0); 543 reg_w_val(gspca_dev, ET_SYNCHRO, 0xf0);
535 reg_w_val(dev, ET_STARTX, 0x56); /* 0x56 */ 544 reg_w_val(gspca_dev, ET_STARTX, 0x56); /* 0x56 */
536 reg_w_val(dev, ET_STARTY, 0x05); /* 0x04 */ 545 reg_w_val(gspca_dev, ET_STARTY, 0x05); /* 0x04 */
537 reg_w_val(dev, ET_WIDTH_LOW, 0x60); 546 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x60);
538 reg_w_val(dev, ET_HEIGTH_LOW, 0x20); 547 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0x20);
539 reg_w_val(dev, ET_W_H_HEIGTH, 0x50); 548 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x50);
540 reg_w_val(dev, ET_REG6e, 0x86); 549 reg_w_val(gspca_dev, ET_REG6e, 0x86);
541 reg_w_val(dev, ET_REG6f, 0x01); 550 reg_w_val(gspca_dev, ET_REG6f, 0x01);
542 reg_w_val(dev, ET_REG70, 0x86); 551 reg_w_val(gspca_dev, ET_REG70, 0x86);
543 reg_w_val(dev, ET_REG71, 0x14); 552 reg_w_val(gspca_dev, ET_REG71, 0x14);
544 reg_w_val(dev, ET_REG72, 0x00); 553 reg_w_val(gspca_dev, ET_REG72, 0x00);
545 /* Clock Pattern registers */ 554 /* Clock Pattern registers */
546 reg_w_val(dev, ET_REG73, 0x00); 555 reg_w_val(gspca_dev, ET_REG73, 0x00);
547 reg_w_val(dev, ET_REG74, 0x00); 556 reg_w_val(gspca_dev, ET_REG74, 0x00);
548 reg_w_val(dev, ET_REG75, 0x0a); 557 reg_w_val(gspca_dev, ET_REG75, 0x0a);
549 reg_w_val(dev, ET_I2C_CLK, 0x04); 558 reg_w_val(gspca_dev, ET_I2C_CLK, 0x04);
550 reg_w_val(dev, ET_PXL_CLK, 0x01); 559 reg_w_val(gspca_dev, ET_PXL_CLK, 0x01);
551 /* set the sensor */ 560 /* set the sensor */
552 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 561 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
553 I2c0[0] = 0x06; 562 I2c0[0] = 0x06;
554 Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof I2c0, 1); 563 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
555 Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof I2c2, 1); 564 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
556 value = 0x06; 565 value = 0x06;
557 Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1); 566 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
558 Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof I2c3, 1); 567 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
559 /* value = 0x1f; */ 568 /* value = 0x1f; */
560 value = 0x04; 569 value = 0x04;
561 Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1); 570 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
562 } else { 571 } else {
563 I2c0[0] = 0x0a; 572 I2c0[0] = 0x0a;
564 573
565 Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof I2c0, 1); 574 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
566 Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof I2c2, 1); 575 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
567 value = 0x0a; 576 value = 0x0a;
568 577 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
569 Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1); 578 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
570 Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
571 value = 0x04; 579 value = 0x04;
572 /* value = 0x10; */ 580 /* value = 0x10; */
573 Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1); 581 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
574 /* bit 2 enable bit 1:2 select 0 1 2 3 582 /* bit 2 enable bit 1:2 select 0 1 2 3
575 value = 0x07; * curve 0 * 583 value = 0x07; * curve 0 *
576 Et_i2cwrite(dev,PAS106_REG0f,&value,1,1); 584 i2c_w(gspca_dev, PAS106_REG0f, &value, 1, 1);
577 */ 585 */
578 } 586 }
579 587
580/* value = 0x01; */ 588/* value = 0x01; */
581/* value = 0x22; */ 589/* value = 0x22; */
582/* Et_i2cwrite(dev, PAS106_REG5, &value, 1, 1); */ 590/* i2c_w(gspca_dev, PAS106_REG5, &value, 1, 1); */
583 /* magnetude and sign bit for DAC */ 591 /* magnetude and sign bit for DAC */
584 Et_i2cwrite(dev, PAS106_REG7, I2c4, sizeof I2c4, 1); 592 i2c_w(gspca_dev, PAS106_REG7, I2c4, sizeof I2c4, 1);
585 /* now set by fifo the whole colors setting */ 593 /* now set by fifo the whole colors setting */
586 reg_w(dev, ET_G_RED, GainRGBG, 6); 594 reg_w(gspca_dev, ET_G_RED, GainRGBG, 6);
587 getcolors(gspca_dev); 595 getcolors(gspca_dev);
588 setcolors(gspca_dev); 596 setcolors(gspca_dev);
589} 597}
@@ -632,14 +640,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
632static int sd_open(struct gspca_dev *gspca_dev) 640static int sd_open(struct gspca_dev *gspca_dev)
633{ 641{
634 struct sd *sd = (struct sd *) gspca_dev; 642 struct sd *sd = (struct sd *) gspca_dev;
635 struct usb_device *dev = gspca_dev->dev;
636 643
637 if (sd->sensor == SENSOR_PAS106) 644 if (sd->sensor == SENSOR_PAS106)
638 Et_init1(gspca_dev); 645 Et_init1(gspca_dev);
639 else 646 else
640 Et_init2(gspca_dev); 647 Et_init2(gspca_dev);
641 reg_w_val(dev, ET_RESET_ALL, 0x08); 648 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
642 et_video(dev, 0); /* video off */ 649 et_video(gspca_dev, 0); /* video off */
643 return 0; 650 return 0;
644} 651}
645 652
@@ -647,20 +654,19 @@ static int sd_open(struct gspca_dev *gspca_dev)
647static void sd_start(struct gspca_dev *gspca_dev) 654static void sd_start(struct gspca_dev *gspca_dev)
648{ 655{
649 struct sd *sd = (struct sd *) gspca_dev; 656 struct sd *sd = (struct sd *) gspca_dev;
650 struct usb_device *dev = gspca_dev->dev;
651 657
652 if (sd->sensor == SENSOR_PAS106) 658 if (sd->sensor == SENSOR_PAS106)
653 Et_init1(gspca_dev); 659 Et_init1(gspca_dev);
654 else 660 else
655 Et_init2(gspca_dev); 661 Et_init2(gspca_dev);
656 662
657 reg_w_val(dev, ET_RESET_ALL, 0x08); 663 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
658 et_video(dev, 1); /* video on */ 664 et_video(gspca_dev, 1); /* video on */
659} 665}
660 666
661static void sd_stopN(struct gspca_dev *gspca_dev) 667static void sd_stopN(struct gspca_dev *gspca_dev)
662{ 668{
663 et_video(gspca_dev->dev, 0); /* video off */ 669 et_video(gspca_dev, 0); /* video off */
664} 670}
665 671
666static void sd_stop0(struct gspca_dev *gspca_dev) 672static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -678,7 +684,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
678 __u8 brightness = sd->brightness; 684 __u8 brightness = sd->brightness;
679 685
680 for (i = 0; i < 4; i++) 686 for (i = 0; i < 4; i++)
681 reg_w_val(gspca_dev->dev, (ET_O_RED + i), brightness); 687 reg_w_val(gspca_dev, ET_O_RED + i, brightness);
682} 688}
683 689
684static void getbrightness(struct gspca_dev *gspca_dev) 690static void getbrightness(struct gspca_dev *gspca_dev)
@@ -686,11 +692,10 @@ static void getbrightness(struct gspca_dev *gspca_dev)
686 struct sd *sd = (struct sd *) gspca_dev; 692 struct sd *sd = (struct sd *) gspca_dev;
687 int i; 693 int i;
688 int brightness = 0; 694 int brightness = 0;
689 __u8 value;
690 695
691 for (i = 0; i < 4; i++) { 696 for (i = 0; i < 4; i++) {
692 reg_r(gspca_dev->dev, (ET_O_RED + i), &value, 1); 697 reg_r(gspca_dev, ET_O_RED + i, 1);
693 brightness += value; 698 brightness += gspca_dev->usb_buf[0];
694 } 699 }
695 sd->brightness = brightness >> 3; 700 sd->brightness = brightness >> 3;
696} 701}
@@ -701,8 +706,8 @@ static void setcontrast(struct gspca_dev *gspca_dev)
701 __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 }; 706 __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
702 __u8 contrast = sd->contrast; 707 __u8 contrast = sd->contrast;
703 708
704 memset(RGBG, contrast, sizeof RGBG - 2); 709 memset(RGBG, contrast, sizeof(RGBG) - 2);
705 reg_w(gspca_dev->dev, ET_G_RED, RGBG, 6); 710 reg_w(gspca_dev, ET_G_RED, RGBG, 6);
706} 711}
707 712
708static void getcontrast(struct gspca_dev *gspca_dev) 713static void getcontrast(struct gspca_dev *gspca_dev)
@@ -710,11 +715,10 @@ static void getcontrast(struct gspca_dev *gspca_dev)
710 struct sd *sd = (struct sd *) gspca_dev; 715 struct sd *sd = (struct sd *) gspca_dev;
711 int i; 716 int i;
712 int contrast = 0; 717 int contrast = 0;
713 __u8 value = 0;
714 718
715 for (i = 0; i < 4; i++) { 719 for (i = 0; i < 4; i++) {
716 reg_r(gspca_dev->dev, (ET_G_RED + i), &value, 1); 720 reg_r(gspca_dev, ET_G_RED + i, 1);
717 contrast += value; 721 contrast += gspca_dev->usb_buf[0];
718 } 722 }
719 sd->contrast = contrast >> 2; 723 sd->contrast = contrast >> 2;
720} 724}
@@ -722,12 +726,11 @@ static void getcontrast(struct gspca_dev *gspca_dev)
722static __u8 Et_getgainG(struct gspca_dev *gspca_dev) 726static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
723{ 727{
724 struct sd *sd = (struct sd *) gspca_dev; 728 struct sd *sd = (struct sd *) gspca_dev;
725 __u8 value = 0;
726 729
727 if (sd->sensor == SENSOR_PAS106) { 730 if (sd->sensor == SENSOR_PAS106) {
728 Et_i2cread(gspca_dev->dev, PAS106_REG0e, &value, 1, 1); 731 i2c_r(gspca_dev, PAS106_REG0e);
729 PDEBUG(D_CONF, "Etoms gain G %d", value); 732 PDEBUG(D_CONF, "Etoms gain G %d", gspca_dev->usb_buf[0]);
730 return value; 733 return gspca_dev->usb_buf[0];
731 } 734 }
732 return 0x1f; 735 return 0x1f;
733} 736}
@@ -735,12 +738,12 @@ static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
735static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain) 738static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
736{ 739{
737 struct sd *sd = (struct sd *) gspca_dev; 740 struct sd *sd = (struct sd *) gspca_dev;
738 struct usb_device *dev = gspca_dev->dev;
739 __u8 i2cflags = 0x01;
740 741
741 if (sd->sensor == SENSOR_PAS106) { 742 if (sd->sensor == SENSOR_PAS106) {
742 Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3); 743 __u8 i2cflags = 0x01;
743 Et_i2cwrite(dev, PAS106_REG0e, &gain, 1, 1); 744
745 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
746 i2c_w(gspca_dev, PAS106_REG0e, &gain, 1, 1);
744 } 747 }
745} 748}
746 749
@@ -751,8 +754,6 @@ static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
751 754
752static void setautogain(struct gspca_dev *gspca_dev) 755static void setautogain(struct gspca_dev *gspca_dev)
753{ 756{
754 struct usb_device *dev = gspca_dev->dev;
755 __u8 GRBG[] = { 0, 0, 0, 0 };
756 __u8 luma = 0; 757 __u8 luma = 0;
757 __u8 luma_mean = 128; 758 __u8 luma_mean = 128;
758 __u8 luma_delta = 20; 759 __u8 luma_delta = 20;
@@ -761,10 +762,10 @@ static void setautogain(struct gspca_dev *gspca_dev)
761 __u8 r, g, b; 762 __u8 r, g, b;
762 763
763 Gbright = Et_getgainG(gspca_dev); 764 Gbright = Et_getgainG(gspca_dev);
764 reg_r(dev, ET_LUMA_CENTER, GRBG, 4); 765 reg_r(gspca_dev, ET_LUMA_CENTER, 4);
765 g = (GRBG[0] + GRBG[3]) >> 1; 766 g = (gspca_dev->usb_buf[0] + gspca_dev->usb_buf[3]) >> 1;
766 r = GRBG[1]; 767 r = gspca_dev->usb_buf[1];
767 b = GRBG[2]; 768 b = gspca_dev->usb_buf[2];
768 r = ((r << 8) - (r << 4) - (r << 3)) >> 10; 769 r = ((r << 8) - (r << 4) - (r << 3)) >> 10;
769 b = ((b << 7) >> 10); 770 b = ((b << 7) >> 10);
770 g = ((g << 9) + (g << 7) + (g << 5)) >> 10; 771 g = ((g << 9) + (g << 7) + (g << 5)) >> 10;