spca500.c 29 KB

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