conex.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. /*
  2. * Connexant Cx11646 library
  3. * Copyright (C) 2004 Michel Xhaard mxhaard@magic.fr
  4. *
  5. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define MODULE_NAME "conex"
  22. #include "gspca.h"
  23. #define CONEX_CAM 1 /* special JPEG header */
  24. #include "jpeg.h"
  25. #define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 0)
  26. static const char version[] = "2.1.0";
  27. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  28. MODULE_DESCRIPTION("GSPCA USB Conexant Camera Driver");
  29. MODULE_LICENSE("GPL");
  30. /* specific webcam descriptor */
  31. struct sd {
  32. struct gspca_dev gspca_dev; /* !! must be the first item */
  33. unsigned char brightness;
  34. unsigned char contrast;
  35. unsigned char colors;
  36. unsigned char qindex;
  37. };
  38. /* V4L2 controls supported by the driver */
  39. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  40. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  41. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  42. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  43. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  44. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  45. static struct ctrl sd_ctrls[] = {
  46. #define SD_BRIGHTNESS 0
  47. {
  48. {
  49. .id = V4L2_CID_BRIGHTNESS,
  50. .type = V4L2_CTRL_TYPE_INTEGER,
  51. .name = "Brightness",
  52. .minimum = 0,
  53. .maximum = 255,
  54. .step = 1,
  55. .default_value = 0xd4,
  56. },
  57. .set = sd_setbrightness,
  58. .get = sd_getbrightness,
  59. },
  60. #define SD_CONTRAST 1
  61. {
  62. {
  63. .id = V4L2_CID_CONTRAST,
  64. .type = V4L2_CTRL_TYPE_INTEGER,
  65. .name = "Contrast",
  66. .minimum = 0x0a,
  67. .maximum = 0x1f,
  68. .step = 1,
  69. .default_value = 0x0c,
  70. },
  71. .set = sd_setcontrast,
  72. .get = sd_getcontrast,
  73. },
  74. #define SD_COLOR 2
  75. {
  76. {
  77. .id = V4L2_CID_SATURATION,
  78. .type = V4L2_CTRL_TYPE_INTEGER,
  79. .name = "Color",
  80. .minimum = 0,
  81. .maximum = 7,
  82. .step = 1,
  83. .default_value = 3,
  84. },
  85. .set = sd_setcolors,
  86. .get = sd_getcolors,
  87. },
  88. };
  89. static struct cam_mode vga_mode[] = {
  90. {V4L2_PIX_FMT_JPEG, 176, 144, 3},
  91. {V4L2_PIX_FMT_JPEG, 320, 240, 2},
  92. {V4L2_PIX_FMT_JPEG, 352, 288, 1},
  93. {V4L2_PIX_FMT_JPEG, 640, 480, 0},
  94. };
  95. static void reg_r(struct usb_device *dev,
  96. __u16 index,
  97. __u8 *buffer, __u16 length)
  98. {
  99. usb_control_msg(dev,
  100. usb_rcvctrlpipe(dev, 0),
  101. 0,
  102. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  103. 0,
  104. index, buffer, length,
  105. 500);
  106. PDEBUG(D_USBI, "reg read i:%02x -> %02x", index, *buffer);
  107. }
  108. static void reg_w(struct usb_device *dev,
  109. __u16 index,
  110. const __u8 *buffer, __u16 length)
  111. {
  112. PDEBUG(D_USBO, "reg write i:%02x = %02x", index, *buffer);
  113. usb_control_msg(dev,
  114. usb_sndctrlpipe(dev, 0),
  115. 0,
  116. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  117. 0,
  118. index, (__u8 *) buffer, length,
  119. 500);
  120. }
  121. static const __u8 cx_sensor_init[][4] = {
  122. {0x88, 0x11, 0x01, 0x01},
  123. {0x88, 0x12, 0x70, 0x01},
  124. {0x88, 0x0f, 0x00, 0x01},
  125. {0x88, 0x05, 0x01, 0x01},
  126. {}
  127. };
  128. static const __u8 cx11646_fw1[][3] = {
  129. {0x00, 0x02, 0x00},
  130. {0x01, 0x43, 0x00},
  131. {0x02, 0xA7, 0x00},
  132. {0x03, 0x8B, 0x01},
  133. {0x04, 0xE9, 0x02},
  134. {0x05, 0x08, 0x04},
  135. {0x06, 0x08, 0x05},
  136. {0x07, 0x07, 0x06},
  137. {0x08, 0xE7, 0x06},
  138. {0x09, 0xC6, 0x07},
  139. {0x0A, 0x86, 0x08},
  140. {0x0B, 0x46, 0x09},
  141. {0x0C, 0x05, 0x0A},
  142. {0x0D, 0xA5, 0x0A},
  143. {0x0E, 0x45, 0x0B},
  144. {0x0F, 0xE5, 0x0B},
  145. {0x10, 0x85, 0x0C},
  146. {0x11, 0x25, 0x0D},
  147. {0x12, 0xC4, 0x0D},
  148. {0x13, 0x45, 0x0E},
  149. {0x14, 0xE4, 0x0E},
  150. {0x15, 0x64, 0x0F},
  151. {0x16, 0xE4, 0x0F},
  152. {0x17, 0x64, 0x10},
  153. {0x18, 0xE4, 0x10},
  154. {0x19, 0x64, 0x11},
  155. {0x1A, 0xE4, 0x11},
  156. {0x1B, 0x64, 0x12},
  157. {0x1C, 0xE3, 0x12},
  158. {0x1D, 0x44, 0x13},
  159. {0x1E, 0xC3, 0x13},
  160. {0x1F, 0x24, 0x14},
  161. {0x20, 0xA3, 0x14},
  162. {0x21, 0x04, 0x15},
  163. {0x22, 0x83, 0x15},
  164. {0x23, 0xE3, 0x15},
  165. {0x24, 0x43, 0x16},
  166. {0x25, 0xA4, 0x16},
  167. {0x26, 0x23, 0x17},
  168. {0x27, 0x83, 0x17},
  169. {0x28, 0xE3, 0x17},
  170. {0x29, 0x43, 0x18},
  171. {0x2A, 0xA3, 0x18},
  172. {0x2B, 0x03, 0x19},
  173. {0x2C, 0x63, 0x19},
  174. {0x2D, 0xC3, 0x19},
  175. {0x2E, 0x22, 0x1A},
  176. {0x2F, 0x63, 0x1A},
  177. {0x30, 0xC3, 0x1A},
  178. {0x31, 0x23, 0x1B},
  179. {0x32, 0x83, 0x1B},
  180. {0x33, 0xE2, 0x1B},
  181. {0x34, 0x23, 0x1C},
  182. {0x35, 0x83, 0x1C},
  183. {0x36, 0xE2, 0x1C},
  184. {0x37, 0x23, 0x1D},
  185. {0x38, 0x83, 0x1D},
  186. {0x39, 0xE2, 0x1D},
  187. {0x3A, 0x23, 0x1E},
  188. {0x3B, 0x82, 0x1E},
  189. {0x3C, 0xC3, 0x1E},
  190. {0x3D, 0x22, 0x1F},
  191. {0x3E, 0x63, 0x1F},
  192. {0x3F, 0xC1, 0x1F},
  193. {}
  194. };
  195. static void cx11646_fw(struct gspca_dev*gspca_dev)
  196. {
  197. __u8 val;
  198. int i = 0;
  199. val = 0x02;
  200. reg_w(gspca_dev->dev, 0x006a, &val, 1);
  201. while (cx11646_fw1[i][1]) {
  202. reg_w(gspca_dev->dev, 0x006b, cx11646_fw1[i], 3);
  203. i++;
  204. }
  205. val = 0x00;
  206. reg_w(gspca_dev->dev, 0x006a, &val, 1);
  207. }
  208. static __u8 cxsensor[] = {
  209. 0x88, 0x12, 0x70, 0x01,
  210. 0x88, 0x0d, 0x02, 0x01,
  211. 0x88, 0x0f, 0x00, 0x01,
  212. 0x88, 0x03, 0x71, 0x01, 0x88, 0x04, 0x00, 0x01, /* 3 */
  213. 0x88, 0x02, 0x10, 0x01,
  214. 0x88, 0x00, 0xD4, 0x01, 0x88, 0x01, 0x01, 0x01, /* 5 */
  215. 0x88, 0x0B, 0x00, 0x01,
  216. 0x88, 0x0A, 0x0A, 0x01,
  217. 0x88, 0x00, 0x08, 0x01, 0x88, 0x01, 0x00, 0x01, /* 8 */
  218. 0x88, 0x05, 0x01, 0x01,
  219. 0xA1, 0x18, 0x00, 0x01,
  220. 0x00
  221. };
  222. static __u8 reg20[] = { 0x10, 0x42, 0x81, 0x19, 0xd3, 0xff, 0xa7, 0xff };
  223. static __u8 reg28[] = { 0x87, 0x00, 0x87, 0x00, 0x8f, 0xff, 0xea, 0xff };
  224. static __u8 reg10[] = { 0xb1, 0xb1 };
  225. static __u8 reg71a[] = { 0x08, 0x18, 0x0a, 0x1e }; /* 640 */
  226. static __u8 reg71b[] = { 0x04, 0x0c, 0x05, 0x0f };
  227. /* 352{0x04,0x0a,0x06,0x12}; //352{0x05,0x0e,0x06,0x11}; //352 */
  228. static __u8 reg71c[] = { 0x02, 0x07, 0x03, 0x09 };
  229. /* 320{0x04,0x0c,0x05,0x0f}; //320 */
  230. static __u8 reg71d[] = { 0x02, 0x07, 0x03, 0x09 }; /* 176 */
  231. static __u8 reg7b[] = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff };
  232. static void cx_sensor(struct gspca_dev*gspca_dev)
  233. {
  234. __u8 val = 0;
  235. int i = 0;
  236. __u8 bufread[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  237. int length = 0;
  238. __u8 *ptsensor = cxsensor;
  239. reg_w(gspca_dev->dev, 0x0020, reg20, 8);
  240. reg_w(gspca_dev->dev, 0x0028, reg28, 8);
  241. reg_w(gspca_dev->dev, 0x0010, reg10, 8);
  242. val = 0x03;
  243. reg_w(gspca_dev->dev, 0x0092, &val, 1);
  244. switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode) {
  245. case 0:
  246. reg_w(gspca_dev->dev, 0x0071, reg71a, 4);
  247. break;
  248. case 1:
  249. reg_w(gspca_dev->dev, 0x0071, reg71b, 4);
  250. break;
  251. default:
  252. /* case 2: */
  253. reg_w(gspca_dev->dev, 0x0071, reg71c, 4);
  254. break;
  255. case 3:
  256. reg_w(gspca_dev->dev, 0x0071, reg71d, 4);
  257. break;
  258. }
  259. reg_w(gspca_dev->dev, 0x007b, reg7b, 6);
  260. val = 0x00;
  261. reg_w(gspca_dev->dev, 0x00f8, &val, 1);
  262. reg_w(gspca_dev->dev, 0x0010, reg10, 8);
  263. val = 0x41;
  264. reg_w(gspca_dev->dev, 0x0098, &val, 1);
  265. for (i = 0; i < 11; i++) {
  266. if (i == 3 || i == 5 || i == 8)
  267. length = 8;
  268. else
  269. length = 4;
  270. reg_w(gspca_dev->dev, 0x00e5, ptsensor, length);
  271. if (length == 4)
  272. reg_r(gspca_dev->dev, 0x00e8, &val, 1);
  273. else
  274. reg_r(gspca_dev->dev, 0x00e8, bufread, length);
  275. ptsensor += length;
  276. }
  277. reg_r(gspca_dev->dev, 0x00e7, bufread, 8);
  278. }
  279. static __u8 cx_inits_176[] = {
  280. 0x33, 0x81, 0xB0, 0x00, 0x90, 0x00, 0x0A, 0x03, /* 176x144 */
  281. 0x00, 0x03, 0x03, 0x03, 0x1B, 0x05, 0x30, 0x03,
  282. 0x65, 0x15, 0x18, 0x25, 0x03, 0x25, 0x08, 0x30,
  283. 0x3B, 0x25, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
  284. 0xDC, 0xFF, 0xEE, 0xFF, 0xC5, 0xFF, 0xBF, 0xFF,
  285. 0xF7, 0xFF, 0x88, 0xFF, 0x66, 0x02, 0x28, 0x02,
  286. 0x1E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  287. };
  288. static __u8 cx_inits_320[] = {
  289. 0x7f, 0x7f, 0x40, 0x01, 0xf0, 0x00, 0x02, 0x01,
  290. 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x02, 0x01,
  291. 0x65, 0x45, 0xfa, 0x4c, 0x2c, 0xdf, 0xb9, 0x81,
  292. 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  293. 0xe2, 0xff, 0xf1, 0xff, 0xc2, 0xff, 0xbc, 0xff,
  294. 0xf5, 0xff, 0x6d, 0xff, 0xf6, 0x01, 0x43, 0x02,
  295. 0xd3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  296. };
  297. static __u8 cx_inits_352[] = {
  298. 0x2e, 0x7c, 0x60, 0x01, 0x20, 0x01, 0x05, 0x03,
  299. 0x00, 0x06, 0x03, 0x06, 0x1b, 0x10, 0x05, 0x3b,
  300. 0x30, 0x25, 0x18, 0x25, 0x08, 0x30, 0x03, 0x25,
  301. 0x3b, 0x30, 0x25, 0x1b, 0x10, 0x05, 0x00, 0x00,
  302. 0xe3, 0xff, 0xf1, 0xff, 0xc2, 0xff, 0xbc, 0xff,
  303. 0xf5, 0xff, 0x6b, 0xff, 0xee, 0x01, 0x43, 0x02,
  304. 0xe4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  305. };
  306. static __u8 cx_inits_640[] = {
  307. 0x7e, 0x7e, 0x80, 0x02, 0xe0, 0x01, 0x01, 0x01,
  308. 0x00, 0x02, 0x01, 0x02, 0x10, 0x30, 0x01, 0x01,
  309. 0x65, 0x45, 0xf7, 0x52, 0x2c, 0xdf, 0xb9, 0x81,
  310. 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  311. 0xe2, 0xff, 0xf1, 0xff, 0xc2, 0xff, 0xbc, 0xff,
  312. 0xf6, 0xff, 0x7b, 0xff, 0x01, 0x02, 0x43, 0x02,
  313. 0x77, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  314. };
  315. static int cx11646_initsize(struct gspca_dev *gspca_dev)
  316. {
  317. __u8 *cxinit;
  318. __u8 val;
  319. static const __u8 reg12[] = { 0x08, 0x05, 0x07, 0x04, 0x24 };
  320. static const __u8 reg17[] =
  321. { 0x0a, 0x00, 0xf2, 0x01, 0x0f, 0x00, 0x97, 0x02 };
  322. switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode) {
  323. case 0:
  324. cxinit = cx_inits_640;
  325. break;
  326. case 1:
  327. cxinit = cx_inits_352;
  328. break;
  329. default:
  330. /* case 2: */
  331. cxinit = cx_inits_320;
  332. break;
  333. case 3:
  334. cxinit = cx_inits_176;
  335. break;
  336. }
  337. val = 0x01;
  338. reg_w(gspca_dev->dev, 0x009a, &val, 1);
  339. val = 0x10;
  340. reg_w(gspca_dev->dev, 0x0010, &val, 1);
  341. reg_w(gspca_dev->dev, 0x0012, reg12, 5);
  342. reg_w(gspca_dev->dev, 0x0017, reg17, 8);
  343. val = 0x00;
  344. reg_w(gspca_dev->dev, 0x00c0, &val, 1);
  345. val = 0x04;
  346. reg_w(gspca_dev->dev, 0x00c1, &val, 1);
  347. val = 0x04;
  348. reg_w(gspca_dev->dev, 0x00c2, &val, 1);
  349. reg_w(gspca_dev->dev, 0x0061, cxinit, 8);
  350. cxinit += 8;
  351. reg_w(gspca_dev->dev, 0x00ca, cxinit, 8);
  352. cxinit += 8;
  353. reg_w(gspca_dev->dev, 0x00d2, cxinit, 8);
  354. cxinit += 8;
  355. reg_w(gspca_dev->dev, 0x00da, cxinit, 6);
  356. cxinit += 8;
  357. reg_w(gspca_dev->dev, 0x0041, cxinit, 8);
  358. cxinit += 8;
  359. reg_w(gspca_dev->dev, 0x0049, cxinit, 8);
  360. cxinit += 8;
  361. reg_w(gspca_dev->dev, 0x0051, cxinit, 2);
  362. reg_r(gspca_dev->dev, 0x0010, &val, 1);
  363. return val;
  364. }
  365. static __u8 cx_jpeg_init[][8] = {
  366. {0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x15}, /* 1 */
  367. {0x0f, 0x10, 0x12, 0x10, 0x0d, 0x15, 0x12, 0x11},
  368. {0x12, 0x18, 0x16, 0x15, 0x19, 0x20, 0x35, 0x22},
  369. {0x20, 0x1d, 0x1d, 0x20, 0x41, 0x2e, 0x31, 0x26},
  370. {0x35, 0x4d, 0x43, 0x51, 0x4f, 0x4b, 0x43, 0x4a},
  371. {0x49, 0x55, 0x5F, 0x79, 0x67, 0x55, 0x5A, 0x73},
  372. {0x5B, 0x49, 0x4A, 0x6A, 0x90, 0x6B, 0x73, 0x7D},
  373. {0x81, 0x88, 0x89, 0x88, 0x52, 0x66, 0x95, 0xA0},
  374. {0x94, 0x84, 0x9E, 0x79, 0x85, 0x88, 0x83, 0x01},
  375. {0x15, 0x0F, 0x10, 0x12, 0x10, 0x0D, 0x15, 0x12},
  376. {0x11, 0x12, 0x18, 0x16, 0x15, 0x19, 0x20, 0x35},
  377. {0x22, 0x20, 0x1D, 0x1D, 0x20, 0x41, 0x2E, 0x31},
  378. {0x26, 0x35, 0x4D, 0x43, 0x51, 0x4F, 0x4B, 0x43},
  379. {0x4A, 0x49, 0x55, 0x5F, 0x79, 0x67, 0x55, 0x5A},
  380. {0x73, 0x5B, 0x49, 0x4A, 0x6A, 0x90, 0x6B, 0x73},
  381. {0x7D, 0x81, 0x88, 0x89, 0x88, 0x52, 0x66, 0x95},
  382. {0xA0, 0x94, 0x84, 0x9E, 0x79, 0x85, 0x88, 0x83},
  383. {0xFF, 0xC4, 0x01, 0xA2, 0x00, 0x00, 0x01, 0x05},
  384. {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00},
  385. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02},
  386. {0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A},
  387. {0x0B, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01},
  388. {0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00},
  389. {0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
  390. {0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x00},
  391. {0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05},
  392. {0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, 0x01},
  393. {0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21},
  394. {0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22},
  395. {0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23},
  396. {0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24},
  397. {0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17},
  398. {0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29},
  399. {0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A},
  400. {0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A},
  401. {0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A},
  402. {0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A},
  403. {0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A},
  404. {0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A},
  405. {0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99},
  406. {0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8},
  407. {0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7},
  408. {0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6},
  409. {0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5},
  410. {0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3},
  411. {0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1},
  412. {0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9},
  413. {0xFA, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04},
  414. {0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01},
  415. {0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04},
  416. {0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07},
  417. {0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14},
  418. {0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33},
  419. {0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16},
  420. {0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19},
  421. {0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36},
  422. {0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46},
  423. {0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56},
  424. {0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66},
  425. {0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76},
  426. {0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85},
  427. {0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94},
  428. {0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3},
  429. {0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2},
  430. {0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA},
  431. {0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9},
  432. {0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8},
  433. {0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7},
  434. {0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6},
  435. {0xF7, 0xF8, 0xF9, 0xFA, 0xFF, 0x20, 0x00, 0x1F},
  436. {0x02, 0x0C, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00},
  437. {0x00, 0x00, 0x11, 0x00, 0x11, 0x22, 0x00, 0x22},
  438. {0x22, 0x11, 0x22, 0x22, 0x11, 0x33, 0x33, 0x11},
  439. {0x44, 0x66, 0x22, 0x55, 0x66, 0xFF, 0xDD, 0x00},
  440. {0x04, 0x00, 0x14, 0xFF, 0xC0, 0x00, 0x11, 0x08},
  441. {0x00, 0xF0, 0x01, 0x40, 0x03, 0x00, 0x21, 0x00},
  442. {0x01, 0x11, 0x01, 0x02, 0x11, 0x01, 0xFF, 0xDA},
  443. {0x00, 0x0C, 0x03, 0x00, 0x00, 0x01, 0x11, 0x02},
  444. {0x11, 0x00, 0x3F, 0x00, 0xFF, 0xD9, 0x00, 0x00} /* 79 */
  445. };
  446. static __u8 cxjpeg_640[][8] = {
  447. {0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x10}, /* 1 */
  448. {0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e, 0x0d},
  449. {0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28, 0x1a},
  450. {0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25, 0x1d},
  451. {0x28, 0x3a, 0x33, 0x3D, 0x3C, 0x39, 0x33, 0x38},
  452. {0x37, 0x40, 0x48, 0x5C, 0x4E, 0x40, 0x44, 0x57},
  453. {0x45, 0x37, 0x38, 0x50, 0x6D, 0x51, 0x57, 0x5F},
  454. {0x62, 0x67, 0x68, 0x67, 0x3E, 0x4D, 0x71, 0x79},
  455. {0x70, 0x64, 0x78, 0x5C, 0x65, 0x67, 0x63, 0x01},
  456. {0x10, 0x0B, 0x0C, 0x0E, 0x0C, 0x0A, 0x10, 0x0E},
  457. {0x0D, 0x0E, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28},
  458. {0x1A, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25},
  459. {0x1D, 0x28, 0x3A, 0x33, 0x3D, 0x3C, 0x39, 0x33},
  460. {0x38, 0x37, 0x40, 0x48, 0x5C, 0x4E, 0x40, 0x44},
  461. {0x57, 0x45, 0x37, 0x38, 0x50, 0x6D, 0x51, 0x57},
  462. {0x5F, 0x62, 0x67, 0x68, 0x67, 0x3E, 0x4D, 0x71},
  463. {0x79, 0x70, 0x64, 0x78, 0x5C, 0x65, 0x67, 0x63},
  464. {0xFF, 0x20, 0x00, 0x1F, 0x00, 0x83, 0x00, 0x00},
  465. {0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
  466. {0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
  467. {0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
  468. {0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x28, 0xFF},
  469. {0xC0, 0x00, 0x11, 0x08, 0x01, 0xE0, 0x02, 0x80},
  470. {0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
  471. {0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
  472. {0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
  473. {0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 27 */
  474. };
  475. static __u8 cxjpeg_352[][8] = {
  476. {0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x0d},
  477. {0x09, 0x09, 0x0b, 0x09, 0x08, 0x0D, 0x0b, 0x0a},
  478. {0x0b, 0x0e, 0x0d, 0x0d, 0x0f, 0x13, 0x1f, 0x14},
  479. {0x13, 0x11, 0x11, 0x13, 0x26, 0x1b, 0x1d, 0x17},
  480. {0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28, 0x2C},
  481. {0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35, 0x44},
  482. {0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44, 0x4A},
  483. {0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58, 0x5F},
  484. {0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D, 0x01},
  485. {0x0D, 0x09, 0x09, 0x0B, 0x09, 0x08, 0x0D, 0x0B},
  486. {0x0A, 0x0B, 0x0E, 0x0D, 0x0D, 0x0F, 0x13, 0x1F},
  487. {0x14, 0x13, 0x11, 0x11, 0x13, 0x26, 0x1B, 0x1D},
  488. {0x17, 0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28},
  489. {0x2C, 0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35},
  490. {0x44, 0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44},
  491. {0x4A, 0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58},
  492. {0x5F, 0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D},
  493. {0xFF, 0x20, 0x00, 0x1F, 0x01, 0x83, 0x00, 0x00},
  494. {0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
  495. {0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
  496. {0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
  497. {0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x16, 0xFF},
  498. {0xC0, 0x00, 0x11, 0x08, 0x01, 0x20, 0x01, 0x60},
  499. {0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
  500. {0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
  501. {0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
  502. {0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  503. };
  504. static __u8 cxjpeg_320[][8] = {
  505. {0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x05},
  506. {0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04},
  507. {0x04, 0x05, 0x05, 0x05, 0x06, 0x07, 0x0c, 0x08},
  508. {0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09},
  509. {0x0C, 0x11, 0x0F, 0x12, 0x12, 0x11, 0x0f, 0x11},
  510. {0x11, 0x13, 0x16, 0x1C, 0x17, 0x13, 0x14, 0x1A},
  511. {0x15, 0x11, 0x11, 0x18, 0x21, 0x18, 0x1A, 0x1D},
  512. {0x1D, 0x1F, 0x1F, 0x1F, 0x13, 0x17, 0x22, 0x24},
  513. {0x22, 0x1E, 0x24, 0x1C, 0x1E, 0x1F, 0x1E, 0x01},
  514. {0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04},
  515. {0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x07, 0x0C},
  516. {0x08, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x0B, 0x0B},
  517. {0x09, 0x0C, 0x11, 0x0F, 0x12, 0x12, 0x11, 0x0F},
  518. {0x11, 0x11, 0x13, 0x16, 0x1C, 0x17, 0x13, 0x14},
  519. {0x1A, 0x15, 0x11, 0x11, 0x18, 0x21, 0x18, 0x1A},
  520. {0x1D, 0x1D, 0x1F, 0x1F, 0x1F, 0x13, 0x17, 0x22},
  521. {0x24, 0x22, 0x1E, 0x24, 0x1C, 0x1E, 0x1F, 0x1E},
  522. {0xFF, 0x20, 0x00, 0x1F, 0x02, 0x0C, 0x00, 0x00},
  523. {0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
  524. {0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
  525. {0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
  526. {0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x14, 0xFF},
  527. {0xC0, 0x00, 0x11, 0x08, 0x00, 0xF0, 0x01, 0x40},
  528. {0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
  529. {0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
  530. {0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
  531. {0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 27 */
  532. };
  533. static __u8 cxjpeg_176[][8] = {
  534. {0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x0d},
  535. {0x09, 0x09, 0x0B, 0x09, 0x08, 0x0D, 0x0B, 0x0A},
  536. {0x0B, 0x0E, 0x0D, 0x0D, 0x0F, 0x13, 0x1F, 0x14},
  537. {0x13, 0x11, 0x11, 0x13, 0x26, 0x1B, 0x1D, 0x17},
  538. {0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28, 0x2C},
  539. {0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35, 0x44},
  540. {0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44, 0x4A},
  541. {0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58, 0x5F},
  542. {0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D, 0x01},
  543. {0x0D, 0x09, 0x09, 0x0B, 0x09, 0x08, 0x0D, 0x0B},
  544. {0x0A, 0x0B, 0x0E, 0x0D, 0x0D, 0x0F, 0x13, 0x1F},
  545. {0x14, 0x13, 0x11, 0x11, 0x13, 0x26, 0x1B, 0x1D},
  546. {0x17, 0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28},
  547. {0x2C, 0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35},
  548. {0x44, 0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44},
  549. {0x4A, 0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58},
  550. {0x5F, 0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D},
  551. {0xFF, 0x20, 0x00, 0x1F, 0x03, 0xA1, 0x00, 0x00},
  552. {0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
  553. {0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
  554. {0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
  555. {0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x0B, 0xFF},
  556. {0xC0, 0x00, 0x11, 0x08, 0x00, 0x90, 0x00, 0xB0},
  557. {0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
  558. {0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
  559. {0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
  560. {0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  561. };
  562. static __u8 cxjpeg_qtable[][8] = { /* 640 take with the zcx30x part */
  563. {0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x08},
  564. {0x06, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07, 0x07},
  565. {0x07, 0x09, 0x09, 0x08, 0x0a, 0x0c, 0x14, 0x0a},
  566. {0x0c, 0x0b, 0x0b, 0x0c, 0x19, 0x12, 0x13, 0x0f},
  567. {0x14, 0x1d, 0x1a, 0x1f, 0x1e, 0x1d, 0x1a, 0x1c},
  568. {0x1c, 0x20, 0x24, 0x2e, 0x27, 0x20, 0x22, 0x2c},
  569. {0x23, 0x1c, 0x1c, 0x28, 0x37, 0x29, 0x2c, 0x30},
  570. {0x31, 0x34, 0x34, 0x34, 0x1f, 0x27, 0x39, 0x3d},
  571. {0x38, 0x32, 0x3c, 0x2e, 0x33, 0x34, 0x32, 0x01},
  572. {0x09, 0x09, 0x09, 0x0c, 0x0b, 0x0c, 0x18, 0x0a},
  573. {0x0a, 0x18, 0x32, 0x21, 0x1c, 0x21, 0x32, 0x32},
  574. {0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
  575. {0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
  576. {0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
  577. {0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
  578. {0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
  579. {0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
  580. {0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 18 */
  581. };
  582. static void cx11646_jpegInit(struct gspca_dev*gspca_dev)
  583. {
  584. __u8 val;
  585. int i;
  586. int length;
  587. val = 0x01;
  588. reg_w(gspca_dev->dev, 0x00c0, &val, 1);
  589. val = 0x00;
  590. reg_w(gspca_dev->dev, 0x00c3, &val, 1);
  591. val = 0x00;
  592. reg_w(gspca_dev->dev, 0x00c0, &val, 1);
  593. reg_r(gspca_dev->dev, 0x0001, &val, 1);
  594. length = 8;
  595. for (i = 0; i < 79; i++) {
  596. if (i == 78)
  597. length = 6;
  598. reg_w(gspca_dev->dev, 0x0008, cx_jpeg_init[i], length);
  599. }
  600. reg_r(gspca_dev->dev, 0x0002, &val, 1);
  601. val = 0x14;
  602. reg_w(gspca_dev->dev, 0x0055, &val, 1);
  603. }
  604. static __u8 reg12[] = { 0x0a, 0x05, 0x07, 0x04, 0x19 };
  605. static __u8 regE5_8[] = { 0x88, 0x00, 0xd4, 0x01, 0x88, 0x01, 0x01, 0x01 };
  606. static __u8 regE5a[] = { 0x88, 0x0a, 0x0c, 0x01 };
  607. static __u8 regE5b[] = { 0x88, 0x0b, 0x12, 0x01 };
  608. static __u8 regE5c[] = { 0x88, 0x05, 0x01, 0x01 };
  609. static __u8 reg51[] = { 0x77, 0x03 };
  610. static __u8 reg70 = 0x03;
  611. static void cx11646_jpeg(struct gspca_dev*gspca_dev)
  612. {
  613. __u8 val;
  614. int i;
  615. int length = 8;
  616. __u8 Reg55 = 0x14;
  617. __u8 bufread[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  618. int retry = 50;
  619. val = 0x01;
  620. reg_w(gspca_dev->dev, 0x00c0, &val, 1);
  621. val = 0x00;
  622. reg_w(gspca_dev->dev, 0x00c3, &val, 1);
  623. val = 0x00;
  624. reg_w(gspca_dev->dev, 0x00c0, &val, 1);
  625. reg_r(gspca_dev->dev, 0x0001, &val, 1);
  626. switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode) {
  627. case 0:
  628. for (i = 0; i < 27; i++) {
  629. if (i == 26)
  630. length = 2;
  631. reg_w(gspca_dev->dev, 0x0008,
  632. cxjpeg_640[i], length);
  633. }
  634. Reg55 = 0x28;
  635. break;
  636. case 1:
  637. for (i = 0; i < 27; i++) {
  638. if (i == 26)
  639. length = 2;
  640. reg_w(gspca_dev->dev, 0x0008,
  641. cxjpeg_352[i], length);
  642. }
  643. Reg55 = 0x16;
  644. break;
  645. default:
  646. /* case 2: */
  647. for (i = 0; i < 27; i++) {
  648. if (i == 26)
  649. length = 2;
  650. reg_w(gspca_dev->dev, 0x0008,
  651. cxjpeg_320[i], length);
  652. }
  653. Reg55 = 0x14;
  654. break;
  655. case 3:
  656. for (i = 0; i < 27; i++) {
  657. if (i == 26)
  658. length = 2;
  659. reg_w(gspca_dev->dev, 0x0008,
  660. cxjpeg_176[i], length);
  661. }
  662. Reg55 = 0x0B;
  663. break;
  664. }
  665. reg_r(gspca_dev->dev, 0x0002, &val, 1);
  666. val = Reg55;
  667. reg_w(gspca_dev->dev, 0x0055, &val, 1);
  668. reg_r(gspca_dev->dev, 0x0002, &val, 1);
  669. reg_w(gspca_dev->dev, 0x0010, reg10, 2);
  670. val = 0x02;
  671. reg_w(gspca_dev->dev, 0x0054, &val, 1);
  672. val = 0x01;
  673. reg_w(gspca_dev->dev, 0x0054, &val, 1);
  674. val = 0x94;
  675. reg_w(gspca_dev->dev, 0x0000, &val, 1);
  676. val = 0xc0;
  677. reg_w(gspca_dev->dev, 0x0053, &val, 1);
  678. val = 0xe1;
  679. reg_w(gspca_dev->dev, 0x00fc, &val, 1);
  680. val = 0x00;
  681. reg_w(gspca_dev->dev, 0x0000, &val, 1);
  682. /* wait for completion */
  683. while (retry--) {
  684. reg_r(gspca_dev->dev, 0x0002, &val, 1);
  685. /* 0x07 until 0x00 */
  686. if (val == 0x00)
  687. break;
  688. val = 0x00;
  689. reg_w(gspca_dev->dev, 0x0053, &val, 1);
  690. }
  691. if (retry == 0)
  692. PDEBUG(D_ERR, "Damned Errors sending jpeg Table");
  693. /* send the qtable now */
  694. reg_r(gspca_dev->dev, 0x0001, &val, 1); /* -> 0x18 */
  695. length = 8;
  696. for (i = 0; i < 18; i++) {
  697. if (i == 17)
  698. length = 2;
  699. reg_w(gspca_dev->dev, 0x0008,
  700. cxjpeg_qtable[i], length);
  701. }
  702. reg_r(gspca_dev->dev, 0x0002, &val, 1); /* 0x00 */
  703. reg_r(gspca_dev->dev, 0x0053, &val, 1); /* 0x00 */
  704. val = 0x02;
  705. reg_w(gspca_dev->dev, 0x0054, &val, 1);
  706. val = 0x01;
  707. reg_w(gspca_dev->dev, 0x0054, &val, 1);
  708. val = 0x94;
  709. reg_w(gspca_dev->dev, 0x0000, &val, 1);
  710. val = 0xc0;
  711. reg_w(gspca_dev->dev, 0x0053, &val, 1);
  712. reg_r(gspca_dev->dev, 0x0038, &val, 1); /* 0x40 */
  713. reg_r(gspca_dev->dev, 0x0038, &val, 1); /* 0x40 */
  714. reg_r(gspca_dev->dev, 0x001f, &val, 1); /* 0x38 */
  715. reg_w(gspca_dev->dev, 0x0012, reg12, 5);
  716. reg_w(gspca_dev->dev, 0x00e5, regE5_8, 8);
  717. reg_r(gspca_dev->dev, 0x00e8, bufread, 8);
  718. reg_w(gspca_dev->dev, 0x00e5, regE5a, 4);
  719. reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */
  720. val = 0x01;
  721. reg_w(gspca_dev->dev, 0x009a, &val, 1);
  722. reg_w(gspca_dev->dev, 0x00e5, regE5b, 4);
  723. reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */
  724. reg_w(gspca_dev->dev, 0x00e5, regE5c, 4);
  725. reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */
  726. reg_w(gspca_dev->dev, 0x0051, reg51, 2);
  727. reg_w(gspca_dev->dev, 0x0010, reg10, 2);
  728. reg_w(gspca_dev->dev, 0x0070, &reg70, 1);
  729. }
  730. static void cx11646_init1(struct gspca_dev *gspca_dev)
  731. {
  732. __u8 val;
  733. int i = 0;
  734. val = 0;
  735. reg_w(gspca_dev->dev, 0x0010, &val, 1);
  736. reg_w(gspca_dev->dev, 0x0053, &val, 1);
  737. reg_w(gspca_dev->dev, 0x0052, &val, 1);
  738. val = 0x2f;
  739. reg_w(gspca_dev->dev, 0x009b, &val, 1);
  740. val = 0x10;
  741. reg_w(gspca_dev->dev, 0x009c, &val, 1);
  742. reg_r(gspca_dev->dev, 0x0098, &val, 1);
  743. val = 0x40;
  744. reg_w(gspca_dev->dev, 0x0098, &val, 1);
  745. reg_r(gspca_dev->dev, 0x0099, &val, 1);
  746. val = 0x07;
  747. reg_w(gspca_dev->dev, 0x0099, &val, 1);
  748. val = 0x40;
  749. reg_w(gspca_dev->dev, 0x0039, &val, 1);
  750. val = 0xff;
  751. reg_w(gspca_dev->dev, 0x003c, &val, 1);
  752. val = 0x1f;
  753. reg_w(gspca_dev->dev, 0x003f, &val, 1);
  754. val = 0x40;
  755. reg_w(gspca_dev->dev, 0x003d, &val, 1);
  756. /* val= 0x60; */
  757. /* reg_w(gspca_dev->dev,0x00,0x00,0x003d,&val,1); */
  758. reg_r(gspca_dev->dev, 0x0099, &val, 1); /* ->0x07 */
  759. while (cx_sensor_init[i][0]) {
  760. reg_w(gspca_dev->dev, 0x00e5, cx_sensor_init[i], 1);
  761. reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* -> 0x00 */
  762. if (i == 1) {
  763. val = 1;
  764. reg_w(gspca_dev->dev, 0x00ed, &val, 1);
  765. reg_r(gspca_dev->dev, 0x00ed, &val, 1); /* -> 0x01 */
  766. }
  767. i++;
  768. }
  769. val = 0x00;
  770. reg_w(gspca_dev->dev, 0x00c3, &val, 1);
  771. }
  772. /* this function is called at probe time */
  773. static int sd_config(struct gspca_dev *gspca_dev,
  774. const struct usb_device_id *id)
  775. {
  776. struct sd *sd = (struct sd *) gspca_dev;
  777. struct cam *cam;
  778. cam = &gspca_dev->cam;
  779. cam->dev_name = (char *) id->driver_info;
  780. cam->epaddr = 0x01;
  781. cam->cam_mode = vga_mode;
  782. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  783. sd->qindex = 0; /* set the quantization table */
  784. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  785. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  786. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  787. return 0;
  788. }
  789. /* this function is called at open time */
  790. static int sd_open(struct gspca_dev *gspca_dev)
  791. {
  792. cx11646_init1(gspca_dev);
  793. cx11646_initsize(gspca_dev);
  794. cx11646_fw(gspca_dev);
  795. cx_sensor(gspca_dev);
  796. cx11646_jpegInit(gspca_dev);
  797. return 0;
  798. }
  799. static void sd_start(struct gspca_dev *gspca_dev)
  800. {
  801. cx11646_initsize(gspca_dev);
  802. cx11646_fw(gspca_dev);
  803. cx_sensor(gspca_dev);
  804. cx11646_jpeg(gspca_dev);
  805. }
  806. static void sd_stopN(struct gspca_dev *gspca_dev)
  807. {
  808. }
  809. static void sd_stop0(struct gspca_dev *gspca_dev)
  810. {
  811. int retry = 50;
  812. __u8 val;
  813. val = 0;
  814. reg_w(gspca_dev->dev, 0x0000, &val, 1);
  815. reg_r(gspca_dev->dev, 0x0002, &val, 1);
  816. val = 0;
  817. reg_w(gspca_dev->dev, 0x0053, &val, 1);
  818. while (retry--) {
  819. /* reg_r (gspca_dev->dev,0x00,0x00,0x0002,&val,1);*/
  820. reg_r(gspca_dev->dev, 0x0053, &val, 1);
  821. if (val == 0)
  822. break;
  823. }
  824. val = 0;
  825. reg_w(gspca_dev->dev, 0x0000, &val, 1);
  826. reg_r(gspca_dev->dev, 0x0002, &val, 1);
  827. val = 0;
  828. reg_w(gspca_dev->dev, 0x0010, &val, 1);
  829. reg_r(gspca_dev->dev, 0x0033, &val, 1);
  830. val = 0xe0;
  831. reg_w(gspca_dev->dev, 0x00fc, &val, 1);
  832. }
  833. static void sd_close(struct gspca_dev *gspca_dev)
  834. {
  835. }
  836. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  837. struct gspca_frame *frame, /* target */
  838. unsigned char *data, /* isoc packet */
  839. int len) /* iso packet length */
  840. {
  841. if (data[0] == 0xff && data[1] == 0xd8) {
  842. /* start of frame */
  843. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  844. data, 0);
  845. /* put the JPEG header in the new frame */
  846. jpeg_put_header(gspca_dev, frame,
  847. ((struct sd *) gspca_dev)->qindex,
  848. 0x22);
  849. data += 2;
  850. len -= 2;
  851. }
  852. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  853. }
  854. static void setbrightness(struct gspca_dev*gspca_dev)
  855. {
  856. struct sd *sd = (struct sd *) gspca_dev;
  857. __u8 regE5cbx[] = { 0x88, 0x00, 0xd4, 0x01, 0x88, 0x01, 0x01, 0x01 };
  858. __u8 reg51c[] = { 0x77, 0x03 };
  859. __u8 bright;
  860. __u8 colors;
  861. __u8 val;
  862. __u8 bufread[8];
  863. bright = sd->brightness;
  864. colors = sd->colors;
  865. regE5cbx[2] = bright;
  866. reg51c[1] = colors;
  867. reg_w(gspca_dev->dev, 0x00e5, regE5cbx, 8);
  868. reg_r(gspca_dev->dev, 0x00e8, bufread, 8);
  869. reg_w(gspca_dev->dev, 0x00e5, regE5c, 4);
  870. reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */
  871. reg_w(gspca_dev->dev, 0x0051, reg51c, 2);
  872. reg_w(gspca_dev->dev, 0x0010, reg10, 2);
  873. reg_w(gspca_dev->dev, 0x0070, &reg70, 1);
  874. }
  875. static void setcontrast(struct gspca_dev*gspca_dev)
  876. {
  877. struct sd *sd = (struct sd *) gspca_dev;
  878. __u8 regE5acx[] = { 0x88, 0x0a, 0x0c, 0x01 }; /* seem MSB */
  879. /* __u8 regE5bcx[]={0x88,0x0b,0x12,0x01}; // LSB */
  880. __u8 reg51c[] = { 0x77, 0x03 };
  881. __u8 val;
  882. reg51c[1] = sd->colors;
  883. regE5acx[2] = sd->contrast;
  884. reg_w(gspca_dev->dev, 0x00e5, regE5acx, 4);
  885. reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */
  886. reg_w(gspca_dev->dev, 0x0051, reg51c, 2);
  887. reg_w(gspca_dev->dev, 0x0010, reg10, 2);
  888. reg_w(gspca_dev->dev, 0x0070, &reg70, 1);
  889. }
  890. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  891. {
  892. struct sd *sd = (struct sd *) gspca_dev;
  893. sd->brightness = val;
  894. if (gspca_dev->streaming)
  895. setbrightness(gspca_dev);
  896. return 0;
  897. }
  898. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  899. {
  900. struct sd *sd = (struct sd *) gspca_dev;
  901. *val = sd->brightness;
  902. return 0;
  903. }
  904. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  905. {
  906. struct sd *sd = (struct sd *) gspca_dev;
  907. sd->contrast = val;
  908. if (gspca_dev->streaming)
  909. setcontrast(gspca_dev);
  910. return 0;
  911. }
  912. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  913. {
  914. struct sd *sd = (struct sd *) gspca_dev;
  915. *val = sd->contrast;
  916. return 0;
  917. }
  918. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  919. {
  920. struct sd *sd = (struct sd *) gspca_dev;
  921. sd->colors = val;
  922. if (gspca_dev->streaming) {
  923. setbrightness(gspca_dev);
  924. setcontrast(gspca_dev);
  925. }
  926. return 0;
  927. }
  928. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  929. {
  930. struct sd *sd = (struct sd *) gspca_dev;
  931. *val = sd->colors;
  932. return 0;
  933. }
  934. /* sub-driver description */
  935. static struct sd_desc sd_desc = {
  936. .name = MODULE_NAME,
  937. .ctrls = sd_ctrls,
  938. .nctrls = ARRAY_SIZE(sd_ctrls),
  939. .config = sd_config,
  940. .open = sd_open,
  941. .start = sd_start,
  942. .stopN = sd_stopN,
  943. .stop0 = sd_stop0,
  944. .close = sd_close,
  945. .pkt_scan = sd_pkt_scan,
  946. };
  947. /* -- module initialisation -- */
  948. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  949. static __devinitdata struct usb_device_id device_table[] = {
  950. {USB_DEVICE(0x0572, 0x0041), DVNM("Creative Notebook cx11646")},
  951. {}
  952. };
  953. MODULE_DEVICE_TABLE(usb, device_table);
  954. /* -- device connect -- */
  955. static int sd_probe(struct usb_interface *intf,
  956. const struct usb_device_id *id)
  957. {
  958. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  959. THIS_MODULE);
  960. }
  961. static struct usb_driver sd_driver = {
  962. .name = MODULE_NAME,
  963. .id_table = device_table,
  964. .probe = sd_probe,
  965. .disconnect = gspca_disconnect,
  966. };
  967. /* -- module insert / remove -- */
  968. static int __init sd_mod_init(void)
  969. {
  970. if (usb_register(&sd_driver) < 0)
  971. return -1;
  972. PDEBUG(D_PROBE, "v%s registered", version);
  973. return 0;
  974. }
  975. static void __exit sd_mod_exit(void)
  976. {
  977. usb_deregister(&sd_driver);
  978. PDEBUG(D_PROBE, "deregistered");
  979. }
  980. module_init(sd_mod_init);
  981. module_exit(sd_mod_exit);