t613.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /*
  2. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *Notes: * t613 + tas5130A
  19. * * Focus to light do not balance well as in win.
  20. * Quality in win is not good, but its kinda better.
  21. * * Fix some "extraneous bytes", most of apps will show the image anyway
  22. * * Gamma table, is there, but its really doing something?
  23. * * 7~8 Fps, its ok, max on win its 10.
  24. * Costantino Leandro
  25. */
  26. #define MODULE_NAME "t613"
  27. #include "gspca.h"
  28. #define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0)
  29. MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
  30. MODULE_DESCRIPTION("GSPCA/T613 (JPEG Compliance) USB Camera Driver");
  31. MODULE_LICENSE("GPL");
  32. struct sd {
  33. struct gspca_dev gspca_dev; /* !! must be the first item */
  34. u8 brightness;
  35. u8 contrast;
  36. u8 colors;
  37. u8 autogain;
  38. u8 gamma;
  39. u8 sharpness;
  40. u8 freq;
  41. u8 whitebalance;
  42. u8 mirror;
  43. u8 effect;
  44. u8 sensor;
  45. #define SENSOR_OM6802 0
  46. #define SENSOR_OTHER 1
  47. #define SENSOR_TAS5130A 2
  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. {
  74. {
  75. .id = V4L2_CID_BRIGHTNESS,
  76. .type = V4L2_CTRL_TYPE_INTEGER,
  77. .name = "Brightness",
  78. .minimum = 0,
  79. .maximum = 14,
  80. .step = 1,
  81. #define BRIGHTNESS_DEF 8
  82. .default_value = BRIGHTNESS_DEF,
  83. },
  84. .set = sd_setbrightness,
  85. .get = sd_getbrightness,
  86. },
  87. {
  88. {
  89. .id = V4L2_CID_CONTRAST,
  90. .type = V4L2_CTRL_TYPE_INTEGER,
  91. .name = "Contrast",
  92. .minimum = 0,
  93. .maximum = 0x0d,
  94. .step = 1,
  95. #define CONTRAST_DEF 0x07
  96. .default_value = CONTRAST_DEF,
  97. },
  98. .set = sd_setcontrast,
  99. .get = sd_getcontrast,
  100. },
  101. {
  102. {
  103. .id = V4L2_CID_SATURATION,
  104. .type = V4L2_CTRL_TYPE_INTEGER,
  105. .name = "Color",
  106. .minimum = 0,
  107. .maximum = 0x0f,
  108. .step = 1,
  109. #define COLORS_DEF 0x05
  110. .default_value = COLORS_DEF,
  111. },
  112. .set = sd_setcolors,
  113. .get = sd_getcolors,
  114. },
  115. #define GAMMA_MAX 16
  116. #define GAMMA_DEF 10
  117. {
  118. {
  119. .id = V4L2_CID_GAMMA, /* (gamma on win) */
  120. .type = V4L2_CTRL_TYPE_INTEGER,
  121. .name = "Gamma",
  122. .minimum = 0,
  123. .maximum = GAMMA_MAX - 1,
  124. .step = 1,
  125. .default_value = GAMMA_DEF,
  126. },
  127. .set = sd_setgamma,
  128. .get = sd_getgamma,
  129. },
  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. #define AUTOGAIN_DEF 0x01
  141. .default_value = AUTOGAIN_DEF,
  142. },
  143. .set = sd_setlowlight,
  144. .get = sd_getlowlight,
  145. },
  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. #define MIRROR_DEF 0
  155. .default_value = MIRROR_DEF,
  156. },
  157. .set = sd_setflip,
  158. .get = sd_getflip
  159. },
  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. #define FREQ_DEF 1
  169. .default_value = FREQ_DEF,
  170. },
  171. .set = sd_setfreq,
  172. .get = sd_getfreq},
  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. #define WHITE_BALANCE_DEF 0
  182. .default_value = WHITE_BALANCE_DEF,
  183. },
  184. .set = sd_setwhitebalance,
  185. .get = sd_getwhitebalance
  186. },
  187. {
  188. {
  189. .id = V4L2_CID_SHARPNESS,
  190. .type = V4L2_CTRL_TYPE_INTEGER,
  191. .name = "Sharpness",
  192. .minimum = 0,
  193. .maximum = 15,
  194. .step = 1,
  195. #define SHARPNESS_DEF 0x06
  196. .default_value = SHARPNESS_DEF,
  197. },
  198. .set = sd_setsharpness,
  199. .get = sd_getsharpness,
  200. },
  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. #define EFFECTS_DEF 0
  210. .default_value = EFFECTS_DEF,
  211. },
  212. .set = sd_seteffect,
  213. .get = sd_geteffect
  214. },
  215. };
  216. static char *effects_control[] = {
  217. "Normal",
  218. "Emboss", /* disabled */
  219. "Monochrome",
  220. "Sepia",
  221. "Sketch",
  222. "Sun Effect", /* disabled */
  223. "Negative",
  224. };
  225. static const struct v4l2_pix_format vga_mode_t16[] = {
  226. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  227. .bytesperline = 160,
  228. .sizeimage = 160 * 120 * 4 / 8 + 590,
  229. .colorspace = V4L2_COLORSPACE_JPEG,
  230. .priv = 4},
  231. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  232. .bytesperline = 176,
  233. .sizeimage = 176 * 144 * 3 / 8 + 590,
  234. .colorspace = V4L2_COLORSPACE_JPEG,
  235. .priv = 3},
  236. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  237. .bytesperline = 320,
  238. .sizeimage = 320 * 240 * 3 / 8 + 590,
  239. .colorspace = V4L2_COLORSPACE_JPEG,
  240. .priv = 2},
  241. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  242. .bytesperline = 352,
  243. .sizeimage = 352 * 288 * 3 / 8 + 590,
  244. .colorspace = V4L2_COLORSPACE_JPEG,
  245. .priv = 1},
  246. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  247. .bytesperline = 640,
  248. .sizeimage = 640 * 480 * 3 / 8 + 590,
  249. .colorspace = V4L2_COLORSPACE_JPEG,
  250. .priv = 0},
  251. };
  252. /* sensor specific data */
  253. struct additional_sensor_data {
  254. const u8 n3[6];
  255. const u8 *n4, n4sz;
  256. const u8 reg80, reg8e;
  257. const u8 nset8[6];
  258. const u8 data1[10];
  259. const u8 data2[9];
  260. const u8 data3[9];
  261. const u8 data4[4];
  262. const u8 data5[6];
  263. const u8 stream[4];
  264. };
  265. static const u8 n4_om6802[] = {
  266. 0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
  267. 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
  268. 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
  269. 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
  270. 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
  271. 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
  272. 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
  273. 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
  274. 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46
  275. };
  276. static const u8 n4_other[] = {
  277. 0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
  278. 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
  279. 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
  280. 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
  281. 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
  282. 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
  283. 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
  284. 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00
  285. };
  286. static const u8 n4_tas5130a[] = {
  287. 0x80, 0x3c, 0x81, 0x68, 0x83, 0xa0, 0x84, 0x20,
  288. 0x8a, 0x68, 0x8b, 0x58, 0x8c, 0x88, 0x8e, 0xb4,
  289. 0x8f, 0x24, 0xa1, 0xb1, 0xa2, 0x30, 0xa5, 0x10,
  290. 0xa6, 0x4a, 0xae, 0x03, 0xb1, 0x44, 0xb2, 0x08,
  291. 0xb7, 0x06, 0xb9, 0xe7, 0xbb, 0xc4, 0xbc, 0x4a,
  292. 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8,
  293. 0xc6, 0xda
  294. };
  295. static const struct additional_sensor_data sensor_data[] = {
  296. { /* 0: OM6802 */
  297. .n3 =
  298. {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04},
  299. .n4 = n4_om6802,
  300. .n4sz = sizeof n4_om6802,
  301. .reg80 = 0x3c,
  302. .reg8e = 0x33,
  303. .nset8 = {0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00},
  304. .data1 =
  305. {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06,
  306. 0xb3, 0xfc},
  307. .data2 =
  308. {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
  309. 0xff},
  310. .data3 =
  311. {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
  312. 0xff},
  313. .data4 = /*Freq (50/60Hz). Splitted for test purpose */
  314. {0x66, 0xca, 0xa8, 0xf0},
  315. .data5 = /* this could be removed later */
  316. {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
  317. .stream =
  318. {0x0b, 0x04, 0x0a, 0x78},
  319. },
  320. { /* 1: OTHER */
  321. .n3 =
  322. {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00},
  323. .n4 = n4_other,
  324. .n4sz = sizeof n4_other,
  325. .reg80 = 0xac,
  326. .reg8e = 0xb8,
  327. .nset8 = {0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00},
  328. .data1 =
  329. {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a,
  330. 0xe8, 0xfc},
  331. .data2 =
  332. {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
  333. 0xd9},
  334. .data3 =
  335. {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
  336. 0xd9},
  337. .data4 =
  338. {0x66, 0x00, 0xa8, 0xa8},
  339. .data5 =
  340. {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69},
  341. .stream =
  342. {0x0b, 0x04, 0x0a, 0x00},
  343. },
  344. { /* 2: TAS5130A */
  345. .n3 =
  346. {0x61, 0xc2, 0x65, 0x0d, 0x60, 0x08},
  347. .n4 = n4_tas5130a,
  348. .n4sz = sizeof n4_tas5130a,
  349. .reg80 = 0x3c,
  350. .reg8e = 0xb4,
  351. .nset8 = {0xa8, 0xf0, 0xc6, 0xda, 0xc0, 0x00},
  352. .data1 =
  353. {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27,
  354. 0xc8, 0xfc},
  355. .data2 =
  356. {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
  357. 0xe0},
  358. .data3 =
  359. {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
  360. 0xe0},
  361. .data4 = /* Freq (50/60Hz). Splitted for test purpose */
  362. {0x66, 0x00, 0xa8, 0xe8},
  363. .data5 =
  364. {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20},
  365. .stream =
  366. {0x0b, 0x04, 0x0a, 0x40},
  367. },
  368. };
  369. #define MAX_EFFECTS 7
  370. /* easily done by soft, this table could be removed,
  371. * i keep it here just in case */
  372. static const u8 effects_table[MAX_EFFECTS][6] = {
  373. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
  374. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
  375. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
  376. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */
  377. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */
  378. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */
  379. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
  380. };
  381. static const u8 gamma_table[GAMMA_MAX][17] = {
  382. {0x00, 0x3e, 0x69, 0x85, 0x95, 0xa1, 0xae, 0xb9, /* 0 */
  383. 0xc2, 0xcb, 0xd4, 0xdb, 0xe3, 0xea, 0xf1, 0xf8,
  384. 0xff},
  385. {0x00, 0x33, 0x5a, 0x75, 0x85, 0x93, 0xa1, 0xad, /* 1 */
  386. 0xb7, 0xc2, 0xcb, 0xd4, 0xde, 0xe7, 0xf0, 0xf7,
  387. 0xff},
  388. {0x00, 0x2f, 0x51, 0x6b, 0x7c, 0x8a, 0x99, 0xa6, /* 2 */
  389. 0xb1, 0xbc, 0xc6, 0xd0, 0xdb, 0xe4, 0xed, 0xf6,
  390. 0xff},
  391. {0x00, 0x29, 0x48, 0x60, 0x72, 0x81, 0x90, 0x9e, /* 3 */
  392. 0xaa, 0xb5, 0xbf, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
  393. 0xff},
  394. {0x00, 0x23, 0x3f, 0x55, 0x68, 0x77, 0x86, 0x95, /* 4 */
  395. 0xa2, 0xad, 0xb9, 0xc6, 0xd2, 0xde, 0xe9, 0xf4,
  396. 0xff},
  397. {0x00, 0x1b, 0x33, 0x48, 0x59, 0x69, 0x79, 0x87, /* 5 */
  398. 0x96, 0xa3, 0xb1, 0xbe, 0xcc, 0xda, 0xe7, 0xf3,
  399. 0xff},
  400. {0x00, 0x02, 0x10, 0x20, 0x32, 0x40, 0x57, 0x67, /* 6 */
  401. 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
  402. 0xff},
  403. {0x00, 0x02, 0x14, 0x26, 0x38, 0x4a, 0x60, 0x70, /* 7 */
  404. 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
  405. 0xff},
  406. {0x00, 0x10, 0x22, 0x35, 0x47, 0x5a, 0x69, 0x79, /* 8 */
  407. 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe0, 0xf0,
  408. 0xff},
  409. {0x00, 0x10, 0x26, 0x40, 0x54, 0x65, 0x75, 0x84, /* 9 */
  410. 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd6, 0xe0, 0xf0,
  411. 0xff},
  412. {0x00, 0x18, 0x2b, 0x44, 0x60, 0x70, 0x80, 0x8e, /* 10 */
  413. 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xd8, 0xe2, 0xf0,
  414. 0xff},
  415. {0x00, 0x1a, 0x34, 0x52, 0x66, 0x7e, 0x8d, 0x9b, /* 11 */
  416. 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
  417. 0xff},
  418. {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
  419. 0xb4, 0xbf, 0xc9, 0xd3, 0xdc, 0xe5, 0xee, 0xf6,
  420. 0xff},
  421. {0x00, 0x54, 0x6f, 0x83, 0x93, 0xa0, 0xad, 0xb7, /* 13 */
  422. 0xc2, 0xcb, 0xd4, 0xdc, 0xe4, 0xeb, 0xf2, 0xf9,
  423. 0xff},
  424. {0x00, 0x6e, 0x88, 0x9a, 0xa8, 0xb3, 0xbd, 0xc6, /* 14 */
  425. 0xcf, 0xd6, 0xdd, 0xe3, 0xe9, 0xef, 0xf4, 0xfa,
  426. 0xff},
  427. {0x00, 0x93, 0xa8, 0xb7, 0xc1, 0xca, 0xd2, 0xd8, /* 15 */
  428. 0xde, 0xe3, 0xe8, 0xed, 0xf1, 0xf5, 0xf8, 0xfc,
  429. 0xff}
  430. };
  431. static const u8 tas5130a_sensor_init[][8] = {
  432. {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
  433. {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
  434. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  435. };
  436. static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
  437. /* read 1 byte */
  438. static u8 reg_r(struct gspca_dev *gspca_dev,
  439. u16 index)
  440. {
  441. usb_control_msg(gspca_dev->dev,
  442. usb_rcvctrlpipe(gspca_dev->dev, 0),
  443. 0, /* request */
  444. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  445. 0, /* value */
  446. index,
  447. gspca_dev->usb_buf, 1, 500);
  448. return gspca_dev->usb_buf[0];
  449. }
  450. static void reg_w(struct gspca_dev *gspca_dev,
  451. u16 index)
  452. {
  453. usb_control_msg(gspca_dev->dev,
  454. usb_sndctrlpipe(gspca_dev->dev, 0),
  455. 0,
  456. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  457. 0, index,
  458. NULL, 0, 500);
  459. }
  460. static void reg_w_buf(struct gspca_dev *gspca_dev,
  461. const u8 *buffer, u16 len)
  462. {
  463. if (len <= USB_BUF_SZ) {
  464. memcpy(gspca_dev->usb_buf, buffer, len);
  465. usb_control_msg(gspca_dev->dev,
  466. usb_sndctrlpipe(gspca_dev->dev, 0),
  467. 0,
  468. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  469. 0x01, 0,
  470. gspca_dev->usb_buf, len, 500);
  471. } else {
  472. u8 *tmpbuf;
  473. tmpbuf = kmalloc(len, GFP_KERNEL);
  474. memcpy(tmpbuf, buffer, len);
  475. usb_control_msg(gspca_dev->dev,
  476. usb_sndctrlpipe(gspca_dev->dev, 0),
  477. 0,
  478. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  479. 0x01, 0,
  480. tmpbuf, len, 500);
  481. kfree(tmpbuf);
  482. }
  483. }
  484. /* write values to consecutive registers */
  485. static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
  486. u8 reg,
  487. const u8 *buffer, u16 len)
  488. {
  489. int i;
  490. u8 *p, *tmpbuf;
  491. if (len * 2 <= USB_BUF_SZ)
  492. p = tmpbuf = gspca_dev->usb_buf;
  493. else
  494. p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
  495. i = len;
  496. while (--i >= 0) {
  497. *p++ = reg++;
  498. *p++ = *buffer++;
  499. }
  500. usb_control_msg(gspca_dev->dev,
  501. usb_sndctrlpipe(gspca_dev->dev, 0),
  502. 0,
  503. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  504. 0x01, 0,
  505. tmpbuf, len * 2, 500);
  506. if (len * 2 > USB_BUF_SZ)
  507. kfree(tmpbuf);
  508. }
  509. /* Reported as OM6802*/
  510. static void om6802_sensor_init(struct gspca_dev *gspca_dev)
  511. {
  512. int i;
  513. const u8 *p;
  514. u8 byte;
  515. u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
  516. static const u8 sensor_init[] = {
  517. 0xdf, 0x6d,
  518. 0xdd, 0x18,
  519. 0x5a, 0xe0,
  520. 0x5c, 0x07,
  521. 0x5d, 0xb0,
  522. 0x5e, 0x1e,
  523. 0x60, 0x71,
  524. 0xef, 0x00,
  525. 0xe9, 0x00,
  526. 0xea, 0x00,
  527. 0x90, 0x24,
  528. 0x91, 0xb2,
  529. 0x82, 0x32,
  530. 0xfd, 0x41,
  531. 0x00 /* table end */
  532. };
  533. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  534. msleep(100);
  535. i = 4;
  536. while (--i > 0) {
  537. byte = reg_r(gspca_dev, 0x0060);
  538. if (!(byte & 0x01))
  539. break;
  540. msleep(100);
  541. }
  542. byte = reg_r(gspca_dev, 0x0063);
  543. if (byte != 0x17) {
  544. err("Bad sensor reset %02x", byte);
  545. /* continue? */
  546. }
  547. p = sensor_init;
  548. while (*p != 0) {
  549. val[1] = *p++;
  550. val[3] = *p++;
  551. if (*p == 0)
  552. reg_w(gspca_dev, 0x3c80);
  553. reg_w_buf(gspca_dev, val, sizeof val);
  554. i = 4;
  555. while (--i >= 0) {
  556. msleep(15);
  557. byte = reg_r(gspca_dev, 0x60);
  558. if (!(byte & 0x01))
  559. break;
  560. }
  561. }
  562. msleep(15);
  563. reg_w(gspca_dev, 0x3c80);
  564. }
  565. /* this function is called at probe time */
  566. static int sd_config(struct gspca_dev *gspca_dev,
  567. const struct usb_device_id *id)
  568. {
  569. struct sd *sd = (struct sd *) gspca_dev;
  570. struct cam *cam;
  571. cam = &gspca_dev->cam;
  572. cam->cam_mode = vga_mode_t16;
  573. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  574. sd->brightness = BRIGHTNESS_DEF;
  575. sd->contrast = CONTRAST_DEF;
  576. sd->colors = COLORS_DEF;
  577. sd->gamma = GAMMA_DEF;
  578. sd->autogain = AUTOGAIN_DEF;
  579. sd->mirror = MIRROR_DEF;
  580. sd->freq = FREQ_DEF;
  581. sd->whitebalance = WHITE_BALANCE_DEF;
  582. sd->sharpness = SHARPNESS_DEF;
  583. sd->effect = EFFECTS_DEF;
  584. return 0;
  585. }
  586. static void setbrightness(struct gspca_dev *gspca_dev)
  587. {
  588. struct sd *sd = (struct sd *) gspca_dev;
  589. unsigned int brightness;
  590. u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
  591. brightness = sd->brightness;
  592. if (brightness < 7) {
  593. set6[1] = 0x26;
  594. set6[3] = 0x70 - brightness * 0x10;
  595. } else {
  596. set6[3] = 0x00 + ((brightness - 7) * 0x10);
  597. }
  598. reg_w_buf(gspca_dev, set6, sizeof set6);
  599. }
  600. static void setcontrast(struct gspca_dev *gspca_dev)
  601. {
  602. struct sd *sd = (struct sd *) gspca_dev;
  603. unsigned int contrast = sd->contrast;
  604. u16 reg_to_write;
  605. if (contrast < 7)
  606. reg_to_write = 0x8ea9 - contrast * 0x200;
  607. else
  608. reg_to_write = 0x00a9 + (contrast - 7) * 0x200;
  609. reg_w(gspca_dev, reg_to_write);
  610. }
  611. static void setcolors(struct gspca_dev *gspca_dev)
  612. {
  613. struct sd *sd = (struct sd *) gspca_dev;
  614. u16 reg_to_write;
  615. reg_to_write = 0x80bb + sd->colors * 0x100; /* was 0xc0 */
  616. reg_w(gspca_dev, reg_to_write);
  617. }
  618. static void setgamma(struct gspca_dev *gspca_dev)
  619. {
  620. struct sd *sd = (struct sd *) gspca_dev;
  621. PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
  622. reg_w_ixbuf(gspca_dev, 0x90,
  623. gamma_table[sd->gamma], sizeof gamma_table[0]);
  624. }
  625. static void setwhitebalance(struct gspca_dev *gspca_dev)
  626. {
  627. struct sd *sd = (struct sd *) gspca_dev;
  628. u8 white_balance[8] =
  629. {0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38};
  630. if (sd->whitebalance)
  631. white_balance[7] = 0x3c;
  632. reg_w_buf(gspca_dev, white_balance, sizeof white_balance);
  633. }
  634. static void setsharpness(struct gspca_dev *gspca_dev)
  635. {
  636. struct sd *sd = (struct sd *) gspca_dev;
  637. u16 reg_to_write;
  638. reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
  639. reg_w(gspca_dev, reg_to_write);
  640. }
  641. /* this function is called at probe and resume time */
  642. static int sd_init(struct gspca_dev *gspca_dev)
  643. {
  644. /* some of this registers are not really neded, because
  645. * they are overriden by setbrigthness, setcontrast, etc,
  646. * but wont hurt anyway, and can help someone with similar webcam
  647. * to see the initial parameters.*/
  648. struct sd *sd = (struct sd *) gspca_dev;
  649. const struct additional_sensor_data *sensor;
  650. int i;
  651. u16 sensor_id;
  652. u8 test_byte = 0;
  653. static const u8 read_indexs[] =
  654. { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  655. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 };
  656. static const u8 n1[] =
  657. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  658. static const u8 n2[] =
  659. {0x08, 0x00};
  660. sensor_id = (reg_r(gspca_dev, 0x06) << 8)
  661. | reg_r(gspca_dev, 0x07);
  662. switch (sensor_id & 0xff0f) {
  663. case 0x0801:
  664. PDEBUG(D_PROBE, "sensor tas5130a");
  665. sd->sensor = SENSOR_TAS5130A;
  666. break;
  667. case 0x0803:
  668. PDEBUG(D_PROBE, "sensor 'other'");
  669. sd->sensor = SENSOR_OTHER;
  670. break;
  671. case 0x0807:
  672. PDEBUG(D_PROBE, "sensor om6802");
  673. sd->sensor = SENSOR_OM6802;
  674. break;
  675. default:
  676. PDEBUG(D_ERR|D_PROBE, "unknown sensor %04x", sensor_id);
  677. return -EINVAL;
  678. }
  679. if (sd->sensor == SENSOR_OM6802) {
  680. reg_w_buf(gspca_dev, n1, sizeof n1);
  681. i = 5;
  682. while (--i >= 0) {
  683. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  684. test_byte = reg_r(gspca_dev, 0x0063);
  685. msleep(100);
  686. if (test_byte == 0x17)
  687. break; /* OK */
  688. }
  689. if (i < 0) {
  690. err("Bad sensor reset %02x", test_byte);
  691. return -EIO;
  692. }
  693. reg_w_buf(gspca_dev, n2, sizeof n2);
  694. }
  695. i = 0;
  696. while (read_indexs[i] != 0x00) {
  697. test_byte = reg_r(gspca_dev, read_indexs[i]);
  698. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
  699. test_byte);
  700. i++;
  701. }
  702. sensor = &sensor_data[sd->sensor];
  703. reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3);
  704. reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
  705. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  706. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  707. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  708. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  709. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  710. reg_w(gspca_dev, (sensor->reg8e << 8) + 0x8e);
  711. setbrightness(gspca_dev);
  712. setcontrast(gspca_dev);
  713. setgamma(gspca_dev);
  714. setcolors(gspca_dev);
  715. setsharpness(gspca_dev);
  716. setwhitebalance(gspca_dev);
  717. reg_w(gspca_dev, 0x2087); /* tied to white balance? */
  718. reg_w(gspca_dev, 0x2088);
  719. reg_w(gspca_dev, 0x2089);
  720. reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4);
  721. reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5);
  722. reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
  723. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  724. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  725. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  726. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  727. return 0;
  728. }
  729. static void setflip(struct gspca_dev *gspca_dev)
  730. {
  731. struct sd *sd = (struct sd *) gspca_dev;
  732. u8 flipcmd[8] =
  733. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
  734. if (sd->mirror)
  735. flipcmd[3] = 0x01;
  736. reg_w_buf(gspca_dev, flipcmd, sizeof flipcmd);
  737. }
  738. static void seteffect(struct gspca_dev *gspca_dev)
  739. {
  740. struct sd *sd = (struct sd *) gspca_dev;
  741. reg_w_buf(gspca_dev, effects_table[sd->effect],
  742. sizeof effects_table[0]);
  743. if (sd->effect == 1 || sd->effect == 5) {
  744. PDEBUG(D_CONF,
  745. "This effect have been disabled for webcam \"safety\"");
  746. return;
  747. }
  748. if (sd->effect == 1 || sd->effect == 4)
  749. reg_w(gspca_dev, 0x4aa6);
  750. else
  751. reg_w(gspca_dev, 0xfaa6);
  752. }
  753. static void setlightfreq(struct gspca_dev *gspca_dev)
  754. {
  755. struct sd *sd = (struct sd *) gspca_dev;
  756. u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
  757. if (sd->freq == 2) /* 60hz */
  758. freq[1] = 0x00;
  759. reg_w_buf(gspca_dev, freq, sizeof freq);
  760. }
  761. /* Is this really needed?
  762. * i added some module parameters for test with some users */
  763. static void poll_sensor(struct gspca_dev *gspca_dev)
  764. {
  765. static const u8 poll1[] =
  766. {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
  767. 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
  768. 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01,
  769. 0x60, 0x14};
  770. static const u8 poll2[] =
  771. {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
  772. 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
  773. static const u8 poll3[] =
  774. {0x87, 0x3f, 0x88, 0x20, 0x89, 0x2d};
  775. static const u8 poll4[] =
  776. {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
  777. 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
  778. 0xc2, 0x80, 0xc3, 0x10};
  779. PDEBUG(D_STREAM, "[Sensor requires polling]");
  780. reg_w_buf(gspca_dev, poll1, sizeof poll1);
  781. reg_w_buf(gspca_dev, poll2, sizeof poll2);
  782. reg_w_buf(gspca_dev, poll3, sizeof poll3);
  783. reg_w_buf(gspca_dev, poll4, sizeof poll4);
  784. }
  785. static int sd_start(struct gspca_dev *gspca_dev)
  786. {
  787. struct sd *sd = (struct sd *) gspca_dev;
  788. const struct additional_sensor_data *sensor;
  789. int i, mode;
  790. u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  791. static const u8 t3[] =
  792. { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
  793. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  794. switch (mode) {
  795. case 0: /* 640x480 (0x00) */
  796. break;
  797. case 1: /* 352x288 */
  798. t2[1] = 0x40;
  799. break;
  800. case 2: /* 320x240 */
  801. t2[1] = 0x10;
  802. break;
  803. case 3: /* 176x144 */
  804. t2[1] = 0x50;
  805. break;
  806. default:
  807. /* case 4: * 160x120 */
  808. t2[1] = 0x20;
  809. break;
  810. }
  811. switch (sd->sensor) {
  812. case SENSOR_OM6802:
  813. om6802_sensor_init(gspca_dev);
  814. break;
  815. case SENSOR_OTHER:
  816. break;
  817. default:
  818. /* case SENSOR_TAS5130A: */
  819. i = 0;
  820. for (;;) {
  821. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  822. sizeof tas5130a_sensor_init[0]);
  823. if (i >= ARRAY_SIZE(tas5130a_sensor_init) - 1)
  824. break;
  825. i++;
  826. }
  827. reg_w(gspca_dev, 0x3c80);
  828. /* just in case and to keep sync with logs (for mine) */
  829. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  830. sizeof tas5130a_sensor_init[0]);
  831. reg_w(gspca_dev, 0x3c80);
  832. break;
  833. }
  834. sensor = &sensor_data[sd->sensor];
  835. reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4);
  836. reg_r(gspca_dev, 0x0012);
  837. reg_w_buf(gspca_dev, t2, sizeof t2);
  838. reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
  839. reg_w(gspca_dev, 0x0013);
  840. msleep(15);
  841. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  842. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  843. if (sd->sensor == SENSOR_OM6802)
  844. poll_sensor(gspca_dev);
  845. return 0;
  846. }
  847. static void sd_stopN(struct gspca_dev *gspca_dev)
  848. {
  849. struct sd *sd = (struct sd *) gspca_dev;
  850. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  851. sizeof sensor_data[sd->sensor].stream);
  852. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  853. sizeof sensor_data[sd->sensor].stream);
  854. if (sd->sensor == SENSOR_OM6802) {
  855. msleep(20);
  856. reg_w(gspca_dev, 0x0309);
  857. }
  858. }
  859. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  860. u8 *data, /* isoc packet */
  861. int len) /* iso packet length */
  862. {
  863. static u8 ffd9[] = { 0xff, 0xd9 };
  864. if (data[0] == 0x5a) {
  865. /* Control Packet, after this came the header again,
  866. * but extra bytes came in the packet before this,
  867. * sometimes an EOF arrives, sometimes not... */
  868. return;
  869. }
  870. data += 2;
  871. len -= 2;
  872. if (data[0] == 0xff && data[1] == 0xd8) {
  873. /* extra bytes....., could be processed too but would be
  874. * a waste of time, right now leave the application and
  875. * libjpeg do it for ourserlves.. */
  876. gspca_frame_add(gspca_dev, LAST_PACKET,
  877. ffd9, 2);
  878. gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
  879. return;
  880. }
  881. if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
  882. /* Just in case, i have seen packets with the marker,
  883. * other's do not include it... */
  884. len -= 2;
  885. }
  886. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  887. }
  888. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  889. {
  890. struct sd *sd = (struct sd *) gspca_dev;
  891. sd->brightness = val;
  892. if (gspca_dev->streaming)
  893. setbrightness(gspca_dev);
  894. return 0;
  895. }
  896. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  897. {
  898. struct sd *sd = (struct sd *) gspca_dev;
  899. *val = sd->brightness;
  900. return *val;
  901. }
  902. static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val)
  903. {
  904. struct sd *sd = (struct sd *) gspca_dev;
  905. sd->whitebalance = val;
  906. if (gspca_dev->streaming)
  907. setwhitebalance(gspca_dev);
  908. return 0;
  909. }
  910. static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val)
  911. {
  912. struct sd *sd = (struct sd *) gspca_dev;
  913. *val = sd->whitebalance;
  914. return *val;
  915. }
  916. static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val)
  917. {
  918. struct sd *sd = (struct sd *) gspca_dev;
  919. sd->mirror = val;
  920. if (gspca_dev->streaming)
  921. setflip(gspca_dev);
  922. return 0;
  923. }
  924. static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val)
  925. {
  926. struct sd *sd = (struct sd *) gspca_dev;
  927. *val = sd->mirror;
  928. return *val;
  929. }
  930. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val)
  931. {
  932. struct sd *sd = (struct sd *) gspca_dev;
  933. sd->effect = val;
  934. if (gspca_dev->streaming)
  935. seteffect(gspca_dev);
  936. return 0;
  937. }
  938. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val)
  939. {
  940. struct sd *sd = (struct sd *) gspca_dev;
  941. *val = sd->effect;
  942. return *val;
  943. }
  944. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  945. {
  946. struct sd *sd = (struct sd *) gspca_dev;
  947. sd->contrast = val;
  948. if (gspca_dev->streaming)
  949. setcontrast(gspca_dev);
  950. return 0;
  951. }
  952. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  953. {
  954. struct sd *sd = (struct sd *) gspca_dev;
  955. *val = sd->contrast;
  956. return *val;
  957. }
  958. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  959. {
  960. struct sd *sd = (struct sd *) gspca_dev;
  961. sd->colors = val;
  962. if (gspca_dev->streaming)
  963. setcolors(gspca_dev);
  964. return 0;
  965. }
  966. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  967. {
  968. struct sd *sd = (struct sd *) gspca_dev;
  969. *val = sd->colors;
  970. return 0;
  971. }
  972. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
  973. {
  974. struct sd *sd = (struct sd *) gspca_dev;
  975. sd->gamma = val;
  976. if (gspca_dev->streaming)
  977. setgamma(gspca_dev);
  978. return 0;
  979. }
  980. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
  981. {
  982. struct sd *sd = (struct sd *) gspca_dev;
  983. *val = sd->gamma;
  984. return 0;
  985. }
  986. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  987. {
  988. struct sd *sd = (struct sd *) gspca_dev;
  989. sd->freq = val;
  990. if (gspca_dev->streaming)
  991. setlightfreq(gspca_dev);
  992. return 0;
  993. }
  994. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  995. {
  996. struct sd *sd = (struct sd *) gspca_dev;
  997. *val = sd->freq;
  998. return 0;
  999. }
  1000. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1001. {
  1002. struct sd *sd = (struct sd *) gspca_dev;
  1003. sd->sharpness = val;
  1004. if (gspca_dev->streaming)
  1005. setsharpness(gspca_dev);
  1006. return 0;
  1007. }
  1008. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1009. {
  1010. struct sd *sd = (struct sd *) gspca_dev;
  1011. *val = sd->sharpness;
  1012. return 0;
  1013. }
  1014. /* Low Light set here......*/
  1015. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
  1016. {
  1017. struct sd *sd = (struct sd *) gspca_dev;
  1018. sd->autogain = val;
  1019. if (val != 0)
  1020. reg_w(gspca_dev, 0xf48e);
  1021. else
  1022. reg_w(gspca_dev, 0xb48e);
  1023. return 0;
  1024. }
  1025. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
  1026. {
  1027. struct sd *sd = (struct sd *) gspca_dev;
  1028. *val = sd->autogain;
  1029. return 0;
  1030. }
  1031. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1032. struct v4l2_querymenu *menu)
  1033. {
  1034. switch (menu->id) {
  1035. case V4L2_CID_POWER_LINE_FREQUENCY:
  1036. switch (menu->index) {
  1037. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  1038. strcpy((char *) menu->name, "50 Hz");
  1039. return 0;
  1040. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  1041. strcpy((char *) menu->name, "60 Hz");
  1042. return 0;
  1043. }
  1044. break;
  1045. case V4L2_CID_EFFECTS:
  1046. if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) {
  1047. strncpy((char *) menu->name,
  1048. effects_control[menu->index], 32);
  1049. return 0;
  1050. }
  1051. break;
  1052. }
  1053. return -EINVAL;
  1054. }
  1055. /* sub-driver description */
  1056. static const struct sd_desc sd_desc = {
  1057. .name = MODULE_NAME,
  1058. .ctrls = sd_ctrls,
  1059. .nctrls = ARRAY_SIZE(sd_ctrls),
  1060. .config = sd_config,
  1061. .init = sd_init,
  1062. .start = sd_start,
  1063. .stopN = sd_stopN,
  1064. .pkt_scan = sd_pkt_scan,
  1065. .querymenu = sd_querymenu,
  1066. };
  1067. /* -- module initialisation -- */
  1068. static const __devinitdata struct usb_device_id device_table[] = {
  1069. {USB_DEVICE(0x17a1, 0x0128)},
  1070. {}
  1071. };
  1072. MODULE_DEVICE_TABLE(usb, device_table);
  1073. /* -- device connect -- */
  1074. static int sd_probe(struct usb_interface *intf,
  1075. const struct usb_device_id *id)
  1076. {
  1077. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1078. THIS_MODULE);
  1079. }
  1080. static struct usb_driver sd_driver = {
  1081. .name = MODULE_NAME,
  1082. .id_table = device_table,
  1083. .probe = sd_probe,
  1084. .disconnect = gspca_disconnect,
  1085. #ifdef CONFIG_PM
  1086. .suspend = gspca_suspend,
  1087. .resume = gspca_resume,
  1088. #endif
  1089. };
  1090. /* -- module insert / remove -- */
  1091. static int __init sd_mod_init(void)
  1092. {
  1093. int ret;
  1094. ret = usb_register(&sd_driver);
  1095. if (ret < 0)
  1096. return ret;
  1097. PDEBUG(D_PROBE, "registered");
  1098. return 0;
  1099. }
  1100. static void __exit sd_mod_exit(void)
  1101. {
  1102. usb_deregister(&sd_driver);
  1103. PDEBUG(D_PROBE, "deregistered");
  1104. }
  1105. module_init(sd_mod_init);
  1106. module_exit(sd_mod_exit);