t613.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  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 data1[10];
  255. const u8 data2[9];
  256. const u8 data3[9];
  257. const u8 data4[4];
  258. const u8 data5[6];
  259. const u8 stream[4];
  260. };
  261. static const struct additional_sensor_data sensor_data[] = {
  262. { /* OM6802 */
  263. .data1 =
  264. {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06,
  265. 0xb3, 0xfc},
  266. .data2 =
  267. {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
  268. 0xff},
  269. .data4 = /*Freq (50/60Hz). Splitted for test purpose */
  270. {0x66, 0xca, 0xa8, 0xf0},
  271. .data5 = /* this could be removed later */
  272. {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
  273. .stream =
  274. {0x0b, 0x04, 0x0a, 0x78},
  275. },
  276. { /* OTHER */
  277. .data1 =
  278. {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a,
  279. 0xe8, 0xfc},
  280. .data2 =
  281. {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
  282. 0xd9},
  283. .data4 =
  284. {0x66, 0x00, 0xa8, 0xa8},
  285. .data5 =
  286. {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69},
  287. .stream =
  288. {0x0b, 0x04, 0x0a, 0x00},
  289. },
  290. { /* TAS5130A */
  291. .data1 =
  292. {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27,
  293. 0xc8, 0xfc},
  294. .data2 =
  295. {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
  296. 0xe0},
  297. .data4 = /* Freq (50/60Hz). Splitted for test purpose */
  298. {0x66, 0x00, 0xa8, 0xe8},
  299. .data5 =
  300. {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20},
  301. .stream =
  302. {0x0b, 0x04, 0x0a, 0x40},
  303. },
  304. };
  305. #define MAX_EFFECTS 7
  306. /* easily done by soft, this table could be removed,
  307. * i keep it here just in case */
  308. static const u8 effects_table[MAX_EFFECTS][6] = {
  309. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
  310. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
  311. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
  312. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */
  313. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */
  314. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */
  315. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
  316. };
  317. static const u8 gamma_table[GAMMA_MAX][17] = {
  318. {0x00, 0x3e, 0x69, 0x85, 0x95, 0xa1, 0xae, 0xb9, /* 0 */
  319. 0xc2, 0xcb, 0xd4, 0xdb, 0xe3, 0xea, 0xf1, 0xf8,
  320. 0xff},
  321. {0x00, 0x33, 0x5a, 0x75, 0x85, 0x93, 0xa1, 0xad, /* 1 */
  322. 0xb7, 0xc2, 0xcb, 0xd4, 0xde, 0xe7, 0xf0, 0xf7,
  323. 0xff},
  324. {0x00, 0x2f, 0x51, 0x6b, 0x7c, 0x8a, 0x99, 0xa6, /* 2 */
  325. 0xb1, 0xbc, 0xc6, 0xd0, 0xdb, 0xe4, 0xed, 0xf6,
  326. 0xff},
  327. {0x00, 0x29, 0x48, 0x60, 0x72, 0x81, 0x90, 0x9e, /* 3 */
  328. 0xaa, 0xb5, 0xbf, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
  329. 0xff},
  330. {0x00, 0x23, 0x3f, 0x55, 0x68, 0x77, 0x86, 0x95, /* 4 */
  331. 0xa2, 0xad, 0xb9, 0xc6, 0xd2, 0xde, 0xe9, 0xf4,
  332. 0xff},
  333. {0x00, 0x1b, 0x33, 0x48, 0x59, 0x69, 0x79, 0x87, /* 5 */
  334. 0x96, 0xa3, 0xb1, 0xbe, 0xcc, 0xda, 0xe7, 0xf3,
  335. 0xff},
  336. {0x00, 0x02, 0x10, 0x20, 0x32, 0x40, 0x57, 0x67, /* 6 */
  337. 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
  338. 0xff},
  339. {0x00, 0x02, 0x14, 0x26, 0x38, 0x4a, 0x60, 0x70, /* 7 */
  340. 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
  341. 0xff},
  342. {0x00, 0x10, 0x22, 0x35, 0x47, 0x5a, 0x69, 0x79, /* 8 */
  343. 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe0, 0xf0,
  344. 0xff},
  345. {0x00, 0x10, 0x26, 0x40, 0x54, 0x65, 0x75, 0x84, /* 9 */
  346. 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd6, 0xe0, 0xf0,
  347. 0xff},
  348. {0x00, 0x18, 0x2b, 0x44, 0x60, 0x70, 0x80, 0x8e, /* 10 */
  349. 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xd8, 0xe2, 0xf0,
  350. 0xff},
  351. {0x00, 0x1a, 0x34, 0x52, 0x66, 0x7e, 0x8D, 0x9B, /* 11 */
  352. 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
  353. 0xff},
  354. {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
  355. 0xb4, 0xbf, 0xc9, 0xd3, 0xdc, 0xe5, 0xee, 0xf6,
  356. 0xff},
  357. {0x00, 0x54, 0x6f, 0x83, 0x93, 0xa0, 0xad, 0xb7, /* 13 */
  358. 0xc2, 0xcb, 0xd4, 0xdc, 0xe4, 0xeb, 0xf2, 0xf9,
  359. 0xff},
  360. {0x00, 0x6e, 0x88, 0x9a, 0xa8, 0xb3, 0xbd, 0xc6, /* 14 */
  361. 0xcf, 0xd6, 0xdd, 0xe3, 0xe9, 0xef, 0xf4, 0xfa,
  362. 0xff},
  363. {0x00, 0x93, 0xa8, 0xb7, 0xc1, 0xca, 0xd2, 0xd8, /* 15 */
  364. 0xde, 0xe3, 0xe8, 0xed, 0xf1, 0xf5, 0xf8, 0xfc,
  365. 0xff}
  366. };
  367. static const u8 tas5130a_sensor_init[][8] = {
  368. {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
  369. {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
  370. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  371. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  372. {},
  373. };
  374. static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
  375. /* read 1 byte */
  376. static u8 reg_r(struct gspca_dev *gspca_dev,
  377. u16 index)
  378. {
  379. usb_control_msg(gspca_dev->dev,
  380. usb_rcvctrlpipe(gspca_dev->dev, 0),
  381. 0, /* request */
  382. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  383. 0, /* value */
  384. index,
  385. gspca_dev->usb_buf, 1, 500);
  386. return gspca_dev->usb_buf[0];
  387. }
  388. static void reg_w(struct gspca_dev *gspca_dev,
  389. u16 index)
  390. {
  391. usb_control_msg(gspca_dev->dev,
  392. usb_sndctrlpipe(gspca_dev->dev, 0),
  393. 0,
  394. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  395. 0, index,
  396. NULL, 0, 500);
  397. }
  398. static void reg_w_buf(struct gspca_dev *gspca_dev,
  399. const u8 *buffer, u16 len)
  400. {
  401. if (len <= USB_BUF_SZ) {
  402. memcpy(gspca_dev->usb_buf, buffer, len);
  403. usb_control_msg(gspca_dev->dev,
  404. usb_sndctrlpipe(gspca_dev->dev, 0),
  405. 0,
  406. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  407. 0x01, 0,
  408. gspca_dev->usb_buf, len, 500);
  409. } else {
  410. u8 *tmpbuf;
  411. tmpbuf = kmalloc(len, GFP_KERNEL);
  412. memcpy(tmpbuf, buffer, len);
  413. usb_control_msg(gspca_dev->dev,
  414. usb_sndctrlpipe(gspca_dev->dev, 0),
  415. 0,
  416. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  417. 0x01, 0,
  418. tmpbuf, len, 500);
  419. kfree(tmpbuf);
  420. }
  421. }
  422. /* write values to consecutive registers */
  423. static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
  424. u8 reg,
  425. const u8 *buffer, u16 len)
  426. {
  427. int i;
  428. u8 *p, *tmpbuf;
  429. if (len * 2 <= USB_BUF_SZ)
  430. p = tmpbuf = gspca_dev->usb_buf;
  431. else
  432. p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
  433. i = len;
  434. while (--i >= 0) {
  435. *p++ = reg++;
  436. *p++ = *buffer++;
  437. }
  438. usb_control_msg(gspca_dev->dev,
  439. usb_sndctrlpipe(gspca_dev->dev, 0),
  440. 0,
  441. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  442. 0x01, 0,
  443. tmpbuf, len * 2, 500);
  444. if (len * 2 > USB_BUF_SZ)
  445. kfree(tmpbuf);
  446. }
  447. /* Reported as OM6802*/
  448. static void om6802_sensor_init(struct gspca_dev *gspca_dev)
  449. {
  450. int i;
  451. const u8 *p;
  452. u8 byte;
  453. u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
  454. static const u8 sensor_init[] = {
  455. 0xdf, 0x6d,
  456. 0xdd, 0x18,
  457. 0x5a, 0xe0,
  458. 0x5c, 0x07,
  459. 0x5d, 0xb0,
  460. 0x5e, 0x1e,
  461. 0x60, 0x71,
  462. 0xef, 0x00,
  463. 0xe9, 0x00,
  464. 0xea, 0x00,
  465. 0x90, 0x24,
  466. 0x91, 0xb2,
  467. 0x82, 0x32,
  468. 0xfd, 0x41,
  469. 0x00 /* table end */
  470. };
  471. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  472. msleep(100);
  473. i = 4;
  474. while (--i > 0) {
  475. byte = reg_r(gspca_dev, 0x0060);
  476. if (!(byte & 0x01))
  477. break;
  478. msleep(100);
  479. }
  480. byte = reg_r(gspca_dev, 0x0063);
  481. if (byte != 0x17) {
  482. err("Bad sensor reset %02x", byte);
  483. /* continue? */
  484. }
  485. p = sensor_init;
  486. while (*p != 0) {
  487. val[1] = *p++;
  488. val[3] = *p++;
  489. if (*p == 0)
  490. reg_w(gspca_dev, 0x3c80);
  491. reg_w_buf(gspca_dev, val, sizeof val);
  492. i = 4;
  493. while (--i >= 0) {
  494. msleep(15);
  495. byte = reg_r(gspca_dev, 0x60);
  496. if (!(byte & 0x01))
  497. break;
  498. }
  499. }
  500. msleep(15);
  501. reg_w(gspca_dev, 0x3c80);
  502. }
  503. /* this function is called at probe time */
  504. static int sd_config(struct gspca_dev *gspca_dev,
  505. const struct usb_device_id *id)
  506. {
  507. struct sd *sd = (struct sd *) gspca_dev;
  508. struct cam *cam;
  509. cam = &gspca_dev->cam;
  510. cam->cam_mode = vga_mode_t16;
  511. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  512. sd->brightness = BRIGHTNESS_DEF;
  513. sd->contrast = CONTRAST_DEF;
  514. sd->colors = COLORS_DEF;
  515. sd->gamma = GAMMA_DEF;
  516. sd->autogain = AUTOGAIN_DEF;
  517. sd->mirror = MIRROR_DEF;
  518. sd->freq = FREQ_DEF;
  519. sd->whitebalance = WHITE_BALANCE_DEF;
  520. sd->sharpness = SHARPNESS_DEF;
  521. sd->effect = EFFECTS_DEF;
  522. return 0;
  523. }
  524. static void setbrightness(struct gspca_dev *gspca_dev)
  525. {
  526. struct sd *sd = (struct sd *) gspca_dev;
  527. unsigned int brightness;
  528. u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
  529. brightness = sd->brightness;
  530. if (brightness < 7) {
  531. set6[1] = 0x26;
  532. set6[3] = 0x70 - brightness * 0x10;
  533. } else {
  534. set6[3] = 0x00 + ((brightness - 7) * 0x10);
  535. }
  536. reg_w_buf(gspca_dev, set6, sizeof set6);
  537. }
  538. static void setcontrast(struct gspca_dev *gspca_dev)
  539. {
  540. struct sd *sd = (struct sd *) gspca_dev;
  541. unsigned int contrast = sd->contrast;
  542. u16 reg_to_write;
  543. if (contrast < 7)
  544. reg_to_write = 0x8ea9 - contrast * 0x200;
  545. else
  546. reg_to_write = 0x00a9 + (contrast - 7) * 0x200;
  547. reg_w(gspca_dev, reg_to_write);
  548. }
  549. static void setcolors(struct gspca_dev *gspca_dev)
  550. {
  551. struct sd *sd = (struct sd *) gspca_dev;
  552. u16 reg_to_write;
  553. reg_to_write = 0x80bb + sd->colors * 0x100; /* was 0xc0 */
  554. reg_w(gspca_dev, reg_to_write);
  555. }
  556. static void setgamma(struct gspca_dev *gspca_dev)
  557. {
  558. struct sd *sd = (struct sd *) gspca_dev;
  559. PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
  560. reg_w_ixbuf(gspca_dev, 0x90,
  561. gamma_table[sd->gamma], sizeof gamma_table[0]);
  562. }
  563. static void setwhitebalance(struct gspca_dev *gspca_dev)
  564. {
  565. struct sd *sd = (struct sd *) gspca_dev;
  566. u8 white_balance[8] =
  567. {0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38};
  568. if (sd->whitebalance)
  569. white_balance[7] = 0x3c;
  570. reg_w_buf(gspca_dev, white_balance, sizeof white_balance);
  571. }
  572. static void setsharpness(struct gspca_dev *gspca_dev)
  573. {
  574. struct sd *sd = (struct sd *) gspca_dev;
  575. u16 reg_to_write;
  576. reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
  577. reg_w(gspca_dev, reg_to_write);
  578. }
  579. /* this function is called at probe and resume time */
  580. static int sd_init(struct gspca_dev *gspca_dev)
  581. {
  582. /* some of this registers are not really neded, because
  583. * they are overriden by setbrigthness, setcontrast, etc,
  584. * but wont hurt anyway, and can help someone with similar webcam
  585. * to see the initial parameters.*/
  586. struct sd *sd = (struct sd *) gspca_dev;
  587. int i;
  588. u16 sensor_id;
  589. u8 test_byte = 0;
  590. u16 reg80, reg8e;
  591. static const u8 read_indexs[] =
  592. { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  593. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 };
  594. static const u8 n1[] =
  595. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  596. static const u8 n2[] =
  597. {0x08, 0x00};
  598. static const u8 n3[6] =
  599. {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
  600. static const u8 n3_other[6] =
  601. {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00};
  602. static const u8 n4[] =
  603. {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
  604. 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
  605. 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
  606. 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
  607. 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
  608. 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
  609. 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
  610. 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
  611. 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
  612. static const u8 n4_other[] =
  613. {0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
  614. 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
  615. 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
  616. 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
  617. 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
  618. 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
  619. 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
  620. 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00};
  621. static const u8 nset8[6] =
  622. { 0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00 };
  623. static const u8 nset8_other[6] =
  624. { 0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00 };
  625. static const u8 nset9[4] =
  626. { 0x0b, 0x04, 0x0a, 0x78 };
  627. static const u8 nset9_other[4] =
  628. { 0x0b, 0x04, 0x0a, 0x00 };
  629. sensor_id = (reg_r(gspca_dev, 0x06) << 8)
  630. | reg_r(gspca_dev, 0x07);
  631. switch (sensor_id & 0xff0f) {
  632. case 0x0801:
  633. PDEBUG(D_PROBE, "sensor tas5130a");
  634. sd->sensor = SENSOR_TAS5130A;
  635. break;
  636. case 0x0803:
  637. PDEBUG(D_PROBE, "sensor 'other'");
  638. sd->sensor = SENSOR_OTHER;
  639. break;
  640. case 0x0807:
  641. PDEBUG(D_PROBE, "sensor om6802");
  642. sd->sensor = SENSOR_OM6802;
  643. break;
  644. default:
  645. PDEBUG(D_ERR|D_PROBE, "unknown sensor %04x", sensor_id);
  646. return -EINVAL;
  647. }
  648. if (sd->sensor != SENSOR_OTHER) {
  649. reg_w_buf(gspca_dev, n1, sizeof n1);
  650. i = 5;
  651. while (--i >= 0) {
  652. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  653. test_byte = reg_r(gspca_dev, 0x0063);
  654. msleep(100);
  655. if (test_byte == 0x17)
  656. break; /* OK */
  657. }
  658. if (i < 0) {
  659. err("Bad sensor reset %02x", test_byte);
  660. /* return -EIO; */
  661. /*fixme: test - continue */
  662. }
  663. reg_w_buf(gspca_dev, n2, sizeof n2);
  664. }
  665. i = 0;
  666. while (read_indexs[i] != 0x00) {
  667. test_byte = reg_r(gspca_dev, read_indexs[i]);
  668. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
  669. test_byte);
  670. i++;
  671. }
  672. if (sd->sensor != SENSOR_OTHER) {
  673. reg_w_buf(gspca_dev, n3, sizeof n3);
  674. reg_w_buf(gspca_dev, n4, sizeof n4);
  675. reg_r(gspca_dev, 0x0080);
  676. reg_w(gspca_dev, 0x2c80);
  677. reg80 = 0x3880;
  678. reg8e = 0x338e;
  679. } else {
  680. reg_w_buf(gspca_dev, n3_other, sizeof n3_other);
  681. reg_w_buf(gspca_dev, n4_other, sizeof n4_other);
  682. sd->gamma = 5;
  683. reg80 = 0xac80;
  684. reg8e = 0xb88e;
  685. }
  686. reg_w_ixbuf(gspca_dev, 0xd0, sensor_data[sd->sensor].data1,
  687. sizeof sensor_data[sd->sensor].data1);
  688. reg_w_ixbuf(gspca_dev, 0xc7, sensor_data[sd->sensor].data2,
  689. sizeof sensor_data[sd->sensor].data2);
  690. reg_w_ixbuf(gspca_dev, 0xe0, sensor_data[sd->sensor].data2,
  691. sizeof sensor_data[sd->sensor].data2);
  692. reg_w(gspca_dev, reg80);
  693. reg_w(gspca_dev, reg80);
  694. reg_w(gspca_dev, reg8e);
  695. setbrightness(gspca_dev);
  696. setcontrast(gspca_dev);
  697. setgamma(gspca_dev);
  698. setcolors(gspca_dev);
  699. setsharpness(gspca_dev);
  700. setwhitebalance(gspca_dev);
  701. reg_w(gspca_dev, 0x2087); /* tied to white balance? */
  702. reg_w(gspca_dev, 0x2088);
  703. reg_w(gspca_dev, 0x2089);
  704. reg_w_buf(gspca_dev, sensor_data[sd->sensor].data4,
  705. sizeof sensor_data[sd->sensor].data4);
  706. reg_w_buf(gspca_dev, sensor_data[sd->sensor].data5,
  707. sizeof sensor_data[sd->sensor].data5);
  708. if (sd->sensor != SENSOR_OTHER) {
  709. reg_w_buf(gspca_dev, nset8, sizeof nset8);
  710. reg_w_buf(gspca_dev, nset9, sizeof nset9);
  711. reg_w(gspca_dev, 0x2880);
  712. } else {
  713. reg_w_buf(gspca_dev, nset8_other, sizeof nset8_other);
  714. reg_w_buf(gspca_dev, nset9_other, sizeof nset9_other);
  715. }
  716. reg_w_ixbuf(gspca_dev, 0xd0, sensor_data[sd->sensor].data1,
  717. sizeof sensor_data[sd->sensor].data1);
  718. reg_w_ixbuf(gspca_dev, 0xc7, sensor_data[sd->sensor].data2,
  719. sizeof sensor_data[sd->sensor].data2);
  720. reg_w_ixbuf(gspca_dev, 0xe0, sensor_data[sd->sensor].data2,
  721. sizeof sensor_data[sd->sensor].data2);
  722. return 0;
  723. }
  724. static void setflip(struct gspca_dev *gspca_dev)
  725. {
  726. struct sd *sd = (struct sd *) gspca_dev;
  727. u8 flipcmd[8] =
  728. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
  729. if (sd->mirror)
  730. flipcmd[3] = 0x01;
  731. reg_w_buf(gspca_dev, flipcmd, sizeof flipcmd);
  732. }
  733. static void seteffect(struct gspca_dev *gspca_dev)
  734. {
  735. struct sd *sd = (struct sd *) gspca_dev;
  736. reg_w_buf(gspca_dev, effects_table[sd->effect],
  737. sizeof effects_table[0]);
  738. if (sd->effect == 1 || sd->effect == 5) {
  739. PDEBUG(D_CONF,
  740. "This effect have been disabled for webcam \"safety\"");
  741. return;
  742. }
  743. if (sd->effect == 1 || sd->effect == 4)
  744. reg_w(gspca_dev, 0x4aa6);
  745. else
  746. reg_w(gspca_dev, 0xfaa6);
  747. }
  748. static void setlightfreq(struct gspca_dev *gspca_dev)
  749. {
  750. struct sd *sd = (struct sd *) gspca_dev;
  751. u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
  752. if (sd->freq == 2) /* 60hz */
  753. freq[1] = 0x00;
  754. reg_w_buf(gspca_dev, freq, sizeof freq);
  755. }
  756. /* Is this really needed?
  757. * i added some module parameters for test with some users */
  758. static void poll_sensor(struct gspca_dev *gspca_dev)
  759. {
  760. struct sd *sd = (struct sd *) gspca_dev;
  761. static const u8 poll1[] =
  762. {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
  763. 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
  764. 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01,
  765. 0x60, 0x14};
  766. static const u8 poll2[] =
  767. {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
  768. 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
  769. static const u8 poll3[] =
  770. {0x87, 0x3f, 0x88, 0x20, 0x89, 0x2d};
  771. static const u8 poll4[] =
  772. {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
  773. 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
  774. 0xc2, 0x80, 0xc3, 0x10};
  775. if (sd->sensor == SENSOR_OM6802) {
  776. PDEBUG(D_STREAM, "[Sensor requires polling]");
  777. reg_w_buf(gspca_dev, poll1, sizeof poll1);
  778. reg_w_buf(gspca_dev, poll2, sizeof poll2);
  779. reg_w_buf(gspca_dev, poll3, sizeof poll3);
  780. reg_w_buf(gspca_dev, poll4, sizeof poll4);
  781. }
  782. }
  783. static int sd_start(struct gspca_dev *gspca_dev)
  784. {
  785. struct sd *sd = (struct sd *) gspca_dev;
  786. int i, mode;
  787. u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  788. static const u8 t3[] =
  789. { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
  790. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
  791. switch (mode) {
  792. case 0: /* 640x480 (0x00) */
  793. break;
  794. case 1: /* 352x288 */
  795. t2[1] = 0x40;
  796. break;
  797. case 2: /* 320x240 */
  798. t2[1] = 0x10;
  799. break;
  800. case 3: /* 176x144 */
  801. t2[1] = 0x50;
  802. break;
  803. default:
  804. /* case 4: * 160x120 */
  805. t2[1] = 0x20;
  806. break;
  807. }
  808. switch (sd->sensor) {
  809. case SENSOR_OM6802:
  810. om6802_sensor_init(gspca_dev);
  811. break;
  812. case SENSOR_OTHER:
  813. break;
  814. default:
  815. /* case SENSOR_TAS5130A: */
  816. i = 0;
  817. while (tas5130a_sensor_init[i][0] != 0) {
  818. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  819. sizeof tas5130a_sensor_init[0]);
  820. i++;
  821. }
  822. reg_w(gspca_dev, 0x3c80);
  823. /* just in case and to keep sync with logs (for mine) */
  824. reg_w_buf(gspca_dev, tas5130a_sensor_init[3],
  825. sizeof tas5130a_sensor_init[0]);
  826. reg_w(gspca_dev, 0x3c80);
  827. break;
  828. }
  829. reg_w_buf(gspca_dev, sensor_data[sd->sensor].data4,
  830. sizeof sensor_data[sd->sensor].data4);
  831. reg_r(gspca_dev, 0x0012);
  832. reg_w_buf(gspca_dev, t2, sizeof t2);
  833. reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
  834. reg_w(gspca_dev, 0x0013);
  835. msleep(15);
  836. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  837. sizeof sensor_data[sd->sensor].stream);
  838. poll_sensor(gspca_dev);
  839. /* restart on each start, just in case, sometimes regs goes wrong
  840. * when using controls from app */
  841. setbrightness(gspca_dev);
  842. setcontrast(gspca_dev);
  843. setcolors(gspca_dev);
  844. return 0;
  845. }
  846. static void sd_stopN(struct gspca_dev *gspca_dev)
  847. {
  848. struct sd *sd = (struct sd *) gspca_dev;
  849. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  850. sizeof sensor_data[sd->sensor].stream);
  851. msleep(20);
  852. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  853. sizeof sensor_data[sd->sensor].stream);
  854. if (sd->sensor != SENSOR_OTHER) {
  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);