sunplus.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  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. #define QUANT_VAL 5 /* quantization table */
  24. #include "jpeg.h"
  25. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  26. MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver");
  27. MODULE_LICENSE("GPL");
  28. /* specific webcam descriptor */
  29. struct sd {
  30. struct gspca_dev gspca_dev; /* !! must be the first item */
  31. __u8 packet[ISO_MAX_SIZE + 128];
  32. /* !! no more than 128 ff in an ISO packet */
  33. unsigned char brightness;
  34. unsigned char contrast;
  35. unsigned char colors;
  36. unsigned char autogain;
  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 const 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 const 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 const 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. sd->bridge = id->driver_info >> 8;
  750. sd->subtype = id->driver_info;
  751. if (sd->subtype == AiptekMiniPenCam13) {
  752. /* try to get the firmware as some cam answer 2.0.1.2.2
  753. * and should be a spca504b then overwrite that setting */
  754. reg_r(gspca_dev, 0x20, 0, 1);
  755. switch (gspca_dev->usb_buf[0]) {
  756. case 1:
  757. break; /* (right bridge/subtype) */
  758. case 2:
  759. sd->bridge = BRIDGE_SPCA504B;
  760. sd->subtype = 0;
  761. break;
  762. default:
  763. return -ENODEV;
  764. }
  765. }
  766. switch (sd->bridge) {
  767. default:
  768. /* case BRIDGE_SPCA504B: */
  769. /* case BRIDGE_SPCA504: */
  770. /* case BRIDGE_SPCA536: */
  771. cam->cam_mode = vga_mode;
  772. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  773. break;
  774. case BRIDGE_SPCA533:
  775. cam->cam_mode = custom_mode;
  776. cam->nmodes = sizeof custom_mode / sizeof custom_mode[0];
  777. break;
  778. case BRIDGE_SPCA504C:
  779. cam->cam_mode = vga_mode2;
  780. cam->nmodes = sizeof vga_mode2 / sizeof vga_mode2[0];
  781. break;
  782. }
  783. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  784. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  785. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  786. return 0;
  787. }
  788. /* this function is called at probe and resume time */
  789. static int sd_init(struct gspca_dev *gspca_dev)
  790. {
  791. struct sd *sd = (struct sd *) gspca_dev;
  792. struct usb_device *dev = gspca_dev->dev;
  793. int rc;
  794. __u8 i;
  795. __u8 info[6];
  796. int err_code;
  797. switch (sd->bridge) {
  798. case BRIDGE_SPCA504B:
  799. reg_w(gspca_dev, 0x1d, 0, 0, 0);
  800. reg_w(gspca_dev, 0, 1, 0x2306, 0);
  801. reg_w(gspca_dev, 0, 0, 0x0d04, 0);
  802. reg_w(gspca_dev, 0, 0, 0x2000, 0);
  803. reg_w(gspca_dev, 0, 0x13, 0x2301, 0);
  804. reg_w(gspca_dev, 0, 0, 0x2306, 0);
  805. /* fall thru */
  806. case BRIDGE_SPCA533:
  807. rc = spca504B_PollingDataReady(gspca_dev);
  808. spca50x_GetFirmware(gspca_dev);
  809. break;
  810. case BRIDGE_SPCA536:
  811. spca50x_GetFirmware(gspca_dev);
  812. reg_r(gspca_dev, 0x00, 0x5002, 1);
  813. gspca_dev->usb_buf[0] = 0;
  814. reg_w(gspca_dev, 0x24, 0, 0, 1);
  815. reg_r(gspca_dev, 0x24, 0, 1);
  816. rc = spca504B_PollingDataReady(gspca_dev);
  817. reg_w(gspca_dev, 0x34, 0, 0, 0);
  818. spca504B_WaitCmdStatus(gspca_dev);
  819. break;
  820. case BRIDGE_SPCA504C: /* pccam600 */
  821. PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)");
  822. reg_w_riv(dev, 0xe0, 0x0000, 0x0000);
  823. reg_w_riv(dev, 0xe0, 0x0000, 0x0001); /* reset */
  824. spca504_wait_status(gspca_dev);
  825. if (sd->subtype == LogitechClickSmart420)
  826. write_vector(gspca_dev,
  827. spca504A_clicksmart420_open_data);
  828. else
  829. write_vector(gspca_dev, spca504_pccam600_open_data);
  830. err_code = spca50x_setup_qtable(gspca_dev,
  831. 0x00, 0x2800,
  832. 0x2840, qtable_creative_pccam);
  833. if (err_code < 0) {
  834. PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed");
  835. return err_code;
  836. }
  837. break;
  838. default:
  839. /* case BRIDGE_SPCA504: */
  840. PDEBUG(D_STREAM, "Opening SPCA504");
  841. if (sd->subtype == AiptekMiniPenCam13) {
  842. /*****************************/
  843. for (i = 0; i < 6; i++)
  844. info[i] = reg_r_1(gspca_dev, i);
  845. PDEBUG(D_STREAM,
  846. "Read info: %d %d %d %d %d %d."
  847. " Should be 1,0,2,2,0,0",
  848. info[0], info[1], info[2],
  849. info[3], info[4], info[5]);
  850. /* spca504a aiptek */
  851. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  852. spca504A_acknowledged_command(gspca_dev, 0x24,
  853. 8, 3, 0x9e, 1);
  854. /* Twice sequencial need status 0xff->0x9e->0x9d */
  855. spca504A_acknowledged_command(gspca_dev, 0x24,
  856. 8, 3, 0x9e, 0);
  857. spca504A_acknowledged_command(gspca_dev, 0x24,
  858. 0, 0, 0x9d, 1);
  859. /******************************/
  860. /* spca504a aiptek */
  861. spca504A_acknowledged_command(gspca_dev, 0x08,
  862. 6, 0, 0x86, 1);
  863. /* reg_write (dev, 0, 0x2000, 0); */
  864. /* reg_write (dev, 0, 0x2883, 1); */
  865. /* spca504A_acknowledged_command (gspca_dev, 0x08,
  866. 6, 0, 0x86, 1); */
  867. /* spca504A_acknowledged_command (gspca_dev, 0x24,
  868. 0, 0, 0x9D, 1); */
  869. reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
  870. reg_w_riv(dev, 0x0, 0x2310, 0x05);
  871. spca504A_acknowledged_command(gspca_dev, 0x01,
  872. 0x0f, 0, 0xff, 0);
  873. }
  874. /* setup qtable */
  875. reg_w_riv(dev, 0, 0x2000, 0);
  876. reg_w_riv(dev, 0, 0x2883, 1);
  877. err_code = spca50x_setup_qtable(gspca_dev,
  878. 0x00, 0x2800,
  879. 0x2840,
  880. qtable_spca504_default);
  881. if (err_code < 0) {
  882. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  883. return err_code;
  884. }
  885. break;
  886. }
  887. return 0;
  888. }
  889. static int sd_start(struct gspca_dev *gspca_dev)
  890. {
  891. struct sd *sd = (struct sd *) gspca_dev;
  892. struct usb_device *dev = gspca_dev->dev;
  893. int rc;
  894. int enable;
  895. __u8 i;
  896. __u8 info[6];
  897. if (sd->bridge == BRIDGE_SPCA504B)
  898. spca504B_setQtable(gspca_dev);
  899. spca504B_SetSizeType(gspca_dev);
  900. switch (sd->bridge) {
  901. default:
  902. /* case BRIDGE_SPCA504B: */
  903. /* case BRIDGE_SPCA533: */
  904. /* case BRIDGE_SPCA536: */
  905. if (sd->subtype == MegapixV4 ||
  906. sd->subtype == LogitechClickSmart820) {
  907. reg_w(gspca_dev, 0xf0, 0, 0, 0);
  908. spca504B_WaitCmdStatus(gspca_dev);
  909. reg_r(gspca_dev, 0xf0, 4, 0);
  910. spca504B_WaitCmdStatus(gspca_dev);
  911. } else {
  912. reg_w(gspca_dev, 0x31, 0, 4, 0);
  913. spca504B_WaitCmdStatus(gspca_dev);
  914. rc = spca504B_PollingDataReady(gspca_dev);
  915. }
  916. break;
  917. case BRIDGE_SPCA504:
  918. if (sd->subtype == AiptekMiniPenCam13) {
  919. for (i = 0; i < 6; i++)
  920. info[i] = reg_r_1(gspca_dev, i);
  921. PDEBUG(D_STREAM,
  922. "Read info: %d %d %d %d %d %d."
  923. " Should be 1,0,2,2,0,0",
  924. info[0], info[1], info[2],
  925. info[3], info[4], info[5]);
  926. /* spca504a aiptek */
  927. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  928. spca504A_acknowledged_command(gspca_dev, 0x24,
  929. 8, 3, 0x9e, 1);
  930. /* Twice sequencial need status 0xff->0x9e->0x9d */
  931. spca504A_acknowledged_command(gspca_dev, 0x24,
  932. 8, 3, 0x9e, 0);
  933. spca504A_acknowledged_command(gspca_dev, 0x24,
  934. 0, 0, 0x9d, 1);
  935. } else {
  936. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  937. for (i = 0; i < 6; i++)
  938. info[i] = reg_r_1(gspca_dev, i);
  939. PDEBUG(D_STREAM,
  940. "Read info: %d %d %d %d %d %d."
  941. " Should be 1,0,2,2,0,0",
  942. info[0], info[1], info[2],
  943. info[3], info[4], info[5]);
  944. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  945. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  946. }
  947. spca504B_SetSizeType(gspca_dev);
  948. reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
  949. reg_w_riv(dev, 0x0, 0x2310, 0x05);
  950. break;
  951. case BRIDGE_SPCA504C:
  952. if (sd->subtype == LogitechClickSmart420) {
  953. write_vector(gspca_dev,
  954. spca504A_clicksmart420_init_data);
  955. } else {
  956. write_vector(gspca_dev, spca504_pccam600_init_data);
  957. }
  958. enable = (sd->autogain ? 0x04 : 0x01);
  959. reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */
  960. reg_w_riv(dev, 0xb0, 0x0000, enable); /* auto whiteness */
  961. /* set default exposure compensation and whiteness balance */
  962. reg_w_riv(dev, 0x30, 0x0001, 800); /* ~ 20 fps */
  963. reg_w_riv(dev, 0x30, 0x0002, 1600);
  964. spca504B_SetSizeType(gspca_dev);
  965. break;
  966. }
  967. sp5xx_initContBrigHueRegisters(gspca_dev);
  968. return 0;
  969. }
  970. static void sd_stopN(struct gspca_dev *gspca_dev)
  971. {
  972. struct sd *sd = (struct sd *) gspca_dev;
  973. struct usb_device *dev = gspca_dev->dev;
  974. switch (sd->bridge) {
  975. default:
  976. /* case BRIDGE_SPCA533: */
  977. /* case BRIDGE_SPCA536: */
  978. /* case BRIDGE_SPCA504B: */
  979. reg_w(gspca_dev, 0x31, 0, 0, 0);
  980. spca504B_WaitCmdStatus(gspca_dev);
  981. spca504B_PollingDataReady(gspca_dev);
  982. break;
  983. case BRIDGE_SPCA504:
  984. case BRIDGE_SPCA504C:
  985. reg_w_riv(dev, 0x00, 0x2000, 0x0000);
  986. if (sd->subtype == AiptekMiniPenCam13) {
  987. /* spca504a aiptek */
  988. /* spca504A_acknowledged_command(gspca_dev, 0x08,
  989. 6, 0, 0x86, 1); */
  990. spca504A_acknowledged_command(gspca_dev, 0x24,
  991. 0x00, 0x00, 0x9d, 1);
  992. spca504A_acknowledged_command(gspca_dev, 0x01,
  993. 0x0f, 0x00, 0xff, 1);
  994. } else {
  995. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  996. reg_w_riv(dev, 0x01, 0x000f, 0x00);
  997. }
  998. break;
  999. }
  1000. }
  1001. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1002. struct gspca_frame *frame, /* target */
  1003. __u8 *data, /* isoc packet */
  1004. int len) /* iso packet length */
  1005. {
  1006. struct sd *sd = (struct sd *) gspca_dev;
  1007. int i, sof = 0;
  1008. unsigned char *s, *d;
  1009. static unsigned char ffd9[] = {0xff, 0xd9};
  1010. /* frames are jpeg 4.1.1 without 0xff escape */
  1011. switch (sd->bridge) {
  1012. case BRIDGE_SPCA533:
  1013. if (data[0] == 0xff) {
  1014. if (data[1] != 0x01) { /* drop packet */
  1015. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1016. return;
  1017. }
  1018. sof = 1;
  1019. data += SPCA533_OFFSET_DATA;
  1020. len -= SPCA533_OFFSET_DATA;
  1021. } else {
  1022. data += 1;
  1023. len -= 1;
  1024. }
  1025. break;
  1026. case BRIDGE_SPCA536:
  1027. if (data[0] == 0xff) {
  1028. sof = 1;
  1029. data += SPCA536_OFFSET_DATA;
  1030. len -= SPCA536_OFFSET_DATA;
  1031. } else {
  1032. data += 2;
  1033. len -= 2;
  1034. }
  1035. break;
  1036. default:
  1037. /* case BRIDGE_SPCA504: */
  1038. /* case BRIDGE_SPCA504B: */
  1039. switch (data[0]) {
  1040. case 0xfe: /* start of frame */
  1041. sof = 1;
  1042. data += SPCA50X_OFFSET_DATA;
  1043. len -= SPCA50X_OFFSET_DATA;
  1044. break;
  1045. case 0xff: /* drop packet */
  1046. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1047. return;
  1048. default:
  1049. data += 1;
  1050. len -= 1;
  1051. break;
  1052. }
  1053. break;
  1054. case BRIDGE_SPCA504C:
  1055. switch (data[0]) {
  1056. case 0xfe: /* start of frame */
  1057. sof = 1;
  1058. data += SPCA504_PCCAM600_OFFSET_DATA;
  1059. len -= SPCA504_PCCAM600_OFFSET_DATA;
  1060. break;
  1061. case 0xff: /* drop packet */
  1062. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  1063. return;
  1064. default:
  1065. data += 1;
  1066. len -= 1;
  1067. break;
  1068. }
  1069. break;
  1070. }
  1071. if (sof) { /* start of frame */
  1072. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  1073. ffd9, 2);
  1074. /* put the JPEG header in the new frame */
  1075. jpeg_put_header(gspca_dev, frame, 0x22);
  1076. }
  1077. /* add 0x00 after 0xff */
  1078. for (i = len; --i >= 0; )
  1079. if (data[i] == 0xff)
  1080. break;
  1081. if (i < 0) { /* no 0xff */
  1082. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  1083. return;
  1084. }
  1085. s = data;
  1086. d = sd->packet;
  1087. for (i = 0; i < len; i++) {
  1088. *d++ = *s++;
  1089. if (s[-1] == 0xff)
  1090. *d++ = 0x00;
  1091. }
  1092. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  1093. sd->packet, d - sd->packet);
  1094. }
  1095. static void setbrightness(struct gspca_dev *gspca_dev)
  1096. {
  1097. struct sd *sd = (struct sd *) gspca_dev;
  1098. struct usb_device *dev = gspca_dev->dev;
  1099. switch (sd->bridge) {
  1100. default:
  1101. /* case BRIDGE_SPCA533: */
  1102. /* case BRIDGE_SPCA504B: */
  1103. /* case BRIDGE_SPCA504: */
  1104. /* case BRIDGE_SPCA504C: */
  1105. reg_w_riv(dev, 0x0, 0x21a7, sd->brightness);
  1106. break;
  1107. case BRIDGE_SPCA536:
  1108. reg_w_riv(dev, 0x0, 0x20f0, sd->brightness);
  1109. break;
  1110. }
  1111. }
  1112. static void getbrightness(struct gspca_dev *gspca_dev)
  1113. {
  1114. struct sd *sd = (struct sd *) gspca_dev;
  1115. __u16 brightness = 0;
  1116. switch (sd->bridge) {
  1117. default:
  1118. /* case BRIDGE_SPCA533: */
  1119. /* case BRIDGE_SPCA504B: */
  1120. /* case BRIDGE_SPCA504: */
  1121. /* case BRIDGE_SPCA504C: */
  1122. brightness = reg_r_12(gspca_dev, 0x00, 0x21a7, 2);
  1123. break;
  1124. case BRIDGE_SPCA536:
  1125. brightness = reg_r_12(gspca_dev, 0x00, 0x20f0, 2);
  1126. break;
  1127. }
  1128. sd->brightness = ((brightness & 0xff) - 128) % 255;
  1129. }
  1130. static void setcontrast(struct gspca_dev *gspca_dev)
  1131. {
  1132. struct sd *sd = (struct sd *) gspca_dev;
  1133. struct usb_device *dev = gspca_dev->dev;
  1134. switch (sd->bridge) {
  1135. default:
  1136. /* case BRIDGE_SPCA533: */
  1137. /* case BRIDGE_SPCA504B: */
  1138. /* case BRIDGE_SPCA504: */
  1139. /* case BRIDGE_SPCA504C: */
  1140. reg_w_riv(dev, 0x0, 0x21a8, sd->contrast);
  1141. break;
  1142. case BRIDGE_SPCA536:
  1143. reg_w_riv(dev, 0x0, 0x20f1, sd->contrast);
  1144. break;
  1145. }
  1146. }
  1147. static void getcontrast(struct gspca_dev *gspca_dev)
  1148. {
  1149. struct sd *sd = (struct sd *) gspca_dev;
  1150. switch (sd->bridge) {
  1151. default:
  1152. /* case BRIDGE_SPCA533: */
  1153. /* case BRIDGE_SPCA504B: */
  1154. /* case BRIDGE_SPCA504: */
  1155. /* case BRIDGE_SPCA504C: */
  1156. sd->contrast = reg_r_12(gspca_dev, 0x00, 0x21a8, 2);
  1157. break;
  1158. case BRIDGE_SPCA536:
  1159. sd->contrast = reg_r_12(gspca_dev, 0x00, 0x20f1, 2);
  1160. break;
  1161. }
  1162. }
  1163. static void setcolors(struct gspca_dev *gspca_dev)
  1164. {
  1165. struct sd *sd = (struct sd *) gspca_dev;
  1166. struct usb_device *dev = gspca_dev->dev;
  1167. switch (sd->bridge) {
  1168. default:
  1169. /* case BRIDGE_SPCA533: */
  1170. /* case BRIDGE_SPCA504B: */
  1171. /* case BRIDGE_SPCA504: */
  1172. /* case BRIDGE_SPCA504C: */
  1173. reg_w_riv(dev, 0x0, 0x21ae, sd->colors);
  1174. break;
  1175. case BRIDGE_SPCA536:
  1176. reg_w_riv(dev, 0x0, 0x20f6, sd->colors);
  1177. break;
  1178. }
  1179. }
  1180. static void getcolors(struct gspca_dev *gspca_dev)
  1181. {
  1182. struct sd *sd = (struct sd *) gspca_dev;
  1183. switch (sd->bridge) {
  1184. default:
  1185. /* case BRIDGE_SPCA533: */
  1186. /* case BRIDGE_SPCA504B: */
  1187. /* case BRIDGE_SPCA504: */
  1188. /* case BRIDGE_SPCA504C: */
  1189. sd->colors = reg_r_12(gspca_dev, 0x00, 0x21ae, 2) >> 1;
  1190. break;
  1191. case BRIDGE_SPCA536:
  1192. sd->colors = reg_r_12(gspca_dev, 0x00, 0x20f6, 2) >> 1;
  1193. break;
  1194. }
  1195. }
  1196. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1197. {
  1198. struct sd *sd = (struct sd *) gspca_dev;
  1199. sd->brightness = val;
  1200. if (gspca_dev->streaming)
  1201. setbrightness(gspca_dev);
  1202. return 0;
  1203. }
  1204. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1205. {
  1206. struct sd *sd = (struct sd *) gspca_dev;
  1207. getbrightness(gspca_dev);
  1208. *val = sd->brightness;
  1209. return 0;
  1210. }
  1211. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1212. {
  1213. struct sd *sd = (struct sd *) gspca_dev;
  1214. sd->contrast = val;
  1215. if (gspca_dev->streaming)
  1216. setcontrast(gspca_dev);
  1217. return 0;
  1218. }
  1219. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1220. {
  1221. struct sd *sd = (struct sd *) gspca_dev;
  1222. getcontrast(gspca_dev);
  1223. *val = sd->contrast;
  1224. return 0;
  1225. }
  1226. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1227. {
  1228. struct sd *sd = (struct sd *) gspca_dev;
  1229. sd->colors = val;
  1230. if (gspca_dev->streaming)
  1231. setcolors(gspca_dev);
  1232. return 0;
  1233. }
  1234. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1235. {
  1236. struct sd *sd = (struct sd *) gspca_dev;
  1237. getcolors(gspca_dev);
  1238. *val = sd->colors;
  1239. return 0;
  1240. }
  1241. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1242. {
  1243. struct sd *sd = (struct sd *) gspca_dev;
  1244. sd->autogain = val;
  1245. return 0;
  1246. }
  1247. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1248. {
  1249. struct sd *sd = (struct sd *) gspca_dev;
  1250. *val = sd->autogain;
  1251. return 0;
  1252. }
  1253. /* sub-driver description */
  1254. static const struct sd_desc sd_desc = {
  1255. .name = MODULE_NAME,
  1256. .ctrls = sd_ctrls,
  1257. .nctrls = ARRAY_SIZE(sd_ctrls),
  1258. .config = sd_config,
  1259. .init = sd_init,
  1260. .start = sd_start,
  1261. .stopN = sd_stopN,
  1262. .pkt_scan = sd_pkt_scan,
  1263. };
  1264. /* -- module initialisation -- */
  1265. #define BS(bridge, subtype) \
  1266. .driver_info = (BRIDGE_ ## bridge << 8) \
  1267. | (subtype)
  1268. static const __devinitdata struct usb_device_id device_table[] = {
  1269. {USB_DEVICE(0x041e, 0x400b), BS(SPCA504C, 0)},
  1270. {USB_DEVICE(0x041e, 0x4012), BS(SPCA504C, 0)},
  1271. {USB_DEVICE(0x041e, 0x4013), BS(SPCA504C, 0)},
  1272. {USB_DEVICE(0x0458, 0x7006), BS(SPCA504B, 0)},
  1273. {USB_DEVICE(0x0461, 0x0821), BS(SPCA533, 0)},
  1274. {USB_DEVICE(0x046d, 0x0905), BS(SPCA533, LogitechClickSmart820)},
  1275. {USB_DEVICE(0x046d, 0x0960), BS(SPCA504C, LogitechClickSmart420)},
  1276. {USB_DEVICE(0x0471, 0x0322), BS(SPCA504B, 0)},
  1277. {USB_DEVICE(0x04a5, 0x3003), BS(SPCA504B, 0)},
  1278. {USB_DEVICE(0x04a5, 0x3008), BS(SPCA533, 0)},
  1279. {USB_DEVICE(0x04a5, 0x300a), BS(SPCA533, 0)},
  1280. {USB_DEVICE(0x04f1, 0x1001), BS(SPCA504B, 0)},
  1281. {USB_DEVICE(0x04fc, 0x500c), BS(SPCA504B, 0)},
  1282. {USB_DEVICE(0x04fc, 0x504a), BS(SPCA504, AiptekMiniPenCam13)},
  1283. {USB_DEVICE(0x04fc, 0x504b), BS(SPCA504B, 0)},
  1284. {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)},
  1285. {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
  1286. {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
  1287. {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
  1288. {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
  1289. {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)},
  1290. {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)},
  1291. {USB_DEVICE(0x055f, 0xc211), BS(SPCA536, 0)},
  1292. {USB_DEVICE(0x055f, 0xc230), BS(SPCA533, 0)},
  1293. {USB_DEVICE(0x055f, 0xc232), BS(SPCA533, 0)},
  1294. {USB_DEVICE(0x055f, 0xc360), BS(SPCA536, 0)},
  1295. {USB_DEVICE(0x055f, 0xc420), BS(SPCA504, 0)},
  1296. {USB_DEVICE(0x055f, 0xc430), BS(SPCA533, 0)},
  1297. {USB_DEVICE(0x055f, 0xc440), BS(SPCA533, 0)},
  1298. {USB_DEVICE(0x055f, 0xc520), BS(SPCA504, 0)},
  1299. {USB_DEVICE(0x055f, 0xc530), BS(SPCA533, 0)},
  1300. {USB_DEVICE(0x055f, 0xc540), BS(SPCA533, 0)},
  1301. {USB_DEVICE(0x055f, 0xc630), BS(SPCA533, 0)},
  1302. {USB_DEVICE(0x055f, 0xc650), BS(SPCA533, 0)},
  1303. {USB_DEVICE(0x05da, 0x1018), BS(SPCA504B, 0)},
  1304. {USB_DEVICE(0x06d6, 0x0031), BS(SPCA533, 0)},
  1305. {USB_DEVICE(0x0733, 0x1311), BS(SPCA533, 0)},
  1306. {USB_DEVICE(0x0733, 0x1314), BS(SPCA533, 0)},
  1307. {USB_DEVICE(0x0733, 0x2211), BS(SPCA533, 0)},
  1308. {USB_DEVICE(0x0733, 0x2221), BS(SPCA533, 0)},
  1309. {USB_DEVICE(0x0733, 0x3261), BS(SPCA536, 0)},
  1310. {USB_DEVICE(0x0733, 0x3281), BS(SPCA536, 0)},
  1311. {USB_DEVICE(0x08ca, 0x0104), BS(SPCA533, 0)},
  1312. {USB_DEVICE(0x08ca, 0x0106), BS(SPCA533, 0)},
  1313. {USB_DEVICE(0x08ca, 0x2008), BS(SPCA504B, 0)},
  1314. {USB_DEVICE(0x08ca, 0x2010), BS(SPCA533, 0)},
  1315. {USB_DEVICE(0x08ca, 0x2016), BS(SPCA504B, 0)},
  1316. {USB_DEVICE(0x08ca, 0x2018), BS(SPCA504B, 0)},
  1317. {USB_DEVICE(0x08ca, 0x2020), BS(SPCA533, 0)},
  1318. {USB_DEVICE(0x08ca, 0x2022), BS(SPCA533, 0)},
  1319. {USB_DEVICE(0x08ca, 0x2024), BS(SPCA536, 0)},
  1320. {USB_DEVICE(0x08ca, 0x2028), BS(SPCA533, 0)},
  1321. {USB_DEVICE(0x08ca, 0x2040), BS(SPCA536, 0)},
  1322. {USB_DEVICE(0x08ca, 0x2042), BS(SPCA536, 0)},
  1323. {USB_DEVICE(0x08ca, 0x2050), BS(SPCA536, 0)},
  1324. {USB_DEVICE(0x08ca, 0x2060), BS(SPCA536, 0)},
  1325. {USB_DEVICE(0x0d64, 0x0303), BS(SPCA536, 0)},
  1326. {}
  1327. };
  1328. MODULE_DEVICE_TABLE(usb, device_table);
  1329. /* -- device connect -- */
  1330. static int sd_probe(struct usb_interface *intf,
  1331. const struct usb_device_id *id)
  1332. {
  1333. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1334. THIS_MODULE);
  1335. }
  1336. static struct usb_driver sd_driver = {
  1337. .name = MODULE_NAME,
  1338. .id_table = device_table,
  1339. .probe = sd_probe,
  1340. .disconnect = gspca_disconnect,
  1341. #ifdef CONFIG_PM
  1342. .suspend = gspca_suspend,
  1343. .resume = gspca_resume,
  1344. #endif
  1345. };
  1346. /* -- module insert / remove -- */
  1347. static int __init sd_mod_init(void)
  1348. {
  1349. int ret;
  1350. ret = usb_register(&sd_driver);
  1351. if (ret < 0)
  1352. return ret;
  1353. PDEBUG(D_PROBE, "registered");
  1354. return 0;
  1355. }
  1356. static void __exit sd_mod_exit(void)
  1357. {
  1358. usb_deregister(&sd_driver);
  1359. PDEBUG(D_PROBE, "deregistered");
  1360. }
  1361. module_init(sd_mod_init);
  1362. module_exit(sd_mod_exit);