t613.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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. memcpy(tmpbuf, buffer, len);
  504. usb_control_msg(gspca_dev->dev,
  505. usb_sndctrlpipe(gspca_dev->dev, 0),
  506. 0,
  507. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  508. 0x01, 0,
  509. tmpbuf, len, 500);
  510. kfree(tmpbuf);
  511. }
  512. }
  513. /* write values to consecutive registers */
  514. static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
  515. u8 reg,
  516. const u8 *buffer, u16 len)
  517. {
  518. int i;
  519. u8 *p, *tmpbuf;
  520. if (len * 2 <= USB_BUF_SZ)
  521. p = tmpbuf = gspca_dev->usb_buf;
  522. else
  523. p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
  524. i = len;
  525. while (--i >= 0) {
  526. *p++ = reg++;
  527. *p++ = *buffer++;
  528. }
  529. usb_control_msg(gspca_dev->dev,
  530. usb_sndctrlpipe(gspca_dev->dev, 0),
  531. 0,
  532. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  533. 0x01, 0,
  534. tmpbuf, len * 2, 500);
  535. if (len * 2 > USB_BUF_SZ)
  536. kfree(tmpbuf);
  537. }
  538. /* Reported as OM6802*/
  539. static void om6802_sensor_init(struct gspca_dev *gspca_dev)
  540. {
  541. int i;
  542. const u8 *p;
  543. u8 byte;
  544. u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
  545. static const u8 sensor_init[] = {
  546. 0xdf, 0x6d,
  547. 0xdd, 0x18,
  548. 0x5a, 0xe0,
  549. 0x5c, 0x07,
  550. 0x5d, 0xb0,
  551. 0x5e, 0x1e,
  552. 0x60, 0x71,
  553. 0xef, 0x00,
  554. 0xe9, 0x00,
  555. 0xea, 0x00,
  556. 0x90, 0x24,
  557. 0x91, 0xb2,
  558. 0x82, 0x32,
  559. 0xfd, 0x41,
  560. 0x00 /* table end */
  561. };
  562. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  563. msleep(100);
  564. i = 4;
  565. while (--i > 0) {
  566. byte = reg_r(gspca_dev, 0x0060);
  567. if (!(byte & 0x01))
  568. break;
  569. msleep(100);
  570. }
  571. byte = reg_r(gspca_dev, 0x0063);
  572. if (byte != 0x17) {
  573. err("Bad sensor reset %02x", byte);
  574. /* continue? */
  575. }
  576. p = sensor_init;
  577. while (*p != 0) {
  578. val[1] = *p++;
  579. val[3] = *p++;
  580. if (*p == 0)
  581. reg_w(gspca_dev, 0x3c80);
  582. reg_w_buf(gspca_dev, val, sizeof val);
  583. i = 4;
  584. while (--i >= 0) {
  585. msleep(15);
  586. byte = reg_r(gspca_dev, 0x60);
  587. if (!(byte & 0x01))
  588. break;
  589. }
  590. }
  591. msleep(15);
  592. reg_w(gspca_dev, 0x3c80);
  593. }
  594. /* this function is called at probe time */
  595. static int sd_config(struct gspca_dev *gspca_dev,
  596. const struct usb_device_id *id)
  597. {
  598. struct sd *sd = (struct sd *) gspca_dev;
  599. struct cam *cam;
  600. cam = &gspca_dev->cam;
  601. cam->cam_mode = vga_mode_t16;
  602. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  603. sd->brightness = BRIGHTNESS_DEF;
  604. sd->contrast = CONTRAST_DEF;
  605. sd->colors = COLORS_DEF;
  606. sd->gamma = GAMMA_DEF;
  607. sd->autogain = AUTOGAIN_DEF;
  608. sd->mirror = MIRROR_DEF;
  609. sd->freq = FREQ_DEF;
  610. sd->whitebalance = WHITE_BALANCE_DEF;
  611. sd->sharpness = SHARPNESS_DEF;
  612. sd->effect = EFFECTS_DEF;
  613. return 0;
  614. }
  615. static void setbrightness(struct gspca_dev *gspca_dev)
  616. {
  617. struct sd *sd = (struct sd *) gspca_dev;
  618. unsigned int brightness;
  619. u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
  620. brightness = sd->brightness;
  621. if (brightness < 7) {
  622. set6[1] = 0x26;
  623. set6[3] = 0x70 - brightness * 0x10;
  624. } else {
  625. set6[3] = 0x00 + ((brightness - 7) * 0x10);
  626. }
  627. reg_w_buf(gspca_dev, set6, sizeof set6);
  628. }
  629. static void setcontrast(struct gspca_dev *gspca_dev)
  630. {
  631. struct sd *sd = (struct sd *) gspca_dev;
  632. unsigned int contrast = sd->contrast;
  633. u16 reg_to_write;
  634. if (contrast < 7)
  635. reg_to_write = 0x8ea9 - contrast * 0x200;
  636. else
  637. reg_to_write = 0x00a9 + (contrast - 7) * 0x200;
  638. reg_w(gspca_dev, reg_to_write);
  639. }
  640. static void setcolors(struct gspca_dev *gspca_dev)
  641. {
  642. struct sd *sd = (struct sd *) gspca_dev;
  643. u16 reg_to_write;
  644. reg_to_write = 0x80bb + sd->colors * 0x100; /* was 0xc0 */
  645. reg_w(gspca_dev, reg_to_write);
  646. }
  647. static void setgamma(struct gspca_dev *gspca_dev)
  648. {
  649. struct sd *sd = (struct sd *) gspca_dev;
  650. PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
  651. reg_w_ixbuf(gspca_dev, 0x90,
  652. gamma_table[sd->gamma], sizeof gamma_table[0]);
  653. }
  654. static void setwhitebalance(struct gspca_dev *gspca_dev)
  655. {
  656. struct sd *sd = (struct sd *) gspca_dev;
  657. u8 white_balance[8] =
  658. {0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38};
  659. if (sd->whitebalance)
  660. white_balance[7] = 0x3c;
  661. reg_w_buf(gspca_dev, white_balance, sizeof white_balance);
  662. }
  663. static void setsharpness(struct gspca_dev *gspca_dev)
  664. {
  665. struct sd *sd = (struct sd *) gspca_dev;
  666. u16 reg_to_write;
  667. reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
  668. reg_w(gspca_dev, reg_to_write);
  669. }
  670. /* this function is called at probe and resume time */
  671. static int sd_init(struct gspca_dev *gspca_dev)
  672. {
  673. /* some of this registers are not really neded, because
  674. * they are overriden by setbrigthness, setcontrast, etc,
  675. * but wont hurt anyway, and can help someone with similar webcam
  676. * to see the initial parameters.*/
  677. struct sd *sd = (struct sd *) gspca_dev;
  678. const struct additional_sensor_data *sensor;
  679. int i;
  680. u16 sensor_id;
  681. u8 test_byte = 0;
  682. static const u8 read_indexs[] =
  683. { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  684. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 };
  685. static const u8 n1[] =
  686. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  687. static const u8 n2[] =
  688. {0x08, 0x00};
  689. sensor_id = (reg_r(gspca_dev, 0x06) << 8)
  690. | reg_r(gspca_dev, 0x07);
  691. switch (sensor_id & 0xff0f) {
  692. case 0x0801:
  693. PDEBUG(D_PROBE, "sensor tas5130a");
  694. sd->sensor = SENSOR_TAS5130A;
  695. break;
  696. case 0x0802:
  697. PDEBUG(D_PROBE, "sensor lt168g");
  698. sd->sensor = SENSOR_LT168G;
  699. break;
  700. case 0x0803:
  701. PDEBUG(D_PROBE, "sensor 'other'");
  702. sd->sensor = SENSOR_OTHER;
  703. break;
  704. case 0x0807:
  705. PDEBUG(D_PROBE, "sensor om6802");
  706. sd->sensor = SENSOR_OM6802;
  707. break;
  708. default:
  709. PDEBUG(D_ERR|D_PROBE, "unknown sensor %04x", sensor_id);
  710. return -EINVAL;
  711. }
  712. if (sd->sensor == SENSOR_OM6802) {
  713. reg_w_buf(gspca_dev, n1, sizeof n1);
  714. i = 5;
  715. while (--i >= 0) {
  716. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  717. test_byte = reg_r(gspca_dev, 0x0063);
  718. msleep(100);
  719. if (test_byte == 0x17)
  720. break; /* OK */
  721. }
  722. if (i < 0) {
  723. err("Bad sensor reset %02x", test_byte);
  724. return -EIO;
  725. }
  726. reg_w_buf(gspca_dev, n2, sizeof n2);
  727. }
  728. i = 0;
  729. while (read_indexs[i] != 0x00) {
  730. test_byte = reg_r(gspca_dev, read_indexs[i]);
  731. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
  732. test_byte);
  733. i++;
  734. }
  735. sensor = &sensor_data[sd->sensor];
  736. reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3);
  737. reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
  738. if (sd->sensor == SENSOR_LT168G) {
  739. test_byte = reg_r(gspca_dev, 0x80);
  740. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
  741. test_byte);
  742. reg_w(gspca_dev, 0x6c80);
  743. }
  744. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  745. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  746. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  747. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  748. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  749. reg_w(gspca_dev, (sensor->reg8e << 8) + 0x8e);
  750. setbrightness(gspca_dev);
  751. setcontrast(gspca_dev);
  752. setgamma(gspca_dev);
  753. setcolors(gspca_dev);
  754. setsharpness(gspca_dev);
  755. setwhitebalance(gspca_dev);
  756. reg_w(gspca_dev, 0x2087); /* tied to white balance? */
  757. reg_w(gspca_dev, 0x2088);
  758. reg_w(gspca_dev, 0x2089);
  759. reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4);
  760. reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5);
  761. reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
  762. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  763. if (sd->sensor == SENSOR_LT168G) {
  764. test_byte = reg_r(gspca_dev, 0x80);
  765. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
  766. test_byte);
  767. reg_w(gspca_dev, 0x6c80);
  768. }
  769. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  770. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  771. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  772. return 0;
  773. }
  774. static void setflip(struct gspca_dev *gspca_dev)
  775. {
  776. struct sd *sd = (struct sd *) gspca_dev;
  777. u8 flipcmd[8] =
  778. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
  779. if (sd->mirror)
  780. flipcmd[3] = 0x01;
  781. reg_w_buf(gspca_dev, flipcmd, sizeof flipcmd);
  782. }
  783. static void seteffect(struct gspca_dev *gspca_dev)
  784. {
  785. struct sd *sd = (struct sd *) gspca_dev;
  786. reg_w_buf(gspca_dev, effects_table[sd->effect],
  787. sizeof effects_table[0]);
  788. if (sd->effect == 1 || sd->effect == 5) {
  789. PDEBUG(D_CONF,
  790. "This effect have been disabled for webcam \"safety\"");
  791. return;
  792. }
  793. if (sd->effect == 1 || sd->effect == 4)
  794. reg_w(gspca_dev, 0x4aa6);
  795. else
  796. reg_w(gspca_dev, 0xfaa6);
  797. }
  798. static void setlightfreq(struct gspca_dev *gspca_dev)
  799. {
  800. struct sd *sd = (struct sd *) gspca_dev;
  801. u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
  802. if (sd->freq == 2) /* 60hz */
  803. freq[1] = 0x00;
  804. reg_w_buf(gspca_dev, freq, sizeof freq);
  805. }
  806. /* Is this really needed?
  807. * i added some module parameters for test with some users */
  808. static void poll_sensor(struct gspca_dev *gspca_dev)
  809. {
  810. static const u8 poll1[] =
  811. {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
  812. 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
  813. 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01,
  814. 0x60, 0x14};
  815. static const u8 poll2[] =
  816. {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
  817. 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
  818. static const u8 poll3[] =
  819. {0x87, 0x3f, 0x88, 0x20, 0x89, 0x2d};
  820. static const u8 poll4[] =
  821. {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
  822. 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
  823. 0xc2, 0x80, 0xc3, 0x10};
  824. PDEBUG(D_STREAM, "[Sensor requires polling]");
  825. reg_w_buf(gspca_dev, poll1, sizeof poll1);
  826. reg_w_buf(gspca_dev, poll2, sizeof poll2);
  827. reg_w_buf(gspca_dev, poll3, sizeof poll3);
  828. reg_w_buf(gspca_dev, poll4, sizeof poll4);
  829. }
  830. static int sd_start(struct gspca_dev *gspca_dev)
  831. {
  832. struct sd *sd = (struct sd *) gspca_dev;
  833. const struct additional_sensor_data *sensor;
  834. int i, mode;
  835. u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  836. static const u8 t3[] =
  837. { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
  838. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  839. switch (mode) {
  840. case 0: /* 640x480 (0x00) */
  841. break;
  842. case 1: /* 352x288 */
  843. t2[1] = 0x40;
  844. break;
  845. case 2: /* 320x240 */
  846. t2[1] = 0x10;
  847. break;
  848. case 3: /* 176x144 */
  849. t2[1] = 0x50;
  850. break;
  851. default:
  852. /* case 4: * 160x120 */
  853. t2[1] = 0x20;
  854. break;
  855. }
  856. switch (sd->sensor) {
  857. case SENSOR_OM6802:
  858. om6802_sensor_init(gspca_dev);
  859. break;
  860. case SENSOR_LT168G:
  861. break;
  862. case SENSOR_OTHER:
  863. break;
  864. default:
  865. /* case SENSOR_TAS5130A: */
  866. i = 0;
  867. for (;;) {
  868. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  869. sizeof tas5130a_sensor_init[0]);
  870. if (i >= ARRAY_SIZE(tas5130a_sensor_init) - 1)
  871. break;
  872. i++;
  873. }
  874. reg_w(gspca_dev, 0x3c80);
  875. /* just in case and to keep sync with logs (for mine) */
  876. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  877. sizeof tas5130a_sensor_init[0]);
  878. reg_w(gspca_dev, 0x3c80);
  879. break;
  880. }
  881. sensor = &sensor_data[sd->sensor];
  882. reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4);
  883. reg_r(gspca_dev, 0x0012);
  884. reg_w_buf(gspca_dev, t2, sizeof t2);
  885. reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
  886. reg_w(gspca_dev, 0x0013);
  887. msleep(15);
  888. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  889. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  890. if (sd->sensor == SENSOR_OM6802)
  891. poll_sensor(gspca_dev);
  892. return 0;
  893. }
  894. static void sd_stopN(struct gspca_dev *gspca_dev)
  895. {
  896. struct sd *sd = (struct sd *) gspca_dev;
  897. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  898. sizeof sensor_data[sd->sensor].stream);
  899. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  900. sizeof sensor_data[sd->sensor].stream);
  901. if (sd->sensor == SENSOR_OM6802) {
  902. msleep(20);
  903. reg_w(gspca_dev, 0x0309);
  904. }
  905. }
  906. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  907. u8 *data, /* isoc packet */
  908. int len) /* iso packet length */
  909. {
  910. static u8 ffd9[] = { 0xff, 0xd9 };
  911. if (data[0] == 0x5a) {
  912. /* Control Packet, after this came the header again,
  913. * but extra bytes came in the packet before this,
  914. * sometimes an EOF arrives, sometimes not... */
  915. return;
  916. }
  917. data += 2;
  918. len -= 2;
  919. if (data[0] == 0xff && data[1] == 0xd8) {
  920. /* extra bytes....., could be processed too but would be
  921. * a waste of time, right now leave the application and
  922. * libjpeg do it for ourserlves.. */
  923. gspca_frame_add(gspca_dev, LAST_PACKET,
  924. ffd9, 2);
  925. gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
  926. return;
  927. }
  928. if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
  929. /* Just in case, i have seen packets with the marker,
  930. * other's do not include it... */
  931. len -= 2;
  932. }
  933. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  934. }
  935. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  936. {
  937. struct sd *sd = (struct sd *) gspca_dev;
  938. sd->brightness = val;
  939. if (gspca_dev->streaming)
  940. setbrightness(gspca_dev);
  941. return 0;
  942. }
  943. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  944. {
  945. struct sd *sd = (struct sd *) gspca_dev;
  946. *val = sd->brightness;
  947. return *val;
  948. }
  949. static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val)
  950. {
  951. struct sd *sd = (struct sd *) gspca_dev;
  952. sd->whitebalance = val;
  953. if (gspca_dev->streaming)
  954. setwhitebalance(gspca_dev);
  955. return 0;
  956. }
  957. static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val)
  958. {
  959. struct sd *sd = (struct sd *) gspca_dev;
  960. *val = sd->whitebalance;
  961. return *val;
  962. }
  963. static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val)
  964. {
  965. struct sd *sd = (struct sd *) gspca_dev;
  966. sd->mirror = val;
  967. if (gspca_dev->streaming)
  968. setflip(gspca_dev);
  969. return 0;
  970. }
  971. static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val)
  972. {
  973. struct sd *sd = (struct sd *) gspca_dev;
  974. *val = sd->mirror;
  975. return *val;
  976. }
  977. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val)
  978. {
  979. struct sd *sd = (struct sd *) gspca_dev;
  980. sd->effect = val;
  981. if (gspca_dev->streaming)
  982. seteffect(gspca_dev);
  983. return 0;
  984. }
  985. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val)
  986. {
  987. struct sd *sd = (struct sd *) gspca_dev;
  988. *val = sd->effect;
  989. return *val;
  990. }
  991. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  992. {
  993. struct sd *sd = (struct sd *) gspca_dev;
  994. sd->contrast = val;
  995. if (gspca_dev->streaming)
  996. setcontrast(gspca_dev);
  997. return 0;
  998. }
  999. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1000. {
  1001. struct sd *sd = (struct sd *) gspca_dev;
  1002. *val = sd->contrast;
  1003. return *val;
  1004. }
  1005. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1006. {
  1007. struct sd *sd = (struct sd *) gspca_dev;
  1008. sd->colors = val;
  1009. if (gspca_dev->streaming)
  1010. setcolors(gspca_dev);
  1011. return 0;
  1012. }
  1013. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1014. {
  1015. struct sd *sd = (struct sd *) gspca_dev;
  1016. *val = sd->colors;
  1017. return 0;
  1018. }
  1019. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
  1020. {
  1021. struct sd *sd = (struct sd *) gspca_dev;
  1022. sd->gamma = val;
  1023. if (gspca_dev->streaming)
  1024. setgamma(gspca_dev);
  1025. return 0;
  1026. }
  1027. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
  1028. {
  1029. struct sd *sd = (struct sd *) gspca_dev;
  1030. *val = sd->gamma;
  1031. return 0;
  1032. }
  1033. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  1034. {
  1035. struct sd *sd = (struct sd *) gspca_dev;
  1036. sd->freq = val;
  1037. if (gspca_dev->streaming)
  1038. setlightfreq(gspca_dev);
  1039. return 0;
  1040. }
  1041. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  1042. {
  1043. struct sd *sd = (struct sd *) gspca_dev;
  1044. *val = sd->freq;
  1045. return 0;
  1046. }
  1047. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1048. {
  1049. struct sd *sd = (struct sd *) gspca_dev;
  1050. sd->sharpness = val;
  1051. if (gspca_dev->streaming)
  1052. setsharpness(gspca_dev);
  1053. return 0;
  1054. }
  1055. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1056. {
  1057. struct sd *sd = (struct sd *) gspca_dev;
  1058. *val = sd->sharpness;
  1059. return 0;
  1060. }
  1061. /* Low Light set here......*/
  1062. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
  1063. {
  1064. struct sd *sd = (struct sd *) gspca_dev;
  1065. sd->autogain = val;
  1066. if (val != 0)
  1067. reg_w(gspca_dev, 0xf48e);
  1068. else
  1069. reg_w(gspca_dev, 0xb48e);
  1070. return 0;
  1071. }
  1072. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
  1073. {
  1074. struct sd *sd = (struct sd *) gspca_dev;
  1075. *val = sd->autogain;
  1076. return 0;
  1077. }
  1078. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1079. struct v4l2_querymenu *menu)
  1080. {
  1081. switch (menu->id) {
  1082. case V4L2_CID_POWER_LINE_FREQUENCY:
  1083. switch (menu->index) {
  1084. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  1085. strcpy((char *) menu->name, "50 Hz");
  1086. return 0;
  1087. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  1088. strcpy((char *) menu->name, "60 Hz");
  1089. return 0;
  1090. }
  1091. break;
  1092. case V4L2_CID_EFFECTS:
  1093. if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) {
  1094. strncpy((char *) menu->name,
  1095. effects_control[menu->index], 32);
  1096. return 0;
  1097. }
  1098. break;
  1099. }
  1100. return -EINVAL;
  1101. }
  1102. /* sub-driver description */
  1103. static const struct sd_desc sd_desc = {
  1104. .name = MODULE_NAME,
  1105. .ctrls = sd_ctrls,
  1106. .nctrls = ARRAY_SIZE(sd_ctrls),
  1107. .config = sd_config,
  1108. .init = sd_init,
  1109. .start = sd_start,
  1110. .stopN = sd_stopN,
  1111. .pkt_scan = sd_pkt_scan,
  1112. .querymenu = sd_querymenu,
  1113. };
  1114. /* -- module initialisation -- */
  1115. static const __devinitdata struct usb_device_id device_table[] = {
  1116. {USB_DEVICE(0x17a1, 0x0128)},
  1117. {}
  1118. };
  1119. MODULE_DEVICE_TABLE(usb, device_table);
  1120. /* -- device connect -- */
  1121. static int sd_probe(struct usb_interface *intf,
  1122. const struct usb_device_id *id)
  1123. {
  1124. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1125. THIS_MODULE);
  1126. }
  1127. static struct usb_driver sd_driver = {
  1128. .name = MODULE_NAME,
  1129. .id_table = device_table,
  1130. .probe = sd_probe,
  1131. .disconnect = gspca_disconnect,
  1132. #ifdef CONFIG_PM
  1133. .suspend = gspca_suspend,
  1134. .resume = gspca_resume,
  1135. #endif
  1136. };
  1137. /* -- module insert / remove -- */
  1138. static int __init sd_mod_init(void)
  1139. {
  1140. int ret;
  1141. ret = usb_register(&sd_driver);
  1142. if (ret < 0)
  1143. return ret;
  1144. PDEBUG(D_PROBE, "registered");
  1145. return 0;
  1146. }
  1147. static void __exit sd_mod_exit(void)
  1148. {
  1149. usb_deregister(&sd_driver);
  1150. PDEBUG(D_PROBE, "deregistered");
  1151. }
  1152. module_init(sd_mod_init);
  1153. module_exit(sd_mod_exit);