t613.c 35 KB

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