sunplus.c 37 KB

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