ov534.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. /*
  2. * ov534-ov772x gspca driver
  3. *
  4. * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
  5. * Copyright (C) 2008 Jim Paris <jim@jtan.com>
  6. * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
  7. *
  8. * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
  9. * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
  10. * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
  11. *
  12. * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
  13. * PS3 Eye camera - brightness, contrast, awb, agc, aec controls
  14. * added by Max Thrun <bear24rw@gmail.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. #define MODULE_NAME "ov534"
  31. #include "gspca.h"
  32. #define OV534_REG_ADDRESS 0xf1 /* sensor address */
  33. #define OV534_REG_SUBADDR 0xf2
  34. #define OV534_REG_WRITE 0xf3
  35. #define OV534_REG_READ 0xf4
  36. #define OV534_REG_OPERATION 0xf5
  37. #define OV534_REG_STATUS 0xf6
  38. #define OV534_OP_WRITE_3 0x37
  39. #define OV534_OP_WRITE_2 0x33
  40. #define OV534_OP_READ_2 0xf9
  41. #define CTRL_TIMEOUT 500
  42. MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
  43. MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
  44. MODULE_LICENSE("GPL");
  45. /* specific webcam descriptor */
  46. struct sd {
  47. struct gspca_dev gspca_dev; /* !! must be the first item */
  48. __u32 last_pts;
  49. u16 last_fid;
  50. u8 frame_rate;
  51. u8 brightness;
  52. u8 contrast;
  53. u8 gain;
  54. u8 exposure;
  55. u8 agc;
  56. u8 awb;
  57. u8 aec;
  58. s8 sharpness;
  59. u8 hflip;
  60. u8 vflip;
  61. u8 freqfltr;
  62. };
  63. /* V4L2 controls supported by the driver */
  64. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  65. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  66. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  67. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  68. static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val);
  69. static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val);
  70. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  76. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
  77. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
  78. static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val);
  86. static int sd_querymenu(struct gspca_dev *gspca_dev,
  87. struct v4l2_querymenu *menu);
  88. static const struct ctrl sd_ctrls[] = {
  89. { /* 0 */
  90. {
  91. .id = V4L2_CID_BRIGHTNESS,
  92. .type = V4L2_CTRL_TYPE_INTEGER,
  93. .name = "Brightness",
  94. .minimum = 0,
  95. .maximum = 255,
  96. .step = 1,
  97. #define BRIGHTNESS_DEF 0
  98. .default_value = BRIGHTNESS_DEF,
  99. },
  100. .set = sd_setbrightness,
  101. .get = sd_getbrightness,
  102. },
  103. { /* 1 */
  104. {
  105. .id = V4L2_CID_CONTRAST,
  106. .type = V4L2_CTRL_TYPE_INTEGER,
  107. .name = "Contrast",
  108. .minimum = 0,
  109. .maximum = 255,
  110. .step = 1,
  111. #define CONTRAST_DEF 32
  112. .default_value = CONTRAST_DEF,
  113. },
  114. .set = sd_setcontrast,
  115. .get = sd_getcontrast,
  116. },
  117. { /* 2 */
  118. {
  119. .id = V4L2_CID_GAIN,
  120. .type = V4L2_CTRL_TYPE_INTEGER,
  121. .name = "Main Gain",
  122. .minimum = 0,
  123. .maximum = 63,
  124. .step = 1,
  125. #define GAIN_DEF 20
  126. .default_value = GAIN_DEF,
  127. },
  128. .set = sd_setgain,
  129. .get = sd_getgain,
  130. },
  131. { /* 3 */
  132. {
  133. .id = V4L2_CID_EXPOSURE,
  134. .type = V4L2_CTRL_TYPE_INTEGER,
  135. .name = "Exposure",
  136. .minimum = 0,
  137. .maximum = 255,
  138. .step = 1,
  139. #define EXPO_DEF 120
  140. .default_value = EXPO_DEF,
  141. },
  142. .set = sd_setexposure,
  143. .get = sd_getexposure,
  144. },
  145. { /* 4 */
  146. {
  147. .id = V4L2_CID_AUTOGAIN,
  148. .type = V4L2_CTRL_TYPE_BOOLEAN,
  149. .name = "Auto Gain",
  150. .minimum = 0,
  151. .maximum = 1,
  152. .step = 1,
  153. #define AGC_DEF 1
  154. .default_value = AGC_DEF,
  155. },
  156. .set = sd_setagc,
  157. .get = sd_getagc,
  158. },
  159. #define AWB_IDX 5
  160. { /* 5 */
  161. {
  162. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  163. .type = V4L2_CTRL_TYPE_BOOLEAN,
  164. .name = "Auto White Balance",
  165. .minimum = 0,
  166. .maximum = 1,
  167. .step = 1,
  168. #define AWB_DEF 1
  169. .default_value = AWB_DEF,
  170. },
  171. .set = sd_setawb,
  172. .get = sd_getawb,
  173. },
  174. { /* 6 */
  175. {
  176. .id = V4L2_CID_EXPOSURE_AUTO,
  177. .type = V4L2_CTRL_TYPE_BOOLEAN,
  178. .name = "Auto Exposure",
  179. .minimum = 0,
  180. .maximum = 1,
  181. .step = 1,
  182. #define AEC_DEF 1
  183. .default_value = AEC_DEF,
  184. },
  185. .set = sd_setaec,
  186. .get = sd_getaec,
  187. },
  188. { /* 7 */
  189. {
  190. .id = V4L2_CID_SHARPNESS,
  191. .type = V4L2_CTRL_TYPE_INTEGER,
  192. .name = "Sharpness",
  193. .minimum = 0,
  194. .maximum = 63,
  195. .step = 1,
  196. #define SHARPNESS_DEF 0
  197. .default_value = SHARPNESS_DEF,
  198. },
  199. .set = sd_setsharpness,
  200. .get = sd_getsharpness,
  201. },
  202. { /* 8 */
  203. {
  204. .id = V4L2_CID_HFLIP,
  205. .type = V4L2_CTRL_TYPE_BOOLEAN,
  206. .name = "HFlip",
  207. .minimum = 0,
  208. .maximum = 1,
  209. .step = 1,
  210. #define HFLIP_DEF 0
  211. .default_value = HFLIP_DEF,
  212. },
  213. .set = sd_sethflip,
  214. .get = sd_gethflip,
  215. },
  216. { /* 9 */
  217. {
  218. .id = V4L2_CID_VFLIP,
  219. .type = V4L2_CTRL_TYPE_BOOLEAN,
  220. .name = "VFlip",
  221. .minimum = 0,
  222. .maximum = 1,
  223. .step = 1,
  224. #define VFLIP_DEF 0
  225. .default_value = VFLIP_DEF,
  226. },
  227. .set = sd_setvflip,
  228. .get = sd_getvflip,
  229. },
  230. { /* 10 */
  231. {
  232. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  233. .type = V4L2_CTRL_TYPE_MENU,
  234. .name = "Light Frequency Filter",
  235. .minimum = 0,
  236. .maximum = 1,
  237. .step = 1,
  238. #define FREQFLTR_DEF 0
  239. .default_value = FREQFLTR_DEF,
  240. },
  241. .set = sd_setfreqfltr,
  242. .get = sd_getfreqfltr,
  243. },
  244. };
  245. static const struct v4l2_pix_format ov772x_mode[] = {
  246. {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  247. .bytesperline = 320 * 2,
  248. .sizeimage = 320 * 240 * 2,
  249. .colorspace = V4L2_COLORSPACE_SRGB,
  250. .priv = 1},
  251. {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  252. .bytesperline = 640 * 2,
  253. .sizeimage = 640 * 480 * 2,
  254. .colorspace = V4L2_COLORSPACE_SRGB,
  255. .priv = 0},
  256. };
  257. static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
  258. static const u8 vga_rates[] = {60, 50, 40, 30, 15};
  259. static const struct framerates ov772x_framerates[] = {
  260. { /* 320x240 */
  261. .rates = qvga_rates,
  262. .nrates = ARRAY_SIZE(qvga_rates),
  263. },
  264. { /* 640x480 */
  265. .rates = vga_rates,
  266. .nrates = ARRAY_SIZE(vga_rates),
  267. },
  268. };
  269. static const u8 bridge_init[][2] = {
  270. { 0xc2, 0x0c },
  271. { 0x88, 0xf8 },
  272. { 0xc3, 0x69 },
  273. { 0x89, 0xff },
  274. { 0x76, 0x03 },
  275. { 0x92, 0x01 },
  276. { 0x93, 0x18 },
  277. { 0x94, 0x10 },
  278. { 0x95, 0x10 },
  279. { 0xe2, 0x00 },
  280. { 0xe7, 0x3e },
  281. { 0x96, 0x00 },
  282. { 0x97, 0x20 },
  283. { 0x97, 0x20 },
  284. { 0x97, 0x20 },
  285. { 0x97, 0x0a },
  286. { 0x97, 0x3f },
  287. { 0x97, 0x4a },
  288. { 0x97, 0x20 },
  289. { 0x97, 0x15 },
  290. { 0x97, 0x0b },
  291. { 0x8e, 0x40 },
  292. { 0x1f, 0x81 },
  293. { 0x34, 0x05 },
  294. { 0xe3, 0x04 },
  295. { 0x88, 0x00 },
  296. { 0x89, 0x00 },
  297. { 0x76, 0x00 },
  298. { 0xe7, 0x2e },
  299. { 0x31, 0xf9 },
  300. { 0x25, 0x42 },
  301. { 0x21, 0xf0 },
  302. { 0x1c, 0x00 },
  303. { 0x1d, 0x40 },
  304. { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
  305. { 0x1d, 0x00 }, /* payload size */
  306. { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
  307. { 0x1d, 0x58 }, /* frame size */
  308. { 0x1d, 0x00 }, /* frame size */
  309. { 0x1c, 0x0a },
  310. { 0x1d, 0x08 }, /* turn on UVC header */
  311. { 0x1d, 0x0e }, /* .. */
  312. { 0x8d, 0x1c },
  313. { 0x8e, 0x80 },
  314. { 0xe5, 0x04 },
  315. { 0xc0, 0x50 },
  316. { 0xc1, 0x3c },
  317. { 0xc2, 0x0c },
  318. };
  319. static const u8 sensor_init[][2] = {
  320. { 0x12, 0x80 },
  321. { 0x11, 0x01 },
  322. /*fixme: better have a delay?*/
  323. { 0x11, 0x01 },
  324. { 0x11, 0x01 },
  325. { 0x11, 0x01 },
  326. { 0x11, 0x01 },
  327. { 0x11, 0x01 },
  328. { 0x11, 0x01 },
  329. { 0x11, 0x01 },
  330. { 0x11, 0x01 },
  331. { 0x11, 0x01 },
  332. { 0x11, 0x01 },
  333. { 0x3d, 0x03 },
  334. { 0x17, 0x26 },
  335. { 0x18, 0xa0 },
  336. { 0x19, 0x07 },
  337. { 0x1a, 0xf0 },
  338. { 0x32, 0x00 },
  339. { 0x29, 0xa0 },
  340. { 0x2c, 0xf0 },
  341. { 0x65, 0x20 },
  342. { 0x11, 0x01 },
  343. { 0x42, 0x7f },
  344. { 0x63, 0xaa }, /* AWB - was e0 */
  345. { 0x64, 0xff },
  346. { 0x66, 0x00 },
  347. { 0x13, 0xf0 }, /* com8 */
  348. { 0x0d, 0x41 },
  349. { 0x0f, 0xc5 },
  350. { 0x14, 0x11 },
  351. { 0x22, 0x7f },
  352. { 0x23, 0x03 },
  353. { 0x24, 0x40 },
  354. { 0x25, 0x30 },
  355. { 0x26, 0xa1 },
  356. { 0x2a, 0x00 },
  357. { 0x2b, 0x00 },
  358. { 0x6b, 0xaa },
  359. { 0x13, 0xff }, /* AWB */
  360. { 0x90, 0x05 },
  361. { 0x91, 0x01 },
  362. { 0x92, 0x03 },
  363. { 0x93, 0x00 },
  364. { 0x94, 0x60 },
  365. { 0x95, 0x3c },
  366. { 0x96, 0x24 },
  367. { 0x97, 0x1e },
  368. { 0x98, 0x62 },
  369. { 0x99, 0x80 },
  370. { 0x9a, 0x1e },
  371. { 0x9b, 0x08 },
  372. { 0x9c, 0x20 },
  373. { 0x9e, 0x81 },
  374. { 0xa6, 0x04 },
  375. { 0x7e, 0x0c },
  376. { 0x7f, 0x16 },
  377. { 0x80, 0x2a },
  378. { 0x81, 0x4e },
  379. { 0x82, 0x61 },
  380. { 0x83, 0x6f },
  381. { 0x84, 0x7b },
  382. { 0x85, 0x86 },
  383. { 0x86, 0x8e },
  384. { 0x87, 0x97 },
  385. { 0x88, 0xa4 },
  386. { 0x89, 0xaf },
  387. { 0x8a, 0xc5 },
  388. { 0x8b, 0xd7 },
  389. { 0x8c, 0xe8 },
  390. { 0x8d, 0x20 },
  391. { 0x0c, 0x90 },
  392. { 0x2b, 0x00 },
  393. { 0x22, 0x7f },
  394. { 0x23, 0x03 },
  395. { 0x11, 0x01 },
  396. { 0x0c, 0xd0 },
  397. { 0x64, 0xff },
  398. { 0x0d, 0x41 },
  399. { 0x14, 0x41 },
  400. { 0x0e, 0xcd },
  401. { 0xac, 0xbf },
  402. { 0x8e, 0x00 }, /* De-noise threshold */
  403. { 0x0c, 0xd0 }
  404. };
  405. static const u8 bridge_start_vga[][2] = {
  406. {0x1c, 0x00},
  407. {0x1d, 0x40},
  408. {0x1d, 0x02},
  409. {0x1d, 0x00},
  410. {0x1d, 0x02},
  411. {0x1d, 0x58},
  412. {0x1d, 0x00},
  413. {0xc0, 0x50},
  414. {0xc1, 0x3c},
  415. };
  416. static const u8 sensor_start_vga[][2] = {
  417. {0x12, 0x00},
  418. {0x17, 0x26},
  419. {0x18, 0xa0},
  420. {0x19, 0x07},
  421. {0x1a, 0xf0},
  422. {0x29, 0xa0},
  423. {0x2c, 0xf0},
  424. {0x65, 0x20},
  425. };
  426. static const u8 bridge_start_qvga[][2] = {
  427. {0x1c, 0x00},
  428. {0x1d, 0x40},
  429. {0x1d, 0x02},
  430. {0x1d, 0x00},
  431. {0x1d, 0x01},
  432. {0x1d, 0x4b},
  433. {0x1d, 0x00},
  434. {0xc0, 0x28},
  435. {0xc1, 0x1e},
  436. };
  437. static const u8 sensor_start_qvga[][2] = {
  438. {0x12, 0x40},
  439. {0x17, 0x3f},
  440. {0x18, 0x50},
  441. {0x19, 0x03},
  442. {0x1a, 0x78},
  443. {0x29, 0x50},
  444. {0x2c, 0x78},
  445. {0x65, 0x2f},
  446. };
  447. static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  448. {
  449. struct usb_device *udev = gspca_dev->dev;
  450. int ret;
  451. PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
  452. gspca_dev->usb_buf[0] = val;
  453. ret = usb_control_msg(udev,
  454. usb_sndctrlpipe(udev, 0),
  455. 0x01,
  456. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  457. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  458. if (ret < 0)
  459. PDEBUG(D_ERR, "write failed");
  460. }
  461. static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  462. {
  463. struct usb_device *udev = gspca_dev->dev;
  464. int ret;
  465. ret = usb_control_msg(udev,
  466. usb_rcvctrlpipe(udev, 0),
  467. 0x01,
  468. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  469. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  470. PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
  471. if (ret < 0)
  472. PDEBUG(D_ERR, "read failed");
  473. return gspca_dev->usb_buf[0];
  474. }
  475. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  476. * (direction and output)? */
  477. static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
  478. {
  479. u8 data;
  480. PDEBUG(D_CONF, "led status: %d", status);
  481. data = ov534_reg_read(gspca_dev, 0x21);
  482. data |= 0x80;
  483. ov534_reg_write(gspca_dev, 0x21, data);
  484. data = ov534_reg_read(gspca_dev, 0x23);
  485. if (status)
  486. data |= 0x80;
  487. else
  488. data &= ~0x80;
  489. ov534_reg_write(gspca_dev, 0x23, data);
  490. if (!status) {
  491. data = ov534_reg_read(gspca_dev, 0x21);
  492. data &= ~0x80;
  493. ov534_reg_write(gspca_dev, 0x21, data);
  494. }
  495. }
  496. static int sccb_check_status(struct gspca_dev *gspca_dev)
  497. {
  498. u8 data;
  499. int i;
  500. for (i = 0; i < 5; i++) {
  501. data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
  502. switch (data) {
  503. case 0x00:
  504. return 1;
  505. case 0x04:
  506. return 0;
  507. case 0x03:
  508. break;
  509. default:
  510. PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
  511. data, i + 1);
  512. }
  513. }
  514. return 0;
  515. }
  516. static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  517. {
  518. PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
  519. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  520. ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
  521. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  522. if (!sccb_check_status(gspca_dev))
  523. PDEBUG(D_ERR, "sccb_reg_write failed");
  524. }
  525. static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  526. {
  527. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  528. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  529. if (!sccb_check_status(gspca_dev))
  530. PDEBUG(D_ERR, "sccb_reg_read failed 1");
  531. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  532. if (!sccb_check_status(gspca_dev))
  533. PDEBUG(D_ERR, "sccb_reg_read failed 2");
  534. return ov534_reg_read(gspca_dev, OV534_REG_READ);
  535. }
  536. /* output a bridge sequence (reg - val) */
  537. static void reg_w_array(struct gspca_dev *gspca_dev,
  538. const u8 (*data)[2], int len)
  539. {
  540. while (--len >= 0) {
  541. ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  542. data++;
  543. }
  544. }
  545. /* output a sensor sequence (reg - val) */
  546. static void sccb_w_array(struct gspca_dev *gspca_dev,
  547. const u8 (*data)[2], int len)
  548. {
  549. while (--len >= 0) {
  550. if ((*data)[0] != 0xff) {
  551. sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  552. } else {
  553. sccb_reg_read(gspca_dev, (*data)[1]);
  554. sccb_reg_write(gspca_dev, 0xff, 0x00);
  555. }
  556. data++;
  557. }
  558. }
  559. /* ov772x specific controls */
  560. static void set_frame_rate(struct gspca_dev *gspca_dev)
  561. {
  562. struct sd *sd = (struct sd *) gspca_dev;
  563. int i;
  564. struct rate_s {
  565. u8 fps;
  566. u8 r11;
  567. u8 r0d;
  568. u8 re5;
  569. };
  570. const struct rate_s *r;
  571. static const struct rate_s rate_0[] = { /* 640x480 */
  572. {60, 0x01, 0xc1, 0x04},
  573. {50, 0x01, 0x41, 0x02},
  574. {40, 0x02, 0xc1, 0x04},
  575. {30, 0x04, 0x81, 0x02},
  576. {15, 0x03, 0x41, 0x04},
  577. };
  578. static const struct rate_s rate_1[] = { /* 320x240 */
  579. {125, 0x02, 0x81, 0x02},
  580. {100, 0x02, 0xc1, 0x04},
  581. {75, 0x03, 0xc1, 0x04},
  582. {60, 0x04, 0xc1, 0x04},
  583. {50, 0x02, 0x41, 0x04},
  584. {40, 0x03, 0x41, 0x04},
  585. {30, 0x04, 0x41, 0x04},
  586. };
  587. if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
  588. r = rate_0;
  589. i = ARRAY_SIZE(rate_0);
  590. } else {
  591. r = rate_1;
  592. i = ARRAY_SIZE(rate_1);
  593. }
  594. while (--i > 0) {
  595. if (sd->frame_rate >= r->fps)
  596. break;
  597. r++;
  598. }
  599. sccb_reg_write(gspca_dev, 0x11, r->r11);
  600. sccb_reg_write(gspca_dev, 0x0d, r->r0d);
  601. ov534_reg_write(gspca_dev, 0xe5, r->re5);
  602. PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
  603. }
  604. static void setbrightness(struct gspca_dev *gspca_dev)
  605. {
  606. struct sd *sd = (struct sd *) gspca_dev;
  607. sccb_reg_write(gspca_dev, 0x9b, sd->brightness);
  608. }
  609. static void setcontrast(struct gspca_dev *gspca_dev)
  610. {
  611. struct sd *sd = (struct sd *) gspca_dev;
  612. sccb_reg_write(gspca_dev, 0x9c, sd->contrast);
  613. }
  614. static void setgain(struct gspca_dev *gspca_dev)
  615. {
  616. struct sd *sd = (struct sd *) gspca_dev;
  617. u8 val;
  618. if (sd->agc)
  619. return;
  620. val = sd->gain;
  621. switch (val & 0x30) {
  622. case 0x00:
  623. val &= 0x0f;
  624. break;
  625. case 0x10:
  626. val &= 0x0f;
  627. val |= 0x30;
  628. break;
  629. case 0x20:
  630. val &= 0x0f;
  631. val |= 0x70;
  632. break;
  633. default:
  634. /* case 0x30: */
  635. val &= 0x0f;
  636. val |= 0xf0;
  637. break;
  638. }
  639. sccb_reg_write(gspca_dev, 0x00, val);
  640. }
  641. static void setexposure(struct gspca_dev *gspca_dev)
  642. {
  643. struct sd *sd = (struct sd *) gspca_dev;
  644. u8 val;
  645. if (sd->aec)
  646. return;
  647. /* 'val' is one byte and represents half of the exposure value we are
  648. * going to set into registers, a two bytes value:
  649. *
  650. * MSB: ((u16) val << 1) >> 8 == val >> 7
  651. * LSB: ((u16) val << 1) & 0xff == val << 1
  652. */
  653. val = sd->exposure;
  654. sccb_reg_write(gspca_dev, 0x08, val >> 7);
  655. sccb_reg_write(gspca_dev, 0x10, val << 1);
  656. }
  657. static void setagc(struct gspca_dev *gspca_dev)
  658. {
  659. struct sd *sd = (struct sd *) gspca_dev;
  660. if (sd->agc) {
  661. sccb_reg_write(gspca_dev, 0x13,
  662. sccb_reg_read(gspca_dev, 0x13) | 0x04);
  663. sccb_reg_write(gspca_dev, 0x64,
  664. sccb_reg_read(gspca_dev, 0x64) | 0x03);
  665. } else {
  666. sccb_reg_write(gspca_dev, 0x13,
  667. sccb_reg_read(gspca_dev, 0x13) & ~0x04);
  668. sccb_reg_write(gspca_dev, 0x64,
  669. sccb_reg_read(gspca_dev, 0x64) & ~0x03);
  670. setgain(gspca_dev);
  671. }
  672. }
  673. static void setawb(struct gspca_dev *gspca_dev)
  674. {
  675. struct sd *sd = (struct sd *) gspca_dev;
  676. if (sd->awb) {
  677. sccb_reg_write(gspca_dev, 0x13,
  678. sccb_reg_read(gspca_dev, 0x13) | 0x02);
  679. sccb_reg_write(gspca_dev, 0x63,
  680. sccb_reg_read(gspca_dev, 0x63) | 0xc0);
  681. } else {
  682. sccb_reg_write(gspca_dev, 0x13,
  683. sccb_reg_read(gspca_dev, 0x13) & ~0x02);
  684. sccb_reg_write(gspca_dev, 0x63,
  685. sccb_reg_read(gspca_dev, 0x63) & ~0xc0);
  686. }
  687. }
  688. static void setaec(struct gspca_dev *gspca_dev)
  689. {
  690. struct sd *sd = (struct sd *) gspca_dev;
  691. if (sd->aec)
  692. sccb_reg_write(gspca_dev, 0x13,
  693. sccb_reg_read(gspca_dev, 0x13) | 0x01);
  694. else {
  695. sccb_reg_write(gspca_dev, 0x13,
  696. sccb_reg_read(gspca_dev, 0x13) & ~0x01);
  697. setexposure(gspca_dev);
  698. }
  699. }
  700. static void setsharpness(struct gspca_dev *gspca_dev)
  701. {
  702. struct sd *sd = (struct sd *) gspca_dev;
  703. u8 val;
  704. val = sd->sharpness;
  705. sccb_reg_write(gspca_dev, 0x91, val); /* Auto de-noise threshold */
  706. sccb_reg_write(gspca_dev, 0x8e, val); /* De-noise threshold */
  707. }
  708. static void sethflip(struct gspca_dev *gspca_dev)
  709. {
  710. struct sd *sd = (struct sd *) gspca_dev;
  711. if (sd->hflip == 0)
  712. sccb_reg_write(gspca_dev, 0x0c,
  713. sccb_reg_read(gspca_dev, 0x0c) | 0x40);
  714. else
  715. sccb_reg_write(gspca_dev, 0x0c,
  716. sccb_reg_read(gspca_dev, 0x0c) & ~0x40);
  717. }
  718. static void setvflip(struct gspca_dev *gspca_dev)
  719. {
  720. struct sd *sd = (struct sd *) gspca_dev;
  721. if (sd->vflip == 0)
  722. sccb_reg_write(gspca_dev, 0x0c,
  723. sccb_reg_read(gspca_dev, 0x0c) | 0x80);
  724. else
  725. sccb_reg_write(gspca_dev, 0x0c,
  726. sccb_reg_read(gspca_dev, 0x0c) & ~0x80);
  727. }
  728. static void setfreqfltr(struct gspca_dev *gspca_dev)
  729. {
  730. struct sd *sd = (struct sd *) gspca_dev;
  731. if (sd->freqfltr == 0)
  732. sccb_reg_write(gspca_dev, 0x2b, 0x00);
  733. else
  734. sccb_reg_write(gspca_dev, 0x2b, 0x9e);
  735. }
  736. /* this function is called at probe time */
  737. static int sd_config(struct gspca_dev *gspca_dev,
  738. const struct usb_device_id *id)
  739. {
  740. struct sd *sd = (struct sd *) gspca_dev;
  741. struct cam *cam;
  742. cam = &gspca_dev->cam;
  743. cam->cam_mode = ov772x_mode;
  744. cam->nmodes = ARRAY_SIZE(ov772x_mode);
  745. cam->mode_framerates = ov772x_framerates;
  746. cam->bulk = 1;
  747. cam->bulk_size = 16384;
  748. cam->bulk_nurbs = 2;
  749. sd->frame_rate = 30;
  750. sd->brightness = BRIGHTNESS_DEF;
  751. sd->contrast = CONTRAST_DEF;
  752. sd->gain = GAIN_DEF;
  753. sd->exposure = EXPO_DEF;
  754. #if AGC_DEF != 0
  755. sd->agc = AGC_DEF;
  756. #else
  757. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  758. #endif
  759. sd->awb = AWB_DEF;
  760. sd->aec = AEC_DEF;
  761. sd->sharpness = SHARPNESS_DEF;
  762. sd->hflip = HFLIP_DEF;
  763. sd->vflip = VFLIP_DEF;
  764. sd->freqfltr = FREQFLTR_DEF;
  765. return 0;
  766. }
  767. /* this function is called at probe and resume time */
  768. static int sd_init(struct gspca_dev *gspca_dev)
  769. {
  770. u16 sensor_id;
  771. /* reset bridge */
  772. ov534_reg_write(gspca_dev, 0xe7, 0x3a);
  773. ov534_reg_write(gspca_dev, 0xe0, 0x08);
  774. msleep(100);
  775. /* initialize the sensor address */
  776. ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
  777. /* reset sensor */
  778. sccb_reg_write(gspca_dev, 0x12, 0x80);
  779. msleep(10);
  780. /* probe the sensor */
  781. sccb_reg_read(gspca_dev, 0x0a);
  782. sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
  783. sccb_reg_read(gspca_dev, 0x0b);
  784. sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
  785. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  786. /* initialize */
  787. reg_w_array(gspca_dev, bridge_init,
  788. ARRAY_SIZE(bridge_init));
  789. ov534_set_led(gspca_dev, 1);
  790. sccb_w_array(gspca_dev, sensor_init,
  791. ARRAY_SIZE(sensor_init));
  792. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  793. ov534_set_led(gspca_dev, 0);
  794. set_frame_rate(gspca_dev);
  795. return 0;
  796. }
  797. static int sd_start(struct gspca_dev *gspca_dev)
  798. {
  799. int mode;
  800. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  801. if (mode != 0) { /* 320x240 */
  802. reg_w_array(gspca_dev, bridge_start_qvga,
  803. ARRAY_SIZE(bridge_start_qvga));
  804. sccb_w_array(gspca_dev, sensor_start_qvga,
  805. ARRAY_SIZE(sensor_start_qvga));
  806. } else { /* 640x480 */
  807. reg_w_array(gspca_dev, bridge_start_vga,
  808. ARRAY_SIZE(bridge_start_vga));
  809. sccb_w_array(gspca_dev, sensor_start_vga,
  810. ARRAY_SIZE(sensor_start_vga));
  811. }
  812. set_frame_rate(gspca_dev);
  813. setagc(gspca_dev);
  814. setawb(gspca_dev);
  815. setaec(gspca_dev);
  816. setgain(gspca_dev);
  817. setexposure(gspca_dev);
  818. setbrightness(gspca_dev);
  819. setcontrast(gspca_dev);
  820. setsharpness(gspca_dev);
  821. setvflip(gspca_dev);
  822. sethflip(gspca_dev);
  823. setfreqfltr(gspca_dev);
  824. ov534_set_led(gspca_dev, 1);
  825. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  826. return 0;
  827. }
  828. static void sd_stopN(struct gspca_dev *gspca_dev)
  829. {
  830. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  831. ov534_set_led(gspca_dev, 0);
  832. }
  833. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  834. #define UVC_STREAM_EOH (1 << 7)
  835. #define UVC_STREAM_ERR (1 << 6)
  836. #define UVC_STREAM_STI (1 << 5)
  837. #define UVC_STREAM_RES (1 << 4)
  838. #define UVC_STREAM_SCR (1 << 3)
  839. #define UVC_STREAM_PTS (1 << 2)
  840. #define UVC_STREAM_EOF (1 << 1)
  841. #define UVC_STREAM_FID (1 << 0)
  842. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  843. u8 *data, int len)
  844. {
  845. struct sd *sd = (struct sd *) gspca_dev;
  846. __u32 this_pts;
  847. u16 this_fid;
  848. int remaining_len = len;
  849. do {
  850. len = min(remaining_len, 2048);
  851. /* Payloads are prefixed with a UVC-style header. We
  852. consider a frame to start when the FID toggles, or the PTS
  853. changes. A frame ends when EOF is set, and we've received
  854. the correct number of bytes. */
  855. /* Verify UVC header. Header length is always 12 */
  856. if (data[0] != 12 || len < 12) {
  857. PDEBUG(D_PACK, "bad header");
  858. goto discard;
  859. }
  860. /* Check errors */
  861. if (data[1] & UVC_STREAM_ERR) {
  862. PDEBUG(D_PACK, "payload error");
  863. goto discard;
  864. }
  865. /* Extract PTS and FID */
  866. if (!(data[1] & UVC_STREAM_PTS)) {
  867. PDEBUG(D_PACK, "PTS not present");
  868. goto discard;
  869. }
  870. this_pts = (data[5] << 24) | (data[4] << 16)
  871. | (data[3] << 8) | data[2];
  872. this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
  873. /* If PTS or FID has changed, start a new frame. */
  874. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  875. if (gspca_dev->last_packet_type == INTER_PACKET)
  876. gspca_frame_add(gspca_dev, LAST_PACKET,
  877. NULL, 0);
  878. sd->last_pts = this_pts;
  879. sd->last_fid = this_fid;
  880. gspca_frame_add(gspca_dev, FIRST_PACKET,
  881. data + 12, len - 12);
  882. /* If this packet is marked as EOF, end the frame */
  883. } else if (data[1] & UVC_STREAM_EOF) {
  884. sd->last_pts = 0;
  885. if (gspca_dev->image_len + len - 12 !=
  886. gspca_dev->width * gspca_dev->height * 2) {
  887. PDEBUG(D_PACK, "wrong sized frame");
  888. goto discard;
  889. }
  890. gspca_frame_add(gspca_dev, LAST_PACKET,
  891. data + 12, len - 12);
  892. } else {
  893. /* Add the data from this payload */
  894. gspca_frame_add(gspca_dev, INTER_PACKET,
  895. data + 12, len - 12);
  896. }
  897. /* Done this payload */
  898. goto scan_next;
  899. discard:
  900. /* Discard data until a new frame starts. */
  901. gspca_dev->last_packet_type = DISCARD_PACKET;
  902. scan_next:
  903. remaining_len -= len;
  904. data += len;
  905. } while (remaining_len > 0);
  906. }
  907. /* controls */
  908. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  909. {
  910. struct sd *sd = (struct sd *) gspca_dev;
  911. sd->gain = val;
  912. if (gspca_dev->streaming)
  913. setgain(gspca_dev);
  914. return 0;
  915. }
  916. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  917. {
  918. struct sd *sd = (struct sd *) gspca_dev;
  919. *val = sd->gain;
  920. return 0;
  921. }
  922. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  923. {
  924. struct sd *sd = (struct sd *) gspca_dev;
  925. sd->exposure = val;
  926. if (gspca_dev->streaming)
  927. setexposure(gspca_dev);
  928. return 0;
  929. }
  930. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  931. {
  932. struct sd *sd = (struct sd *) gspca_dev;
  933. *val = sd->exposure;
  934. return 0;
  935. }
  936. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  937. {
  938. struct sd *sd = (struct sd *) gspca_dev;
  939. sd->brightness = val;
  940. if (gspca_dev->streaming)
  941. setbrightness(gspca_dev);
  942. return 0;
  943. }
  944. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  945. {
  946. struct sd *sd = (struct sd *) gspca_dev;
  947. *val = sd->brightness;
  948. return 0;
  949. }
  950. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  951. {
  952. struct sd *sd = (struct sd *) gspca_dev;
  953. sd->contrast = val;
  954. if (gspca_dev->streaming)
  955. setcontrast(gspca_dev);
  956. return 0;
  957. }
  958. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  959. {
  960. struct sd *sd = (struct sd *) gspca_dev;
  961. *val = sd->contrast;
  962. return 0;
  963. }
  964. static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val)
  965. {
  966. struct sd *sd = (struct sd *) gspca_dev;
  967. sd->agc = val;
  968. if (gspca_dev->streaming) {
  969. /* the auto white balance control works only
  970. * when auto gain is set */
  971. if (val)
  972. gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
  973. else
  974. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  975. setagc(gspca_dev);
  976. }
  977. return 0;
  978. }
  979. static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val)
  980. {
  981. struct sd *sd = (struct sd *) gspca_dev;
  982. *val = sd->agc;
  983. return 0;
  984. }
  985. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
  986. {
  987. struct sd *sd = (struct sd *) gspca_dev;
  988. sd->awb = val;
  989. if (gspca_dev->streaming)
  990. setawb(gspca_dev);
  991. return 0;
  992. }
  993. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
  994. {
  995. struct sd *sd = (struct sd *) gspca_dev;
  996. *val = sd->awb;
  997. return 0;
  998. }
  999. static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val)
  1000. {
  1001. struct sd *sd = (struct sd *) gspca_dev;
  1002. sd->aec = val;
  1003. if (gspca_dev->streaming)
  1004. setaec(gspca_dev);
  1005. return 0;
  1006. }
  1007. static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val)
  1008. {
  1009. struct sd *sd = (struct sd *) gspca_dev;
  1010. *val = sd->aec;
  1011. return 0;
  1012. }
  1013. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1014. {
  1015. struct sd *sd = (struct sd *) gspca_dev;
  1016. sd->sharpness = val;
  1017. if (gspca_dev->streaming)
  1018. setsharpness(gspca_dev);
  1019. return 0;
  1020. }
  1021. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1022. {
  1023. struct sd *sd = (struct sd *) gspca_dev;
  1024. *val = sd->sharpness;
  1025. return 0;
  1026. }
  1027. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  1028. {
  1029. struct sd *sd = (struct sd *) gspca_dev;
  1030. sd->hflip = val;
  1031. if (gspca_dev->streaming)
  1032. sethflip(gspca_dev);
  1033. return 0;
  1034. }
  1035. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1036. {
  1037. struct sd *sd = (struct sd *) gspca_dev;
  1038. *val = sd->hflip;
  1039. return 0;
  1040. }
  1041. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1042. {
  1043. struct sd *sd = (struct sd *) gspca_dev;
  1044. sd->vflip = val;
  1045. if (gspca_dev->streaming)
  1046. setvflip(gspca_dev);
  1047. return 0;
  1048. }
  1049. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1050. {
  1051. struct sd *sd = (struct sd *) gspca_dev;
  1052. *val = sd->vflip;
  1053. return 0;
  1054. }
  1055. static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val)
  1056. {
  1057. struct sd *sd = (struct sd *) gspca_dev;
  1058. sd->freqfltr = val;
  1059. if (gspca_dev->streaming)
  1060. setfreqfltr(gspca_dev);
  1061. return 0;
  1062. }
  1063. static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val)
  1064. {
  1065. struct sd *sd = (struct sd *) gspca_dev;
  1066. *val = sd->freqfltr;
  1067. return 0;
  1068. }
  1069. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1070. struct v4l2_querymenu *menu)
  1071. {
  1072. switch (menu->id) {
  1073. case V4L2_CID_POWER_LINE_FREQUENCY:
  1074. switch (menu->index) {
  1075. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  1076. strcpy((char *) menu->name, "Disabled");
  1077. return 0;
  1078. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  1079. strcpy((char *) menu->name, "50 Hz");
  1080. return 0;
  1081. }
  1082. break;
  1083. }
  1084. return -EINVAL;
  1085. }
  1086. /* get stream parameters (framerate) */
  1087. static int sd_get_streamparm(struct gspca_dev *gspca_dev,
  1088. struct v4l2_streamparm *parm)
  1089. {
  1090. struct v4l2_captureparm *cp = &parm->parm.capture;
  1091. struct v4l2_fract *tpf = &cp->timeperframe;
  1092. struct sd *sd = (struct sd *) gspca_dev;
  1093. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1094. return -EINVAL;
  1095. cp->capability |= V4L2_CAP_TIMEPERFRAME;
  1096. tpf->numerator = 1;
  1097. tpf->denominator = sd->frame_rate;
  1098. return 0;
  1099. }
  1100. /* set stream parameters (framerate) */
  1101. static int sd_set_streamparm(struct gspca_dev *gspca_dev,
  1102. struct v4l2_streamparm *parm)
  1103. {
  1104. struct v4l2_captureparm *cp = &parm->parm.capture;
  1105. struct v4l2_fract *tpf = &cp->timeperframe;
  1106. struct sd *sd = (struct sd *) gspca_dev;
  1107. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1108. return -EINVAL;
  1109. /* Set requested framerate */
  1110. sd->frame_rate = tpf->denominator / tpf->numerator;
  1111. if (gspca_dev->streaming)
  1112. set_frame_rate(gspca_dev);
  1113. /* Return the actual framerate */
  1114. tpf->numerator = 1;
  1115. tpf->denominator = sd->frame_rate;
  1116. return 0;
  1117. }
  1118. /* sub-driver description */
  1119. static const struct sd_desc sd_desc = {
  1120. .name = MODULE_NAME,
  1121. .ctrls = sd_ctrls,
  1122. .nctrls = ARRAY_SIZE(sd_ctrls),
  1123. .config = sd_config,
  1124. .init = sd_init,
  1125. .start = sd_start,
  1126. .stopN = sd_stopN,
  1127. .pkt_scan = sd_pkt_scan,
  1128. .querymenu = sd_querymenu,
  1129. .get_streamparm = sd_get_streamparm,
  1130. .set_streamparm = sd_set_streamparm,
  1131. };
  1132. /* -- module initialisation -- */
  1133. static const __devinitdata struct usb_device_id device_table[] = {
  1134. {USB_DEVICE(0x1415, 0x2000)},
  1135. {}
  1136. };
  1137. MODULE_DEVICE_TABLE(usb, device_table);
  1138. /* -- device connect -- */
  1139. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1140. {
  1141. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1142. THIS_MODULE);
  1143. }
  1144. static struct usb_driver sd_driver = {
  1145. .name = MODULE_NAME,
  1146. .id_table = device_table,
  1147. .probe = sd_probe,
  1148. .disconnect = gspca_disconnect,
  1149. #ifdef CONFIG_PM
  1150. .suspend = gspca_suspend,
  1151. .resume = gspca_resume,
  1152. #endif
  1153. };
  1154. /* -- module insert / remove -- */
  1155. static int __init sd_mod_init(void)
  1156. {
  1157. int ret;
  1158. ret = usb_register(&sd_driver);
  1159. if (ret < 0)
  1160. return ret;
  1161. PDEBUG(D_PROBE, "registered");
  1162. return 0;
  1163. }
  1164. static void __exit sd_mod_exit(void)
  1165. {
  1166. usb_deregister(&sd_driver);
  1167. PDEBUG(D_PROBE, "deregistered");
  1168. }
  1169. module_init(sd_mod_init);
  1170. module_exit(sd_mod_exit);