t613.c 35 KB

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