t613.c 35 KB

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