sunplus.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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. s8 brightness;
  31. u8 contrast;
  32. u8 colors;
  33. u8 autogain;
  34. u8 quality;
  35. #define QUALITY_MIN 70
  36. #define QUALITY_MAX 95
  37. #define QUALITY_DEF 85
  38. u8 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. u8 subtype;
  45. #define AiptekMiniPenCam13 1
  46. #define LogitechClickSmart420 2
  47. #define LogitechClickSmart820 3
  48. #define MegapixV4 4
  49. #define MegaImageVI 5
  50. u8 jpeg_hdr[JPEG_HDR_SZ];
  51. };
  52. /* V4L2 controls supported by the driver */
  53. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  54. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  55. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  56. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  57. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  58. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  59. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  60. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  61. static const struct ctrl sd_ctrls[] = {
  62. {
  63. {
  64. .id = V4L2_CID_BRIGHTNESS,
  65. .type = V4L2_CTRL_TYPE_INTEGER,
  66. .name = "Brightness",
  67. .minimum = -128,
  68. .maximum = 127,
  69. .step = 1,
  70. #define BRIGHTNESS_DEF 0
  71. .default_value = BRIGHTNESS_DEF,
  72. },
  73. .set = sd_setbrightness,
  74. .get = sd_getbrightness,
  75. },
  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. #define CONTRAST_DEF 0x20
  85. .default_value = CONTRAST_DEF,
  86. },
  87. .set = sd_setcontrast,
  88. .get = sd_getcontrast,
  89. },
  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. #define COLOR_DEF 0x1a
  99. .default_value = COLOR_DEF,
  100. },
  101. .set = sd_setcolors,
  102. .get = sd_getcolors,
  103. },
  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. #define AUTOGAIN_DEF 1
  113. .default_value = AUTOGAIN_DEF,
  114. },
  115. .set = sd_setautogain,
  116. .get = sd_getautogain,
  117. },
  118. };
  119. static const struct v4l2_pix_format vga_mode[] = {
  120. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  121. .bytesperline = 320,
  122. .sizeimage = 320 * 240 * 3 / 8 + 590,
  123. .colorspace = V4L2_COLORSPACE_JPEG,
  124. .priv = 2},
  125. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  126. .bytesperline = 640,
  127. .sizeimage = 640 * 480 * 3 / 8 + 590,
  128. .colorspace = V4L2_COLORSPACE_JPEG,
  129. .priv = 1},
  130. };
  131. static const struct v4l2_pix_format custom_mode[] = {
  132. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  133. .bytesperline = 320,
  134. .sizeimage = 320 * 240 * 3 / 8 + 590,
  135. .colorspace = V4L2_COLORSPACE_JPEG,
  136. .priv = 2},
  137. {464, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  138. .bytesperline = 464,
  139. .sizeimage = 464 * 480 * 3 / 8 + 590,
  140. .colorspace = V4L2_COLORSPACE_JPEG,
  141. .priv = 1},
  142. };
  143. static const struct v4l2_pix_format vga_mode2[] = {
  144. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  145. .bytesperline = 176,
  146. .sizeimage = 176 * 144 * 3 / 8 + 590,
  147. .colorspace = V4L2_COLORSPACE_JPEG,
  148. .priv = 4},
  149. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  150. .bytesperline = 320,
  151. .sizeimage = 320 * 240 * 3 / 8 + 590,
  152. .colorspace = V4L2_COLORSPACE_JPEG,
  153. .priv = 3},
  154. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  155. .bytesperline = 352,
  156. .sizeimage = 352 * 288 * 3 / 8 + 590,
  157. .colorspace = V4L2_COLORSPACE_JPEG,
  158. .priv = 2},
  159. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  160. .bytesperline = 640,
  161. .sizeimage = 640 * 480 * 3 / 8 + 590,
  162. .colorspace = V4L2_COLORSPACE_JPEG,
  163. .priv = 1},
  164. };
  165. #define SPCA50X_OFFSET_DATA 10
  166. #define SPCA504_PCCAM600_OFFSET_SNAPSHOT 3
  167. #define SPCA504_PCCAM600_OFFSET_COMPRESS 4
  168. #define SPCA504_PCCAM600_OFFSET_MODE 5
  169. #define SPCA504_PCCAM600_OFFSET_DATA 14
  170. /* Frame packet header offsets for the spca533 */
  171. #define SPCA533_OFFSET_DATA 16
  172. #define SPCA533_OFFSET_FRAMSEQ 15
  173. /* Frame packet header offsets for the spca536 */
  174. #define SPCA536_OFFSET_DATA 4
  175. #define SPCA536_OFFSET_FRAMSEQ 1
  176. struct cmd {
  177. u8 req;
  178. u16 val;
  179. u16 idx;
  180. };
  181. /* Initialisation data for the Creative PC-CAM 600 */
  182. static const struct cmd spca504_pccam600_init_data[] = {
  183. /* {0xa0, 0x0000, 0x0503}, * capture mode */
  184. {0x00, 0x0000, 0x2000},
  185. {0x00, 0x0013, 0x2301},
  186. {0x00, 0x0003, 0x2000},
  187. {0x00, 0x0001, 0x21ac},
  188. {0x00, 0x0001, 0x21a6},
  189. {0x00, 0x0000, 0x21a7}, /* brightness */
  190. {0x00, 0x0020, 0x21a8}, /* contrast */
  191. {0x00, 0x0001, 0x21ac}, /* sat/hue */
  192. {0x00, 0x0000, 0x21ad}, /* hue */
  193. {0x00, 0x001a, 0x21ae}, /* saturation */
  194. {0x00, 0x0002, 0x21a3}, /* gamma */
  195. {0x30, 0x0154, 0x0008},
  196. {0x30, 0x0004, 0x0006},
  197. {0x30, 0x0258, 0x0009},
  198. {0x30, 0x0004, 0x0000},
  199. {0x30, 0x0093, 0x0004},
  200. {0x30, 0x0066, 0x0005},
  201. {0x00, 0x0000, 0x2000},
  202. {0x00, 0x0013, 0x2301},
  203. {0x00, 0x0003, 0x2000},
  204. {0x00, 0x0013, 0x2301},
  205. {0x00, 0x0003, 0x2000},
  206. };
  207. /* Creative PC-CAM 600 specific open data, sent before using the
  208. * generic initialisation data from spca504_open_data.
  209. */
  210. static const struct cmd spca504_pccam600_open_data[] = {
  211. {0x00, 0x0001, 0x2501},
  212. {0x20, 0x0500, 0x0001}, /* snapshot mode */
  213. {0x00, 0x0003, 0x2880},
  214. {0x00, 0x0001, 0x2881},
  215. };
  216. /* Initialisation data for the logitech clicksmart 420 */
  217. static const struct cmd spca504A_clicksmart420_init_data[] = {
  218. /* {0xa0, 0x0000, 0x0503}, * capture mode */
  219. {0x00, 0x0000, 0x2000},
  220. {0x00, 0x0013, 0x2301},
  221. {0x00, 0x0003, 0x2000},
  222. {0x00, 0x0001, 0x21ac},
  223. {0x00, 0x0001, 0x21a6},
  224. {0x00, 0x0000, 0x21a7}, /* brightness */
  225. {0x00, 0x0020, 0x21a8}, /* contrast */
  226. {0x00, 0x0001, 0x21ac}, /* sat/hue */
  227. {0x00, 0x0000, 0x21ad}, /* hue */
  228. {0x00, 0x001a, 0x21ae}, /* saturation */
  229. {0x00, 0x0002, 0x21a3}, /* gamma */
  230. {0x30, 0x0004, 0x000a},
  231. {0xb0, 0x0001, 0x0000},
  232. {0xa1, 0x0080, 0x0001},
  233. {0x30, 0x0049, 0x0000},
  234. {0x30, 0x0060, 0x0005},
  235. {0x0c, 0x0004, 0x0000},
  236. {0x00, 0x0000, 0x0000},
  237. {0x00, 0x0000, 0x2000},
  238. {0x00, 0x0013, 0x2301},
  239. {0x00, 0x0003, 0x2000},
  240. {0x00, 0x0000, 0x2000},
  241. };
  242. /* clicksmart 420 open data ? */
  243. static const struct cmd spca504A_clicksmart420_open_data[] = {
  244. {0x00, 0x0001, 0x2501},
  245. {0x20, 0x0502, 0x0000},
  246. {0x06, 0x0000, 0x0000},
  247. {0x00, 0x0004, 0x2880},
  248. {0x00, 0x0001, 0x2881},
  249. {0xa0, 0x0000, 0x0503},
  250. };
  251. static const u8 qtable_creative_pccam[2][64] = {
  252. { /* Q-table Y-components */
  253. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  254. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  255. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  256. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  257. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  258. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  259. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  260. 0x16, 0x1c, 0x1d, 0x1d, 0x22, 0x1e, 0x1f, 0x1e},
  261. { /* Q-table C-components */
  262. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  263. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  264. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  265. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  266. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  267. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  268. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  269. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  270. };
  271. /* FIXME: This Q-table is identical to the Creative PC-CAM one,
  272. * except for one byte. Possibly a typo?
  273. * NWG: 18/05/2003.
  274. */
  275. static const u8 qtable_spca504_default[2][64] = {
  276. { /* Q-table Y-components */
  277. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  278. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  279. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  280. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  281. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  282. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  283. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  284. 0x16, 0x1c, 0x1d, 0x1d, 0x1d /* 0x22 */ , 0x1e, 0x1f, 0x1e,
  285. },
  286. { /* Q-table C-components */
  287. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  288. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  289. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  290. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  291. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  292. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  293. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  294. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  295. };
  296. /* read <len> bytes to gspca_dev->usb_buf */
  297. static void reg_r(struct gspca_dev *gspca_dev,
  298. u8 req,
  299. u16 index,
  300. u16 len)
  301. {
  302. int ret;
  303. #ifdef GSPCA_DEBUG
  304. if (len > USB_BUF_SZ) {
  305. err("reg_r: buffer overflow");
  306. return;
  307. }
  308. #endif
  309. if (gspca_dev->usb_err < 0)
  310. return;
  311. ret = usb_control_msg(gspca_dev->dev,
  312. usb_rcvctrlpipe(gspca_dev->dev, 0),
  313. req,
  314. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  315. 0, /* value */
  316. index,
  317. len ? gspca_dev->usb_buf : NULL, len,
  318. 500);
  319. if (ret < 0) {
  320. err("reg_r err %d", ret);
  321. gspca_dev->usb_err = ret;
  322. }
  323. }
  324. /* write one byte */
  325. static void reg_w_1(struct gspca_dev *gspca_dev,
  326. u8 req,
  327. u16 value,
  328. u16 index,
  329. u16 byte)
  330. {
  331. int ret;
  332. if (gspca_dev->usb_err < 0)
  333. return;
  334. gspca_dev->usb_buf[0] = byte;
  335. ret = usb_control_msg(gspca_dev->dev,
  336. usb_sndctrlpipe(gspca_dev->dev, 0),
  337. req,
  338. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  339. value, index,
  340. gspca_dev->usb_buf, 1,
  341. 500);
  342. if (ret < 0) {
  343. err("reg_w_1 err %d", ret);
  344. gspca_dev->usb_err = ret;
  345. }
  346. }
  347. /* write req / index / value */
  348. static void reg_w_riv(struct gspca_dev *gspca_dev,
  349. u8 req, u16 index, u16 value)
  350. {
  351. struct usb_device *dev = gspca_dev->dev;
  352. int ret;
  353. if (gspca_dev->usb_err < 0)
  354. return;
  355. ret = usb_control_msg(dev,
  356. usb_sndctrlpipe(dev, 0),
  357. req,
  358. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  359. value, index, NULL, 0, 500);
  360. if (ret < 0) {
  361. err("reg_w_riv err %d", ret);
  362. gspca_dev->usb_err = ret;
  363. return;
  364. }
  365. PDEBUG(D_USBO, "reg_w_riv: 0x%02x,0x%04x:0x%04x",
  366. req, index, value);
  367. }
  368. /* read 1 byte */
  369. static u8 reg_r_1(struct gspca_dev *gspca_dev,
  370. u16 value) /* wValue */
  371. {
  372. int ret;
  373. if (gspca_dev->usb_err < 0)
  374. return 0;
  375. ret = usb_control_msg(gspca_dev->dev,
  376. usb_rcvctrlpipe(gspca_dev->dev, 0),
  377. 0x20, /* request */
  378. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  379. value,
  380. 0, /* index */
  381. gspca_dev->usb_buf, 1,
  382. 500); /* timeout */
  383. if (ret < 0) {
  384. err("reg_r_1 err %d", ret);
  385. gspca_dev->usb_err = ret;
  386. return 0;
  387. }
  388. return gspca_dev->usb_buf[0];
  389. }
  390. /* read 1 or 2 bytes */
  391. static u16 reg_r_12(struct gspca_dev *gspca_dev,
  392. u8 req, /* bRequest */
  393. u16 index, /* wIndex */
  394. u16 length) /* wLength (1 or 2 only) */
  395. {
  396. int ret;
  397. if (gspca_dev->usb_err < 0)
  398. return 0;
  399. gspca_dev->usb_buf[1] = 0;
  400. ret = usb_control_msg(gspca_dev->dev,
  401. usb_rcvctrlpipe(gspca_dev->dev, 0),
  402. req,
  403. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  404. 0, /* value */
  405. index,
  406. gspca_dev->usb_buf, length,
  407. 500);
  408. if (ret < 0) {
  409. err("reg_r_12 err %d", ret);
  410. gspca_dev->usb_err = ret;
  411. return 0;
  412. }
  413. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  414. }
  415. static void write_vector(struct gspca_dev *gspca_dev,
  416. const struct cmd *data, int ncmds)
  417. {
  418. while (--ncmds >= 0) {
  419. reg_w_riv(gspca_dev, data->req, data->idx, data->val);
  420. data++;
  421. }
  422. }
  423. static void setup_qtable(struct gspca_dev *gspca_dev,
  424. const u8 qtable[2][64])
  425. {
  426. int i;
  427. /* loop over y components */
  428. for (i = 0; i < 64; i++)
  429. reg_w_riv(gspca_dev, 0x00, 0x2800 + i, qtable[0][i]);
  430. /* loop over c components */
  431. for (i = 0; i < 64; i++)
  432. reg_w_riv(gspca_dev, 0x00, 0x2840 + i, qtable[1][i]);
  433. }
  434. static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
  435. u8 req, u16 idx, u16 val)
  436. {
  437. u16 notdone;
  438. reg_w_riv(gspca_dev, req, idx, val);
  439. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  440. reg_w_riv(gspca_dev, req, idx, val);
  441. PDEBUG(D_FRAM, "before wait 0x%04x", notdone);
  442. msleep(200);
  443. notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  444. PDEBUG(D_FRAM, "after wait 0x%04x", notdone);
  445. }
  446. static void spca504_read_info(struct gspca_dev *gspca_dev)
  447. {
  448. int i;
  449. u8 info[6];
  450. for (i = 0; i < 6; i++)
  451. info[i] = reg_r_1(gspca_dev, i);
  452. PDEBUG(D_STREAM,
  453. "Read info: %d %d %d %d %d %d."
  454. " Should be 1,0,2,2,0,0",
  455. info[0], info[1], info[2],
  456. info[3], info[4], info[5]);
  457. }
  458. static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
  459. u8 req,
  460. u16 idx, u16 val, u16 endcode, u8 count)
  461. {
  462. u16 status;
  463. reg_w_riv(gspca_dev, req, idx, val);
  464. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  465. if (gspca_dev->usb_err < 0)
  466. return;
  467. PDEBUG(D_FRAM, "Status 0x%04x Need 0x%04x", status, endcode);
  468. if (!count)
  469. return;
  470. count = 200;
  471. while (--count > 0) {
  472. msleep(10);
  473. /* gsmart mini2 write a each wait setting 1 ms is enough */
  474. /* reg_w_riv(gspca_dev, req, idx, val); */
  475. status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
  476. if (status == endcode) {
  477. PDEBUG(D_FRAM, "status 0x%04x after wait %d",
  478. status, 200 - count);
  479. break;
  480. }
  481. }
  482. }
  483. static void spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
  484. {
  485. int count = 10;
  486. while (--count > 0) {
  487. reg_r(gspca_dev, 0x21, 0, 1);
  488. if ((gspca_dev->usb_buf[0] & 0x01) == 0)
  489. break;
  490. msleep(10);
  491. }
  492. }
  493. static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
  494. {
  495. int count = 50;
  496. while (--count > 0) {
  497. reg_r(gspca_dev, 0x21, 1, 1);
  498. if (gspca_dev->usb_buf[0] != 0) {
  499. reg_w_1(gspca_dev, 0x21, 0, 1, 0);
  500. reg_r(gspca_dev, 0x21, 1, 1);
  501. spca504B_PollingDataReady(gspca_dev);
  502. break;
  503. }
  504. msleep(10);
  505. }
  506. }
  507. static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
  508. {
  509. u8 *data;
  510. data = gspca_dev->usb_buf;
  511. reg_r(gspca_dev, 0x20, 0, 5);
  512. PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ",
  513. data[0], data[1], data[2], data[3], data[4]);
  514. reg_r(gspca_dev, 0x23, 0, 64);
  515. reg_r(gspca_dev, 0x23, 1, 64);
  516. }
  517. static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
  518. {
  519. struct sd *sd = (struct sd *) gspca_dev;
  520. u8 Size;
  521. Size = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  522. switch (sd->bridge) {
  523. case BRIDGE_SPCA533:
  524. reg_w_riv(gspca_dev, 0x31, 0, 0);
  525. spca504B_WaitCmdStatus(gspca_dev);
  526. spca504B_PollingDataReady(gspca_dev);
  527. spca50x_GetFirmware(gspca_dev);
  528. reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */
  529. reg_r(gspca_dev, 0x24, 8, 1);
  530. reg_w_1(gspca_dev, 0x25, 0, 4, Size);
  531. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  532. spca504B_PollingDataReady(gspca_dev);
  533. /* Init the cam width height with some values get on init ? */
  534. reg_w_riv(gspca_dev, 0x31, 0x0004, 0x00);
  535. spca504B_WaitCmdStatus(gspca_dev);
  536. spca504B_PollingDataReady(gspca_dev);
  537. break;
  538. default:
  539. /* case BRIDGE_SPCA504B: */
  540. /* case BRIDGE_SPCA536: */
  541. reg_w_1(gspca_dev, 0x25, 0, 4, Size);
  542. reg_r(gspca_dev, 0x25, 4, 1); /* size */
  543. reg_w_1(gspca_dev, 0x27, 0, 0, 6);
  544. reg_r(gspca_dev, 0x27, 0, 1); /* type */
  545. spca504B_PollingDataReady(gspca_dev);
  546. break;
  547. case BRIDGE_SPCA504:
  548. Size += 3;
  549. if (sd->subtype == AiptekMiniPenCam13) {
  550. /* spca504a aiptek */
  551. spca504A_acknowledged_command(gspca_dev,
  552. 0x08, Size, 0,
  553. 0x80 | (Size & 0x0f), 1);
  554. spca504A_acknowledged_command(gspca_dev,
  555. 1, 3, 0, 0x9f, 0);
  556. } else {
  557. spca504_acknowledged_command(gspca_dev, 0x08, Size, 0);
  558. }
  559. break;
  560. case BRIDGE_SPCA504C:
  561. /* capture mode */
  562. reg_w_riv(gspca_dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x00);
  563. reg_w_riv(gspca_dev, 0x20, 0x01, 0x0500 | (Size & 0x0f));
  564. break;
  565. }
  566. }
  567. static void spca504_wait_status(struct gspca_dev *gspca_dev)
  568. {
  569. int cnt;
  570. cnt = 256;
  571. while (--cnt > 0) {
  572. /* With this we get the status, when return 0 it's all ok */
  573. if (reg_r_12(gspca_dev, 0x06, 0x00, 1) == 0)
  574. return;
  575. msleep(10);
  576. }
  577. }
  578. static void spca504B_setQtable(struct gspca_dev *gspca_dev)
  579. {
  580. reg_w_1(gspca_dev, 0x26, 0, 0, 3);
  581. reg_r(gspca_dev, 0x26, 0, 1);
  582. spca504B_PollingDataReady(gspca_dev);
  583. }
  584. static void setbrightness(struct gspca_dev *gspca_dev)
  585. {
  586. struct sd *sd = (struct sd *) gspca_dev;
  587. u16 reg;
  588. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
  589. reg_w_riv(gspca_dev, 0x00, reg, sd->brightness);
  590. }
  591. static void setcontrast(struct gspca_dev *gspca_dev)
  592. {
  593. struct sd *sd = (struct sd *) gspca_dev;
  594. u16 reg;
  595. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
  596. reg_w_riv(gspca_dev, 0x00, reg, sd->contrast);
  597. }
  598. static void setcolors(struct gspca_dev *gspca_dev)
  599. {
  600. struct sd *sd = (struct sd *) gspca_dev;
  601. u16 reg;
  602. reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
  603. reg_w_riv(gspca_dev, 0x00, reg, sd->colors);
  604. }
  605. static void init_ctl_reg(struct gspca_dev *gspca_dev)
  606. {
  607. struct sd *sd = (struct sd *) gspca_dev;
  608. int pollreg = 1;
  609. setbrightness(gspca_dev);
  610. setcontrast(gspca_dev);
  611. setcolors(gspca_dev);
  612. switch (sd->bridge) {
  613. case BRIDGE_SPCA504:
  614. case BRIDGE_SPCA504C:
  615. pollreg = 0;
  616. /* fall thru */
  617. default:
  618. /* case BRIDGE_SPCA533: */
  619. /* case BRIDGE_SPCA504B: */
  620. reg_w_riv(gspca_dev, 0, 0x21ad, 0x00); /* hue */
  621. reg_w_riv(gspca_dev, 0, 0x21ac, 0x01); /* sat/hue */
  622. reg_w_riv(gspca_dev, 0, 0x21a3, 0x00); /* gamma */
  623. break;
  624. case BRIDGE_SPCA536:
  625. reg_w_riv(gspca_dev, 0, 0x20f5, 0x40);
  626. reg_w_riv(gspca_dev, 0, 0x20f4, 0x01);
  627. reg_w_riv(gspca_dev, 0, 0x2089, 0x00);
  628. break;
  629. }
  630. if (pollreg)
  631. spca504B_PollingDataReady(gspca_dev);
  632. }
  633. /* this function is called at probe time */
  634. static int sd_config(struct gspca_dev *gspca_dev,
  635. const struct usb_device_id *id)
  636. {
  637. struct sd *sd = (struct sd *) gspca_dev;
  638. struct cam *cam;
  639. cam = &gspca_dev->cam;
  640. sd->bridge = id->driver_info >> 8;
  641. sd->subtype = id->driver_info;
  642. if (sd->subtype == AiptekMiniPenCam13) {
  643. /* try to get the firmware as some cam answer 2.0.1.2.2
  644. * and should be a spca504b then overwrite that setting */
  645. reg_r(gspca_dev, 0x20, 0, 1);
  646. switch (gspca_dev->usb_buf[0]) {
  647. case 1:
  648. break; /* (right bridge/subtype) */
  649. case 2:
  650. sd->bridge = BRIDGE_SPCA504B;
  651. sd->subtype = 0;
  652. break;
  653. default:
  654. return -ENODEV;
  655. }
  656. }
  657. switch (sd->bridge) {
  658. default:
  659. /* case BRIDGE_SPCA504B: */
  660. /* case BRIDGE_SPCA504: */
  661. /* case BRIDGE_SPCA536: */
  662. cam->cam_mode = vga_mode;
  663. cam->nmodes = ARRAY_SIZE(vga_mode);
  664. break;
  665. case BRIDGE_SPCA533:
  666. cam->cam_mode = custom_mode;
  667. if (sd->subtype == MegaImageVI) /* 320x240 only */
  668. cam->nmodes = ARRAY_SIZE(custom_mode) - 1;
  669. else
  670. cam->nmodes = ARRAY_SIZE(custom_mode);
  671. break;
  672. case BRIDGE_SPCA504C:
  673. cam->cam_mode = vga_mode2;
  674. cam->nmodes = ARRAY_SIZE(vga_mode2);
  675. break;
  676. }
  677. sd->brightness = BRIGHTNESS_DEF;
  678. sd->contrast = CONTRAST_DEF;
  679. sd->colors = COLOR_DEF;
  680. sd->autogain = AUTOGAIN_DEF;
  681. sd->quality = QUALITY_DEF;
  682. return 0;
  683. }
  684. /* this function is called at probe and resume time */
  685. static int sd_init(struct gspca_dev *gspca_dev)
  686. {
  687. struct sd *sd = (struct sd *) gspca_dev;
  688. switch (sd->bridge) {
  689. case BRIDGE_SPCA504B:
  690. reg_w_riv(gspca_dev, 0x1d, 0x00, 0);
  691. reg_w_riv(gspca_dev, 0x00, 0x2306, 0x01);
  692. reg_w_riv(gspca_dev, 0x00, 0x0d04, 0x00);
  693. reg_w_riv(gspca_dev, 0x00, 0x2000, 0x00);
  694. reg_w_riv(gspca_dev, 0x00, 0x2301, 0x13);
  695. reg_w_riv(gspca_dev, 0x00, 0x2306, 0x00);
  696. /* fall thru */
  697. case BRIDGE_SPCA533:
  698. spca504B_PollingDataReady(gspca_dev);
  699. spca50x_GetFirmware(gspca_dev);
  700. break;
  701. case BRIDGE_SPCA536:
  702. spca50x_GetFirmware(gspca_dev);
  703. reg_r(gspca_dev, 0x00, 0x5002, 1);
  704. reg_w_1(gspca_dev, 0x24, 0, 0, 0);
  705. reg_r(gspca_dev, 0x24, 0, 1);
  706. spca504B_PollingDataReady(gspca_dev);
  707. reg_w_riv(gspca_dev, 0x34, 0, 0);
  708. spca504B_WaitCmdStatus(gspca_dev);
  709. break;
  710. case BRIDGE_SPCA504C: /* pccam600 */
  711. PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)");
  712. reg_w_riv(gspca_dev, 0xe0, 0x0000, 0x0000);
  713. reg_w_riv(gspca_dev, 0xe0, 0x0000, 0x0001); /* reset */
  714. spca504_wait_status(gspca_dev);
  715. if (sd->subtype == LogitechClickSmart420)
  716. write_vector(gspca_dev,
  717. spca504A_clicksmart420_open_data,
  718. ARRAY_SIZE(spca504A_clicksmart420_open_data));
  719. else
  720. write_vector(gspca_dev, spca504_pccam600_open_data,
  721. ARRAY_SIZE(spca504_pccam600_open_data));
  722. setup_qtable(gspca_dev, qtable_creative_pccam);
  723. break;
  724. default:
  725. /* case BRIDGE_SPCA504: */
  726. PDEBUG(D_STREAM, "Opening SPCA504");
  727. if (sd->subtype == AiptekMiniPenCam13) {
  728. spca504_read_info(gspca_dev);
  729. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  730. spca504A_acknowledged_command(gspca_dev, 0x24,
  731. 8, 3, 0x9e, 1);
  732. /* Twice sequential need status 0xff->0x9e->0x9d */
  733. spca504A_acknowledged_command(gspca_dev, 0x24,
  734. 8, 3, 0x9e, 0);
  735. spca504A_acknowledged_command(gspca_dev, 0x24,
  736. 0, 0, 0x9d, 1);
  737. /******************************/
  738. /* spca504a aiptek */
  739. spca504A_acknowledged_command(gspca_dev, 0x08,
  740. 6, 0, 0x86, 1);
  741. /* reg_write (dev, 0, 0x2000, 0); */
  742. /* reg_write (dev, 0, 0x2883, 1); */
  743. /* spca504A_acknowledged_command (gspca_dev, 0x08,
  744. 6, 0, 0x86, 1); */
  745. /* spca504A_acknowledged_command (gspca_dev, 0x24,
  746. 0, 0, 0x9D, 1); */
  747. reg_w_riv(gspca_dev, 0x00, 0x270c, 0x05);
  748. /* L92 sno1t.txt */
  749. reg_w_riv(gspca_dev, 0x00, 0x2310, 0x05);
  750. spca504A_acknowledged_command(gspca_dev, 0x01,
  751. 0x0f, 0, 0xff, 0);
  752. }
  753. /* setup qtable */
  754. reg_w_riv(gspca_dev, 0, 0x2000, 0);
  755. reg_w_riv(gspca_dev, 0, 0x2883, 1);
  756. setup_qtable(gspca_dev, qtable_spca504_default);
  757. break;
  758. }
  759. return gspca_dev->usb_err;
  760. }
  761. static int sd_start(struct gspca_dev *gspca_dev)
  762. {
  763. struct sd *sd = (struct sd *) gspca_dev;
  764. int enable;
  765. /* create the JPEG header */
  766. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  767. 0x22); /* JPEG 411 */
  768. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  769. if (sd->bridge == BRIDGE_SPCA504B)
  770. spca504B_setQtable(gspca_dev);
  771. spca504B_SetSizeType(gspca_dev);
  772. switch (sd->bridge) {
  773. default:
  774. /* case BRIDGE_SPCA504B: */
  775. /* case BRIDGE_SPCA533: */
  776. /* case BRIDGE_SPCA536: */
  777. switch (sd->subtype) {
  778. case MegapixV4:
  779. case LogitechClickSmart820:
  780. case MegaImageVI:
  781. reg_w_riv(gspca_dev, 0xf0, 0, 0);
  782. spca504B_WaitCmdStatus(gspca_dev);
  783. reg_r(gspca_dev, 0xf0, 4, 0);
  784. spca504B_WaitCmdStatus(gspca_dev);
  785. break;
  786. default:
  787. reg_w_riv(gspca_dev, 0x31, 0x0004, 0x00);
  788. spca504B_WaitCmdStatus(gspca_dev);
  789. spca504B_PollingDataReady(gspca_dev);
  790. break;
  791. }
  792. break;
  793. case BRIDGE_SPCA504:
  794. if (sd->subtype == AiptekMiniPenCam13) {
  795. spca504_read_info(gspca_dev);
  796. /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
  797. spca504A_acknowledged_command(gspca_dev, 0x24,
  798. 8, 3, 0x9e, 1);
  799. /* Twice sequential need status 0xff->0x9e->0x9d */
  800. spca504A_acknowledged_command(gspca_dev, 0x24,
  801. 8, 3, 0x9e, 0);
  802. spca504A_acknowledged_command(gspca_dev, 0x24,
  803. 0, 0, 0x9d, 1);
  804. } else {
  805. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  806. spca504_read_info(gspca_dev);
  807. spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
  808. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  809. }
  810. spca504B_SetSizeType(gspca_dev);
  811. reg_w_riv(gspca_dev, 0x00, 0x270c, 0x05);
  812. /* L92 sno1t.txt */
  813. reg_w_riv(gspca_dev, 0x00, 0x2310, 0x05);
  814. break;
  815. case BRIDGE_SPCA504C:
  816. if (sd->subtype == LogitechClickSmart420) {
  817. write_vector(gspca_dev,
  818. spca504A_clicksmart420_init_data,
  819. ARRAY_SIZE(spca504A_clicksmart420_init_data));
  820. } else {
  821. write_vector(gspca_dev, spca504_pccam600_init_data,
  822. ARRAY_SIZE(spca504_pccam600_init_data));
  823. }
  824. enable = (sd->autogain ? 0x04 : 0x01);
  825. reg_w_riv(gspca_dev, 0x0c, 0x0000, enable);
  826. /* auto exposure */
  827. reg_w_riv(gspca_dev, 0xb0, 0x0000, enable);
  828. /* auto whiteness */
  829. /* set default exposure compensation and whiteness balance */
  830. reg_w_riv(gspca_dev, 0x30, 0x0001, 800); /* ~ 20 fps */
  831. reg_w_riv(gspca_dev, 0x30, 0x0002, 1600);
  832. spca504B_SetSizeType(gspca_dev);
  833. break;
  834. }
  835. init_ctl_reg(gspca_dev);
  836. return gspca_dev->usb_err;
  837. }
  838. static void sd_stopN(struct gspca_dev *gspca_dev)
  839. {
  840. struct sd *sd = (struct sd *) gspca_dev;
  841. switch (sd->bridge) {
  842. default:
  843. /* case BRIDGE_SPCA533: */
  844. /* case BRIDGE_SPCA536: */
  845. /* case BRIDGE_SPCA504B: */
  846. reg_w_riv(gspca_dev, 0x31, 0, 0);
  847. spca504B_WaitCmdStatus(gspca_dev);
  848. spca504B_PollingDataReady(gspca_dev);
  849. break;
  850. case BRIDGE_SPCA504:
  851. case BRIDGE_SPCA504C:
  852. reg_w_riv(gspca_dev, 0x00, 0x2000, 0x0000);
  853. if (sd->subtype == AiptekMiniPenCam13) {
  854. /* spca504a aiptek */
  855. /* spca504A_acknowledged_command(gspca_dev, 0x08,
  856. 6, 0, 0x86, 1); */
  857. spca504A_acknowledged_command(gspca_dev, 0x24,
  858. 0x00, 0x00, 0x9d, 1);
  859. spca504A_acknowledged_command(gspca_dev, 0x01,
  860. 0x0f, 0x00, 0xff, 1);
  861. } else {
  862. spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
  863. reg_w_riv(gspca_dev, 0x01, 0x000f, 0x0000);
  864. }
  865. break;
  866. }
  867. }
  868. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  869. u8 *data, /* isoc packet */
  870. int len) /* iso packet length */
  871. {
  872. struct sd *sd = (struct sd *) gspca_dev;
  873. int i, sof = 0;
  874. static u8 ffd9[] = {0xff, 0xd9};
  875. /* frames are jpeg 4.1.1 without 0xff escape */
  876. switch (sd->bridge) {
  877. case BRIDGE_SPCA533:
  878. if (data[0] == 0xff) {
  879. if (data[1] != 0x01) { /* drop packet */
  880. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  881. return;
  882. }
  883. sof = 1;
  884. data += SPCA533_OFFSET_DATA;
  885. len -= SPCA533_OFFSET_DATA;
  886. } else {
  887. data += 1;
  888. len -= 1;
  889. }
  890. break;
  891. case BRIDGE_SPCA536:
  892. if (data[0] == 0xff) {
  893. sof = 1;
  894. data += SPCA536_OFFSET_DATA;
  895. len -= SPCA536_OFFSET_DATA;
  896. } else {
  897. data += 2;
  898. len -= 2;
  899. }
  900. break;
  901. default:
  902. /* case BRIDGE_SPCA504: */
  903. /* case BRIDGE_SPCA504B: */
  904. switch (data[0]) {
  905. case 0xfe: /* start of frame */
  906. sof = 1;
  907. data += SPCA50X_OFFSET_DATA;
  908. len -= SPCA50X_OFFSET_DATA;
  909. break;
  910. case 0xff: /* drop packet */
  911. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  912. return;
  913. default:
  914. data += 1;
  915. len -= 1;
  916. break;
  917. }
  918. break;
  919. case BRIDGE_SPCA504C:
  920. switch (data[0]) {
  921. case 0xfe: /* start of frame */
  922. sof = 1;
  923. data += SPCA504_PCCAM600_OFFSET_DATA;
  924. len -= SPCA504_PCCAM600_OFFSET_DATA;
  925. break;
  926. case 0xff: /* drop packet */
  927. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  928. return;
  929. default:
  930. data += 1;
  931. len -= 1;
  932. break;
  933. }
  934. break;
  935. }
  936. if (sof) { /* start of frame */
  937. gspca_frame_add(gspca_dev, LAST_PACKET,
  938. ffd9, 2);
  939. /* put the JPEG header in the new frame */
  940. gspca_frame_add(gspca_dev, FIRST_PACKET,
  941. sd->jpeg_hdr, JPEG_HDR_SZ);
  942. }
  943. /* add 0x00 after 0xff */
  944. i = 0;
  945. do {
  946. if (data[i] == 0xff) {
  947. gspca_frame_add(gspca_dev, INTER_PACKET,
  948. data, i + 1);
  949. len -= i;
  950. data += i;
  951. *data = 0x00;
  952. i = 0;
  953. }
  954. i++;
  955. } while (i < len);
  956. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  957. }
  958. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  959. {
  960. struct sd *sd = (struct sd *) gspca_dev;
  961. sd->brightness = val;
  962. if (gspca_dev->streaming)
  963. setbrightness(gspca_dev);
  964. return gspca_dev->usb_err;
  965. }
  966. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  967. {
  968. struct sd *sd = (struct sd *) gspca_dev;
  969. *val = sd->brightness;
  970. return 0;
  971. }
  972. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  973. {
  974. struct sd *sd = (struct sd *) gspca_dev;
  975. sd->contrast = val;
  976. if (gspca_dev->streaming)
  977. setcontrast(gspca_dev);
  978. return gspca_dev->usb_err;
  979. }
  980. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  981. {
  982. struct sd *sd = (struct sd *) gspca_dev;
  983. *val = sd->contrast;
  984. return 0;
  985. }
  986. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  987. {
  988. struct sd *sd = (struct sd *) gspca_dev;
  989. sd->colors = val;
  990. if (gspca_dev->streaming)
  991. setcolors(gspca_dev);
  992. return gspca_dev->usb_err;
  993. }
  994. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  995. {
  996. struct sd *sd = (struct sd *) gspca_dev;
  997. *val = sd->colors;
  998. return 0;
  999. }
  1000. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1001. {
  1002. struct sd *sd = (struct sd *) gspca_dev;
  1003. sd->autogain = val;
  1004. return 0;
  1005. }
  1006. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1007. {
  1008. struct sd *sd = (struct sd *) gspca_dev;
  1009. *val = sd->autogain;
  1010. return 0;
  1011. }
  1012. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  1013. struct v4l2_jpegcompression *jcomp)
  1014. {
  1015. struct sd *sd = (struct sd *) gspca_dev;
  1016. if (jcomp->quality < QUALITY_MIN)
  1017. sd->quality = QUALITY_MIN;
  1018. else if (jcomp->quality > QUALITY_MAX)
  1019. sd->quality = QUALITY_MAX;
  1020. else
  1021. sd->quality = jcomp->quality;
  1022. if (gspca_dev->streaming)
  1023. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  1024. return gspca_dev->usb_err;
  1025. }
  1026. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  1027. struct v4l2_jpegcompression *jcomp)
  1028. {
  1029. struct sd *sd = (struct sd *) gspca_dev;
  1030. memset(jcomp, 0, sizeof *jcomp);
  1031. jcomp->quality = sd->quality;
  1032. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  1033. | V4L2_JPEG_MARKER_DQT;
  1034. return 0;
  1035. }
  1036. /* sub-driver description */
  1037. static const struct sd_desc sd_desc = {
  1038. .name = MODULE_NAME,
  1039. .ctrls = sd_ctrls,
  1040. .nctrls = ARRAY_SIZE(sd_ctrls),
  1041. .config = sd_config,
  1042. .init = sd_init,
  1043. .start = sd_start,
  1044. .stopN = sd_stopN,
  1045. .pkt_scan = sd_pkt_scan,
  1046. .get_jcomp = sd_get_jcomp,
  1047. .set_jcomp = sd_set_jcomp,
  1048. };
  1049. /* -- module initialisation -- */
  1050. #define BS(bridge, subtype) \
  1051. .driver_info = (BRIDGE_ ## bridge << 8) \
  1052. | (subtype)
  1053. static const struct usb_device_id device_table[] = {
  1054. {USB_DEVICE(0x041e, 0x400b), BS(SPCA504C, 0)},
  1055. {USB_DEVICE(0x041e, 0x4012), BS(SPCA504C, 0)},
  1056. {USB_DEVICE(0x041e, 0x4013), BS(SPCA504C, 0)},
  1057. {USB_DEVICE(0x0458, 0x7006), BS(SPCA504B, 0)},
  1058. {USB_DEVICE(0x0461, 0x0821), BS(SPCA533, 0)},
  1059. {USB_DEVICE(0x046d, 0x0905), BS(SPCA533, LogitechClickSmart820)},
  1060. {USB_DEVICE(0x046d, 0x0960), BS(SPCA504C, LogitechClickSmart420)},
  1061. {USB_DEVICE(0x0471, 0x0322), BS(SPCA504B, 0)},
  1062. {USB_DEVICE(0x04a5, 0x3003), BS(SPCA504B, 0)},
  1063. {USB_DEVICE(0x04a5, 0x3008), BS(SPCA533, 0)},
  1064. {USB_DEVICE(0x04a5, 0x300a), BS(SPCA533, 0)},
  1065. {USB_DEVICE(0x04f1, 0x1001), BS(SPCA504B, 0)},
  1066. {USB_DEVICE(0x04fc, 0x500c), BS(SPCA504B, 0)},
  1067. {USB_DEVICE(0x04fc, 0x504a), BS(SPCA504, AiptekMiniPenCam13)},
  1068. {USB_DEVICE(0x04fc, 0x504b), BS(SPCA504B, 0)},
  1069. {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)},
  1070. {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
  1071. {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
  1072. {USB_DEVICE(0x052b, 0x1507), BS(SPCA533, MegapixV4)},
  1073. {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
  1074. {USB_DEVICE(0x052b, 0x1803), BS(SPCA533, MegaImageVI)},
  1075. {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
  1076. {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)},
  1077. {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)},
  1078. {USB_DEVICE(0x055f, 0xc211), BS(SPCA536, 0)},
  1079. {USB_DEVICE(0x055f, 0xc230), BS(SPCA533, 0)},
  1080. {USB_DEVICE(0x055f, 0xc232), BS(SPCA533, 0)},
  1081. {USB_DEVICE(0x055f, 0xc360), BS(SPCA536, 0)},
  1082. {USB_DEVICE(0x055f, 0xc420), BS(SPCA504, 0)},
  1083. {USB_DEVICE(0x055f, 0xc430), BS(SPCA533, 0)},
  1084. {USB_DEVICE(0x055f, 0xc440), BS(SPCA533, 0)},
  1085. {USB_DEVICE(0x055f, 0xc520), BS(SPCA504, 0)},
  1086. {USB_DEVICE(0x055f, 0xc530), BS(SPCA533, 0)},
  1087. {USB_DEVICE(0x055f, 0xc540), BS(SPCA533, 0)},
  1088. {USB_DEVICE(0x055f, 0xc630), BS(SPCA533, 0)},
  1089. {USB_DEVICE(0x055f, 0xc650), BS(SPCA533, 0)},
  1090. {USB_DEVICE(0x05da, 0x1018), BS(SPCA504B, 0)},
  1091. {USB_DEVICE(0x06d6, 0x0031), BS(SPCA533, 0)},
  1092. {USB_DEVICE(0x0733, 0x1311), BS(SPCA533, 0)},
  1093. {USB_DEVICE(0x0733, 0x1314), BS(SPCA533, 0)},
  1094. {USB_DEVICE(0x0733, 0x2211), BS(SPCA533, 0)},
  1095. {USB_DEVICE(0x0733, 0x2221), BS(SPCA533, 0)},
  1096. {USB_DEVICE(0x0733, 0x3261), BS(SPCA536, 0)},
  1097. {USB_DEVICE(0x0733, 0x3281), BS(SPCA536, 0)},
  1098. {USB_DEVICE(0x08ca, 0x0104), BS(SPCA533, 0)},
  1099. {USB_DEVICE(0x08ca, 0x0106), BS(SPCA533, 0)},
  1100. {USB_DEVICE(0x08ca, 0x2008), BS(SPCA504B, 0)},
  1101. {USB_DEVICE(0x08ca, 0x2010), BS(SPCA533, 0)},
  1102. {USB_DEVICE(0x08ca, 0x2016), BS(SPCA504B, 0)},
  1103. {USB_DEVICE(0x08ca, 0x2018), BS(SPCA504B, 0)},
  1104. {USB_DEVICE(0x08ca, 0x2020), BS(SPCA533, 0)},
  1105. {USB_DEVICE(0x08ca, 0x2022), BS(SPCA533, 0)},
  1106. {USB_DEVICE(0x08ca, 0x2024), BS(SPCA536, 0)},
  1107. {USB_DEVICE(0x08ca, 0x2028), BS(SPCA533, 0)},
  1108. {USB_DEVICE(0x08ca, 0x2040), BS(SPCA536, 0)},
  1109. {USB_DEVICE(0x08ca, 0x2042), BS(SPCA536, 0)},
  1110. {USB_DEVICE(0x08ca, 0x2050), BS(SPCA536, 0)},
  1111. {USB_DEVICE(0x08ca, 0x2060), BS(SPCA536, 0)},
  1112. {USB_DEVICE(0x0d64, 0x0303), BS(SPCA536, 0)},
  1113. {}
  1114. };
  1115. MODULE_DEVICE_TABLE(usb, device_table);
  1116. /* -- device connect -- */
  1117. static int sd_probe(struct usb_interface *intf,
  1118. const struct usb_device_id *id)
  1119. {
  1120. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1121. THIS_MODULE);
  1122. }
  1123. static struct usb_driver sd_driver = {
  1124. .name = MODULE_NAME,
  1125. .id_table = device_table,
  1126. .probe = sd_probe,
  1127. .disconnect = gspca_disconnect,
  1128. #ifdef CONFIG_PM
  1129. .suspend = gspca_suspend,
  1130. .resume = gspca_resume,
  1131. #endif
  1132. };
  1133. /* -- module insert / remove -- */
  1134. static int __init sd_mod_init(void)
  1135. {
  1136. return usb_register(&sd_driver);
  1137. }
  1138. static void __exit sd_mod_exit(void)
  1139. {
  1140. usb_deregister(&sd_driver);
  1141. }
  1142. module_init(sd_mod_init);
  1143. module_exit(sd_mod_exit);