sunplus.c 38 KB

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