sunplus.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  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 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. /* look like setting a qTable */
  250. {0x00, 0x0006, 0x2800},
  251. {0x00, 0x0004, 0x2801},
  252. {0x00, 0x0004, 0x2802},
  253. {0x00, 0x0006, 0x2803},
  254. {0x00, 0x000a, 0x2804},
  255. {0x00, 0x0010, 0x2805},
  256. {0x00, 0x0014, 0x2806},
  257. {0x00, 0x0018, 0x2807},
  258. {0x00, 0x0005, 0x2808},
  259. {0x00, 0x0005, 0x2809},
  260. {0x00, 0x0006, 0x280a},
  261. {0x00, 0x0008, 0x280b},
  262. {0x00, 0x000a, 0x280c},
  263. {0x00, 0x0017, 0x280d},
  264. {0x00, 0x0018, 0x280e},
  265. {0x00, 0x0016, 0x280f},
  266. {0x00, 0x0006, 0x2810},
  267. {0x00, 0x0005, 0x2811},
  268. {0x00, 0x0006, 0x2812},
  269. {0x00, 0x000a, 0x2813},
  270. {0x00, 0x0010, 0x2814},
  271. {0x00, 0x0017, 0x2815},
  272. {0x00, 0x001c, 0x2816},
  273. {0x00, 0x0016, 0x2817},
  274. {0x00, 0x0006, 0x2818},
  275. {0x00, 0x0007, 0x2819},
  276. {0x00, 0x0009, 0x281a},
  277. {0x00, 0x000c, 0x281b},
  278. {0x00, 0x0014, 0x281c},
  279. {0x00, 0x0023, 0x281d},
  280. {0x00, 0x0020, 0x281e},
  281. {0x00, 0x0019, 0x281f},
  282. {0x00, 0x0007, 0x2820},
  283. {0x00, 0x0009, 0x2821},
  284. {0x00, 0x000f, 0x2822},
  285. {0x00, 0x0016, 0x2823},
  286. {0x00, 0x001b, 0x2824},
  287. {0x00, 0x002c, 0x2825},
  288. {0x00, 0x0029, 0x2826},
  289. {0x00, 0x001f, 0x2827},
  290. {0x00, 0x000a, 0x2828},
  291. {0x00, 0x000e, 0x2829},
  292. {0x00, 0x0016, 0x282a},
  293. {0x00, 0x001a, 0x282b},
  294. {0x00, 0x0020, 0x282c},
  295. {0x00, 0x002a, 0x282d},
  296. {0x00, 0x002d, 0x282e},
  297. {0x00, 0x0025, 0x282f},
  298. {0x00, 0x0014, 0x2830},
  299. {0x00, 0x001a, 0x2831},
  300. {0x00, 0x001f, 0x2832},
  301. {0x00, 0x0023, 0x2833},
  302. {0x00, 0x0029, 0x2834},
  303. {0x00, 0x0030, 0x2835},
  304. {0x00, 0x0030, 0x2836},
  305. {0x00, 0x0028, 0x2837},
  306. {0x00, 0x001d, 0x2838},
  307. {0x00, 0x0025, 0x2839},
  308. {0x00, 0x0026, 0x283a},
  309. {0x00, 0x0027, 0x283b},
  310. {0x00, 0x002d, 0x283c},
  311. {0x00, 0x0028, 0x283d},
  312. {0x00, 0x0029, 0x283e},
  313. {0x00, 0x0028, 0x283f},
  314. {0x00, 0x0007, 0x2840},
  315. {0x00, 0x0007, 0x2841},
  316. {0x00, 0x000a, 0x2842},
  317. {0x00, 0x0013, 0x2843},
  318. {0x00, 0x0028, 0x2844},
  319. {0x00, 0x0028, 0x2845},
  320. {0x00, 0x0028, 0x2846},
  321. {0x00, 0x0028, 0x2847},
  322. {0x00, 0x0007, 0x2848},
  323. {0x00, 0x0008, 0x2849},
  324. {0x00, 0x000a, 0x284a},
  325. {0x00, 0x001a, 0x284b},
  326. {0x00, 0x0028, 0x284c},
  327. {0x00, 0x0028, 0x284d},
  328. {0x00, 0x0028, 0x284e},
  329. {0x00, 0x0028, 0x284f},
  330. {0x00, 0x000a, 0x2850},
  331. {0x00, 0x000a, 0x2851},
  332. {0x00, 0x0016, 0x2852},
  333. {0x00, 0x0028, 0x2853},
  334. {0x00, 0x0028, 0x2854},
  335. {0x00, 0x0028, 0x2855},
  336. {0x00, 0x0028, 0x2856},
  337. {0x00, 0x0028, 0x2857},
  338. {0x00, 0x0013, 0x2858},
  339. {0x00, 0x001a, 0x2859},
  340. {0x00, 0x0028, 0x285a},
  341. {0x00, 0x0028, 0x285b},
  342. {0x00, 0x0028, 0x285c},
  343. {0x00, 0x0028, 0x285d},
  344. {0x00, 0x0028, 0x285e},
  345. {0x00, 0x0028, 0x285f},
  346. {0x00, 0x0028, 0x2860},
  347. {0x00, 0x0028, 0x2861},
  348. {0x00, 0x0028, 0x2862},
  349. {0x00, 0x0028, 0x2863},
  350. {0x00, 0x0028, 0x2864},
  351. {0x00, 0x0028, 0x2865},
  352. {0x00, 0x0028, 0x2866},
  353. {0x00, 0x0028, 0x2867},
  354. {0x00, 0x0028, 0x2868},
  355. {0x00, 0x0028, 0x2869},
  356. {0x00, 0x0028, 0x286a},
  357. {0x00, 0x0028, 0x286b},
  358. {0x00, 0x0028, 0x286c},
  359. {0x00, 0x0028, 0x286d},
  360. {0x00, 0x0028, 0x286e},
  361. {0x00, 0x0028, 0x286f},
  362. {0x00, 0x0028, 0x2870},
  363. {0x00, 0x0028, 0x2871},
  364. {0x00, 0x0028, 0x2872},
  365. {0x00, 0x0028, 0x2873},
  366. {0x00, 0x0028, 0x2874},
  367. {0x00, 0x0028, 0x2875},
  368. {0x00, 0x0028, 0x2876},
  369. {0x00, 0x0028, 0x2877},
  370. {0x00, 0x0028, 0x2878},
  371. {0x00, 0x0028, 0x2879},
  372. {0x00, 0x0028, 0x287a},
  373. {0x00, 0x0028, 0x287b},
  374. {0x00, 0x0028, 0x287c},
  375. {0x00, 0x0028, 0x287d},
  376. {0x00, 0x0028, 0x287e},
  377. {0x00, 0x0028, 0x287f},
  378. {0xa0, 0x0000, 0x0503},
  379. };
  380. static const u8 qtable_creative_pccam[2][64] = {
  381. { /* Q-table Y-components */
  382. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  383. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  384. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  385. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  386. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  387. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  388. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  389. 0x16, 0x1c, 0x1d, 0x1d, 0x22, 0x1e, 0x1f, 0x1e},
  390. { /* Q-table C-components */
  391. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  392. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  393. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  394. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  395. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  396. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  397. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  398. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  399. };
  400. /* FIXME: This Q-table is identical to the Creative PC-CAM one,
  401. * except for one byte. Possibly a typo?
  402. * NWG: 18/05/2003.
  403. */
  404. static const u8 qtable_spca504_default[2][64] = {
  405. { /* Q-table Y-components */
  406. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  407. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  408. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  409. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  410. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  411. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  412. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  413. 0x16, 0x1c, 0x1d, 0x1d, 0x1d /* 0x22 */ , 0x1e, 0x1f, 0x1e,
  414. },
  415. { /* Q-table C-components */
  416. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  417. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  418. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  419. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  420. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  421. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  422. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  423. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  424. };
  425. /* read <len> bytes to gspca_dev->usb_buf */
  426. static void reg_r(struct gspca_dev *gspca_dev,
  427. u8 req,
  428. u16 index,
  429. u16 len)
  430. {
  431. int ret;
  432. #ifdef GSPCA_DEBUG
  433. if (len > USB_BUF_SZ) {
  434. err("reg_r: buffer overflow");
  435. return;
  436. }
  437. #endif
  438. if (gspca_dev->usb_err < 0)
  439. return;
  440. ret = usb_control_msg(gspca_dev->dev,
  441. usb_rcvctrlpipe(gspca_dev->dev, 0),
  442. req,
  443. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  444. 0, /* value */
  445. index,
  446. len ? gspca_dev->usb_buf : NULL, len,
  447. 500);
  448. if (ret < 0) {
  449. PDEBUG(D_ERR, "reg_r err %d", ret);
  450. gspca_dev->usb_err = ret;
  451. }
  452. }
  453. /* write one byte */
  454. static void reg_w_1(struct gspca_dev *gspca_dev,
  455. u8 req,
  456. u16 value,
  457. u16 index,
  458. u16 byte)
  459. {
  460. int ret;
  461. if (gspca_dev->usb_err < 0)
  462. return;
  463. gspca_dev->usb_buf[0] = byte;
  464. ret = usb_control_msg(gspca_dev->dev,
  465. usb_sndctrlpipe(gspca_dev->dev, 0),
  466. req,
  467. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  468. value, index,
  469. gspca_dev->usb_buf, 1,
  470. 500);
  471. if (ret < 0) {
  472. PDEBUG(D_ERR, "reg_w_1 err %d", ret);
  473. gspca_dev->usb_err = ret;
  474. }
  475. }
  476. /* write req / index / value */
  477. static void reg_w_riv(struct gspca_dev *gspca_dev,
  478. u8 req, u16 index, u16 value)
  479. {
  480. struct usb_device *dev = gspca_dev->dev;
  481. int ret;
  482. if (gspca_dev->usb_err < 0)
  483. return;
  484. ret = usb_control_msg(dev,
  485. usb_sndctrlpipe(dev, 0),
  486. req,
  487. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  488. value, index, NULL, 0, 500);
  489. if (ret < 0) {
  490. PDEBUG(D_ERR, "reg_w_riv err %d", ret);
  491. gspca_dev->usb_err = ret;
  492. return;
  493. }
  494. PDEBUG(D_USBO, "reg_w_riv: 0x%02x,0x%04x:0x%04x",
  495. req, index, value);
  496. }
  497. /* read 1 byte */
  498. static u8 reg_r_1(struct gspca_dev *gspca_dev,
  499. u16 value) /* wValue */
  500. {
  501. int ret;
  502. if (gspca_dev->usb_err < 0)
  503. return 0;
  504. ret = usb_control_msg(gspca_dev->dev,
  505. usb_rcvctrlpipe(gspca_dev->dev, 0),
  506. 0x20, /* request */
  507. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  508. value,
  509. 0, /* index */
  510. gspca_dev->usb_buf, 1,
  511. 500); /* timeout */
  512. if (ret < 0) {
  513. PDEBUG(D_ERR, "reg_r_1 err %d", ret);
  514. gspca_dev->usb_err = ret;
  515. return 0;
  516. }
  517. return gspca_dev->usb_buf[0];
  518. }
  519. /* read 1 or 2 bytes */
  520. static u16 reg_r_12(struct gspca_dev *gspca_dev,
  521. u8 req, /* bRequest */
  522. u16 index, /* wIndex */
  523. u16 length) /* wLength (1 or 2 only) */
  524. {
  525. int ret;
  526. if (gspca_dev->usb_err < 0)
  527. return 0;
  528. gspca_dev->usb_buf[1] = 0;
  529. ret = usb_control_msg(gspca_dev->dev,
  530. usb_rcvctrlpipe(gspca_dev->dev, 0),
  531. req,
  532. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  533. 0, /* value */
  534. index,
  535. gspca_dev->usb_buf, length,
  536. 500);
  537. if (ret < 0) {
  538. PDEBUG(D_ERR, "reg_r_12 err %d", ret);
  539. gspca_dev->usb_err = ret;
  540. return 0;
  541. }
  542. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  543. }
  544. static void write_vector(struct gspca_dev *gspca_dev,
  545. const struct cmd *data, int ncmds)
  546. {
  547. while (--ncmds >= 0) {
  548. reg_w_riv(gspca_dev, data->req, data->idx, data->val);
  549. data++;
  550. }
  551. }
  552. static void setup_qtable(struct gspca_dev *gspca_dev,
  553. const u8 qtable[2][64])
  554. {
  555. int i;
  556. /* loop over y components */
  557. for (i = 0; i < 64; i++)
  558. reg_w_riv(gspca_dev, 0x00, 0x2800 + i, qtable[0][i]);
  559. /* loop over c components */
  560. for (i = 0; i < 64; i++)
  561. reg_w_riv(gspca_dev, 0x00, 0x2840 + i, qtable[1][i]);
  562. }
  563. static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
  564. u8 req, u16 idx, u16 val)
  565. {
  566. u16 notdone;
  567. reg_w_riv(gspca_dev, req, idx, val);
  568. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  569. reg_w_riv(gspca_dev, req, idx, val);
  570. PDEBUG(D_FRAM, "before wait 0x%04x", notdone);
  571. msleep(200);
  572. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  573. PDEBUG(D_FRAM, "after wait 0x%04x", notdone);
  574. }
  575. static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
  576. u8 req,
  577. u16 idx, u16 val, u16 endcode, u8 count)
  578. {
  579. u16 status;
  580. reg_w_riv(gspca_dev, req, idx, val);
  581. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  582. if (gspca_dev->usb_err < 0)
  583. return;
  584. PDEBUG(D_FRAM, "Status 0x%04x Need 0x%04x", status, endcode);
  585. if (!count)
  586. return;
  587. count = 200;
  588. while (--count > 0) {
  589. msleep(10);
  590. /* gsmart mini2 write a each wait setting 1 ms is enough */
  591. /* reg_w_riv(gspca_dev, req, idx, val); */
  592. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  593. if (status == endcode) {
  594. PDEBUG(D_FRAM, "status 0x%04x after wait %d",
  595. status, 200 - count);
  596. break;
  597. }
  598. }
  599. }
  600. static void spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
  601. {
  602. int count = 10;
  603. while (--count > 0) {
  604. reg_r(gspca_dev, 0x21, 0, 1);
  605. if ((gspca_dev->usb_buf[0] & 0x01) == 0)
  606. break;
  607. msleep(10);
  608. }
  609. }
  610. static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
  611. {
  612. int count = 50;
  613. while (--count > 0) {
  614. reg_r(gspca_dev, 0x21, 1, 1);
  615. if (gspca_dev->usb_buf[0] != 0) {
  616. reg_w_1(gspca_dev, 0x21, 0, 1, 0);
  617. reg_r(gspca_dev, 0x21, 1, 1);
  618. spca504B_PollingDataReady(gspca_dev);
  619. break;
  620. }
  621. msleep(10);
  622. }
  623. }
  624. static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
  625. {
  626. u8 *data;
  627. data = gspca_dev->usb_buf;
  628. reg_r(gspca_dev, 0x20, 0, 5);
  629. PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ",
  630. data[0], data[1], data[2], data[3], data[4]);
  631. reg_r(gspca_dev, 0x23, 0, 64);
  632. reg_r(gspca_dev, 0x23, 1, 64);
  633. }
  634. static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
  635. {
  636. struct sd *sd = (struct sd *) gspca_dev;
  637. u8 Size;
  638. Size = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  639. switch (sd->bridge) {
  640. case BRIDGE_SPCA533:
  641. reg_w_riv(gspca_dev, 0x31, 0, 0);
  642. spca504B_WaitCmdStatus(gspca_dev);
  643. spca504B_PollingDataReady(gspca_dev);
  644. spca50x_GetFirmware(gspca_dev);
  645. reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */
  646. reg_r(gspca_dev, 0x24, 8, 1);
  647. reg_w_1(gspca_dev, 0x25, 0, 4, Size);
  648. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  649. spca504B_PollingDataReady(gspca_dev);
  650. /* Init the cam width height with some values get on init ? */
  651. reg_w_riv(gspca_dev, 0x31, 0, 0x04);
  652. spca504B_WaitCmdStatus(gspca_dev);
  653. spca504B_PollingDataReady(gspca_dev);
  654. break;
  655. default:
  656. /* case BRIDGE_SPCA504B: */
  657. /* case BRIDGE_SPCA536: */
  658. reg_w_1(gspca_dev, 0x25, 0, 4, Size);
  659. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  660. reg_w_1(gspca_dev, 0x27, 0, 0, 6);
  661. reg_r(gspca_dev, 0x27, 0, 1); /* type */
  662. spca504B_PollingDataReady(gspca_dev);
  663. break;
  664. case BRIDGE_SPCA504:
  665. Size += 3;
  666. if (sd->subtype == AiptekMiniPenCam13) {
  667. /* spca504a aiptek */
  668. spca504A_acknowledged_command(gspca_dev,
  669. 0x08, Size, 0,
  670. 0x80 | (Size & 0x0f), 1);
  671. spca504A_acknowledged_command(gspca_dev,
  672. 1, 3, 0, 0x9f, 0);
  673. } else {
  674. spca504_acknowledged_command(gspca_dev, 0x08, Size, 0);
  675. }
  676. break;
  677. case BRIDGE_SPCA504C:
  678. /* capture mode */
  679. reg_w_riv(gspca_dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x00);
  680. reg_w_riv(gspca_dev, 0x20, 0x01, 0x0500 | (Size & 0x0f));
  681. break;
  682. }
  683. }
  684. static void spca504_wait_status(struct gspca_dev *gspca_dev)
  685. {
  686. int cnt;
  687. cnt = 256;
  688. while (--cnt > 0) {
  689. /* With this we get the status, when return 0 it's all ok */
  690. if (reg_r_12(gspca_dev, 0x06, 0x00, 1) == 0)
  691. return;
  692. msleep(10);
  693. }
  694. }
  695. static void spca504B_setQtable(struct gspca_dev *gspca_dev)
  696. {
  697. reg_w_1(gspca_dev, 0x26, 0, 0, 3);
  698. reg_r(gspca_dev, 0x26, 0, 1);
  699. spca504B_PollingDataReady(gspca_dev);
  700. }
  701. static void setbrightness(struct gspca_dev *gspca_dev)
  702. {
  703. struct sd *sd = (struct sd *) gspca_dev;
  704. u16 reg;
  705. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
  706. reg_w_riv(gspca_dev, 0x00, reg, sd->brightness);
  707. }
  708. static void setcontrast(struct gspca_dev *gspca_dev)
  709. {
  710. struct sd *sd = (struct sd *) gspca_dev;
  711. u16 reg;
  712. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
  713. reg_w_riv(gspca_dev, 0x00, reg, sd->contrast);
  714. }
  715. static void setcolors(struct gspca_dev *gspca_dev)
  716. {
  717. struct sd *sd = (struct sd *) gspca_dev;
  718. u16 reg;
  719. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
  720. reg_w_riv(gspca_dev, 0x00, reg, sd->colors);
  721. }
  722. static void init_ctl_reg(struct gspca_dev *gspca_dev)
  723. {
  724. struct sd *sd = (struct sd *) gspca_dev;
  725. int pollreg = 1;
  726. setbrightness(gspca_dev);
  727. setcontrast(gspca_dev);
  728. setcolors(gspca_dev);
  729. switch (sd->bridge) {
  730. case BRIDGE_SPCA504:
  731. case BRIDGE_SPCA504C:
  732. pollreg = 0;
  733. /* fall thru */
  734. default:
  735. /* case BRIDGE_SPCA533: */
  736. /* case BRIDGE_SPCA504B: */
  737. reg_w_riv(gspca_dev, 0, 0x00, 0x21ad); /* hue */
  738. reg_w_riv(gspca_dev, 0, 0x01, 0x21ac); /* sat/hue */
  739. reg_w_riv(gspca_dev, 0, 0x00, 0x21a3); /* gamma */
  740. break;
  741. case BRIDGE_SPCA536:
  742. reg_w_riv(gspca_dev, 0, 0x40, 0x20f5);
  743. reg_w_riv(gspca_dev, 0, 0x01, 0x20f4);
  744. reg_w_riv(gspca_dev, 0, 0x00, 0x2089);
  745. break;
  746. }
  747. if (pollreg)
  748. spca504B_PollingDataReady(gspca_dev);
  749. }
  750. /* this function is called at probe time */
  751. static int sd_config(struct gspca_dev *gspca_dev,
  752. const struct usb_device_id *id)
  753. {
  754. struct sd *sd = (struct sd *) gspca_dev;
  755. struct cam *cam;
  756. cam = &gspca_dev->cam;
  757. sd->bridge = id->driver_info >> 8;
  758. sd->subtype = id->driver_info;
  759. if (sd->subtype == AiptekMiniPenCam13) {
  760. /* try to get the firmware as some cam answer 2.0.1.2.2
  761. * and should be a spca504b then overwrite that setting */
  762. reg_r(gspca_dev, 0x20, 0, 1);
  763. switch (gspca_dev->usb_buf[0]) {
  764. case 1:
  765. break; /* (right bridge/subtype) */
  766. case 2:
  767. sd->bridge = BRIDGE_SPCA504B;
  768. sd->subtype = 0;
  769. break;
  770. default:
  771. return -ENODEV;
  772. }
  773. }
  774. switch (sd->bridge) {
  775. default:
  776. /* case BRIDGE_SPCA504B: */
  777. /* case BRIDGE_SPCA504: */
  778. /* case BRIDGE_SPCA536: */
  779. cam->cam_mode = vga_mode;
  780. cam->nmodes =ARRAY_SIZE(vga_mode);
  781. break;
  782. case BRIDGE_SPCA533:
  783. cam->cam_mode = custom_mode;
  784. if (sd->subtype == MegaImageVI) /* 320x240 only */
  785. cam->nmodes = ARRAY_SIZE(custom_mode) - 1;
  786. else
  787. cam->nmodes = ARRAY_SIZE(custom_mode);
  788. break;
  789. case BRIDGE_SPCA504C:
  790. cam->cam_mode = vga_mode2;
  791. cam->nmodes = ARRAY_SIZE(vga_mode2);
  792. break;
  793. }
  794. sd->brightness = BRIGHTNESS_DEF;
  795. sd->contrast = CONTRAST_DEF;
  796. sd->colors = COLOR_DEF;
  797. sd->autogain = AUTOGAIN_DEF;
  798. sd->quality = QUALITY_DEF;
  799. return 0;
  800. }
  801. /* this function is called at probe and resume time */
  802. static int sd_init(struct gspca_dev *gspca_dev)
  803. {
  804. struct sd *sd = (struct sd *) gspca_dev;
  805. int i;
  806. u8 info[6];
  807. switch (sd->bridge) {
  808. case BRIDGE_SPCA504B:
  809. reg_w_riv(gspca_dev, 0x1d, 0x00, 0);
  810. reg_w_riv(gspca_dev, 0, 0x01, 0x2306);
  811. reg_w_riv(gspca_dev, 0, 0x00, 0x0d04);
  812. reg_w_riv(gspca_dev, 0, 0x00, 0x2000);
  813. reg_w_riv(gspca_dev, 0, 0x13, 0x2301);
  814. reg_w_riv(gspca_dev, 0, 0x00, 0x2306);
  815. /* fall thru */
  816. case BRIDGE_SPCA533:
  817. spca504B_PollingDataReady(gspca_dev);
  818. spca50x_GetFirmware(gspca_dev);
  819. break;
  820. case BRIDGE_SPCA536:
  821. spca50x_GetFirmware(gspca_dev);
  822. reg_r(gspca_dev, 0x00, 0x5002, 1);
  823. reg_w_1(gspca_dev, 0x24, 0, 0, 0);
  824. reg_r(gspca_dev, 0x24, 0, 1);
  825. spca504B_PollingDataReady(gspca_dev);
  826. reg_w_riv(gspca_dev, 0x34, 0, 0);
  827. spca504B_WaitCmdStatus(gspca_dev);
  828. break;
  829. case BRIDGE_SPCA504C: /* pccam600 */
  830. PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)");
  831. reg_w_riv(gspca_dev, 0xe0, 0x0000, 0x0000);
  832. reg_w_riv(gspca_dev, 0xe0, 0x0000, 0x0001); /* reset */
  833. spca504_wait_status(gspca_dev);
  834. if (sd->subtype == LogitechClickSmart420)
  835. write_vector(gspca_dev,
  836. spca504A_clicksmart420_open_data,
  837. ARRAY_SIZE(spca504A_clicksmart420_open_data));
  838. else
  839. write_vector(gspca_dev, spca504_pccam600_open_data,
  840. ARRAY_SIZE(spca504_pccam600_open_data));
  841. setup_qtable(gspca_dev, qtable_creative_pccam);
  842. break;
  843. default:
  844. /* case BRIDGE_SPCA504: */
  845. PDEBUG(D_STREAM, "Opening SPCA504");
  846. if (sd->subtype == AiptekMiniPenCam13) {
  847. /*****************************/
  848. for (i = 0; i < 6; i++)
  849. info[i] = reg_r_1(gspca_dev, i);
  850. PDEBUG(D_STREAM,
  851. "Read info: %d %d %d %d %d %d."
  852. " Should be 1,0,2,2,0,0",
  853. info[0], info[1], info[2],
  854. info[3], info[4], info[5]);
  855. /* spca504a aiptek */
  856. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  857. spca504A_acknowledged_command(gspca_dev, 0x24,
  858. 8, 3, 0x9e, 1);
  859. /* Twice sequencial need status 0xff->0x9e->0x9d */
  860. spca504A_acknowledged_command(gspca_dev, 0x24,
  861. 8, 3, 0x9e, 0);
  862. spca504A_acknowledged_command(gspca_dev, 0x24,
  863. 0, 0, 0x9d, 1);
  864. /******************************/
  865. /* spca504a aiptek */
  866. spca504A_acknowledged_command(gspca_dev, 0x08,
  867. 6, 0, 0x86, 1);
  868. /* reg_write (dev, 0, 0x2000, 0); */
  869. /* reg_write (dev, 0, 0x2883, 1); */
  870. /* spca504A_acknowledged_command (gspca_dev, 0x08,
  871. 6, 0, 0x86, 1); */
  872. /* spca504A_acknowledged_command (gspca_dev, 0x24,
  873. 0, 0, 0x9D, 1); */
  874. reg_w_riv(gspca_dev, 0x00, 0x270c, 0x05);
  875. /* L92 sno1t.txt */
  876. reg_w_riv(gspca_dev, 0x00, 0x2310, 0x05);
  877. spca504A_acknowledged_command(gspca_dev, 0x01,
  878. 0x0f, 0, 0xff, 0);
  879. }
  880. /* setup qtable */
  881. reg_w_riv(gspca_dev, 0, 0x2000, 0);
  882. reg_w_riv(gspca_dev, 0, 0x2883, 1);
  883. setup_qtable(gspca_dev, qtable_spca504_default);
  884. break;
  885. }
  886. return gspca_dev->usb_err;
  887. }
  888. static int sd_start(struct gspca_dev *gspca_dev)
  889. {
  890. struct sd *sd = (struct sd *) gspca_dev;
  891. int enable;
  892. int i;
  893. u8 info[6];
  894. /* create the JPEG header */
  895. sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
  896. if (!sd->jpeg_hdr)
  897. return -ENOMEM;
  898. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  899. 0x22); /* JPEG 411 */
  900. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  901. if (sd->bridge == BRIDGE_SPCA504B)
  902. spca504B_setQtable(gspca_dev);
  903. spca504B_SetSizeType(gspca_dev);
  904. switch (sd->bridge) {
  905. default:
  906. /* case BRIDGE_SPCA504B: */
  907. /* case BRIDGE_SPCA533: */
  908. /* case BRIDGE_SPCA536: */
  909. switch (sd->subtype) {
  910. case MegapixV4:
  911. case LogitechClickSmart820:
  912. case MegaImageVI:
  913. reg_w_riv(gspca_dev, 0xf0, 0, 0);
  914. spca504B_WaitCmdStatus(gspca_dev);
  915. reg_r(gspca_dev, 0xf0, 4, 0);
  916. spca504B_WaitCmdStatus(gspca_dev);
  917. break;
  918. default:
  919. reg_w_riv(gspca_dev, 0x31, 0, 0x04);
  920. spca504B_WaitCmdStatus(gspca_dev);
  921. spca504B_PollingDataReady(gspca_dev);
  922. break;
  923. }
  924. break;
  925. case BRIDGE_SPCA504:
  926. if (sd->subtype == AiptekMiniPenCam13) {
  927. for (i = 0; i < 6; i++)
  928. info[i] = reg_r_1(gspca_dev, i);
  929. PDEBUG(D_STREAM,
  930. "Read info: %d %d %d %d %d %d."
  931. " Should be 1,0,2,2,0,0",
  932. info[0], info[1], info[2],
  933. info[3], info[4], info[5]);
  934. /* spca504a aiptek */
  935. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  936. spca504A_acknowledged_command(gspca_dev, 0x24,
  937. 8, 3, 0x9e, 1);
  938. /* Twice sequencial need status 0xff->0x9e->0x9d */
  939. spca504A_acknowledged_command(gspca_dev, 0x24,
  940. 8, 3, 0x9e, 0);
  941. spca504A_acknowledged_command(gspca_dev, 0x24,
  942. 0, 0, 0x9d, 1);
  943. } else {
  944. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  945. for (i = 0; i < 6; i++)
  946. info[i] = reg_r_1(gspca_dev, i);
  947. PDEBUG(D_STREAM,
  948. "Read info: %d %d %d %d %d %d."
  949. " Should be 1,0,2,2,0,0",
  950. info[0], info[1], info[2],
  951. info[3], info[4], info[5]);
  952. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  953. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  954. }
  955. spca504B_SetSizeType(gspca_dev);
  956. reg_w_riv(gspca_dev, 0x00, 0x270c, 0x05);
  957. /* L92 sno1t.txt */
  958. reg_w_riv(gspca_dev, 0x00, 0x2310, 0x05);
  959. break;
  960. case BRIDGE_SPCA504C:
  961. if (sd->subtype == LogitechClickSmart420) {
  962. write_vector(gspca_dev,
  963. spca504A_clicksmart420_init_data,
  964. ARRAY_SIZE(spca504A_clicksmart420_init_data));
  965. } else {
  966. write_vector(gspca_dev, spca504_pccam600_init_data,
  967. ARRAY_SIZE(spca504_pccam600_init_data));
  968. }
  969. enable = (sd->autogain ? 0x04 : 0x01);
  970. reg_w_riv(gspca_dev, 0x0c, 0x0000, enable);
  971. /* auto exposure */
  972. reg_w_riv(gspca_dev, 0xb0, 0x0000, enable);
  973. /* auto whiteness */
  974. /* set default exposure compensation and whiteness balance */
  975. reg_w_riv(gspca_dev, 0x30, 0x0001, 800); /* ~ 20 fps */
  976. reg_w_riv(gspca_dev, 0x30, 0x0002, 1600);
  977. spca504B_SetSizeType(gspca_dev);
  978. break;
  979. }
  980. init_ctl_reg(gspca_dev);
  981. return gspca_dev->usb_err;
  982. }
  983. static void sd_stopN(struct gspca_dev *gspca_dev)
  984. {
  985. struct sd *sd = (struct sd *) gspca_dev;
  986. switch (sd->bridge) {
  987. default:
  988. /* case BRIDGE_SPCA533: */
  989. /* case BRIDGE_SPCA536: */
  990. /* case BRIDGE_SPCA504B: */
  991. reg_w_riv(gspca_dev, 0x31, 0, 0);
  992. spca504B_WaitCmdStatus(gspca_dev);
  993. spca504B_PollingDataReady(gspca_dev);
  994. break;
  995. case BRIDGE_SPCA504:
  996. case BRIDGE_SPCA504C:
  997. reg_w_riv(gspca_dev, 0x00, 0x2000, 0x0000);
  998. if (sd->subtype == AiptekMiniPenCam13) {
  999. /* spca504a aiptek */
  1000. /* spca504A_acknowledged_command(gspca_dev, 0x08,
  1001. 6, 0, 0x86, 1); */
  1002. spca504A_acknowledged_command(gspca_dev, 0x24,
  1003. 0x00, 0x00, 0x9d, 1);
  1004. spca504A_acknowledged_command(gspca_dev, 0x01,
  1005. 0x0f, 0x00, 0xff, 1);
  1006. } else {
  1007. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  1008. reg_w_riv(gspca_dev, 0x01, 0x000f, 0x0000);
  1009. }
  1010. break;
  1011. }
  1012. }
  1013. static void sd_stop0(struct gspca_dev *gspca_dev)
  1014. {
  1015. struct sd *sd = (struct sd *) gspca_dev;
  1016. kfree(sd->jpeg_hdr);
  1017. }
  1018. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1019. u8 *data, /* isoc packet */
  1020. int len) /* iso packet length */
  1021. {
  1022. struct sd *sd = (struct sd *) gspca_dev;
  1023. int i, sof = 0;
  1024. static u8 ffd9[] = {0xff, 0xd9};
  1025. /* frames are jpeg 4.1.1 without 0xff escape */
  1026. switch (sd->bridge) {
  1027. case BRIDGE_SPCA533:
  1028. if (data[0] == 0xff) {
  1029. if (data[1] != 0x01) { /* drop packet */
  1030. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1031. return;
  1032. }
  1033. sof = 1;
  1034. data += SPCA533_OFFSET_DATA;
  1035. len -= SPCA533_OFFSET_DATA;
  1036. } else {
  1037. data += 1;
  1038. len -= 1;
  1039. }
  1040. break;
  1041. case BRIDGE_SPCA536:
  1042. if (data[0] == 0xff) {
  1043. sof = 1;
  1044. data += SPCA536_OFFSET_DATA;
  1045. len -= SPCA536_OFFSET_DATA;
  1046. } else {
  1047. data += 2;
  1048. len -= 2;
  1049. }
  1050. break;
  1051. default:
  1052. /* case BRIDGE_SPCA504: */
  1053. /* case BRIDGE_SPCA504B: */
  1054. switch (data[0]) {
  1055. case 0xfe: /* start of frame */
  1056. sof = 1;
  1057. data += SPCA50X_OFFSET_DATA;
  1058. len -= SPCA50X_OFFSET_DATA;
  1059. break;
  1060. case 0xff: /* drop packet */
  1061. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1062. return;
  1063. default:
  1064. data += 1;
  1065. len -= 1;
  1066. break;
  1067. }
  1068. break;
  1069. case BRIDGE_SPCA504C:
  1070. switch (data[0]) {
  1071. case 0xfe: /* start of frame */
  1072. sof = 1;
  1073. data += SPCA504_PCCAM600_OFFSET_DATA;
  1074. len -= SPCA504_PCCAM600_OFFSET_DATA;
  1075. break;
  1076. case 0xff: /* drop packet */
  1077. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1078. return;
  1079. default:
  1080. data += 1;
  1081. len -= 1;
  1082. break;
  1083. }
  1084. break;
  1085. }
  1086. if (sof) { /* start of frame */
  1087. gspca_frame_add(gspca_dev, LAST_PACKET,
  1088. ffd9, 2);
  1089. /* put the JPEG header in the new frame */
  1090. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1091. sd->jpeg_hdr, JPEG_HDR_SZ);
  1092. }
  1093. /* add 0x00 after 0xff */
  1094. i = 0;
  1095. do {
  1096. if (data[i] == 0xff) {
  1097. gspca_frame_add(gspca_dev, INTER_PACKET,
  1098. data, i + 1);
  1099. len -= i;
  1100. data += i;
  1101. *data = 0x00;
  1102. i = 0;
  1103. }
  1104. i++;
  1105. } while (i < len);
  1106. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  1107. }
  1108. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1109. {
  1110. struct sd *sd = (struct sd *) gspca_dev;
  1111. sd->brightness = val;
  1112. if (gspca_dev->streaming)
  1113. setbrightness(gspca_dev);
  1114. return gspca_dev->usb_err;
  1115. }
  1116. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1117. {
  1118. struct sd *sd = (struct sd *) gspca_dev;
  1119. *val = sd->brightness;
  1120. return 0;
  1121. }
  1122. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1123. {
  1124. struct sd *sd = (struct sd *) gspca_dev;
  1125. sd->contrast = val;
  1126. if (gspca_dev->streaming)
  1127. setcontrast(gspca_dev);
  1128. return gspca_dev->usb_err;
  1129. }
  1130. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1131. {
  1132. struct sd *sd = (struct sd *) gspca_dev;
  1133. *val = sd->contrast;
  1134. return 0;
  1135. }
  1136. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1137. {
  1138. struct sd *sd = (struct sd *) gspca_dev;
  1139. sd->colors = val;
  1140. if (gspca_dev->streaming)
  1141. setcolors(gspca_dev);
  1142. return gspca_dev->usb_err;
  1143. }
  1144. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1145. {
  1146. struct sd *sd = (struct sd *) gspca_dev;
  1147. *val = sd->colors;
  1148. return 0;
  1149. }
  1150. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1151. {
  1152. struct sd *sd = (struct sd *) gspca_dev;
  1153. sd->autogain = val;
  1154. return 0;
  1155. }
  1156. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1157. {
  1158. struct sd *sd = (struct sd *) gspca_dev;
  1159. *val = sd->autogain;
  1160. return 0;
  1161. }
  1162. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  1163. struct v4l2_jpegcompression *jcomp)
  1164. {
  1165. struct sd *sd = (struct sd *) gspca_dev;
  1166. if (jcomp->quality < QUALITY_MIN)
  1167. sd->quality = QUALITY_MIN;
  1168. else if (jcomp->quality > QUALITY_MAX)
  1169. sd->quality = QUALITY_MAX;
  1170. else
  1171. sd->quality = jcomp->quality;
  1172. if (gspca_dev->streaming)
  1173. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  1174. return gspca_dev->usb_err;
  1175. }
  1176. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  1177. struct v4l2_jpegcompression *jcomp)
  1178. {
  1179. struct sd *sd = (struct sd *) gspca_dev;
  1180. memset(jcomp, 0, sizeof *jcomp);
  1181. jcomp->quality = sd->quality;
  1182. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  1183. | V4L2_JPEG_MARKER_DQT;
  1184. return 0;
  1185. }
  1186. /* sub-driver description */
  1187. static const struct sd_desc sd_desc = {
  1188. .name = MODULE_NAME,
  1189. .ctrls = sd_ctrls,
  1190. .nctrls = ARRAY_SIZE(sd_ctrls),
  1191. .config = sd_config,
  1192. .init = sd_init,
  1193. .start = sd_start,
  1194. .stopN = sd_stopN,
  1195. .stop0 = sd_stop0,
  1196. .pkt_scan = sd_pkt_scan,
  1197. .get_jcomp = sd_get_jcomp,
  1198. .set_jcomp = sd_set_jcomp,
  1199. };
  1200. /* -- module initialisation -- */
  1201. #define BS(bridge, subtype) \
  1202. .driver_info = (BRIDGE_ ## bridge << 8) \
  1203. | (subtype)
  1204. static const __devinitdata struct usb_device_id device_table[] = {
  1205. {USB_DEVICE(0x041e, 0x400b), BS(SPCA504C, 0)},
  1206. {USB_DEVICE(0x041e, 0x4012), BS(SPCA504C, 0)},
  1207. {USB_DEVICE(0x041e, 0x4013), BS(SPCA504C, 0)},
  1208. {USB_DEVICE(0x0458, 0x7006), BS(SPCA504B, 0)},
  1209. {USB_DEVICE(0x0461, 0x0821), BS(SPCA533, 0)},
  1210. {USB_DEVICE(0x046d, 0x0905), BS(SPCA533, LogitechClickSmart820)},
  1211. {USB_DEVICE(0x046d, 0x0960), BS(SPCA504C, LogitechClickSmart420)},
  1212. {USB_DEVICE(0x0471, 0x0322), BS(SPCA504B, 0)},
  1213. {USB_DEVICE(0x04a5, 0x3003), BS(SPCA504B, 0)},
  1214. {USB_DEVICE(0x04a5, 0x3008), BS(SPCA533, 0)},
  1215. {USB_DEVICE(0x04a5, 0x300a), BS(SPCA533, 0)},
  1216. {USB_DEVICE(0x04f1, 0x1001), BS(SPCA504B, 0)},
  1217. {USB_DEVICE(0x04fc, 0x500c), BS(SPCA504B, 0)},
  1218. {USB_DEVICE(0x04fc, 0x504a), BS(SPCA504, AiptekMiniPenCam13)},
  1219. {USB_DEVICE(0x04fc, 0x504b), BS(SPCA504B, 0)},
  1220. {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)},
  1221. {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
  1222. {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
  1223. {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
  1224. {USB_DEVICE(0x052b, 0x1803), BS(SPCA533, MegaImageVI)},
  1225. {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
  1226. {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)},
  1227. {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)},
  1228. {USB_DEVICE(0x055f, 0xc211), BS(SPCA536, 0)},
  1229. {USB_DEVICE(0x055f, 0xc230), BS(SPCA533, 0)},
  1230. {USB_DEVICE(0x055f, 0xc232), BS(SPCA533, 0)},
  1231. {USB_DEVICE(0x055f, 0xc360), BS(SPCA536, 0)},
  1232. {USB_DEVICE(0x055f, 0xc420), BS(SPCA504, 0)},
  1233. {USB_DEVICE(0x055f, 0xc430), BS(SPCA533, 0)},
  1234. {USB_DEVICE(0x055f, 0xc440), BS(SPCA533, 0)},
  1235. {USB_DEVICE(0x055f, 0xc520), BS(SPCA504, 0)},
  1236. {USB_DEVICE(0x055f, 0xc530), BS(SPCA533, 0)},
  1237. {USB_DEVICE(0x055f, 0xc540), BS(SPCA533, 0)},
  1238. {USB_DEVICE(0x055f, 0xc630), BS(SPCA533, 0)},
  1239. {USB_DEVICE(0x055f, 0xc650), BS(SPCA533, 0)},
  1240. {USB_DEVICE(0x05da, 0x1018), BS(SPCA504B, 0)},
  1241. {USB_DEVICE(0x06d6, 0x0031), BS(SPCA533, 0)},
  1242. {USB_DEVICE(0x0733, 0x1311), BS(SPCA533, 0)},
  1243. {USB_DEVICE(0x0733, 0x1314), BS(SPCA533, 0)},
  1244. {USB_DEVICE(0x0733, 0x2211), BS(SPCA533, 0)},
  1245. {USB_DEVICE(0x0733, 0x2221), BS(SPCA533, 0)},
  1246. {USB_DEVICE(0x0733, 0x3261), BS(SPCA536, 0)},
  1247. {USB_DEVICE(0x0733, 0x3281), BS(SPCA536, 0)},
  1248. {USB_DEVICE(0x08ca, 0x0104), BS(SPCA533, 0)},
  1249. {USB_DEVICE(0x08ca, 0x0106), BS(SPCA533, 0)},
  1250. {USB_DEVICE(0x08ca, 0x2008), BS(SPCA504B, 0)},
  1251. {USB_DEVICE(0x08ca, 0x2010), BS(SPCA533, 0)},
  1252. {USB_DEVICE(0x08ca, 0x2016), BS(SPCA504B, 0)},
  1253. {USB_DEVICE(0x08ca, 0x2018), BS(SPCA504B, 0)},
  1254. {USB_DEVICE(0x08ca, 0x2020), BS(SPCA533, 0)},
  1255. {USB_DEVICE(0x08ca, 0x2022), BS(SPCA533, 0)},
  1256. {USB_DEVICE(0x08ca, 0x2024), BS(SPCA536, 0)},
  1257. {USB_DEVICE(0x08ca, 0x2028), BS(SPCA533, 0)},
  1258. {USB_DEVICE(0x08ca, 0x2040), BS(SPCA536, 0)},
  1259. {USB_DEVICE(0x08ca, 0x2042), BS(SPCA536, 0)},
  1260. {USB_DEVICE(0x08ca, 0x2050), BS(SPCA536, 0)},
  1261. {USB_DEVICE(0x08ca, 0x2060), BS(SPCA536, 0)},
  1262. {USB_DEVICE(0x0d64, 0x0303), BS(SPCA536, 0)},
  1263. {}
  1264. };
  1265. MODULE_DEVICE_TABLE(usb, device_table);
  1266. /* -- device connect -- */
  1267. static int sd_probe(struct usb_interface *intf,
  1268. const struct usb_device_id *id)
  1269. {
  1270. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1271. THIS_MODULE);
  1272. }
  1273. static struct usb_driver sd_driver = {
  1274. .name = MODULE_NAME,
  1275. .id_table = device_table,
  1276. .probe = sd_probe,
  1277. .disconnect = gspca_disconnect,
  1278. #ifdef CONFIG_PM
  1279. .suspend = gspca_suspend,
  1280. .resume = gspca_resume,
  1281. #endif
  1282. };
  1283. /* -- module insert / remove -- */
  1284. static int __init sd_mod_init(void)
  1285. {
  1286. int ret;
  1287. ret = usb_register(&sd_driver);
  1288. if (ret < 0)
  1289. return ret;
  1290. PDEBUG(D_PROBE, "registered");
  1291. return 0;
  1292. }
  1293. static void __exit sd_mod_exit(void)
  1294. {
  1295. usb_deregister(&sd_driver);
  1296. PDEBUG(D_PROBE, "deregistered");
  1297. }
  1298. module_init(sd_mod_init);
  1299. module_exit(sd_mod_exit);