ov534_9.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. /*
  2. * ov534-ov965x gspca driver
  3. *
  4. * Copyright (C) 2009-2010 Jean-Francois Moine http://moinejf.free.fr
  5. * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
  6. * Copyright (C) 2008 Jim Paris <jim@jtan.com>
  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. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #define MODULE_NAME "ov534_9"
  27. #include "gspca.h"
  28. #define OV534_REG_ADDRESS 0xf1 /* sensor address */
  29. #define OV534_REG_SUBADDR 0xf2
  30. #define OV534_REG_WRITE 0xf3
  31. #define OV534_REG_READ 0xf4
  32. #define OV534_REG_OPERATION 0xf5
  33. #define OV534_REG_STATUS 0xf6
  34. #define OV534_OP_WRITE_3 0x37
  35. #define OV534_OP_WRITE_2 0x33
  36. #define OV534_OP_READ_2 0xf9
  37. #define CTRL_TIMEOUT 500
  38. MODULE_AUTHOR("Jean-Francois Moine <moinejf@free.fr>");
  39. MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver");
  40. MODULE_LICENSE("GPL");
  41. /* specific webcam descriptor */
  42. struct sd {
  43. struct gspca_dev gspca_dev; /* !! must be the first item */
  44. __u32 last_pts;
  45. u8 last_fid;
  46. u8 brightness;
  47. u8 contrast;
  48. u8 autogain;
  49. u8 exposure;
  50. s8 sharpness;
  51. u8 satur;
  52. u8 freq;
  53. };
  54. /* V4L2 controls supported by the driver */
  55. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  56. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  57. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  58. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  59. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  60. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  61. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  62. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  63. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  64. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  65. static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val);
  66. static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val);
  67. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  68. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  69. static const struct ctrl sd_ctrls[] = {
  70. { /* 0 */
  71. {
  72. .id = V4L2_CID_BRIGHTNESS,
  73. .type = V4L2_CTRL_TYPE_INTEGER,
  74. .name = "Brightness",
  75. .minimum = 0,
  76. .maximum = 15,
  77. .step = 1,
  78. #define BRIGHTNESS_DEF 7
  79. .default_value = BRIGHTNESS_DEF,
  80. },
  81. .set = sd_setbrightness,
  82. .get = sd_getbrightness,
  83. },
  84. { /* 1 */
  85. {
  86. .id = V4L2_CID_CONTRAST,
  87. .type = V4L2_CTRL_TYPE_INTEGER,
  88. .name = "Contrast",
  89. .minimum = 0,
  90. .maximum = 15,
  91. .step = 1,
  92. #define CONTRAST_DEF 3
  93. .default_value = CONTRAST_DEF,
  94. },
  95. .set = sd_setcontrast,
  96. .get = sd_getcontrast,
  97. },
  98. { /* 2 */
  99. {
  100. .id = V4L2_CID_AUTOGAIN,
  101. .type = V4L2_CTRL_TYPE_BOOLEAN,
  102. .name = "Autogain",
  103. .minimum = 0,
  104. .maximum = 1,
  105. .step = 1,
  106. #define AUTOGAIN_DEF 1
  107. .default_value = AUTOGAIN_DEF,
  108. },
  109. .set = sd_setautogain,
  110. .get = sd_getautogain,
  111. },
  112. #define EXPO_IDX 3
  113. { /* 3 */
  114. {
  115. .id = V4L2_CID_EXPOSURE,
  116. .type = V4L2_CTRL_TYPE_INTEGER,
  117. .name = "Exposure",
  118. .minimum = 0,
  119. .maximum = 3,
  120. .step = 1,
  121. #define EXPO_DEF 0
  122. .default_value = EXPO_DEF,
  123. },
  124. .set = sd_setexposure,
  125. .get = sd_getexposure,
  126. },
  127. { /* 4 */
  128. {
  129. .id = V4L2_CID_SHARPNESS,
  130. .type = V4L2_CTRL_TYPE_INTEGER,
  131. .name = "Sharpness",
  132. .minimum = -1, /* -1 = auto */
  133. .maximum = 4,
  134. .step = 1,
  135. #define SHARPNESS_DEF -1
  136. .default_value = SHARPNESS_DEF,
  137. },
  138. .set = sd_setsharpness,
  139. .get = sd_getsharpness,
  140. },
  141. { /* 5 */
  142. {
  143. .id = V4L2_CID_SATURATION,
  144. .type = V4L2_CTRL_TYPE_INTEGER,
  145. .name = "Saturation",
  146. .minimum = 0,
  147. .maximum = 4,
  148. .step = 1,
  149. #define SATUR_DEF 2
  150. .default_value = SATUR_DEF,
  151. },
  152. .set = sd_setsatur,
  153. .get = sd_getsatur,
  154. },
  155. {
  156. {
  157. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  158. .type = V4L2_CTRL_TYPE_MENU,
  159. .name = "Light frequency filter",
  160. .minimum = 0,
  161. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  162. .step = 1,
  163. #define FREQ_DEF 0
  164. .default_value = FREQ_DEF,
  165. },
  166. .set = sd_setfreq,
  167. .get = sd_getfreq,
  168. },
  169. };
  170. static const struct v4l2_pix_format ov965x_mode[] = {
  171. #define QVGA_MODE 0
  172. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  173. .bytesperline = 320,
  174. .sizeimage = 320 * 240 * 3 / 8 + 590,
  175. .colorspace = V4L2_COLORSPACE_JPEG},
  176. #define VGA_MODE 1
  177. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  178. .bytesperline = 640,
  179. .sizeimage = 640 * 480 * 3 / 8 + 590,
  180. .colorspace = V4L2_COLORSPACE_JPEG},
  181. #define SVGA_MODE 2
  182. {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  183. .bytesperline = 800,
  184. .sizeimage = 800 * 600 * 3 / 8 + 590,
  185. .colorspace = V4L2_COLORSPACE_JPEG},
  186. #define XGA_MODE 3
  187. {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  188. .bytesperline = 1024,
  189. .sizeimage = 1024 * 768 * 3 / 8 + 590,
  190. .colorspace = V4L2_COLORSPACE_JPEG},
  191. #define SXGA_MODE 4
  192. {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  193. .bytesperline = 1280,
  194. .sizeimage = 1280 * 1024 * 3 / 8 + 590,
  195. .colorspace = V4L2_COLORSPACE_JPEG},
  196. };
  197. static const u8 bridge_init[][2] = {
  198. {0x88, 0xf8},
  199. {0x89, 0xff},
  200. {0x76, 0x03},
  201. {0x92, 0x03},
  202. {0x95, 0x10},
  203. {0xe2, 0x00},
  204. {0xe7, 0x3e},
  205. {0x8d, 0x1c},
  206. {0x8e, 0x00},
  207. {0x8f, 0x00},
  208. {0x1f, 0x00},
  209. {0xc3, 0xf9},
  210. {0x89, 0xff},
  211. {0x88, 0xf8},
  212. {0x76, 0x03},
  213. {0x92, 0x01},
  214. {0x93, 0x18},
  215. {0x1c, 0x0a},
  216. {0x1d, 0x48},
  217. {0xc0, 0x50},
  218. {0xc1, 0x3c},
  219. {0x34, 0x05},
  220. {0xc2, 0x0c},
  221. {0xc3, 0xf9},
  222. {0x34, 0x05},
  223. {0xe7, 0x2e},
  224. {0x31, 0xf9},
  225. {0x35, 0x02},
  226. {0xd9, 0x10},
  227. {0x25, 0x42},
  228. {0x94, 0x11},
  229. };
  230. static const u8 sensor_init[][2] = {
  231. {0x12, 0x80}, /* com7 - SSCB reset */
  232. {0x00, 0x00}, /* gain */
  233. {0x01, 0x80}, /* blue */
  234. {0x02, 0x80}, /* red */
  235. {0x03, 0x1b}, /* vref */
  236. {0x04, 0x03}, /* com1 - exposure low bits */
  237. {0x0b, 0x57}, /* ver */
  238. {0x0e, 0x61}, /* com5 */
  239. {0x0f, 0x42}, /* com6 */
  240. {0x11, 0x00}, /* clkrc */
  241. {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
  242. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  243. {0x14, 0x28}, /* com9 */
  244. {0x16, 0x24}, /* reg16 */
  245. {0x17, 0x1d}, /* hstart*/
  246. {0x18, 0xbd}, /* hstop */
  247. {0x19, 0x01}, /* vstrt */
  248. {0x1a, 0x81}, /* vstop*/
  249. {0x1e, 0x04}, /* mvfp */
  250. {0x24, 0x3c}, /* aew */
  251. {0x25, 0x36}, /* aeb */
  252. {0x26, 0x71}, /* vpt */
  253. {0x27, 0x08}, /* bbias */
  254. {0x28, 0x08}, /* gbbias */
  255. {0x29, 0x15}, /* gr com */
  256. {0x2a, 0x00}, /* exhch */
  257. {0x2b, 0x00}, /* exhcl */
  258. {0x2c, 0x08}, /* rbias */
  259. {0x32, 0xff}, /* href */
  260. {0x33, 0x00}, /* chlf */
  261. {0x34, 0x3f}, /* aref1 */
  262. {0x35, 0x00}, /* aref2 */
  263. {0x36, 0xf8}, /* aref3 */
  264. {0x38, 0x72}, /* adc2 */
  265. {0x39, 0x57}, /* aref4 */
  266. {0x3a, 0x80}, /* tslb - yuyv */
  267. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  268. {0x3d, 0x99}, /* com13 */
  269. {0x3f, 0xc1}, /* edge */
  270. {0x40, 0xc0}, /* com15 */
  271. {0x41, 0x40}, /* com16 */
  272. {0x42, 0xc0}, /* com17 */
  273. {0x43, 0x0a}, /* rsvd */
  274. {0x44, 0xf0},
  275. {0x45, 0x46},
  276. {0x46, 0x62},
  277. {0x47, 0x2a},
  278. {0x48, 0x3c},
  279. {0x4a, 0xfc},
  280. {0x4b, 0xfc},
  281. {0x4c, 0x7f},
  282. {0x4d, 0x7f},
  283. {0x4e, 0x7f},
  284. {0x4f, 0x98}, /* matrix */
  285. {0x50, 0x98},
  286. {0x51, 0x00},
  287. {0x52, 0x28},
  288. {0x53, 0x70},
  289. {0x54, 0x98},
  290. {0x58, 0x1a}, /* matrix coef sign */
  291. {0x59, 0x85}, /* AWB control */
  292. {0x5a, 0xa9},
  293. {0x5b, 0x64},
  294. {0x5c, 0x84},
  295. {0x5d, 0x53},
  296. {0x5e, 0x0e},
  297. {0x5f, 0xf0}, /* AWB blue limit */
  298. {0x60, 0xf0}, /* AWB red limit */
  299. {0x61, 0xf0}, /* AWB green limit */
  300. {0x62, 0x00}, /* lcc1 */
  301. {0x63, 0x00}, /* lcc2 */
  302. {0x64, 0x02}, /* lcc3 */
  303. {0x65, 0x16}, /* lcc4 */
  304. {0x66, 0x01}, /* lcc5 */
  305. {0x69, 0x02}, /* hv */
  306. {0x6b, 0x5a}, /* dbvl */
  307. {0x6c, 0x04},
  308. {0x6d, 0x55},
  309. {0x6e, 0x00},
  310. {0x6f, 0x9d},
  311. {0x70, 0x21}, /* dnsth */
  312. {0x71, 0x78},
  313. {0x72, 0x00}, /* poidx */
  314. {0x73, 0x01}, /* pckdv */
  315. {0x74, 0x3a}, /* xindx */
  316. {0x75, 0x35}, /* yindx */
  317. {0x76, 0x01},
  318. {0x77, 0x02},
  319. {0x7a, 0x12}, /* gamma curve */
  320. {0x7b, 0x08},
  321. {0x7c, 0x16},
  322. {0x7d, 0x30},
  323. {0x7e, 0x5e},
  324. {0x7f, 0x72},
  325. {0x80, 0x82},
  326. {0x81, 0x8e},
  327. {0x82, 0x9a},
  328. {0x83, 0xa4},
  329. {0x84, 0xac},
  330. {0x85, 0xb8},
  331. {0x86, 0xc3},
  332. {0x87, 0xd6},
  333. {0x88, 0xe6},
  334. {0x89, 0xf2},
  335. {0x8a, 0x03},
  336. {0x8c, 0x89}, /* com19 */
  337. {0x14, 0x28}, /* com9 */
  338. {0x90, 0x7d},
  339. {0x91, 0x7b},
  340. {0x9d, 0x03}, /* lcc6 */
  341. {0x9e, 0x04}, /* lcc7 */
  342. {0x9f, 0x7a},
  343. {0xa0, 0x79},
  344. {0xa1, 0x40}, /* aechm */
  345. {0xa4, 0x50}, /* com21 */
  346. {0xa5, 0x68}, /* com26 */
  347. {0xa6, 0x4a}, /* AWB green */
  348. {0xa8, 0xc1}, /* refa8 */
  349. {0xa9, 0xef}, /* refa9 */
  350. {0xaa, 0x92},
  351. {0xab, 0x04},
  352. {0xac, 0x80}, /* black level control */
  353. {0xad, 0x80},
  354. {0xae, 0x80},
  355. {0xaf, 0x80},
  356. {0xb2, 0xf2},
  357. {0xb3, 0x20},
  358. {0xb4, 0x20}, /* ctrlb4 */
  359. {0xb5, 0x00},
  360. {0xb6, 0xaf},
  361. {0xbb, 0xae},
  362. {0xbc, 0x7f}, /* ADC channel offsets */
  363. {0xdb, 0x7f},
  364. {0xbe, 0x7f},
  365. {0xbf, 0x7f},
  366. {0xc0, 0xe2},
  367. {0xc1, 0xc0},
  368. {0xc2, 0x01},
  369. {0xc3, 0x4e},
  370. {0xc6, 0x85},
  371. {0xc7, 0x80}, /* com24 */
  372. {0xc9, 0xe0},
  373. {0xca, 0xe8},
  374. {0xcb, 0xf0},
  375. {0xcc, 0xd8},
  376. {0xcd, 0xf1},
  377. {0x4f, 0x98}, /* matrix */
  378. {0x50, 0x98},
  379. {0x51, 0x00},
  380. {0x52, 0x28},
  381. {0x53, 0x70},
  382. {0x54, 0x98},
  383. {0x58, 0x1a},
  384. {0xff, 0x41}, /* read 41, write ff 00 */
  385. {0x41, 0x40}, /* com16 */
  386. {0xc5, 0x03}, /* 60 Hz banding filter */
  387. {0x6a, 0x02}, /* 50 Hz banding filter */
  388. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  389. {0x36, 0xfa}, /* aref3 */
  390. {0x69, 0x0a}, /* hv */
  391. {0x8c, 0x89}, /* com22 */
  392. {0x14, 0x28}, /* com9 */
  393. {0x3e, 0x0c},
  394. {0x41, 0x40}, /* com16 */
  395. {0x72, 0x00},
  396. {0x73, 0x00},
  397. {0x74, 0x3a},
  398. {0x75, 0x35},
  399. {0x76, 0x01},
  400. {0xc7, 0x80},
  401. {0x03, 0x12}, /* vref */
  402. {0x17, 0x16}, /* hstart */
  403. {0x18, 0x02}, /* hstop */
  404. {0x19, 0x01}, /* vstrt */
  405. {0x1a, 0x3d}, /* vstop */
  406. {0x32, 0xff}, /* href */
  407. {0xc0, 0xaa},
  408. };
  409. static const u8 bridge_init_2[][2] = {
  410. {0x94, 0xaa},
  411. {0xf1, 0x60},
  412. {0xe5, 0x04},
  413. {0xc0, 0x50},
  414. {0xc1, 0x3c},
  415. {0x8c, 0x00},
  416. {0x8d, 0x1c},
  417. {0x34, 0x05},
  418. {0xc2, 0x0c},
  419. {0xc3, 0xf9},
  420. {0xda, 0x01},
  421. {0x50, 0x00},
  422. {0x51, 0xa0},
  423. {0x52, 0x3c},
  424. {0x53, 0x00},
  425. {0x54, 0x00},
  426. {0x55, 0x00},
  427. {0x57, 0x00},
  428. {0x5c, 0x00},
  429. {0x5a, 0xa0},
  430. {0x5b, 0x78},
  431. {0x35, 0x02},
  432. {0xd9, 0x10},
  433. {0x94, 0x11},
  434. };
  435. static const u8 sensor_init_2[][2] = {
  436. {0x3b, 0xc4},
  437. {0x1e, 0x04}, /* mvfp */
  438. {0x13, 0xe0}, /* com8 */
  439. {0x00, 0x00}, /* gain */
  440. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  441. {0x11, 0x03}, /* clkrc */
  442. {0x6b, 0x5a}, /* dblv */
  443. {0x6a, 0x05},
  444. {0xc5, 0x07},
  445. {0xa2, 0x4b},
  446. {0xa3, 0x3e},
  447. {0x2d, 0x00},
  448. {0xff, 0x42}, /* read 42, write ff 00 */
  449. {0x42, 0xc0}, /* com17 */
  450. {0x2d, 0x00},
  451. {0xff, 0x42}, /* read 42, write ff 00 */
  452. {0x42, 0xc1}, /* com17 */
  453. /* sharpness */
  454. {0x3f, 0x01},
  455. {0xff, 0x42}, /* read 42, write ff 00 */
  456. {0x42, 0xc1}, /* com17 */
  457. /* saturation */
  458. {0x4f, 0x98}, /* matrix */
  459. {0x50, 0x98},
  460. {0x51, 0x00},
  461. {0x52, 0x28},
  462. {0x53, 0x70},
  463. {0x54, 0x98},
  464. {0x58, 0x1a},
  465. {0xff, 0x41}, /* read 41, write ff 00 */
  466. {0x41, 0x40}, /* com16 */
  467. /* contrast */
  468. {0x56, 0x40},
  469. /* brightness */
  470. {0x55, 0x8f},
  471. /* expo */
  472. {0x10, 0x25}, /* aech - exposure high bits */
  473. {0xff, 0x13}, /* read 13, write ff 00 */
  474. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  475. };
  476. static const u8 sensor_start_1_vga[][2] = { /* same for qvga */
  477. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  478. {0x36, 0xfa}, /* aref3 */
  479. {0x69, 0x0a}, /* hv */
  480. {0x8c, 0x89}, /* com22 */
  481. {0x14, 0x28}, /* com9 */
  482. {0x3e, 0x0c}, /* com14 */
  483. {0x41, 0x40}, /* com16 */
  484. {0x72, 0x00},
  485. {0x73, 0x00},
  486. {0x74, 0x3a},
  487. {0x75, 0x35},
  488. {0x76, 0x01},
  489. {0xc7, 0x80}, /* com24 */
  490. {0x03, 0x12}, /* vref */
  491. {0x17, 0x16}, /* hstart */
  492. {0x18, 0x02}, /* hstop */
  493. {0x19, 0x01}, /* vstrt */
  494. {0x1a, 0x3d}, /* vstop */
  495. {0x32, 0xff}, /* href */
  496. {0xc0, 0xaa},
  497. };
  498. static const u8 sensor_start_1_svga[][2] = {
  499. {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
  500. {0x36, 0xf8}, /* aref3 */
  501. {0x69, 0x02}, /* hv */
  502. {0x8c, 0x0d}, /* com22 */
  503. {0x3e, 0x0c}, /* com14 */
  504. {0x41, 0x40}, /* com16 */
  505. {0x72, 0x00},
  506. {0x73, 0x01},
  507. {0x74, 0x3a},
  508. {0x75, 0x35},
  509. {0x76, 0x01},
  510. {0xc7, 0x80}, /* com24 */
  511. {0x03, 0x1b}, /* vref */
  512. {0x17, 0x1d}, /* hstart */
  513. {0x18, 0xbd}, /* hstop */
  514. {0x19, 0x01}, /* vstrt */
  515. {0x1a, 0x81}, /* vstop */
  516. {0x32, 0xff}, /* href */
  517. {0xc0, 0xe2},
  518. };
  519. static const u8 sensor_start_1_xga[][2] = {
  520. {0x12, 0x02}, /* com7 */
  521. {0x36, 0xf8}, /* aref3 */
  522. {0x69, 0x02}, /* hv */
  523. {0x8c, 0x89}, /* com22 */
  524. {0x14, 0x28}, /* com9 */
  525. {0x3e, 0x0c}, /* com14 */
  526. {0x41, 0x40}, /* com16 */
  527. {0x72, 0x00},
  528. {0x73, 0x01},
  529. {0x74, 0x3a},
  530. {0x75, 0x35},
  531. {0x76, 0x01},
  532. {0xc7, 0x80}, /* com24 */
  533. {0x03, 0x1b}, /* vref */
  534. {0x17, 0x1d}, /* hstart */
  535. {0x18, 0xbd}, /* hstop */
  536. {0x19, 0x01}, /* vstrt */
  537. {0x1a, 0x81}, /* vstop */
  538. {0x32, 0xff}, /* href */
  539. {0xc0, 0xe2},
  540. };
  541. static const u8 sensor_start_1_sxga[][2] = {
  542. {0x12, 0x02}, /* com7 */
  543. {0x36, 0xf8}, /* aref3 */
  544. {0x69, 0x02}, /* hv */
  545. {0x8c, 0x89}, /* com22 */
  546. {0x14, 0x28}, /* com9 */
  547. {0x3e, 0x0c}, /* com14 */
  548. {0x41, 0x40}, /* com16 */
  549. {0x72, 0x00},
  550. {0x73, 0x01},
  551. {0x74, 0x3a},
  552. {0x75, 0x35},
  553. {0x76, 0x01},
  554. {0xc7, 0x80}, /* com24 */
  555. {0x03, 0x1b}, /* vref */
  556. {0x17, 0x1d}, /* hstart */
  557. {0x18, 0x02}, /* hstop */
  558. {0x19, 0x01}, /* vstrt */
  559. {0x1a, 0x81}, /* vstop */
  560. {0x32, 0xff}, /* href */
  561. {0xc0, 0xe2},
  562. };
  563. static const u8 bridge_start_qvga[][2] = {
  564. {0x94, 0xaa},
  565. {0xf1, 0x60},
  566. {0xe5, 0x04},
  567. {0xc0, 0x50},
  568. {0xc1, 0x3c},
  569. {0x8c, 0x00},
  570. {0x8d, 0x1c},
  571. {0x34, 0x05},
  572. {0xc2, 0x4c},
  573. {0xc3, 0xf9},
  574. {0xda, 0x00},
  575. {0x50, 0x00},
  576. {0x51, 0xa0},
  577. {0x52, 0x78},
  578. {0x53, 0x00},
  579. {0x54, 0x00},
  580. {0x55, 0x00},
  581. {0x57, 0x00},
  582. {0x5c, 0x00},
  583. {0x5a, 0x50},
  584. {0x5b, 0x3c},
  585. {0x35, 0x02},
  586. {0xd9, 0x10},
  587. {0x94, 0x11},
  588. };
  589. static const u8 bridge_start_vga[][2] = {
  590. {0x94, 0xaa},
  591. {0xf1, 0x60},
  592. {0xe5, 0x04},
  593. {0xc0, 0x50},
  594. {0xc1, 0x3c},
  595. {0x8c, 0x00},
  596. {0x8d, 0x1c},
  597. {0x34, 0x05},
  598. {0xc2, 0x0c},
  599. {0xc3, 0xf9},
  600. {0xda, 0x01},
  601. {0x50, 0x00},
  602. {0x51, 0xa0},
  603. {0x52, 0x3c},
  604. {0x53, 0x00},
  605. {0x54, 0x00},
  606. {0x55, 0x00},
  607. {0x57, 0x00},
  608. {0x5c, 0x00},
  609. {0x5a, 0xa0},
  610. {0x5b, 0x78},
  611. {0x35, 0x02},
  612. {0xd9, 0x10},
  613. {0x94, 0x11},
  614. };
  615. static const u8 bridge_start_svga[][2] = {
  616. {0x94, 0xaa},
  617. {0xf1, 0x60},
  618. {0xe5, 0x04},
  619. {0xc0, 0xa0},
  620. {0xc1, 0x80},
  621. {0x8c, 0x00},
  622. {0x8d, 0x1c},
  623. {0x34, 0x05},
  624. {0xc2, 0x4c},
  625. {0xc3, 0xf9},
  626. {0x50, 0x00},
  627. {0x51, 0x40},
  628. {0x52, 0x00},
  629. {0x53, 0x00},
  630. {0x54, 0x00},
  631. {0x55, 0x88},
  632. {0x57, 0x00},
  633. {0x5c, 0x00},
  634. {0x5a, 0xc8},
  635. {0x5b, 0x96},
  636. {0x35, 0x02},
  637. {0xd9, 0x10},
  638. {0xda, 0x00},
  639. {0x94, 0x11},
  640. };
  641. static const u8 bridge_start_xga[][2] = {
  642. {0x94, 0xaa},
  643. {0xf1, 0x60},
  644. {0xe5, 0x04},
  645. {0xc0, 0xa0},
  646. {0xc1, 0x80},
  647. {0x8c, 0x00},
  648. {0x8d, 0x1c},
  649. {0x34, 0x05},
  650. {0xc2, 0x4c},
  651. {0xc3, 0xf9},
  652. {0x50, 0x00},
  653. {0x51, 0x40},
  654. {0x52, 0x00},
  655. {0x53, 0x00},
  656. {0x54, 0x00},
  657. {0x55, 0x88},
  658. {0x57, 0x00},
  659. {0x5c, 0x01},
  660. {0x5a, 0x00},
  661. {0x5b, 0xc0},
  662. {0x35, 0x02},
  663. {0xd9, 0x10},
  664. {0xda, 0x01},
  665. {0x94, 0x11},
  666. };
  667. static const u8 bridge_start_sxga[][2] = {
  668. {0x94, 0xaa},
  669. {0xf1, 0x60},
  670. {0xe5, 0x04},
  671. {0xc0, 0xa0},
  672. {0xc1, 0x80},
  673. {0x8c, 0x00},
  674. {0x8d, 0x1c},
  675. {0x34, 0x05},
  676. {0xc2, 0x0c},
  677. {0xc3, 0xf9},
  678. {0xda, 0x00},
  679. {0x35, 0x02},
  680. {0xd9, 0x10},
  681. {0x94, 0x11},
  682. };
  683. static const u8 sensor_start_2_qvga[][2] = {
  684. {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
  685. {0x1e, 0x04}, /* mvfp */
  686. {0x13, 0xe0}, /* com8 */
  687. {0x00, 0x00},
  688. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  689. {0x11, 0x01}, /* clkrc */
  690. {0x6b, 0x5a}, /* dblv */
  691. {0x6a, 0x02}, /* 50 Hz banding filter */
  692. {0xc5, 0x03}, /* 60 Hz banding filter */
  693. {0xa2, 0x96}, /* bd50 */
  694. {0xa3, 0x7d}, /* bd60 */
  695. {0xff, 0x13}, /* read 13, write ff 00 */
  696. {0x13, 0xe7},
  697. {0x3a, 0x80}, /* tslb - yuyv */
  698. };
  699. static const u8 sensor_start_2_vga[][2] = {
  700. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  701. {0x1e, 0x04}, /* mvfp */
  702. {0x13, 0xe0}, /* com8 */
  703. {0x00, 0x00},
  704. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  705. {0x11, 0x03}, /* clkrc */
  706. {0x6b, 0x5a}, /* dblv */
  707. {0x6a, 0x05}, /* 50 Hz banding filter */
  708. {0xc5, 0x07}, /* 60 Hz banding filter */
  709. {0xa2, 0x4b}, /* bd50 */
  710. {0xa3, 0x3e}, /* bd60 */
  711. {0x2d, 0x00}, /* advfl */
  712. };
  713. static const u8 sensor_start_2_svga[][2] = { /* same for xga */
  714. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  715. {0x1e, 0x04}, /* mvfp */
  716. {0x13, 0xe0}, /* com8 */
  717. {0x00, 0x00},
  718. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  719. {0x11, 0x01}, /* clkrc */
  720. {0x6b, 0x5a}, /* dblv */
  721. {0x6a, 0x0c}, /* 50 Hz banding filter */
  722. {0xc5, 0x0f}, /* 60 Hz banding filter */
  723. {0xa2, 0x4e}, /* bd50 */
  724. {0xa3, 0x41}, /* bd60 */
  725. };
  726. static const u8 sensor_start_2_sxga[][2] = {
  727. {0x13, 0xe0}, /* com8 */
  728. {0x00, 0x00},
  729. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  730. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  731. {0x1e, 0x04}, /* mvfp */
  732. {0x11, 0x01}, /* clkrc */
  733. {0x6b, 0x5a}, /* dblv */
  734. {0x6a, 0x0c}, /* 50 Hz banding filter */
  735. {0xc5, 0x0f}, /* 60 Hz banding filter */
  736. {0xa2, 0x4e}, /* bd50 */
  737. {0xa3, 0x41}, /* bd60 */
  738. };
  739. static void reg_w_i(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  740. {
  741. struct usb_device *udev = gspca_dev->dev;
  742. int ret;
  743. if (gspca_dev->usb_err < 0)
  744. return;
  745. gspca_dev->usb_buf[0] = val;
  746. ret = usb_control_msg(udev,
  747. usb_sndctrlpipe(udev, 0),
  748. 0x01,
  749. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  750. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  751. if (ret < 0) {
  752. PDEBUG(D_ERR, "reg_w failed %d", ret);
  753. gspca_dev->usb_err = ret;
  754. }
  755. }
  756. static void reg_w(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  757. {
  758. PDEBUG(D_USBO, "reg_w [%04x] = %02x", reg, val);
  759. reg_w_i(gspca_dev, reg, val);
  760. }
  761. static u8 reg_r(struct gspca_dev *gspca_dev, u16 reg)
  762. {
  763. struct usb_device *udev = gspca_dev->dev;
  764. int ret;
  765. if (gspca_dev->usb_err < 0)
  766. return 0;
  767. ret = usb_control_msg(udev,
  768. usb_rcvctrlpipe(udev, 0),
  769. 0x01,
  770. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  771. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  772. PDEBUG(D_USBI, "reg_r [%04x] -> %02x", reg, gspca_dev->usb_buf[0]);
  773. if (ret < 0) {
  774. PDEBUG(D_ERR, "reg_r err %d", ret);
  775. gspca_dev->usb_err = ret;
  776. }
  777. return gspca_dev->usb_buf[0];
  778. }
  779. static int sccb_check_status(struct gspca_dev *gspca_dev)
  780. {
  781. u8 data;
  782. int i;
  783. for (i = 0; i < 5; i++) {
  784. data = reg_r(gspca_dev, OV534_REG_STATUS);
  785. switch (data) {
  786. case 0x00:
  787. return 1;
  788. case 0x04:
  789. return 0;
  790. case 0x03:
  791. break;
  792. default:
  793. PDEBUG(D_USBI|D_USBO,
  794. "sccb status 0x%02x, attempt %d/5",
  795. data, i + 1);
  796. }
  797. }
  798. return 0;
  799. }
  800. static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  801. {
  802. PDEBUG(D_USBO, "sccb_write [%02x] = %02x", reg, val);
  803. reg_w_i(gspca_dev, OV534_REG_SUBADDR, reg);
  804. reg_w_i(gspca_dev, OV534_REG_WRITE, val);
  805. reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  806. if (!sccb_check_status(gspca_dev))
  807. PDEBUG(D_ERR, "sccb_write failed");
  808. }
  809. static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
  810. {
  811. reg_w(gspca_dev, OV534_REG_SUBADDR, reg);
  812. reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  813. if (!sccb_check_status(gspca_dev))
  814. PDEBUG(D_ERR, "sccb_read failed 1");
  815. reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  816. if (!sccb_check_status(gspca_dev))
  817. PDEBUG(D_ERR, "sccb_read failed 2");
  818. return reg_r(gspca_dev, OV534_REG_READ);
  819. }
  820. /* output a bridge sequence (reg - val) */
  821. static void reg_w_array(struct gspca_dev *gspca_dev,
  822. const u8 (*data)[2], int len)
  823. {
  824. while (--len >= 0) {
  825. reg_w(gspca_dev, (*data)[0], (*data)[1]);
  826. data++;
  827. }
  828. }
  829. /* output a sensor sequence (reg - val) */
  830. static void sccb_w_array(struct gspca_dev *gspca_dev,
  831. const u8 (*data)[2], int len)
  832. {
  833. while (--len >= 0) {
  834. if ((*data)[0] != 0xff) {
  835. sccb_write(gspca_dev, (*data)[0], (*data)[1]);
  836. } else {
  837. sccb_read(gspca_dev, (*data)[1]);
  838. sccb_write(gspca_dev, 0xff, 0x00);
  839. }
  840. data++;
  841. }
  842. }
  843. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  844. * (direction and output)? */
  845. static void set_led(struct gspca_dev *gspca_dev, int status)
  846. {
  847. u8 data;
  848. PDEBUG(D_CONF, "led status: %d", status);
  849. data = reg_r(gspca_dev, 0x21);
  850. data |= 0x80;
  851. reg_w(gspca_dev, 0x21, data);
  852. data = reg_r(gspca_dev, 0x23);
  853. if (status)
  854. data |= 0x80;
  855. else
  856. data &= ~0x80;
  857. reg_w(gspca_dev, 0x23, data);
  858. if (!status) {
  859. data = reg_r(gspca_dev, 0x21);
  860. data &= ~0x80;
  861. reg_w(gspca_dev, 0x21, data);
  862. }
  863. }
  864. static void setbrightness(struct gspca_dev *gspca_dev)
  865. {
  866. struct sd *sd = (struct sd *) gspca_dev;
  867. u8 val;
  868. val = sd->brightness;
  869. if (val < 8)
  870. val = 15 - val; /* f .. 8 */
  871. else
  872. val = val - 8; /* 0 .. 7 */
  873. sccb_write(gspca_dev, 0x55, /* brtn - brightness adjustment */
  874. 0x0f | (val << 4));
  875. }
  876. static void setcontrast(struct gspca_dev *gspca_dev)
  877. {
  878. struct sd *sd = (struct sd *) gspca_dev;
  879. sccb_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */
  880. sd->contrast << 4);
  881. }
  882. static void setautogain(struct gspca_dev *gspca_dev)
  883. {
  884. struct sd *sd = (struct sd *) gspca_dev;
  885. u8 val;
  886. /*fixme: should adjust agc/awb/aec by different controls */
  887. val = sd->autogain;
  888. val = sccb_read(gspca_dev, 0x13); /* com8 */
  889. sccb_write(gspca_dev, 0xff, 0x00);
  890. if (sd->autogain)
  891. val |= 0x05; /* agc & aec */
  892. else
  893. val &= 0xfa;
  894. sccb_write(gspca_dev, 0x13, val);
  895. }
  896. static void setexposure(struct gspca_dev *gspca_dev)
  897. {
  898. struct sd *sd = (struct sd *) gspca_dev;
  899. u8 val;
  900. static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
  901. sccb_write(gspca_dev, 0x10, /* aec[9:2] */
  902. expo[sd->exposure]);
  903. val = sccb_read(gspca_dev, 0x13); /* com8 */
  904. sccb_write(gspca_dev, 0xff, 0x00);
  905. sccb_write(gspca_dev, 0x13, val);
  906. val = sccb_read(gspca_dev, 0xa1); /* aech */
  907. sccb_write(gspca_dev, 0xff, 0x00);
  908. sccb_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */
  909. }
  910. static void setsharpness(struct gspca_dev *gspca_dev)
  911. {
  912. struct sd *sd = (struct sd *) gspca_dev;
  913. s8 val;
  914. val = sd->sharpness;
  915. if (val < 0) { /* auto */
  916. val = sccb_read(gspca_dev, 0x42); /* com17 */
  917. sccb_write(gspca_dev, 0xff, 0x00);
  918. sccb_write(gspca_dev, 0x42, val | 0x40);
  919. /* Edge enhancement strength auto adjust */
  920. return;
  921. }
  922. if (val != 0)
  923. val = 1 << (val - 1);
  924. sccb_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */
  925. val);
  926. val = sccb_read(gspca_dev, 0x42); /* com17 */
  927. sccb_write(gspca_dev, 0xff, 0x00);
  928. sccb_write(gspca_dev, 0x42, val & 0xbf);
  929. }
  930. static void setsatur(struct gspca_dev *gspca_dev)
  931. {
  932. struct sd *sd = (struct sd *) gspca_dev;
  933. u8 val1, val2, val3;
  934. static const u8 matrix[5][2] = {
  935. {0x14, 0x38},
  936. {0x1e, 0x54},
  937. {0x28, 0x70},
  938. {0x32, 0x8c},
  939. {0x48, 0x90}
  940. };
  941. val1 = matrix[sd->satur][0];
  942. val2 = matrix[sd->satur][1];
  943. val3 = val1 + val2;
  944. sccb_write(gspca_dev, 0x4f, val3); /* matrix coeff */
  945. sccb_write(gspca_dev, 0x50, val3);
  946. sccb_write(gspca_dev, 0x51, 0x00);
  947. sccb_write(gspca_dev, 0x52, val1);
  948. sccb_write(gspca_dev, 0x53, val2);
  949. sccb_write(gspca_dev, 0x54, val3);
  950. sccb_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */
  951. val1 = sccb_read(gspca_dev, 0x41); /* com16 */
  952. sccb_write(gspca_dev, 0xff, 0x00);
  953. sccb_write(gspca_dev, 0x41, val1);
  954. }
  955. static void setfreq(struct gspca_dev *gspca_dev)
  956. {
  957. struct sd *sd = (struct sd *) gspca_dev;
  958. u8 val;
  959. val = sccb_read(gspca_dev, 0x13); /* com8 */
  960. sccb_write(gspca_dev, 0xff, 0x00);
  961. if (sd->freq == 0) {
  962. sccb_write(gspca_dev, 0x13, val & 0xdf);
  963. return;
  964. }
  965. sccb_write(gspca_dev, 0x13, val | 0x20);
  966. val = sccb_read(gspca_dev, 0x42); /* com17 */
  967. sccb_write(gspca_dev, 0xff, 0x00);
  968. if (sd->freq == 1)
  969. val |= 0x01;
  970. else
  971. val &= 0xfe;
  972. sccb_write(gspca_dev, 0x42, val);
  973. }
  974. /* this function is called at probe time */
  975. static int sd_config(struct gspca_dev *gspca_dev,
  976. const struct usb_device_id *id)
  977. {
  978. struct sd *sd = (struct sd *) gspca_dev;
  979. struct cam *cam;
  980. cam = &gspca_dev->cam;
  981. cam->cam_mode = ov965x_mode;
  982. cam->nmodes = ARRAY_SIZE(ov965x_mode);
  983. sd->brightness = BRIGHTNESS_DEF;
  984. sd->contrast = CONTRAST_DEF;
  985. #if AUTOGAIN_DEF != 0
  986. sd->autogain = AUTOGAIN_DEF;
  987. gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
  988. #endif
  989. #if EXPO_DEF != 0
  990. sd->exposure = EXPO_DEF;
  991. #endif
  992. #if SHARPNESS_DEF != 0
  993. sd->sharpness = SHARPNESS_DEF;
  994. #endif
  995. sd->satur = SATUR_DEF;
  996. sd->freq = FREQ_DEF;
  997. return 0;
  998. }
  999. /* this function is called at probe and resume time */
  1000. static int sd_init(struct gspca_dev *gspca_dev)
  1001. {
  1002. u16 sensor_id;
  1003. /* reset bridge */
  1004. reg_w(gspca_dev, 0xe7, 0x3a);
  1005. reg_w(gspca_dev, 0xe0, 0x08);
  1006. msleep(100);
  1007. /* initialize the sensor address */
  1008. reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60);
  1009. /* reset sensor */
  1010. sccb_write(gspca_dev, 0x12, 0x80);
  1011. msleep(10);
  1012. /* probe the sensor */
  1013. sccb_read(gspca_dev, 0x0a);
  1014. sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
  1015. sccb_read(gspca_dev, 0x0b);
  1016. sensor_id |= sccb_read(gspca_dev, 0x0b);
  1017. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  1018. /* initialize */
  1019. reg_w_array(gspca_dev, bridge_init,
  1020. ARRAY_SIZE(bridge_init));
  1021. sccb_w_array(gspca_dev, sensor_init,
  1022. ARRAY_SIZE(sensor_init));
  1023. reg_w_array(gspca_dev, bridge_init_2,
  1024. ARRAY_SIZE(bridge_init_2));
  1025. sccb_w_array(gspca_dev, sensor_init_2,
  1026. ARRAY_SIZE(sensor_init_2));
  1027. reg_w(gspca_dev, 0xe0, 0x00);
  1028. reg_w(gspca_dev, 0xe0, 0x01);
  1029. set_led(gspca_dev, 0);
  1030. reg_w(gspca_dev, 0xe0, 0x00);
  1031. return gspca_dev->usb_err;
  1032. }
  1033. static int sd_start(struct gspca_dev *gspca_dev)
  1034. {
  1035. switch (gspca_dev->curr_mode) {
  1036. case QVGA_MODE: /* 320x240 */
  1037. sccb_w_array(gspca_dev, sensor_start_1_vga,
  1038. ARRAY_SIZE(sensor_start_1_vga));
  1039. reg_w_array(gspca_dev, bridge_start_qvga,
  1040. ARRAY_SIZE(bridge_start_qvga));
  1041. sccb_w_array(gspca_dev, sensor_start_2_qvga,
  1042. ARRAY_SIZE(sensor_start_2_qvga));
  1043. break;
  1044. case VGA_MODE: /* 640x480 */
  1045. sccb_w_array(gspca_dev, sensor_start_1_vga,
  1046. ARRAY_SIZE(sensor_start_1_vga));
  1047. reg_w_array(gspca_dev, bridge_start_vga,
  1048. ARRAY_SIZE(bridge_start_vga));
  1049. sccb_w_array(gspca_dev, sensor_start_2_vga,
  1050. ARRAY_SIZE(sensor_start_2_vga));
  1051. break;
  1052. case SVGA_MODE: /* 800x600 */
  1053. sccb_w_array(gspca_dev, sensor_start_1_svga,
  1054. ARRAY_SIZE(sensor_start_1_svga));
  1055. reg_w_array(gspca_dev, bridge_start_svga,
  1056. ARRAY_SIZE(bridge_start_svga));
  1057. sccb_w_array(gspca_dev, sensor_start_2_svga,
  1058. ARRAY_SIZE(sensor_start_2_svga));
  1059. break;
  1060. case XGA_MODE: /* 1024x768 */
  1061. sccb_w_array(gspca_dev, sensor_start_1_xga,
  1062. ARRAY_SIZE(sensor_start_1_xga));
  1063. reg_w_array(gspca_dev, bridge_start_xga,
  1064. ARRAY_SIZE(bridge_start_xga));
  1065. sccb_w_array(gspca_dev, sensor_start_2_svga,
  1066. ARRAY_SIZE(sensor_start_2_svga));
  1067. break;
  1068. default:
  1069. /* case SXGA_MODE: * 1280x1024 */
  1070. sccb_w_array(gspca_dev, sensor_start_1_sxga,
  1071. ARRAY_SIZE(sensor_start_1_sxga));
  1072. reg_w_array(gspca_dev, bridge_start_sxga,
  1073. ARRAY_SIZE(bridge_start_sxga));
  1074. sccb_w_array(gspca_dev, sensor_start_2_sxga,
  1075. ARRAY_SIZE(sensor_start_2_sxga));
  1076. break;
  1077. }
  1078. setfreq(gspca_dev);
  1079. setautogain(gspca_dev);
  1080. setbrightness(gspca_dev);
  1081. setcontrast(gspca_dev);
  1082. setexposure(gspca_dev);
  1083. setsharpness(gspca_dev);
  1084. setsatur(gspca_dev);
  1085. reg_w(gspca_dev, 0xe0, 0x00);
  1086. reg_w(gspca_dev, 0xe0, 0x00);
  1087. set_led(gspca_dev, 1);
  1088. return gspca_dev->usb_err;
  1089. }
  1090. static void sd_stopN(struct gspca_dev *gspca_dev)
  1091. {
  1092. reg_w(gspca_dev, 0xe0, 0x01);
  1093. set_led(gspca_dev, 0);
  1094. reg_w(gspca_dev, 0xe0, 0x00);
  1095. }
  1096. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1097. #define UVC_STREAM_EOH (1 << 7)
  1098. #define UVC_STREAM_ERR (1 << 6)
  1099. #define UVC_STREAM_STI (1 << 5)
  1100. #define UVC_STREAM_RES (1 << 4)
  1101. #define UVC_STREAM_SCR (1 << 3)
  1102. #define UVC_STREAM_PTS (1 << 2)
  1103. #define UVC_STREAM_EOF (1 << 1)
  1104. #define UVC_STREAM_FID (1 << 0)
  1105. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1106. u8 *data, int len)
  1107. {
  1108. struct sd *sd = (struct sd *) gspca_dev;
  1109. __u32 this_pts;
  1110. u8 this_fid;
  1111. int remaining_len = len;
  1112. do {
  1113. len = min(remaining_len, 2040);
  1114. /* Payloads are prefixed with a UVC-style header. We
  1115. consider a frame to start when the FID toggles, or the PTS
  1116. changes. A frame ends when EOF is set, and we've received
  1117. the correct number of bytes. */
  1118. /* Verify UVC header. Header length is always 12 */
  1119. if (data[0] != 12 || len < 12) {
  1120. PDEBUG(D_PACK, "bad header");
  1121. goto discard;
  1122. }
  1123. /* Check errors */
  1124. if (data[1] & UVC_STREAM_ERR) {
  1125. PDEBUG(D_PACK, "payload error");
  1126. goto discard;
  1127. }
  1128. /* Extract PTS and FID */
  1129. if (!(data[1] & UVC_STREAM_PTS)) {
  1130. PDEBUG(D_PACK, "PTS not present");
  1131. goto discard;
  1132. }
  1133. this_pts = (data[5] << 24) | (data[4] << 16)
  1134. | (data[3] << 8) | data[2];
  1135. this_fid = data[1] & UVC_STREAM_FID;
  1136. /* If PTS or FID has changed, start a new frame. */
  1137. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1138. if (gspca_dev->last_packet_type == INTER_PACKET)
  1139. gspca_frame_add(gspca_dev, LAST_PACKET,
  1140. NULL, 0);
  1141. sd->last_pts = this_pts;
  1142. sd->last_fid = this_fid;
  1143. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1144. data + 12, len - 12);
  1145. /* If this packet is marked as EOF, end the frame */
  1146. } else if (data[1] & UVC_STREAM_EOF) {
  1147. sd->last_pts = 0;
  1148. gspca_frame_add(gspca_dev, LAST_PACKET,
  1149. data + 12, len - 12);
  1150. } else {
  1151. /* Add the data from this payload */
  1152. gspca_frame_add(gspca_dev, INTER_PACKET,
  1153. data + 12, len - 12);
  1154. }
  1155. /* Done this payload */
  1156. goto scan_next;
  1157. discard:
  1158. /* Discard data until a new frame starts. */
  1159. gspca_dev->last_packet_type = DISCARD_PACKET;
  1160. scan_next:
  1161. remaining_len -= len;
  1162. data += len;
  1163. } while (remaining_len > 0);
  1164. }
  1165. /* controls */
  1166. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1167. {
  1168. struct sd *sd = (struct sd *) gspca_dev;
  1169. sd->brightness = val;
  1170. if (gspca_dev->streaming)
  1171. setbrightness(gspca_dev);
  1172. return gspca_dev->usb_err;
  1173. }
  1174. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1175. {
  1176. struct sd *sd = (struct sd *) gspca_dev;
  1177. *val = sd->brightness;
  1178. return 0;
  1179. }
  1180. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1181. {
  1182. struct sd *sd = (struct sd *) gspca_dev;
  1183. sd->contrast = val;
  1184. if (gspca_dev->streaming)
  1185. setcontrast(gspca_dev);
  1186. return gspca_dev->usb_err;
  1187. }
  1188. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1189. {
  1190. struct sd *sd = (struct sd *) gspca_dev;
  1191. *val = sd->contrast;
  1192. return 0;
  1193. }
  1194. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1195. {
  1196. struct sd *sd = (struct sd *) gspca_dev;
  1197. sd->autogain = val;
  1198. if (gspca_dev->streaming) {
  1199. if (val)
  1200. gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
  1201. else
  1202. gspca_dev->ctrl_inac &= ~(1 << EXPO_IDX);
  1203. setautogain(gspca_dev);
  1204. }
  1205. return gspca_dev->usb_err;
  1206. }
  1207. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1208. {
  1209. struct sd *sd = (struct sd *) gspca_dev;
  1210. *val = sd->autogain;
  1211. return 0;
  1212. }
  1213. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  1214. {
  1215. struct sd *sd = (struct sd *) gspca_dev;
  1216. sd->exposure = val;
  1217. if (gspca_dev->streaming)
  1218. setexposure(gspca_dev);
  1219. return gspca_dev->usb_err;
  1220. }
  1221. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  1222. {
  1223. struct sd *sd = (struct sd *) gspca_dev;
  1224. *val = sd->exposure;
  1225. return 0;
  1226. }
  1227. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1228. {
  1229. struct sd *sd = (struct sd *) gspca_dev;
  1230. sd->sharpness = val;
  1231. if (gspca_dev->streaming)
  1232. setsharpness(gspca_dev);
  1233. return gspca_dev->usb_err;
  1234. }
  1235. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1236. {
  1237. struct sd *sd = (struct sd *) gspca_dev;
  1238. *val = sd->sharpness;
  1239. return 0;
  1240. }
  1241. static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val)
  1242. {
  1243. struct sd *sd = (struct sd *) gspca_dev;
  1244. sd->satur = val;
  1245. if (gspca_dev->streaming)
  1246. setsatur(gspca_dev);
  1247. return gspca_dev->usb_err;
  1248. }
  1249. static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val)
  1250. {
  1251. struct sd *sd = (struct sd *) gspca_dev;
  1252. *val = sd->satur;
  1253. return 0;
  1254. }
  1255. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  1256. {
  1257. struct sd *sd = (struct sd *) gspca_dev;
  1258. sd->freq = val;
  1259. if (gspca_dev->streaming)
  1260. setfreq(gspca_dev);
  1261. return gspca_dev->usb_err;
  1262. }
  1263. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  1264. {
  1265. struct sd *sd = (struct sd *) gspca_dev;
  1266. *val = sd->freq;
  1267. return 0;
  1268. }
  1269. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1270. struct v4l2_querymenu *menu)
  1271. {
  1272. switch (menu->id) {
  1273. case V4L2_CID_POWER_LINE_FREQUENCY:
  1274. switch (menu->index) {
  1275. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  1276. strcpy((char *) menu->name, "NoFliker");
  1277. return 0;
  1278. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  1279. strcpy((char *) menu->name, "50 Hz");
  1280. return 0;
  1281. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  1282. strcpy((char *) menu->name, "60 Hz");
  1283. return 0;
  1284. }
  1285. break;
  1286. }
  1287. return -EINVAL;
  1288. }
  1289. /* sub-driver description */
  1290. static const struct sd_desc sd_desc = {
  1291. .name = MODULE_NAME,
  1292. .ctrls = sd_ctrls,
  1293. .nctrls = ARRAY_SIZE(sd_ctrls),
  1294. .config = sd_config,
  1295. .init = sd_init,
  1296. .start = sd_start,
  1297. .stopN = sd_stopN,
  1298. .pkt_scan = sd_pkt_scan,
  1299. .querymenu = sd_querymenu,
  1300. };
  1301. /* -- module initialisation -- */
  1302. static const __devinitdata struct usb_device_id device_table[] = {
  1303. {USB_DEVICE(0x06f8, 0x3003)},
  1304. {}
  1305. };
  1306. MODULE_DEVICE_TABLE(usb, device_table);
  1307. /* -- device connect -- */
  1308. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1309. {
  1310. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1311. THIS_MODULE);
  1312. }
  1313. static struct usb_driver sd_driver = {
  1314. .name = MODULE_NAME,
  1315. .id_table = device_table,
  1316. .probe = sd_probe,
  1317. .disconnect = gspca_disconnect,
  1318. #ifdef CONFIG_PM
  1319. .suspend = gspca_suspend,
  1320. .resume = gspca_resume,
  1321. #endif
  1322. };
  1323. /* -- module insert / remove -- */
  1324. static int __init sd_mod_init(void)
  1325. {
  1326. int ret;
  1327. ret = usb_register(&sd_driver);
  1328. if (ret < 0)
  1329. return ret;
  1330. PDEBUG(D_PROBE, "registered");
  1331. return 0;
  1332. }
  1333. static void __exit sd_mod_exit(void)
  1334. {
  1335. usb_deregister(&sd_driver);
  1336. PDEBUG(D_PROBE, "deregistered");
  1337. }
  1338. module_init(sd_mod_init);
  1339. module_exit(sd_mod_exit);