spca500.c 30 KB

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