etoms.c 26 KB

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