spca500.c 29 KB

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