t613.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /*
  2. *Notes: * t613 + tas5130A
  3. * * Focus to light do not balance well as in win.
  4. * Quality in win is not good, but its kinda better.
  5. * * Fix some "extraneous bytes", most of apps will show the image anyway
  6. * * Gamma table, is there, but its really doing something?
  7. * * 7~8 Fps, its ok, max on win its 10.
  8. * Costantino Leandro
  9. *
  10. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #define MODULE_NAME "t613"
  27. #include "gspca.h"
  28. #define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5)
  29. static const char version[] = "2.1.5";
  30. #define MAX_GAMMA 0x10 /* 0 to 15 */
  31. /* From LUVCVIEW */
  32. #define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 3)
  33. MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
  34. MODULE_DESCRIPTION("GSPCA/T613 (JPEG Compliance) USB Camera Driver");
  35. MODULE_LICENSE("GPL");
  36. struct sd {
  37. struct gspca_dev gspca_dev; /* !! must be the first item */
  38. unsigned char brightness;
  39. unsigned char contrast;
  40. unsigned char colors;
  41. unsigned char autogain;
  42. unsigned char gamma;
  43. unsigned char sharpness;
  44. unsigned char freq;
  45. unsigned char whitebalance;
  46. unsigned char mirror;
  47. unsigned char effect;
  48. };
  49. /* V4L2 controls supported by the driver */
  50. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  51. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  52. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  53. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  54. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  55. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  56. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val);
  57. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val);
  58. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
  59. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
  60. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  61. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  62. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  63. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  64. static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val);
  65. static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val);
  66. static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val);
  67. static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val);
  68. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val);
  69. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val);
  70. static int sd_querymenu(struct gspca_dev *gspca_dev,
  71. struct v4l2_querymenu *menu);
  72. static struct ctrl sd_ctrls[] = {
  73. #define SD_BRIGHTNESS 0
  74. {
  75. {
  76. .id = V4L2_CID_BRIGHTNESS,
  77. .type = V4L2_CTRL_TYPE_INTEGER,
  78. .name = "Brightness",
  79. .minimum = 0,
  80. .maximum = 0x0f,
  81. .step = 1,
  82. .default_value = 0x09,
  83. },
  84. .set = sd_setbrightness,
  85. .get = sd_getbrightness,
  86. },
  87. #define SD_CONTRAST 1
  88. {
  89. {
  90. .id = V4L2_CID_CONTRAST,
  91. .type = V4L2_CTRL_TYPE_INTEGER,
  92. .name = "Contrast",
  93. .minimum = 0,
  94. .maximum = 0x0d,
  95. .step = 1,
  96. .default_value = 0x07,
  97. },
  98. .set = sd_setcontrast,
  99. .get = sd_getcontrast,
  100. },
  101. #define SD_COLOR 2
  102. {
  103. {
  104. .id = V4L2_CID_SATURATION,
  105. .type = V4L2_CTRL_TYPE_INTEGER,
  106. .name = "Color",
  107. .minimum = 0,
  108. .maximum = 0x0f,
  109. .step = 1,
  110. .default_value = 0x05,
  111. },
  112. .set = sd_setcolors,
  113. .get = sd_getcolors,
  114. },
  115. #define SD_GAMMA 3
  116. {
  117. {
  118. .id = V4L2_CID_GAMMA, /* (gamma on win) */
  119. .type = V4L2_CTRL_TYPE_INTEGER,
  120. .name = "Gamma (Untested)",
  121. .minimum = 0,
  122. .maximum = MAX_GAMMA,
  123. .step = 1,
  124. .default_value = 0x09,
  125. },
  126. .set = sd_setgamma,
  127. .get = sd_getgamma,
  128. },
  129. #define SD_AUTOGAIN 4
  130. {
  131. {
  132. .id = V4L2_CID_GAIN, /* here, i activate only the lowlight,
  133. * some apps dont bring up the
  134. * backligth_compensation control) */
  135. .type = V4L2_CTRL_TYPE_INTEGER,
  136. .name = "Low Light",
  137. .minimum = 0,
  138. .maximum = 1,
  139. .step = 1,
  140. .default_value = 0x01,
  141. },
  142. .set = sd_setlowlight,
  143. .get = sd_getlowlight,
  144. },
  145. #define SD_MIRROR 5
  146. {
  147. {
  148. .id = V4L2_CID_HFLIP,
  149. .type = V4L2_CTRL_TYPE_BOOLEAN,
  150. .name = "Mirror Image",
  151. .minimum = 0,
  152. .maximum = 1,
  153. .step = 1,
  154. .default_value = 0,
  155. },
  156. .set = sd_setflip,
  157. .get = sd_getflip
  158. },
  159. #define SD_LIGHTFREQ 6
  160. {
  161. {
  162. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  163. .type = V4L2_CTRL_TYPE_MENU,
  164. .name = "Light Frequency Filter",
  165. .minimum = 1, /* 1 -> 0x50, 2->0x60 */
  166. .maximum = 2,
  167. .step = 1,
  168. .default_value = 1,
  169. },
  170. .set = sd_setfreq,
  171. .get = sd_getfreq},
  172. #define SD_WHITE_BALANCE 7
  173. {
  174. {
  175. .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE,
  176. .type = V4L2_CTRL_TYPE_INTEGER,
  177. .name = "White Balance",
  178. .minimum = 0,
  179. .maximum = 1,
  180. .step = 1,
  181. .default_value = 1,
  182. },
  183. .set = sd_setwhitebalance,
  184. .get = sd_getwhitebalance
  185. },
  186. #define SD_SHARPNESS 8 /* (aka definition on win) */
  187. {
  188. {
  189. .id = V4L2_CID_SHARPNESS,
  190. .type = V4L2_CTRL_TYPE_INTEGER,
  191. .name = "Sharpness",
  192. .minimum = 0,
  193. .maximum = MAX_GAMMA, /* 0 to 16 */
  194. .step = 1,
  195. .default_value = 0x06,
  196. },
  197. .set = sd_setsharpness,
  198. .get = sd_getsharpness,
  199. },
  200. #define SD_EFFECTS 9
  201. {
  202. {
  203. .id = V4L2_CID_EFFECTS,
  204. .type = V4L2_CTRL_TYPE_MENU,
  205. .name = "Webcam Effects",
  206. .minimum = 0,
  207. .maximum = 4,
  208. .step = 1,
  209. .default_value = 0,
  210. },
  211. .set = sd_seteffect,
  212. .get = sd_geteffect
  213. },
  214. };
  215. static char *effects_control[] = {
  216. "Normal",
  217. "Emboss", /* disabled */
  218. "Monochrome",
  219. "Sepia",
  220. "Sketch",
  221. "Sun Effect", /* disabled */
  222. "Negative",
  223. };
  224. static struct v4l2_pix_format vga_mode_t16[] = {
  225. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  226. .bytesperline = 160,
  227. .sizeimage = 160 * 120 * 3 / 8 + 590,
  228. .colorspace = V4L2_COLORSPACE_JPEG,
  229. .priv = 4},
  230. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  231. .bytesperline = 176,
  232. .sizeimage = 176 * 144 * 3 / 8 + 590,
  233. .colorspace = V4L2_COLORSPACE_JPEG,
  234. .priv = 3},
  235. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  236. .bytesperline = 320,
  237. .sizeimage = 320 * 240 * 3 / 8 + 590,
  238. .colorspace = V4L2_COLORSPACE_JPEG,
  239. .priv = 2},
  240. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  241. .bytesperline = 352,
  242. .sizeimage = 352 * 288 * 3 / 8 + 590,
  243. .colorspace = V4L2_COLORSPACE_JPEG,
  244. .priv = 1},
  245. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  246. .bytesperline = 640,
  247. .sizeimage = 640 * 480 * 3 / 8 + 590,
  248. .colorspace = V4L2_COLORSPACE_JPEG,
  249. .priv = 0},
  250. };
  251. #define T16_OFFSET_DATA 631
  252. #define MAX_EFFECTS 7
  253. /* easily done by soft, this table could be removed,
  254. * i keep it here just in case */
  255. static const __u8 effects_table[MAX_EFFECTS][6] = {
  256. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
  257. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
  258. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
  259. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */
  260. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */
  261. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */
  262. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
  263. };
  264. static const __u8 gamma_table[MAX_GAMMA][34] = {
  265. {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85,
  266. 0x94, 0x95, 0x95, 0xa1, 0x96, 0xae, 0x97, 0xb9,
  267. 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdb,
  268. 0x9c, 0xe3, 0x9d, 0xea, 0x9e, 0xf1, 0x9f, 0xf8,
  269. 0xa0, 0xff},
  270. {0x90, 0x00, 0x91, 0x33, 0x92, 0x5A, 0x93, 0x75,
  271. 0x94, 0x85, 0x95, 0x93, 0x96, 0xA1, 0x97, 0xAD,
  272. 0x98, 0xB7, 0x99, 0xC2, 0x9A, 0xCB, 0x9B, 0xD4,
  273. 0x9C, 0xDE, 0x9D, 0xE7, 0x9E, 0xF0, 0x9F, 0xF7,
  274. 0xa0, 0xff},
  275. {0x90, 0x00, 0x91, 0x2F, 0x92, 0x51, 0x93, 0x6B,
  276. 0x94, 0x7C, 0x95, 0x8A, 0x96, 0x99, 0x97, 0xA6,
  277. 0x98, 0xB1, 0x99, 0xBC, 0x9A, 0xC6, 0x9B, 0xD0,
  278. 0x9C, 0xDB, 0x9D, 0xE4, 0x9E, 0xED, 0x9F, 0xF6,
  279. 0xa0, 0xff},
  280. {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60,
  281. 0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9E,
  282. 0x98, 0xAA, 0x99, 0xB5, 0x9A, 0xBF, 0x9B, 0xCB,
  283. 0x9C, 0xD6, 0x9D, 0xE1, 0x9E, 0xEB, 0x9F, 0xF5,
  284. 0xa0, 0xff},
  285. {0x90, 0x00, 0x91, 0x23, 0x92, 0x3F, 0x93, 0x55,
  286. 0x94, 0x68, 0x95, 0x77, 0x96, 0x86, 0x97, 0x95,
  287. 0x98, 0xA2, 0x99, 0xAD, 0x9A, 0xB9, 0x9B, 0xC6,
  288. 0x9C, 0xD2, 0x9D, 0xDE, 0x9E, 0xE9, 0x9F, 0xF4,
  289. 0xa0, 0xff},
  290. {0x90, 0x00, 0x91, 0x1B, 0x92, 0x33, 0x93, 0x48,
  291. 0x94, 0x59, 0x95, 0x69, 0x96, 0x79, 0x97, 0x87,
  292. 0x98, 0x96, 0x99, 0xA3, 0x9A, 0xB1, 0x9B, 0xBE,
  293. 0x9C, 0xCC, 0x9D, 0xDA, 0x9E, 0xE7, 0x9F, 0xF3,
  294. 0xa0, 0xff},
  295. {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20,
  296. 0x94, 0x32, 0x95, 0x40, 0x96, 0x57, 0x97, 0x67,
  297. 0x98, 0x77, 0x99, 0x88, 0x9a, 0x99, 0x9b, 0xaa,
  298. 0x9c, 0xbb, 0x9d, 0xcc, 0x9e, 0xdd, 0x9f, 0xee,
  299. 0xa0, 0xff},
  300. {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26,
  301. 0x94, 0x38, 0x95, 0x4A, 0x96, 0x60, 0x97, 0x70,
  302. 0x98, 0x80, 0x99, 0x90, 0x9A, 0xA0, 0x9B, 0xB0,
  303. 0x9C, 0xC0, 0x9D, 0xD0, 0x9E, 0xE0, 0x9F, 0xF0,
  304. 0xa0, 0xff},
  305. {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35,
  306. 0x94, 0x47, 0x95, 0x5A, 0x96, 0x69, 0x97, 0x79,
  307. 0x98, 0x88, 0x99, 0x97, 0x9A, 0xA7, 0x9B, 0xB6,
  308. 0x9C, 0xC4, 0x9D, 0xD3, 0x9E, 0xE0, 0x9F, 0xF0,
  309. 0xa0, 0xff},
  310. {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40,
  311. 0x94, 0x54, 0x95, 0x65, 0x96, 0x75, 0x97, 0x84,
  312. 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd,
  313. 0x9c, 0xca, 0x9d, 0xd6, 0x9e, 0xe0, 0x9f, 0xf0,
  314. 0xa0, 0xff},
  315. {0x90, 0x00, 0x91, 0x18, 0x92, 0x2B, 0x93, 0x44,
  316. 0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8E,
  317. 0x98, 0x9C, 0x99, 0xAA, 0x9A, 0xB7, 0x9B, 0xC4,
  318. 0x9C, 0xD0, 0x9D, 0xD8, 0x9E, 0xE2, 0x9F, 0xF0,
  319. 0xa0, 0xff},
  320. {0x90, 0x00, 0x91, 0x1A, 0x92, 0x34, 0x93, 0x52,
  321. 0x94, 0x66, 0x95, 0x7E, 0x96, 0x8D, 0x97, 0x9B,
  322. 0x98, 0xA8, 0x99, 0xB4, 0x9A, 0xC0, 0x9B, 0xCB,
  323. 0x9C, 0xD6, 0x9D, 0xE1, 0x9E, 0xEB, 0x9F, 0xF5,
  324. 0xa0, 0xff},
  325. {0x90, 0x00, 0x91, 0x3F, 0x92, 0x5A, 0x93, 0x6E,
  326. 0x94, 0x7F, 0x95, 0x8E, 0x96, 0x9C, 0x97, 0xA8,
  327. 0x98, 0xB4, 0x99, 0xBF, 0x9A, 0xC9, 0x9B, 0xD3,
  328. 0x9C, 0xDC, 0x9D, 0xE5, 0x9E, 0xEE, 0x9F, 0xF6,
  329. 0xA0, 0xFF},
  330. {0x90, 0x00, 0x91, 0x54, 0x92, 0x6F, 0x93, 0x83,
  331. 0x94, 0x93, 0x95, 0xA0, 0x96, 0xAD, 0x97, 0xB7,
  332. 0x98, 0xC2, 0x99, 0xCB, 0x9A, 0xD4, 0x9B, 0xDC,
  333. 0x9C, 0xE4, 0x9D, 0xEB, 0x9E, 0xF2, 0x9F, 0xF9,
  334. 0xa0, 0xff},
  335. {0x90, 0x00, 0x91, 0x6E, 0x92, 0x88, 0x93, 0x9A,
  336. 0x94, 0xA8, 0x95, 0xB3, 0x96, 0xBD, 0x97, 0xC6,
  337. 0x98, 0xCF, 0x99, 0xD6, 0x9A, 0xDD, 0x9B, 0xE3,
  338. 0x9C, 0xE9, 0x9D, 0xEF, 0x9E, 0xF4, 0x9F, 0xFA,
  339. 0xa0, 0xff},
  340. {0x90, 0x00, 0x91, 0x93, 0x92, 0xA8, 0x93, 0xB7,
  341. 0x94, 0xC1, 0x95, 0xCA, 0x96, 0xD2, 0x97, 0xD8,
  342. 0x98, 0xDE, 0x99, 0xE3, 0x9A, 0xE8, 0x9B, 0xED,
  343. 0x9C, 0xF1, 0x9D, 0xF5, 0x9E, 0xF8, 0x9F, 0xFC,
  344. 0xA0, 0xFF}
  345. };
  346. static const __u8 tas5130a_sensor_init[][8] = {
  347. {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
  348. {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
  349. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  350. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  351. {},
  352. };
  353. static void t16RegRead(struct usb_device *dev,
  354. __u16 index, __u8 *buffer, __u16 length)
  355. {
  356. usb_control_msg(dev,
  357. usb_rcvctrlpipe(dev, 0),
  358. 0, /* request */
  359. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  360. 0, /* value */
  361. index, buffer, length, 500);
  362. }
  363. static void t16RegWrite(struct usb_device *dev,
  364. __u16 value,
  365. __u16 index,
  366. const __u8 *buffer, __u16 len)
  367. {
  368. if (buffer == NULL) {
  369. usb_control_msg(dev,
  370. usb_sndctrlpipe(dev, 0),
  371. 0,
  372. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  373. value, index,
  374. NULL, 0, 500);
  375. return;
  376. }
  377. if (len < 16) {
  378. __u8 tmpbuf[16];
  379. memcpy(tmpbuf, buffer, len);
  380. usb_control_msg(dev,
  381. usb_sndctrlpipe(dev, 0),
  382. 0,
  383. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  384. value, index,
  385. tmpbuf, len, 500);
  386. } else {
  387. __u8 *tmpbuf;
  388. tmpbuf = kmalloc(len, GFP_KERNEL);
  389. memcpy(tmpbuf, buffer, len);
  390. usb_control_msg(dev,
  391. usb_sndctrlpipe(dev, 0),
  392. 0,
  393. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  394. value, index,
  395. tmpbuf, len, 500);
  396. kfree(tmpbuf);
  397. }
  398. }
  399. /* this function is called at probe time */
  400. static int sd_config(struct gspca_dev *gspca_dev,
  401. const struct usb_device_id *id)
  402. {
  403. struct sd *sd = (struct sd *) gspca_dev;
  404. struct cam *cam;
  405. cam = &gspca_dev->cam;
  406. cam->dev_name = (char *) id->driver_info;
  407. cam->epaddr = 0x01;
  408. cam->cam_mode = vga_mode_t16;
  409. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  410. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  411. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  412. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  413. sd->gamma = sd_ctrls[SD_GAMMA].qctrl.default_value;
  414. sd->mirror = sd_ctrls[SD_MIRROR].qctrl.default_value;
  415. sd->freq = sd_ctrls[SD_LIGHTFREQ].qctrl.default_value;
  416. sd->whitebalance = sd_ctrls[SD_WHITE_BALANCE].qctrl.default_value;
  417. sd->sharpness = sd_ctrls[SD_SHARPNESS].qctrl.default_value;
  418. sd->effect = sd_ctrls[SD_EFFECTS].qctrl.default_value;
  419. return 0;
  420. }
  421. static int init_default_parameters(struct gspca_dev *gspca_dev)
  422. {
  423. struct usb_device *dev = gspca_dev->dev;
  424. /* some of this registers are not really neded, because
  425. * they are overriden by setbrigthness, setcontrast, etc,
  426. * but wont hurt anyway, and can help someone with similar webcam
  427. * to see the initial parameters.*/
  428. int i = 0;
  429. __u8 test_byte;
  430. static const __u8 read_indexs[] =
  431. { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  432. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00, 0x00 };
  433. static const __u8 n1[6] =
  434. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  435. static const __u8 n2[2] =
  436. {0x08, 0x00};
  437. static const __u8 nset[6] =
  438. { 0x61, 0x68, 0x62, 0xff, 0x60, 0x07 };
  439. static const __u8 n3[6] =
  440. {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
  441. static const __u8 n4[0x46] =
  442. {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
  443. 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
  444. 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
  445. 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
  446. 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
  447. 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
  448. 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
  449. 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
  450. 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
  451. static const __u8 nset4[18] = {
  452. 0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 0xe4, 0xa8,
  453. 0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8,
  454. 0xe8, 0xe0
  455. };
  456. /* ojo puede ser 0xe6 en vez de 0xe9 */
  457. static const __u8 nset2[20] = {
  458. 0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 0xd4, 0xbb,
  459. 0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27,
  460. 0xd8, 0xc8, 0xd9, 0xfc
  461. };
  462. static const __u8 missing[8] =
  463. { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 };
  464. static const __u8 nset3[18] = {
  465. 0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60, 0xcb, 0xa8,
  466. 0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8,
  467. 0xcf, 0xe0
  468. };
  469. static const __u8 nset5[4] =
  470. { 0x8f, 0x24, 0xc3, 0x00 }; /* bright */
  471. static const __u8 nset6[34] = {
  472. 0x90, 0x00, 0x91, 0x1c, 0x92, 0x30, 0x93, 0x43, 0x94, 0x54,
  473. 0x95, 0x65, 0x96, 0x75, 0x97, 0x84,
  474. 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd, 0x9c, 0xca,
  475. 0x9d, 0xd8, 0x9e, 0xe5, 0x9f, 0xf2,
  476. 0xa0, 0xff
  477. }; /* Gamma */
  478. static const __u8 nset7[4] =
  479. { 0x66, 0xca, 0xa8, 0xf8 }; /* 50/60 Hz */
  480. static const __u8 nset9[4] =
  481. { 0x0b, 0x04, 0x0a, 0x78 };
  482. static const __u8 nset8[6] =
  483. { 0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00 };
  484. static const __u8 nset10[6] =
  485. { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 };
  486. t16RegWrite(dev, 0x01, 0x0000, n1, 0x06);
  487. t16RegWrite(dev, 0x01, 0x0000, nset, 0x06);
  488. t16RegRead(dev, 0x0063, &test_byte, 1);
  489. t16RegWrite(dev, 0x01, 0x0000, n2, 0x02);
  490. while (read_indexs[i] != 0x00) {
  491. t16RegRead(dev, read_indexs[i], &test_byte, 1);
  492. PDEBUG(D_CONF, "Reg 0x%x => 0x%x", read_indexs[i],
  493. test_byte);
  494. i++;
  495. }
  496. t16RegWrite(dev, 0x01, 0x0000, n3, 0x06);
  497. t16RegWrite(dev, 0x01, 0x0000, n4, 0x46);
  498. t16RegRead(dev, 0x0080, &test_byte, 1);
  499. t16RegWrite(dev, 0x00, 0x2c80, NULL, 0);
  500. t16RegWrite(dev, 0x01, 0x0000, nset2, 0x14);
  501. t16RegWrite(dev, 0x01, 0x0000, nset3, 0x12);
  502. t16RegWrite(dev, 0x01, 0x0000, nset4, 0x12);
  503. t16RegWrite(dev, 0x00, 0x3880, NULL, 0);
  504. t16RegWrite(dev, 0x00, 0x3880, NULL, 0);
  505. t16RegWrite(dev, 0x00, 0x338e, NULL, 0);
  506. t16RegWrite(dev, 0x01, 0x0000, nset5, 0x04);
  507. t16RegWrite(dev, 0x00, 0x00a9, NULL, 0);
  508. t16RegWrite(dev, 0x01, 0x0000, nset6, 0x22);
  509. t16RegWrite(dev, 0x00, 0x86bb, NULL, 0);
  510. t16RegWrite(dev, 0x00, 0x4aa6, NULL, 0);
  511. t16RegWrite(dev, 0x01, 0x0000, missing, 0x08);
  512. t16RegWrite(dev, 0x00, 0x2087, NULL, 0);
  513. t16RegWrite(dev, 0x00, 0x2088, NULL, 0);
  514. t16RegWrite(dev, 0x00, 0x2089, NULL, 0);
  515. t16RegWrite(dev, 0x01, 0x0000, nset7, 0x04);
  516. t16RegWrite(dev, 0x01, 0x0000, nset10, 0x06);
  517. t16RegWrite(dev, 0x01, 0x0000, nset8, 0x06);
  518. t16RegWrite(dev, 0x01, 0x0000, nset9, 0x04);
  519. t16RegWrite(dev, 0x00, 0x2880, NULL, 0);
  520. t16RegWrite(dev, 0x01, 0x0000, nset2, 0x14);
  521. t16RegWrite(dev, 0x01, 0x0000, nset3, 0x12);
  522. t16RegWrite(dev, 0x01, 0x0000, nset4, 0x12);
  523. return 0;
  524. }
  525. static void setbrightness(struct gspca_dev *gspca_dev)
  526. {
  527. struct sd *sd = (struct sd *) gspca_dev;
  528. struct usb_device *dev = gspca_dev->dev;
  529. unsigned int brightness;
  530. __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x80 };
  531. brightness = sd->brightness;
  532. if (brightness < 7) {
  533. set6[3] = 0x70 - (brightness * 0xa);
  534. } else {
  535. set6[1] = 0x24;
  536. set6[3] = 0x00 + ((brightness - 7) * 0xa);
  537. }
  538. t16RegWrite(dev, 0x01, 0x0000, set6, 4);
  539. }
  540. static void setflip(struct gspca_dev *gspca_dev)
  541. {
  542. struct sd *sd = (struct sd *) gspca_dev;
  543. struct usb_device *dev = gspca_dev->dev;
  544. __u8 flipcmd[8] =
  545. { 0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09 };
  546. if (sd->mirror == 1)
  547. flipcmd[3] = 0x01;
  548. t16RegWrite(dev, 0x01, 0x0000, flipcmd, 8);
  549. }
  550. static void seteffect(struct gspca_dev *gspca_dev)
  551. {
  552. struct sd *sd = (struct sd *) gspca_dev;
  553. struct usb_device *dev = gspca_dev->dev;
  554. t16RegWrite(dev, 0x01, 0x0000, effects_table[sd->effect], 0x06);
  555. if (sd->effect == 1 || sd->effect == 5) {
  556. PDEBUG(D_CONF,
  557. "This effect have been disabled for webcam \"safety\"");
  558. return;
  559. }
  560. if (sd->effect == 1 || sd->effect == 4)
  561. t16RegWrite(dev, 0x00, 0x4aa6, NULL, 0);
  562. else
  563. t16RegWrite(dev, 0x00, 0xfaa6, NULL, 0);
  564. }
  565. static void setwhitebalance(struct gspca_dev *gspca_dev)
  566. {
  567. struct sd *sd = (struct sd *) gspca_dev;
  568. struct usb_device *dev = gspca_dev->dev;
  569. __u8 white_balance[8] =
  570. { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 };
  571. if (sd->whitebalance == 1)
  572. white_balance[7] = 0x3c;
  573. t16RegWrite(dev, 0x01, 0x0000, white_balance, 8);
  574. }
  575. static void setlightfreq(struct gspca_dev *gspca_dev)
  576. {
  577. struct sd *sd = (struct sd *) gspca_dev;
  578. struct usb_device *dev = gspca_dev->dev;
  579. __u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
  580. if (sd->freq == 2) /* 60hz */
  581. freq[1] = 0x00;
  582. t16RegWrite(dev, 0x1, 0x0000, freq, 0x4);
  583. }
  584. static void setcontrast(struct gspca_dev *gspca_dev)
  585. {
  586. struct sd *sd = (struct sd *) gspca_dev;
  587. struct usb_device *dev = gspca_dev->dev;
  588. unsigned int contrast = sd->contrast;
  589. __u16 reg_to_write = 0x00;
  590. if (contrast < 7)
  591. reg_to_write = 0x8ea9 - (0x200 * contrast);
  592. else
  593. reg_to_write = (0x00a9 + ((contrast - 7) * 0x200));
  594. t16RegWrite(dev, 0x00, reg_to_write, NULL, 0);
  595. }
  596. static void setcolors(struct gspca_dev *gspca_dev)
  597. {
  598. struct sd *sd = (struct sd *) gspca_dev;
  599. struct usb_device *dev = gspca_dev->dev;
  600. __u16 reg_to_write;
  601. reg_to_write = 0xc0bb + sd->colors * 0x100;
  602. t16RegWrite(dev, 0x00, reg_to_write, NULL, 0);
  603. }
  604. static void setgamma(struct gspca_dev *gspca_dev)
  605. {
  606. }
  607. static void setsharpness(struct gspca_dev *gspca_dev)
  608. {
  609. struct sd *sd = (struct sd *) gspca_dev;
  610. struct usb_device *dev = gspca_dev->dev;
  611. __u16 reg_to_write;
  612. reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
  613. t16RegWrite(dev, 0x00, reg_to_write, NULL, 0);
  614. }
  615. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  616. {
  617. struct sd *sd = (struct sd *) gspca_dev;
  618. sd->brightness = val;
  619. if (gspca_dev->streaming)
  620. setbrightness(gspca_dev);
  621. return 0;
  622. }
  623. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  624. {
  625. struct sd *sd = (struct sd *) gspca_dev;
  626. *val = sd->brightness;
  627. return *val;
  628. }
  629. static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val)
  630. {
  631. struct sd *sd = (struct sd *) gspca_dev;
  632. sd->whitebalance = val;
  633. if (gspca_dev->streaming)
  634. setwhitebalance(gspca_dev);
  635. return 0;
  636. }
  637. static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val)
  638. {
  639. struct sd *sd = (struct sd *) gspca_dev;
  640. *val = sd->whitebalance;
  641. return *val;
  642. }
  643. static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val)
  644. {
  645. struct sd *sd = (struct sd *) gspca_dev;
  646. sd->mirror = val;
  647. if (gspca_dev->streaming)
  648. setflip(gspca_dev);
  649. return 0;
  650. }
  651. static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val)
  652. {
  653. struct sd *sd = (struct sd *) gspca_dev;
  654. *val = sd->mirror;
  655. return *val;
  656. }
  657. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val)
  658. {
  659. struct sd *sd = (struct sd *) gspca_dev;
  660. sd->effect = val;
  661. if (gspca_dev->streaming)
  662. seteffect(gspca_dev);
  663. return 0;
  664. }
  665. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val)
  666. {
  667. struct sd *sd = (struct sd *) gspca_dev;
  668. *val = sd->effect;
  669. return *val;
  670. }
  671. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  672. {
  673. struct sd *sd = (struct sd *) gspca_dev;
  674. sd->contrast = val;
  675. if (gspca_dev->streaming)
  676. setcontrast(gspca_dev);
  677. return 0;
  678. }
  679. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  680. {
  681. struct sd *sd = (struct sd *) gspca_dev;
  682. *val = sd->contrast;
  683. return *val;
  684. }
  685. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  686. {
  687. struct sd *sd = (struct sd *) gspca_dev;
  688. sd->colors = val;
  689. if (gspca_dev->streaming)
  690. setcolors(gspca_dev);
  691. return 0;
  692. }
  693. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  694. {
  695. struct sd *sd = (struct sd *) gspca_dev;
  696. *val = sd->colors;
  697. return 0;
  698. }
  699. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
  700. {
  701. struct sd *sd = (struct sd *) gspca_dev;
  702. sd->gamma = val;
  703. if (gspca_dev->streaming)
  704. setgamma(gspca_dev);
  705. return 0;
  706. }
  707. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
  708. {
  709. struct sd *sd = (struct sd *) gspca_dev;
  710. *val = sd->gamma;
  711. return 0;
  712. }
  713. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  714. {
  715. struct sd *sd = (struct sd *) gspca_dev;
  716. sd->freq = val;
  717. if (gspca_dev->streaming)
  718. setlightfreq(gspca_dev);
  719. return 0;
  720. }
  721. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  722. {
  723. struct sd *sd = (struct sd *) gspca_dev;
  724. *val = sd->freq;
  725. return 0;
  726. }
  727. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  728. {
  729. struct sd *sd = (struct sd *) gspca_dev;
  730. sd->sharpness = val;
  731. if (gspca_dev->streaming)
  732. setsharpness(gspca_dev);
  733. return 0;
  734. }
  735. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  736. {
  737. struct sd *sd = (struct sd *) gspca_dev;
  738. *val = sd->sharpness;
  739. return 0;
  740. }
  741. /* Low Light set here......*/
  742. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
  743. {
  744. struct sd *sd = (struct sd *) gspca_dev;
  745. struct usb_device *dev = gspca_dev->dev;
  746. sd->autogain = val;
  747. if (val != 0)
  748. t16RegWrite(dev, 0x00, 0xf48e, NULL, 0);
  749. else
  750. t16RegWrite(dev, 0x00, 0xb48e, NULL, 0);
  751. return 0;
  752. }
  753. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
  754. {
  755. struct sd *sd = (struct sd *) gspca_dev;
  756. *val = sd->autogain;
  757. return 0;
  758. }
  759. static void sd_start(struct gspca_dev *gspca_dev)
  760. {
  761. struct usb_device *dev = gspca_dev->dev;
  762. int mode;
  763. __u8 test_byte;
  764. static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
  765. __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  766. static const __u8 t3[] =
  767. { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06,
  768. 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
  769. static const __u8 t4[] = { 0x0b, 0x04, 0x0a, 0x40 };
  770. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
  771. switch (mode) {
  772. case 1: /* 352x288 */
  773. t2[1] = 0x40;
  774. break;
  775. case 2: /* 320x240 */
  776. t2[1] = 0x10;
  777. break;
  778. case 3: /* 176x144 */
  779. t2[1] = 0x50;
  780. break;
  781. case 4: /* 160x120 */
  782. t2[1] = 0x20;
  783. break;
  784. default: /* 640x480 (0x00) */
  785. break;
  786. }
  787. t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[0], 0x8);
  788. t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[1], 0x8);
  789. t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[2], 0x8);
  790. t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
  791. t16RegWrite(dev, 0x00, 0x3c80, NULL, 0);
  792. /* just in case and to keep sync with logs (for mine) */
  793. t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
  794. t16RegWrite(dev, 0x00, 0x3c80, NULL, 0);
  795. /* just in case and to keep sync with logs (for mine) */
  796. t16RegWrite(dev, 0x01, 0x0000, t1, 4);
  797. t16RegWrite(dev, 0x01, 0x0000, t2, 6);
  798. t16RegRead(dev, 0x0012, &test_byte, 0x01);
  799. t16RegWrite(dev, 0x01, 0x0000, t3, 0x10);
  800. t16RegWrite(dev, 0x00, 0x0013, NULL, 0);
  801. t16RegWrite(dev, 0x01, 0x0000, t4, 0x4);
  802. /* restart on each start, just in case, sometimes regs goes wrong
  803. * when using controls from app */
  804. setbrightness(gspca_dev);
  805. setcontrast(gspca_dev);
  806. setcolors(gspca_dev);
  807. }
  808. static void sd_stopN(struct gspca_dev *gspca_dev)
  809. {
  810. }
  811. static void sd_stop0(struct gspca_dev *gspca_dev)
  812. {
  813. }
  814. static void sd_close(struct gspca_dev *gspca_dev)
  815. {
  816. }
  817. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  818. struct gspca_frame *frame, /* target */
  819. __u8 *data, /* isoc packet */
  820. int len) /* iso packet length */
  821. {
  822. int sof = 0;
  823. static __u8 ffd9[] = { 0xff, 0xd9 };
  824. if (data[0] == 0x5a) {
  825. /* Control Packet, after this came the header again,
  826. * but extra bytes came in the packet before this,
  827. * sometimes an EOF arrives, sometimes not... */
  828. return;
  829. }
  830. if (data[len - 1] == 0xff && data[len] == 0xd9) {
  831. /* Just in case, i have seen packets with the marker,
  832. * other's do not include it... */
  833. data += 2;
  834. len -= 4;
  835. } else if (data[2] == 0xff && data[3] == 0xd8) {
  836. sof = 1;
  837. data += 2;
  838. len -= 2;
  839. } else {
  840. data += 2;
  841. len -= 2;
  842. }
  843. if (sof) {
  844. /* extra bytes....., could be processed too but would be
  845. * a waste of time, right now leave the application and
  846. * libjpeg do it for ourserlves.. */
  847. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  848. ffd9, 2);
  849. gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
  850. return;
  851. }
  852. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  853. }
  854. static int sd_querymenu(struct gspca_dev *gspca_dev,
  855. struct v4l2_querymenu *menu)
  856. {
  857. switch (menu->id) {
  858. case V4L2_CID_POWER_LINE_FREQUENCY:
  859. switch (menu->index) {
  860. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  861. strcpy((char *) menu->name, "50 Hz");
  862. return 0;
  863. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  864. strcpy((char *) menu->name, "60 Hz");
  865. return 0;
  866. }
  867. break;
  868. case V4L2_CID_EFFECTS:
  869. if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) {
  870. strncpy((char *) menu->name,
  871. effects_control[menu->index], 32);
  872. return 0;
  873. }
  874. break;
  875. }
  876. return -EINVAL;
  877. }
  878. /* this function is called at open time */
  879. static int sd_open(struct gspca_dev *gspca_dev)
  880. {
  881. init_default_parameters(gspca_dev);
  882. return 0;
  883. }
  884. /* sub-driver description */
  885. static const struct sd_desc sd_desc = {
  886. .name = MODULE_NAME,
  887. .ctrls = sd_ctrls,
  888. .nctrls = ARRAY_SIZE(sd_ctrls),
  889. .config = sd_config,
  890. .open = sd_open,
  891. .start = sd_start,
  892. .stopN = sd_stopN,
  893. .stop0 = sd_stop0,
  894. .close = sd_close,
  895. .pkt_scan = sd_pkt_scan,
  896. .querymenu = sd_querymenu,
  897. };
  898. /* -- module initialisation -- */
  899. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  900. static const __devinitdata struct usb_device_id device_table[] = {
  901. {USB_DEVICE(0x17a1, 0x0128), DVNM("XPX Webcam")},
  902. {}
  903. };
  904. MODULE_DEVICE_TABLE(usb, device_table);
  905. /* -- device connect -- */
  906. static int sd_probe(struct usb_interface *intf,
  907. const struct usb_device_id *id)
  908. {
  909. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  910. THIS_MODULE);
  911. }
  912. static struct usb_driver sd_driver = {
  913. .name = MODULE_NAME,
  914. .id_table = device_table,
  915. .probe = sd_probe,
  916. .disconnect = gspca_disconnect,
  917. };
  918. /* -- module insert / remove -- */
  919. static int __init sd_mod_init(void)
  920. {
  921. if (usb_register(&sd_driver) < 0)
  922. return -1;
  923. PDEBUG(D_PROBE, "v%s registered", version);
  924. return 0;
  925. }
  926. static void __exit sd_mod_exit(void)
  927. {
  928. usb_deregister(&sd_driver);
  929. PDEBUG(D_PROBE, "deregistered");
  930. }
  931. module_init(sd_mod_init);
  932. module_exit(sd_mod_exit);