sunplus.c 38 KB

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