sunplus.c 39 KB

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