sunplus.c 38 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. /* read <len> bytes to gspca_dev->usb_buf */
  422. static void reg_r(struct gspca_dev *gspca_dev,
  423. __u16 req,
  424. __u16 index,
  425. __u16 len)
  426. {
  427. #ifdef GSPCA_DEBUG
  428. if (len > USB_BUF_SZ) {
  429. err("reg_r: buffer overflow");
  430. return;
  431. }
  432. #endif
  433. usb_control_msg(gspca_dev->dev,
  434. usb_rcvctrlpipe(gspca_dev->dev, 0),
  435. req,
  436. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  437. 0, /* value */
  438. index,
  439. len ? gspca_dev->usb_buf : NULL, len,
  440. 500);
  441. }
  442. /* write <len> bytes from gspca_dev->usb_buf */
  443. static void reg_w(struct gspca_dev *gspca_dev,
  444. __u16 req,
  445. __u16 value,
  446. __u16 index,
  447. __u16 len)
  448. {
  449. #ifdef GSPCA_DEBUG
  450. if (len > USB_BUF_SZ) {
  451. err("reg_w: buffer overflow");
  452. return;
  453. }
  454. #endif
  455. usb_control_msg(gspca_dev->dev,
  456. usb_sndctrlpipe(gspca_dev->dev, 0),
  457. req,
  458. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  459. value, index,
  460. len ? gspca_dev->usb_buf : NULL, len,
  461. 500);
  462. }
  463. /* write req / index / value */
  464. static int reg_w_riv(struct usb_device *dev,
  465. __u16 req, __u16 index, __u16 value)
  466. {
  467. int ret;
  468. ret = usb_control_msg(dev,
  469. usb_sndctrlpipe(dev, 0),
  470. req,
  471. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  472. value, index, NULL, 0, 500);
  473. PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d",
  474. req, index, value, ret);
  475. if (ret < 0)
  476. PDEBUG(D_ERR, "reg write: error %d", ret);
  477. return ret;
  478. }
  479. /* read 1 byte */
  480. static int reg_r_1(struct gspca_dev *gspca_dev,
  481. __u16 value) /* wValue */
  482. {
  483. int ret;
  484. ret = usb_control_msg(gspca_dev->dev,
  485. usb_rcvctrlpipe(gspca_dev->dev, 0),
  486. 0x20, /* request */
  487. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  488. value,
  489. 0, /* index */
  490. gspca_dev->usb_buf, 1,
  491. 500); /* timeout */
  492. if (ret < 0) {
  493. PDEBUG(D_ERR, "reg_r_1 err %d", ret);
  494. return 0;
  495. }
  496. return gspca_dev->usb_buf[0];
  497. }
  498. /* read 1 or 2 bytes - returns < 0 if error */
  499. static int reg_r_12(struct gspca_dev *gspca_dev,
  500. __u16 req, /* bRequest */
  501. __u16 index, /* wIndex */
  502. __u16 length) /* wLength (1 or 2 only) */
  503. {
  504. int ret;
  505. gspca_dev->usb_buf[1] = 0;
  506. ret = usb_control_msg(gspca_dev->dev,
  507. usb_rcvctrlpipe(gspca_dev->dev, 0),
  508. req,
  509. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  510. 0, /* value */
  511. index,
  512. gspca_dev->usb_buf, length,
  513. 500);
  514. if (ret < 0) {
  515. PDEBUG(D_ERR, "reg_read err %d", ret);
  516. return -1;
  517. }
  518. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  519. }
  520. static int write_vector(struct gspca_dev *gspca_dev,
  521. const __u16 data[][3])
  522. {
  523. struct usb_device *dev = gspca_dev->dev;
  524. int ret, i = 0;
  525. while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
  526. ret = reg_w_riv(dev, data[i][0], data[i][2], data[i][1]);
  527. if (ret < 0) {
  528. PDEBUG(D_ERR,
  529. "Register write failed for 0x%x,0x%x,0x%x",
  530. data[i][0], data[i][1], data[i][2]);
  531. return ret;
  532. }
  533. i++;
  534. }
  535. return 0;
  536. }
  537. static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
  538. unsigned int request,
  539. unsigned int ybase,
  540. unsigned int cbase,
  541. const __u8 qtable[2][64])
  542. {
  543. struct usb_device *dev = gspca_dev->dev;
  544. int i, err;
  545. /* loop over y components */
  546. for (i = 0; i < 64; i++) {
  547. err = reg_w_riv(dev, request, ybase + i, qtable[0][i]);
  548. if (err < 0)
  549. return err;
  550. }
  551. /* loop over c components */
  552. for (i = 0; i < 64; i++) {
  553. err = reg_w_riv(dev, request, cbase + i, qtable[1][i]);
  554. if (err < 0)
  555. return err;
  556. }
  557. return 0;
  558. }
  559. static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
  560. __u16 req, __u16 idx, __u16 val)
  561. {
  562. struct usb_device *dev = gspca_dev->dev;
  563. __u8 notdone;
  564. reg_w_riv(dev, req, idx, val);
  565. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  566. reg_w_riv(dev, req, idx, val);
  567. PDEBUG(D_FRAM, "before wait 0x%x", notdone);
  568. msleep(200);
  569. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  570. PDEBUG(D_FRAM, "after wait 0x%x", notdone);
  571. }
  572. static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
  573. __u16 req,
  574. __u16 idx, __u16 val, __u8 stat, __u8 count)
  575. {
  576. struct usb_device *dev = gspca_dev->dev;
  577. __u8 status;
  578. __u8 endcode;
  579. reg_w_riv(dev, req, idx, val);
  580. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  581. endcode = stat;
  582. PDEBUG(D_FRAM, "Status 0x%x Need 0x%x", status, stat);
  583. if (!count)
  584. return;
  585. count = 200;
  586. while (--count > 0) {
  587. msleep(10);
  588. /* gsmart mini2 write a each wait setting 1 ms is enought */
  589. /* reg_w_riv(dev, req, idx, val); */
  590. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  591. if (status == endcode) {
  592. PDEBUG(D_FRAM, "status 0x%x after wait 0x%x",
  593. status, 200 - count);
  594. break;
  595. }
  596. }
  597. }
  598. static int spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
  599. {
  600. int count = 10;
  601. while (--count > 0) {
  602. reg_r(gspca_dev, 0x21, 0, 1);
  603. if ((gspca_dev->usb_buf[0] & 0x01) == 0)
  604. break;
  605. msleep(10);
  606. }
  607. return gspca_dev->usb_buf[0];
  608. }
  609. static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
  610. {
  611. int count = 50;
  612. while (--count > 0) {
  613. reg_r(gspca_dev, 0x21, 1, 1);
  614. if (gspca_dev->usb_buf[0] != 0) {
  615. gspca_dev->usb_buf[0] = 0;
  616. reg_w(gspca_dev, 0x21, 0, 1, 1);
  617. reg_r(gspca_dev, 0x21, 1, 1);
  618. spca504B_PollingDataReady(gspca_dev);
  619. break;
  620. }
  621. msleep(10);
  622. }
  623. }
  624. static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
  625. {
  626. __u8 *data;
  627. data = gspca_dev->usb_buf;
  628. reg_r(gspca_dev, 0x20, 0, 5);
  629. PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ",
  630. data[0], data[1], data[2], data[3], data[4]);
  631. reg_r(gspca_dev, 0x23, 0, 64);
  632. reg_r(gspca_dev, 0x23, 1, 64);
  633. }
  634. static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
  635. {
  636. struct sd *sd = (struct sd *) gspca_dev;
  637. struct usb_device *dev = gspca_dev->dev;
  638. __u8 Size;
  639. __u8 Type;
  640. int rc;
  641. Size = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  642. Type = 0;
  643. switch (sd->bridge) {
  644. case BRIDGE_SPCA533:
  645. reg_w(gspca_dev, 0x31, 0, 0, 0);
  646. spca504B_WaitCmdStatus(gspca_dev);
  647. rc = spca504B_PollingDataReady(gspca_dev);
  648. spca50x_GetFirmware(gspca_dev);
  649. gspca_dev->usb_buf[0] = 2; /* type */
  650. reg_w(gspca_dev, 0x24, 0, 8, 1);
  651. reg_r(gspca_dev, 0x24, 8, 1);
  652. gspca_dev->usb_buf[0] = Size;
  653. reg_w(gspca_dev, 0x25, 0, 4, 1);
  654. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  655. rc = spca504B_PollingDataReady(gspca_dev);
  656. /* Init the cam width height with some values get on init ? */
  657. reg_w(gspca_dev, 0x31, 0, 4, 0);
  658. spca504B_WaitCmdStatus(gspca_dev);
  659. rc = spca504B_PollingDataReady(gspca_dev);
  660. break;
  661. default:
  662. /* case BRIDGE_SPCA504B: */
  663. /* case BRIDGE_SPCA536: */
  664. gspca_dev->usb_buf[0] = Size;
  665. reg_w(gspca_dev, 0x25, 0, 4, 1);
  666. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  667. Type = 6;
  668. gspca_dev->usb_buf[0] = Type;
  669. reg_w(gspca_dev, 0x27, 0, 0, 1);
  670. reg_r(gspca_dev, 0x27, 0, 1); /* type */
  671. rc = spca504B_PollingDataReady(gspca_dev);
  672. break;
  673. case BRIDGE_SPCA504:
  674. Size += 3;
  675. if (sd->subtype == AiptekMiniPenCam13) {
  676. /* spca504a aiptek */
  677. spca504A_acknowledged_command(gspca_dev,
  678. 0x08, Size, 0,
  679. 0x80 | (Size & 0x0f), 1);
  680. spca504A_acknowledged_command(gspca_dev,
  681. 1, 3, 0, 0x9f, 0);
  682. } else {
  683. spca504_acknowledged_command(gspca_dev, 0x08, Size, 0);
  684. }
  685. break;
  686. case BRIDGE_SPCA504C:
  687. /* capture mode */
  688. reg_w_riv(dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x00);
  689. reg_w_riv(dev, 0x20, 0x01, 0x0500 | (Size & 0x0f));
  690. break;
  691. }
  692. }
  693. static void spca504_wait_status(struct gspca_dev *gspca_dev)
  694. {
  695. int cnt;
  696. cnt = 256;
  697. while (--cnt > 0) {
  698. /* With this we get the status, when return 0 it's all ok */
  699. if (reg_r_12(gspca_dev, 0x06, 0x00, 1) == 0)
  700. return;
  701. msleep(10);
  702. }
  703. }
  704. static void spca504B_setQtable(struct gspca_dev *gspca_dev)
  705. {
  706. gspca_dev->usb_buf[0] = 3;
  707. reg_w(gspca_dev, 0x26, 0, 0, 1);
  708. reg_r(gspca_dev, 0x26, 0, 1);
  709. spca504B_PollingDataReady(gspca_dev);
  710. }
  711. static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
  712. {
  713. struct sd *sd = (struct sd *) gspca_dev;
  714. int pollreg = 1;
  715. switch (sd->bridge) {
  716. case BRIDGE_SPCA504:
  717. case BRIDGE_SPCA504C:
  718. pollreg = 0;
  719. /* fall thru */
  720. default:
  721. /* case BRIDGE_SPCA533: */
  722. /* case BRIDGE_SPCA504B: */
  723. reg_w(gspca_dev, 0, 0, 0x21a7, 0); /* brightness */
  724. reg_w(gspca_dev, 0, 0x20, 0x21a8, 0); /* contrast */
  725. reg_w(gspca_dev, 0, 0, 0x21ad, 0); /* hue */
  726. reg_w(gspca_dev, 0, 1, 0x21ac, 0); /* sat/hue */
  727. reg_w(gspca_dev, 0, 0x20, 0x21ae, 0); /* saturation */
  728. reg_w(gspca_dev, 0, 0, 0x21a3, 0); /* gamma */
  729. break;
  730. case BRIDGE_SPCA536:
  731. reg_w(gspca_dev, 0, 0, 0x20f0, 0);
  732. reg_w(gspca_dev, 0, 0x21, 0x20f1, 0);
  733. reg_w(gspca_dev, 0, 0x40, 0x20f5, 0);
  734. reg_w(gspca_dev, 0, 1, 0x20f4, 0);
  735. reg_w(gspca_dev, 0, 0x40, 0x20f6, 0);
  736. reg_w(gspca_dev, 0, 0, 0x2089, 0);
  737. break;
  738. }
  739. if (pollreg)
  740. spca504B_PollingDataReady(gspca_dev);
  741. }
  742. /* this function is called at probe time */
  743. static int sd_config(struct gspca_dev *gspca_dev,
  744. const struct usb_device_id *id)
  745. {
  746. struct sd *sd = (struct sd *) gspca_dev;
  747. struct cam *cam;
  748. cam = &gspca_dev->cam;
  749. cam->epaddr = 0x01;
  750. sd->bridge = id->driver_info >> 8;
  751. sd->subtype = id->driver_info;
  752. if (sd->subtype == AiptekMiniPenCam13) {
  753. /* try to get the firmware as some cam answer 2.0.1.2.2
  754. * and should be a spca504b then overwrite that setting */
  755. reg_r(gspca_dev, 0x20, 0, 1);
  756. switch (gspca_dev->usb_buf[0]) {
  757. case 1:
  758. break; /* (right bridge/subtype) */
  759. case 2:
  760. sd->bridge = BRIDGE_SPCA504B;
  761. sd->subtype = 0;
  762. break;
  763. default:
  764. return -ENODEV;
  765. }
  766. }
  767. switch (sd->bridge) {
  768. default:
  769. /* case BRIDGE_SPCA504B: */
  770. /* case BRIDGE_SPCA504: */
  771. /* case BRIDGE_SPCA536: */
  772. cam->cam_mode = vga_mode;
  773. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  774. break;
  775. case BRIDGE_SPCA533:
  776. cam->cam_mode = custom_mode;
  777. cam->nmodes = sizeof custom_mode / sizeof custom_mode[0];
  778. break;
  779. case BRIDGE_SPCA504C:
  780. cam->cam_mode = vga_mode2;
  781. cam->nmodes = sizeof vga_mode2 / sizeof vga_mode2[0];
  782. break;
  783. }
  784. sd->qindex = 5; /* set the quantization table */
  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. return 0;
  789. }
  790. /* this function is called at probe and resume time */
  791. static int sd_init(struct gspca_dev *gspca_dev)
  792. {
  793. struct sd *sd = (struct sd *) gspca_dev;
  794. struct usb_device *dev = gspca_dev->dev;
  795. int rc;
  796. __u8 i;
  797. __u8 info[6];
  798. int err_code;
  799. switch (sd->bridge) {
  800. case BRIDGE_SPCA504B:
  801. reg_w(gspca_dev, 0x1d, 0, 0, 0);
  802. reg_w(gspca_dev, 0, 1, 0x2306, 0);
  803. reg_w(gspca_dev, 0, 0, 0x0d04, 0);
  804. reg_w(gspca_dev, 0, 0, 0x2000, 0);
  805. reg_w(gspca_dev, 0, 0x13, 0x2301, 0);
  806. reg_w(gspca_dev, 0, 0, 0x2306, 0);
  807. /* fall thru */
  808. case BRIDGE_SPCA533:
  809. rc = spca504B_PollingDataReady(gspca_dev);
  810. spca50x_GetFirmware(gspca_dev);
  811. break;
  812. case BRIDGE_SPCA536:
  813. spca50x_GetFirmware(gspca_dev);
  814. reg_r(gspca_dev, 0x00, 0x5002, 1);
  815. gspca_dev->usb_buf[0] = 0;
  816. reg_w(gspca_dev, 0x24, 0, 0, 1);
  817. reg_r(gspca_dev, 0x24, 0, 1);
  818. rc = spca504B_PollingDataReady(gspca_dev);
  819. reg_w(gspca_dev, 0x34, 0, 0, 0);
  820. spca504B_WaitCmdStatus(gspca_dev);
  821. break;
  822. case BRIDGE_SPCA504C: /* pccam600 */
  823. PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)");
  824. reg_w_riv(dev, 0xe0, 0x0000, 0x0000);
  825. reg_w_riv(dev, 0xe0, 0x0000, 0x0001); /* reset */
  826. spca504_wait_status(gspca_dev);
  827. if (sd->subtype == LogitechClickSmart420)
  828. write_vector(gspca_dev,
  829. spca504A_clicksmart420_open_data);
  830. else
  831. write_vector(gspca_dev, spca504_pccam600_open_data);
  832. err_code = spca50x_setup_qtable(gspca_dev,
  833. 0x00, 0x2800,
  834. 0x2840, qtable_creative_pccam);
  835. if (err_code < 0) {
  836. PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed");
  837. return err_code;
  838. }
  839. break;
  840. default:
  841. /* case BRIDGE_SPCA504: */
  842. PDEBUG(D_STREAM, "Opening SPCA504");
  843. if (sd->subtype == AiptekMiniPenCam13) {
  844. /*****************************/
  845. for (i = 0; i < 6; i++)
  846. info[i] = reg_r_1(gspca_dev, i);
  847. PDEBUG(D_STREAM,
  848. "Read info: %d %d %d %d %d %d."
  849. " Should be 1,0,2,2,0,0",
  850. info[0], info[1], info[2],
  851. info[3], info[4], info[5]);
  852. /* spca504a aiptek */
  853. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  854. spca504A_acknowledged_command(gspca_dev, 0x24,
  855. 8, 3, 0x9e, 1);
  856. /* Twice sequencial need status 0xff->0x9e->0x9d */
  857. spca504A_acknowledged_command(gspca_dev, 0x24,
  858. 8, 3, 0x9e, 0);
  859. spca504A_acknowledged_command(gspca_dev, 0x24,
  860. 0, 0, 0x9d, 1);
  861. /******************************/
  862. /* spca504a aiptek */
  863. spca504A_acknowledged_command(gspca_dev, 0x08,
  864. 6, 0, 0x86, 1);
  865. /* reg_write (dev, 0, 0x2000, 0); */
  866. /* reg_write (dev, 0, 0x2883, 1); */
  867. /* spca504A_acknowledged_command (gspca_dev, 0x08,
  868. 6, 0, 0x86, 1); */
  869. /* spca504A_acknowledged_command (gspca_dev, 0x24,
  870. 0, 0, 0x9D, 1); */
  871. reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
  872. reg_w_riv(dev, 0x0, 0x2310, 0x05);
  873. spca504A_acknowledged_command(gspca_dev, 0x01,
  874. 0x0f, 0, 0xff, 0);
  875. }
  876. /* setup qtable */
  877. reg_w_riv(dev, 0, 0x2000, 0);
  878. reg_w_riv(dev, 0, 0x2883, 1);
  879. err_code = spca50x_setup_qtable(gspca_dev,
  880. 0x00, 0x2800,
  881. 0x2840,
  882. qtable_spca504_default);
  883. if (err_code < 0) {
  884. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  885. return err_code;
  886. }
  887. break;
  888. }
  889. return 0;
  890. }
  891. static int sd_start(struct gspca_dev *gspca_dev)
  892. {
  893. struct sd *sd = (struct sd *) gspca_dev;
  894. struct usb_device *dev = gspca_dev->dev;
  895. int rc;
  896. int enable;
  897. __u8 i;
  898. __u8 info[6];
  899. if (sd->bridge == BRIDGE_SPCA504B)
  900. spca504B_setQtable(gspca_dev);
  901. spca504B_SetSizeType(gspca_dev);
  902. switch (sd->bridge) {
  903. default:
  904. /* case BRIDGE_SPCA504B: */
  905. /* case BRIDGE_SPCA533: */
  906. /* case BRIDGE_SPCA536: */
  907. if (sd->subtype == MegapixV4 ||
  908. sd->subtype == LogitechClickSmart820) {
  909. reg_w(gspca_dev, 0xf0, 0, 0, 0);
  910. spca504B_WaitCmdStatus(gspca_dev);
  911. reg_r(gspca_dev, 0xf0, 4, 0);
  912. spca504B_WaitCmdStatus(gspca_dev);
  913. } else {
  914. reg_w(gspca_dev, 0x31, 0, 4, 0);
  915. spca504B_WaitCmdStatus(gspca_dev);
  916. rc = spca504B_PollingDataReady(gspca_dev);
  917. }
  918. break;
  919. case BRIDGE_SPCA504:
  920. if (sd->subtype == AiptekMiniPenCam13) {
  921. for (i = 0; i < 6; i++)
  922. info[i] = reg_r_1(gspca_dev, i);
  923. PDEBUG(D_STREAM,
  924. "Read info: %d %d %d %d %d %d."
  925. " Should be 1,0,2,2,0,0",
  926. info[0], info[1], info[2],
  927. info[3], info[4], info[5]);
  928. /* spca504a aiptek */
  929. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  930. spca504A_acknowledged_command(gspca_dev, 0x24,
  931. 8, 3, 0x9e, 1);
  932. /* Twice sequencial need status 0xff->0x9e->0x9d */
  933. spca504A_acknowledged_command(gspca_dev, 0x24,
  934. 8, 3, 0x9e, 0);
  935. spca504A_acknowledged_command(gspca_dev, 0x24,
  936. 0, 0, 0x9d, 1);
  937. } else {
  938. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  939. for (i = 0; i < 6; i++)
  940. info[i] = reg_r_1(gspca_dev, i);
  941. PDEBUG(D_STREAM,
  942. "Read info: %d %d %d %d %d %d."
  943. " Should be 1,0,2,2,0,0",
  944. info[0], info[1], info[2],
  945. info[3], info[4], info[5]);
  946. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  947. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  948. }
  949. spca504B_SetSizeType(gspca_dev);
  950. reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
  951. reg_w_riv(dev, 0x0, 0x2310, 0x05);
  952. break;
  953. case BRIDGE_SPCA504C:
  954. if (sd->subtype == LogitechClickSmart420) {
  955. write_vector(gspca_dev,
  956. spca504A_clicksmart420_init_data);
  957. } else {
  958. write_vector(gspca_dev, spca504_pccam600_init_data);
  959. }
  960. enable = (sd->autogain ? 0x04 : 0x01);
  961. reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */
  962. reg_w_riv(dev, 0xb0, 0x0000, enable); /* auto whiteness */
  963. /* set default exposure compensation and whiteness balance */
  964. reg_w_riv(dev, 0x30, 0x0001, 800); /* ~ 20 fps */
  965. reg_w_riv(dev, 0x30, 0x0002, 1600);
  966. spca504B_SetSizeType(gspca_dev);
  967. break;
  968. }
  969. sp5xx_initContBrigHueRegisters(gspca_dev);
  970. return 0;
  971. }
  972. static void sd_stopN(struct gspca_dev *gspca_dev)
  973. {
  974. struct sd *sd = (struct sd *) gspca_dev;
  975. struct usb_device *dev = gspca_dev->dev;
  976. switch (sd->bridge) {
  977. default:
  978. /* case BRIDGE_SPCA533: */
  979. /* case BRIDGE_SPCA536: */
  980. /* case BRIDGE_SPCA504B: */
  981. reg_w(gspca_dev, 0x31, 0, 0, 0);
  982. spca504B_WaitCmdStatus(gspca_dev);
  983. spca504B_PollingDataReady(gspca_dev);
  984. break;
  985. case BRIDGE_SPCA504:
  986. case BRIDGE_SPCA504C:
  987. reg_w_riv(dev, 0x00, 0x2000, 0x0000);
  988. if (sd->subtype == AiptekMiniPenCam13) {
  989. /* spca504a aiptek */
  990. /* spca504A_acknowledged_command(gspca_dev, 0x08,
  991. 6, 0, 0x86, 1); */
  992. spca504A_acknowledged_command(gspca_dev, 0x24,
  993. 0x00, 0x00, 0x9d, 1);
  994. spca504A_acknowledged_command(gspca_dev, 0x01,
  995. 0x0f, 0x00, 0xff, 1);
  996. } else {
  997. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  998. reg_w_riv(dev, 0x01, 0x000f, 0x00);
  999. }
  1000. break;
  1001. }
  1002. }
  1003. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1004. struct gspca_frame *frame, /* target */
  1005. __u8 *data, /* isoc packet */
  1006. int len) /* iso packet length */
  1007. {
  1008. struct sd *sd = (struct sd *) gspca_dev;
  1009. int i, sof = 0;
  1010. unsigned char *s, *d;
  1011. static unsigned char ffd9[] = {0xff, 0xd9};
  1012. /* frames are jpeg 4.1.1 without 0xff escape */
  1013. switch (sd->bridge) {
  1014. case BRIDGE_SPCA533:
  1015. if (data[0] == 0xff) {
  1016. if (data[1] != 0x01) { /* drop packet */
  1017. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1018. return;
  1019. }
  1020. sof = 1;
  1021. data += SPCA533_OFFSET_DATA;
  1022. len -= SPCA533_OFFSET_DATA;
  1023. } else {
  1024. data += 1;
  1025. len -= 1;
  1026. }
  1027. break;
  1028. case BRIDGE_SPCA536:
  1029. if (data[0] == 0xff) {
  1030. sof = 1;
  1031. data += SPCA536_OFFSET_DATA;
  1032. len -= SPCA536_OFFSET_DATA;
  1033. } else {
  1034. data += 2;
  1035. len -= 2;
  1036. }
  1037. break;
  1038. default:
  1039. /* case BRIDGE_SPCA504: */
  1040. /* case BRIDGE_SPCA504B: */
  1041. switch (data[0]) {
  1042. case 0xfe: /* start of frame */
  1043. sof = 1;
  1044. data += SPCA50X_OFFSET_DATA;
  1045. len -= SPCA50X_OFFSET_DATA;
  1046. break;
  1047. case 0xff: /* drop packet */
  1048. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1049. return;
  1050. default:
  1051. data += 1;
  1052. len -= 1;
  1053. break;
  1054. }
  1055. break;
  1056. case BRIDGE_SPCA504C:
  1057. switch (data[0]) {
  1058. case 0xfe: /* start of frame */
  1059. sof = 1;
  1060. data += SPCA504_PCCAM600_OFFSET_DATA;
  1061. len -= SPCA504_PCCAM600_OFFSET_DATA;
  1062. break;
  1063. case 0xff: /* drop packet */
  1064. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1065. return;
  1066. default:
  1067. data += 1;
  1068. len -= 1;
  1069. break;
  1070. }
  1071. break;
  1072. }
  1073. if (sof) { /* start of frame */
  1074. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  1075. ffd9, 2);
  1076. /* put the JPEG header in the new frame */
  1077. jpeg_put_header(gspca_dev, frame,
  1078. ((struct sd *) gspca_dev)->qindex,
  1079. 0x22);
  1080. }
  1081. /* add 0x00 after 0xff */
  1082. for (i = len; --i >= 0; )
  1083. if (data[i] == 0xff)
  1084. break;
  1085. if (i < 0) { /* no 0xff */
  1086. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  1087. return;
  1088. }
  1089. s = data;
  1090. d = sd->packet;
  1091. for (i = 0; i < len; i++) {
  1092. *d++ = *s++;
  1093. if (s[-1] == 0xff)
  1094. *d++ = 0x00;
  1095. }
  1096. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  1097. sd->packet, d - sd->packet);
  1098. }
  1099. static void setbrightness(struct gspca_dev *gspca_dev)
  1100. {
  1101. struct sd *sd = (struct sd *) gspca_dev;
  1102. struct usb_device *dev = gspca_dev->dev;
  1103. switch (sd->bridge) {
  1104. default:
  1105. /* case BRIDGE_SPCA533: */
  1106. /* case BRIDGE_SPCA504B: */
  1107. /* case BRIDGE_SPCA504: */
  1108. /* case BRIDGE_SPCA504C: */
  1109. reg_w_riv(dev, 0x0, 0x21a7, sd->brightness);
  1110. break;
  1111. case BRIDGE_SPCA536:
  1112. reg_w_riv(dev, 0x0, 0x20f0, sd->brightness);
  1113. break;
  1114. }
  1115. }
  1116. static void getbrightness(struct gspca_dev *gspca_dev)
  1117. {
  1118. struct sd *sd = (struct sd *) gspca_dev;
  1119. __u16 brightness = 0;
  1120. switch (sd->bridge) {
  1121. default:
  1122. /* case BRIDGE_SPCA533: */
  1123. /* case BRIDGE_SPCA504B: */
  1124. /* case BRIDGE_SPCA504: */
  1125. /* case BRIDGE_SPCA504C: */
  1126. brightness = reg_r_12(gspca_dev, 0x00, 0x21a7, 2);
  1127. break;
  1128. case BRIDGE_SPCA536:
  1129. brightness = reg_r_12(gspca_dev, 0x00, 0x20f0, 2);
  1130. break;
  1131. }
  1132. sd->brightness = ((brightness & 0xff) - 128) % 255;
  1133. }
  1134. static void setcontrast(struct gspca_dev *gspca_dev)
  1135. {
  1136. struct sd *sd = (struct sd *) gspca_dev;
  1137. struct usb_device *dev = gspca_dev->dev;
  1138. switch (sd->bridge) {
  1139. default:
  1140. /* case BRIDGE_SPCA533: */
  1141. /* case BRIDGE_SPCA504B: */
  1142. /* case BRIDGE_SPCA504: */
  1143. /* case BRIDGE_SPCA504C: */
  1144. reg_w_riv(dev, 0x0, 0x21a8, sd->contrast);
  1145. break;
  1146. case BRIDGE_SPCA536:
  1147. reg_w_riv(dev, 0x0, 0x20f1, sd->contrast);
  1148. break;
  1149. }
  1150. }
  1151. static void getcontrast(struct gspca_dev *gspca_dev)
  1152. {
  1153. struct sd *sd = (struct sd *) gspca_dev;
  1154. switch (sd->bridge) {
  1155. default:
  1156. /* case BRIDGE_SPCA533: */
  1157. /* case BRIDGE_SPCA504B: */
  1158. /* case BRIDGE_SPCA504: */
  1159. /* case BRIDGE_SPCA504C: */
  1160. sd->contrast = reg_r_12(gspca_dev, 0x00, 0x21a8, 2);
  1161. break;
  1162. case BRIDGE_SPCA536:
  1163. sd->contrast = reg_r_12(gspca_dev, 0x00, 0x20f1, 2);
  1164. break;
  1165. }
  1166. }
  1167. static void setcolors(struct gspca_dev *gspca_dev)
  1168. {
  1169. struct sd *sd = (struct sd *) gspca_dev;
  1170. struct usb_device *dev = gspca_dev->dev;
  1171. switch (sd->bridge) {
  1172. default:
  1173. /* case BRIDGE_SPCA533: */
  1174. /* case BRIDGE_SPCA504B: */
  1175. /* case BRIDGE_SPCA504: */
  1176. /* case BRIDGE_SPCA504C: */
  1177. reg_w_riv(dev, 0x0, 0x21ae, sd->colors);
  1178. break;
  1179. case BRIDGE_SPCA536:
  1180. reg_w_riv(dev, 0x0, 0x20f6, sd->colors);
  1181. break;
  1182. }
  1183. }
  1184. static void getcolors(struct gspca_dev *gspca_dev)
  1185. {
  1186. struct sd *sd = (struct sd *) gspca_dev;
  1187. switch (sd->bridge) {
  1188. default:
  1189. /* case BRIDGE_SPCA533: */
  1190. /* case BRIDGE_SPCA504B: */
  1191. /* case BRIDGE_SPCA504: */
  1192. /* case BRIDGE_SPCA504C: */
  1193. sd->colors = reg_r_12(gspca_dev, 0x00, 0x21ae, 2) >> 1;
  1194. break;
  1195. case BRIDGE_SPCA536:
  1196. sd->colors = reg_r_12(gspca_dev, 0x00, 0x20f6, 2) >> 1;
  1197. break;
  1198. }
  1199. }
  1200. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1201. {
  1202. struct sd *sd = (struct sd *) gspca_dev;
  1203. sd->brightness = val;
  1204. if (gspca_dev->streaming)
  1205. setbrightness(gspca_dev);
  1206. return 0;
  1207. }
  1208. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1209. {
  1210. struct sd *sd = (struct sd *) gspca_dev;
  1211. getbrightness(gspca_dev);
  1212. *val = sd->brightness;
  1213. return 0;
  1214. }
  1215. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1216. {
  1217. struct sd *sd = (struct sd *) gspca_dev;
  1218. sd->contrast = val;
  1219. if (gspca_dev->streaming)
  1220. setcontrast(gspca_dev);
  1221. return 0;
  1222. }
  1223. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1224. {
  1225. struct sd *sd = (struct sd *) gspca_dev;
  1226. getcontrast(gspca_dev);
  1227. *val = sd->contrast;
  1228. return 0;
  1229. }
  1230. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1231. {
  1232. struct sd *sd = (struct sd *) gspca_dev;
  1233. sd->colors = val;
  1234. if (gspca_dev->streaming)
  1235. setcolors(gspca_dev);
  1236. return 0;
  1237. }
  1238. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1239. {
  1240. struct sd *sd = (struct sd *) gspca_dev;
  1241. getcolors(gspca_dev);
  1242. *val = sd->colors;
  1243. return 0;
  1244. }
  1245. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1246. {
  1247. struct sd *sd = (struct sd *) gspca_dev;
  1248. sd->autogain = val;
  1249. return 0;
  1250. }
  1251. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1252. {
  1253. struct sd *sd = (struct sd *) gspca_dev;
  1254. *val = sd->autogain;
  1255. return 0;
  1256. }
  1257. /* sub-driver description */
  1258. static const struct sd_desc sd_desc = {
  1259. .name = MODULE_NAME,
  1260. .ctrls = sd_ctrls,
  1261. .nctrls = ARRAY_SIZE(sd_ctrls),
  1262. .config = sd_config,
  1263. .init = sd_init,
  1264. .start = sd_start,
  1265. .stopN = sd_stopN,
  1266. .pkt_scan = sd_pkt_scan,
  1267. };
  1268. /* -- module initialisation -- */
  1269. #define BS(bridge, subtype) \
  1270. .driver_info = (BRIDGE_ ## bridge << 8) \
  1271. | (subtype)
  1272. static const __devinitdata struct usb_device_id device_table[] = {
  1273. {USB_DEVICE(0x041e, 0x400b), BS(SPCA504C, 0)},
  1274. {USB_DEVICE(0x041e, 0x4012), BS(SPCA504C, 0)},
  1275. {USB_DEVICE(0x041e, 0x4013), BS(SPCA504C, 0)},
  1276. {USB_DEVICE(0x0458, 0x7006), BS(SPCA504B, 0)},
  1277. {USB_DEVICE(0x0461, 0x0821), BS(SPCA533, 0)},
  1278. {USB_DEVICE(0x046d, 0x0905), BS(SPCA533, LogitechClickSmart820)},
  1279. {USB_DEVICE(0x046d, 0x0960), BS(SPCA504C, LogitechClickSmart420)},
  1280. {USB_DEVICE(0x0471, 0x0322), BS(SPCA504B, 0)},
  1281. {USB_DEVICE(0x04a5, 0x3003), BS(SPCA504B, 0)},
  1282. {USB_DEVICE(0x04a5, 0x3008), BS(SPCA533, 0)},
  1283. {USB_DEVICE(0x04a5, 0x300a), BS(SPCA533, 0)},
  1284. {USB_DEVICE(0x04f1, 0x1001), BS(SPCA504B, 0)},
  1285. {USB_DEVICE(0x04fc, 0x500c), BS(SPCA504B, 0)},
  1286. {USB_DEVICE(0x04fc, 0x504a), BS(SPCA504, AiptekMiniPenCam13)},
  1287. {USB_DEVICE(0x04fc, 0x504b), BS(SPCA504B, 0)},
  1288. {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)},
  1289. {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
  1290. {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
  1291. {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
  1292. {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
  1293. {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)},
  1294. {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)},
  1295. {USB_DEVICE(0x055f, 0xc211), BS(SPCA536, 0)},
  1296. {USB_DEVICE(0x055f, 0xc230), BS(SPCA533, 0)},
  1297. {USB_DEVICE(0x055f, 0xc232), BS(SPCA533, 0)},
  1298. {USB_DEVICE(0x055f, 0xc360), BS(SPCA536, 0)},
  1299. {USB_DEVICE(0x055f, 0xc420), BS(SPCA504, 0)},
  1300. {USB_DEVICE(0x055f, 0xc430), BS(SPCA533, 0)},
  1301. {USB_DEVICE(0x055f, 0xc440), BS(SPCA533, 0)},
  1302. {USB_DEVICE(0x055f, 0xc520), BS(SPCA504, 0)},
  1303. {USB_DEVICE(0x055f, 0xc530), BS(SPCA533, 0)},
  1304. {USB_DEVICE(0x055f, 0xc540), BS(SPCA533, 0)},
  1305. {USB_DEVICE(0x055f, 0xc630), BS(SPCA533, 0)},
  1306. {USB_DEVICE(0x055f, 0xc650), BS(SPCA533, 0)},
  1307. {USB_DEVICE(0x05da, 0x1018), BS(SPCA504B, 0)},
  1308. {USB_DEVICE(0x06d6, 0x0031), BS(SPCA533, 0)},
  1309. {USB_DEVICE(0x0733, 0x1311), BS(SPCA533, 0)},
  1310. {USB_DEVICE(0x0733, 0x1314), BS(SPCA533, 0)},
  1311. {USB_DEVICE(0x0733, 0x2211), BS(SPCA533, 0)},
  1312. {USB_DEVICE(0x0733, 0x2221), BS(SPCA533, 0)},
  1313. {USB_DEVICE(0x0733, 0x3261), BS(SPCA536, 0)},
  1314. {USB_DEVICE(0x0733, 0x3281), BS(SPCA536, 0)},
  1315. {USB_DEVICE(0x08ca, 0x0104), BS(SPCA533, 0)},
  1316. {USB_DEVICE(0x08ca, 0x0106), BS(SPCA533, 0)},
  1317. {USB_DEVICE(0x08ca, 0x2008), BS(SPCA504B, 0)},
  1318. {USB_DEVICE(0x08ca, 0x2010), BS(SPCA533, 0)},
  1319. {USB_DEVICE(0x08ca, 0x2016), BS(SPCA504B, 0)},
  1320. {USB_DEVICE(0x08ca, 0x2018), BS(SPCA504B, 0)},
  1321. {USB_DEVICE(0x08ca, 0x2020), BS(SPCA533, 0)},
  1322. {USB_DEVICE(0x08ca, 0x2022), BS(SPCA533, 0)},
  1323. {USB_DEVICE(0x08ca, 0x2024), BS(SPCA536, 0)},
  1324. {USB_DEVICE(0x08ca, 0x2028), BS(SPCA533, 0)},
  1325. {USB_DEVICE(0x08ca, 0x2040), BS(SPCA536, 0)},
  1326. {USB_DEVICE(0x08ca, 0x2042), BS(SPCA536, 0)},
  1327. {USB_DEVICE(0x08ca, 0x2050), BS(SPCA536, 0)},
  1328. {USB_DEVICE(0x08ca, 0x2060), BS(SPCA536, 0)},
  1329. {USB_DEVICE(0x0d64, 0x0303), BS(SPCA536, 0)},
  1330. {}
  1331. };
  1332. MODULE_DEVICE_TABLE(usb, device_table);
  1333. /* -- device connect -- */
  1334. static int sd_probe(struct usb_interface *intf,
  1335. const struct usb_device_id *id)
  1336. {
  1337. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1338. THIS_MODULE);
  1339. }
  1340. static struct usb_driver sd_driver = {
  1341. .name = MODULE_NAME,
  1342. .id_table = device_table,
  1343. .probe = sd_probe,
  1344. .disconnect = gspca_disconnect,
  1345. #ifdef CONFIG_PM
  1346. .suspend = gspca_suspend,
  1347. .resume = gspca_resume,
  1348. #endif
  1349. };
  1350. /* -- module insert / remove -- */
  1351. static int __init sd_mod_init(void)
  1352. {
  1353. if (usb_register(&sd_driver) < 0)
  1354. return -1;
  1355. PDEBUG(D_PROBE, "registered");
  1356. return 0;
  1357. }
  1358. static void __exit sd_mod_exit(void)
  1359. {
  1360. usb_deregister(&sd_driver);
  1361. PDEBUG(D_PROBE, "deregistered");
  1362. }
  1363. module_init(sd_mod_init);
  1364. module_exit(sd_mod_exit);