t613.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  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_OTHER 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 = 1,
  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. /* read 1 byte */
  353. static int reg_r(struct gspca_dev *gspca_dev,
  354. __u16 index)
  355. {
  356. usb_control_msg(gspca_dev->dev,
  357. usb_rcvctrlpipe(gspca_dev->dev, 0),
  358. 0, /* request */
  359. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  360. 0, /* value */
  361. index,
  362. gspca_dev->usb_buf, 1, 500);
  363. return gspca_dev->usb_buf[0];
  364. }
  365. static void reg_w(struct gspca_dev *gspca_dev,
  366. __u16 index)
  367. {
  368. usb_control_msg(gspca_dev->dev,
  369. usb_sndctrlpipe(gspca_dev->dev, 0),
  370. 0,
  371. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  372. 0, index,
  373. NULL, 0, 500);
  374. }
  375. static void reg_w_buf(struct gspca_dev *gspca_dev,
  376. const __u8 *buffer, __u16 len)
  377. {
  378. if (len <= USB_BUF_SZ) {
  379. memcpy(gspca_dev->usb_buf, buffer, len);
  380. usb_control_msg(gspca_dev->dev,
  381. usb_sndctrlpipe(gspca_dev->dev, 0),
  382. 0,
  383. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  384. 0x01, 0,
  385. gspca_dev->usb_buf, len, 500);
  386. } else {
  387. __u8 *tmpbuf;
  388. tmpbuf = kmalloc(len, GFP_KERNEL);
  389. memcpy(tmpbuf, buffer, len);
  390. usb_control_msg(gspca_dev->dev,
  391. usb_sndctrlpipe(gspca_dev->dev, 0),
  392. 0,
  393. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  394. 0x01, 0,
  395. tmpbuf, len, 500);
  396. kfree(tmpbuf);
  397. }
  398. }
  399. static void other_sensor_init(struct gspca_dev *gspca_dev)
  400. {
  401. int i;
  402. const __u8 *p;
  403. __u8 byte;
  404. __u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
  405. static const __u8 sensor_init[] = {
  406. 0xdf, 0x6d,
  407. 0xdd, 0x18,
  408. 0x5a, 0xe0,
  409. 0x5c, 0x07,
  410. 0x5d, 0xb0,
  411. 0x5e, 0x1e,
  412. 0x60, 0x71,
  413. 0xef, 0x00,
  414. 0xe9, 0x00,
  415. 0xea, 0x00,
  416. 0x90, 0x24,
  417. 0x91, 0xb2,
  418. 0x82, 0x32,
  419. 0xfd, 0x00,
  420. 0xfd, 0x01,
  421. 0xfd, 0x41,
  422. 0x00 /* table end */
  423. };
  424. p = sensor_init;
  425. while (*p != 0) {
  426. val[1] = *p++;
  427. val[3] = *p++;
  428. if (*p == 0)
  429. reg_w(gspca_dev, 0x3c80);
  430. reg_w_buf(gspca_dev, val, sizeof val);
  431. i = 4;
  432. while (--i >= 0) {
  433. msleep(15);
  434. byte = reg_r(gspca_dev, 0x60);
  435. if (!(byte & 0x01))
  436. break;
  437. }
  438. }
  439. reg_w(gspca_dev, 0x3c80);
  440. }
  441. /* this function is called at probe time */
  442. static int sd_config(struct gspca_dev *gspca_dev,
  443. const struct usb_device_id *id)
  444. {
  445. struct sd *sd = (struct sd *) gspca_dev;
  446. struct cam *cam;
  447. cam = &gspca_dev->cam;
  448. cam->epaddr = 0x01;
  449. cam->cam_mode = vga_mode_t16;
  450. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  451. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  452. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  453. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  454. sd->gamma = GAMMA_DEF;
  455. sd->mirror = sd_ctrls[SD_MIRROR].qctrl.default_value;
  456. sd->freq = sd_ctrls[SD_LIGHTFREQ].qctrl.default_value;
  457. sd->whitebalance = sd_ctrls[SD_WHITE_BALANCE].qctrl.default_value;
  458. sd->sharpness = sd_ctrls[SD_SHARPNESS].qctrl.default_value;
  459. sd->effect = sd_ctrls[SD_EFFECTS].qctrl.default_value;
  460. return 0;
  461. }
  462. static void setgamma(struct gspca_dev *gspca_dev)
  463. {
  464. struct sd *sd = (struct sd *) gspca_dev;
  465. PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
  466. reg_w_buf(gspca_dev, gamma_table[sd->gamma], sizeof gamma_table[0]);
  467. }
  468. /* this function is called at probe and resume time */
  469. static int sd_init(struct gspca_dev *gspca_dev)
  470. {
  471. /* some of this registers are not really neded, because
  472. * they are overriden by setbrigthness, setcontrast, etc,
  473. * but wont hurt anyway, and can help someone with similar webcam
  474. * to see the initial parameters.*/
  475. struct sd *sd = (struct sd *) gspca_dev;
  476. int i;
  477. __u8 byte, test_byte;
  478. static const __u8 read_indexs[] =
  479. { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  480. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00, 0x00 };
  481. static const __u8 n1[] =
  482. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  483. static const __u8 n2[] =
  484. {0x08, 0x00};
  485. static const __u8 nset[] =
  486. { 0x61, 0x68, 0x62, 0xff, 0x60, 0x07 };
  487. static const __u8 n3[] =
  488. {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
  489. static const __u8 n4[] =
  490. {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
  491. 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
  492. 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
  493. 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
  494. 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
  495. 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
  496. 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
  497. 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
  498. 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
  499. static const __u8 nset4[] = {
  500. 0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 0xe4, 0xa8,
  501. 0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8,
  502. 0xe8, 0xe0
  503. };
  504. /* ojo puede ser 0xe6 en vez de 0xe9 */
  505. static const __u8 nset2[] = {
  506. 0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 0xd4, 0xbb,
  507. 0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27,
  508. 0xd8, 0xc8, 0xd9, 0xfc
  509. };
  510. static const __u8 missing[] =
  511. { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 };
  512. static const __u8 nset3[] = {
  513. 0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60, 0xcb, 0xa8,
  514. 0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8,
  515. 0xcf, 0xe0
  516. };
  517. static const __u8 nset5[] =
  518. { 0x8f, 0x24, 0xc3, 0x00 }; /* bright */
  519. static const __u8 nset7[4] =
  520. { 0x66, 0xca, 0xa8, 0xf8 }; /* 50/60 Hz */
  521. static const __u8 nset9[4] =
  522. { 0x0b, 0x04, 0x0a, 0x78 };
  523. static const __u8 nset8[6] =
  524. { 0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00 };
  525. static const __u8 nset10[6] =
  526. { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 };
  527. byte = reg_r(gspca_dev, 0x06);
  528. test_byte = reg_r(gspca_dev, 0x07);
  529. if (byte == 0x08 && test_byte == 0x07) {
  530. PDEBUG(D_CONF, "other sensor");
  531. sd->sensor = SENSOR_OTHER;
  532. } else {
  533. PDEBUG(D_CONF, "sensor %02x %02x", byte, test_byte);
  534. sd->sensor = SENSOR_TAS5130A;
  535. }
  536. reg_w_buf(gspca_dev, n1, sizeof n1);
  537. test_byte = 0;
  538. i = 5;
  539. while (--i >= 0) {
  540. reg_w_buf(gspca_dev, nset, sizeof nset);
  541. msleep(5);
  542. test_byte = reg_r(gspca_dev, 0x0063);
  543. msleep(100);
  544. if (test_byte == 0x17)
  545. break; /* OK */
  546. }
  547. if (i < 0) {
  548. err("Bad sensor reset %02x", test_byte);
  549. /* return -EIO; */
  550. /*fixme: test - continue */
  551. }
  552. reg_w_buf(gspca_dev, n2, sizeof n2);
  553. i = 0;
  554. while (read_indexs[i] != 0x00) {
  555. test_byte = reg_r(gspca_dev, read_indexs[i]);
  556. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
  557. test_byte);
  558. i++;
  559. }
  560. reg_w_buf(gspca_dev, n3, sizeof n3);
  561. reg_w_buf(gspca_dev, n4, sizeof n4);
  562. reg_r(gspca_dev, 0x0080);
  563. reg_w(gspca_dev, 0x2c80);
  564. reg_w_buf(gspca_dev, nset2, sizeof nset2);
  565. reg_w_buf(gspca_dev, nset3, sizeof nset3);
  566. reg_w_buf(gspca_dev, nset4, sizeof nset4);
  567. reg_w(gspca_dev, 0x3880);
  568. reg_w(gspca_dev, 0x3880);
  569. reg_w(gspca_dev, 0x338e);
  570. reg_w_buf(gspca_dev, nset5, sizeof nset5);
  571. reg_w(gspca_dev, 0x00a9);
  572. setgamma(gspca_dev);
  573. reg_w(gspca_dev, 0x86bb);
  574. reg_w(gspca_dev, 0x4aa6);
  575. reg_w_buf(gspca_dev, missing, sizeof missing);
  576. reg_w(gspca_dev, 0x2087);
  577. reg_w(gspca_dev, 0x2088);
  578. reg_w(gspca_dev, 0x2089);
  579. reg_w_buf(gspca_dev, nset7, sizeof nset7);
  580. reg_w_buf(gspca_dev, nset10, sizeof nset10);
  581. reg_w_buf(gspca_dev, nset8, sizeof nset8);
  582. reg_w_buf(gspca_dev, nset9, sizeof nset9);
  583. reg_w(gspca_dev, 0x2880);
  584. reg_w_buf(gspca_dev, nset2, sizeof nset2);
  585. reg_w_buf(gspca_dev, nset3, sizeof nset3);
  586. reg_w_buf(gspca_dev, nset4, sizeof nset4);
  587. return 0;
  588. }
  589. static void setbrightness(struct gspca_dev *gspca_dev)
  590. {
  591. struct sd *sd = (struct sd *) gspca_dev;
  592. unsigned int brightness;
  593. __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x00 };
  594. brightness = sd->brightness;
  595. if (brightness < 7) {
  596. set6[3] = 0x70 - brightness * 0x10;
  597. } else {
  598. set6[1] = 0x24;
  599. set6[3] = 0x00 + ((brightness - 7) * 0x10);
  600. }
  601. reg_w_buf(gspca_dev, set6, sizeof set6);
  602. }
  603. static void setflip(struct gspca_dev *gspca_dev)
  604. {
  605. struct sd *sd = (struct sd *) gspca_dev;
  606. __u8 flipcmd[8] =
  607. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
  608. if (sd->mirror)
  609. flipcmd[3] = 0x01;
  610. reg_w_buf(gspca_dev, flipcmd, sizeof flipcmd);
  611. }
  612. static void seteffect(struct gspca_dev *gspca_dev)
  613. {
  614. struct sd *sd = (struct sd *) gspca_dev;
  615. reg_w_buf(gspca_dev, effects_table[sd->effect],
  616. sizeof effects_table[0]);
  617. if (sd->effect == 1 || sd->effect == 5) {
  618. PDEBUG(D_CONF,
  619. "This effect have been disabled for webcam \"safety\"");
  620. return;
  621. }
  622. if (sd->effect == 1 || sd->effect == 4)
  623. reg_w(gspca_dev, 0x4aa6);
  624. else
  625. reg_w(gspca_dev, 0xfaa6);
  626. }
  627. static void setwhitebalance(struct gspca_dev *gspca_dev)
  628. {
  629. struct sd *sd = (struct sd *) gspca_dev;
  630. __u8 white_balance[8] =
  631. { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 };
  632. if (sd->whitebalance == 1)
  633. white_balance[7] = 0x3c;
  634. reg_w_buf(gspca_dev, white_balance, sizeof white_balance);
  635. }
  636. static void setlightfreq(struct gspca_dev *gspca_dev)
  637. {
  638. struct sd *sd = (struct sd *) gspca_dev;
  639. __u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
  640. if (sd->freq == 2) /* 60hz */
  641. freq[1] = 0x00;
  642. reg_w_buf(gspca_dev, freq, sizeof freq);
  643. }
  644. static void setcontrast(struct gspca_dev *gspca_dev)
  645. {
  646. struct sd *sd = (struct sd *) gspca_dev;
  647. unsigned int contrast = sd->contrast;
  648. __u16 reg_to_write;
  649. if (contrast < 7)
  650. reg_to_write = 0x8ea9 - (0x200 * contrast);
  651. else
  652. reg_to_write = (0x00a9 + ((contrast - 7) * 0x200));
  653. reg_w(gspca_dev, reg_to_write);
  654. }
  655. static void setcolors(struct gspca_dev *gspca_dev)
  656. {
  657. struct sd *sd = (struct sd *) gspca_dev;
  658. __u16 reg_to_write;
  659. reg_to_write = 0xc0bb + sd->colors * 0x100;
  660. reg_w(gspca_dev, reg_to_write);
  661. }
  662. static void setsharpness(struct gspca_dev *gspca_dev)
  663. {
  664. struct sd *sd = (struct sd *) gspca_dev;
  665. __u16 reg_to_write;
  666. reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
  667. reg_w(gspca_dev, reg_to_write);
  668. }
  669. static int sd_start(struct gspca_dev *gspca_dev)
  670. {
  671. struct sd *sd = (struct sd *) gspca_dev;
  672. int i, mode;
  673. static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
  674. __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  675. static const __u8 t3[] =
  676. { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06,
  677. 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
  678. static const __u8 t4[] = { 0x0b, 0x04, 0x0a, 0x40 };
  679. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
  680. switch (mode) {
  681. case 1: /* 352x288 */
  682. t2[1] = 0x40;
  683. break;
  684. case 2: /* 320x240 */
  685. t2[1] = 0x10;
  686. break;
  687. case 3: /* 176x144 */
  688. t2[1] = 0x50;
  689. break;
  690. case 4: /* 160x120 */
  691. t2[1] = 0x20;
  692. break;
  693. default: /* 640x480 (0x00) */
  694. break;
  695. }
  696. if (sd->sensor == SENSOR_TAS5130A) {
  697. i = 0;
  698. while (tas5130a_sensor_init[i][0] != 0) {
  699. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  700. sizeof tas5130a_sensor_init[0]);
  701. i++;
  702. }
  703. reg_w(gspca_dev, 0x3c80);
  704. /* just in case and to keep sync with logs (for mine) */
  705. reg_w_buf(gspca_dev, tas5130a_sensor_init[3],
  706. sizeof tas5130a_sensor_init[0]);
  707. reg_w(gspca_dev, 0x3c80);
  708. } else {
  709. other_sensor_init(gspca_dev);
  710. }
  711. /* just in case and to keep sync with logs (for mine) */
  712. reg_w_buf(gspca_dev, t1, sizeof t1);
  713. reg_w_buf(gspca_dev, t2, sizeof t2);
  714. reg_r(gspca_dev, 0x0012);
  715. reg_w_buf(gspca_dev, t3, sizeof t3);
  716. reg_w(gspca_dev, 0x0013);
  717. reg_w_buf(gspca_dev, t4, sizeof t4);
  718. /* restart on each start, just in case, sometimes regs goes wrong
  719. * when using controls from app */
  720. setbrightness(gspca_dev);
  721. setcontrast(gspca_dev);
  722. setcolors(gspca_dev);
  723. return 0;
  724. }
  725. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  726. struct gspca_frame *frame, /* target */
  727. __u8 *data, /* isoc packet */
  728. int len) /* iso packet length */
  729. {
  730. static __u8 ffd9[] = { 0xff, 0xd9 };
  731. if (data[0] == 0x5a) {
  732. /* Control Packet, after this came the header again,
  733. * but extra bytes came in the packet before this,
  734. * sometimes an EOF arrives, sometimes not... */
  735. return;
  736. }
  737. data += 2;
  738. len -= 2;
  739. if (data[0] == 0xff && data[1] == 0xd8) {
  740. /* extra bytes....., could be processed too but would be
  741. * a waste of time, right now leave the application and
  742. * libjpeg do it for ourserlves.. */
  743. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  744. ffd9, 2);
  745. gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
  746. return;
  747. }
  748. if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
  749. /* Just in case, i have seen packets with the marker,
  750. * other's do not include it... */
  751. len -= 2;
  752. }
  753. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  754. }
  755. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  756. {
  757. struct sd *sd = (struct sd *) gspca_dev;
  758. sd->brightness = val;
  759. if (gspca_dev->streaming)
  760. setbrightness(gspca_dev);
  761. return 0;
  762. }
  763. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  764. {
  765. struct sd *sd = (struct sd *) gspca_dev;
  766. *val = sd->brightness;
  767. return *val;
  768. }
  769. static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val)
  770. {
  771. struct sd *sd = (struct sd *) gspca_dev;
  772. sd->whitebalance = val;
  773. if (gspca_dev->streaming)
  774. setwhitebalance(gspca_dev);
  775. return 0;
  776. }
  777. static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val)
  778. {
  779. struct sd *sd = (struct sd *) gspca_dev;
  780. *val = sd->whitebalance;
  781. return *val;
  782. }
  783. static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val)
  784. {
  785. struct sd *sd = (struct sd *) gspca_dev;
  786. sd->mirror = val;
  787. if (gspca_dev->streaming)
  788. setflip(gspca_dev);
  789. return 0;
  790. }
  791. static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val)
  792. {
  793. struct sd *sd = (struct sd *) gspca_dev;
  794. *val = sd->mirror;
  795. return *val;
  796. }
  797. static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val)
  798. {
  799. struct sd *sd = (struct sd *) gspca_dev;
  800. sd->effect = val;
  801. if (gspca_dev->streaming)
  802. seteffect(gspca_dev);
  803. return 0;
  804. }
  805. static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val)
  806. {
  807. struct sd *sd = (struct sd *) gspca_dev;
  808. *val = sd->effect;
  809. return *val;
  810. }
  811. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  812. {
  813. struct sd *sd = (struct sd *) gspca_dev;
  814. sd->contrast = val;
  815. if (gspca_dev->streaming)
  816. setcontrast(gspca_dev);
  817. return 0;
  818. }
  819. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  820. {
  821. struct sd *sd = (struct sd *) gspca_dev;
  822. *val = sd->contrast;
  823. return *val;
  824. }
  825. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  826. {
  827. struct sd *sd = (struct sd *) gspca_dev;
  828. sd->colors = val;
  829. if (gspca_dev->streaming)
  830. setcolors(gspca_dev);
  831. return 0;
  832. }
  833. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  834. {
  835. struct sd *sd = (struct sd *) gspca_dev;
  836. *val = sd->colors;
  837. return 0;
  838. }
  839. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
  840. {
  841. struct sd *sd = (struct sd *) gspca_dev;
  842. sd->gamma = val;
  843. if (gspca_dev->streaming)
  844. setgamma(gspca_dev);
  845. return 0;
  846. }
  847. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
  848. {
  849. struct sd *sd = (struct sd *) gspca_dev;
  850. *val = sd->gamma;
  851. return 0;
  852. }
  853. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  854. {
  855. struct sd *sd = (struct sd *) gspca_dev;
  856. sd->freq = val;
  857. if (gspca_dev->streaming)
  858. setlightfreq(gspca_dev);
  859. return 0;
  860. }
  861. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  862. {
  863. struct sd *sd = (struct sd *) gspca_dev;
  864. *val = sd->freq;
  865. return 0;
  866. }
  867. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  868. {
  869. struct sd *sd = (struct sd *) gspca_dev;
  870. sd->sharpness = val;
  871. if (gspca_dev->streaming)
  872. setsharpness(gspca_dev);
  873. return 0;
  874. }
  875. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  876. {
  877. struct sd *sd = (struct sd *) gspca_dev;
  878. *val = sd->sharpness;
  879. return 0;
  880. }
  881. /* Low Light set here......*/
  882. static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
  883. {
  884. struct sd *sd = (struct sd *) gspca_dev;
  885. sd->autogain = val;
  886. if (val != 0)
  887. reg_w(gspca_dev, 0xf48e);
  888. else
  889. reg_w(gspca_dev, 0xb48e);
  890. return 0;
  891. }
  892. static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
  893. {
  894. struct sd *sd = (struct sd *) gspca_dev;
  895. *val = sd->autogain;
  896. return 0;
  897. }
  898. static int sd_querymenu(struct gspca_dev *gspca_dev,
  899. struct v4l2_querymenu *menu)
  900. {
  901. switch (menu->id) {
  902. case V4L2_CID_POWER_LINE_FREQUENCY:
  903. switch (menu->index) {
  904. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  905. strcpy((char *) menu->name, "50 Hz");
  906. return 0;
  907. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  908. strcpy((char *) menu->name, "60 Hz");
  909. return 0;
  910. }
  911. break;
  912. case V4L2_CID_EFFECTS:
  913. if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) {
  914. strncpy((char *) menu->name,
  915. effects_control[menu->index], 32);
  916. return 0;
  917. }
  918. break;
  919. }
  920. return -EINVAL;
  921. }
  922. /* sub-driver description */
  923. static const struct sd_desc sd_desc = {
  924. .name = MODULE_NAME,
  925. .ctrls = sd_ctrls,
  926. .nctrls = ARRAY_SIZE(sd_ctrls),
  927. .config = sd_config,
  928. .init = sd_init,
  929. .start = sd_start,
  930. .pkt_scan = sd_pkt_scan,
  931. .querymenu = sd_querymenu,
  932. };
  933. /* -- module initialisation -- */
  934. static const __devinitdata struct usb_device_id device_table[] = {
  935. {USB_DEVICE(0x17a1, 0x0128)},
  936. {}
  937. };
  938. MODULE_DEVICE_TABLE(usb, device_table);
  939. /* -- device connect -- */
  940. static int sd_probe(struct usb_interface *intf,
  941. const struct usb_device_id *id)
  942. {
  943. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  944. THIS_MODULE);
  945. }
  946. static struct usb_driver sd_driver = {
  947. .name = MODULE_NAME,
  948. .id_table = device_table,
  949. .probe = sd_probe,
  950. .disconnect = gspca_disconnect,
  951. #ifdef CONFIG_PM
  952. .suspend = gspca_suspend,
  953. .resume = gspca_resume,
  954. #endif
  955. };
  956. /* -- module insert / remove -- */
  957. static int __init sd_mod_init(void)
  958. {
  959. if (usb_register(&sd_driver) < 0)
  960. return -1;
  961. PDEBUG(D_PROBE, "registered");
  962. return 0;
  963. }
  964. static void __exit sd_mod_exit(void)
  965. {
  966. usb_deregister(&sd_driver);
  967. PDEBUG(D_PROBE, "deregistered");
  968. }
  969. module_init(sd_mod_init);
  970. module_exit(sd_mod_exit);