spca500.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. /*
  2. * SPCA500 chip based cameras initialization data
  3. *
  4. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #define MODULE_NAME "spca500"
  22. #include "gspca.h"
  23. #include "jpeg.h"
  24. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  25. MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver");
  26. MODULE_LICENSE("GPL");
  27. /* specific webcam descriptor */
  28. struct sd {
  29. struct gspca_dev gspca_dev; /* !! must be the first item */
  30. __u8 packet[ISO_MAX_SIZE + 128];
  31. /* !! no more than 128 ff in an ISO packet */
  32. unsigned char brightness;
  33. unsigned char contrast;
  34. unsigned char colors;
  35. u8 quality;
  36. #define QUALITY_MIN 70
  37. #define QUALITY_MAX 95
  38. #define QUALITY_DEF 85
  39. char subtype;
  40. #define AgfaCl20 0
  41. #define AiptekPocketDV 1
  42. #define BenqDC1016 2
  43. #define CreativePCCam300 3
  44. #define DLinkDSC350 4
  45. #define Gsmartmini 5
  46. #define IntelPocketPCCamera 6
  47. #define KodakEZ200 7
  48. #define LogitechClickSmart310 8
  49. #define LogitechClickSmart510 9
  50. #define LogitechTraveler 10
  51. #define MustekGsmart300 11
  52. #define Optimedia 12
  53. #define PalmPixDC85 13
  54. #define ToptroIndus 14
  55. u8 *jpeg_hdr;
  56. };
  57. /* V4L2 controls supported by the driver */
  58. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  59. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  60. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  61. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  62. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  63. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  64. static struct ctrl sd_ctrls[] = {
  65. {
  66. {
  67. .id = V4L2_CID_BRIGHTNESS,
  68. .type = V4L2_CTRL_TYPE_INTEGER,
  69. .name = "Brightness",
  70. .minimum = 0,
  71. .maximum = 255,
  72. .step = 1,
  73. #define BRIGHTNESS_DEF 127
  74. .default_value = BRIGHTNESS_DEF,
  75. },
  76. .set = sd_setbrightness,
  77. .get = sd_getbrightness,
  78. },
  79. {
  80. {
  81. .id = V4L2_CID_CONTRAST,
  82. .type = V4L2_CTRL_TYPE_INTEGER,
  83. .name = "Contrast",
  84. .minimum = 0,
  85. .maximum = 63,
  86. .step = 1,
  87. #define CONTRAST_DEF 31
  88. .default_value = CONTRAST_DEF,
  89. },
  90. .set = sd_setcontrast,
  91. .get = sd_getcontrast,
  92. },
  93. {
  94. {
  95. .id = V4L2_CID_SATURATION,
  96. .type = V4L2_CTRL_TYPE_INTEGER,
  97. .name = "Color",
  98. .minimum = 0,
  99. .maximum = 63,
  100. .step = 1,
  101. #define COLOR_DEF 31
  102. .default_value = COLOR_DEF,
  103. },
  104. .set = sd_setcolors,
  105. .get = sd_getcolors,
  106. },
  107. };
  108. static const struct v4l2_pix_format vga_mode[] = {
  109. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  110. .bytesperline = 320,
  111. .sizeimage = 320 * 240 * 3 / 8 + 590,
  112. .colorspace = V4L2_COLORSPACE_JPEG,
  113. .priv = 1},
  114. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  115. .bytesperline = 640,
  116. .sizeimage = 640 * 480 * 3 / 8 + 590,
  117. .colorspace = V4L2_COLORSPACE_JPEG,
  118. .priv = 0},
  119. };
  120. static const struct v4l2_pix_format sif_mode[] = {
  121. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  122. .bytesperline = 176,
  123. .sizeimage = 176 * 144 * 3 / 8 + 590,
  124. .colorspace = V4L2_COLORSPACE_JPEG,
  125. .priv = 1},
  126. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  127. .bytesperline = 352,
  128. .sizeimage = 352 * 288 * 3 / 8 + 590,
  129. .colorspace = V4L2_COLORSPACE_JPEG,
  130. .priv = 0},
  131. };
  132. /* Frame packet header offsets for the spca500 */
  133. #define SPCA500_OFFSET_PADDINGLB 2
  134. #define SPCA500_OFFSET_PADDINGHB 3
  135. #define SPCA500_OFFSET_MODE 4
  136. #define SPCA500_OFFSET_IMGWIDTH 5
  137. #define SPCA500_OFFSET_IMGHEIGHT 6
  138. #define SPCA500_OFFSET_IMGMODE 7
  139. #define SPCA500_OFFSET_QTBLINDEX 8
  140. #define SPCA500_OFFSET_FRAMSEQ 9
  141. #define SPCA500_OFFSET_CDSPINFO 10
  142. #define SPCA500_OFFSET_GPIO 11
  143. #define SPCA500_OFFSET_AUGPIO 12
  144. #define SPCA500_OFFSET_DATA 16
  145. static const __u16 spca500_visual_defaults[][3] = {
  146. {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync,
  147. * hue (H byte) = 0,
  148. * saturation/hue enable,
  149. * brightness/contrast enable.
  150. */
  151. {0x00, 0x0000, 0x8167}, /* brightness = 0 */
  152. {0x00, 0x0020, 0x8168}, /* contrast = 0 */
  153. {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync,
  154. * hue (H byte) = 0, saturation/hue enable,
  155. * brightness/contrast enable.
  156. * was 0x0003, now 0x0000.
  157. */
  158. {0x00, 0x0000, 0x816a}, /* hue (L byte) = 0 */
  159. {0x00, 0x0020, 0x8169}, /* saturation = 0x20 */
  160. {0x00, 0x0050, 0x8157}, /* edge gain high threshold */
  161. {0x00, 0x0030, 0x8158}, /* edge gain low threshold */
  162. {0x00, 0x0028, 0x8159}, /* edge bandwidth high threshold */
  163. {0x00, 0x000a, 0x815a}, /* edge bandwidth low threshold */
  164. {0x00, 0x0001, 0x8202}, /* clock rate compensation = 1/25 sec/frame */
  165. {0x0c, 0x0004, 0x0000},
  166. /* set interface */
  167. {}
  168. };
  169. static const __u16 Clicksmart510_defaults[][3] = {
  170. {0x00, 0x00, 0x8211},
  171. {0x00, 0x01, 0x82c0},
  172. {0x00, 0x10, 0x82cb},
  173. {0x00, 0x0f, 0x800d},
  174. {0x00, 0x82, 0x8225},
  175. {0x00, 0x21, 0x8228},
  176. {0x00, 0x00, 0x8203},
  177. {0x00, 0x00, 0x8204},
  178. {0x00, 0x08, 0x8205},
  179. {0x00, 0xf8, 0x8206},
  180. {0x00, 0x28, 0x8207},
  181. {0x00, 0xa0, 0x8208},
  182. {0x00, 0x08, 0x824a},
  183. {0x00, 0x08, 0x8214},
  184. {0x00, 0x80, 0x82c1},
  185. {0x00, 0x00, 0x82c2},
  186. {0x00, 0x00, 0x82ca},
  187. {0x00, 0x80, 0x82c1},
  188. {0x00, 0x04, 0x82c2},
  189. {0x00, 0x00, 0x82ca},
  190. {0x00, 0xfc, 0x8100},
  191. {0x00, 0xfc, 0x8105},
  192. {0x00, 0x30, 0x8101},
  193. {0x00, 0x00, 0x8102},
  194. {0x00, 0x00, 0x8103},
  195. {0x00, 0x66, 0x8107},
  196. {0x00, 0x00, 0x816b},
  197. {0x00, 0x00, 0x8155},
  198. {0x00, 0x01, 0x8156},
  199. {0x00, 0x60, 0x8157},
  200. {0x00, 0x40, 0x8158},
  201. {0x00, 0x0a, 0x8159},
  202. {0x00, 0x06, 0x815a},
  203. {0x00, 0x00, 0x813f},
  204. {0x00, 0x00, 0x8200},
  205. {0x00, 0x19, 0x8201},
  206. {0x00, 0x00, 0x82c1},
  207. {0x00, 0xa0, 0x82c2},
  208. {0x00, 0x00, 0x82ca},
  209. {0x00, 0x00, 0x8117},
  210. {0x00, 0x00, 0x8118},
  211. {0x00, 0x65, 0x8119},
  212. {0x00, 0x00, 0x811a},
  213. {0x00, 0x00, 0x811b},
  214. {0x00, 0x55, 0x811c},
  215. {0x00, 0x65, 0x811d},
  216. {0x00, 0x55, 0x811e},
  217. {0x00, 0x16, 0x811f},
  218. {0x00, 0x19, 0x8120},
  219. {0x00, 0x80, 0x8103},
  220. {0x00, 0x83, 0x816b},
  221. {0x00, 0x25, 0x8168},
  222. {0x00, 0x01, 0x820f},
  223. {0x00, 0xff, 0x8115},
  224. {0x00, 0x48, 0x8116},
  225. {0x00, 0x50, 0x8151},
  226. {0x00, 0x40, 0x8152},
  227. {0x00, 0x78, 0x8153},
  228. {0x00, 0x40, 0x8154},
  229. {0x00, 0x00, 0x8167},
  230. {0x00, 0x20, 0x8168},
  231. {0x00, 0x00, 0x816a},
  232. {0x00, 0x03, 0x816b},
  233. {0x00, 0x20, 0x8169},
  234. {0x00, 0x60, 0x8157},
  235. {0x00, 0x00, 0x8190},
  236. {0x00, 0x00, 0x81a1},
  237. {0x00, 0x00, 0x81b2},
  238. {0x00, 0x27, 0x8191},
  239. {0x00, 0x27, 0x81a2},
  240. {0x00, 0x27, 0x81b3},
  241. {0x00, 0x4b, 0x8192},
  242. {0x00, 0x4b, 0x81a3},
  243. {0x00, 0x4b, 0x81b4},
  244. {0x00, 0x66, 0x8193},
  245. {0x00, 0x66, 0x81a4},
  246. {0x00, 0x66, 0x81b5},
  247. {0x00, 0x79, 0x8194},
  248. {0x00, 0x79, 0x81a5},
  249. {0x00, 0x79, 0x81b6},
  250. {0x00, 0x8a, 0x8195},
  251. {0x00, 0x8a, 0x81a6},
  252. {0x00, 0x8a, 0x81b7},
  253. {0x00, 0x9b, 0x8196},
  254. {0x00, 0x9b, 0x81a7},
  255. {0x00, 0x9b, 0x81b8},
  256. {0x00, 0xa6, 0x8197},
  257. {0x00, 0xa6, 0x81a8},
  258. {0x00, 0xa6, 0x81b9},
  259. {0x00, 0xb2, 0x8198},
  260. {0x00, 0xb2, 0x81a9},
  261. {0x00, 0xb2, 0x81ba},
  262. {0x00, 0xbe, 0x8199},
  263. {0x00, 0xbe, 0x81aa},
  264. {0x00, 0xbe, 0x81bb},
  265. {0x00, 0xc8, 0x819a},
  266. {0x00, 0xc8, 0x81ab},
  267. {0x00, 0xc8, 0x81bc},
  268. {0x00, 0xd2, 0x819b},
  269. {0x00, 0xd2, 0x81ac},
  270. {0x00, 0xd2, 0x81bd},
  271. {0x00, 0xdb, 0x819c},
  272. {0x00, 0xdb, 0x81ad},
  273. {0x00, 0xdb, 0x81be},
  274. {0x00, 0xe4, 0x819d},
  275. {0x00, 0xe4, 0x81ae},
  276. {0x00, 0xe4, 0x81bf},
  277. {0x00, 0xed, 0x819e},
  278. {0x00, 0xed, 0x81af},
  279. {0x00, 0xed, 0x81c0},
  280. {0x00, 0xf7, 0x819f},
  281. {0x00, 0xf7, 0x81b0},
  282. {0x00, 0xf7, 0x81c1},
  283. {0x00, 0xff, 0x81a0},
  284. {0x00, 0xff, 0x81b1},
  285. {0x00, 0xff, 0x81c2},
  286. {0x00, 0x03, 0x8156},
  287. {0x00, 0x00, 0x8211},
  288. {0x00, 0x20, 0x8168},
  289. {0x00, 0x01, 0x8202},
  290. {0x00, 0x30, 0x8101},
  291. {0x00, 0x00, 0x8111},
  292. {0x00, 0x00, 0x8112},
  293. {0x00, 0x00, 0x8113},
  294. {0x00, 0x00, 0x8114},
  295. {}
  296. };
  297. static const __u8 qtable_creative_pccam[2][64] = {
  298. { /* Q-table Y-components */
  299. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  300. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  301. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  302. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  303. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  304. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  305. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  306. 0x16, 0x1c, 0x1d, 0x1d, 0x22, 0x1e, 0x1f, 0x1e},
  307. { /* Q-table C-components */
  308. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  309. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  310. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  311. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  312. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  313. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  314. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  315. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  316. };
  317. static const __u8 qtable_kodak_ez200[2][64] = {
  318. { /* Q-table Y-components */
  319. 0x02, 0x01, 0x01, 0x02, 0x02, 0x04, 0x05, 0x06,
  320. 0x01, 0x01, 0x01, 0x02, 0x03, 0x06, 0x06, 0x06,
  321. 0x01, 0x01, 0x02, 0x02, 0x04, 0x06, 0x07, 0x06,
  322. 0x01, 0x02, 0x02, 0x03, 0x05, 0x09, 0x08, 0x06,
  323. 0x02, 0x02, 0x04, 0x06, 0x07, 0x0b, 0x0a, 0x08,
  324. 0x02, 0x04, 0x06, 0x06, 0x08, 0x0a, 0x0b, 0x09,
  325. 0x05, 0x06, 0x08, 0x09, 0x0a, 0x0c, 0x0c, 0x0a,
  326. 0x07, 0x09, 0x0a, 0x0a, 0x0b, 0x0a, 0x0a, 0x0a},
  327. { /* Q-table C-components */
  328. 0x02, 0x02, 0x02, 0x05, 0x0a, 0x0a, 0x0a, 0x0a,
  329. 0x02, 0x02, 0x03, 0x07, 0x0a, 0x0a, 0x0a, 0x0a,
  330. 0x02, 0x03, 0x06, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  331. 0x05, 0x07, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  332. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  333. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  334. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  335. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}
  336. };
  337. static const __u8 qtable_pocketdv[2][64] = {
  338. { /* Q-table Y-components start registers 0x8800 */
  339. 0x06, 0x04, 0x04, 0x06, 0x0a, 0x10, 0x14, 0x18,
  340. 0x05, 0x05, 0x06, 0x08, 0x0a, 0x17, 0x18, 0x16,
  341. 0x06, 0x05, 0x06, 0x0a, 0x10, 0x17, 0x1c, 0x16,
  342. 0x06, 0x07, 0x09, 0x0c, 0x14, 0x23, 0x20, 0x19,
  343. 0x07, 0x09, 0x0f, 0x16, 0x1b, 0x2c, 0x29, 0x1f,
  344. 0x0a, 0x0e, 0x16, 0x1a, 0x20, 0x2a, 0x2d, 0x25,
  345. 0x14, 0x1a, 0x1f, 0x23, 0x29, 0x30, 0x30, 0x28,
  346. 0x1d, 0x25, 0x26, 0x27, 0x2d, 0x28, 0x29, 0x28,
  347. },
  348. { /* Q-table C-components start registers 0x8840 */
  349. 0x07, 0x07, 0x0a, 0x13, 0x28, 0x28, 0x28, 0x28,
  350. 0x07, 0x08, 0x0a, 0x1a, 0x28, 0x28, 0x28, 0x28,
  351. 0x0a, 0x0a, 0x16, 0x28, 0x28, 0x28, 0x28, 0x28,
  352. 0x13, 0x1a, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  353. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  354. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  355. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  356. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28}
  357. };
  358. /* read 'len' bytes to gspca_dev->usb_buf */
  359. static void reg_r(struct gspca_dev *gspca_dev,
  360. __u16 index,
  361. __u16 length)
  362. {
  363. usb_control_msg(gspca_dev->dev,
  364. usb_rcvctrlpipe(gspca_dev->dev, 0),
  365. 0,
  366. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  367. 0, /* value */
  368. index, gspca_dev->usb_buf, length, 500);
  369. }
  370. static int reg_w(struct gspca_dev *gspca_dev,
  371. __u16 req, __u16 index, __u16 value)
  372. {
  373. int ret;
  374. PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x", index, value);
  375. ret = usb_control_msg(gspca_dev->dev,
  376. usb_sndctrlpipe(gspca_dev->dev, 0),
  377. req,
  378. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  379. value, index, NULL, 0, 500);
  380. if (ret < 0)
  381. PDEBUG(D_ERR, "reg write: error %d", ret);
  382. return ret;
  383. }
  384. /* returns: negative is error, pos or zero is data */
  385. static int reg_r_12(struct gspca_dev *gspca_dev,
  386. __u16 req, /* bRequest */
  387. __u16 index, /* wIndex */
  388. __u16 length) /* wLength (1 or 2 only) */
  389. {
  390. int ret;
  391. gspca_dev->usb_buf[1] = 0;
  392. ret = usb_control_msg(gspca_dev->dev,
  393. usb_rcvctrlpipe(gspca_dev->dev, 0),
  394. req,
  395. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  396. 0, /* value */
  397. index,
  398. gspca_dev->usb_buf, length,
  399. 500); /* timeout */
  400. if (ret < 0) {
  401. PDEBUG(D_ERR, "reg_r_12 err %d", ret);
  402. return -1;
  403. }
  404. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  405. }
  406. /*
  407. * Simple function to wait for a given 8-bit value to be returned from
  408. * a reg_read call.
  409. * Returns: negative is error or timeout, zero is success.
  410. */
  411. static int reg_r_wait(struct gspca_dev *gspca_dev,
  412. __u16 reg, __u16 index, __u16 value)
  413. {
  414. int ret, cnt = 20;
  415. while (--cnt > 0) {
  416. ret = reg_r_12(gspca_dev, reg, index, 1);
  417. if (ret == value)
  418. return 0;
  419. msleep(50);
  420. }
  421. return -EIO;
  422. }
  423. static int write_vector(struct gspca_dev *gspca_dev,
  424. const __u16 data[][3])
  425. {
  426. int ret, i = 0;
  427. while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
  428. ret = reg_w(gspca_dev, data[i][0], data[i][2], data[i][1]);
  429. if (ret < 0)
  430. return ret;
  431. i++;
  432. }
  433. return 0;
  434. }
  435. static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
  436. unsigned int request,
  437. unsigned int ybase,
  438. unsigned int cbase,
  439. const __u8 qtable[2][64])
  440. {
  441. int i, err;
  442. /* loop over y components */
  443. for (i = 0; i < 64; i++) {
  444. err = reg_w(gspca_dev, request, ybase + i, qtable[0][i]);
  445. if (err < 0)
  446. return err;
  447. }
  448. /* loop over c components */
  449. for (i = 0; i < 64; i++) {
  450. err = reg_w(gspca_dev, request, cbase + i, qtable[1][i]);
  451. if (err < 0)
  452. return err;
  453. }
  454. return 0;
  455. }
  456. static void spca500_ping310(struct gspca_dev *gspca_dev)
  457. {
  458. reg_r(gspca_dev, 0x0d04, 2);
  459. PDEBUG(D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x",
  460. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
  461. }
  462. static void spca500_clksmart310_init(struct gspca_dev *gspca_dev)
  463. {
  464. reg_r(gspca_dev, 0x0d05, 2);
  465. PDEBUG(D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x",
  466. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
  467. reg_w(gspca_dev, 0x00, 0x8167, 0x5a);
  468. spca500_ping310(gspca_dev);
  469. reg_w(gspca_dev, 0x00, 0x8168, 0x22);
  470. reg_w(gspca_dev, 0x00, 0x816a, 0xc0);
  471. reg_w(gspca_dev, 0x00, 0x816b, 0x0b);
  472. reg_w(gspca_dev, 0x00, 0x8169, 0x25);
  473. reg_w(gspca_dev, 0x00, 0x8157, 0x5b);
  474. reg_w(gspca_dev, 0x00, 0x8158, 0x5b);
  475. reg_w(gspca_dev, 0x00, 0x813f, 0x03);
  476. reg_w(gspca_dev, 0x00, 0x8151, 0x4a);
  477. reg_w(gspca_dev, 0x00, 0x8153, 0x78);
  478. reg_w(gspca_dev, 0x00, 0x0d01, 0x04);
  479. /* 00 for adjust shutter */
  480. reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
  481. reg_w(gspca_dev, 0x00, 0x8169, 0x25);
  482. reg_w(gspca_dev, 0x00, 0x0d01, 0x02);
  483. }
  484. static void spca500_setmode(struct gspca_dev *gspca_dev,
  485. __u8 xmult, __u8 ymult)
  486. {
  487. int mode;
  488. /* set x multiplier */
  489. reg_w(gspca_dev, 0, 0x8001, xmult);
  490. /* set y multiplier */
  491. reg_w(gspca_dev, 0, 0x8002, ymult);
  492. /* use compressed mode, VGA, with mode specific subsample */
  493. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  494. reg_w(gspca_dev, 0, 0x8003, mode << 4);
  495. }
  496. static int spca500_full_reset(struct gspca_dev *gspca_dev)
  497. {
  498. int err;
  499. /* send the reset command */
  500. err = reg_w(gspca_dev, 0xe0, 0x0001, 0x0000);
  501. if (err < 0)
  502. return err;
  503. /* wait for the reset to complete */
  504. err = reg_r_wait(gspca_dev, 0x06, 0x0000, 0x0000);
  505. if (err < 0)
  506. return err;
  507. err = reg_w(gspca_dev, 0xe0, 0x0000, 0x0000);
  508. if (err < 0)
  509. return err;
  510. err = reg_r_wait(gspca_dev, 0x06, 0, 0);
  511. if (err < 0) {
  512. PDEBUG(D_ERR, "reg_r_wait() failed");
  513. return err;
  514. }
  515. /* all ok */
  516. return 0;
  517. }
  518. /* Synchro the Bridge with sensor */
  519. /* Maybe that will work on all spca500 chip */
  520. /* because i only own a clicksmart310 try for that chip */
  521. /* using spca50x_set_packet_size() cause an Ooops here */
  522. /* usb_set_interface from kernel 2.6.x clear all the urb stuff */
  523. /* up-port the same feature as in 2.4.x kernel */
  524. static int spca500_synch310(struct gspca_dev *gspca_dev)
  525. {
  526. if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) {
  527. PDEBUG(D_ERR, "Set packet size: set interface error");
  528. goto error;
  529. }
  530. spca500_ping310(gspca_dev);
  531. reg_r(gspca_dev, 0x0d00, 1);
  532. /* need alt setting here */
  533. PDEBUG(D_PACK, "ClickSmart310 sync alt: %d", gspca_dev->alt);
  534. /* Windoze use pipe with altsetting 6 why 7 here */
  535. if (usb_set_interface(gspca_dev->dev,
  536. gspca_dev->iface,
  537. gspca_dev->alt) < 0) {
  538. PDEBUG(D_ERR, "Set packet size: set interface error");
  539. goto error;
  540. }
  541. return 0;
  542. error:
  543. return -EBUSY;
  544. }
  545. static void spca500_reinit(struct gspca_dev *gspca_dev)
  546. {
  547. int err;
  548. __u8 Data;
  549. /* some unknow command from Aiptek pocket dv and family300 */
  550. reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
  551. reg_w(gspca_dev, 0x00, 0x0d03, 0x00);
  552. reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
  553. /* enable drop packet */
  554. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  555. err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840,
  556. qtable_pocketdv);
  557. if (err < 0)
  558. PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed on init");
  559. /* set qtable index */
  560. reg_w(gspca_dev, 0x00, 0x8880, 2);
  561. /* family cam Quicksmart stuff */
  562. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  563. /* Set agc transfer: synced inbetween frames */
  564. reg_w(gspca_dev, 0x00, 0x820f, 0x01);
  565. /* Init SDRAM - needed for SDRAM access */
  566. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  567. /*Start init sequence or stream */
  568. reg_w(gspca_dev, 0, 0x8003, 0x00);
  569. /* switch to video camera mode */
  570. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  571. msleep(2000);
  572. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) {
  573. reg_r(gspca_dev, 0x816b, 1);
  574. Data = gspca_dev->usb_buf[0];
  575. reg_w(gspca_dev, 0x00, 0x816b, Data);
  576. }
  577. }
  578. /* this function is called at probe time */
  579. static int sd_config(struct gspca_dev *gspca_dev,
  580. const struct usb_device_id *id)
  581. {
  582. struct sd *sd = (struct sd *) gspca_dev;
  583. struct cam *cam;
  584. cam = &gspca_dev->cam;
  585. sd->subtype = id->driver_info;
  586. if (sd->subtype != LogitechClickSmart310) {
  587. cam->cam_mode = vga_mode;
  588. cam->nmodes = ARRAY_SIZE(vga_mode);
  589. } else {
  590. cam->cam_mode = sif_mode;
  591. cam->nmodes = ARRAY_SIZE(sif_mode);
  592. }
  593. sd->brightness = BRIGHTNESS_DEF;
  594. sd->contrast = CONTRAST_DEF;
  595. sd->colors = COLOR_DEF;
  596. sd->quality = QUALITY_DEF;
  597. return 0;
  598. }
  599. /* this function is called at probe and resume time */
  600. static int sd_init(struct gspca_dev *gspca_dev)
  601. {
  602. struct sd *sd = (struct sd *) gspca_dev;
  603. /* initialisation of spca500 based cameras is deferred */
  604. PDEBUG(D_STREAM, "SPCA500 init");
  605. if (sd->subtype == LogitechClickSmart310)
  606. spca500_clksmart310_init(gspca_dev);
  607. /* else
  608. spca500_initialise(gspca_dev); */
  609. PDEBUG(D_STREAM, "SPCA500 init done");
  610. return 0;
  611. }
  612. static int sd_start(struct gspca_dev *gspca_dev)
  613. {
  614. struct sd *sd = (struct sd *) gspca_dev;
  615. int err;
  616. __u8 Data;
  617. __u8 xmult, ymult;
  618. /* create the JPEG header */
  619. sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
  620. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  621. 0x22); /* JPEG 411 */
  622. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  623. if (sd->subtype == LogitechClickSmart310) {
  624. xmult = 0x16;
  625. ymult = 0x12;
  626. } else {
  627. xmult = 0x28;
  628. ymult = 0x1e;
  629. }
  630. /* is there a sensor here ? */
  631. reg_r(gspca_dev, 0x8a04, 1);
  632. PDEBUG(D_STREAM, "Spca500 Sensor Address 0x%02x",
  633. gspca_dev->usb_buf[0]);
  634. PDEBUG(D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02x, Ymult: 0x%02x",
  635. gspca_dev->curr_mode, xmult, ymult);
  636. /* setup qtable */
  637. switch (sd->subtype) {
  638. case LogitechClickSmart310:
  639. spca500_setmode(gspca_dev, xmult, ymult);
  640. /* enable drop packet */
  641. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  642. reg_w(gspca_dev, 0x00, 0x8880, 3);
  643. err = spca50x_setup_qtable(gspca_dev,
  644. 0x00, 0x8800, 0x8840,
  645. qtable_creative_pccam);
  646. if (err < 0)
  647. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  648. /* Init SDRAM - needed for SDRAM access */
  649. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  650. /* switch to video camera mode */
  651. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  652. msleep(500);
  653. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  654. PDEBUG(D_ERR, "reg_r_wait() failed");
  655. reg_r(gspca_dev, 0x816b, 1);
  656. Data = gspca_dev->usb_buf[0];
  657. reg_w(gspca_dev, 0x00, 0x816b, Data);
  658. spca500_synch310(gspca_dev);
  659. write_vector(gspca_dev, spca500_visual_defaults);
  660. spca500_setmode(gspca_dev, xmult, ymult);
  661. /* enable drop packet */
  662. err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  663. if (err < 0)
  664. PDEBUG(D_ERR, "failed to enable drop packet");
  665. reg_w(gspca_dev, 0x00, 0x8880, 3);
  666. err = spca50x_setup_qtable(gspca_dev,
  667. 0x00, 0x8800, 0x8840,
  668. qtable_creative_pccam);
  669. if (err < 0)
  670. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  671. /* Init SDRAM - needed for SDRAM access */
  672. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  673. /* switch to video camera mode */
  674. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  675. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  676. PDEBUG(D_ERR, "reg_r_wait() failed");
  677. reg_r(gspca_dev, 0x816b, 1);
  678. Data = gspca_dev->usb_buf[0];
  679. reg_w(gspca_dev, 0x00, 0x816b, Data);
  680. break;
  681. case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */
  682. case IntelPocketPCCamera: /* FIXME: Temporary fix for
  683. * Intel Pocket PC Camera
  684. * - NWG (Sat 29th March 2003) */
  685. /* do a full reset */
  686. err = spca500_full_reset(gspca_dev);
  687. if (err < 0)
  688. PDEBUG(D_ERR, "spca500_full_reset failed");
  689. /* enable drop packet */
  690. err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  691. if (err < 0)
  692. PDEBUG(D_ERR, "failed to enable drop packet");
  693. reg_w(gspca_dev, 0x00, 0x8880, 3);
  694. err = spca50x_setup_qtable(gspca_dev,
  695. 0x00, 0x8800, 0x8840,
  696. qtable_creative_pccam);
  697. if (err < 0)
  698. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  699. spca500_setmode(gspca_dev, xmult, ymult);
  700. reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
  701. /* switch to video camera mode */
  702. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  703. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  704. PDEBUG(D_ERR, "reg_r_wait() failed");
  705. reg_r(gspca_dev, 0x816b, 1);
  706. Data = gspca_dev->usb_buf[0];
  707. reg_w(gspca_dev, 0x00, 0x816b, Data);
  708. /* write_vector(gspca_dev, spca500_visual_defaults); */
  709. break;
  710. case KodakEZ200: /* Kodak EZ200 */
  711. /* do a full reset */
  712. err = spca500_full_reset(gspca_dev);
  713. if (err < 0)
  714. PDEBUG(D_ERR, "spca500_full_reset failed");
  715. /* enable drop packet */
  716. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  717. reg_w(gspca_dev, 0x00, 0x8880, 0);
  718. err = spca50x_setup_qtable(gspca_dev,
  719. 0x00, 0x8800, 0x8840,
  720. qtable_kodak_ez200);
  721. if (err < 0)
  722. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  723. spca500_setmode(gspca_dev, xmult, ymult);
  724. reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
  725. /* switch to video camera mode */
  726. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  727. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  728. PDEBUG(D_ERR, "reg_r_wait() failed");
  729. reg_r(gspca_dev, 0x816b, 1);
  730. Data = gspca_dev->usb_buf[0];
  731. reg_w(gspca_dev, 0x00, 0x816b, Data);
  732. /* write_vector(gspca_dev, spca500_visual_defaults); */
  733. break;
  734. case BenqDC1016:
  735. case DLinkDSC350: /* FamilyCam 300 */
  736. case AiptekPocketDV: /* Aiptek PocketDV */
  737. case Gsmartmini: /*Mustek Gsmart Mini */
  738. case MustekGsmart300: /* Mustek Gsmart 300 */
  739. case PalmPixDC85:
  740. case Optimedia:
  741. case ToptroIndus:
  742. case AgfaCl20:
  743. spca500_reinit(gspca_dev);
  744. reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
  745. /* enable drop packet */
  746. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  747. err = spca50x_setup_qtable(gspca_dev,
  748. 0x00, 0x8800, 0x8840, qtable_pocketdv);
  749. if (err < 0)
  750. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  751. reg_w(gspca_dev, 0x00, 0x8880, 2);
  752. /* familycam Quicksmart pocketDV stuff */
  753. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  754. /* Set agc transfer: synced inbetween frames */
  755. reg_w(gspca_dev, 0x00, 0x820f, 0x01);
  756. /* Init SDRAM - needed for SDRAM access */
  757. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  758. spca500_setmode(gspca_dev, xmult, ymult);
  759. /* switch to video camera mode */
  760. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  761. reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
  762. reg_r(gspca_dev, 0x816b, 1);
  763. Data = gspca_dev->usb_buf[0];
  764. reg_w(gspca_dev, 0x00, 0x816b, Data);
  765. break;
  766. case LogitechTraveler:
  767. case LogitechClickSmart510:
  768. reg_w(gspca_dev, 0x02, 0x00, 0x00);
  769. /* enable drop packet */
  770. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  771. err = spca50x_setup_qtable(gspca_dev,
  772. 0x00, 0x8800,
  773. 0x8840, qtable_creative_pccam);
  774. if (err < 0)
  775. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  776. reg_w(gspca_dev, 0x00, 0x8880, 3);
  777. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  778. /* Init SDRAM - needed for SDRAM access */
  779. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  780. spca500_setmode(gspca_dev, xmult, ymult);
  781. /* switch to video camera mode */
  782. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  783. reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
  784. reg_r(gspca_dev, 0x816b, 1);
  785. Data = gspca_dev->usb_buf[0];
  786. reg_w(gspca_dev, 0x00, 0x816b, Data);
  787. write_vector(gspca_dev, Clicksmart510_defaults);
  788. break;
  789. }
  790. return 0;
  791. }
  792. static void sd_stopN(struct gspca_dev *gspca_dev)
  793. {
  794. reg_w(gspca_dev, 0, 0x8003, 0x00);
  795. /* switch to video camera mode */
  796. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  797. reg_r(gspca_dev, 0x8000, 1);
  798. PDEBUG(D_STREAM, "stop SPCA500 done reg8000: 0x%2x",
  799. gspca_dev->usb_buf[0]);
  800. }
  801. static void sd_stop0(struct gspca_dev *gspca_dev)
  802. {
  803. struct sd *sd = (struct sd *) gspca_dev;
  804. kfree(sd->jpeg_hdr);
  805. }
  806. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  807. struct gspca_frame *frame, /* target */
  808. __u8 *data, /* isoc packet */
  809. int len) /* iso packet length */
  810. {
  811. struct sd *sd = (struct sd *) gspca_dev;
  812. int i;
  813. __u8 *s, *d;
  814. static __u8 ffd9[] = {0xff, 0xd9};
  815. /* frames are jpeg 4.1.1 without 0xff escape */
  816. if (data[0] == 0xff) {
  817. if (data[1] != 0x01) { /* drop packet */
  818. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  819. return;
  820. }
  821. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  822. ffd9, 2);
  823. /* put the JPEG header in the new frame */
  824. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  825. sd->jpeg_hdr, JPEG_HDR_SZ);
  826. data += SPCA500_OFFSET_DATA;
  827. len -= SPCA500_OFFSET_DATA;
  828. } else {
  829. data += 1;
  830. len -= 1;
  831. }
  832. /* add 0x00 after 0xff */
  833. for (i = len; --i >= 0; )
  834. if (data[i] == 0xff)
  835. break;
  836. if (i < 0) { /* no 0xff */
  837. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  838. return;
  839. }
  840. s = data;
  841. d = sd->packet;
  842. for (i = 0; i < len; i++) {
  843. *d++ = *s++;
  844. if (s[-1] == 0xff)
  845. *d++ = 0x00;
  846. }
  847. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  848. sd->packet, d - sd->packet);
  849. }
  850. static void setbrightness(struct gspca_dev *gspca_dev)
  851. {
  852. struct sd *sd = (struct sd *) gspca_dev;
  853. reg_w(gspca_dev, 0x00, 0x8167,
  854. (__u8) (sd->brightness - 128));
  855. }
  856. static void setcontrast(struct gspca_dev *gspca_dev)
  857. {
  858. struct sd *sd = (struct sd *) gspca_dev;
  859. reg_w(gspca_dev, 0x00, 0x8168, sd->contrast);
  860. }
  861. static void setcolors(struct gspca_dev *gspca_dev)
  862. {
  863. struct sd *sd = (struct sd *) gspca_dev;
  864. reg_w(gspca_dev, 0x00, 0x8169, sd->colors);
  865. }
  866. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  867. {
  868. struct sd *sd = (struct sd *) gspca_dev;
  869. sd->brightness = val;
  870. if (gspca_dev->streaming)
  871. setbrightness(gspca_dev);
  872. return 0;
  873. }
  874. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  875. {
  876. struct sd *sd = (struct sd *) gspca_dev;
  877. *val = sd->brightness;
  878. return 0;
  879. }
  880. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  881. {
  882. struct sd *sd = (struct sd *) gspca_dev;
  883. sd->contrast = val;
  884. if (gspca_dev->streaming)
  885. setcontrast(gspca_dev);
  886. return 0;
  887. }
  888. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  889. {
  890. struct sd *sd = (struct sd *) gspca_dev;
  891. *val = sd->contrast;
  892. return 0;
  893. }
  894. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  895. {
  896. struct sd *sd = (struct sd *) gspca_dev;
  897. sd->colors = val;
  898. if (gspca_dev->streaming)
  899. setcolors(gspca_dev);
  900. return 0;
  901. }
  902. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  903. {
  904. struct sd *sd = (struct sd *) gspca_dev;
  905. *val = sd->colors;
  906. return 0;
  907. }
  908. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  909. struct v4l2_jpegcompression *jcomp)
  910. {
  911. struct sd *sd = (struct sd *) gspca_dev;
  912. if (jcomp->quality < QUALITY_MIN)
  913. sd->quality = QUALITY_MIN;
  914. else if (jcomp->quality > QUALITY_MAX)
  915. sd->quality = QUALITY_MAX;
  916. else
  917. sd->quality = jcomp->quality;
  918. if (gspca_dev->streaming)
  919. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  920. return 0;
  921. }
  922. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  923. struct v4l2_jpegcompression *jcomp)
  924. {
  925. struct sd *sd = (struct sd *) gspca_dev;
  926. memset(jcomp, 0, sizeof *jcomp);
  927. jcomp->quality = sd->quality;
  928. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  929. | V4L2_JPEG_MARKER_DQT;
  930. return 0;
  931. }
  932. /* sub-driver description */
  933. static struct sd_desc sd_desc = {
  934. .name = MODULE_NAME,
  935. .ctrls = sd_ctrls,
  936. .nctrls = ARRAY_SIZE(sd_ctrls),
  937. .config = sd_config,
  938. .init = sd_init,
  939. .start = sd_start,
  940. .stopN = sd_stopN,
  941. .stop0 = sd_stop0,
  942. .pkt_scan = sd_pkt_scan,
  943. .get_jcomp = sd_get_jcomp,
  944. .set_jcomp = sd_set_jcomp,
  945. };
  946. /* -- module initialisation -- */
  947. static const __devinitdata struct usb_device_id device_table[] = {
  948. {USB_DEVICE(0x040a, 0x0300), .driver_info = KodakEZ200},
  949. {USB_DEVICE(0x041e, 0x400a), .driver_info = CreativePCCam300},
  950. {USB_DEVICE(0x046d, 0x0890), .driver_info = LogitechTraveler},
  951. {USB_DEVICE(0x046d, 0x0900), .driver_info = LogitechClickSmart310},
  952. {USB_DEVICE(0x046d, 0x0901), .driver_info = LogitechClickSmart510},
  953. {USB_DEVICE(0x04a5, 0x300c), .driver_info = BenqDC1016},
  954. {USB_DEVICE(0x04fc, 0x7333), .driver_info = PalmPixDC85},
  955. {USB_DEVICE(0x055f, 0xc200), .driver_info = MustekGsmart300},
  956. {USB_DEVICE(0x055f, 0xc220), .driver_info = Gsmartmini},
  957. {USB_DEVICE(0x06bd, 0x0404), .driver_info = AgfaCl20},
  958. {USB_DEVICE(0x06be, 0x0800), .driver_info = Optimedia},
  959. {USB_DEVICE(0x084d, 0x0003), .driver_info = DLinkDSC350},
  960. {USB_DEVICE(0x08ca, 0x0103), .driver_info = AiptekPocketDV},
  961. {USB_DEVICE(0x2899, 0x012c), .driver_info = ToptroIndus},
  962. {USB_DEVICE(0x8086, 0x0630), .driver_info = IntelPocketPCCamera},
  963. {}
  964. };
  965. MODULE_DEVICE_TABLE(usb, device_table);
  966. /* -- device connect -- */
  967. static int sd_probe(struct usb_interface *intf,
  968. const struct usb_device_id *id)
  969. {
  970. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  971. THIS_MODULE);
  972. }
  973. static struct usb_driver sd_driver = {
  974. .name = MODULE_NAME,
  975. .id_table = device_table,
  976. .probe = sd_probe,
  977. .disconnect = gspca_disconnect,
  978. #ifdef CONFIG_PM
  979. .suspend = gspca_suspend,
  980. .resume = gspca_resume,
  981. #endif
  982. };
  983. /* -- module insert / remove -- */
  984. static int __init sd_mod_init(void)
  985. {
  986. int ret;
  987. ret = usb_register(&sd_driver);
  988. if (ret < 0)
  989. return ret;
  990. PDEBUG(D_PROBE, "registered");
  991. return 0;
  992. }
  993. static void __exit sd_mod_exit(void)
  994. {
  995. usb_deregister(&sd_driver);
  996. PDEBUG(D_PROBE, "deregistered");
  997. }
  998. module_init(sd_mod_init);
  999. module_exit(sd_mod_exit);