t613.c 30 KB

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