ov534_9.c 34 KB

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