t613.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. /*
  2. * T613 subdriver
  3. *
  4. * Copyright (C) 2010 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. *Notes: * t613 + tas5130A
  21. * * Focus to light do not balance well as in win.
  22. * Quality in win is not good, but its kinda better.
  23. * * Fix some "extraneous bytes", most of apps will show the image anyway
  24. * * Gamma table, is there, but its really doing something?
  25. * * 7~8 Fps, its ok, max on win its 10.
  26. * Costantino Leandro
  27. */
  28. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #define MODULE_NAME "t613"
  30. #include <linux/input.h>
  31. #include <linux/slab.h>
  32. #include "gspca.h"
  33. #define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0)
  34. MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
  35. MODULE_DESCRIPTION("GSPCA/T613 (JPEG Compliance) USB Camera Driver");
  36. MODULE_LICENSE("GPL");
  37. struct sd {
  38. struct gspca_dev gspca_dev; /* !! must be the first item */
  39. u8 brightness;
  40. u8 contrast;
  41. u8 colors;
  42. u8 autogain;
  43. u8 gamma;
  44. u8 sharpness;
  45. u8 freq;
  46. u8 red_gain;
  47. u8 blue_gain;
  48. u8 green_gain;
  49. u8 awb; /* set default r/g/b and activate */
  50. u8 mirror;
  51. u8 effect;
  52. u8 sensor;
  53. u8 button_pressed;
  54. };
  55. enum sensors {
  56. SENSOR_OM6802,
  57. SENSOR_OTHER,
  58. SENSOR_TAS5130A,
  59. SENSOR_LT168G, /* must verify if this is the actual model */
  60. };
  61. /* V4L2 controls supported by the driver */
  62. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  63. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  64. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  65. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  66. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  67. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  68. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val);
  69. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val);
  70. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  76. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
  77. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
  78. static int sd_setblue_gain(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_getblue_gain(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_setred_gain(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_getred_gain(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_setmirror(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_getmirror(struct gspca_dev *gspca_dev, __s32 *val);
  86. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val);
  87. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val);
  88. static const struct ctrl sd_ctrls[] = {
  89. {
  90. {
  91. .id = V4L2_CID_BRIGHTNESS,
  92. .type = V4L2_CTRL_TYPE_INTEGER,
  93. .name = "Brightness",
  94. .minimum = 0,
  95. .maximum = 14,
  96. .step = 1,
  97. #define BRIGHTNESS_DEF 8
  98. .default_value = BRIGHTNESS_DEF,
  99. },
  100. .set = sd_setbrightness,
  101. .get = sd_getbrightness,
  102. },
  103. {
  104. {
  105. .id = V4L2_CID_CONTRAST,
  106. .type = V4L2_CTRL_TYPE_INTEGER,
  107. .name = "Contrast",
  108. .minimum = 0,
  109. .maximum = 0x0d,
  110. .step = 1,
  111. #define CONTRAST_DEF 0x07
  112. .default_value = CONTRAST_DEF,
  113. },
  114. .set = sd_setcontrast,
  115. .get = sd_getcontrast,
  116. },
  117. {
  118. {
  119. .id = V4L2_CID_SATURATION,
  120. .type = V4L2_CTRL_TYPE_INTEGER,
  121. .name = "Color",
  122. .minimum = 0,
  123. .maximum = 0x0f,
  124. .step = 1,
  125. #define COLORS_DEF 0x05
  126. .default_value = COLORS_DEF,
  127. },
  128. .set = sd_setcolors,
  129. .get = sd_getcolors,
  130. },
  131. #define GAMMA_MAX 16
  132. #define GAMMA_DEF 10
  133. {
  134. {
  135. .id = V4L2_CID_GAMMA, /* (gamma on win) */
  136. .type = V4L2_CTRL_TYPE_INTEGER,
  137. .name = "Gamma",
  138. .minimum = 0,
  139. .maximum = GAMMA_MAX - 1,
  140. .step = 1,
  141. .default_value = GAMMA_DEF,
  142. },
  143. .set = sd_setgamma,
  144. .get = sd_getgamma,
  145. },
  146. {
  147. {
  148. .id = V4L2_CID_BACKLIGHT_COMPENSATION, /* Activa lowlight,
  149. * some apps dont bring up the
  150. * backligth_compensation control) */
  151. .type = V4L2_CTRL_TYPE_INTEGER,
  152. .name = "Low Light",
  153. .minimum = 0,
  154. .maximum = 1,
  155. .step = 1,
  156. #define AUTOGAIN_DEF 0x01
  157. .default_value = AUTOGAIN_DEF,
  158. },
  159. .set = sd_setlowlight,
  160. .get = sd_getlowlight,
  161. },
  162. {
  163. {
  164. .id = V4L2_CID_HFLIP,
  165. .type = V4L2_CTRL_TYPE_BOOLEAN,
  166. .name = "Mirror Image",
  167. .minimum = 0,
  168. .maximum = 1,
  169. .step = 1,
  170. #define MIRROR_DEF 0
  171. .default_value = MIRROR_DEF,
  172. },
  173. .set = sd_setmirror,
  174. .get = sd_getmirror
  175. },
  176. {
  177. {
  178. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  179. .type = V4L2_CTRL_TYPE_MENU,
  180. .name = "Light Frequency Filter",
  181. .minimum = 1, /* 1 -> 0x50, 2->0x60 */
  182. .maximum = 2,
  183. .step = 1,
  184. #define FREQ_DEF 1
  185. .default_value = FREQ_DEF,
  186. },
  187. .set = sd_setfreq,
  188. .get = sd_getfreq},
  189. {
  190. {
  191. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  192. .type = V4L2_CTRL_TYPE_INTEGER,
  193. .name = "Auto White Balance",
  194. .minimum = 0,
  195. .maximum = 1,
  196. .step = 1,
  197. #define AWB_DEF 0
  198. .default_value = AWB_DEF,
  199. },
  200. .set = sd_setawb,
  201. .get = sd_getawb
  202. },
  203. {
  204. {
  205. .id = V4L2_CID_SHARPNESS,
  206. .type = V4L2_CTRL_TYPE_INTEGER,
  207. .name = "Sharpness",
  208. .minimum = 0,
  209. .maximum = 15,
  210. .step = 1,
  211. #define SHARPNESS_DEF 0x06
  212. .default_value = SHARPNESS_DEF,
  213. },
  214. .set = sd_setsharpness,
  215. .get = sd_getsharpness,
  216. },
  217. {
  218. {
  219. .id = V4L2_CID_EFFECTS,
  220. .type = V4L2_CTRL_TYPE_MENU,
  221. .name = "Webcam Effects",
  222. .minimum = 0,
  223. .maximum = 4,
  224. .step = 1,
  225. #define EFFECTS_DEF 0
  226. .default_value = EFFECTS_DEF,
  227. },
  228. .set = sd_seteffect,
  229. .get = sd_geteffect
  230. },
  231. {
  232. {
  233. .id = V4L2_CID_BLUE_BALANCE,
  234. .type = V4L2_CTRL_TYPE_INTEGER,
  235. .name = "Blue Balance",
  236. .minimum = 0x10,
  237. .maximum = 0x40,
  238. .step = 1,
  239. #define BLUE_GAIN_DEF 0x20
  240. .default_value = BLUE_GAIN_DEF,
  241. },
  242. .set = sd_setblue_gain,
  243. .get = sd_getblue_gain,
  244. },
  245. {
  246. {
  247. .id = V4L2_CID_RED_BALANCE,
  248. .type = V4L2_CTRL_TYPE_INTEGER,
  249. .name = "Red Balance",
  250. .minimum = 0x10,
  251. .maximum = 0x40,
  252. .step = 1,
  253. #define RED_GAIN_DEF 0x20
  254. .default_value = RED_GAIN_DEF,
  255. },
  256. .set = sd_setred_gain,
  257. .get = sd_getred_gain,
  258. },
  259. {
  260. {
  261. .id = V4L2_CID_GAIN,
  262. .type = V4L2_CTRL_TYPE_INTEGER,
  263. .name = "Gain",
  264. .minimum = 0x10,
  265. .maximum = 0x40,
  266. .step = 1,
  267. #define GAIN_DEF 0x20
  268. .default_value = GAIN_DEF,
  269. },
  270. .set = sd_setgain,
  271. .get = sd_getgain,
  272. },
  273. };
  274. static const struct v4l2_pix_format vga_mode_t16[] = {
  275. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  276. .bytesperline = 160,
  277. .sizeimage = 160 * 120 * 4 / 8 + 590,
  278. .colorspace = V4L2_COLORSPACE_JPEG,
  279. .priv = 4},
  280. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  281. .bytesperline = 176,
  282. .sizeimage = 176 * 144 * 3 / 8 + 590,
  283. .colorspace = V4L2_COLORSPACE_JPEG,
  284. .priv = 3},
  285. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  286. .bytesperline = 320,
  287. .sizeimage = 320 * 240 * 3 / 8 + 590,
  288. .colorspace = V4L2_COLORSPACE_JPEG,
  289. .priv = 2},
  290. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  291. .bytesperline = 352,
  292. .sizeimage = 352 * 288 * 3 / 8 + 590,
  293. .colorspace = V4L2_COLORSPACE_JPEG,
  294. .priv = 1},
  295. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  296. .bytesperline = 640,
  297. .sizeimage = 640 * 480 * 3 / 8 + 590,
  298. .colorspace = V4L2_COLORSPACE_JPEG,
  299. .priv = 0},
  300. };
  301. /* sensor specific data */
  302. struct additional_sensor_data {
  303. const u8 n3[6];
  304. const u8 *n4, n4sz;
  305. const u8 reg80, reg8e;
  306. const u8 nset8[6];
  307. const u8 data1[10];
  308. const u8 data2[9];
  309. const u8 data3[9];
  310. const u8 data5[6];
  311. const u8 stream[4];
  312. };
  313. static const u8 n4_om6802[] = {
  314. 0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
  315. 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
  316. 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
  317. 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
  318. 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
  319. 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
  320. 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
  321. 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
  322. 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46
  323. };
  324. static const u8 n4_other[] = {
  325. 0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
  326. 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
  327. 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
  328. 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
  329. 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
  330. 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
  331. 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
  332. 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00
  333. };
  334. static const u8 n4_tas5130a[] = {
  335. 0x80, 0x3c, 0x81, 0x68, 0x83, 0xa0, 0x84, 0x20,
  336. 0x8a, 0x68, 0x8b, 0x58, 0x8c, 0x88, 0x8e, 0xb4,
  337. 0x8f, 0x24, 0xa1, 0xb1, 0xa2, 0x30, 0xa5, 0x10,
  338. 0xa6, 0x4a, 0xae, 0x03, 0xb1, 0x44, 0xb2, 0x08,
  339. 0xb7, 0x06, 0xb9, 0xe7, 0xbb, 0xc4, 0xbc, 0x4a,
  340. 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8,
  341. 0xc6, 0xda
  342. };
  343. static const u8 n4_lt168g[] = {
  344. 0x66, 0x01, 0x7f, 0x00, 0x80, 0x7c, 0x81, 0x28,
  345. 0x83, 0x44, 0x84, 0x20, 0x86, 0x20, 0x8a, 0x70,
  346. 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xa0, 0x8e, 0xb3,
  347. 0x8f, 0x24, 0xa1, 0xb0, 0xa2, 0x38, 0xa5, 0x20,
  348. 0xa6, 0x4a, 0xa8, 0xe8, 0xaf, 0x38, 0xb0, 0x68,
  349. 0xb1, 0x44, 0xb2, 0x88, 0xbb, 0x86, 0xbd, 0x40,
  350. 0xbe, 0x26, 0xc1, 0x05, 0xc2, 0x88, 0xc5, 0xc0,
  351. 0xda, 0x8e, 0xdb, 0xca, 0xdc, 0xa8, 0xdd, 0x8c,
  352. 0xde, 0x44, 0xdf, 0x0c, 0xe9, 0x80
  353. };
  354. static const struct additional_sensor_data sensor_data[] = {
  355. [SENSOR_OM6802] = {
  356. .n3 =
  357. {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04},
  358. .n4 = n4_om6802,
  359. .n4sz = sizeof n4_om6802,
  360. .reg80 = 0x3c,
  361. .reg8e = 0x33,
  362. .nset8 = {0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00},
  363. .data1 =
  364. {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06,
  365. 0xb3, 0xfc},
  366. .data2 =
  367. {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
  368. 0xff},
  369. .data3 =
  370. {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
  371. 0xff},
  372. .data5 = /* this could be removed later */
  373. {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
  374. .stream =
  375. {0x0b, 0x04, 0x0a, 0x78},
  376. },
  377. [SENSOR_OTHER] = {
  378. .n3 =
  379. {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00},
  380. .n4 = n4_other,
  381. .n4sz = sizeof n4_other,
  382. .reg80 = 0xac,
  383. .reg8e = 0xb8,
  384. .nset8 = {0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00},
  385. .data1 =
  386. {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a,
  387. 0xe8, 0xfc},
  388. .data2 =
  389. {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
  390. 0xd9},
  391. .data3 =
  392. {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
  393. 0xd9},
  394. .data5 =
  395. {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69},
  396. .stream =
  397. {0x0b, 0x04, 0x0a, 0x00},
  398. },
  399. [SENSOR_TAS5130A] = {
  400. .n3 =
  401. {0x61, 0xc2, 0x65, 0x0d, 0x60, 0x08},
  402. .n4 = n4_tas5130a,
  403. .n4sz = sizeof n4_tas5130a,
  404. .reg80 = 0x3c,
  405. .reg8e = 0xb4,
  406. .nset8 = {0xa8, 0xf0, 0xc6, 0xda, 0xc0, 0x00},
  407. .data1 =
  408. {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27,
  409. 0xc8, 0xfc},
  410. .data2 =
  411. {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
  412. 0xe0},
  413. .data3 =
  414. {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
  415. 0xe0},
  416. .data5 =
  417. {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20},
  418. .stream =
  419. {0x0b, 0x04, 0x0a, 0x40},
  420. },
  421. [SENSOR_LT168G] = {
  422. .n3 = {0x61, 0xc2, 0x65, 0x68, 0x60, 0x00},
  423. .n4 = n4_lt168g,
  424. .n4sz = sizeof n4_lt168g,
  425. .reg80 = 0x7c,
  426. .reg8e = 0xb3,
  427. .nset8 = {0xa8, 0xf0, 0xc6, 0xba, 0xc0, 0x00},
  428. .data1 = {0xc0, 0x38, 0x08, 0x10, 0xc0, 0x30, 0x10, 0x40,
  429. 0xb0, 0xf4},
  430. .data2 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
  431. 0xff},
  432. .data3 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
  433. 0xff},
  434. .data5 = {0x0c, 0x03, 0xab, 0x4b, 0x81, 0x2b},
  435. .stream = {0x0b, 0x04, 0x0a, 0x28},
  436. },
  437. };
  438. #define MAX_EFFECTS 7
  439. /* easily done by soft, this table could be removed,
  440. * i keep it here just in case */
  441. static char *effects_control[MAX_EFFECTS] = {
  442. "Normal",
  443. "Emboss", /* disabled */
  444. "Monochrome",
  445. "Sepia",
  446. "Sketch",
  447. "Sun Effect", /* disabled */
  448. "Negative",
  449. };
  450. static const u8 effects_table[MAX_EFFECTS][6] = {
  451. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
  452. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
  453. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
  454. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */
  455. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */
  456. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */
  457. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
  458. };
  459. static const u8 gamma_table[GAMMA_MAX][17] = {
  460. /* gamma table from cam1690.ini */
  461. {0x00, 0x00, 0x01, 0x04, 0x08, 0x0e, 0x16, 0x21, /* 0 */
  462. 0x2e, 0x3d, 0x50, 0x65, 0x7d, 0x99, 0xb8, 0xdb,
  463. 0xff},
  464. {0x00, 0x01, 0x03, 0x08, 0x0e, 0x16, 0x21, 0x2d, /* 1 */
  465. 0x3c, 0x4d, 0x60, 0x75, 0x8d, 0xa6, 0xc2, 0xe1,
  466. 0xff},
  467. {0x00, 0x01, 0x05, 0x0b, 0x12, 0x1c, 0x28, 0x35, /* 2 */
  468. 0x45, 0x56, 0x69, 0x7e, 0x95, 0xad, 0xc7, 0xe3,
  469. 0xff},
  470. {0x00, 0x02, 0x07, 0x0f, 0x18, 0x24, 0x30, 0x3f, /* 3 */
  471. 0x4f, 0x61, 0x73, 0x88, 0x9d, 0xb4, 0xcd, 0xe6,
  472. 0xff},
  473. {0x00, 0x04, 0x0b, 0x15, 0x20, 0x2d, 0x3b, 0x4a, /* 4 */
  474. 0x5b, 0x6c, 0x7f, 0x92, 0xa7, 0xbc, 0xd2, 0xe9,
  475. 0xff},
  476. {0x00, 0x07, 0x11, 0x15, 0x20, 0x2d, 0x48, 0x58, /* 5 */
  477. 0x68, 0x79, 0x8b, 0x9d, 0xb0, 0xc4, 0xd7, 0xec,
  478. 0xff},
  479. {0x00, 0x0c, 0x1a, 0x29, 0x38, 0x47, 0x57, 0x67, /* 6 */
  480. 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
  481. 0xff},
  482. {0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, /* 7 */
  483. 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
  484. 0xff},
  485. {0x00, 0x15, 0x27, 0x38, 0x49, 0x59, 0x69, 0x79, /* 8 */
  486. 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe2, 0xf0,
  487. 0xff},
  488. {0x00, 0x1c, 0x30, 0x43, 0x54, 0x65, 0x75, 0x84, /* 9 */
  489. 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd8, 0xe5, 0xf2,
  490. 0xff},
  491. {0x00, 0x24, 0x3b, 0x4f, 0x60, 0x70, 0x80, 0x8e, /* 10 */
  492. 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xdc, 0xe8, 0xf3,
  493. 0xff},
  494. {0x00, 0x2a, 0x3c, 0x5d, 0x6e, 0x7e, 0x8d, 0x9b, /* 11 */
  495. 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
  496. 0xff},
  497. {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
  498. 0xb4, 0xbf, 0xc9, 0xd3, 0xdc, 0xe5, 0xee, 0xf6,
  499. 0xff},
  500. {0x00, 0x54, 0x6f, 0x83, 0x93, 0xa0, 0xad, 0xb7, /* 13 */
  501. 0xc2, 0xcb, 0xd4, 0xdc, 0xe4, 0xeb, 0xf2, 0xf9,
  502. 0xff},
  503. {0x00, 0x6e, 0x88, 0x9a, 0xa8, 0xb3, 0xbd, 0xc6, /* 14 */
  504. 0xcf, 0xd6, 0xdd, 0xe3, 0xe9, 0xef, 0xf4, 0xfa,
  505. 0xff},
  506. {0x00, 0x93, 0xa8, 0xb7, 0xc1, 0xca, 0xd2, 0xd8, /* 15 */
  507. 0xde, 0xe3, 0xe8, 0xed, 0xf1, 0xf5, 0xf8, 0xfc,
  508. 0xff}
  509. };
  510. static const u8 tas5130a_sensor_init[][8] = {
  511. {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
  512. {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
  513. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  514. };
  515. static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
  516. /* read 1 byte */
  517. static u8 reg_r(struct gspca_dev *gspca_dev,
  518. u16 index)
  519. {
  520. usb_control_msg(gspca_dev->dev,
  521. usb_rcvctrlpipe(gspca_dev->dev, 0),
  522. 0, /* request */
  523. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  524. 0, /* value */
  525. index,
  526. gspca_dev->usb_buf, 1, 500);
  527. return gspca_dev->usb_buf[0];
  528. }
  529. static void reg_w(struct gspca_dev *gspca_dev,
  530. u16 index)
  531. {
  532. usb_control_msg(gspca_dev->dev,
  533. usb_sndctrlpipe(gspca_dev->dev, 0),
  534. 0,
  535. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  536. 0, index,
  537. NULL, 0, 500);
  538. }
  539. static void reg_w_buf(struct gspca_dev *gspca_dev,
  540. const u8 *buffer, u16 len)
  541. {
  542. if (len <= USB_BUF_SZ) {
  543. memcpy(gspca_dev->usb_buf, buffer, len);
  544. usb_control_msg(gspca_dev->dev,
  545. usb_sndctrlpipe(gspca_dev->dev, 0),
  546. 0,
  547. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  548. 0x01, 0,
  549. gspca_dev->usb_buf, len, 500);
  550. } else {
  551. u8 *tmpbuf;
  552. tmpbuf = kmemdup(buffer, len, GFP_KERNEL);
  553. if (!tmpbuf) {
  554. pr_err("Out of memory\n");
  555. return;
  556. }
  557. usb_control_msg(gspca_dev->dev,
  558. usb_sndctrlpipe(gspca_dev->dev, 0),
  559. 0,
  560. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  561. 0x01, 0,
  562. tmpbuf, len, 500);
  563. kfree(tmpbuf);
  564. }
  565. }
  566. /* write values to consecutive registers */
  567. static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
  568. u8 reg,
  569. const u8 *buffer, u16 len)
  570. {
  571. int i;
  572. u8 *p, *tmpbuf;
  573. if (len * 2 <= USB_BUF_SZ) {
  574. p = tmpbuf = gspca_dev->usb_buf;
  575. } else {
  576. p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
  577. if (!tmpbuf) {
  578. pr_err("Out of memory\n");
  579. return;
  580. }
  581. }
  582. i = len;
  583. while (--i >= 0) {
  584. *p++ = reg++;
  585. *p++ = *buffer++;
  586. }
  587. usb_control_msg(gspca_dev->dev,
  588. usb_sndctrlpipe(gspca_dev->dev, 0),
  589. 0,
  590. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  591. 0x01, 0,
  592. tmpbuf, len * 2, 500);
  593. if (len * 2 > USB_BUF_SZ)
  594. kfree(tmpbuf);
  595. }
  596. static void om6802_sensor_init(struct gspca_dev *gspca_dev)
  597. {
  598. int i;
  599. const u8 *p;
  600. u8 byte;
  601. u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
  602. static const u8 sensor_init[] = {
  603. 0xdf, 0x6d,
  604. 0xdd, 0x18,
  605. 0x5a, 0xe0,
  606. 0x5c, 0x07,
  607. 0x5d, 0xb0,
  608. 0x5e, 0x1e,
  609. 0x60, 0x71,
  610. 0xef, 0x00,
  611. 0xe9, 0x00,
  612. 0xea, 0x00,
  613. 0x90, 0x24,
  614. 0x91, 0xb2,
  615. 0x82, 0x32,
  616. 0xfd, 0x41,
  617. 0x00 /* table end */
  618. };
  619. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  620. msleep(100);
  621. i = 4;
  622. while (--i > 0) {
  623. byte = reg_r(gspca_dev, 0x0060);
  624. if (!(byte & 0x01))
  625. break;
  626. msleep(100);
  627. }
  628. byte = reg_r(gspca_dev, 0x0063);
  629. if (byte != 0x17) {
  630. pr_err("Bad sensor reset %02x\n", byte);
  631. /* continue? */
  632. }
  633. p = sensor_init;
  634. while (*p != 0) {
  635. val[1] = *p++;
  636. val[3] = *p++;
  637. if (*p == 0)
  638. reg_w(gspca_dev, 0x3c80);
  639. reg_w_buf(gspca_dev, val, sizeof val);
  640. i = 4;
  641. while (--i >= 0) {
  642. msleep(15);
  643. byte = reg_r(gspca_dev, 0x60);
  644. if (!(byte & 0x01))
  645. break;
  646. }
  647. }
  648. msleep(15);
  649. reg_w(gspca_dev, 0x3c80);
  650. }
  651. /* this function is called at probe time */
  652. static int sd_config(struct gspca_dev *gspca_dev,
  653. const struct usb_device_id *id)
  654. {
  655. struct sd *sd = (struct sd *) gspca_dev;
  656. struct cam *cam;
  657. cam = &gspca_dev->cam;
  658. cam->cam_mode = vga_mode_t16;
  659. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  660. sd->brightness = BRIGHTNESS_DEF;
  661. sd->contrast = CONTRAST_DEF;
  662. sd->colors = COLORS_DEF;
  663. sd->gamma = GAMMA_DEF;
  664. sd->autogain = AUTOGAIN_DEF;
  665. sd->mirror = MIRROR_DEF;
  666. sd->freq = FREQ_DEF;
  667. sd->awb = AWB_DEF;
  668. sd->sharpness = SHARPNESS_DEF;
  669. sd->effect = EFFECTS_DEF;
  670. sd->red_gain = RED_GAIN_DEF;
  671. sd->blue_gain = BLUE_GAIN_DEF;
  672. sd->green_gain = GAIN_DEF * 3 - RED_GAIN_DEF - BLUE_GAIN_DEF;
  673. return 0;
  674. }
  675. static void setbrightness(struct gspca_dev *gspca_dev)
  676. {
  677. struct sd *sd = (struct sd *) gspca_dev;
  678. unsigned int brightness;
  679. u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
  680. brightness = sd->brightness;
  681. if (brightness < 7) {
  682. set6[1] = 0x26;
  683. set6[3] = 0x70 - brightness * 0x10;
  684. } else {
  685. set6[3] = 0x00 + ((brightness - 7) * 0x10);
  686. }
  687. reg_w_buf(gspca_dev, set6, sizeof set6);
  688. }
  689. static void setcontrast(struct gspca_dev *gspca_dev)
  690. {
  691. struct sd *sd = (struct sd *) gspca_dev;
  692. unsigned int contrast = sd->contrast;
  693. u16 reg_to_write;
  694. if (contrast < 7)
  695. reg_to_write = 0x8ea9 - contrast * 0x200;
  696. else
  697. reg_to_write = 0x00a9 + (contrast - 7) * 0x200;
  698. reg_w(gspca_dev, reg_to_write);
  699. }
  700. static void setcolors(struct gspca_dev *gspca_dev)
  701. {
  702. struct sd *sd = (struct sd *) gspca_dev;
  703. u16 reg_to_write;
  704. reg_to_write = 0x80bb + sd->colors * 0x100; /* was 0xc0 */
  705. reg_w(gspca_dev, reg_to_write);
  706. }
  707. static void setgamma(struct gspca_dev *gspca_dev)
  708. {
  709. struct sd *sd = (struct sd *) gspca_dev;
  710. PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
  711. reg_w_ixbuf(gspca_dev, 0x90,
  712. gamma_table[sd->gamma], sizeof gamma_table[0]);
  713. }
  714. static void setRGB(struct gspca_dev *gspca_dev)
  715. {
  716. struct sd *sd = (struct sd *) gspca_dev;
  717. u8 all_gain_reg[6] =
  718. {0x87, 0x00, 0x88, 0x00, 0x89, 0x00};
  719. all_gain_reg[1] = sd->red_gain;
  720. all_gain_reg[3] = sd->blue_gain;
  721. all_gain_reg[5] = sd->green_gain;
  722. reg_w_buf(gspca_dev, all_gain_reg, sizeof all_gain_reg);
  723. }
  724. /* Generic fnc for r/b balance, exposure and awb */
  725. static void setawb(struct gspca_dev *gspca_dev)
  726. {
  727. struct sd *sd = (struct sd *) gspca_dev;
  728. u16 reg80;
  729. reg80 = (sensor_data[sd->sensor].reg80 << 8) | 0x80;
  730. /* on awb leave defaults values */
  731. if (!sd->awb) {
  732. /* shoud we wait here.. */
  733. /* update and reset RGB gains with webcam values */
  734. sd->red_gain = reg_r(gspca_dev, 0x0087);
  735. sd->blue_gain = reg_r(gspca_dev, 0x0088);
  736. sd->green_gain = reg_r(gspca_dev, 0x0089);
  737. reg80 &= ~0x0400; /* AWB off */
  738. }
  739. reg_w(gspca_dev, reg80);
  740. reg_w(gspca_dev, reg80);
  741. }
  742. static void init_gains(struct gspca_dev *gspca_dev)
  743. {
  744. struct sd *sd = (struct sd *) gspca_dev;
  745. u16 reg80;
  746. u8 all_gain_reg[8] =
  747. {0x87, 0x00, 0x88, 0x00, 0x89, 0x00, 0x80, 0x00};
  748. all_gain_reg[1] = sd->red_gain;
  749. all_gain_reg[3] = sd->blue_gain;
  750. all_gain_reg[5] = sd->green_gain;
  751. reg80 = sensor_data[sd->sensor].reg80;
  752. if (!sd->awb)
  753. reg80 &= ~0x04;
  754. all_gain_reg[7] = reg80;
  755. reg_w_buf(gspca_dev, all_gain_reg, sizeof all_gain_reg);
  756. reg_w(gspca_dev, (sd->red_gain << 8) + 0x87);
  757. reg_w(gspca_dev, (sd->blue_gain << 8) + 0x88);
  758. reg_w(gspca_dev, (sd->green_gain << 8) + 0x89);
  759. }
  760. static void setsharpness(struct gspca_dev *gspca_dev)
  761. {
  762. struct sd *sd = (struct sd *) gspca_dev;
  763. u16 reg_to_write;
  764. reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
  765. reg_w(gspca_dev, reg_to_write);
  766. }
  767. static void setfreq(struct gspca_dev *gspca_dev)
  768. {
  769. struct sd *sd = (struct sd *) gspca_dev;
  770. u8 reg66;
  771. u8 freq[4] = { 0x66, 0x00, 0xa8, 0xe8 };
  772. switch (sd->sensor) {
  773. case SENSOR_LT168G:
  774. if (sd->freq != 0)
  775. freq[3] = 0xa8;
  776. reg66 = 0x41;
  777. break;
  778. case SENSOR_OM6802:
  779. reg66 = 0xca;
  780. break;
  781. default:
  782. reg66 = 0x40;
  783. break;
  784. }
  785. switch (sd->freq) {
  786. case 0: /* no flicker */
  787. freq[3] = 0xf0;
  788. break;
  789. case 2: /* 60Hz */
  790. reg66 &= ~0x40;
  791. break;
  792. }
  793. freq[1] = reg66;
  794. reg_w_buf(gspca_dev, freq, sizeof freq);
  795. }
  796. /* this function is called at probe and resume time */
  797. static int sd_init(struct gspca_dev *gspca_dev)
  798. {
  799. /* some of this registers are not really neded, because
  800. * they are overriden by setbrigthness, setcontrast, etc,
  801. * but wont hurt anyway, and can help someone with similar webcam
  802. * to see the initial parameters.*/
  803. struct sd *sd = (struct sd *) gspca_dev;
  804. const struct additional_sensor_data *sensor;
  805. int i;
  806. u16 sensor_id;
  807. u8 test_byte = 0;
  808. static const u8 read_indexs[] =
  809. { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  810. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 };
  811. static const u8 n1[] =
  812. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  813. static const u8 n2[] =
  814. {0x08, 0x00};
  815. sensor_id = (reg_r(gspca_dev, 0x06) << 8)
  816. | reg_r(gspca_dev, 0x07);
  817. switch (sensor_id & 0xff0f) {
  818. case 0x0801:
  819. PDEBUG(D_PROBE, "sensor tas5130a");
  820. sd->sensor = SENSOR_TAS5130A;
  821. break;
  822. case 0x0802:
  823. PDEBUG(D_PROBE, "sensor lt168g");
  824. sd->sensor = SENSOR_LT168G;
  825. break;
  826. case 0x0803:
  827. PDEBUG(D_PROBE, "sensor 'other'");
  828. sd->sensor = SENSOR_OTHER;
  829. break;
  830. case 0x0807:
  831. PDEBUG(D_PROBE, "sensor om6802");
  832. sd->sensor = SENSOR_OM6802;
  833. break;
  834. default:
  835. pr_err("unknown sensor %04x\n", sensor_id);
  836. return -EINVAL;
  837. }
  838. if (sd->sensor == SENSOR_OM6802) {
  839. reg_w_buf(gspca_dev, n1, sizeof n1);
  840. i = 5;
  841. while (--i >= 0) {
  842. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  843. test_byte = reg_r(gspca_dev, 0x0063);
  844. msleep(100);
  845. if (test_byte == 0x17)
  846. break; /* OK */
  847. }
  848. if (i < 0) {
  849. pr_err("Bad sensor reset %02x\n", test_byte);
  850. return -EIO;
  851. }
  852. reg_w_buf(gspca_dev, n2, sizeof n2);
  853. }
  854. i = 0;
  855. while (read_indexs[i] != 0x00) {
  856. test_byte = reg_r(gspca_dev, read_indexs[i]);
  857. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
  858. test_byte);
  859. i++;
  860. }
  861. sensor = &sensor_data[sd->sensor];
  862. reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3);
  863. reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
  864. if (sd->sensor == SENSOR_LT168G) {
  865. test_byte = reg_r(gspca_dev, 0x80);
  866. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
  867. test_byte);
  868. reg_w(gspca_dev, 0x6c80);
  869. }
  870. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  871. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  872. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  873. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  874. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  875. reg_w(gspca_dev, (sensor->reg8e << 8) + 0x8e);
  876. setbrightness(gspca_dev);
  877. setcontrast(gspca_dev);
  878. setgamma(gspca_dev);
  879. setcolors(gspca_dev);
  880. setsharpness(gspca_dev);
  881. init_gains(gspca_dev);
  882. setfreq(gspca_dev);
  883. reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5);
  884. reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
  885. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  886. if (sd->sensor == SENSOR_LT168G) {
  887. test_byte = reg_r(gspca_dev, 0x80);
  888. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
  889. test_byte);
  890. reg_w(gspca_dev, 0x6c80);
  891. }
  892. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  893. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  894. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  895. return 0;
  896. }
  897. static void setmirror(struct gspca_dev *gspca_dev)
  898. {
  899. struct sd *sd = (struct sd *) gspca_dev;
  900. u8 hflipcmd[8] =
  901. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
  902. if (sd->mirror)
  903. hflipcmd[3] = 0x01;
  904. reg_w_buf(gspca_dev, hflipcmd, sizeof hflipcmd);
  905. }
  906. static void seteffect(struct gspca_dev *gspca_dev)
  907. {
  908. struct sd *sd = (struct sd *) gspca_dev;
  909. reg_w_buf(gspca_dev, effects_table[sd->effect],
  910. sizeof effects_table[0]);
  911. if (sd->effect == 1 || sd->effect == 5) {
  912. PDEBUG(D_CONF,
  913. "This effect have been disabled for webcam \"safety\"");
  914. return;
  915. }
  916. if (sd->effect == 1 || sd->effect == 4)
  917. reg_w(gspca_dev, 0x4aa6);
  918. else
  919. reg_w(gspca_dev, 0xfaa6);
  920. }
  921. /* Is this really needed?
  922. * i added some module parameters for test with some users */
  923. static void poll_sensor(struct gspca_dev *gspca_dev)
  924. {
  925. static const u8 poll1[] =
  926. {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
  927. 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
  928. 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01,
  929. 0x60, 0x14};
  930. static const u8 poll2[] =
  931. {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
  932. 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
  933. static const u8 noise03[] = /* (some differences / ms-drv) */
  934. {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
  935. 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
  936. 0xc2, 0x80, 0xc3, 0x10};
  937. PDEBUG(D_STREAM, "[Sensor requires polling]");
  938. reg_w_buf(gspca_dev, poll1, sizeof poll1);
  939. reg_w_buf(gspca_dev, poll2, sizeof poll2);
  940. reg_w_buf(gspca_dev, noise03, sizeof noise03);
  941. }
  942. static int sd_start(struct gspca_dev *gspca_dev)
  943. {
  944. struct sd *sd = (struct sd *) gspca_dev;
  945. const struct additional_sensor_data *sensor;
  946. int i, mode;
  947. u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  948. static const u8 t3[] =
  949. { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
  950. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  951. switch (mode) {
  952. case 0: /* 640x480 (0x00) */
  953. break;
  954. case 1: /* 352x288 */
  955. t2[1] = 0x40;
  956. break;
  957. case 2: /* 320x240 */
  958. t2[1] = 0x10;
  959. break;
  960. case 3: /* 176x144 */
  961. t2[1] = 0x50;
  962. break;
  963. default:
  964. /* case 4: * 160x120 */
  965. t2[1] = 0x20;
  966. break;
  967. }
  968. switch (sd->sensor) {
  969. case SENSOR_OM6802:
  970. om6802_sensor_init(gspca_dev);
  971. break;
  972. case SENSOR_TAS5130A:
  973. i = 0;
  974. for (;;) {
  975. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  976. sizeof tas5130a_sensor_init[0]);
  977. if (i >= ARRAY_SIZE(tas5130a_sensor_init) - 1)
  978. break;
  979. i++;
  980. }
  981. reg_w(gspca_dev, 0x3c80);
  982. /* just in case and to keep sync with logs (for mine) */
  983. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  984. sizeof tas5130a_sensor_init[0]);
  985. reg_w(gspca_dev, 0x3c80);
  986. break;
  987. }
  988. sensor = &sensor_data[sd->sensor];
  989. setfreq(gspca_dev);
  990. reg_r(gspca_dev, 0x0012);
  991. reg_w_buf(gspca_dev, t2, sizeof t2);
  992. reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
  993. reg_w(gspca_dev, 0x0013);
  994. msleep(15);
  995. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  996. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  997. if (sd->sensor == SENSOR_OM6802)
  998. poll_sensor(gspca_dev);
  999. return 0;
  1000. }
  1001. static void sd_stopN(struct gspca_dev *gspca_dev)
  1002. {
  1003. struct sd *sd = (struct sd *) gspca_dev;
  1004. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  1005. sizeof sensor_data[sd->sensor].stream);
  1006. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  1007. sizeof sensor_data[sd->sensor].stream);
  1008. if (sd->sensor == SENSOR_OM6802) {
  1009. msleep(20);
  1010. reg_w(gspca_dev, 0x0309);
  1011. }
  1012. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  1013. /* If the last button state is pressed, release it now! */
  1014. if (sd->button_pressed) {
  1015. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  1016. input_sync(gspca_dev->input_dev);
  1017. sd->button_pressed = 0;
  1018. }
  1019. #endif
  1020. }
  1021. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1022. u8 *data, /* isoc packet */
  1023. int len) /* iso packet length */
  1024. {
  1025. struct sd *sd = (struct sd *) gspca_dev;
  1026. int pkt_type;
  1027. if (data[0] == 0x5a) {
  1028. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  1029. if (len > 20) {
  1030. u8 state = (data[20] & 0x80) ? 1 : 0;
  1031. if (sd->button_pressed != state) {
  1032. input_report_key(gspca_dev->input_dev,
  1033. KEY_CAMERA, state);
  1034. input_sync(gspca_dev->input_dev);
  1035. sd->button_pressed = state;
  1036. }
  1037. }
  1038. #endif
  1039. /* Control Packet, after this came the header again,
  1040. * but extra bytes came in the packet before this,
  1041. * sometimes an EOF arrives, sometimes not... */
  1042. return;
  1043. }
  1044. data += 2;
  1045. len -= 2;
  1046. if (data[0] == 0xff && data[1] == 0xd8)
  1047. pkt_type = FIRST_PACKET;
  1048. else if (data[len - 2] == 0xff && data[len - 1] == 0xd9)
  1049. pkt_type = LAST_PACKET;
  1050. else
  1051. pkt_type = INTER_PACKET;
  1052. gspca_frame_add(gspca_dev, pkt_type, data, len);
  1053. }
  1054. static int sd_setblue_gain(struct gspca_dev *gspca_dev, __s32 val)
  1055. {
  1056. struct sd *sd = (struct sd *) gspca_dev;
  1057. sd->blue_gain = val;
  1058. if (gspca_dev->streaming)
  1059. reg_w(gspca_dev, (val << 8) + 0x88);
  1060. return 0;
  1061. }
  1062. static int sd_getblue_gain(struct gspca_dev *gspca_dev, __s32 *val)
  1063. {
  1064. struct sd *sd = (struct sd *) gspca_dev;
  1065. *val = sd->blue_gain;
  1066. return 0;
  1067. }
  1068. static int sd_setred_gain(struct gspca_dev *gspca_dev, __s32 val)
  1069. {
  1070. struct sd *sd = (struct sd *) gspca_dev;
  1071. sd->red_gain = val;
  1072. if (gspca_dev->streaming)
  1073. reg_w(gspca_dev, (val << 8) + 0x87);
  1074. return 0;
  1075. }
  1076. static int sd_getred_gain(struct gspca_dev *gspca_dev, __s32 *val)
  1077. {
  1078. struct sd *sd = (struct sd *) gspca_dev;
  1079. *val = sd->red_gain;
  1080. return 0;
  1081. }
  1082. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  1083. {
  1084. struct sd *sd = (struct sd *) gspca_dev;
  1085. u16 psg, nsg;
  1086. psg = sd->red_gain + sd->blue_gain + sd->green_gain;
  1087. nsg = val * 3;
  1088. sd->red_gain = sd->red_gain * nsg / psg;
  1089. if (sd->red_gain > 0x40)
  1090. sd->red_gain = 0x40;
  1091. else if (sd->red_gain < 0x10)
  1092. sd->red_gain = 0x10;
  1093. sd->blue_gain = sd->blue_gain * nsg / psg;
  1094. if (sd->blue_gain > 0x40)
  1095. sd->blue_gain = 0x40;
  1096. else if (sd->blue_gain < 0x10)
  1097. sd->blue_gain = 0x10;
  1098. sd->green_gain = sd->green_gain * nsg / psg;
  1099. if (sd->green_gain > 0x40)
  1100. sd->green_gain = 0x40;
  1101. else if (sd->green_gain < 0x10)
  1102. sd->green_gain = 0x10;
  1103. if (gspca_dev->streaming)
  1104. setRGB(gspca_dev);
  1105. return 0;
  1106. }
  1107. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  1108. {
  1109. struct sd *sd = (struct sd *) gspca_dev;
  1110. *val = (sd->red_gain + sd->blue_gain + sd->green_gain) / 3;
  1111. return 0;
  1112. }
  1113. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1114. {
  1115. struct sd *sd = (struct sd *) gspca_dev;
  1116. sd->brightness = val;
  1117. if (gspca_dev->streaming)
  1118. setbrightness(gspca_dev);
  1119. return 0;
  1120. }
  1121. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1122. {
  1123. struct sd *sd = (struct sd *) gspca_dev;
  1124. *val = sd->brightness;
  1125. return *val;
  1126. }
  1127. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
  1128. {
  1129. struct sd *sd = (struct sd *) gspca_dev;
  1130. sd->awb = val;
  1131. if (gspca_dev->streaming)
  1132. setawb(gspca_dev);
  1133. return 0;
  1134. }
  1135. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
  1136. {
  1137. struct sd *sd = (struct sd *) gspca_dev;
  1138. *val = sd->awb;
  1139. return *val;
  1140. }
  1141. static int sd_setmirror(struct gspca_dev *gspca_dev, __s32 val)
  1142. {
  1143. struct sd *sd = (struct sd *) gspca_dev;
  1144. sd->mirror = val;
  1145. if (gspca_dev->streaming)
  1146. setmirror(gspca_dev);
  1147. return 0;
  1148. }
  1149. static int sd_getmirror(struct gspca_dev *gspca_dev, __s32 *val)
  1150. {
  1151. struct sd *sd = (struct sd *) gspca_dev;
  1152. *val = sd->mirror;
  1153. return *val;
  1154. }
  1155. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val)
  1156. {
  1157. struct sd *sd = (struct sd *) gspca_dev;
  1158. sd->effect = val;
  1159. if (gspca_dev->streaming)
  1160. seteffect(gspca_dev);
  1161. return 0;
  1162. }
  1163. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val)
  1164. {
  1165. struct sd *sd = (struct sd *) gspca_dev;
  1166. *val = sd->effect;
  1167. return *val;
  1168. }
  1169. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1170. {
  1171. struct sd *sd = (struct sd *) gspca_dev;
  1172. sd->contrast = val;
  1173. if (gspca_dev->streaming)
  1174. setcontrast(gspca_dev);
  1175. return 0;
  1176. }
  1177. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1178. {
  1179. struct sd *sd = (struct sd *) gspca_dev;
  1180. *val = sd->contrast;
  1181. return *val;
  1182. }
  1183. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1184. {
  1185. struct sd *sd = (struct sd *) gspca_dev;
  1186. sd->colors = val;
  1187. if (gspca_dev->streaming)
  1188. setcolors(gspca_dev);
  1189. return 0;
  1190. }
  1191. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1192. {
  1193. struct sd *sd = (struct sd *) gspca_dev;
  1194. *val = sd->colors;
  1195. return 0;
  1196. }
  1197. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
  1198. {
  1199. struct sd *sd = (struct sd *) gspca_dev;
  1200. sd->gamma = val;
  1201. if (gspca_dev->streaming)
  1202. setgamma(gspca_dev);
  1203. return 0;
  1204. }
  1205. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
  1206. {
  1207. struct sd *sd = (struct sd *) gspca_dev;
  1208. *val = sd->gamma;
  1209. return 0;
  1210. }
  1211. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  1212. {
  1213. struct sd *sd = (struct sd *) gspca_dev;
  1214. sd->freq = val;
  1215. if (gspca_dev->streaming)
  1216. setfreq(gspca_dev);
  1217. return 0;
  1218. }
  1219. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  1220. {
  1221. struct sd *sd = (struct sd *) gspca_dev;
  1222. *val = sd->freq;
  1223. return 0;
  1224. }
  1225. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1226. {
  1227. struct sd *sd = (struct sd *) gspca_dev;
  1228. sd->sharpness = val;
  1229. if (gspca_dev->streaming)
  1230. setsharpness(gspca_dev);
  1231. return 0;
  1232. }
  1233. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1234. {
  1235. struct sd *sd = (struct sd *) gspca_dev;
  1236. *val = sd->sharpness;
  1237. return 0;
  1238. }
  1239. /* Low Light set here......*/
  1240. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
  1241. {
  1242. struct sd *sd = (struct sd *) gspca_dev;
  1243. sd->autogain = val;
  1244. if (val != 0)
  1245. reg_w(gspca_dev, 0xf48e);
  1246. else
  1247. reg_w(gspca_dev, 0xb48e);
  1248. return 0;
  1249. }
  1250. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
  1251. {
  1252. struct sd *sd = (struct sd *) gspca_dev;
  1253. *val = sd->autogain;
  1254. return 0;
  1255. }
  1256. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1257. struct v4l2_querymenu *menu)
  1258. {
  1259. static const char *freq_nm[3] = {"NoFliker", "50 Hz", "60 Hz"};
  1260. switch (menu->id) {
  1261. case V4L2_CID_POWER_LINE_FREQUENCY:
  1262. if ((unsigned) menu->index >= ARRAY_SIZE(freq_nm))
  1263. break;
  1264. strcpy((char *) menu->name, freq_nm[menu->index]);
  1265. return 0;
  1266. case V4L2_CID_EFFECTS:
  1267. if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) {
  1268. strlcpy((char *) menu->name,
  1269. effects_control[menu->index],
  1270. sizeof menu->name);
  1271. return 0;
  1272. }
  1273. break;
  1274. }
  1275. return -EINVAL;
  1276. }
  1277. /* sub-driver description */
  1278. static const struct sd_desc sd_desc = {
  1279. .name = MODULE_NAME,
  1280. .ctrls = sd_ctrls,
  1281. .nctrls = ARRAY_SIZE(sd_ctrls),
  1282. .config = sd_config,
  1283. .init = sd_init,
  1284. .start = sd_start,
  1285. .stopN = sd_stopN,
  1286. .pkt_scan = sd_pkt_scan,
  1287. .querymenu = sd_querymenu,
  1288. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  1289. .other_input = 1,
  1290. #endif
  1291. };
  1292. /* -- module initialisation -- */
  1293. static const struct usb_device_id device_table[] = {
  1294. {USB_DEVICE(0x17a1, 0x0128)},
  1295. {}
  1296. };
  1297. MODULE_DEVICE_TABLE(usb, device_table);
  1298. /* -- device connect -- */
  1299. static int sd_probe(struct usb_interface *intf,
  1300. const struct usb_device_id *id)
  1301. {
  1302. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1303. THIS_MODULE);
  1304. }
  1305. static struct usb_driver sd_driver = {
  1306. .name = MODULE_NAME,
  1307. .id_table = device_table,
  1308. .probe = sd_probe,
  1309. .disconnect = gspca_disconnect,
  1310. #ifdef CONFIG_PM
  1311. .suspend = gspca_suspend,
  1312. .resume = gspca_resume,
  1313. #endif
  1314. };
  1315. module_usb_driver(sd_driver);