etoms.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. /*
  2. * Etoms Et61x151 GPL Linux driver by Michel Xhaard (09/09/2004)
  3. *
  4. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #define MODULE_NAME "etoms"
  21. #include "gspca.h"
  22. #define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 4)
  23. static const char version[] = "2.1.4";
  24. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  25. MODULE_DESCRIPTION("Etoms USB Camera Driver");
  26. MODULE_LICENSE("GPL");
  27. /* specific webcam descriptor */
  28. struct sd {
  29. struct gspca_dev gspca_dev; /* !! must be the first item */
  30. unsigned char brightness;
  31. unsigned char contrast;
  32. unsigned char colors;
  33. unsigned char autogain;
  34. char sensor;
  35. #define SENSOR_PAS106 0
  36. #define SENSOR_TAS5130CXX 1
  37. signed char ag_cnt;
  38. #define AG_CNT_START 13
  39. };
  40. /* V4L2 controls supported by the driver */
  41. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  42. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  43. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  44. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  45. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  46. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  47. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  48. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  49. static struct ctrl sd_ctrls[] = {
  50. {
  51. {
  52. .id = V4L2_CID_BRIGHTNESS,
  53. .type = V4L2_CTRL_TYPE_INTEGER,
  54. .name = "Brightness",
  55. .minimum = 1,
  56. .maximum = 127,
  57. .step = 1,
  58. #define BRIGHTNESS_DEF 63
  59. .default_value = BRIGHTNESS_DEF,
  60. },
  61. .set = sd_setbrightness,
  62. .get = sd_getbrightness,
  63. },
  64. {
  65. {
  66. .id = V4L2_CID_CONTRAST,
  67. .type = V4L2_CTRL_TYPE_INTEGER,
  68. .name = "Contrast",
  69. .minimum = 0,
  70. .maximum = 255,
  71. .step = 1,
  72. #define CONTRAST_DEF 127
  73. .default_value = CONTRAST_DEF,
  74. },
  75. .set = sd_setcontrast,
  76. .get = sd_getcontrast,
  77. },
  78. {
  79. {
  80. .id = V4L2_CID_SATURATION,
  81. .type = V4L2_CTRL_TYPE_INTEGER,
  82. .name = "Color",
  83. .minimum = 0,
  84. .maximum = 15,
  85. .step = 1,
  86. #define COLOR_DEF 7
  87. .default_value = COLOR_DEF,
  88. },
  89. .set = sd_setcolors,
  90. .get = sd_getcolors,
  91. },
  92. {
  93. {
  94. .id = V4L2_CID_AUTOGAIN,
  95. .type = V4L2_CTRL_TYPE_BOOLEAN,
  96. .name = "Auto Gain",
  97. .minimum = 0,
  98. .maximum = 1,
  99. .step = 1,
  100. #define AUTOGAIN_DEF 1
  101. .default_value = AUTOGAIN_DEF,
  102. },
  103. .set = sd_setautogain,
  104. .get = sd_getautogain,
  105. },
  106. };
  107. static struct cam_mode vga_mode[] = {
  108. {V4L2_PIX_FMT_SBGGR8, 320, 240, 1},
  109. /* {V4L2_PIX_FMT_SBGGR8, 640, 480, 0}, */
  110. };
  111. static struct cam_mode sif_mode[] = {
  112. {V4L2_PIX_FMT_SBGGR8, 176, 144, 1},
  113. {V4L2_PIX_FMT_SBGGR8, 352, 288, 0},
  114. };
  115. #define ETOMS_ALT_SIZE_1000 12
  116. #define ET_GPIO_DIR_CTRL 0x04 /* Control IO bit[0..5] (0 in 1 out) */
  117. #define ET_GPIO_OUT 0x05 /* Only IO data */
  118. #define ET_GPIO_IN 0x06 /* Read Only IO data */
  119. #define ET_RESET_ALL 0x03
  120. #define ET_ClCK 0x01
  121. #define ET_CTRL 0x02 /* enable i2c OutClck Powerdown mode */
  122. #define ET_COMP 0x12 /* Compression register */
  123. #define ET_MAXQt 0x13
  124. #define ET_MINQt 0x14
  125. #define ET_COMP_VAL0 0x02
  126. #define ET_COMP_VAL1 0x03
  127. #define ET_REG1d 0x1d
  128. #define ET_REG1e 0x1e
  129. #define ET_REG1f 0x1f
  130. #define ET_REG20 0x20
  131. #define ET_REG21 0x21
  132. #define ET_REG22 0x22
  133. #define ET_REG23 0x23
  134. #define ET_REG24 0x24
  135. #define ET_REG25 0x25
  136. /* base registers for luma calculation */
  137. #define ET_LUMA_CENTER 0x39
  138. #define ET_G_RED 0x4d
  139. #define ET_G_GREEN1 0x4e
  140. #define ET_G_BLUE 0x4f
  141. #define ET_G_GREEN2 0x50
  142. #define ET_G_GR_H 0x51
  143. #define ET_G_GB_H 0x52
  144. #define ET_O_RED 0x34
  145. #define ET_O_GREEN1 0x35
  146. #define ET_O_BLUE 0x36
  147. #define ET_O_GREEN2 0x37
  148. #define ET_SYNCHRO 0x68
  149. #define ET_STARTX 0x69
  150. #define ET_STARTY 0x6a
  151. #define ET_WIDTH_LOW 0x6b
  152. #define ET_HEIGTH_LOW 0x6c
  153. #define ET_W_H_HEIGTH 0x6d
  154. #define ET_REG6e 0x6e /* OBW */
  155. #define ET_REG6f 0x6f /* OBW */
  156. #define ET_REG70 0x70 /* OBW_AWB */
  157. #define ET_REG71 0x71 /* OBW_AWB */
  158. #define ET_REG72 0x72 /* OBW_AWB */
  159. #define ET_REG73 0x73 /* Clkdelay ns */
  160. #define ET_REG74 0x74 /* test pattern */
  161. #define ET_REG75 0x75 /* test pattern */
  162. #define ET_I2C_CLK 0x8c
  163. #define ET_PXL_CLK 0x60
  164. #define ET_I2C_BASE 0x89
  165. #define ET_I2C_COUNT 0x8a
  166. #define ET_I2C_PREFETCH 0x8b
  167. #define ET_I2C_REG 0x88
  168. #define ET_I2C_DATA7 0x87
  169. #define ET_I2C_DATA6 0x86
  170. #define ET_I2C_DATA5 0x85
  171. #define ET_I2C_DATA4 0x84
  172. #define ET_I2C_DATA3 0x83
  173. #define ET_I2C_DATA2 0x82
  174. #define ET_I2C_DATA1 0x81
  175. #define ET_I2C_DATA0 0x80
  176. #define PAS106_REG2 0x02 /* pxlClk = systemClk/(reg2) */
  177. #define PAS106_REG3 0x03 /* line/frame H [11..4] */
  178. #define PAS106_REG4 0x04 /* line/frame L [3..0] */
  179. #define PAS106_REG5 0x05 /* exposure time line offset(default 5) */
  180. #define PAS106_REG6 0x06 /* exposure time pixel offset(default 6) */
  181. #define PAS106_REG7 0x07 /* signbit Dac (default 0) */
  182. #define PAS106_REG9 0x09
  183. #define PAS106_REG0e 0x0e /* global gain [4..0](default 0x0e) */
  184. #define PAS106_REG13 0x13 /* end i2c write */
  185. static const __u8 GainRGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
  186. static const __u8 I2c2[] = { 0x08, 0x08, 0x08, 0x08, 0x0d };
  187. static const __u8 I2c3[] = { 0x12, 0x05 };
  188. static const __u8 I2c4[] = { 0x41, 0x08 };
  189. static void reg_r(struct usb_device *dev,
  190. __u16 index, __u8 *buffer, int len)
  191. {
  192. usb_control_msg(dev,
  193. usb_rcvctrlpipe(dev, 0),
  194. 0,
  195. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  196. 0, index, buffer, len, 500);
  197. }
  198. static void reg_w_val(struct usb_device *dev,
  199. __u16 index, __u8 val)
  200. {
  201. __u8 data;
  202. data = val;
  203. usb_control_msg(dev,
  204. usb_sndctrlpipe(dev, 0),
  205. 0,
  206. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  207. 0, index, &data, 1, 500);
  208. }
  209. static void reg_w(struct usb_device *dev,
  210. __u16 index, const __u8 *buffer, __u16 len)
  211. {
  212. __u8 tmpbuf[8];
  213. memcpy(tmpbuf, buffer, len);
  214. usb_control_msg(dev,
  215. usb_sndctrlpipe(dev, 0),
  216. 0,
  217. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  218. 0, index, tmpbuf, len, 500);
  219. }
  220. static int Et_i2cwrite(struct usb_device *dev, __u8 reg,
  221. const __u8 *buffer,
  222. __u16 len, __u8 mode)
  223. {
  224. /* buffer should be [D0..D7] */
  225. __u8 ptchcount;
  226. /* set the base address */
  227. reg_w_val(dev, ET_I2C_BASE, 0x40); /* sensor base for the pas106 */
  228. /* set count and prefetch */
  229. ptchcount = ((len & 0x07) << 4) | (mode & 0x03);
  230. reg_w_val(dev, ET_I2C_COUNT, ptchcount);
  231. /* set the register base */
  232. reg_w_val(dev, ET_I2C_REG, reg);
  233. while (--len >= 0)
  234. reg_w_val(dev, ET_I2C_DATA0 + len, buffer[len]);
  235. return 0;
  236. }
  237. static int Et_i2cread(struct usb_device *dev, __u8 reg,
  238. __u8 *buffer,
  239. __u16 length, __u8 mode)
  240. {
  241. /* buffer should be [D0..D7] */
  242. int i, j;
  243. __u8 ptchcount;
  244. /* set the base address */
  245. reg_w_val(dev, ET_I2C_BASE, 0x40); /* sensor base for the pas106 */
  246. /* set count and prefetch */
  247. ptchcount = ((length & 0x07) << 4) | (mode & 0x03);
  248. reg_w_val(dev, ET_I2C_COUNT, ptchcount);
  249. /* set the register base */
  250. reg_w_val(dev, ET_I2C_REG, reg);
  251. reg_w_val(dev, ET_I2C_PREFETCH, 0x02); /* prefetch */
  252. reg_w_val(dev, ET_I2C_PREFETCH, 0);
  253. j = length - 1;
  254. for (i = 0; i < length; i++) {
  255. reg_r(dev, (ET_I2C_DATA0 + j), &buffer[j], 1);
  256. j--;
  257. }
  258. return 0;
  259. }
  260. static int Et_WaitStatus(struct usb_device *dev)
  261. {
  262. __u8 bytereceived;
  263. int retry = 10;
  264. while (retry--) {
  265. reg_r(dev, ET_ClCK, &bytereceived, 1);
  266. if (bytereceived != 0)
  267. return 1;
  268. }
  269. return 0;
  270. }
  271. static int et_video(struct usb_device *dev, int on)
  272. {
  273. int err;
  274. reg_w_val(dev, ET_GPIO_OUT, on
  275. ? 0x10 /* startvideo - set Bit5 */
  276. : 0); /* stopvideo */
  277. err = Et_WaitStatus(dev);
  278. if (!err)
  279. PDEBUG(D_ERR, "timeout video on/off");
  280. return err;
  281. }
  282. static void Et_init2(struct gspca_dev *gspca_dev)
  283. {
  284. struct usb_device *dev = gspca_dev->dev;
  285. __u8 value;
  286. __u8 received;
  287. static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 };
  288. PDEBUG(D_STREAM, "Open Init2 ET");
  289. reg_w_val(dev, ET_GPIO_DIR_CTRL, 0x2f);
  290. reg_w_val(dev, ET_GPIO_OUT, 0x10);
  291. reg_r(dev, ET_GPIO_IN, &received, 1);
  292. reg_w_val(dev, ET_ClCK, 0x14); /* 0x14 // 0x16 enabled pattern */
  293. reg_w_val(dev, ET_CTRL, 0x1b);
  294. /* compression et subsampling */
  295. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode)
  296. value = ET_COMP_VAL1; /* 320 */
  297. else
  298. value = ET_COMP_VAL0; /* 640 */
  299. reg_w_val(dev, ET_COMP, value);
  300. reg_w_val(dev, ET_MAXQt, 0x1f);
  301. reg_w_val(dev, ET_MINQt, 0x04);
  302. /* undocumented registers */
  303. reg_w_val(dev, ET_REG1d, 0xff);
  304. reg_w_val(dev, ET_REG1e, 0xff);
  305. reg_w_val(dev, ET_REG1f, 0xff);
  306. reg_w_val(dev, ET_REG20, 0x35);
  307. reg_w_val(dev, ET_REG21, 0x01);
  308. reg_w_val(dev, ET_REG22, 0x00);
  309. reg_w_val(dev, ET_REG23, 0xff);
  310. reg_w_val(dev, ET_REG24, 0xff);
  311. reg_w_val(dev, ET_REG25, 0x0f);
  312. /* colors setting */
  313. reg_w_val(dev, 0x30, 0x11); /* 0x30 */
  314. reg_w_val(dev, 0x31, 0x40);
  315. reg_w_val(dev, 0x32, 0x00);
  316. reg_w_val(dev, ET_O_RED, 0x00); /* 0x34 */
  317. reg_w_val(dev, ET_O_GREEN1, 0x00);
  318. reg_w_val(dev, ET_O_BLUE, 0x00);
  319. reg_w_val(dev, ET_O_GREEN2, 0x00);
  320. /*************/
  321. reg_w_val(dev, ET_G_RED, 0x80); /* 0x4d */
  322. reg_w_val(dev, ET_G_GREEN1, 0x80);
  323. reg_w_val(dev, ET_G_BLUE, 0x80);
  324. reg_w_val(dev, ET_G_GREEN2, 0x80);
  325. reg_w_val(dev, ET_G_GR_H, 0x00);
  326. reg_w_val(dev, ET_G_GB_H, 0x00); /* 0x52 */
  327. /* Window control registers */
  328. reg_w_val(dev, 0x61, 0x80); /* use cmc_out */
  329. reg_w_val(dev, 0x62, 0x02);
  330. reg_w_val(dev, 0x63, 0x03);
  331. reg_w_val(dev, 0x64, 0x14);
  332. reg_w_val(dev, 0x65, 0x0e);
  333. reg_w_val(dev, 0x66, 0x02);
  334. reg_w_val(dev, 0x67, 0x02);
  335. /**************************************/
  336. reg_w_val(dev, ET_SYNCHRO, 0x8f); /* 0x68 */
  337. reg_w_val(dev, ET_STARTX, 0x69); /* 0x6a //0x69 */
  338. reg_w_val(dev, ET_STARTY, 0x0d); /* 0x0d //0x0c */
  339. reg_w_val(dev, ET_WIDTH_LOW, 0x80);
  340. reg_w_val(dev, ET_HEIGTH_LOW, 0xe0);
  341. reg_w_val(dev, ET_W_H_HEIGTH, 0x60); /* 6d */
  342. reg_w_val(dev, ET_REG6e, 0x86);
  343. reg_w_val(dev, ET_REG6f, 0x01);
  344. reg_w_val(dev, ET_REG70, 0x26);
  345. reg_w_val(dev, ET_REG71, 0x7a);
  346. reg_w_val(dev, ET_REG72, 0x01);
  347. /* Clock Pattern registers ***************** */
  348. reg_w_val(dev, ET_REG73, 0x00);
  349. reg_w_val(dev, ET_REG74, 0x18); /* 0x28 */
  350. reg_w_val(dev, ET_REG75, 0x0f); /* 0x01 */
  351. /**********************************************/
  352. reg_w_val(dev, 0x8a, 0x20);
  353. reg_w_val(dev, 0x8d, 0x0f);
  354. reg_w_val(dev, 0x8e, 0x08);
  355. /**************************************/
  356. reg_w_val(dev, 0x03, 0x08);
  357. reg_w_val(dev, ET_PXL_CLK, 0x03);
  358. reg_w_val(dev, 0x81, 0xff);
  359. reg_w_val(dev, 0x80, 0x00);
  360. reg_w_val(dev, 0x81, 0xff);
  361. reg_w_val(dev, 0x80, 0x20);
  362. reg_w_val(dev, 0x03, 0x01);
  363. reg_w_val(dev, 0x03, 0x00);
  364. reg_w_val(dev, 0x03, 0x08);
  365. /********************************************/
  366. /* reg_r(dev, ET_I2C_BASE, &received, 1);
  367. always 0x40 as the pas106 ??? */
  368. /* set the sensor */
  369. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode)
  370. value = 0x04; /* 320 */
  371. else /* 640 */
  372. value = 0x1e; /* 0x17 * setting PixelClock
  373. * 0x03 mean 24/(3+1) = 6 Mhz
  374. * 0x05 -> 24/(5+1) = 4 Mhz
  375. * 0x0b -> 24/(11+1) = 2 Mhz
  376. * 0x17 -> 24/(23+1) = 1 Mhz
  377. */
  378. reg_w_val(dev, ET_PXL_CLK, value);
  379. /* now set by fifo the FormatLine setting */
  380. reg_w(dev, 0x62, FormLine, 6);
  381. /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */
  382. reg_w_val(dev, 0x81, 0x47); /* 0x47; */
  383. reg_w_val(dev, 0x80, 0x40); /* 0x40; */
  384. /* Pedro change */
  385. /* Brightness change Brith+ decrease value */
  386. /* Brigth- increase value */
  387. /* original value = 0x70; */
  388. reg_w_val(dev, 0x81, 0x30); /* 0x20; - set brightness */
  389. reg_w_val(dev, 0x80, 0x20); /* 0x20; */
  390. }
  391. static void setcolors(struct gspca_dev *gspca_dev)
  392. {
  393. struct sd *sd = (struct sd *) gspca_dev;
  394. struct usb_device *dev = gspca_dev->dev;
  395. __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d };
  396. __u8 i2cflags = 0x01;
  397. /* __u8 green = 0; */
  398. __u8 colors = sd->colors;
  399. I2cc[3] = colors; /* red */
  400. I2cc[0] = 15 - colors; /* blue */
  401. /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */
  402. /* I2cc[1] = I2cc[2] = green; */
  403. if (sd->sensor == SENSOR_PAS106) {
  404. Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3);
  405. Et_i2cwrite(dev, PAS106_REG9, I2cc, sizeof I2cc, 1);
  406. }
  407. /* PDEBUG(D_CONF , "Etoms red %d blue %d green %d",
  408. I2cc[3], I2cc[0], green); */
  409. }
  410. static void getcolors(struct gspca_dev *gspca_dev)
  411. {
  412. struct sd *sd = (struct sd *) gspca_dev;
  413. /* __u8 valblue; */
  414. __u8 valred;
  415. if (sd->sensor == SENSOR_PAS106) {
  416. /* Et_i2cread(gspca_dev->dev, PAS106_REG9, &valblue, 1, 1); */
  417. Et_i2cread(gspca_dev->dev, PAS106_REG9 + 3, &valred, 1, 1);
  418. sd->colors = valred & 0x0f;
  419. }
  420. }
  421. static void Et_init1(struct gspca_dev *gspca_dev)
  422. {
  423. struct usb_device *dev = gspca_dev->dev;
  424. __u8 value;
  425. __u8 received;
  426. /* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0x22, 0xac, 0x00, 0x01, 0x00}; */
  427. __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 };
  428. /* try 1/120 0x6d 0xcd 0x40 */
  429. /* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0xfe, 0xfe, 0xc0, 0x01, 0x00};
  430. * 1/60000 hmm ?? */
  431. PDEBUG(D_STREAM, "Open Init1 ET");
  432. reg_w_val(dev, ET_GPIO_DIR_CTRL, 7);
  433. reg_r(dev, ET_GPIO_IN, &received, 1);
  434. reg_w_val(dev, ET_RESET_ALL, 1);
  435. reg_w_val(dev, ET_RESET_ALL, 0);
  436. reg_w_val(dev, ET_ClCK, 0x10);
  437. reg_w_val(dev, ET_CTRL, 0x19);
  438. /* compression et subsampling */
  439. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode)
  440. value = ET_COMP_VAL1;
  441. else
  442. value = ET_COMP_VAL0;
  443. PDEBUG(D_STREAM, "Open mode %d Compression %d",
  444. gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode,
  445. value);
  446. reg_w_val(dev, ET_COMP, value);
  447. reg_w_val(dev, ET_MAXQt, 0x1d);
  448. reg_w_val(dev, ET_MINQt, 0x02);
  449. /* undocumented registers */
  450. reg_w_val(dev, ET_REG1d, 0xff);
  451. reg_w_val(dev, ET_REG1e, 0xff);
  452. reg_w_val(dev, ET_REG1f, 0xff);
  453. reg_w_val(dev, ET_REG20, 0x35);
  454. reg_w_val(dev, ET_REG21, 0x01);
  455. reg_w_val(dev, ET_REG22, 0x00);
  456. reg_w_val(dev, ET_REG23, 0xf7);
  457. reg_w_val(dev, ET_REG24, 0xff);
  458. reg_w_val(dev, ET_REG25, 0x07);
  459. /* colors setting */
  460. reg_w_val(dev, ET_G_RED, 0x80);
  461. reg_w_val(dev, ET_G_GREEN1, 0x80);
  462. reg_w_val(dev, ET_G_BLUE, 0x80);
  463. reg_w_val(dev, ET_G_GREEN2, 0x80);
  464. reg_w_val(dev, ET_G_GR_H, 0x00);
  465. reg_w_val(dev, ET_G_GB_H, 0x00);
  466. /* Window control registers */
  467. reg_w_val(dev, ET_SYNCHRO, 0xf0);
  468. reg_w_val(dev, ET_STARTX, 0x56); /* 0x56 */
  469. reg_w_val(dev, ET_STARTY, 0x05); /* 0x04 */
  470. reg_w_val(dev, ET_WIDTH_LOW, 0x60);
  471. reg_w_val(dev, ET_HEIGTH_LOW, 0x20);
  472. reg_w_val(dev, ET_W_H_HEIGTH, 0x50);
  473. reg_w_val(dev, ET_REG6e, 0x86);
  474. reg_w_val(dev, ET_REG6f, 0x01);
  475. reg_w_val(dev, ET_REG70, 0x86);
  476. reg_w_val(dev, ET_REG71, 0x14);
  477. reg_w_val(dev, ET_REG72, 0x00);
  478. /* Clock Pattern registers */
  479. reg_w_val(dev, ET_REG73, 0x00);
  480. reg_w_val(dev, ET_REG74, 0x00);
  481. reg_w_val(dev, ET_REG75, 0x0a);
  482. reg_w_val(dev, ET_I2C_CLK, 0x04);
  483. reg_w_val(dev, ET_PXL_CLK, 0x01);
  484. /* set the sensor */
  485. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode) {
  486. I2c0[0] = 0x06;
  487. Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
  488. Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
  489. value = 0x06;
  490. Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1);
  491. Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
  492. /* value = 0x1f; */
  493. value = 0x04;
  494. Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1);
  495. } else {
  496. I2c0[0] = 0x0a;
  497. Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
  498. Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
  499. value = 0x0a;
  500. Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1);
  501. Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
  502. value = 0x04;
  503. /* value = 0x10; */
  504. Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1);
  505. /* bit 2 enable bit 1:2 select 0 1 2 3
  506. value = 0x07; * curve 0 *
  507. Et_i2cwrite(dev,PAS106_REG0f,&value,1,1);
  508. */
  509. }
  510. /* value = 0x01; */
  511. /* value = 0x22; */
  512. /* Et_i2cwrite(dev, PAS106_REG5, &value, 1, 1); */
  513. /* magnetude and sign bit for DAC */
  514. Et_i2cwrite(dev, PAS106_REG7, I2c4, sizeof I2c4, 1);
  515. /* now set by fifo the whole colors setting */
  516. reg_w(dev, ET_G_RED, GainRGBG, 6);
  517. getcolors(gspca_dev);
  518. setcolors(gspca_dev);
  519. }
  520. /* this function is called at probe time */
  521. static int sd_config(struct gspca_dev *gspca_dev,
  522. const struct usb_device_id *id)
  523. {
  524. struct sd *sd = (struct sd *) gspca_dev;
  525. struct cam *cam;
  526. __u16 vendor;
  527. __u16 product;
  528. vendor = id->idVendor;
  529. product = id->idProduct;
  530. /* switch (vendor) { */
  531. /* case 0x102c: * Etoms */
  532. switch (product) {
  533. case 0x6151:
  534. sd->sensor = SENSOR_PAS106; /* Etoms61x151 */
  535. break;
  536. case 0x6251:
  537. sd->sensor = SENSOR_TAS5130CXX; /* Etoms61x251 */
  538. break;
  539. /* } */
  540. /* break; */
  541. }
  542. cam = &gspca_dev->cam;
  543. cam->dev_name = (char *) id->driver_info;
  544. cam->epaddr = 1;
  545. if (sd->sensor == SENSOR_PAS106) {
  546. cam->cam_mode = sif_mode;
  547. cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
  548. } else {
  549. cam->cam_mode = vga_mode;
  550. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  551. }
  552. sd->brightness = BRIGHTNESS_DEF;
  553. sd->contrast = CONTRAST_DEF;
  554. sd->colors = COLOR_DEF;
  555. sd->autogain = AUTOGAIN_DEF;
  556. return 0;
  557. }
  558. /* this function is called at open time */
  559. static int sd_open(struct gspca_dev *gspca_dev)
  560. {
  561. struct sd *sd = (struct sd *) gspca_dev;
  562. struct usb_device *dev = gspca_dev->dev;
  563. if (sd->sensor == SENSOR_PAS106)
  564. Et_init1(gspca_dev);
  565. else
  566. Et_init2(gspca_dev);
  567. reg_w_val(dev, ET_RESET_ALL, 0x08);
  568. et_video(dev, 0); /* video off */
  569. return 0;
  570. }
  571. /* -- start the camera -- */
  572. static void sd_start(struct gspca_dev *gspca_dev)
  573. {
  574. struct sd *sd = (struct sd *) gspca_dev;
  575. struct usb_device *dev = gspca_dev->dev;
  576. if (sd->sensor == SENSOR_PAS106)
  577. Et_init1(gspca_dev);
  578. else
  579. Et_init2(gspca_dev);
  580. reg_w_val(dev, ET_RESET_ALL, 0x08);
  581. et_video(dev, 1); /* video on */
  582. }
  583. static void sd_stopN(struct gspca_dev *gspca_dev)
  584. {
  585. et_video(gspca_dev->dev, 0); /* video off */
  586. }
  587. static void sd_stop0(struct gspca_dev *gspca_dev)
  588. {
  589. }
  590. static void sd_close(struct gspca_dev *gspca_dev)
  591. {
  592. }
  593. static void setbrightness(struct gspca_dev *gspca_dev)
  594. {
  595. struct sd *sd = (struct sd *) gspca_dev;
  596. int i;
  597. __u8 brightness = sd->brightness;
  598. for (i = 0; i < 4; i++)
  599. reg_w_val(gspca_dev->dev, (ET_O_RED + i), brightness);
  600. }
  601. static void getbrightness(struct gspca_dev *gspca_dev)
  602. {
  603. struct sd *sd = (struct sd *) gspca_dev;
  604. int i;
  605. int brightness = 0;
  606. __u8 value;
  607. for (i = 0; i < 4; i++) {
  608. reg_r(gspca_dev->dev, (ET_O_RED + i), &value, 1);
  609. brightness += value;
  610. }
  611. sd->brightness = brightness >> 3;
  612. }
  613. static void setcontrast(struct gspca_dev *gspca_dev)
  614. {
  615. struct sd *sd = (struct sd *) gspca_dev;
  616. __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
  617. __u8 contrast = sd->contrast;
  618. memset(RGBG, contrast, sizeof RGBG - 2);
  619. reg_w(gspca_dev->dev, ET_G_RED, RGBG, 6);
  620. }
  621. static void getcontrast(struct gspca_dev *gspca_dev)
  622. {
  623. struct sd *sd = (struct sd *) gspca_dev;
  624. int i;
  625. int contrast = 0;
  626. __u8 value = 0;
  627. for (i = 0; i < 4; i++) {
  628. reg_r(gspca_dev->dev, (ET_G_RED + i), &value, 1);
  629. contrast += value;
  630. }
  631. sd->contrast = contrast >> 2;
  632. }
  633. static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
  634. {
  635. struct sd *sd = (struct sd *) gspca_dev;
  636. __u8 value = 0;
  637. if (sd->sensor == SENSOR_PAS106) {
  638. Et_i2cread(gspca_dev->dev, PAS106_REG0e, &value, 1, 1);
  639. PDEBUG(D_CONF, "Etoms gain G %d", value);
  640. return value;
  641. }
  642. return 0x1f;
  643. }
  644. static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
  645. {
  646. struct sd *sd = (struct sd *) gspca_dev;
  647. struct usb_device *dev = gspca_dev->dev;
  648. __u8 i2cflags = 0x01;
  649. if (sd->sensor == SENSOR_PAS106) {
  650. Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3);
  651. Et_i2cwrite(dev, PAS106_REG0e, &gain, 1, 1);
  652. }
  653. }
  654. #define BLIMIT(bright) \
  655. (__u8)((bright > 0x1f)?0x1f:((bright < 4)?3:bright))
  656. #define LIMIT(color) \
  657. (unsigned char)((color > 0xff)?0xff:((color < 0)?0:color))
  658. static void setautogain(struct gspca_dev *gspca_dev)
  659. {
  660. struct usb_device *dev = gspca_dev->dev;
  661. __u8 GRBG[] = { 0, 0, 0, 0 };
  662. __u8 luma = 0;
  663. __u8 luma_mean = 128;
  664. __u8 luma_delta = 20;
  665. __u8 spring = 4;
  666. int Gbright = 0;
  667. __u8 r, g, b;
  668. Gbright = Et_getgainG(gspca_dev);
  669. reg_r(dev, ET_LUMA_CENTER, GRBG, 4);
  670. g = (GRBG[0] + GRBG[3]) >> 1;
  671. r = GRBG[1];
  672. b = GRBG[2];
  673. r = ((r << 8) - (r << 4) - (r << 3)) >> 10;
  674. b = ((b << 7) >> 10);
  675. g = ((g << 9) + (g << 7) + (g << 5)) >> 10;
  676. luma = LIMIT(r + g + b);
  677. PDEBUG(D_FRAM, "Etoms luma G %d", luma);
  678. if (luma < luma_mean - luma_delta || luma > luma_mean + luma_delta) {
  679. Gbright += (luma_mean - luma) >> spring;
  680. Gbright = BLIMIT(Gbright);
  681. PDEBUG(D_FRAM, "Etoms Gbright %d", Gbright);
  682. Et_setgainG(gspca_dev, (__u8) Gbright);
  683. }
  684. }
  685. #undef BLIMIT
  686. #undef LIMIT
  687. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  688. struct gspca_frame *frame, /* target */
  689. __u8 *data, /* isoc packet */
  690. int len) /* iso packet length */
  691. {
  692. struct sd *sd;
  693. int seqframe;
  694. seqframe = data[0] & 0x3f;
  695. len = (int) (((data[0] & 0xc0) << 2) | data[1]);
  696. if (seqframe == 0x3f) {
  697. PDEBUG(D_FRAM,
  698. "header packet found datalength %d !!", len);
  699. PDEBUG(D_FRAM, "G %d R %d G %d B %d",
  700. data[2], data[3], data[4], data[5]);
  701. data += 30;
  702. /* don't change datalength as the chips provided it */
  703. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  704. data, 0);
  705. gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
  706. sd = (struct sd *) gspca_dev;
  707. if (sd->ag_cnt >= 0) {
  708. if (--sd->ag_cnt < 0) {
  709. sd->ag_cnt = AG_CNT_START;
  710. setautogain(gspca_dev);
  711. }
  712. }
  713. return;
  714. }
  715. if (len) {
  716. data += 8;
  717. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  718. } else { /* Drop Packet */
  719. gspca_dev->last_packet_type = DISCARD_PACKET;
  720. }
  721. }
  722. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  723. {
  724. struct sd *sd = (struct sd *) gspca_dev;
  725. sd->brightness = val;
  726. if (gspca_dev->streaming)
  727. setbrightness(gspca_dev);
  728. return 0;
  729. }
  730. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  731. {
  732. struct sd *sd = (struct sd *) gspca_dev;
  733. getbrightness(gspca_dev);
  734. *val = sd->brightness;
  735. return 0;
  736. }
  737. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  738. {
  739. struct sd *sd = (struct sd *) gspca_dev;
  740. sd->contrast = val;
  741. if (gspca_dev->streaming)
  742. setcontrast(gspca_dev);
  743. return 0;
  744. }
  745. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  746. {
  747. struct sd *sd = (struct sd *) gspca_dev;
  748. getcontrast(gspca_dev);
  749. *val = sd->contrast;
  750. return 0;
  751. }
  752. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  753. {
  754. struct sd *sd = (struct sd *) gspca_dev;
  755. sd->colors = val;
  756. if (gspca_dev->streaming)
  757. setcolors(gspca_dev);
  758. return 0;
  759. }
  760. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  761. {
  762. struct sd *sd = (struct sd *) gspca_dev;
  763. getcolors(gspca_dev);
  764. *val = sd->colors;
  765. return 0;
  766. }
  767. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  768. {
  769. struct sd *sd = (struct sd *) gspca_dev;
  770. sd->autogain = val;
  771. if (val)
  772. sd->ag_cnt = AG_CNT_START;
  773. else
  774. sd->ag_cnt = -1;
  775. return 0;
  776. }
  777. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  778. {
  779. struct sd *sd = (struct sd *) gspca_dev;
  780. *val = sd->autogain;
  781. return 0;
  782. }
  783. /* sub-driver description */
  784. static struct sd_desc sd_desc = {
  785. .name = MODULE_NAME,
  786. .ctrls = sd_ctrls,
  787. .nctrls = ARRAY_SIZE(sd_ctrls),
  788. .config = sd_config,
  789. .open = sd_open,
  790. .start = sd_start,
  791. .stopN = sd_stopN,
  792. .stop0 = sd_stop0,
  793. .close = sd_close,
  794. .pkt_scan = sd_pkt_scan,
  795. };
  796. /* -- module initialisation -- */
  797. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  798. static __devinitdata struct usb_device_id device_table[] = {
  799. {USB_DEVICE(0x102c, 0x6151), DVNM("Qcam Sangha CIF")},
  800. {USB_DEVICE(0x102c, 0x6251), DVNM("Qcam xxxxxx VGA")},
  801. {}
  802. };
  803. MODULE_DEVICE_TABLE(usb, device_table);
  804. /* -- device connect -- */
  805. static int sd_probe(struct usb_interface *intf,
  806. const struct usb_device_id *id)
  807. {
  808. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  809. THIS_MODULE);
  810. }
  811. static struct usb_driver sd_driver = {
  812. .name = MODULE_NAME,
  813. .id_table = device_table,
  814. .probe = sd_probe,
  815. .disconnect = gspca_disconnect,
  816. };
  817. /* -- module insert / remove -- */
  818. static int __init sd_mod_init(void)
  819. {
  820. if (usb_register(&sd_driver) < 0)
  821. return -1;
  822. PDEBUG(D_PROBE, "v%s registered", version);
  823. return 0;
  824. }
  825. static void __exit sd_mod_exit(void)
  826. {
  827. usb_deregister(&sd_driver);
  828. PDEBUG(D_PROBE, "deregistered");
  829. }
  830. module_init(sd_mod_init);
  831. module_exit(sd_mod_exit);