ov534.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  1. /*
  2. * ov534 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, hue, AWB control added
  14. * 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 redblc;
  56. u8 blueblc;
  57. u8 hue;
  58. u8 autogain;
  59. u8 awb;
  60. u8 sharpness;
  61. u8 hflip;
  62. u8 vflip;
  63. u8 sensor;
  64. #define SENSOR_OV772X 0
  65. #define SENSOR_OV965X 1
  66. };
  67. /* V4L2 controls supported by the driver */
  68. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  69. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  70. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val);
  76. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  77. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  78. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
  86. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
  87. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
  88. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  89. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  90. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  91. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  92. static struct ctrl sd_ctrls_ov772x[] = {
  93. { /* 0 */
  94. {
  95. .id = V4L2_CID_BRIGHTNESS,
  96. .type = V4L2_CTRL_TYPE_INTEGER,
  97. .name = "Brightness",
  98. .minimum = 0,
  99. .maximum = 255,
  100. .step = 1,
  101. #define BRIGHTNESS_DEF 20
  102. .default_value = BRIGHTNESS_DEF,
  103. },
  104. .set = sd_setbrightness,
  105. .get = sd_getbrightness,
  106. },
  107. { /* 1 */
  108. {
  109. .id = V4L2_CID_CONTRAST,
  110. .type = V4L2_CTRL_TYPE_INTEGER,
  111. .name = "Contrast",
  112. .minimum = 0,
  113. .maximum = 255,
  114. .step = 1,
  115. #define CONTRAST_DEF 37
  116. .default_value = CONTRAST_DEF,
  117. },
  118. .set = sd_setcontrast,
  119. .get = sd_getcontrast,
  120. },
  121. { /* 2 */
  122. {
  123. .id = V4L2_CID_GAIN,
  124. .type = V4L2_CTRL_TYPE_INTEGER,
  125. .name = "Main Gain",
  126. .minimum = 0,
  127. .maximum = 63,
  128. .step = 1,
  129. #define GAIN_DEF 20
  130. .default_value = GAIN_DEF,
  131. },
  132. .set = sd_setgain,
  133. .get = sd_getgain,
  134. },
  135. { /* 3 */
  136. {
  137. .id = V4L2_CID_EXPOSURE,
  138. .type = V4L2_CTRL_TYPE_INTEGER,
  139. .name = "Exposure",
  140. .minimum = 0,
  141. .maximum = 255,
  142. .step = 1,
  143. #define EXPO_DEF 120
  144. .default_value = EXPO_DEF,
  145. },
  146. .set = sd_setexposure,
  147. .get = sd_getexposure,
  148. },
  149. { /* 4 */
  150. {
  151. .id = V4L2_CID_RED_BALANCE,
  152. .type = V4L2_CTRL_TYPE_INTEGER,
  153. .name = "Red Balance",
  154. .minimum = 0,
  155. .maximum = 255,
  156. .step = 1,
  157. #define RED_BALANCE_DEF 128
  158. .default_value = RED_BALANCE_DEF,
  159. },
  160. .set = sd_setredblc,
  161. .get = sd_getredblc,
  162. },
  163. { /* 5 */
  164. {
  165. .id = V4L2_CID_BLUE_BALANCE,
  166. .type = V4L2_CTRL_TYPE_INTEGER,
  167. .name = "Blue Balance",
  168. .minimum = 0,
  169. .maximum = 255,
  170. .step = 1,
  171. #define BLUE_BALANCE_DEF 128
  172. .default_value = BLUE_BALANCE_DEF,
  173. },
  174. .set = sd_setblueblc,
  175. .get = sd_getblueblc,
  176. },
  177. { /* 6 */
  178. {
  179. .id = V4L2_CID_HUE,
  180. .type = V4L2_CTRL_TYPE_INTEGER,
  181. .name = "Hue",
  182. .minimum = 0,
  183. .maximum = 255,
  184. .step = 1,
  185. #define HUE_DEF 143
  186. .default_value = HUE_DEF,
  187. },
  188. .set = sd_sethue,
  189. .get = sd_gethue,
  190. },
  191. { /* 7 */
  192. {
  193. .id = V4L2_CID_AUTOGAIN,
  194. .type = V4L2_CTRL_TYPE_BOOLEAN,
  195. .name = "Autogain",
  196. .minimum = 0,
  197. .maximum = 1,
  198. .step = 1,
  199. #define AUTOGAIN_DEF 0
  200. .default_value = AUTOGAIN_DEF,
  201. },
  202. .set = sd_setautogain,
  203. .get = sd_getautogain,
  204. },
  205. #define AWB_IDX 8
  206. { /* 8 */
  207. {
  208. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  209. .type = V4L2_CTRL_TYPE_BOOLEAN,
  210. .name = "Auto White Balance",
  211. .minimum = 0,
  212. .maximum = 1,
  213. .step = 1,
  214. #define AWB_DEF 0
  215. .default_value = AWB_DEF,
  216. },
  217. .set = sd_setawb,
  218. .get = sd_getawb,
  219. },
  220. { /* 9 */
  221. {
  222. .id = V4L2_CID_SHARPNESS,
  223. .type = V4L2_CTRL_TYPE_INTEGER,
  224. .name = "Sharpness",
  225. .minimum = 0,
  226. .maximum = 63,
  227. .step = 1,
  228. #define SHARPNESS_DEF 0
  229. .default_value = SHARPNESS_DEF,
  230. },
  231. .set = sd_setsharpness,
  232. .get = sd_getsharpness,
  233. },
  234. { /* 10 */
  235. {
  236. .id = V4L2_CID_HFLIP,
  237. .type = V4L2_CTRL_TYPE_BOOLEAN,
  238. .name = "HFlip",
  239. .minimum = 0,
  240. .maximum = 1,
  241. .step = 1,
  242. #define HFLIP_DEF 0
  243. .default_value = HFLIP_DEF,
  244. },
  245. .set = sd_sethflip,
  246. .get = sd_gethflip,
  247. },
  248. { /* 11 */
  249. {
  250. .id = V4L2_CID_VFLIP,
  251. .type = V4L2_CTRL_TYPE_BOOLEAN,
  252. .name = "VFlip",
  253. .minimum = 0,
  254. .maximum = 1,
  255. .step = 1,
  256. #define VFLIP_DEF 0
  257. .default_value = VFLIP_DEF,
  258. },
  259. .set = sd_setvflip,
  260. .get = sd_getvflip,
  261. },
  262. };
  263. static struct ctrl sd_ctrls_ov965x[] = {
  264. };
  265. static const struct v4l2_pix_format vga_yuyv_mode[] = {
  266. {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  267. .bytesperline = 320 * 2,
  268. .sizeimage = 320 * 240 * 2,
  269. .colorspace = V4L2_COLORSPACE_SRGB,
  270. .priv = 1},
  271. {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  272. .bytesperline = 640 * 2,
  273. .sizeimage = 640 * 480 * 2,
  274. .colorspace = V4L2_COLORSPACE_SRGB,
  275. .priv = 0},
  276. };
  277. static const struct v4l2_pix_format vga_jpeg_mode[] = {
  278. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  279. .bytesperline = 320,
  280. .sizeimage = 320 * 240 * 3 / 8 + 590,
  281. .colorspace = V4L2_COLORSPACE_JPEG,
  282. .priv = 1},
  283. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  284. .bytesperline = 640,
  285. .sizeimage = 640 * 480 * 3 / 8 + 590,
  286. .colorspace = V4L2_COLORSPACE_JPEG,
  287. .priv = 0},
  288. };
  289. static const u8 bridge_init_ov772x[][2] = {
  290. { 0xc2, 0x0c },
  291. { 0x88, 0xf8 },
  292. { 0xc3, 0x69 },
  293. { 0x89, 0xff },
  294. { 0x76, 0x03 },
  295. { 0x92, 0x01 },
  296. { 0x93, 0x18 },
  297. { 0x94, 0x10 },
  298. { 0x95, 0x10 },
  299. { 0xe2, 0x00 },
  300. { 0xe7, 0x3e },
  301. { 0x96, 0x00 },
  302. { 0x97, 0x20 },
  303. { 0x97, 0x20 },
  304. { 0x97, 0x20 },
  305. { 0x97, 0x0a },
  306. { 0x97, 0x3f },
  307. { 0x97, 0x4a },
  308. { 0x97, 0x20 },
  309. { 0x97, 0x15 },
  310. { 0x97, 0x0b },
  311. { 0x8e, 0x40 },
  312. { 0x1f, 0x81 },
  313. { 0x34, 0x05 },
  314. { 0xe3, 0x04 },
  315. { 0x88, 0x00 },
  316. { 0x89, 0x00 },
  317. { 0x76, 0x00 },
  318. { 0xe7, 0x2e },
  319. { 0x31, 0xf9 },
  320. { 0x25, 0x42 },
  321. { 0x21, 0xf0 },
  322. { 0x1c, 0x00 },
  323. { 0x1d, 0x40 },
  324. { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
  325. { 0x1d, 0x00 }, /* payload size */
  326. { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
  327. { 0x1d, 0x58 }, /* frame size */
  328. { 0x1d, 0x00 }, /* frame size */
  329. { 0x1c, 0x0a },
  330. { 0x1d, 0x08 }, /* turn on UVC header */
  331. { 0x1d, 0x0e }, /* .. */
  332. { 0x8d, 0x1c },
  333. { 0x8e, 0x80 },
  334. { 0xe5, 0x04 },
  335. { 0xc0, 0x50 },
  336. { 0xc1, 0x3c },
  337. { 0xc2, 0x0c },
  338. };
  339. static const u8 sensor_init_ov772x[][2] = {
  340. { 0x12, 0x80 },
  341. { 0x11, 0x01 },
  342. /*fixme: better have a delay?*/
  343. { 0x11, 0x01 },
  344. { 0x11, 0x01 },
  345. { 0x11, 0x01 },
  346. { 0x11, 0x01 },
  347. { 0x11, 0x01 },
  348. { 0x11, 0x01 },
  349. { 0x11, 0x01 },
  350. { 0x11, 0x01 },
  351. { 0x11, 0x01 },
  352. { 0x11, 0x01 },
  353. { 0x3d, 0x03 },
  354. { 0x17, 0x26 },
  355. { 0x18, 0xa0 },
  356. { 0x19, 0x07 },
  357. { 0x1a, 0xf0 },
  358. { 0x32, 0x00 },
  359. { 0x29, 0xa0 },
  360. { 0x2c, 0xf0 },
  361. { 0x65, 0x20 },
  362. { 0x11, 0x01 },
  363. { 0x42, 0x7f },
  364. { 0x63, 0xaa }, /* AWB - was e0 */
  365. { 0x64, 0xff },
  366. { 0x66, 0x00 },
  367. { 0x13, 0xf0 }, /* com8 */
  368. { 0x0d, 0x41 },
  369. { 0x0f, 0xc5 },
  370. { 0x14, 0x11 },
  371. { 0x22, 0x7f },
  372. { 0x23, 0x03 },
  373. { 0x24, 0x40 },
  374. { 0x25, 0x30 },
  375. { 0x26, 0xa1 },
  376. { 0x2a, 0x00 },
  377. { 0x2b, 0x00 },
  378. { 0x6b, 0xaa },
  379. { 0x13, 0xff }, /* AWB */
  380. { 0x90, 0x05 },
  381. { 0x91, 0x01 },
  382. { 0x92, 0x03 },
  383. { 0x93, 0x00 },
  384. { 0x94, 0x60 },
  385. { 0x95, 0x3c },
  386. { 0x96, 0x24 },
  387. { 0x97, 0x1e },
  388. { 0x98, 0x62 },
  389. { 0x99, 0x80 },
  390. { 0x9a, 0x1e },
  391. { 0x9b, 0x08 },
  392. { 0x9c, 0x20 },
  393. { 0x9e, 0x81 },
  394. { 0xa6, 0x04 },
  395. { 0x7e, 0x0c },
  396. { 0x7f, 0x16 },
  397. { 0x80, 0x2a },
  398. { 0x81, 0x4e },
  399. { 0x82, 0x61 },
  400. { 0x83, 0x6f },
  401. { 0x84, 0x7b },
  402. { 0x85, 0x86 },
  403. { 0x86, 0x8e },
  404. { 0x87, 0x97 },
  405. { 0x88, 0xa4 },
  406. { 0x89, 0xaf },
  407. { 0x8a, 0xc5 },
  408. { 0x8b, 0xd7 },
  409. { 0x8c, 0xe8 },
  410. { 0x8d, 0x20 },
  411. { 0x0c, 0x90 },
  412. { 0x2b, 0x00 },
  413. { 0x22, 0x7f },
  414. { 0x23, 0x03 },
  415. { 0x11, 0x01 },
  416. { 0x0c, 0xd0 },
  417. { 0x64, 0xff },
  418. { 0x0d, 0x41 },
  419. { 0x14, 0x41 },
  420. { 0x0e, 0xcd },
  421. { 0xac, 0xbf },
  422. { 0x8e, 0x00 }, /* De-noise threshold */
  423. { 0x0c, 0xd0 }
  424. };
  425. static const u8 bridge_start_ov772x_vga[][2] = {
  426. {0x1c, 0x00},
  427. {0x1d, 0x40},
  428. {0x1d, 0x02},
  429. {0x1d, 0x00},
  430. {0x1d, 0x02},
  431. {0x1d, 0x58},
  432. {0x1d, 0x00},
  433. {0xc0, 0x50},
  434. {0xc1, 0x3c},
  435. };
  436. static const u8 sensor_start_ov772x_vga[][2] = {
  437. {0x12, 0x00},
  438. {0x17, 0x26},
  439. {0x18, 0xa0},
  440. {0x19, 0x07},
  441. {0x1a, 0xf0},
  442. {0x29, 0xa0},
  443. {0x2c, 0xf0},
  444. {0x65, 0x20},
  445. };
  446. static const u8 bridge_start_ov772x_qvga[][2] = {
  447. {0x1c, 0x00},
  448. {0x1d, 0x40},
  449. {0x1d, 0x02},
  450. {0x1d, 0x00},
  451. {0x1d, 0x01},
  452. {0x1d, 0x4b},
  453. {0x1d, 0x00},
  454. {0xc0, 0x28},
  455. {0xc1, 0x1e},
  456. };
  457. static const u8 sensor_start_ov772x_qvga[][2] = {
  458. {0x12, 0x40},
  459. {0x17, 0x3f},
  460. {0x18, 0x50},
  461. {0x19, 0x03},
  462. {0x1a, 0x78},
  463. {0x29, 0x50},
  464. {0x2c, 0x78},
  465. {0x65, 0x2f},
  466. };
  467. static const u8 bridge_init_ov965x[][2] = {
  468. {0x88, 0xf8},
  469. {0x89, 0xff},
  470. {0x76, 0x03},
  471. {0x92, 0x03},
  472. {0x95, 0x10},
  473. {0xe2, 0x00},
  474. {0xe7, 0x3e},
  475. {0x8d, 0x1c},
  476. {0x8e, 0x00},
  477. {0x8f, 0x00},
  478. {0x1f, 0x00},
  479. {0xc3, 0xf9},
  480. {0x89, 0xff},
  481. {0x88, 0xf8},
  482. {0x76, 0x03},
  483. {0x92, 0x01},
  484. {0x93, 0x18},
  485. {0x1c, 0x0a},
  486. {0x1d, 0x48},
  487. {0xc0, 0x50},
  488. {0xc1, 0x3c},
  489. {0x34, 0x05},
  490. {0xc2, 0x0c},
  491. {0xc3, 0xf9},
  492. {0x34, 0x05},
  493. {0xe7, 0x2e},
  494. {0x31, 0xf9},
  495. {0x35, 0x02},
  496. {0xd9, 0x10},
  497. {0x25, 0x42},
  498. {0x94, 0x11},
  499. };
  500. static const u8 sensor_init_ov965x[][2] = {
  501. {0x12, 0x80}, /* com7 - SSCB reset */
  502. {0x00, 0x00}, /* gain */
  503. {0x01, 0x80}, /* blue */
  504. {0x02, 0x80}, /* red */
  505. {0x03, 0x1b}, /* vref */
  506. {0x04, 0x03}, /* com1 - exposure low bits */
  507. {0x0b, 0x57}, /* ver */
  508. {0x0e, 0x61}, /* com5 */
  509. {0x0f, 0x42}, /* com6 */
  510. {0x11, 0x00}, /* clkrc */
  511. {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
  512. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  513. {0x14, 0x28}, /* com9 */
  514. {0x16, 0x24}, /* reg16 */
  515. {0x17, 0x1d}, /* hstart*/
  516. {0x18, 0xbd}, /* hstop */
  517. {0x19, 0x01}, /* vstrt */
  518. {0x1a, 0x81}, /* vstop*/
  519. {0x1e, 0x04}, /* mvfp */
  520. {0x24, 0x3c}, /* aew */
  521. {0x25, 0x36}, /* aeb */
  522. {0x26, 0x71}, /* vpt */
  523. {0x27, 0x08}, /* bbias */
  524. {0x28, 0x08}, /* gbbias */
  525. {0x29, 0x15}, /* gr com */
  526. {0x2a, 0x00}, /* exhch */
  527. {0x2b, 0x00}, /* exhcl */
  528. {0x2c, 0x08}, /* rbias */
  529. {0x32, 0xff}, /* href */
  530. {0x33, 0x00}, /* chlf */
  531. {0x34, 0x3f}, /* aref1 */
  532. {0x35, 0x00}, /* aref2 */
  533. {0x36, 0xf8}, /* aref3 */
  534. {0x38, 0x72}, /* adc2 */
  535. {0x39, 0x57}, /* aref4 */
  536. {0x3a, 0x80}, /* tslb - yuyv */
  537. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  538. {0x3d, 0x99}, /* com13 */
  539. {0x3f, 0xc1}, /* edge */
  540. {0x40, 0xc0}, /* com15 */
  541. {0x41, 0x40}, /* com16 */
  542. {0x42, 0xc0}, /* com17 */
  543. {0x43, 0x0a}, /* rsvd */
  544. {0x44, 0xf0},
  545. {0x45, 0x46},
  546. {0x46, 0x62},
  547. {0x47, 0x2a},
  548. {0x48, 0x3c},
  549. {0x4a, 0xfc},
  550. {0x4b, 0xfc},
  551. {0x4c, 0x7f},
  552. {0x4d, 0x7f},
  553. {0x4e, 0x7f},
  554. {0x4f, 0x98}, /* matrix */
  555. {0x50, 0x98},
  556. {0x51, 0x00},
  557. {0x52, 0x28},
  558. {0x53, 0x70},
  559. {0x54, 0x98},
  560. {0x58, 0x1a}, /* matrix coef sign */
  561. {0x59, 0x85}, /* AWB control */
  562. {0x5a, 0xa9},
  563. {0x5b, 0x64},
  564. {0x5c, 0x84},
  565. {0x5d, 0x53},
  566. {0x5e, 0x0e},
  567. {0x5f, 0xf0}, /* AWB blue limit */
  568. {0x60, 0xf0}, /* AWB red limit */
  569. {0x61, 0xf0}, /* AWB green limit */
  570. {0x62, 0x00}, /* lcc1 */
  571. {0x63, 0x00}, /* lcc2 */
  572. {0x64, 0x02}, /* lcc3 */
  573. {0x65, 0x16}, /* lcc4 */
  574. {0x66, 0x01}, /* lcc5 */
  575. {0x69, 0x02}, /* hv */
  576. {0x6b, 0x5a}, /* dbvl */
  577. {0x6c, 0x04},
  578. {0x6d, 0x55},
  579. {0x6e, 0x00},
  580. {0x6f, 0x9d},
  581. {0x70, 0x21}, /* dnsth */
  582. {0x71, 0x78},
  583. {0x72, 0x00}, /* poidx */
  584. {0x73, 0x01}, /* pckdv */
  585. {0x74, 0x3a}, /* xindx */
  586. {0x75, 0x35}, /* yindx */
  587. {0x76, 0x01},
  588. {0x77, 0x02},
  589. {0x7a, 0x12}, /* gamma curve */
  590. {0x7b, 0x08},
  591. {0x7c, 0x16},
  592. {0x7d, 0x30},
  593. {0x7e, 0x5e},
  594. {0x7f, 0x72},
  595. {0x80, 0x82},
  596. {0x81, 0x8e},
  597. {0x82, 0x9a},
  598. {0x83, 0xa4},
  599. {0x84, 0xac},
  600. {0x85, 0xb8},
  601. {0x86, 0xc3},
  602. {0x87, 0xd6},
  603. {0x88, 0xe6},
  604. {0x89, 0xf2},
  605. {0x8a, 0x03},
  606. {0x8c, 0x89}, /* com19 */
  607. {0x14, 0x28}, /* com9 */
  608. {0x90, 0x7d},
  609. {0x91, 0x7b},
  610. {0x9d, 0x03}, /* lcc6 */
  611. {0x9e, 0x04}, /* lcc7 */
  612. {0x9f, 0x7a},
  613. {0xa0, 0x79},
  614. {0xa1, 0x40}, /* aechm */
  615. {0xa4, 0x50}, /* com21 */
  616. {0xa5, 0x68}, /* com26 */
  617. {0xa6, 0x4a}, /* AWB green */
  618. {0xa8, 0xc1}, /* refa8 */
  619. {0xa9, 0xef}, /* refa9 */
  620. {0xaa, 0x92},
  621. {0xab, 0x04},
  622. {0xac, 0x80}, /* black level control */
  623. {0xad, 0x80},
  624. {0xae, 0x80},
  625. {0xaf, 0x80},
  626. {0xb2, 0xf2},
  627. {0xb3, 0x20},
  628. {0xb4, 0x20}, /* ctrlb4 */
  629. {0xb5, 0x00},
  630. {0xb6, 0xaf},
  631. {0xbb, 0xae},
  632. {0xbc, 0x7f}, /* ADC channel offsets */
  633. {0xdb, 0x7f},
  634. {0xbe, 0x7f},
  635. {0xbf, 0x7f},
  636. {0xc0, 0xe2},
  637. {0xc1, 0xc0},
  638. {0xc2, 0x01},
  639. {0xc3, 0x4e},
  640. {0xc6, 0x85},
  641. {0xc7, 0x80}, /* com24 */
  642. {0xc9, 0xe0},
  643. {0xca, 0xe8},
  644. {0xcb, 0xf0},
  645. {0xcc, 0xd8},
  646. {0xcd, 0xf1},
  647. {0x4f, 0x98},
  648. {0x50, 0x98},
  649. {0x51, 0x00},
  650. {0x52, 0x28},
  651. {0x53, 0x70},
  652. {0x54, 0x98},
  653. {0x58, 0x1a},
  654. {0xff, 0x41}, /* read 41, write ff 00 */
  655. {0x41, 0x40}, /* com16 */
  656. {0xc5, 0x03}, /* 60 Hz banding filter */
  657. {0x6a, 0x02}, /* 50 Hz banding filter */
  658. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  659. {0x36, 0xfa}, /* aref3 */
  660. {0x69, 0x0a}, /* hv */
  661. {0x8c, 0x89}, /* com22 */
  662. {0x14, 0x28}, /* com9 */
  663. {0x3e, 0x0c},
  664. {0x41, 0x40}, /* com16 */
  665. {0x72, 0x00},
  666. {0x73, 0x00},
  667. {0x74, 0x3a},
  668. {0x75, 0x35},
  669. {0x76, 0x01},
  670. {0xc7, 0x80},
  671. {0x03, 0x12}, /* vref */
  672. {0x17, 0x16}, /* hstart */
  673. {0x18, 0x02}, /* hstop */
  674. {0x19, 0x01}, /* vstrt */
  675. {0x1a, 0x3d}, /* vstop */
  676. {0x32, 0xff}, /* href */
  677. {0xc0, 0xaa},
  678. };
  679. static const u8 bridge_init_ov965x_2[][2] = {
  680. {0x94, 0xaa},
  681. {0xf1, 0x60},
  682. {0xe5, 0x04},
  683. {0xc0, 0x50},
  684. {0xc1, 0x3c},
  685. {0x8c, 0x00},
  686. {0x8d, 0x1c},
  687. {0x34, 0x05},
  688. {0xc2, 0x0c},
  689. {0xc3, 0xf9},
  690. {0xda, 0x01},
  691. {0x50, 0x00},
  692. {0x51, 0xa0},
  693. {0x52, 0x3c},
  694. {0x53, 0x00},
  695. {0x54, 0x00},
  696. {0x55, 0x00}, /* brightness */
  697. {0x57, 0x00}, /* contrast 2 */
  698. {0x5c, 0x00},
  699. {0x5a, 0xa0},
  700. {0x5b, 0x78},
  701. {0x35, 0x02},
  702. {0xd9, 0x10},
  703. {0x94, 0x11},
  704. };
  705. static const u8 sensor_init_ov965x_2[][2] = {
  706. {0x3b, 0xc4},
  707. {0x1e, 0x04}, /* mvfp */
  708. {0x13, 0xe0}, /* com8 */
  709. {0x00, 0x00}, /* gain */
  710. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  711. {0x11, 0x03}, /* clkrc */
  712. {0x6b, 0x5a}, /* dblv */
  713. {0x6a, 0x05},
  714. {0xc5, 0x07},
  715. {0xa2, 0x4b},
  716. {0xa3, 0x3e},
  717. {0x2d, 0x00},
  718. {0xff, 0x42}, /* read 42, write ff 00 */
  719. {0x42, 0xc0},
  720. {0x2d, 0x00},
  721. {0xff, 0x42}, /* read 42, write ff 00 */
  722. {0x42, 0xc1},
  723. {0x3f, 0x01},
  724. {0xff, 0x42}, /* read 42, write ff 00 */
  725. {0x42, 0xc1},
  726. {0x4f, 0x98},
  727. {0x50, 0x98},
  728. {0x51, 0x00},
  729. {0x52, 0x28},
  730. {0x53, 0x70},
  731. {0x54, 0x98},
  732. {0x58, 0x1a},
  733. {0xff, 0x41}, /* read 41, write ff 00 */
  734. {0x41, 0x40}, /* com16 */
  735. {0x56, 0x40},
  736. {0x55, 0x8f},
  737. {0x10, 0x25}, /* aech - exposure high bits */
  738. {0xff, 0x13}, /* read 13, write ff 00 */
  739. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  740. };
  741. static const u8 sensor_start_ov965x[][2] = {
  742. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  743. {0x36, 0xfa}, /* aref3 */
  744. {0x69, 0x0a}, /* hv */
  745. {0x8c, 0x89}, /* com22 */
  746. {0x14, 0x28}, /* com9 */
  747. {0x3e, 0x0c}, /* com14 */
  748. {0x41, 0x40}, /* com16 */
  749. {0x72, 0x00},
  750. {0x73, 0x00},
  751. {0x74, 0x3a},
  752. {0x75, 0x35},
  753. {0x76, 0x01},
  754. {0xc7, 0x80}, /* com24 */
  755. {0x03, 0x12}, /* vref */
  756. {0x17, 0x16}, /* hstart */
  757. {0x18, 0x02}, /* hstop */
  758. {0x19, 0x01}, /* vstrt */
  759. {0x1a, 0x3d}, /* vstop */
  760. {0x32, 0xff}, /* href */
  761. {0xc0, 0xaa},
  762. {}
  763. };
  764. static const u8 bridge_start_ov965x[][2] = {
  765. {0x94, 0xaa},
  766. {0xf1, 0x60},
  767. {0xe5, 0x04},
  768. {0xc0, 0x50},
  769. {0xc1, 0x3c},
  770. {0x8c, 0x00},
  771. {0x8d, 0x1c},
  772. {0x34, 0x05},
  773. {}
  774. };
  775. static const u8 bridge_start_ov965x_vga[][2] = {
  776. {0xc2, 0x0c},
  777. {0xc3, 0xf9},
  778. {0xda, 0x01},
  779. {0x50, 0x00},
  780. {0x51, 0xa0},
  781. {0x52, 0x3c},
  782. {0x53, 0x00},
  783. {0x54, 0x00},
  784. {0x55, 0x00},
  785. {0x57, 0x00},
  786. {0x5c, 0x00},
  787. {0x5a, 0xa0},
  788. {0x5b, 0x78},
  789. {0x35, 0x02},
  790. {0xd9, 0x10},
  791. {0x94, 0x11},
  792. {}
  793. };
  794. static const u8 bridge_start_ov965x_qvga[][2] = {
  795. {0xc2, 0x4c},
  796. {0xc3, 0xf9},
  797. {0xda, 0x00},
  798. {0x50, 0x00},
  799. {0x51, 0xa0},
  800. {0x52, 0x78},
  801. {0x53, 0x00},
  802. {0x54, 0x00},
  803. {0x55, 0x00},
  804. {0x57, 0x00},
  805. {0x5c, 0x00},
  806. {0x5a, 0x50},
  807. {0x5b, 0x3c},
  808. {0x35, 0x02},
  809. {0xd9, 0x10},
  810. {0x94, 0x11},
  811. {}
  812. };
  813. static const u8 sensor_start_ov965x_vga[][2] = {
  814. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  815. {0x1e, 0x04}, /* mvfp */
  816. {0x13, 0xe0}, /* com8 */
  817. {0x00, 0x00},
  818. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  819. {0x11, 0x03}, /* clkrc */
  820. {0x6b, 0x5a}, /* dblv */
  821. {0x6a, 0x05}, /* 50 Hz banding filter */
  822. {0xc5, 0x07}, /* 60 Hz banding filter */
  823. {0xa2, 0x4b}, /* bd50 */
  824. {0xa3, 0x3e}, /* bd60 */
  825. {0x2d, 0x00}, /* advfl */
  826. {}
  827. };
  828. static const u8 sensor_start_ov965x_qvga[][2] = {
  829. {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
  830. {0x1e, 0x04}, /* mvfp */
  831. {0x13, 0xe0}, /* com8 */
  832. {0x00, 0x00},
  833. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  834. {0x11, 0x01}, /* clkrc */
  835. {0x6b, 0x5a}, /* dblv */
  836. {0x6a, 0x02}, /* 50 Hz banding filter */
  837. {0xc5, 0x03}, /* 60 Hz banding filter */
  838. {0xa2, 0x96}, /* bd50 */
  839. {0xa3, 0x7d}, /* bd60 */
  840. {0xff, 0x13}, /* read 13, write ff 00 */
  841. {0x13, 0xe7},
  842. {0x3a, 0x80}, /* tslb - yuyv */
  843. {}
  844. };
  845. static const u8 sensor_start_ov965x_2[][2] = {
  846. {0xff, 0x42}, /* read 42, write ff 00 */
  847. {0x42, 0xc1}, /* com17 - 50 Hz filter */
  848. {}
  849. };
  850. static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  851. {
  852. struct usb_device *udev = gspca_dev->dev;
  853. int ret;
  854. PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
  855. gspca_dev->usb_buf[0] = val;
  856. ret = usb_control_msg(udev,
  857. usb_sndctrlpipe(udev, 0),
  858. 0x01,
  859. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  860. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  861. if (ret < 0)
  862. PDEBUG(D_ERR, "write failed");
  863. }
  864. static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  865. {
  866. struct usb_device *udev = gspca_dev->dev;
  867. int ret;
  868. ret = usb_control_msg(udev,
  869. usb_rcvctrlpipe(udev, 0),
  870. 0x01,
  871. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  872. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  873. PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
  874. if (ret < 0)
  875. PDEBUG(D_ERR, "read failed");
  876. return gspca_dev->usb_buf[0];
  877. }
  878. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  879. * (direction and output)? */
  880. static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
  881. {
  882. u8 data;
  883. PDEBUG(D_CONF, "led status: %d", status);
  884. data = ov534_reg_read(gspca_dev, 0x21);
  885. data |= 0x80;
  886. ov534_reg_write(gspca_dev, 0x21, data);
  887. data = ov534_reg_read(gspca_dev, 0x23);
  888. if (status)
  889. data |= 0x80;
  890. else
  891. data &= ~0x80;
  892. ov534_reg_write(gspca_dev, 0x23, data);
  893. if (!status) {
  894. data = ov534_reg_read(gspca_dev, 0x21);
  895. data &= ~0x80;
  896. ov534_reg_write(gspca_dev, 0x21, data);
  897. }
  898. }
  899. static int sccb_check_status(struct gspca_dev *gspca_dev)
  900. {
  901. u8 data;
  902. int i;
  903. for (i = 0; i < 5; i++) {
  904. data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
  905. switch (data) {
  906. case 0x00:
  907. return 1;
  908. case 0x04:
  909. return 0;
  910. case 0x03:
  911. break;
  912. default:
  913. PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
  914. data, i + 1);
  915. }
  916. }
  917. return 0;
  918. }
  919. static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  920. {
  921. PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
  922. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  923. ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
  924. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  925. if (!sccb_check_status(gspca_dev))
  926. PDEBUG(D_ERR, "sccb_reg_write failed");
  927. }
  928. static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  929. {
  930. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  931. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  932. if (!sccb_check_status(gspca_dev))
  933. PDEBUG(D_ERR, "sccb_reg_read failed 1");
  934. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  935. if (!sccb_check_status(gspca_dev))
  936. PDEBUG(D_ERR, "sccb_reg_read failed 2");
  937. return ov534_reg_read(gspca_dev, OV534_REG_READ);
  938. }
  939. /* output a bridge sequence (reg - val) */
  940. static void reg_w_array(struct gspca_dev *gspca_dev,
  941. const u8 (*data)[2], int len)
  942. {
  943. while (--len >= 0) {
  944. ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  945. data++;
  946. }
  947. }
  948. /* output a sensor sequence (reg - val) */
  949. static void sccb_w_array(struct gspca_dev *gspca_dev,
  950. const u8 (*data)[2], int len)
  951. {
  952. while (--len >= 0) {
  953. if ((*data)[0] != 0xff) {
  954. sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  955. } else {
  956. sccb_reg_read(gspca_dev, (*data)[1]);
  957. sccb_reg_write(gspca_dev, 0xff, 0x00);
  958. }
  959. data++;
  960. }
  961. }
  962. /* ov772x specific controls */
  963. static void set_frame_rate(struct gspca_dev *gspca_dev)
  964. {
  965. struct sd *sd = (struct sd *) gspca_dev;
  966. int i;
  967. struct rate_s {
  968. u8 fps;
  969. u8 r11;
  970. u8 r0d;
  971. u8 re5;
  972. };
  973. const struct rate_s *r;
  974. static const struct rate_s rate_0[] = { /* 640x480 */
  975. {60, 0x01, 0xc1, 0x04},
  976. {50, 0x01, 0x41, 0x02},
  977. {40, 0x02, 0xc1, 0x04},
  978. {30, 0x04, 0x81, 0x02},
  979. {15, 0x03, 0x41, 0x04},
  980. };
  981. static const struct rate_s rate_1[] = { /* 320x240 */
  982. {125, 0x02, 0x81, 0x02},
  983. {100, 0x02, 0xc1, 0x04},
  984. {75, 0x03, 0xc1, 0x04},
  985. {60, 0x04, 0xc1, 0x04},
  986. {50, 0x02, 0x41, 0x04},
  987. {40, 0x03, 0x41, 0x04},
  988. {30, 0x04, 0x41, 0x04},
  989. };
  990. if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
  991. r = rate_0;
  992. i = ARRAY_SIZE(rate_0);
  993. } else {
  994. r = rate_1;
  995. i = ARRAY_SIZE(rate_1);
  996. }
  997. while (--i > 0) {
  998. if (sd->frame_rate >= r->fps)
  999. break;
  1000. r++;
  1001. }
  1002. sccb_reg_write(gspca_dev, 0x11, r->r11);
  1003. sccb_reg_write(gspca_dev, 0x0d, r->r0d);
  1004. ov534_reg_write(gspca_dev, 0xe5, r->re5);
  1005. PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
  1006. }
  1007. static void setbrightness(struct gspca_dev *gspca_dev)
  1008. {
  1009. struct sd *sd = (struct sd *) gspca_dev;
  1010. sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
  1011. }
  1012. static void setcontrast(struct gspca_dev *gspca_dev)
  1013. {
  1014. struct sd *sd = (struct sd *) gspca_dev;
  1015. sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
  1016. }
  1017. static void setgain(struct gspca_dev *gspca_dev)
  1018. {
  1019. struct sd *sd = (struct sd *) gspca_dev;
  1020. u8 val;
  1021. val = sd->gain;
  1022. switch (val & 0x30) {
  1023. case 0x00:
  1024. val &= 0x0f;
  1025. break;
  1026. case 0x10:
  1027. val &= 0x0f;
  1028. val |= 0x30;
  1029. break;
  1030. case 0x20:
  1031. val &= 0x0f;
  1032. val |= 0x70;
  1033. break;
  1034. default:
  1035. /* case 0x30: */
  1036. val &= 0x0f;
  1037. val |= 0xf0;
  1038. break;
  1039. }
  1040. sccb_reg_write(gspca_dev, 0x00, val);
  1041. }
  1042. static void setexposure(struct gspca_dev *gspca_dev)
  1043. {
  1044. struct sd *sd = (struct sd *) gspca_dev;
  1045. u8 val;
  1046. val = sd->exposure;
  1047. sccb_reg_write(gspca_dev, 0x08, val >> 7);
  1048. sccb_reg_write(gspca_dev, 0x10, val << 1);
  1049. }
  1050. static void setredblc(struct gspca_dev *gspca_dev)
  1051. {
  1052. struct sd *sd = (struct sd *) gspca_dev;
  1053. sccb_reg_write(gspca_dev, 0x43, sd->redblc);
  1054. }
  1055. static void setblueblc(struct gspca_dev *gspca_dev)
  1056. {
  1057. struct sd *sd = (struct sd *) gspca_dev;
  1058. sccb_reg_write(gspca_dev, 0x42, sd->blueblc);
  1059. }
  1060. static void sethue(struct gspca_dev *gspca_dev)
  1061. {
  1062. struct sd *sd = (struct sd *) gspca_dev;
  1063. sccb_reg_write(gspca_dev, 0x01, sd->hue);
  1064. }
  1065. static void setautogain(struct gspca_dev *gspca_dev)
  1066. {
  1067. struct sd *sd = (struct sd *) gspca_dev;
  1068. if (sd->autogain) {
  1069. sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */
  1070. sccb_reg_write(gspca_dev, 0x64,
  1071. sccb_reg_read(gspca_dev, 0x64) | 0x03);
  1072. } else {
  1073. sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */
  1074. sccb_reg_write(gspca_dev, 0x64,
  1075. sccb_reg_read(gspca_dev, 0x64) & 0xfc);
  1076. }
  1077. }
  1078. static void setawb(struct gspca_dev *gspca_dev)
  1079. {
  1080. struct sd *sd = (struct sd *) gspca_dev;
  1081. if (sd->awb)
  1082. sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */
  1083. else
  1084. sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */
  1085. }
  1086. static void setsharpness(struct gspca_dev *gspca_dev)
  1087. {
  1088. struct sd *sd = (struct sd *) gspca_dev;
  1089. u8 val;
  1090. val = sd->sharpness;
  1091. sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */
  1092. sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */
  1093. }
  1094. static void sethflip(struct gspca_dev *gspca_dev)
  1095. {
  1096. struct sd *sd = (struct sd *) gspca_dev;
  1097. if (sd->hflip == 0)
  1098. sccb_reg_write(gspca_dev, 0x0c,
  1099. sccb_reg_read(gspca_dev, 0x0c) | 0x40);
  1100. else
  1101. sccb_reg_write(gspca_dev, 0x0c,
  1102. sccb_reg_read(gspca_dev, 0x0c) & 0xbf);
  1103. }
  1104. static void setvflip(struct gspca_dev *gspca_dev)
  1105. {
  1106. struct sd *sd = (struct sd *) gspca_dev;
  1107. if (sd->vflip == 0)
  1108. sccb_reg_write(gspca_dev, 0x0c,
  1109. sccb_reg_read(gspca_dev, 0x0c) | 0x80);
  1110. else
  1111. sccb_reg_write(gspca_dev, 0x0c,
  1112. sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
  1113. }
  1114. /* this function is called at probe time */
  1115. static int sd_config(struct gspca_dev *gspca_dev,
  1116. const struct usb_device_id *id)
  1117. {
  1118. struct sd *sd = (struct sd *) gspca_dev;
  1119. struct cam *cam;
  1120. sd->sensor = id->driver_info;
  1121. cam = &gspca_dev->cam;
  1122. if (sd->sensor == SENSOR_OV772X) {
  1123. cam->cam_mode = vga_yuyv_mode;
  1124. cam->nmodes = ARRAY_SIZE(vga_yuyv_mode);
  1125. cam->bulk = 1;
  1126. cam->bulk_size = 16384;
  1127. cam->bulk_nurbs = 2;
  1128. } else { /* ov965x */
  1129. cam->cam_mode = vga_jpeg_mode;
  1130. cam->nmodes = ARRAY_SIZE(vga_jpeg_mode);
  1131. }
  1132. sd->frame_rate = 30;
  1133. sd->brightness = BRIGHTNESS_DEF;
  1134. sd->contrast = CONTRAST_DEF;
  1135. sd->gain = GAIN_DEF;
  1136. sd->exposure = EXPO_DEF;
  1137. sd->redblc = RED_BALANCE_DEF;
  1138. sd->blueblc = BLUE_BALANCE_DEF;
  1139. sd->hue = HUE_DEF;
  1140. #if AUTOGAIN_DEF != 0
  1141. sd->autogain = AUTOGAIN_DEF;
  1142. #else
  1143. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  1144. #endif
  1145. #if AWB_DEF != 0
  1146. sd->awb = AWB_DEF
  1147. #endif
  1148. sd->sharpness = SHARPNESS_DEF;
  1149. #if HFLIP_DEF != 0
  1150. sd->hflip = HFLIP_DEF;
  1151. #endif
  1152. #if VFLIP_DEF != 0
  1153. sd->vflip = VFLIP_DEF;
  1154. #endif
  1155. return 0;
  1156. }
  1157. /* this function is called at probe and resume time */
  1158. static int sd_init(struct gspca_dev *gspca_dev)
  1159. {
  1160. struct sd *sd = (struct sd *) gspca_dev;
  1161. u16 sensor_id;
  1162. static const u8 sensor_addr[2] = {
  1163. 0x42, /* 0 SENSOR_OV772X */
  1164. 0x60, /* 1 SENSOR_OV965X */
  1165. };
  1166. /* reset bridge */
  1167. ov534_reg_write(gspca_dev, 0xe7, 0x3a);
  1168. ov534_reg_write(gspca_dev, 0xe0, 0x08);
  1169. msleep(100);
  1170. /* initialize the sensor address */
  1171. ov534_reg_write(gspca_dev, OV534_REG_ADDRESS,
  1172. sensor_addr[sd->sensor]);
  1173. /* reset sensor */
  1174. sccb_reg_write(gspca_dev, 0x12, 0x80);
  1175. msleep(10);
  1176. /* probe the sensor */
  1177. sccb_reg_read(gspca_dev, 0x0a);
  1178. sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
  1179. sccb_reg_read(gspca_dev, 0x0b);
  1180. sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
  1181. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  1182. /* initialize */
  1183. switch (sd->sensor) {
  1184. case SENSOR_OV772X:
  1185. reg_w_array(gspca_dev, bridge_init_ov772x,
  1186. ARRAY_SIZE(bridge_init_ov772x));
  1187. ov534_set_led(gspca_dev, 1);
  1188. sccb_w_array(gspca_dev, sensor_init_ov772x,
  1189. ARRAY_SIZE(sensor_init_ov772x));
  1190. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1191. ov534_set_led(gspca_dev, 0);
  1192. set_frame_rate(gspca_dev);
  1193. break;
  1194. default:
  1195. /* case SENSOR_OV965X: */
  1196. reg_w_array(gspca_dev, bridge_init_ov965x,
  1197. ARRAY_SIZE(bridge_init_ov965x));
  1198. sccb_w_array(gspca_dev, sensor_init_ov965x,
  1199. ARRAY_SIZE(sensor_init_ov965x));
  1200. reg_w_array(gspca_dev, bridge_init_ov965x_2,
  1201. ARRAY_SIZE(bridge_init_ov965x_2));
  1202. sccb_w_array(gspca_dev, sensor_init_ov965x_2,
  1203. ARRAY_SIZE(sensor_init_ov965x_2));
  1204. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1205. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1206. ov534_set_led(gspca_dev, 0);
  1207. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1208. }
  1209. return 0;
  1210. }
  1211. static int sd_start_ov772x(struct gspca_dev *gspca_dev)
  1212. {
  1213. int mode;
  1214. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1215. if (mode != 0) { /* 320x240 */
  1216. reg_w_array(gspca_dev, bridge_start_ov772x_qvga,
  1217. ARRAY_SIZE(bridge_start_ov772x_qvga));
  1218. sccb_w_array(gspca_dev, sensor_start_ov772x_qvga,
  1219. ARRAY_SIZE(sensor_start_ov772x_qvga));
  1220. } else { /* 640x480 */
  1221. reg_w_array(gspca_dev, bridge_start_ov772x_vga,
  1222. ARRAY_SIZE(bridge_start_ov772x_vga));
  1223. sccb_w_array(gspca_dev, sensor_start_ov772x_vga,
  1224. ARRAY_SIZE(sensor_start_ov772x_vga));
  1225. }
  1226. set_frame_rate(gspca_dev);
  1227. setautogain(gspca_dev);
  1228. setawb(gspca_dev);
  1229. setgain(gspca_dev);
  1230. setredblc(gspca_dev);
  1231. setblueblc(gspca_dev);
  1232. sethue(gspca_dev);
  1233. setexposure(gspca_dev);
  1234. setbrightness(gspca_dev);
  1235. setcontrast(gspca_dev);
  1236. setsharpness(gspca_dev);
  1237. setvflip(gspca_dev);
  1238. sethflip(gspca_dev);
  1239. ov534_set_led(gspca_dev, 1);
  1240. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1241. return 0;
  1242. }
  1243. static int sd_start_ov965x(struct gspca_dev *gspca_dev)
  1244. {
  1245. int mode;
  1246. sccb_w_array(gspca_dev, sensor_start_ov965x,
  1247. ARRAY_SIZE(sensor_start_ov965x));
  1248. reg_w_array(gspca_dev, bridge_start_ov965x,
  1249. ARRAY_SIZE(bridge_start_ov965x));
  1250. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1251. if (mode != 0) { /* 320x240 */
  1252. reg_w_array(gspca_dev, bridge_start_ov965x_qvga,
  1253. ARRAY_SIZE(bridge_start_ov965x_qvga));
  1254. sccb_w_array(gspca_dev, sensor_start_ov965x_qvga,
  1255. ARRAY_SIZE(sensor_start_ov965x_qvga));
  1256. } else { /* 640x480 */
  1257. reg_w_array(gspca_dev, bridge_start_ov965x_vga,
  1258. ARRAY_SIZE(bridge_start_ov965x_vga));
  1259. sccb_w_array(gspca_dev, sensor_start_ov965x_vga,
  1260. ARRAY_SIZE(sensor_start_ov965x_vga));
  1261. }
  1262. sccb_w_array(gspca_dev, sensor_start_ov965x_2,
  1263. ARRAY_SIZE(sensor_start_ov965x_2));
  1264. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1265. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1266. ov534_set_led(gspca_dev, 1);
  1267. return 0;
  1268. }
  1269. static void sd_stopN_ov772x(struct gspca_dev *gspca_dev)
  1270. {
  1271. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1272. ov534_set_led(gspca_dev, 0);
  1273. }
  1274. static void sd_stopN_ov965x(struct gspca_dev *gspca_dev)
  1275. {
  1276. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1277. ov534_set_led(gspca_dev, 0);
  1278. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1279. }
  1280. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1281. #define UVC_STREAM_EOH (1 << 7)
  1282. #define UVC_STREAM_ERR (1 << 6)
  1283. #define UVC_STREAM_STI (1 << 5)
  1284. #define UVC_STREAM_RES (1 << 4)
  1285. #define UVC_STREAM_SCR (1 << 3)
  1286. #define UVC_STREAM_PTS (1 << 2)
  1287. #define UVC_STREAM_EOF (1 << 1)
  1288. #define UVC_STREAM_FID (1 << 0)
  1289. static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame,
  1290. __u8 *data, int len)
  1291. {
  1292. struct sd *sd = (struct sd *) gspca_dev;
  1293. __u32 this_pts;
  1294. u16 this_fid;
  1295. int remaining_len = len;
  1296. int payload_len;
  1297. payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
  1298. do {
  1299. len = min(remaining_len, payload_len);
  1300. /* Payloads are prefixed with a UVC-style header. We
  1301. consider a frame to start when the FID toggles, or the PTS
  1302. changes. A frame ends when EOF is set, and we've received
  1303. the correct number of bytes. */
  1304. /* Verify UVC header. Header length is always 12 */
  1305. if (data[0] != 12 || len < 12) {
  1306. PDEBUG(D_PACK, "bad header");
  1307. goto discard;
  1308. }
  1309. /* Check errors */
  1310. if (data[1] & UVC_STREAM_ERR) {
  1311. PDEBUG(D_PACK, "payload error");
  1312. goto discard;
  1313. }
  1314. /* Extract PTS and FID */
  1315. if (!(data[1] & UVC_STREAM_PTS)) {
  1316. PDEBUG(D_PACK, "PTS not present");
  1317. goto discard;
  1318. }
  1319. this_pts = (data[5] << 24) | (data[4] << 16)
  1320. | (data[3] << 8) | data[2];
  1321. this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
  1322. /* If PTS or FID has changed, start a new frame. */
  1323. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1324. if (gspca_dev->last_packet_type == INTER_PACKET)
  1325. frame = gspca_frame_add(gspca_dev,
  1326. LAST_PACKET, frame,
  1327. NULL, 0);
  1328. sd->last_pts = this_pts;
  1329. sd->last_fid = this_fid;
  1330. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  1331. data + 12, len - 12);
  1332. /* If this packet is marked as EOF, end the frame */
  1333. } else if (data[1] & UVC_STREAM_EOF) {
  1334. sd->last_pts = 0;
  1335. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  1336. data + 12, len - 12);
  1337. } else {
  1338. /* Add the data from this payload */
  1339. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  1340. data + 12, len - 12);
  1341. }
  1342. /* Done this payload */
  1343. goto scan_next;
  1344. discard:
  1345. /* Discard data until a new frame starts. */
  1346. gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0);
  1347. scan_next:
  1348. remaining_len -= len;
  1349. data += len;
  1350. } while (remaining_len > 0);
  1351. }
  1352. /* ov772x controls */
  1353. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  1354. {
  1355. struct sd *sd = (struct sd *) gspca_dev;
  1356. sd->gain = val;
  1357. if (gspca_dev->streaming)
  1358. setgain(gspca_dev);
  1359. return 0;
  1360. }
  1361. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  1362. {
  1363. struct sd *sd = (struct sd *) gspca_dev;
  1364. *val = sd->gain;
  1365. return 0;
  1366. }
  1367. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  1368. {
  1369. struct sd *sd = (struct sd *) gspca_dev;
  1370. sd->exposure = val;
  1371. if (gspca_dev->streaming)
  1372. setexposure(gspca_dev);
  1373. return 0;
  1374. }
  1375. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  1376. {
  1377. struct sd *sd = (struct sd *) gspca_dev;
  1378. *val = sd->exposure;
  1379. return 0;
  1380. }
  1381. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1382. {
  1383. struct sd *sd = (struct sd *) gspca_dev;
  1384. sd->brightness = val;
  1385. if (gspca_dev->streaming)
  1386. setbrightness(gspca_dev);
  1387. return 0;
  1388. }
  1389. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1390. {
  1391. struct sd *sd = (struct sd *) gspca_dev;
  1392. *val = sd->brightness;
  1393. return 0;
  1394. }
  1395. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1396. {
  1397. struct sd *sd = (struct sd *) gspca_dev;
  1398. sd->contrast = val;
  1399. if (gspca_dev->streaming)
  1400. setcontrast(gspca_dev);
  1401. return 0;
  1402. }
  1403. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1404. {
  1405. struct sd *sd = (struct sd *) gspca_dev;
  1406. *val = sd->contrast;
  1407. return 0;
  1408. }
  1409. static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val)
  1410. {
  1411. struct sd *sd = (struct sd *) gspca_dev;
  1412. sd->redblc = val;
  1413. if (gspca_dev->streaming)
  1414. setredblc(gspca_dev);
  1415. return 0;
  1416. }
  1417. static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val)
  1418. {
  1419. struct sd *sd = (struct sd *) gspca_dev;
  1420. *val = sd->redblc;
  1421. return 0;
  1422. }
  1423. static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val)
  1424. {
  1425. struct sd *sd = (struct sd *) gspca_dev;
  1426. sd->blueblc = val;
  1427. if (gspca_dev->streaming)
  1428. setblueblc(gspca_dev);
  1429. return 0;
  1430. }
  1431. static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val)
  1432. {
  1433. struct sd *sd = (struct sd *) gspca_dev;
  1434. *val = sd->blueblc;
  1435. return 0;
  1436. }
  1437. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
  1438. {
  1439. struct sd *sd = (struct sd *) gspca_dev;
  1440. sd->hue = val;
  1441. if (gspca_dev->streaming)
  1442. sethue(gspca_dev);
  1443. return 0;
  1444. }
  1445. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
  1446. {
  1447. struct sd *sd = (struct sd *) gspca_dev;
  1448. *val = sd->hue;
  1449. return 0;
  1450. }
  1451. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1452. {
  1453. struct sd *sd = (struct sd *) gspca_dev;
  1454. sd->autogain = val;
  1455. /* the auto white balance control works only when auto gain is set */
  1456. if (val)
  1457. gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
  1458. else
  1459. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  1460. if (gspca_dev->streaming)
  1461. setautogain(gspca_dev);
  1462. return 0;
  1463. }
  1464. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1465. {
  1466. struct sd *sd = (struct sd *) gspca_dev;
  1467. *val = sd->autogain;
  1468. return 0;
  1469. }
  1470. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
  1471. {
  1472. struct sd *sd = (struct sd *) gspca_dev;
  1473. sd->awb = val;
  1474. if (gspca_dev->streaming)
  1475. setawb(gspca_dev);
  1476. return 0;
  1477. }
  1478. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
  1479. {
  1480. struct sd *sd = (struct sd *) gspca_dev;
  1481. *val = sd->awb;
  1482. return 0;
  1483. }
  1484. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1485. {
  1486. struct sd *sd = (struct sd *) gspca_dev;
  1487. sd->sharpness = val;
  1488. if (gspca_dev->streaming)
  1489. setsharpness(gspca_dev);
  1490. return 0;
  1491. }
  1492. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1493. {
  1494. struct sd *sd = (struct sd *) gspca_dev;
  1495. *val = sd->sharpness;
  1496. return 0;
  1497. }
  1498. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  1499. {
  1500. struct sd *sd = (struct sd *) gspca_dev;
  1501. sd->hflip = val;
  1502. if (gspca_dev->streaming)
  1503. sethflip(gspca_dev);
  1504. return 0;
  1505. }
  1506. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1507. {
  1508. struct sd *sd = (struct sd *) gspca_dev;
  1509. *val = sd->hflip;
  1510. return 0;
  1511. }
  1512. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1513. {
  1514. struct sd *sd = (struct sd *) gspca_dev;
  1515. sd->vflip = val;
  1516. if (gspca_dev->streaming)
  1517. setvflip(gspca_dev);
  1518. return 0;
  1519. }
  1520. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1521. {
  1522. struct sd *sd = (struct sd *) gspca_dev;
  1523. *val = sd->vflip;
  1524. return 0;
  1525. }
  1526. /* get stream parameters (framerate) */
  1527. static int sd_get_streamparm(struct gspca_dev *gspca_dev,
  1528. struct v4l2_streamparm *parm)
  1529. {
  1530. struct v4l2_captureparm *cp = &parm->parm.capture;
  1531. struct v4l2_fract *tpf = &cp->timeperframe;
  1532. struct sd *sd = (struct sd *) gspca_dev;
  1533. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1534. return -EINVAL;
  1535. cp->capability |= V4L2_CAP_TIMEPERFRAME;
  1536. tpf->numerator = 1;
  1537. tpf->denominator = sd->frame_rate;
  1538. return 0;
  1539. }
  1540. /* set stream parameters (framerate) */
  1541. static int sd_set_streamparm(struct gspca_dev *gspca_dev,
  1542. struct v4l2_streamparm *parm)
  1543. {
  1544. struct v4l2_captureparm *cp = &parm->parm.capture;
  1545. struct v4l2_fract *tpf = &cp->timeperframe;
  1546. struct sd *sd = (struct sd *) gspca_dev;
  1547. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1548. return -EINVAL;
  1549. /* Set requested framerate */
  1550. sd->frame_rate = tpf->denominator / tpf->numerator;
  1551. if (gspca_dev->streaming && sd->sensor == SENSOR_OV772X)
  1552. set_frame_rate(gspca_dev);
  1553. /* Return the actual framerate */
  1554. tpf->numerator = 1;
  1555. tpf->denominator = sd->frame_rate;
  1556. return 0;
  1557. }
  1558. /* sub-driver description */
  1559. static const struct sd_desc sd_desc_ov772x = {
  1560. .name = MODULE_NAME,
  1561. .ctrls = sd_ctrls_ov772x,
  1562. .nctrls = ARRAY_SIZE(sd_ctrls_ov772x),
  1563. .config = sd_config,
  1564. .init = sd_init,
  1565. .start = sd_start_ov772x,
  1566. .stopN = sd_stopN_ov772x,
  1567. .pkt_scan = sd_pkt_scan,
  1568. .get_streamparm = sd_get_streamparm,
  1569. .set_streamparm = sd_set_streamparm,
  1570. };
  1571. static const struct sd_desc sd_desc_ov965x = {
  1572. .name = MODULE_NAME,
  1573. .ctrls = sd_ctrls_ov965x,
  1574. .nctrls = ARRAY_SIZE(sd_ctrls_ov965x),
  1575. .config = sd_config,
  1576. .init = sd_init,
  1577. .start = sd_start_ov965x,
  1578. .stopN = sd_stopN_ov965x,
  1579. .pkt_scan = sd_pkt_scan,
  1580. .get_streamparm = sd_get_streamparm,
  1581. .set_streamparm = sd_set_streamparm,
  1582. };
  1583. /* -- module initialisation -- */
  1584. static const __devinitdata struct usb_device_id device_table[] = {
  1585. {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X},
  1586. {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X},
  1587. {}
  1588. };
  1589. MODULE_DEVICE_TABLE(usb, device_table);
  1590. /* -- device connect -- */
  1591. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1592. {
  1593. return gspca_dev_probe(intf, id,
  1594. id->driver_info == SENSOR_OV772X
  1595. ? &sd_desc_ov772x
  1596. : &sd_desc_ov965x,
  1597. sizeof(struct sd),
  1598. THIS_MODULE);
  1599. }
  1600. static struct usb_driver sd_driver = {
  1601. .name = MODULE_NAME,
  1602. .id_table = device_table,
  1603. .probe = sd_probe,
  1604. .disconnect = gspca_disconnect,
  1605. #ifdef CONFIG_PM
  1606. .suspend = gspca_suspend,
  1607. .resume = gspca_resume,
  1608. #endif
  1609. };
  1610. /* -- module insert / remove -- */
  1611. static int __init sd_mod_init(void)
  1612. {
  1613. int ret;
  1614. ret = usb_register(&sd_driver);
  1615. if (ret < 0)
  1616. return ret;
  1617. PDEBUG(D_PROBE, "registered");
  1618. return 0;
  1619. }
  1620. static void __exit sd_mod_exit(void)
  1621. {
  1622. usb_deregister(&sd_driver);
  1623. PDEBUG(D_PROBE, "deregistered");
  1624. }
  1625. module_init(sd_mod_init);
  1626. module_exit(sd_mod_exit);