etoms.c 25 KB

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