sunplus.c 32 KB

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