t613.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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. unsigned char brightness;
  35. unsigned char contrast;
  36. unsigned char colors;
  37. unsigned char autogain;
  38. unsigned char gamma;
  39. unsigned char sharpness;
  40. unsigned char freq;
  41. unsigned char whitebalance;
  42. unsigned char mirror;
  43. unsigned char effect;
  44. __u8 sensor;
  45. #define SENSOR_TAS5130A 0
  46. #define SENSOR_OM6802 1
  47. };
  48. /* V4L2 controls supported by the driver */
  49. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  50. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  51. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  52. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  53. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  54. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  55. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val);
  56. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val);
  57. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
  58. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
  59. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  60. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  61. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  62. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  63. static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val);
  64. static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val);
  65. static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val);
  66. static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val);
  67. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val);
  68. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val);
  69. static int sd_querymenu(struct gspca_dev *gspca_dev,
  70. struct v4l2_querymenu *menu);
  71. static struct ctrl sd_ctrls[] = {
  72. #define SD_BRIGHTNESS 0
  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. .default_value = 8,
  82. },
  83. .set = sd_setbrightness,
  84. .get = sd_getbrightness,
  85. },
  86. #define SD_CONTRAST 1
  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. .default_value = 0x07,
  96. },
  97. .set = sd_setcontrast,
  98. .get = sd_getcontrast,
  99. },
  100. #define SD_COLOR 2
  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. .default_value = 0x05,
  110. },
  111. .set = sd_setcolors,
  112. .get = sd_getcolors,
  113. },
  114. #define GAMMA_MAX 16
  115. #define GAMMA_DEF 10
  116. {
  117. {
  118. .id = V4L2_CID_GAMMA, /* (gamma on win) */
  119. .type = V4L2_CTRL_TYPE_INTEGER,
  120. .name = "Gamma",
  121. .minimum = 0,
  122. .maximum = GAMMA_MAX - 1,
  123. .step = 1,
  124. .default_value = GAMMA_DEF,
  125. },
  126. .set = sd_setgamma,
  127. .get = sd_getgamma,
  128. },
  129. #define SD_AUTOGAIN 4
  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. .default_value = 0x01,
  141. },
  142. .set = sd_setlowlight,
  143. .get = sd_getlowlight,
  144. },
  145. #define SD_MIRROR 5
  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. .default_value = 0,
  155. },
  156. .set = sd_setflip,
  157. .get = sd_getflip
  158. },
  159. #define SD_LIGHTFREQ 6
  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. .default_value = 1,
  169. },
  170. .set = sd_setfreq,
  171. .get = sd_getfreq},
  172. #define SD_WHITE_BALANCE 7
  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. .default_value = 0,
  182. },
  183. .set = sd_setwhitebalance,
  184. .get = sd_getwhitebalance
  185. },
  186. #define SD_SHARPNESS 8 /* (aka definition on win) */
  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. .default_value = 0x06,
  196. },
  197. .set = sd_setsharpness,
  198. .get = sd_getsharpness,
  199. },
  200. #define SD_EFFECTS 9
  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. .default_value = 0,
  210. },
  211. .set = sd_seteffect,
  212. .get = sd_geteffect
  213. },
  214. };
  215. static char *effects_control[] = {
  216. "Normal",
  217. "Emboss", /* disabled */
  218. "Monochrome",
  219. "Sepia",
  220. "Sketch",
  221. "Sun Effect", /* disabled */
  222. "Negative",
  223. };
  224. static struct v4l2_pix_format vga_mode_t16[] = {
  225. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  226. .bytesperline = 160,
  227. .sizeimage = 160 * 120 * 4 / 8 + 590,
  228. .colorspace = V4L2_COLORSPACE_JPEG,
  229. .priv = 4},
  230. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  231. .bytesperline = 176,
  232. .sizeimage = 176 * 144 * 3 / 8 + 590,
  233. .colorspace = V4L2_COLORSPACE_JPEG,
  234. .priv = 3},
  235. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  236. .bytesperline = 320,
  237. .sizeimage = 320 * 240 * 3 / 8 + 590,
  238. .colorspace = V4L2_COLORSPACE_JPEG,
  239. .priv = 2},
  240. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  241. .bytesperline = 352,
  242. .sizeimage = 352 * 288 * 3 / 8 + 590,
  243. .colorspace = V4L2_COLORSPACE_JPEG,
  244. .priv = 1},
  245. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  246. .bytesperline = 640,
  247. .sizeimage = 640 * 480 * 3 / 8 + 590,
  248. .colorspace = V4L2_COLORSPACE_JPEG,
  249. .priv = 0},
  250. };
  251. #define MAX_EFFECTS 7
  252. /* easily done by soft, this table could be removed,
  253. * i keep it here just in case */
  254. static const __u8 effects_table[MAX_EFFECTS][6] = {
  255. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
  256. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
  257. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
  258. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */
  259. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */
  260. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */
  261. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
  262. };
  263. static const __u8 gamma_table[GAMMA_MAX][34] = {
  264. {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85, /* 0 */
  265. 0x94, 0x95, 0x95, 0xa1, 0x96, 0xae, 0x97, 0xb9,
  266. 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdb,
  267. 0x9c, 0xe3, 0x9d, 0xea, 0x9e, 0xf1, 0x9f, 0xf8,
  268. 0xa0, 0xff},
  269. {0x90, 0x00, 0x91, 0x33, 0x92, 0x5a, 0x93, 0x75, /* 1 */
  270. 0x94, 0x85, 0x95, 0x93, 0x96, 0xa1, 0x97, 0xad,
  271. 0x98, 0xb7, 0x99, 0xc2, 0x9a, 0xcb, 0x9b, 0xd4,
  272. 0x9c, 0xde, 0x9D, 0xe7, 0x9e, 0xf0, 0x9f, 0xf7,
  273. 0xa0, 0xff},
  274. {0x90, 0x00, 0x91, 0x2f, 0x92, 0x51, 0x93, 0x6b, /* 2 */
  275. 0x94, 0x7c, 0x95, 0x8a, 0x96, 0x99, 0x97, 0xa6,
  276. 0x98, 0xb1, 0x99, 0xbc, 0x9a, 0xc6, 0x9b, 0xd0,
  277. 0x9c, 0xdb, 0x9d, 0xe4, 0x9e, 0xed, 0x9f, 0xf6,
  278. 0xa0, 0xff},
  279. {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60, /* 3 */
  280. 0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9e,
  281. 0x98, 0xaa, 0x99, 0xb5, 0x9a, 0xbf, 0x9b, 0xcb,
  282. 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5,
  283. 0xa0, 0xff},
  284. {0x90, 0x00, 0x91, 0x23, 0x92, 0x3f, 0x93, 0x55, /* 4 */
  285. 0x94, 0x68, 0x95, 0x77, 0x96, 0x86, 0x97, 0x95,
  286. 0x98, 0xa2, 0x99, 0xad, 0x9a, 0xb9, 0x9b, 0xc6,
  287. 0x9c, 0xd2, 0x9d, 0xde, 0x9e, 0xe9, 0x9f, 0xf4,
  288. 0xa0, 0xff},
  289. {0x90, 0x00, 0x91, 0x1b, 0x92, 0x33, 0x93, 0x48, /* 5 */
  290. 0x94, 0x59, 0x95, 0x69, 0x96, 0x79, 0x97, 0x87,
  291. 0x98, 0x96, 0x99, 0xa3, 0x9a, 0xb1, 0x9b, 0xbe,
  292. 0x9c, 0xcc, 0x9d, 0xda, 0x9e, 0xe7, 0x9f, 0xf3,
  293. 0xa0, 0xff},
  294. {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20, /* 6 */
  295. 0x94, 0x32, 0x95, 0x40, 0x96, 0x57, 0x97, 0x67,
  296. 0x98, 0x77, 0x99, 0x88, 0x9a, 0x99, 0x9b, 0xaa,
  297. 0x9c, 0xbb, 0x9d, 0xcc, 0x9e, 0xdd, 0x9f, 0xee,
  298. 0xa0, 0xff},
  299. {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26, /* 7 */
  300. 0x94, 0x38, 0x95, 0x4a, 0x96, 0x60, 0x97, 0x70,
  301. 0x98, 0x80, 0x99, 0x90, 0x9a, 0xa0, 0x9b, 0xb0,
  302. 0x9c, 0xc0, 0x9D, 0xd0, 0x9e, 0xe0, 0x9f, 0xf0,
  303. 0xa0, 0xff},
  304. {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35, /* 8 */
  305. 0x94, 0x47, 0x95, 0x5a, 0x96, 0x69, 0x97, 0x79,
  306. 0x98, 0x88, 0x99, 0x97, 0x9a, 0xa7, 0x9b, 0xb6,
  307. 0x9c, 0xc4, 0x9d, 0xd3, 0x9e, 0xe0, 0x9f, 0xf0,
  308. 0xa0, 0xff},
  309. {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40, /* 9 */
  310. 0x94, 0x54, 0x95, 0x65, 0x96, 0x75, 0x97, 0x84,
  311. 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd,
  312. 0x9c, 0xca, 0x9d, 0xd6, 0x9e, 0xe0, 0x9f, 0xf0,
  313. 0xa0, 0xff},
  314. {0x90, 0x00, 0x91, 0x18, 0x92, 0x2b, 0x93, 0x44, /* 10 */
  315. 0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8e,
  316. 0x98, 0x9c, 0x99, 0xaa, 0x9a, 0xb7, 0x9b, 0xc4,
  317. 0x9c, 0xd0, 0x9d, 0xd8, 0x9e, 0xe2, 0x9f, 0xf0,
  318. 0xa0, 0xff},
  319. {0x90, 0x00, 0x91, 0x1a, 0x92, 0x34, 0x93, 0x52, /* 11 */
  320. 0x94, 0x66, 0x95, 0x7e, 0x96, 0x8D, 0x97, 0x9B,
  321. 0x98, 0xa8, 0x99, 0xb4, 0x9a, 0xc0, 0x9b, 0xcb,
  322. 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5,
  323. 0xa0, 0xff},
  324. {0x90, 0x00, 0x91, 0x3f, 0x92, 0x5a, 0x93, 0x6e, /* 12 */
  325. 0x94, 0x7f, 0x95, 0x8e, 0x96, 0x9c, 0x97, 0xa8,
  326. 0x98, 0xb4, 0x99, 0xbf, 0x9a, 0xc9, 0x9b, 0xd3,
  327. 0x9c, 0xdc, 0x9d, 0xe5, 0x9e, 0xee, 0x9f, 0xf6,
  328. 0xa0, 0xff},
  329. {0x90, 0x00, 0x91, 0x54, 0x92, 0x6f, 0x93, 0x83, /* 13 */
  330. 0x94, 0x93, 0x95, 0xa0, 0x96, 0xad, 0x97, 0xb7,
  331. 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdc,
  332. 0x9c, 0xe4, 0x9d, 0xeb, 0x9e, 0xf2, 0x9f, 0xf9,
  333. 0xa0, 0xff},
  334. {0x90, 0x00, 0x91, 0x6e, 0x92, 0x88, 0x93, 0x9a, /* 14 */
  335. 0x94, 0xa8, 0x95, 0xb3, 0x96, 0xbd, 0x97, 0xc6,
  336. 0x98, 0xcf, 0x99, 0xd6, 0x9a, 0xdd, 0x9b, 0xe3,
  337. 0x9c, 0xe9, 0x9d, 0xef, 0x9e, 0xf4, 0x9f, 0xfa,
  338. 0xa0, 0xff},
  339. {0x90, 0x00, 0x91, 0x93, 0x92, 0xa8, 0x93, 0xb7, /* 15 */
  340. 0x94, 0xc1, 0x95, 0xca, 0x96, 0xd2, 0x97, 0xd8,
  341. 0x98, 0xde, 0x99, 0xe3, 0x9a, 0xe8, 0x9b, 0xed,
  342. 0x9c, 0xf1, 0x9d, 0xf5, 0x9e, 0xf8, 0x9f, 0xfc,
  343. 0xa0, 0xff}
  344. };
  345. static const __u8 tas5130a_sensor_init[][8] = {
  346. {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
  347. {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
  348. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  349. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  350. {},
  351. };
  352. static __u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
  353. /* read 1 byte */
  354. static int reg_r(struct gspca_dev *gspca_dev,
  355. __u16 index)
  356. {
  357. usb_control_msg(gspca_dev->dev,
  358. usb_rcvctrlpipe(gspca_dev->dev, 0),
  359. 0, /* request */
  360. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  361. 0, /* value */
  362. index,
  363. gspca_dev->usb_buf, 1, 500);
  364. return gspca_dev->usb_buf[0];
  365. }
  366. static void reg_w(struct gspca_dev *gspca_dev,
  367. __u16 index)
  368. {
  369. usb_control_msg(gspca_dev->dev,
  370. usb_sndctrlpipe(gspca_dev->dev, 0),
  371. 0,
  372. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  373. 0, index,
  374. NULL, 0, 500);
  375. }
  376. static void reg_w_buf(struct gspca_dev *gspca_dev,
  377. const __u8 *buffer, __u16 len)
  378. {
  379. if (len <= USB_BUF_SZ) {
  380. memcpy(gspca_dev->usb_buf, buffer, len);
  381. usb_control_msg(gspca_dev->dev,
  382. usb_sndctrlpipe(gspca_dev->dev, 0),
  383. 0,
  384. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  385. 0x01, 0,
  386. gspca_dev->usb_buf, len, 500);
  387. } else {
  388. __u8 *tmpbuf;
  389. tmpbuf = kmalloc(len, GFP_KERNEL);
  390. memcpy(tmpbuf, buffer, len);
  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. 0x01, 0,
  396. tmpbuf, len, 500);
  397. kfree(tmpbuf);
  398. }
  399. }
  400. /* Reported as OM6802*/
  401. static void om6802_sensor_init(struct gspca_dev *gspca_dev)
  402. {
  403. int i;
  404. const __u8 *p;
  405. __u8 byte;
  406. __u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
  407. static const __u8 sensor_init[] = {
  408. 0xdf, 0x6d,
  409. 0xdd, 0x18,
  410. 0x5a, 0xe0,
  411. 0x5c, 0x07,
  412. 0x5d, 0xb0,
  413. 0x5e, 0x1e,
  414. 0x60, 0x71,
  415. 0xef, 0x00,
  416. 0xe9, 0x00,
  417. 0xea, 0x00,
  418. 0x90, 0x24,
  419. 0x91, 0xb2,
  420. 0x82, 0x32,
  421. 0xfd, 0x41,
  422. 0x00 /* table end */
  423. };
  424. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  425. msleep(5);
  426. i = 4;
  427. while (--i < 0) {
  428. byte = reg_r(gspca_dev, 0x0060);
  429. if (!(byte & 0x01))
  430. break;
  431. msleep(100);
  432. }
  433. byte = reg_r(gspca_dev, 0x0063);
  434. if (byte != 0x17) {
  435. err("Bad sensor reset %02x", byte);
  436. /* continue? */
  437. }
  438. p = sensor_init;
  439. while (*p != 0) {
  440. val[1] = *p++;
  441. val[3] = *p++;
  442. if (*p == 0)
  443. reg_w(gspca_dev, 0x3c80);
  444. reg_w_buf(gspca_dev, val, sizeof val);
  445. i = 4;
  446. while (--i >= 0) {
  447. msleep(15);
  448. byte = reg_r(gspca_dev, 0x60);
  449. if (!(byte & 0x01))
  450. break;
  451. }
  452. }
  453. msleep(15);
  454. reg_w(gspca_dev, 0x3c80);
  455. }
  456. /* this function is called at probe time */
  457. static int sd_config(struct gspca_dev *gspca_dev,
  458. const struct usb_device_id *id)
  459. {
  460. struct sd *sd = (struct sd *) gspca_dev;
  461. struct cam *cam;
  462. cam = &gspca_dev->cam;
  463. cam->epaddr = 0x01;
  464. cam->cam_mode = vga_mode_t16;
  465. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  466. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  467. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  468. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  469. sd->gamma = GAMMA_DEF;
  470. sd->mirror = sd_ctrls[SD_MIRROR].qctrl.default_value;
  471. sd->freq = sd_ctrls[SD_LIGHTFREQ].qctrl.default_value;
  472. sd->whitebalance = sd_ctrls[SD_WHITE_BALANCE].qctrl.default_value;
  473. sd->sharpness = sd_ctrls[SD_SHARPNESS].qctrl.default_value;
  474. sd->effect = sd_ctrls[SD_EFFECTS].qctrl.default_value;
  475. return 0;
  476. }
  477. static void setbrightness(struct gspca_dev *gspca_dev)
  478. {
  479. struct sd *sd = (struct sd *) gspca_dev;
  480. unsigned int brightness;
  481. __u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
  482. brightness = sd->brightness;
  483. if (brightness < 7) {
  484. set6[1] = 0x26;
  485. set6[3] = 0x70 - brightness * 0x10;
  486. } else {
  487. set6[3] = 0x00 + ((brightness - 7) * 0x10);
  488. }
  489. reg_w_buf(gspca_dev, set6, sizeof set6);
  490. }
  491. static void setcontrast(struct gspca_dev *gspca_dev)
  492. {
  493. struct sd *sd = (struct sd *) gspca_dev;
  494. unsigned int contrast = sd->contrast;
  495. __u16 reg_to_write;
  496. if (contrast < 7)
  497. reg_to_write = 0x8ea9 - contrast * 0x200;
  498. else
  499. reg_to_write = 0x00a9 + (contrast - 7) * 0x200;
  500. reg_w(gspca_dev, reg_to_write);
  501. }
  502. static void setcolors(struct gspca_dev *gspca_dev)
  503. {
  504. struct sd *sd = (struct sd *) gspca_dev;
  505. __u16 reg_to_write;
  506. reg_to_write = 0x80bb + sd->colors * 0x100; /* was 0xc0 */
  507. reg_w(gspca_dev, reg_to_write);
  508. }
  509. static void setgamma(struct gspca_dev *gspca_dev)
  510. {
  511. struct sd *sd = (struct sd *) gspca_dev;
  512. PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
  513. reg_w_buf(gspca_dev, gamma_table[sd->gamma], sizeof gamma_table[0]);
  514. }
  515. static void setwhitebalance(struct gspca_dev *gspca_dev)
  516. {
  517. struct sd *sd = (struct sd *) gspca_dev;
  518. __u8 white_balance[8] =
  519. {0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38};
  520. if (sd->whitebalance)
  521. white_balance[7] = 0x3c;
  522. reg_w_buf(gspca_dev, white_balance, sizeof white_balance);
  523. }
  524. static void setsharpness(struct gspca_dev *gspca_dev)
  525. {
  526. struct sd *sd = (struct sd *) gspca_dev;
  527. __u16 reg_to_write;
  528. reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
  529. reg_w(gspca_dev, reg_to_write);
  530. }
  531. /* this function is called at probe and resume time */
  532. static int sd_init(struct gspca_dev *gspca_dev)
  533. {
  534. /* some of this registers are not really neded, because
  535. * they are overriden by setbrigthness, setcontrast, etc,
  536. * but wont hurt anyway, and can help someone with similar webcam
  537. * to see the initial parameters.*/
  538. struct sd *sd = (struct sd *) gspca_dev;
  539. int i;
  540. __u8 byte, test_byte;
  541. static const __u8 read_indexs[] =
  542. { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  543. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00, 0x00 };
  544. static const __u8 n1[] =
  545. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  546. static const __u8 n2[] =
  547. {0x08, 0x00};
  548. static const __u8 n3[] =
  549. {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
  550. static const __u8 n4[] =
  551. {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
  552. 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
  553. 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
  554. 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
  555. 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
  556. 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
  557. 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
  558. 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
  559. 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
  560. static const __u8 nset4[] = {
  561. 0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 0xe4, 0xa8,
  562. 0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8,
  563. 0xe8, 0xe0
  564. };
  565. /* ojo puede ser 0xe6 en vez de 0xe9 */
  566. static const __u8 nset2[] = {
  567. 0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 0xd4, 0xbb,
  568. 0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27,
  569. 0xd8, 0xc8, 0xd9, 0xfc
  570. };
  571. static const __u8 nset3[] = {
  572. 0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60, 0xcb, 0xa8,
  573. 0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8,
  574. 0xcf, 0xe0
  575. };
  576. static const __u8 nset5[] =
  577. { 0x8f, 0x24, 0xc3, 0x00 }; /* bright */
  578. static const __u8 nset7[4] =
  579. { 0x66, 0xca, 0xa8, 0xf8 }; /* 50/60 Hz */
  580. static const __u8 nset9[4] =
  581. { 0x0b, 0x04, 0x0a, 0x78 };
  582. static const __u8 nset8[6] =
  583. { 0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00 };
  584. static const __u8 nset10[6] =
  585. { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 };
  586. byte = reg_r(gspca_dev, 0x06);
  587. test_byte = reg_r(gspca_dev, 0x07);
  588. if (byte == 0x08 && test_byte == 0x07) {
  589. PDEBUG(D_CONF, "sensor om6802");
  590. sd->sensor = SENSOR_OM6802;
  591. } else if (byte == 0x08 && test_byte == 0x01) {
  592. PDEBUG(D_CONF, "sensor tas5130a");
  593. sd->sensor = SENSOR_TAS5130A;
  594. } else {
  595. PDEBUG(D_CONF, "unknown sensor %02x %02x", byte, test_byte);
  596. sd->sensor = SENSOR_TAS5130A;
  597. }
  598. reg_w_buf(gspca_dev, n1, sizeof n1);
  599. test_byte = 0;
  600. i = 5;
  601. while (--i >= 0) {
  602. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  603. test_byte = reg_r(gspca_dev, 0x0063);
  604. msleep(100);
  605. if (test_byte == 0x17)
  606. break; /* OK */
  607. }
  608. if (i < 0) {
  609. err("Bad sensor reset %02x", test_byte);
  610. /* return -EIO; */
  611. /*fixme: test - continue */
  612. }
  613. reg_w_buf(gspca_dev, n2, sizeof n2);
  614. i = 0;
  615. while (read_indexs[i] != 0x00) {
  616. test_byte = reg_r(gspca_dev, read_indexs[i]);
  617. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
  618. test_byte);
  619. i++;
  620. }
  621. reg_w_buf(gspca_dev, n3, sizeof n3);
  622. reg_w_buf(gspca_dev, n4, sizeof n4);
  623. reg_r(gspca_dev, 0x0080);
  624. reg_w(gspca_dev, 0x2c80);
  625. reg_w_buf(gspca_dev, nset2, sizeof nset2);
  626. reg_w_buf(gspca_dev, nset3, sizeof nset3);
  627. reg_w_buf(gspca_dev, nset4, sizeof nset4);
  628. reg_w(gspca_dev, 0x3880);
  629. reg_w(gspca_dev, 0x3880);
  630. reg_w(gspca_dev, 0x338e);
  631. nset5 - missing
  632. setbrightness(gspca_dev);
  633. setcontrast(gspca_dev);
  634. setgamma(gspca_dev);
  635. setcolors(gspca_dev);
  636. setsharpness(gspca_dev);
  637. setwhitebalance(gspca_dev);
  638. reg_w(gspca_dev, 0x2087); /* tied to white balance? */
  639. reg_w(gspca_dev, 0x2088);
  640. reg_w(gspca_dev, 0x2089);
  641. reg_w_buf(gspca_dev, nset7, sizeof nset7);
  642. reg_w_buf(gspca_dev, nset10, sizeof nset10);
  643. reg_w_buf(gspca_dev, nset8, sizeof nset8);
  644. reg_w_buf(gspca_dev, nset9, sizeof nset9);
  645. reg_w(gspca_dev, 0x2880);
  646. reg_w_buf(gspca_dev, nset2, sizeof nset2);
  647. reg_w_buf(gspca_dev, nset3, sizeof nset3);
  648. reg_w_buf(gspca_dev, nset4, sizeof nset4);
  649. return 0;
  650. }
  651. static void setflip(struct gspca_dev *gspca_dev)
  652. {
  653. struct sd *sd = (struct sd *) gspca_dev;
  654. __u8 flipcmd[8] =
  655. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
  656. if (sd->mirror)
  657. flipcmd[3] = 0x01;
  658. reg_w_buf(gspca_dev, flipcmd, sizeof flipcmd);
  659. }
  660. static void seteffect(struct gspca_dev *gspca_dev)
  661. {
  662. struct sd *sd = (struct sd *) gspca_dev;
  663. reg_w_buf(gspca_dev, effects_table[sd->effect],
  664. sizeof effects_table[0]);
  665. if (sd->effect == 1 || sd->effect == 5) {
  666. PDEBUG(D_CONF,
  667. "This effect have been disabled for webcam \"safety\"");
  668. return;
  669. }
  670. if (sd->effect == 1 || sd->effect == 4)
  671. reg_w(gspca_dev, 0x4aa6);
  672. else
  673. reg_w(gspca_dev, 0xfaa6);
  674. }
  675. static void setlightfreq(struct gspca_dev *gspca_dev)
  676. {
  677. struct sd *sd = (struct sd *) gspca_dev;
  678. __u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
  679. if (sd->freq == 2) /* 60hz */
  680. freq[1] = 0x00;
  681. reg_w_buf(gspca_dev, freq, sizeof freq);
  682. }
  683. static int sd_start(struct gspca_dev *gspca_dev)
  684. {
  685. struct sd *sd = (struct sd *) gspca_dev;
  686. int i, mode;
  687. static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
  688. __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  689. static const __u8 t3[] =
  690. { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06,
  691. 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
  692. static const __u8 t4[] = { 0x0b, 0x04, 0x0a, 0x40 };
  693. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
  694. switch (mode) {
  695. case 1: /* 352x288 */
  696. t2[1] = 0x40;
  697. break;
  698. case 2: /* 320x240 */
  699. t2[1] = 0x10;
  700. break;
  701. case 3: /* 176x144 */
  702. t2[1] = 0x50;
  703. break;
  704. case 4: /* 160x120 */
  705. t2[1] = 0x20;
  706. break;
  707. default: /* 640x480 (0x00) */
  708. break;
  709. }
  710. if (sd->sensor == SENSOR_TAS5130A) {
  711. i = 0;
  712. while (tas5130a_sensor_init[i][0] != 0) {
  713. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  714. sizeof tas5130a_sensor_init[0]);
  715. i++;
  716. }
  717. reg_w(gspca_dev, 0x3c80);
  718. /* just in case and to keep sync with logs (for mine) */
  719. reg_w_buf(gspca_dev, tas5130a_sensor_init[3],
  720. sizeof tas5130a_sensor_init[0]);
  721. reg_w(gspca_dev, 0x3c80);
  722. } else {
  723. om6802_sensor_init(gspca_dev);
  724. }
  725. /* just in case and to keep sync with logs (for mine) */
  726. reg_w_buf(gspca_dev, t1, sizeof t1);
  727. reg_w_buf(gspca_dev, t2, sizeof t2);
  728. reg_r(gspca_dev, 0x0012);
  729. reg_w_buf(gspca_dev, t3, sizeof t3);
  730. reg_w(gspca_dev, 0x0013);
  731. reg_w_buf(gspca_dev, t4, sizeof t4);
  732. /* restart on each start, just in case, sometimes regs goes wrong
  733. * when using controls from app */
  734. setbrightness(gspca_dev);
  735. setcontrast(gspca_dev);
  736. setcolors(gspca_dev);
  737. return 0;
  738. }
  739. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  740. struct gspca_frame *frame, /* target */
  741. __u8 *data, /* isoc packet */
  742. int len) /* iso packet length */
  743. {
  744. static __u8 ffd9[] = { 0xff, 0xd9 };
  745. if (data[0] == 0x5a) {
  746. /* Control Packet, after this came the header again,
  747. * but extra bytes came in the packet before this,
  748. * sometimes an EOF arrives, sometimes not... */
  749. return;
  750. }
  751. data += 2;
  752. len -= 2;
  753. if (data[0] == 0xff && data[1] == 0xd8) {
  754. /* extra bytes....., could be processed too but would be
  755. * a waste of time, right now leave the application and
  756. * libjpeg do it for ourserlves.. */
  757. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  758. ffd9, 2);
  759. gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
  760. return;
  761. }
  762. if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
  763. /* Just in case, i have seen packets with the marker,
  764. * other's do not include it... */
  765. len -= 2;
  766. }
  767. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  768. }
  769. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  770. {
  771. struct sd *sd = (struct sd *) gspca_dev;
  772. sd->brightness = val;
  773. if (gspca_dev->streaming)
  774. setbrightness(gspca_dev);
  775. return 0;
  776. }
  777. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  778. {
  779. struct sd *sd = (struct sd *) gspca_dev;
  780. *val = sd->brightness;
  781. return *val;
  782. }
  783. static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val)
  784. {
  785. struct sd *sd = (struct sd *) gspca_dev;
  786. sd->whitebalance = val;
  787. if (gspca_dev->streaming)
  788. setwhitebalance(gspca_dev);
  789. return 0;
  790. }
  791. static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val)
  792. {
  793. struct sd *sd = (struct sd *) gspca_dev;
  794. *val = sd->whitebalance;
  795. return *val;
  796. }
  797. static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val)
  798. {
  799. struct sd *sd = (struct sd *) gspca_dev;
  800. sd->mirror = val;
  801. if (gspca_dev->streaming)
  802. setflip(gspca_dev);
  803. return 0;
  804. }
  805. static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val)
  806. {
  807. struct sd *sd = (struct sd *) gspca_dev;
  808. *val = sd->mirror;
  809. return *val;
  810. }
  811. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val)
  812. {
  813. struct sd *sd = (struct sd *) gspca_dev;
  814. sd->effect = val;
  815. if (gspca_dev->streaming)
  816. seteffect(gspca_dev);
  817. return 0;
  818. }
  819. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val)
  820. {
  821. struct sd *sd = (struct sd *) gspca_dev;
  822. *val = sd->effect;
  823. return *val;
  824. }
  825. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  826. {
  827. struct sd *sd = (struct sd *) gspca_dev;
  828. sd->contrast = val;
  829. if (gspca_dev->streaming)
  830. setcontrast(gspca_dev);
  831. return 0;
  832. }
  833. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  834. {
  835. struct sd *sd = (struct sd *) gspca_dev;
  836. *val = sd->contrast;
  837. return *val;
  838. }
  839. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  840. {
  841. struct sd *sd = (struct sd *) gspca_dev;
  842. sd->colors = val;
  843. if (gspca_dev->streaming)
  844. setcolors(gspca_dev);
  845. return 0;
  846. }
  847. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  848. {
  849. struct sd *sd = (struct sd *) gspca_dev;
  850. *val = sd->colors;
  851. return 0;
  852. }
  853. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
  854. {
  855. struct sd *sd = (struct sd *) gspca_dev;
  856. sd->gamma = val;
  857. if (gspca_dev->streaming)
  858. setgamma(gspca_dev);
  859. return 0;
  860. }
  861. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
  862. {
  863. struct sd *sd = (struct sd *) gspca_dev;
  864. *val = sd->gamma;
  865. return 0;
  866. }
  867. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  868. {
  869. struct sd *sd = (struct sd *) gspca_dev;
  870. sd->freq = val;
  871. if (gspca_dev->streaming)
  872. setlightfreq(gspca_dev);
  873. return 0;
  874. }
  875. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  876. {
  877. struct sd *sd = (struct sd *) gspca_dev;
  878. *val = sd->freq;
  879. return 0;
  880. }
  881. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  882. {
  883. struct sd *sd = (struct sd *) gspca_dev;
  884. sd->sharpness = val;
  885. if (gspca_dev->streaming)
  886. setsharpness(gspca_dev);
  887. return 0;
  888. }
  889. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  890. {
  891. struct sd *sd = (struct sd *) gspca_dev;
  892. *val = sd->sharpness;
  893. return 0;
  894. }
  895. /* Low Light set here......*/
  896. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
  897. {
  898. struct sd *sd = (struct sd *) gspca_dev;
  899. sd->autogain = val;
  900. if (val != 0)
  901. reg_w(gspca_dev, 0xf48e);
  902. else
  903. reg_w(gspca_dev, 0xb48e);
  904. return 0;
  905. }
  906. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
  907. {
  908. struct sd *sd = (struct sd *) gspca_dev;
  909. *val = sd->autogain;
  910. return 0;
  911. }
  912. static int sd_querymenu(struct gspca_dev *gspca_dev,
  913. struct v4l2_querymenu *menu)
  914. {
  915. switch (menu->id) {
  916. case V4L2_CID_POWER_LINE_FREQUENCY:
  917. switch (menu->index) {
  918. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  919. strcpy((char *) menu->name, "50 Hz");
  920. return 0;
  921. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  922. strcpy((char *) menu->name, "60 Hz");
  923. return 0;
  924. }
  925. break;
  926. case V4L2_CID_EFFECTS:
  927. if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) {
  928. strncpy((char *) menu->name,
  929. effects_control[menu->index], 32);
  930. return 0;
  931. }
  932. break;
  933. }
  934. return -EINVAL;
  935. }
  936. /* sub-driver description */
  937. static const struct sd_desc sd_desc = {
  938. .name = MODULE_NAME,
  939. .ctrls = sd_ctrls,
  940. .nctrls = ARRAY_SIZE(sd_ctrls),
  941. .config = sd_config,
  942. .init = sd_init,
  943. .start = sd_start,
  944. .pkt_scan = sd_pkt_scan,
  945. .querymenu = sd_querymenu,
  946. };
  947. /* -- module initialisation -- */
  948. static const __devinitdata struct usb_device_id device_table[] = {
  949. {USB_DEVICE(0x17a1, 0x0128)},
  950. {}
  951. };
  952. MODULE_DEVICE_TABLE(usb, device_table);
  953. /* -- device connect -- */
  954. static int sd_probe(struct usb_interface *intf,
  955. const struct usb_device_id *id)
  956. {
  957. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  958. THIS_MODULE);
  959. }
  960. static struct usb_driver sd_driver = {
  961. .name = MODULE_NAME,
  962. .id_table = device_table,
  963. .probe = sd_probe,
  964. .disconnect = gspca_disconnect,
  965. #ifdef CONFIG_PM
  966. .suspend = gspca_suspend,
  967. .resume = gspca_resume,
  968. #endif
  969. };
  970. /* -- module insert / remove -- */
  971. static int __init sd_mod_init(void)
  972. {
  973. if (usb_register(&sd_driver) < 0)
  974. return -1;
  975. PDEBUG(D_PROBE, "registered");
  976. return 0;
  977. }
  978. static void __exit sd_mod_exit(void)
  979. {
  980. usb_deregister(&sd_driver);
  981. PDEBUG(D_PROBE, "deregistered");
  982. }
  983. module_init(sd_mod_init);
  984. module_exit(sd_mod_exit);