sunplus.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. /*
  2. * Sunplus spca504(abc) spca533 spca536 library
  3. * Copyright (C) 2005 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 "sunplus"
  22. #include "gspca.h"
  23. #include "jpeg.h"
  24. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  25. MODULE_DESCRIPTION("GSPCA/SPCA5xx 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. s8 brightness;
  31. u8 contrast;
  32. u8 colors;
  33. u8 autogain;
  34. u8 quality;
  35. #define QUALITY_MIN 70
  36. #define QUALITY_MAX 95
  37. #define QUALITY_DEF 85
  38. u8 bridge;
  39. #define BRIDGE_SPCA504 0
  40. #define BRIDGE_SPCA504B 1
  41. #define BRIDGE_SPCA504C 2
  42. #define BRIDGE_SPCA533 3
  43. #define BRIDGE_SPCA536 4
  44. u8 subtype;
  45. #define AiptekMiniPenCam13 1
  46. #define LogitechClickSmart420 2
  47. #define LogitechClickSmart820 3
  48. #define MegapixV4 4
  49. #define MegaImageVI 5
  50. u8 *jpeg_hdr;
  51. };
  52. /* V4L2 controls supported by the driver */
  53. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  54. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  55. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  56. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  57. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  58. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  59. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  60. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  61. static const struct ctrl sd_ctrls[] = {
  62. {
  63. {
  64. .id = V4L2_CID_BRIGHTNESS,
  65. .type = V4L2_CTRL_TYPE_INTEGER,
  66. .name = "Brightness",
  67. .minimum = -128,
  68. .maximum = 127,
  69. .step = 1,
  70. #define BRIGHTNESS_DEF 0
  71. .default_value = BRIGHTNESS_DEF,
  72. },
  73. .set = sd_setbrightness,
  74. .get = sd_getbrightness,
  75. },
  76. {
  77. {
  78. .id = V4L2_CID_CONTRAST,
  79. .type = V4L2_CTRL_TYPE_INTEGER,
  80. .name = "Contrast",
  81. .minimum = 0,
  82. .maximum = 0xff,
  83. .step = 1,
  84. #define CONTRAST_DEF 0x20
  85. .default_value = CONTRAST_DEF,
  86. },
  87. .set = sd_setcontrast,
  88. .get = sd_getcontrast,
  89. },
  90. {
  91. {
  92. .id = V4L2_CID_SATURATION,
  93. .type = V4L2_CTRL_TYPE_INTEGER,
  94. .name = "Color",
  95. .minimum = 0,
  96. .maximum = 0xff,
  97. .step = 1,
  98. #define COLOR_DEF 0x1a
  99. .default_value = COLOR_DEF,
  100. },
  101. .set = sd_setcolors,
  102. .get = sd_getcolors,
  103. },
  104. {
  105. {
  106. .id = V4L2_CID_AUTOGAIN,
  107. .type = V4L2_CTRL_TYPE_BOOLEAN,
  108. .name = "Auto Gain",
  109. .minimum = 0,
  110. .maximum = 1,
  111. .step = 1,
  112. #define AUTOGAIN_DEF 1
  113. .default_value = AUTOGAIN_DEF,
  114. },
  115. .set = sd_setautogain,
  116. .get = sd_getautogain,
  117. },
  118. };
  119. static const struct v4l2_pix_format vga_mode[] = {
  120. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  121. .bytesperline = 320,
  122. .sizeimage = 320 * 240 * 3 / 8 + 590,
  123. .colorspace = V4L2_COLORSPACE_JPEG,
  124. .priv = 2},
  125. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  126. .bytesperline = 640,
  127. .sizeimage = 640 * 480 * 3 / 8 + 590,
  128. .colorspace = V4L2_COLORSPACE_JPEG,
  129. .priv = 1},
  130. };
  131. static const struct v4l2_pix_format custom_mode[] = {
  132. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  133. .bytesperline = 320,
  134. .sizeimage = 320 * 240 * 3 / 8 + 590,
  135. .colorspace = V4L2_COLORSPACE_JPEG,
  136. .priv = 2},
  137. {464, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  138. .bytesperline = 464,
  139. .sizeimage = 464 * 480 * 3 / 8 + 590,
  140. .colorspace = V4L2_COLORSPACE_JPEG,
  141. .priv = 1},
  142. };
  143. static const struct v4l2_pix_format vga_mode2[] = {
  144. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  145. .bytesperline = 176,
  146. .sizeimage = 176 * 144 * 3 / 8 + 590,
  147. .colorspace = V4L2_COLORSPACE_JPEG,
  148. .priv = 4},
  149. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  150. .bytesperline = 320,
  151. .sizeimage = 320 * 240 * 3 / 8 + 590,
  152. .colorspace = V4L2_COLORSPACE_JPEG,
  153. .priv = 3},
  154. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  155. .bytesperline = 352,
  156. .sizeimage = 352 * 288 * 3 / 8 + 590,
  157. .colorspace = V4L2_COLORSPACE_JPEG,
  158. .priv = 2},
  159. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  160. .bytesperline = 640,
  161. .sizeimage = 640 * 480 * 3 / 8 + 590,
  162. .colorspace = V4L2_COLORSPACE_JPEG,
  163. .priv = 1},
  164. };
  165. #define SPCA50X_OFFSET_DATA 10
  166. #define SPCA504_PCCAM600_OFFSET_SNAPSHOT 3
  167. #define SPCA504_PCCAM600_OFFSET_COMPRESS 4
  168. #define SPCA504_PCCAM600_OFFSET_MODE 5
  169. #define SPCA504_PCCAM600_OFFSET_DATA 14
  170. /* Frame packet header offsets for the spca533 */
  171. #define SPCA533_OFFSET_DATA 16
  172. #define SPCA533_OFFSET_FRAMSEQ 15
  173. /* Frame packet header offsets for the spca536 */
  174. #define SPCA536_OFFSET_DATA 4
  175. #define SPCA536_OFFSET_FRAMSEQ 1
  176. struct cmd {
  177. u8 req;
  178. u16 val;
  179. u16 idx;
  180. };
  181. /* Initialisation data for the Creative PC-CAM 600 */
  182. static const struct cmd spca504_pccam600_init_data[] = {
  183. /* {0xa0, 0x0000, 0x0503}, * capture mode */
  184. {0x00, 0x0000, 0x2000},
  185. {0x00, 0x0013, 0x2301},
  186. {0x00, 0x0003, 0x2000},
  187. {0x00, 0x0001, 0x21ac},
  188. {0x00, 0x0001, 0x21a6},
  189. {0x00, 0x0000, 0x21a7}, /* brightness */
  190. {0x00, 0x0020, 0x21a8}, /* contrast */
  191. {0x00, 0x0001, 0x21ac}, /* sat/hue */
  192. {0x00, 0x0000, 0x21ad}, /* hue */
  193. {0x00, 0x001a, 0x21ae}, /* saturation */
  194. {0x00, 0x0002, 0x21a3}, /* gamma */
  195. {0x30, 0x0154, 0x0008},
  196. {0x30, 0x0004, 0x0006},
  197. {0x30, 0x0258, 0x0009},
  198. {0x30, 0x0004, 0x0000},
  199. {0x30, 0x0093, 0x0004},
  200. {0x30, 0x0066, 0x0005},
  201. {0x00, 0x0000, 0x2000},
  202. {0x00, 0x0013, 0x2301},
  203. {0x00, 0x0003, 0x2000},
  204. {0x00, 0x0013, 0x2301},
  205. {0x00, 0x0003, 0x2000},
  206. };
  207. /* Creative PC-CAM 600 specific open data, sent before using the
  208. * generic initialisation data from spca504_open_data.
  209. */
  210. static const struct cmd spca504_pccam600_open_data[] = {
  211. {0x00, 0x0001, 0x2501},
  212. {0x20, 0x0500, 0x0001}, /* snapshot mode */
  213. {0x00, 0x0003, 0x2880},
  214. {0x00, 0x0001, 0x2881},
  215. };
  216. /* Initialisation data for the logitech clicksmart 420 */
  217. static const struct cmd spca504A_clicksmart420_init_data[] = {
  218. /* {0xa0, 0x0000, 0x0503}, * capture mode */
  219. {0x00, 0x0000, 0x2000},
  220. {0x00, 0x0013, 0x2301},
  221. {0x00, 0x0003, 0x2000},
  222. {0x00, 0x0001, 0x21ac},
  223. {0x00, 0x0001, 0x21a6},
  224. {0x00, 0x0000, 0x21a7}, /* brightness */
  225. {0x00, 0x0020, 0x21a8}, /* contrast */
  226. {0x00, 0x0001, 0x21ac}, /* sat/hue */
  227. {0x00, 0x0000, 0x21ad}, /* hue */
  228. {0x00, 0x001a, 0x21ae}, /* saturation */
  229. {0x00, 0x0002, 0x21a3}, /* gamma */
  230. {0x30, 0x0004, 0x000a},
  231. {0xb0, 0x0001, 0x0000},
  232. {0xa1, 0x0080, 0x0001},
  233. {0x30, 0x0049, 0x0000},
  234. {0x30, 0x0060, 0x0005},
  235. {0x0c, 0x0004, 0x0000},
  236. {0x00, 0x0000, 0x0000},
  237. {0x00, 0x0000, 0x2000},
  238. {0x00, 0x0013, 0x2301},
  239. {0x00, 0x0003, 0x2000},
  240. {0x00, 0x0000, 0x2000},
  241. };
  242. /* clicksmart 420 open data ? */
  243. static const struct cmd spca504A_clicksmart420_open_data[] = {
  244. {0x00, 0x0001, 0x2501},
  245. {0x20, 0x0502, 0x0000},
  246. {0x06, 0x0000, 0x0000},
  247. {0x00, 0x0004, 0x2880},
  248. {0x00, 0x0001, 0x2881},
  249. {0xa0, 0x0000, 0x0503},
  250. };
  251. static const u8 qtable_creative_pccam[2][64] = {
  252. { /* Q-table Y-components */
  253. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  254. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  255. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  256. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  257. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  258. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  259. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  260. 0x16, 0x1c, 0x1d, 0x1d, 0x22, 0x1e, 0x1f, 0x1e},
  261. { /* Q-table C-components */
  262. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  263. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  264. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  265. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  266. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  267. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  268. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  269. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  270. };
  271. /* FIXME: This Q-table is identical to the Creative PC-CAM one,
  272. * except for one byte. Possibly a typo?
  273. * NWG: 18/05/2003.
  274. */
  275. static const u8 qtable_spca504_default[2][64] = {
  276. { /* Q-table Y-components */
  277. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  278. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  279. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  280. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  281. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  282. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  283. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  284. 0x16, 0x1c, 0x1d, 0x1d, 0x1d /* 0x22 */ , 0x1e, 0x1f, 0x1e,
  285. },
  286. { /* Q-table C-components */
  287. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  288. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  289. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  290. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  291. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  292. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  293. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  294. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  295. };
  296. /* read <len> bytes to gspca_dev->usb_buf */
  297. static void reg_r(struct gspca_dev *gspca_dev,
  298. u8 req,
  299. u16 index,
  300. u16 len)
  301. {
  302. int ret;
  303. #ifdef GSPCA_DEBUG
  304. if (len > USB_BUF_SZ) {
  305. err("reg_r: buffer overflow");
  306. return;
  307. }
  308. #endif
  309. if (gspca_dev->usb_err < 0)
  310. return;
  311. ret = usb_control_msg(gspca_dev->dev,
  312. usb_rcvctrlpipe(gspca_dev->dev, 0),
  313. req,
  314. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  315. 0, /* value */
  316. index,
  317. len ? gspca_dev->usb_buf : NULL, len,
  318. 500);
  319. if (ret < 0) {
  320. PDEBUG(D_ERR, "reg_r err %d", ret);
  321. gspca_dev->usb_err = ret;
  322. }
  323. }
  324. /* write one byte */
  325. static void reg_w_1(struct gspca_dev *gspca_dev,
  326. u8 req,
  327. u16 value,
  328. u16 index,
  329. u16 byte)
  330. {
  331. int ret;
  332. if (gspca_dev->usb_err < 0)
  333. return;
  334. gspca_dev->usb_buf[0] = byte;
  335. ret = usb_control_msg(gspca_dev->dev,
  336. usb_sndctrlpipe(gspca_dev->dev, 0),
  337. req,
  338. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  339. value, index,
  340. gspca_dev->usb_buf, 1,
  341. 500);
  342. if (ret < 0) {
  343. PDEBUG(D_ERR, "reg_w_1 err %d", ret);
  344. gspca_dev->usb_err = ret;
  345. }
  346. }
  347. /* write req / index / value */
  348. static void reg_w_riv(struct gspca_dev *gspca_dev,
  349. u8 req, u16 index, u16 value)
  350. {
  351. struct usb_device *dev = gspca_dev->dev;
  352. int ret;
  353. if (gspca_dev->usb_err < 0)
  354. return;
  355. ret = usb_control_msg(dev,
  356. usb_sndctrlpipe(dev, 0),
  357. req,
  358. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  359. value, index, NULL, 0, 500);
  360. if (ret < 0) {
  361. PDEBUG(D_ERR, "reg_w_riv err %d", ret);
  362. gspca_dev->usb_err = ret;
  363. return;
  364. }
  365. PDEBUG(D_USBO, "reg_w_riv: 0x%02x,0x%04x:0x%04x",
  366. req, index, value);
  367. }
  368. /* read 1 byte */
  369. static u8 reg_r_1(struct gspca_dev *gspca_dev,
  370. u16 value) /* wValue */
  371. {
  372. int ret;
  373. if (gspca_dev->usb_err < 0)
  374. return 0;
  375. ret = usb_control_msg(gspca_dev->dev,
  376. usb_rcvctrlpipe(gspca_dev->dev, 0),
  377. 0x20, /* request */
  378. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  379. value,
  380. 0, /* index */
  381. gspca_dev->usb_buf, 1,
  382. 500); /* timeout */
  383. if (ret < 0) {
  384. PDEBUG(D_ERR, "reg_r_1 err %d", ret);
  385. gspca_dev->usb_err = ret;
  386. return 0;
  387. }
  388. return gspca_dev->usb_buf[0];
  389. }
  390. /* read 1 or 2 bytes */
  391. static u16 reg_r_12(struct gspca_dev *gspca_dev,
  392. u8 req, /* bRequest */
  393. u16 index, /* wIndex */
  394. u16 length) /* wLength (1 or 2 only) */
  395. {
  396. int ret;
  397. if (gspca_dev->usb_err < 0)
  398. return 0;
  399. gspca_dev->usb_buf[1] = 0;
  400. ret = usb_control_msg(gspca_dev->dev,
  401. usb_rcvctrlpipe(gspca_dev->dev, 0),
  402. req,
  403. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  404. 0, /* value */
  405. index,
  406. gspca_dev->usb_buf, length,
  407. 500);
  408. if (ret < 0) {
  409. PDEBUG(D_ERR, "reg_r_12 err %d", ret);
  410. gspca_dev->usb_err = ret;
  411. return 0;
  412. }
  413. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  414. }
  415. static void write_vector(struct gspca_dev *gspca_dev,
  416. const struct cmd *data, int ncmds)
  417. {
  418. while (--ncmds >= 0) {
  419. reg_w_riv(gspca_dev, data->req, data->idx, data->val);
  420. data++;
  421. }
  422. }
  423. static void setup_qtable(struct gspca_dev *gspca_dev,
  424. const u8 qtable[2][64])
  425. {
  426. int i;
  427. /* loop over y components */
  428. for (i = 0; i < 64; i++)
  429. reg_w_riv(gspca_dev, 0x00, 0x2800 + i, qtable[0][i]);
  430. /* loop over c components */
  431. for (i = 0; i < 64; i++)
  432. reg_w_riv(gspca_dev, 0x00, 0x2840 + i, qtable[1][i]);
  433. }
  434. static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
  435. u8 req, u16 idx, u16 val)
  436. {
  437. u16 notdone;
  438. reg_w_riv(gspca_dev, req, idx, val);
  439. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  440. reg_w_riv(gspca_dev, req, idx, val);
  441. PDEBUG(D_FRAM, "before wait 0x%04x", notdone);
  442. msleep(200);
  443. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  444. PDEBUG(D_FRAM, "after wait 0x%04x", notdone);
  445. }
  446. static void spca504_read_info(struct gspca_dev *gspca_dev)
  447. {
  448. int i;
  449. u8 info[6];
  450. for (i = 0; i < 6; i++)
  451. info[i] = reg_r_1(gspca_dev, i);
  452. PDEBUG(D_STREAM,
  453. "Read info: %d %d %d %d %d %d."
  454. " Should be 1,0,2,2,0,0",
  455. info[0], info[1], info[2],
  456. info[3], info[4], info[5]);
  457. }
  458. static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
  459. u8 req,
  460. u16 idx, u16 val, u16 endcode, u8 count)
  461. {
  462. u16 status;
  463. reg_w_riv(gspca_dev, req, idx, val);
  464. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  465. if (gspca_dev->usb_err < 0)
  466. return;
  467. PDEBUG(D_FRAM, "Status 0x%04x Need 0x%04x", status, endcode);
  468. if (!count)
  469. return;
  470. count = 200;
  471. while (--count > 0) {
  472. msleep(10);
  473. /* gsmart mini2 write a each wait setting 1 ms is enough */
  474. /* reg_w_riv(gspca_dev, req, idx, val); */
  475. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  476. if (status == endcode) {
  477. PDEBUG(D_FRAM, "status 0x%04x after wait %d",
  478. status, 200 - count);
  479. break;
  480. }
  481. }
  482. }
  483. static void spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
  484. {
  485. int count = 10;
  486. while (--count > 0) {
  487. reg_r(gspca_dev, 0x21, 0, 1);
  488. if ((gspca_dev->usb_buf[0] & 0x01) == 0)
  489. break;
  490. msleep(10);
  491. }
  492. }
  493. static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
  494. {
  495. int count = 50;
  496. while (--count > 0) {
  497. reg_r(gspca_dev, 0x21, 1, 1);
  498. if (gspca_dev->usb_buf[0] != 0) {
  499. reg_w_1(gspca_dev, 0x21, 0, 1, 0);
  500. reg_r(gspca_dev, 0x21, 1, 1);
  501. spca504B_PollingDataReady(gspca_dev);
  502. break;
  503. }
  504. msleep(10);
  505. }
  506. }
  507. static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
  508. {
  509. u8 *data;
  510. data = gspca_dev->usb_buf;
  511. reg_r(gspca_dev, 0x20, 0, 5);
  512. PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ",
  513. data[0], data[1], data[2], data[3], data[4]);
  514. reg_r(gspca_dev, 0x23, 0, 64);
  515. reg_r(gspca_dev, 0x23, 1, 64);
  516. }
  517. static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
  518. {
  519. struct sd *sd = (struct sd *) gspca_dev;
  520. u8 Size;
  521. Size = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  522. switch (sd->bridge) {
  523. case BRIDGE_SPCA533:
  524. reg_w_riv(gspca_dev, 0x31, 0, 0);
  525. spca504B_WaitCmdStatus(gspca_dev);
  526. spca504B_PollingDataReady(gspca_dev);
  527. spca50x_GetFirmware(gspca_dev);
  528. reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */
  529. reg_r(gspca_dev, 0x24, 8, 1);
  530. reg_w_1(gspca_dev, 0x25, 0, 4, Size);
  531. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  532. spca504B_PollingDataReady(gspca_dev);
  533. /* Init the cam width height with some values get on init ? */
  534. reg_w_riv(gspca_dev, 0x31, 0x0004, 0x00);
  535. spca504B_WaitCmdStatus(gspca_dev);
  536. spca504B_PollingDataReady(gspca_dev);
  537. break;
  538. default:
  539. /* case BRIDGE_SPCA504B: */
  540. /* case BRIDGE_SPCA536: */
  541. reg_w_1(gspca_dev, 0x25, 0, 4, Size);
  542. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  543. reg_w_1(gspca_dev, 0x27, 0, 0, 6);
  544. reg_r(gspca_dev, 0x27, 0, 1); /* type */
  545. spca504B_PollingDataReady(gspca_dev);
  546. break;
  547. case BRIDGE_SPCA504:
  548. Size += 3;
  549. if (sd->subtype == AiptekMiniPenCam13) {
  550. /* spca504a aiptek */
  551. spca504A_acknowledged_command(gspca_dev,
  552. 0x08, Size, 0,
  553. 0x80 | (Size & 0x0f), 1);
  554. spca504A_acknowledged_command(gspca_dev,
  555. 1, 3, 0, 0x9f, 0);
  556. } else {
  557. spca504_acknowledged_command(gspca_dev, 0x08, Size, 0);
  558. }
  559. break;
  560. case BRIDGE_SPCA504C:
  561. /* capture mode */
  562. reg_w_riv(gspca_dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x00);
  563. reg_w_riv(gspca_dev, 0x20, 0x01, 0x0500 | (Size & 0x0f));
  564. break;
  565. }
  566. }
  567. static void spca504_wait_status(struct gspca_dev *gspca_dev)
  568. {
  569. int cnt;
  570. cnt = 256;
  571. while (--cnt > 0) {
  572. /* With this we get the status, when return 0 it's all ok */
  573. if (reg_r_12(gspca_dev, 0x06, 0x00, 1) == 0)
  574. return;
  575. msleep(10);
  576. }
  577. }
  578. static void spca504B_setQtable(struct gspca_dev *gspca_dev)
  579. {
  580. reg_w_1(gspca_dev, 0x26, 0, 0, 3);
  581. reg_r(gspca_dev, 0x26, 0, 1);
  582. spca504B_PollingDataReady(gspca_dev);
  583. }
  584. static void setbrightness(struct gspca_dev *gspca_dev)
  585. {
  586. struct sd *sd = (struct sd *) gspca_dev;
  587. u16 reg;
  588. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
  589. reg_w_riv(gspca_dev, 0x00, reg, sd->brightness);
  590. }
  591. static void setcontrast(struct gspca_dev *gspca_dev)
  592. {
  593. struct sd *sd = (struct sd *) gspca_dev;
  594. u16 reg;
  595. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
  596. reg_w_riv(gspca_dev, 0x00, reg, sd->contrast);
  597. }
  598. static void setcolors(struct gspca_dev *gspca_dev)
  599. {
  600. struct sd *sd = (struct sd *) gspca_dev;
  601. u16 reg;
  602. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
  603. reg_w_riv(gspca_dev, 0x00, reg, sd->colors);
  604. }
  605. static void init_ctl_reg(struct gspca_dev *gspca_dev)
  606. {
  607. struct sd *sd = (struct sd *) gspca_dev;
  608. int pollreg = 1;
  609. setbrightness(gspca_dev);
  610. setcontrast(gspca_dev);
  611. setcolors(gspca_dev);
  612. switch (sd->bridge) {
  613. case BRIDGE_SPCA504:
  614. case BRIDGE_SPCA504C:
  615. pollreg = 0;
  616. /* fall thru */
  617. default:
  618. /* case BRIDGE_SPCA533: */
  619. /* case BRIDGE_SPCA504B: */
  620. reg_w_riv(gspca_dev, 0, 0x21ad, 0x00); /* hue */
  621. reg_w_riv(gspca_dev, 0, 0x21ac, 0x01); /* sat/hue */
  622. reg_w_riv(gspca_dev, 0, 0x21a3, 0x00); /* gamma */
  623. break;
  624. case BRIDGE_SPCA536:
  625. reg_w_riv(gspca_dev, 0, 0x20f5, 0x40);
  626. reg_w_riv(gspca_dev, 0, 0x20f4, 0x01);
  627. reg_w_riv(gspca_dev, 0, 0x2089, 0x00);
  628. break;
  629. }
  630. if (pollreg)
  631. spca504B_PollingDataReady(gspca_dev);
  632. }
  633. /* this function is called at probe time */
  634. static int sd_config(struct gspca_dev *gspca_dev,
  635. const struct usb_device_id *id)
  636. {
  637. struct sd *sd = (struct sd *) gspca_dev;
  638. struct cam *cam;
  639. cam = &gspca_dev->cam;
  640. sd->bridge = id->driver_info >> 8;
  641. sd->subtype = id->driver_info;
  642. if (sd->subtype == AiptekMiniPenCam13) {
  643. /* try to get the firmware as some cam answer 2.0.1.2.2
  644. * and should be a spca504b then overwrite that setting */
  645. reg_r(gspca_dev, 0x20, 0, 1);
  646. switch (gspca_dev->usb_buf[0]) {
  647. case 1:
  648. break; /* (right bridge/subtype) */
  649. case 2:
  650. sd->bridge = BRIDGE_SPCA504B;
  651. sd->subtype = 0;
  652. break;
  653. default:
  654. return -ENODEV;
  655. }
  656. }
  657. switch (sd->bridge) {
  658. default:
  659. /* case BRIDGE_SPCA504B: */
  660. /* case BRIDGE_SPCA504: */
  661. /* case BRIDGE_SPCA536: */
  662. cam->cam_mode = vga_mode;
  663. cam->nmodes =ARRAY_SIZE(vga_mode);
  664. break;
  665. case BRIDGE_SPCA533:
  666. cam->cam_mode = custom_mode;
  667. if (sd->subtype == MegaImageVI) /* 320x240 only */
  668. cam->nmodes = ARRAY_SIZE(custom_mode) - 1;
  669. else
  670. cam->nmodes = ARRAY_SIZE(custom_mode);
  671. break;
  672. case BRIDGE_SPCA504C:
  673. cam->cam_mode = vga_mode2;
  674. cam->nmodes = ARRAY_SIZE(vga_mode2);
  675. break;
  676. }
  677. sd->brightness = BRIGHTNESS_DEF;
  678. sd->contrast = CONTRAST_DEF;
  679. sd->colors = COLOR_DEF;
  680. sd->autogain = AUTOGAIN_DEF;
  681. sd->quality = QUALITY_DEF;
  682. return 0;
  683. }
  684. /* this function is called at probe and resume time */
  685. static int sd_init(struct gspca_dev *gspca_dev)
  686. {
  687. struct sd *sd = (struct sd *) gspca_dev;
  688. switch (sd->bridge) {
  689. case BRIDGE_SPCA504B:
  690. reg_w_riv(gspca_dev, 0x1d, 0x00, 0);
  691. reg_w_riv(gspca_dev, 0x00, 0x2306, 0x01);
  692. reg_w_riv(gspca_dev, 0x00, 0x0d04, 0x00);
  693. reg_w_riv(gspca_dev, 0x00, 0x2000, 0x00);
  694. reg_w_riv(gspca_dev, 0x00, 0x2301, 0x13);
  695. reg_w_riv(gspca_dev, 0x00, 0x2306, 0x00);
  696. /* fall thru */
  697. case BRIDGE_SPCA533:
  698. spca504B_PollingDataReady(gspca_dev);
  699. spca50x_GetFirmware(gspca_dev);
  700. break;
  701. case BRIDGE_SPCA536:
  702. spca50x_GetFirmware(gspca_dev);
  703. reg_r(gspca_dev, 0x00, 0x5002, 1);
  704. reg_w_1(gspca_dev, 0x24, 0, 0, 0);
  705. reg_r(gspca_dev, 0x24, 0, 1);
  706. spca504B_PollingDataReady(gspca_dev);
  707. reg_w_riv(gspca_dev, 0x34, 0, 0);
  708. spca504B_WaitCmdStatus(gspca_dev);
  709. break;
  710. case BRIDGE_SPCA504C: /* pccam600 */
  711. PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)");
  712. reg_w_riv(gspca_dev, 0xe0, 0x0000, 0x0000);
  713. reg_w_riv(gspca_dev, 0xe0, 0x0000, 0x0001); /* reset */
  714. spca504_wait_status(gspca_dev);
  715. if (sd->subtype == LogitechClickSmart420)
  716. write_vector(gspca_dev,
  717. spca504A_clicksmart420_open_data,
  718. ARRAY_SIZE(spca504A_clicksmart420_open_data));
  719. else
  720. write_vector(gspca_dev, spca504_pccam600_open_data,
  721. ARRAY_SIZE(spca504_pccam600_open_data));
  722. setup_qtable(gspca_dev, qtable_creative_pccam);
  723. break;
  724. default:
  725. /* case BRIDGE_SPCA504: */
  726. PDEBUG(D_STREAM, "Opening SPCA504");
  727. if (sd->subtype == AiptekMiniPenCam13) {
  728. spca504_read_info(gspca_dev);
  729. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  730. spca504A_acknowledged_command(gspca_dev, 0x24,
  731. 8, 3, 0x9e, 1);
  732. /* Twice sequencial need status 0xff->0x9e->0x9d */
  733. spca504A_acknowledged_command(gspca_dev, 0x24,
  734. 8, 3, 0x9e, 0);
  735. spca504A_acknowledged_command(gspca_dev, 0x24,
  736. 0, 0, 0x9d, 1);
  737. /******************************/
  738. /* spca504a aiptek */
  739. spca504A_acknowledged_command(gspca_dev, 0x08,
  740. 6, 0, 0x86, 1);
  741. /* reg_write (dev, 0, 0x2000, 0); */
  742. /* reg_write (dev, 0, 0x2883, 1); */
  743. /* spca504A_acknowledged_command (gspca_dev, 0x08,
  744. 6, 0, 0x86, 1); */
  745. /* spca504A_acknowledged_command (gspca_dev, 0x24,
  746. 0, 0, 0x9D, 1); */
  747. reg_w_riv(gspca_dev, 0x00, 0x270c, 0x05);
  748. /* L92 sno1t.txt */
  749. reg_w_riv(gspca_dev, 0x00, 0x2310, 0x05);
  750. spca504A_acknowledged_command(gspca_dev, 0x01,
  751. 0x0f, 0, 0xff, 0);
  752. }
  753. /* setup qtable */
  754. reg_w_riv(gspca_dev, 0, 0x2000, 0);
  755. reg_w_riv(gspca_dev, 0, 0x2883, 1);
  756. setup_qtable(gspca_dev, qtable_spca504_default);
  757. break;
  758. }
  759. return gspca_dev->usb_err;
  760. }
  761. static int sd_start(struct gspca_dev *gspca_dev)
  762. {
  763. struct sd *sd = (struct sd *) gspca_dev;
  764. int enable;
  765. /* create the JPEG header */
  766. sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
  767. if (!sd->jpeg_hdr)
  768. return -ENOMEM;
  769. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  770. 0x22); /* JPEG 411 */
  771. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  772. if (sd->bridge == BRIDGE_SPCA504B)
  773. spca504B_setQtable(gspca_dev);
  774. spca504B_SetSizeType(gspca_dev);
  775. switch (sd->bridge) {
  776. default:
  777. /* case BRIDGE_SPCA504B: */
  778. /* case BRIDGE_SPCA533: */
  779. /* case BRIDGE_SPCA536: */
  780. switch (sd->subtype) {
  781. case MegapixV4:
  782. case LogitechClickSmart820:
  783. case MegaImageVI:
  784. reg_w_riv(gspca_dev, 0xf0, 0, 0);
  785. spca504B_WaitCmdStatus(gspca_dev);
  786. reg_r(gspca_dev, 0xf0, 4, 0);
  787. spca504B_WaitCmdStatus(gspca_dev);
  788. break;
  789. default:
  790. reg_w_riv(gspca_dev, 0x31, 0x0004, 0x00);
  791. spca504B_WaitCmdStatus(gspca_dev);
  792. spca504B_PollingDataReady(gspca_dev);
  793. break;
  794. }
  795. break;
  796. case BRIDGE_SPCA504:
  797. if (sd->subtype == AiptekMiniPenCam13) {
  798. spca504_read_info(gspca_dev);
  799. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  800. spca504A_acknowledged_command(gspca_dev, 0x24,
  801. 8, 3, 0x9e, 1);
  802. /* Twice sequencial need status 0xff->0x9e->0x9d */
  803. spca504A_acknowledged_command(gspca_dev, 0x24,
  804. 8, 3, 0x9e, 0);
  805. spca504A_acknowledged_command(gspca_dev, 0x24,
  806. 0, 0, 0x9d, 1);
  807. } else {
  808. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  809. spca504_read_info(gspca_dev);
  810. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  811. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  812. }
  813. spca504B_SetSizeType(gspca_dev);
  814. reg_w_riv(gspca_dev, 0x00, 0x270c, 0x05);
  815. /* L92 sno1t.txt */
  816. reg_w_riv(gspca_dev, 0x00, 0x2310, 0x05);
  817. break;
  818. case BRIDGE_SPCA504C:
  819. if (sd->subtype == LogitechClickSmart420) {
  820. write_vector(gspca_dev,
  821. spca504A_clicksmart420_init_data,
  822. ARRAY_SIZE(spca504A_clicksmart420_init_data));
  823. } else {
  824. write_vector(gspca_dev, spca504_pccam600_init_data,
  825. ARRAY_SIZE(spca504_pccam600_init_data));
  826. }
  827. enable = (sd->autogain ? 0x04 : 0x01);
  828. reg_w_riv(gspca_dev, 0x0c, 0x0000, enable);
  829. /* auto exposure */
  830. reg_w_riv(gspca_dev, 0xb0, 0x0000, enable);
  831. /* auto whiteness */
  832. /* set default exposure compensation and whiteness balance */
  833. reg_w_riv(gspca_dev, 0x30, 0x0001, 800); /* ~ 20 fps */
  834. reg_w_riv(gspca_dev, 0x30, 0x0002, 1600);
  835. spca504B_SetSizeType(gspca_dev);
  836. break;
  837. }
  838. init_ctl_reg(gspca_dev);
  839. return gspca_dev->usb_err;
  840. }
  841. static void sd_stopN(struct gspca_dev *gspca_dev)
  842. {
  843. struct sd *sd = (struct sd *) gspca_dev;
  844. switch (sd->bridge) {
  845. default:
  846. /* case BRIDGE_SPCA533: */
  847. /* case BRIDGE_SPCA536: */
  848. /* case BRIDGE_SPCA504B: */
  849. reg_w_riv(gspca_dev, 0x31, 0, 0);
  850. spca504B_WaitCmdStatus(gspca_dev);
  851. spca504B_PollingDataReady(gspca_dev);
  852. break;
  853. case BRIDGE_SPCA504:
  854. case BRIDGE_SPCA504C:
  855. reg_w_riv(gspca_dev, 0x00, 0x2000, 0x0000);
  856. if (sd->subtype == AiptekMiniPenCam13) {
  857. /* spca504a aiptek */
  858. /* spca504A_acknowledged_command(gspca_dev, 0x08,
  859. 6, 0, 0x86, 1); */
  860. spca504A_acknowledged_command(gspca_dev, 0x24,
  861. 0x00, 0x00, 0x9d, 1);
  862. spca504A_acknowledged_command(gspca_dev, 0x01,
  863. 0x0f, 0x00, 0xff, 1);
  864. } else {
  865. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  866. reg_w_riv(gspca_dev, 0x01, 0x000f, 0x0000);
  867. }
  868. break;
  869. }
  870. }
  871. static void sd_stop0(struct gspca_dev *gspca_dev)
  872. {
  873. struct sd *sd = (struct sd *) gspca_dev;
  874. kfree(sd->jpeg_hdr);
  875. }
  876. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  877. u8 *data, /* isoc packet */
  878. int len) /* iso packet length */
  879. {
  880. struct sd *sd = (struct sd *) gspca_dev;
  881. int i, sof = 0;
  882. static u8 ffd9[] = {0xff, 0xd9};
  883. /* frames are jpeg 4.1.1 without 0xff escape */
  884. switch (sd->bridge) {
  885. case BRIDGE_SPCA533:
  886. if (data[0] == 0xff) {
  887. if (data[1] != 0x01) { /* drop packet */
  888. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  889. return;
  890. }
  891. sof = 1;
  892. data += SPCA533_OFFSET_DATA;
  893. len -= SPCA533_OFFSET_DATA;
  894. } else {
  895. data += 1;
  896. len -= 1;
  897. }
  898. break;
  899. case BRIDGE_SPCA536:
  900. if (data[0] == 0xff) {
  901. sof = 1;
  902. data += SPCA536_OFFSET_DATA;
  903. len -= SPCA536_OFFSET_DATA;
  904. } else {
  905. data += 2;
  906. len -= 2;
  907. }
  908. break;
  909. default:
  910. /* case BRIDGE_SPCA504: */
  911. /* case BRIDGE_SPCA504B: */
  912. switch (data[0]) {
  913. case 0xfe: /* start of frame */
  914. sof = 1;
  915. data += SPCA50X_OFFSET_DATA;
  916. len -= SPCA50X_OFFSET_DATA;
  917. break;
  918. case 0xff: /* drop packet */
  919. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  920. return;
  921. default:
  922. data += 1;
  923. len -= 1;
  924. break;
  925. }
  926. break;
  927. case BRIDGE_SPCA504C:
  928. switch (data[0]) {
  929. case 0xfe: /* start of frame */
  930. sof = 1;
  931. data += SPCA504_PCCAM600_OFFSET_DATA;
  932. len -= SPCA504_PCCAM600_OFFSET_DATA;
  933. break;
  934. case 0xff: /* drop packet */
  935. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  936. return;
  937. default:
  938. data += 1;
  939. len -= 1;
  940. break;
  941. }
  942. break;
  943. }
  944. if (sof) { /* start of frame */
  945. gspca_frame_add(gspca_dev, LAST_PACKET,
  946. ffd9, 2);
  947. /* put the JPEG header in the new frame */
  948. gspca_frame_add(gspca_dev, FIRST_PACKET,
  949. sd->jpeg_hdr, JPEG_HDR_SZ);
  950. }
  951. /* add 0x00 after 0xff */
  952. i = 0;
  953. do {
  954. if (data[i] == 0xff) {
  955. gspca_frame_add(gspca_dev, INTER_PACKET,
  956. data, i + 1);
  957. len -= i;
  958. data += i;
  959. *data = 0x00;
  960. i = 0;
  961. }
  962. i++;
  963. } while (i < len);
  964. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  965. }
  966. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  967. {
  968. struct sd *sd = (struct sd *) gspca_dev;
  969. sd->brightness = val;
  970. if (gspca_dev->streaming)
  971. setbrightness(gspca_dev);
  972. return gspca_dev->usb_err;
  973. }
  974. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  975. {
  976. struct sd *sd = (struct sd *) gspca_dev;
  977. *val = sd->brightness;
  978. return 0;
  979. }
  980. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  981. {
  982. struct sd *sd = (struct sd *) gspca_dev;
  983. sd->contrast = val;
  984. if (gspca_dev->streaming)
  985. setcontrast(gspca_dev);
  986. return gspca_dev->usb_err;
  987. }
  988. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  989. {
  990. struct sd *sd = (struct sd *) gspca_dev;
  991. *val = sd->contrast;
  992. return 0;
  993. }
  994. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  995. {
  996. struct sd *sd = (struct sd *) gspca_dev;
  997. sd->colors = val;
  998. if (gspca_dev->streaming)
  999. setcolors(gspca_dev);
  1000. return gspca_dev->usb_err;
  1001. }
  1002. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1003. {
  1004. struct sd *sd = (struct sd *) gspca_dev;
  1005. *val = sd->colors;
  1006. return 0;
  1007. }
  1008. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1009. {
  1010. struct sd *sd = (struct sd *) gspca_dev;
  1011. sd->autogain = val;
  1012. return 0;
  1013. }
  1014. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1015. {
  1016. struct sd *sd = (struct sd *) gspca_dev;
  1017. *val = sd->autogain;
  1018. return 0;
  1019. }
  1020. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  1021. struct v4l2_jpegcompression *jcomp)
  1022. {
  1023. struct sd *sd = (struct sd *) gspca_dev;
  1024. if (jcomp->quality < QUALITY_MIN)
  1025. sd->quality = QUALITY_MIN;
  1026. else if (jcomp->quality > QUALITY_MAX)
  1027. sd->quality = QUALITY_MAX;
  1028. else
  1029. sd->quality = jcomp->quality;
  1030. if (gspca_dev->streaming)
  1031. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  1032. return gspca_dev->usb_err;
  1033. }
  1034. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  1035. struct v4l2_jpegcompression *jcomp)
  1036. {
  1037. struct sd *sd = (struct sd *) gspca_dev;
  1038. memset(jcomp, 0, sizeof *jcomp);
  1039. jcomp->quality = sd->quality;
  1040. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  1041. | V4L2_JPEG_MARKER_DQT;
  1042. return 0;
  1043. }
  1044. /* sub-driver description */
  1045. static const struct sd_desc sd_desc = {
  1046. .name = MODULE_NAME,
  1047. .ctrls = sd_ctrls,
  1048. .nctrls = ARRAY_SIZE(sd_ctrls),
  1049. .config = sd_config,
  1050. .init = sd_init,
  1051. .start = sd_start,
  1052. .stopN = sd_stopN,
  1053. .stop0 = sd_stop0,
  1054. .pkt_scan = sd_pkt_scan,
  1055. .get_jcomp = sd_get_jcomp,
  1056. .set_jcomp = sd_set_jcomp,
  1057. };
  1058. /* -- module initialisation -- */
  1059. #define BS(bridge, subtype) \
  1060. .driver_info = (BRIDGE_ ## bridge << 8) \
  1061. | (subtype)
  1062. static const __devinitdata struct usb_device_id device_table[] = {
  1063. {USB_DEVICE(0x041e, 0x400b), BS(SPCA504C, 0)},
  1064. {USB_DEVICE(0x041e, 0x4012), BS(SPCA504C, 0)},
  1065. {USB_DEVICE(0x041e, 0x4013), BS(SPCA504C, 0)},
  1066. {USB_DEVICE(0x0458, 0x7006), BS(SPCA504B, 0)},
  1067. {USB_DEVICE(0x0461, 0x0821), BS(SPCA533, 0)},
  1068. {USB_DEVICE(0x046d, 0x0905), BS(SPCA533, LogitechClickSmart820)},
  1069. {USB_DEVICE(0x046d, 0x0960), BS(SPCA504C, LogitechClickSmart420)},
  1070. {USB_DEVICE(0x0471, 0x0322), BS(SPCA504B, 0)},
  1071. {USB_DEVICE(0x04a5, 0x3003), BS(SPCA504B, 0)},
  1072. {USB_DEVICE(0x04a5, 0x3008), BS(SPCA533, 0)},
  1073. {USB_DEVICE(0x04a5, 0x300a), BS(SPCA533, 0)},
  1074. {USB_DEVICE(0x04f1, 0x1001), BS(SPCA504B, 0)},
  1075. {USB_DEVICE(0x04fc, 0x500c), BS(SPCA504B, 0)},
  1076. {USB_DEVICE(0x04fc, 0x504a), BS(SPCA504, AiptekMiniPenCam13)},
  1077. {USB_DEVICE(0x04fc, 0x504b), BS(SPCA504B, 0)},
  1078. {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)},
  1079. {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
  1080. {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
  1081. {USB_DEVICE(0x052b, 0x1507), BS(SPCA533, MegapixV4)},
  1082. {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
  1083. {USB_DEVICE(0x052b, 0x1803), BS(SPCA533, MegaImageVI)},
  1084. {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
  1085. {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)},
  1086. {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)},
  1087. {USB_DEVICE(0x055f, 0xc211), BS(SPCA536, 0)},
  1088. {USB_DEVICE(0x055f, 0xc230), BS(SPCA533, 0)},
  1089. {USB_DEVICE(0x055f, 0xc232), BS(SPCA533, 0)},
  1090. {USB_DEVICE(0x055f, 0xc360), BS(SPCA536, 0)},
  1091. {USB_DEVICE(0x055f, 0xc420), BS(SPCA504, 0)},
  1092. {USB_DEVICE(0x055f, 0xc430), BS(SPCA533, 0)},
  1093. {USB_DEVICE(0x055f, 0xc440), BS(SPCA533, 0)},
  1094. {USB_DEVICE(0x055f, 0xc520), BS(SPCA504, 0)},
  1095. {USB_DEVICE(0x055f, 0xc530), BS(SPCA533, 0)},
  1096. {USB_DEVICE(0x055f, 0xc540), BS(SPCA533, 0)},
  1097. {USB_DEVICE(0x055f, 0xc630), BS(SPCA533, 0)},
  1098. {USB_DEVICE(0x055f, 0xc650), BS(SPCA533, 0)},
  1099. {USB_DEVICE(0x05da, 0x1018), BS(SPCA504B, 0)},
  1100. {USB_DEVICE(0x06d6, 0x0031), BS(SPCA533, 0)},
  1101. {USB_DEVICE(0x0733, 0x1311), BS(SPCA533, 0)},
  1102. {USB_DEVICE(0x0733, 0x1314), BS(SPCA533, 0)},
  1103. {USB_DEVICE(0x0733, 0x2211), BS(SPCA533, 0)},
  1104. {USB_DEVICE(0x0733, 0x2221), BS(SPCA533, 0)},
  1105. {USB_DEVICE(0x0733, 0x3261), BS(SPCA536, 0)},
  1106. {USB_DEVICE(0x0733, 0x3281), BS(SPCA536, 0)},
  1107. {USB_DEVICE(0x08ca, 0x0104), BS(SPCA533, 0)},
  1108. {USB_DEVICE(0x08ca, 0x0106), BS(SPCA533, 0)},
  1109. {USB_DEVICE(0x08ca, 0x2008), BS(SPCA504B, 0)},
  1110. {USB_DEVICE(0x08ca, 0x2010), BS(SPCA533, 0)},
  1111. {USB_DEVICE(0x08ca, 0x2016), BS(SPCA504B, 0)},
  1112. {USB_DEVICE(0x08ca, 0x2018), BS(SPCA504B, 0)},
  1113. {USB_DEVICE(0x08ca, 0x2020), BS(SPCA533, 0)},
  1114. {USB_DEVICE(0x08ca, 0x2022), BS(SPCA533, 0)},
  1115. {USB_DEVICE(0x08ca, 0x2024), BS(SPCA536, 0)},
  1116. {USB_DEVICE(0x08ca, 0x2028), BS(SPCA533, 0)},
  1117. {USB_DEVICE(0x08ca, 0x2040), BS(SPCA536, 0)},
  1118. {USB_DEVICE(0x08ca, 0x2042), BS(SPCA536, 0)},
  1119. {USB_DEVICE(0x08ca, 0x2050), BS(SPCA536, 0)},
  1120. {USB_DEVICE(0x08ca, 0x2060), BS(SPCA536, 0)},
  1121. {USB_DEVICE(0x0d64, 0x0303), BS(SPCA536, 0)},
  1122. {}
  1123. };
  1124. MODULE_DEVICE_TABLE(usb, device_table);
  1125. /* -- device connect -- */
  1126. static int sd_probe(struct usb_interface *intf,
  1127. const struct usb_device_id *id)
  1128. {
  1129. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1130. THIS_MODULE);
  1131. }
  1132. static struct usb_driver sd_driver = {
  1133. .name = MODULE_NAME,
  1134. .id_table = device_table,
  1135. .probe = sd_probe,
  1136. .disconnect = gspca_disconnect,
  1137. #ifdef CONFIG_PM
  1138. .suspend = gspca_suspend,
  1139. .resume = gspca_resume,
  1140. #endif
  1141. };
  1142. /* -- module insert / remove -- */
  1143. static int __init sd_mod_init(void)
  1144. {
  1145. int ret;
  1146. ret = usb_register(&sd_driver);
  1147. if (ret < 0)
  1148. return ret;
  1149. PDEBUG(D_PROBE, "registered");
  1150. return 0;
  1151. }
  1152. static void __exit sd_mod_exit(void)
  1153. {
  1154. usb_deregister(&sd_driver);
  1155. PDEBUG(D_PROBE, "deregistered");
  1156. }
  1157. module_init(sd_mod_init);
  1158. module_exit(sd_mod_exit);