etoms.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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, 0)
  23. static const char version[] = "2.1.0";
  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. #define SD_BRIGHTNESS 0
  51. {
  52. {
  53. .id = V4L2_CID_BRIGHTNESS,
  54. .type = V4L2_CTRL_TYPE_INTEGER,
  55. .name = "Brightness",
  56. .minimum = 1,
  57. .maximum = 127,
  58. .step = 1,
  59. .default_value = 63,
  60. },
  61. .set = sd_setbrightness,
  62. .get = sd_getbrightness,
  63. },
  64. #define SD_CONTRAST 1
  65. {
  66. {
  67. .id = V4L2_CID_CONTRAST,
  68. .type = V4L2_CTRL_TYPE_INTEGER,
  69. .name = "Contrast",
  70. .minimum = 0,
  71. .maximum = 255,
  72. .step = 1,
  73. .default_value = 127,
  74. },
  75. .set = sd_setcontrast,
  76. .get = sd_getcontrast,
  77. },
  78. #define SD_COLOR 2
  79. {
  80. {
  81. .id = V4L2_CID_SATURATION,
  82. .type = V4L2_CTRL_TYPE_INTEGER,
  83. .name = "Color",
  84. .minimum = 0,
  85. .maximum = 15,
  86. .step = 1,
  87. .default_value = 7,
  88. },
  89. .set = sd_setcolors,
  90. .get = sd_getcolors,
  91. },
  92. #define SD_AUTOGAIN 3
  93. {
  94. {
  95. .id = V4L2_CID_AUTOGAIN,
  96. .type = V4L2_CTRL_TYPE_BOOLEAN,
  97. .name = "Auto Gain",
  98. .minimum = 0,
  99. .maximum = 1,
  100. .step = 1,
  101. .default_value = 1,
  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 __u8 GainRGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
  186. static __u8 I2c2[] = { 0x08, 0x08, 0x08, 0x08, 0x0d };
  187. static __u8 I2c3[] = { 0x12, 0x05 };
  188. static __u8 I2c4[] = { 0x41, 0x08 };
  189. static void Et_RegRead(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 Et_RegWrite(struct usb_device *dev,
  199. __u16 index, __u8 *buffer, __u16 len)
  200. {
  201. usb_control_msg(dev,
  202. usb_sndctrlpipe(dev, 0),
  203. 0,
  204. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  205. 0, index, buffer, len, 500);
  206. }
  207. static int Et_i2cwrite(struct usb_device *dev, __u8 reg, __u8 * buffer,
  208. __u16 length, __u8 mode)
  209. {
  210. /* buffer should be [D0..D7] */
  211. int i, j;
  212. __u8 base = 0x40; /* sensor base for the pas106 */
  213. __u8 ptchcount = 0;
  214. ptchcount = (((length & 0x07) << 4) | (mode & 0x03));
  215. /* set the base address */
  216. Et_RegWrite(dev, ET_I2C_BASE, &base, 1);
  217. /* set count and prefetch */
  218. Et_RegWrite(dev, ET_I2C_COUNT, &ptchcount, 1);
  219. /* set the register base */
  220. Et_RegWrite(dev, ET_I2C_REG, &reg, 1);
  221. j = length - 1;
  222. for (i = 0; i < length; i++) {
  223. Et_RegWrite(dev, (ET_I2C_DATA0 + j), &buffer[j], 1);
  224. j--;
  225. }
  226. return 0;
  227. }
  228. static int Et_i2cread(struct usb_device *dev, __u8 reg, __u8 * buffer,
  229. __u16 length, __u8 mode)
  230. {
  231. /* buffer should be [D0..D7] */
  232. int i, j;
  233. __u8 base = 0x40; /* sensor base for the pas106 */
  234. __u8 ptchcount;
  235. __u8 prefetch = 0x02;
  236. ptchcount = (((length & 0x07) << 4) | (mode & 0x03));
  237. /* set the base address */
  238. Et_RegWrite(dev, ET_I2C_BASE, &base, 1);
  239. /* set count and prefetch */
  240. Et_RegWrite(dev, ET_I2C_COUNT, &ptchcount, 1);
  241. /* set the register base */
  242. Et_RegWrite(dev, ET_I2C_REG, &reg, 1);
  243. Et_RegWrite(dev, ET_I2C_PREFETCH, &prefetch, 1);
  244. prefetch = 0x00;
  245. Et_RegWrite(dev, ET_I2C_PREFETCH, &prefetch, 1);
  246. j = length - 1;
  247. for (i = 0; i < length; i++) {
  248. Et_RegRead(dev, (ET_I2C_DATA0 + j), &buffer[j], 1);
  249. j--;
  250. }
  251. return 0;
  252. }
  253. static int Et_WaitStatus(struct usb_device *dev)
  254. {
  255. __u8 bytereceived;
  256. int retry = 10;
  257. while (retry--) {
  258. Et_RegRead(dev, ET_ClCK, &bytereceived, 1);
  259. if (bytereceived != 0)
  260. return 1;
  261. }
  262. return 0;
  263. }
  264. static int Et_videoOff(struct usb_device *dev)
  265. {
  266. int err;
  267. __u8 stopvideo = 0;
  268. Et_RegWrite(dev, ET_GPIO_OUT, &stopvideo, 1);
  269. err = Et_WaitStatus(dev);
  270. if (!err)
  271. PDEBUG(D_ERR, "timeout Et_waitStatus VideoON");
  272. return err;
  273. }
  274. static int Et_videoOn(struct usb_device *dev)
  275. {
  276. int err;
  277. __u8 startvideo = 0x10; /* set Bit5 */
  278. Et_RegWrite(dev, ET_GPIO_OUT, &startvideo, 1);
  279. err = Et_WaitStatus(dev);
  280. if (!err)
  281. PDEBUG(D_ERR, "timeout Et_waitStatus VideoOFF");
  282. return err;
  283. }
  284. static void Et_init2(struct gspca_dev *gspca_dev)
  285. {
  286. struct usb_device *dev = gspca_dev->dev;
  287. __u8 value = 0x00;
  288. __u8 received = 0x00;
  289. __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 };
  290. PDEBUG(D_STREAM, "Open Init2 ET");
  291. value = 0x2f;
  292. Et_RegWrite(dev, ET_GPIO_DIR_CTRL, &value, 1);
  293. value = 0x10;
  294. Et_RegWrite(dev, ET_GPIO_OUT, &value, 1);
  295. Et_RegRead(dev, ET_GPIO_IN, &received, 1);
  296. value = 0x14; /* 0x14 // 0x16 enabled pattern */
  297. Et_RegWrite(dev, ET_ClCK, &value, 1);
  298. value = 0x1b;
  299. Et_RegWrite(dev, ET_CTRL, &value, 1);
  300. /* compression et subsampling */
  301. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode)
  302. value = ET_COMP_VAL1; /* 320 */
  303. else
  304. value = ET_COMP_VAL0; /* 640 */
  305. Et_RegWrite(dev, ET_COMP, &value, 1);
  306. value = 0x1f;
  307. Et_RegWrite(dev, ET_MAXQt, &value, 1);
  308. value = 0x04;
  309. Et_RegWrite(dev, ET_MINQt, &value, 1);
  310. /* undocumented registers */
  311. value = 0xff;
  312. Et_RegWrite(dev, ET_REG1d, &value, 1);
  313. value = 0xff;
  314. Et_RegWrite(dev, ET_REG1e, &value, 1);
  315. value = 0xff;
  316. Et_RegWrite(dev, ET_REG1f, &value, 1);
  317. value = 0x35;
  318. Et_RegWrite(dev, ET_REG20, &value, 1);
  319. value = 0x01;
  320. Et_RegWrite(dev, ET_REG21, &value, 1);
  321. value = 0x00;
  322. Et_RegWrite(dev, ET_REG22, &value, 1);
  323. value = 0xff;
  324. Et_RegWrite(dev, ET_REG23, &value, 1);
  325. value = 0xff;
  326. Et_RegWrite(dev, ET_REG24, &value, 1);
  327. value = 0x0f;
  328. Et_RegWrite(dev, ET_REG25, &value, 1);
  329. /* colors setting */
  330. value = 0x11;
  331. Et_RegWrite(dev, 0x30, &value, 1); /* 0x30 */
  332. value = 0x40;
  333. Et_RegWrite(dev, 0x31, &value, 1);
  334. value = 0x00;
  335. Et_RegWrite(dev, 0x32, &value, 1);
  336. value = 0x00;
  337. Et_RegWrite(dev, ET_O_RED, &value, 1); /* 0x34 */
  338. value = 0x00;
  339. Et_RegWrite(dev, ET_O_GREEN1, &value, 1);
  340. value = 0x00;
  341. Et_RegWrite(dev, ET_O_BLUE, &value, 1);
  342. value = 0x00;
  343. Et_RegWrite(dev, ET_O_GREEN2, &value, 1);
  344. /*************/
  345. value = 0x80;
  346. Et_RegWrite(dev, ET_G_RED, &value, 1); /* 0x4d */
  347. value = 0x80;
  348. Et_RegWrite(dev, ET_G_GREEN1, &value, 1);
  349. value = 0x80;
  350. Et_RegWrite(dev, ET_G_BLUE, &value, 1);
  351. value = 0x80;
  352. Et_RegWrite(dev, ET_G_GREEN2, &value, 1);
  353. value = 0x00;
  354. Et_RegWrite(dev, ET_G_GR_H, &value, 1);
  355. value = 0x00;
  356. Et_RegWrite(dev, ET_G_GB_H, &value, 1); /* 0x52 */
  357. /* Window control registers */
  358. value = 0x80; /* use cmc_out */
  359. Et_RegWrite(dev, 0x61, &value, 1);
  360. value = 0x02;
  361. Et_RegWrite(dev, 0x62, &value, 1);
  362. value = 0x03;
  363. Et_RegWrite(dev, 0x63, &value, 1);
  364. value = 0x14;
  365. Et_RegWrite(dev, 0x64, &value, 1);
  366. value = 0x0e;
  367. Et_RegWrite(dev, 0x65, &value, 1);
  368. value = 0x02;
  369. Et_RegWrite(dev, 0x66, &value, 1);
  370. value = 0x02;
  371. Et_RegWrite(dev, 0x67, &value, 1);
  372. /**************************************/
  373. value = 0x8f;
  374. Et_RegWrite(dev, ET_SYNCHRO, &value, 1); /* 0x68 */
  375. value = 0x69; /* 0x6a //0x69 */
  376. Et_RegWrite(dev, ET_STARTX, &value, 1);
  377. value = 0x0d; /* 0x0d //0x0c */
  378. Et_RegWrite(dev, ET_STARTY, &value, 1);
  379. value = 0x80;
  380. Et_RegWrite(dev, ET_WIDTH_LOW, &value, 1);
  381. value = 0xe0;
  382. Et_RegWrite(dev, ET_HEIGTH_LOW, &value, 1);
  383. value = 0x60;
  384. Et_RegWrite(dev, ET_W_H_HEIGTH, &value, 1); /* 6d */
  385. value = 0x86;
  386. Et_RegWrite(dev, ET_REG6e, &value, 1);
  387. value = 0x01;
  388. Et_RegWrite(dev, ET_REG6f, &value, 1);
  389. value = 0x26;
  390. Et_RegWrite(dev, ET_REG70, &value, 1);
  391. value = 0x7a;
  392. Et_RegWrite(dev, ET_REG71, &value, 1);
  393. value = 0x01;
  394. Et_RegWrite(dev, ET_REG72, &value, 1);
  395. /* Clock Pattern registers ***************** */
  396. value = 0x00;
  397. Et_RegWrite(dev, ET_REG73, &value, 1);
  398. value = 0x18; /* 0x28 */
  399. Et_RegWrite(dev, ET_REG74, &value, 1);
  400. value = 0x0f; /* 0x01 */
  401. Et_RegWrite(dev, ET_REG75, &value, 1);
  402. /**********************************************/
  403. value = 0x20;
  404. Et_RegWrite(dev, 0x8a, &value, 1);
  405. value = 0x0f;
  406. Et_RegWrite(dev, 0x8d, &value, 1);
  407. value = 0x08;
  408. Et_RegWrite(dev, 0x8e, &value, 1);
  409. /**************************************/
  410. value = 0x08;
  411. Et_RegWrite(dev, 0x03, &value, 1);
  412. value = 0x03;
  413. Et_RegWrite(dev, ET_PXL_CLK, &value, 1);
  414. value = 0xff;
  415. Et_RegWrite(dev, 0x81, &value, 1);
  416. value = 0x00;
  417. Et_RegWrite(dev, 0x80, &value, 1);
  418. value = 0xff;
  419. Et_RegWrite(dev, 0x81, &value, 1);
  420. value = 0x20;
  421. Et_RegWrite(dev, 0x80, &value, 1);
  422. value = 0x01;
  423. Et_RegWrite(dev, 0x03, &value, 1);
  424. value = 0x00;
  425. Et_RegWrite(dev, 0x03, &value, 1);
  426. value = 0x08;
  427. Et_RegWrite(dev, 0x03, &value, 1);
  428. /********************************************/
  429. /* Et_RegRead(dev,0x0,ET_I2C_BASE,&received,1);
  430. always 0x40 as the pas106 ??? */
  431. /* set the sensor */
  432. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode) {
  433. value = 0x04; /* 320 */
  434. Et_RegWrite(dev, ET_PXL_CLK, &value, 1);
  435. /* now set by fifo the FormatLine setting */
  436. Et_RegWrite(dev, 0x62, FormLine, 6);
  437. } else { /* 640 */
  438. /* setting PixelClock
  439. 0x03 mean 24/(3+1) = 6 Mhz
  440. 0x05 -> 24/(5+1) = 4 Mhz
  441. 0x0b -> 24/(11+1) = 2 Mhz
  442. 0x17 -> 24/(23+1) = 1 Mhz
  443. */
  444. value = 0x1e; /* 0x17 */
  445. Et_RegWrite(dev, ET_PXL_CLK, &value, 1);
  446. /* now set by fifo the FormatLine setting */
  447. Et_RegWrite(dev, 0x62, FormLine, 6);
  448. }
  449. /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */
  450. value = 0x47; /* 0x47; */
  451. Et_RegWrite(dev, 0x81, &value, 1);
  452. value = 0x40; /* 0x40; */
  453. Et_RegWrite(dev, 0x80, &value, 1);
  454. /* Pedro change */
  455. /* Brightness change Brith+ decrease value */
  456. /* Brigth- increase value */
  457. /* original value = 0x70; */
  458. value = 0x30; /* 0x20; */
  459. Et_RegWrite(dev, 0x81, &value, 1); /* set brightness */
  460. value = 0x20; /* 0x20; */
  461. Et_RegWrite(dev, 0x80, &value, 1);
  462. }
  463. static void setcolors(struct gspca_dev *gspca_dev)
  464. {
  465. struct sd *sd = (struct sd *) gspca_dev;
  466. struct usb_device *dev = gspca_dev->dev;
  467. static __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d };
  468. __u8 i2cflags = 0x01;
  469. /* __u8 green = 0; */
  470. __u8 colors = sd->colors;
  471. I2cc[3] = colors; /* red */
  472. I2cc[0] = 15 - colors; /* blue */
  473. /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */
  474. /* I2cc[1] = I2cc[2] = green; */
  475. if (sd->sensor == SENSOR_PAS106) {
  476. Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3);
  477. Et_i2cwrite(dev, PAS106_REG9, I2cc, sizeof(I2cc), 1);
  478. }
  479. /* PDEBUG(D_CONF , "Etoms red %d blue %d green %d",
  480. I2cc[3], I2cc[0], green); */
  481. }
  482. static void getcolors(struct gspca_dev *gspca_dev)
  483. {
  484. struct sd *sd = (struct sd *) gspca_dev;
  485. /* __u8 valblue = 0; */
  486. __u8 valred;
  487. if (sd->sensor == SENSOR_PAS106) {
  488. /* Et_i2cread(gspca_dev->dev,PAS106_REG9,&valblue,1,1); */
  489. Et_i2cread(gspca_dev->dev, PAS106_REG9 + 3, &valred, 1, 1);
  490. sd->colors = valred & 0x0f;
  491. }
  492. }
  493. static void Et_init1(struct gspca_dev *gspca_dev)
  494. {
  495. struct usb_device *dev = gspca_dev->dev;
  496. __u8 value = 0x00;
  497. __u8 received = 0x00;
  498. /* __u8 I2c0 [] ={0x0a,0x12,0x05,0x22,0xac,0x00,0x01,0x00}; */
  499. __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 };
  500. /* try 1/120 0x6d 0xcd 0x40 */
  501. /* __u8 I2c0 [] ={0x0a,0x12,0x05,0xfe,0xfe,0xc0,0x01,0x00};
  502. * 1/60000 hmm ?? */
  503. PDEBUG(D_STREAM, "Open Init1 ET");
  504. value = 7;
  505. Et_RegWrite(dev, ET_GPIO_DIR_CTRL, &value, 1);
  506. Et_RegRead(dev, ET_GPIO_IN, &received, 1);
  507. value = 1;
  508. Et_RegWrite(dev, ET_RESET_ALL, &value, 1);
  509. value = 0;
  510. Et_RegWrite(dev, ET_RESET_ALL, &value, 1);
  511. value = 0x10;
  512. Et_RegWrite(dev, ET_ClCK, &value, 1);
  513. value = 0x19;
  514. Et_RegWrite(dev, ET_CTRL, &value, 1);
  515. /* compression et subsampling */
  516. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode)
  517. value = ET_COMP_VAL1;
  518. else
  519. value = ET_COMP_VAL0;
  520. PDEBUG(D_STREAM, "Open mode %d Compression %d",
  521. gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode,
  522. value);
  523. Et_RegWrite(dev, ET_COMP, &value, 1);
  524. value = 0x1d;
  525. Et_RegWrite(dev, ET_MAXQt, &value, 1);
  526. value = 0x02;
  527. Et_RegWrite(dev, ET_MINQt, &value, 1);
  528. /* undocumented registers */
  529. value = 0xff;
  530. Et_RegWrite(dev, ET_REG1d, &value, 1);
  531. value = 0xff;
  532. Et_RegWrite(dev, ET_REG1e, &value, 1);
  533. value = 0xff;
  534. Et_RegWrite(dev, ET_REG1f, &value, 1);
  535. value = 0x35;
  536. Et_RegWrite(dev, ET_REG20, &value, 1);
  537. value = 0x01;
  538. Et_RegWrite(dev, ET_REG21, &value, 1);
  539. value = 0x00;
  540. Et_RegWrite(dev, ET_REG22, &value, 1);
  541. value = 0xf7;
  542. Et_RegWrite(dev, ET_REG23, &value, 1);
  543. value = 0xff;
  544. Et_RegWrite(dev, ET_REG24, &value, 1);
  545. value = 0x07;
  546. Et_RegWrite(dev, ET_REG25, &value, 1);
  547. /* colors setting */
  548. value = 0x80;
  549. Et_RegWrite(dev, ET_G_RED, &value, 1);
  550. value = 0x80;
  551. Et_RegWrite(dev, ET_G_GREEN1, &value, 1);
  552. value = 0x80;
  553. Et_RegWrite(dev, ET_G_BLUE, &value, 1);
  554. value = 0x80;
  555. Et_RegWrite(dev, ET_G_GREEN2, &value, 1);
  556. value = 0x00;
  557. Et_RegWrite(dev, ET_G_GR_H, &value, 1);
  558. value = 0x00;
  559. Et_RegWrite(dev, ET_G_GB_H, &value, 1);
  560. /* Window control registers */
  561. value = 0xf0;
  562. Et_RegWrite(dev, ET_SYNCHRO, &value, 1);
  563. value = 0x56; /* 0x56 */
  564. Et_RegWrite(dev, ET_STARTX, &value, 1);
  565. value = 0x05; /* 0x04 */
  566. Et_RegWrite(dev, ET_STARTY, &value, 1);
  567. value = 0x60;
  568. Et_RegWrite(dev, ET_WIDTH_LOW, &value, 1);
  569. value = 0x20;
  570. Et_RegWrite(dev, ET_HEIGTH_LOW, &value, 1);
  571. value = 0x50;
  572. Et_RegWrite(dev, ET_W_H_HEIGTH, &value, 1);
  573. value = 0x86;
  574. Et_RegWrite(dev, ET_REG6e, &value, 1);
  575. value = 0x01;
  576. Et_RegWrite(dev, ET_REG6f, &value, 1);
  577. value = 0x86;
  578. Et_RegWrite(dev, ET_REG70, &value, 1);
  579. value = 0x14;
  580. Et_RegWrite(dev, ET_REG71, &value, 1);
  581. value = 0x00;
  582. Et_RegWrite(dev, ET_REG72, &value, 1);
  583. /* Clock Pattern registers */
  584. value = 0x00;
  585. Et_RegWrite(dev, ET_REG73, &value, 1);
  586. value = 0x00;
  587. Et_RegWrite(dev, ET_REG74, &value, 1);
  588. value = 0x0a;
  589. Et_RegWrite(dev, ET_REG75, &value, 1);
  590. value = 0x04;
  591. Et_RegWrite(dev, ET_I2C_CLK, &value, 1);
  592. value = 0x01;
  593. Et_RegWrite(dev, ET_PXL_CLK, &value, 1);
  594. /* set the sensor */
  595. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode) {
  596. I2c0[0] = 0x06;
  597. Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof(I2c0), 1);
  598. Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof(I2c2), 1);
  599. value = 0x06;
  600. Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1);
  601. Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof(I2c3), 1);
  602. /* value = 0x1f; */
  603. value = 0x04;
  604. Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1);
  605. } else {
  606. I2c0[0] = 0x0a;
  607. Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof(I2c0), 1);
  608. Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof(I2c2), 1);
  609. value = 0x0a;
  610. Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1);
  611. Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof(I2c3), 1);
  612. value = 0x04;
  613. /* value = 0x10; */
  614. Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1);
  615. /* bit 2 enable bit 1:2 select 0 1 2 3
  616. value = 0x07; * curve 0 *
  617. Et_i2cwrite(dev,PAS106_REG0f,&value,1,1);
  618. */
  619. }
  620. /* value = 0x01; */
  621. /* value = 0x22; */
  622. /* Et_i2cwrite(dev, PAS106_REG5, &value, 1, 1); */
  623. /* magnetude and sign bit for DAC */
  624. Et_i2cwrite(dev, PAS106_REG7, I2c4, sizeof I2c4, 1);
  625. /* now set by fifo the whole colors setting */
  626. Et_RegWrite(dev, ET_G_RED, GainRGBG, 6);
  627. getcolors(gspca_dev);
  628. setcolors(gspca_dev);
  629. }
  630. /* this function is called at probe time */
  631. static int sd_config(struct gspca_dev *gspca_dev,
  632. const struct usb_device_id *id)
  633. {
  634. struct sd *sd = (struct sd *) gspca_dev;
  635. struct cam *cam;
  636. __u16 vendor;
  637. __u16 product;
  638. vendor = id->idVendor;
  639. product = id->idProduct;
  640. /* switch (vendor) { */
  641. /* case 0x102c: * Etoms */
  642. switch (product) {
  643. case 0x6151:
  644. sd->sensor = SENSOR_PAS106; /* Etoms61x151 */
  645. break;
  646. case 0x6251:
  647. sd->sensor = SENSOR_TAS5130CXX; /* Etoms61x251 */
  648. break;
  649. /* } */
  650. /* break; */
  651. }
  652. cam = &gspca_dev->cam;
  653. cam->dev_name = (char *) id->driver_info;
  654. cam->epaddr = 1;
  655. if (sd->sensor == SENSOR_PAS106) {
  656. cam->cam_mode = sif_mode;
  657. cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
  658. } else {
  659. cam->cam_mode = vga_mode;
  660. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  661. }
  662. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  663. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  664. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  665. sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value;
  666. return 0;
  667. }
  668. /* this function is called at open time */
  669. static int sd_open(struct gspca_dev *gspca_dev)
  670. {
  671. struct sd *sd = (struct sd *) gspca_dev;
  672. struct usb_device *dev = gspca_dev->dev;
  673. int err;
  674. __u8 value;
  675. PDEBUG(D_STREAM, "Initialize ET1");
  676. if (sd->sensor == SENSOR_PAS106)
  677. Et_init1(gspca_dev);
  678. else
  679. Et_init2(gspca_dev);
  680. value = 0x08;
  681. Et_RegWrite(dev, ET_RESET_ALL, &value, 1);
  682. err = Et_videoOff(dev);
  683. PDEBUG(D_STREAM, "Et_Init_VideoOff %d", err);
  684. return 0;
  685. }
  686. /* -- start the camera -- */
  687. static void sd_start(struct gspca_dev *gspca_dev)
  688. {
  689. struct sd *sd = (struct sd *) gspca_dev;
  690. struct usb_device *dev = gspca_dev->dev;
  691. int err;
  692. __u8 value;
  693. if (sd->sensor == SENSOR_PAS106)
  694. Et_init1(gspca_dev);
  695. else
  696. Et_init2(gspca_dev);
  697. value = 0x08;
  698. Et_RegWrite(dev, ET_RESET_ALL, &value, 1);
  699. err = Et_videoOn(dev);
  700. PDEBUG(D_STREAM, "Et_VideoOn %d", err);
  701. }
  702. static void sd_stopN(struct gspca_dev *gspca_dev)
  703. {
  704. int err;
  705. err = Et_videoOff(gspca_dev->dev);
  706. PDEBUG(D_STREAM, "Et_VideoOff %d", err);
  707. }
  708. static void sd_stop0(struct gspca_dev *gspca_dev)
  709. {
  710. }
  711. static void sd_close(struct gspca_dev *gspca_dev)
  712. {
  713. }
  714. static void setbrightness(struct gspca_dev *gspca_dev)
  715. {
  716. struct sd *sd = (struct sd *) gspca_dev;
  717. int i;
  718. __u8 brightness = sd->brightness;
  719. for (i = 0; i < 4; i++)
  720. Et_RegWrite(gspca_dev->dev, (ET_O_RED + i), &brightness, 1);
  721. }
  722. static void getbrightness(struct gspca_dev *gspca_dev)
  723. {
  724. struct sd *sd = (struct sd *) gspca_dev;
  725. int i;
  726. int brightness = 0;
  727. __u8 value = 0;
  728. for (i = 0; i < 4; i++) {
  729. Et_RegRead(gspca_dev->dev, (ET_O_RED + i), &value, 1);
  730. brightness += value;
  731. }
  732. sd->brightness = brightness >> 3;
  733. }
  734. static void setcontrast(struct gspca_dev *gspca_dev)
  735. {
  736. struct sd *sd = (struct sd *) gspca_dev;
  737. __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
  738. __u8 contrast = sd->contrast;
  739. memset(RGBG, contrast, sizeof RGBG - 2);
  740. Et_RegWrite(gspca_dev->dev, ET_G_RED, RGBG, 6);
  741. }
  742. static void getcontrast(struct gspca_dev *gspca_dev)
  743. {
  744. struct sd *sd = (struct sd *) gspca_dev;
  745. int i;
  746. int contrast = 0;
  747. __u8 value = 0;
  748. for (i = 0; i < 4; i++) {
  749. Et_RegRead(gspca_dev->dev, (ET_G_RED + i), &value, 1);
  750. contrast += value;
  751. }
  752. sd->contrast = contrast >> 2;
  753. }
  754. static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
  755. {
  756. struct sd *sd = (struct sd *) gspca_dev;
  757. __u8 value = 0;
  758. if (sd->sensor == SENSOR_PAS106) {
  759. Et_i2cread(gspca_dev->dev, PAS106_REG0e, &value, 1, 1);
  760. PDEBUG(D_CONF, "Etoms gain G %d", value);
  761. return value;
  762. }
  763. return 0x1f;
  764. }
  765. static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
  766. {
  767. struct sd *sd = (struct sd *) gspca_dev;
  768. struct usb_device *dev = gspca_dev->dev;
  769. __u8 i2cflags = 0x01;
  770. if (sd->sensor == SENSOR_PAS106) {
  771. Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3);
  772. Et_i2cwrite(dev, PAS106_REG0e, &gain, 1, 1);
  773. }
  774. }
  775. #define BLIMIT(bright) \
  776. (__u8)((bright > 0x1f)?0x1f:((bright < 4)?3:bright))
  777. #define LIMIT(color) \
  778. (unsigned char)((color > 0xff)?0xff:((color < 0)?0:color))
  779. static void setautogain(struct gspca_dev *gspca_dev)
  780. {
  781. struct usb_device *dev = gspca_dev->dev;
  782. __u8 GRBG[] = { 0, 0, 0, 0 };
  783. __u8 luma = 0;
  784. __u8 luma_mean = 128;
  785. __u8 luma_delta = 20;
  786. __u8 spring = 4;
  787. int Gbright = 0;
  788. __u8 r, g, b;
  789. Gbright = Et_getgainG(gspca_dev);
  790. Et_RegRead(dev, ET_LUMA_CENTER, GRBG, 4);
  791. g = (GRBG[0] + GRBG[3]) >> 1;
  792. r = GRBG[1];
  793. b = GRBG[2];
  794. r = ((r << 8) - (r << 4) - (r << 3)) >> 10;
  795. b = ((b << 7) >> 10);
  796. g = ((g << 9) + (g << 7) + (g << 5)) >> 10;
  797. luma = LIMIT(r + g + b);
  798. PDEBUG(D_FRAM, "Etoms luma G %d", luma);
  799. if (luma < luma_mean - luma_delta || luma > luma_mean + luma_delta) {
  800. Gbright += (luma_mean - luma) >> spring;
  801. Gbright = BLIMIT(Gbright);
  802. PDEBUG(D_FRAM, "Etoms Gbright %d", Gbright);
  803. Et_setgainG(gspca_dev, (__u8) Gbright);
  804. }
  805. }
  806. #undef BLIMIT
  807. #undef LIMIT
  808. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  809. struct gspca_frame *frame, /* target */
  810. unsigned char *data, /* isoc packet */
  811. int len) /* iso packet length */
  812. {
  813. struct sd *sd;
  814. int seqframe;
  815. seqframe = data[0] & 0x3f;
  816. len = (int) (((data[0] & 0xc0) << 2) | data[1]);
  817. if (seqframe == 0x3f) {
  818. PDEBUG(D_FRAM,
  819. "header packet found datalength %d !!", len);
  820. PDEBUG(D_FRAM, "G %d R %d G %d B %d",
  821. data[2], data[3], data[4], data[5]);
  822. data += 30;
  823. /* don't change datalength as the chips provided it */
  824. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  825. data, 0);
  826. gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
  827. sd = (struct sd *) gspca_dev;
  828. if (sd->ag_cnt >= 0) {
  829. if (--sd->ag_cnt < 0) {
  830. sd->ag_cnt = AG_CNT_START;
  831. setautogain(gspca_dev);
  832. }
  833. }
  834. return;
  835. }
  836. if (len) {
  837. data += 8;
  838. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  839. } else { /* Drop Packet */
  840. gspca_dev->last_packet_type = DISCARD_PACKET;
  841. }
  842. }
  843. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  844. {
  845. struct sd *sd = (struct sd *) gspca_dev;
  846. sd->brightness = val;
  847. if (gspca_dev->streaming)
  848. setbrightness(gspca_dev);
  849. return 0;
  850. }
  851. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  852. {
  853. struct sd *sd = (struct sd *) gspca_dev;
  854. getbrightness(gspca_dev);
  855. *val = sd->brightness;
  856. return 0;
  857. }
  858. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  859. {
  860. struct sd *sd = (struct sd *) gspca_dev;
  861. sd->contrast = val;
  862. if (gspca_dev->streaming)
  863. setcontrast(gspca_dev);
  864. return 0;
  865. }
  866. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  867. {
  868. struct sd *sd = (struct sd *) gspca_dev;
  869. getcontrast(gspca_dev);
  870. *val = sd->contrast;
  871. return 0;
  872. }
  873. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  874. {
  875. struct sd *sd = (struct sd *) gspca_dev;
  876. sd->colors = val;
  877. if (gspca_dev->streaming)
  878. setcolors(gspca_dev);
  879. return 0;
  880. }
  881. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  882. {
  883. struct sd *sd = (struct sd *) gspca_dev;
  884. getcolors(gspca_dev);
  885. *val = sd->colors;
  886. return 0;
  887. }
  888. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  889. {
  890. struct sd *sd = (struct sd *) gspca_dev;
  891. sd->autogain = val;
  892. if (val)
  893. sd->ag_cnt = AG_CNT_START;
  894. else
  895. sd->ag_cnt = -1;
  896. return 0;
  897. }
  898. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  899. {
  900. struct sd *sd = (struct sd *) gspca_dev;
  901. *val = sd->autogain;
  902. return 0;
  903. }
  904. /* sub-driver description */
  905. static struct sd_desc sd_desc = {
  906. .name = MODULE_NAME,
  907. .ctrls = sd_ctrls,
  908. .nctrls = ARRAY_SIZE(sd_ctrls),
  909. .config = sd_config,
  910. .open = sd_open,
  911. .start = sd_start,
  912. .stopN = sd_stopN,
  913. .stop0 = sd_stop0,
  914. .close = sd_close,
  915. .pkt_scan = sd_pkt_scan,
  916. };
  917. /* -- module initialisation -- */
  918. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  919. static __devinitdata struct usb_device_id device_table[] = {
  920. {USB_DEVICE(0x102c, 0x6151), DVNM("Qcam Sangha CIF")},
  921. {USB_DEVICE(0x102c, 0x6251), DVNM("Qcam xxxxxx VGA")},
  922. {}
  923. };
  924. MODULE_DEVICE_TABLE(usb, device_table);
  925. /* -- device connect -- */
  926. static int sd_probe(struct usb_interface *intf,
  927. const struct usb_device_id *id)
  928. {
  929. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  930. THIS_MODULE);
  931. }
  932. static struct usb_driver sd_driver = {
  933. .name = MODULE_NAME,
  934. .id_table = device_table,
  935. .probe = sd_probe,
  936. .disconnect = gspca_disconnect,
  937. };
  938. /* -- module insert / remove -- */
  939. static int __init sd_mod_init(void)
  940. {
  941. if (usb_register(&sd_driver) < 0)
  942. return -1;
  943. PDEBUG(D_PROBE, "v%s registered", version);
  944. return 0;
  945. }
  946. static void __exit sd_mod_exit(void)
  947. {
  948. usb_deregister(&sd_driver);
  949. PDEBUG(D_PROBE, "deregistered");
  950. }
  951. module_init(sd_mod_init);
  952. module_exit(sd_mod_exit);