ov534.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  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. err("write failed %d", ret);
  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. err("read failed %d", ret);
  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. 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. 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. 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 void 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. cp->capability |= V4L2_CAP_TIMEPERFRAME;
  1094. tpf->numerator = 1;
  1095. tpf->denominator = sd->frame_rate;
  1096. }
  1097. /* set stream parameters (framerate) */
  1098. static void sd_set_streamparm(struct gspca_dev *gspca_dev,
  1099. struct v4l2_streamparm *parm)
  1100. {
  1101. struct v4l2_captureparm *cp = &parm->parm.capture;
  1102. struct v4l2_fract *tpf = &cp->timeperframe;
  1103. struct sd *sd = (struct sd *) gspca_dev;
  1104. /* Set requested framerate */
  1105. sd->frame_rate = tpf->denominator / tpf->numerator;
  1106. if (gspca_dev->streaming)
  1107. set_frame_rate(gspca_dev);
  1108. /* Return the actual framerate */
  1109. tpf->numerator = 1;
  1110. tpf->denominator = sd->frame_rate;
  1111. }
  1112. /* sub-driver description */
  1113. static const struct sd_desc sd_desc = {
  1114. .name = MODULE_NAME,
  1115. .ctrls = sd_ctrls,
  1116. .nctrls = ARRAY_SIZE(sd_ctrls),
  1117. .config = sd_config,
  1118. .init = sd_init,
  1119. .start = sd_start,
  1120. .stopN = sd_stopN,
  1121. .pkt_scan = sd_pkt_scan,
  1122. .querymenu = sd_querymenu,
  1123. .get_streamparm = sd_get_streamparm,
  1124. .set_streamparm = sd_set_streamparm,
  1125. };
  1126. /* -- module initialisation -- */
  1127. static const struct usb_device_id device_table[] = {
  1128. {USB_DEVICE(0x1415, 0x2000)},
  1129. {}
  1130. };
  1131. MODULE_DEVICE_TABLE(usb, device_table);
  1132. /* -- device connect -- */
  1133. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1134. {
  1135. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1136. THIS_MODULE);
  1137. }
  1138. static struct usb_driver sd_driver = {
  1139. .name = MODULE_NAME,
  1140. .id_table = device_table,
  1141. .probe = sd_probe,
  1142. .disconnect = gspca_disconnect,
  1143. #ifdef CONFIG_PM
  1144. .suspend = gspca_suspend,
  1145. .resume = gspca_resume,
  1146. #endif
  1147. };
  1148. /* -- module insert / remove -- */
  1149. static int __init sd_mod_init(void)
  1150. {
  1151. return usb_register(&sd_driver);
  1152. }
  1153. static void __exit sd_mod_exit(void)
  1154. {
  1155. usb_deregister(&sd_driver);
  1156. }
  1157. module_init(sd_mod_init);
  1158. module_exit(sd_mod_exit);