conex.c 30 KB

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