t613.c 32 KB

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