ov534_9.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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. 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. 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. 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. 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. 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 = sccb_read(gspca_dev, 0x13); /* com8 */
  888. sccb_write(gspca_dev, 0xff, 0x00);
  889. if (sd->autogain)
  890. val |= 0x05; /* agc & aec */
  891. else
  892. val &= 0xfa;
  893. sccb_write(gspca_dev, 0x13, val);
  894. }
  895. static void setexposure(struct gspca_dev *gspca_dev)
  896. {
  897. struct sd *sd = (struct sd *) gspca_dev;
  898. u8 val;
  899. static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
  900. sccb_write(gspca_dev, 0x10, /* aec[9:2] */
  901. expo[sd->exposure]);
  902. val = sccb_read(gspca_dev, 0x13); /* com8 */
  903. sccb_write(gspca_dev, 0xff, 0x00);
  904. sccb_write(gspca_dev, 0x13, val);
  905. val = sccb_read(gspca_dev, 0xa1); /* aech */
  906. sccb_write(gspca_dev, 0xff, 0x00);
  907. sccb_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */
  908. }
  909. static void setsharpness(struct gspca_dev *gspca_dev)
  910. {
  911. struct sd *sd = (struct sd *) gspca_dev;
  912. s8 val;
  913. val = sd->sharpness;
  914. if (val < 0) { /* auto */
  915. val = sccb_read(gspca_dev, 0x42); /* com17 */
  916. sccb_write(gspca_dev, 0xff, 0x00);
  917. sccb_write(gspca_dev, 0x42, val | 0x40);
  918. /* Edge enhancement strength auto adjust */
  919. return;
  920. }
  921. if (val != 0)
  922. val = 1 << (val - 1);
  923. sccb_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */
  924. val);
  925. val = sccb_read(gspca_dev, 0x42); /* com17 */
  926. sccb_write(gspca_dev, 0xff, 0x00);
  927. sccb_write(gspca_dev, 0x42, val & 0xbf);
  928. }
  929. static void setsatur(struct gspca_dev *gspca_dev)
  930. {
  931. struct sd *sd = (struct sd *) gspca_dev;
  932. u8 val1, val2, val3;
  933. static const u8 matrix[5][2] = {
  934. {0x14, 0x38},
  935. {0x1e, 0x54},
  936. {0x28, 0x70},
  937. {0x32, 0x8c},
  938. {0x48, 0x90}
  939. };
  940. val1 = matrix[sd->satur][0];
  941. val2 = matrix[sd->satur][1];
  942. val3 = val1 + val2;
  943. sccb_write(gspca_dev, 0x4f, val3); /* matrix coeff */
  944. sccb_write(gspca_dev, 0x50, val3);
  945. sccb_write(gspca_dev, 0x51, 0x00);
  946. sccb_write(gspca_dev, 0x52, val1);
  947. sccb_write(gspca_dev, 0x53, val2);
  948. sccb_write(gspca_dev, 0x54, val3);
  949. sccb_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */
  950. val1 = sccb_read(gspca_dev, 0x41); /* com16 */
  951. sccb_write(gspca_dev, 0xff, 0x00);
  952. sccb_write(gspca_dev, 0x41, val1);
  953. }
  954. static void setfreq(struct gspca_dev *gspca_dev)
  955. {
  956. struct sd *sd = (struct sd *) gspca_dev;
  957. u8 val;
  958. val = sccb_read(gspca_dev, 0x13); /* com8 */
  959. sccb_write(gspca_dev, 0xff, 0x00);
  960. if (sd->freq == 0) {
  961. sccb_write(gspca_dev, 0x13, val & 0xdf);
  962. return;
  963. }
  964. sccb_write(gspca_dev, 0x13, val | 0x20);
  965. val = sccb_read(gspca_dev, 0x42); /* com17 */
  966. sccb_write(gspca_dev, 0xff, 0x00);
  967. if (sd->freq == 1)
  968. val |= 0x01;
  969. else
  970. val &= 0xfe;
  971. sccb_write(gspca_dev, 0x42, val);
  972. }
  973. /* this function is called at probe time */
  974. static int sd_config(struct gspca_dev *gspca_dev,
  975. const struct usb_device_id *id)
  976. {
  977. struct sd *sd = (struct sd *) gspca_dev;
  978. struct cam *cam;
  979. cam = &gspca_dev->cam;
  980. cam->cam_mode = ov965x_mode;
  981. cam->nmodes = ARRAY_SIZE(ov965x_mode);
  982. sd->brightness = BRIGHTNESS_DEF;
  983. sd->contrast = CONTRAST_DEF;
  984. #if AUTOGAIN_DEF != 0
  985. sd->autogain = AUTOGAIN_DEF;
  986. gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
  987. #endif
  988. #if EXPO_DEF != 0
  989. sd->exposure = EXPO_DEF;
  990. #endif
  991. #if SHARPNESS_DEF != 0
  992. sd->sharpness = SHARPNESS_DEF;
  993. #endif
  994. sd->satur = SATUR_DEF;
  995. sd->freq = FREQ_DEF;
  996. return 0;
  997. }
  998. /* this function is called at probe and resume time */
  999. static int sd_init(struct gspca_dev *gspca_dev)
  1000. {
  1001. u16 sensor_id;
  1002. /* reset bridge */
  1003. reg_w(gspca_dev, 0xe7, 0x3a);
  1004. reg_w(gspca_dev, 0xe0, 0x08);
  1005. msleep(100);
  1006. /* initialize the sensor address */
  1007. reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60);
  1008. /* reset sensor */
  1009. sccb_write(gspca_dev, 0x12, 0x80);
  1010. msleep(10);
  1011. /* probe the sensor */
  1012. sccb_read(gspca_dev, 0x0a);
  1013. sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
  1014. sccb_read(gspca_dev, 0x0b);
  1015. sensor_id |= sccb_read(gspca_dev, 0x0b);
  1016. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  1017. /* initialize */
  1018. reg_w_array(gspca_dev, bridge_init,
  1019. ARRAY_SIZE(bridge_init));
  1020. sccb_w_array(gspca_dev, sensor_init,
  1021. ARRAY_SIZE(sensor_init));
  1022. reg_w_array(gspca_dev, bridge_init_2,
  1023. ARRAY_SIZE(bridge_init_2));
  1024. sccb_w_array(gspca_dev, sensor_init_2,
  1025. ARRAY_SIZE(sensor_init_2));
  1026. reg_w(gspca_dev, 0xe0, 0x00);
  1027. reg_w(gspca_dev, 0xe0, 0x01);
  1028. set_led(gspca_dev, 0);
  1029. reg_w(gspca_dev, 0xe0, 0x00);
  1030. return gspca_dev->usb_err;
  1031. }
  1032. static int sd_start(struct gspca_dev *gspca_dev)
  1033. {
  1034. switch (gspca_dev->curr_mode) {
  1035. case QVGA_MODE: /* 320x240 */
  1036. sccb_w_array(gspca_dev, sensor_start_1_vga,
  1037. ARRAY_SIZE(sensor_start_1_vga));
  1038. reg_w_array(gspca_dev, bridge_start_qvga,
  1039. ARRAY_SIZE(bridge_start_qvga));
  1040. sccb_w_array(gspca_dev, sensor_start_2_qvga,
  1041. ARRAY_SIZE(sensor_start_2_qvga));
  1042. break;
  1043. case VGA_MODE: /* 640x480 */
  1044. sccb_w_array(gspca_dev, sensor_start_1_vga,
  1045. ARRAY_SIZE(sensor_start_1_vga));
  1046. reg_w_array(gspca_dev, bridge_start_vga,
  1047. ARRAY_SIZE(bridge_start_vga));
  1048. sccb_w_array(gspca_dev, sensor_start_2_vga,
  1049. ARRAY_SIZE(sensor_start_2_vga));
  1050. break;
  1051. case SVGA_MODE: /* 800x600 */
  1052. sccb_w_array(gspca_dev, sensor_start_1_svga,
  1053. ARRAY_SIZE(sensor_start_1_svga));
  1054. reg_w_array(gspca_dev, bridge_start_svga,
  1055. ARRAY_SIZE(bridge_start_svga));
  1056. sccb_w_array(gspca_dev, sensor_start_2_svga,
  1057. ARRAY_SIZE(sensor_start_2_svga));
  1058. break;
  1059. case XGA_MODE: /* 1024x768 */
  1060. sccb_w_array(gspca_dev, sensor_start_1_xga,
  1061. ARRAY_SIZE(sensor_start_1_xga));
  1062. reg_w_array(gspca_dev, bridge_start_xga,
  1063. ARRAY_SIZE(bridge_start_xga));
  1064. sccb_w_array(gspca_dev, sensor_start_2_svga,
  1065. ARRAY_SIZE(sensor_start_2_svga));
  1066. break;
  1067. default:
  1068. /* case SXGA_MODE: * 1280x1024 */
  1069. sccb_w_array(gspca_dev, sensor_start_1_sxga,
  1070. ARRAY_SIZE(sensor_start_1_sxga));
  1071. reg_w_array(gspca_dev, bridge_start_sxga,
  1072. ARRAY_SIZE(bridge_start_sxga));
  1073. sccb_w_array(gspca_dev, sensor_start_2_sxga,
  1074. ARRAY_SIZE(sensor_start_2_sxga));
  1075. break;
  1076. }
  1077. setfreq(gspca_dev);
  1078. setautogain(gspca_dev);
  1079. setbrightness(gspca_dev);
  1080. setcontrast(gspca_dev);
  1081. setexposure(gspca_dev);
  1082. setsharpness(gspca_dev);
  1083. setsatur(gspca_dev);
  1084. reg_w(gspca_dev, 0xe0, 0x00);
  1085. reg_w(gspca_dev, 0xe0, 0x00);
  1086. set_led(gspca_dev, 1);
  1087. return gspca_dev->usb_err;
  1088. }
  1089. static void sd_stopN(struct gspca_dev *gspca_dev)
  1090. {
  1091. reg_w(gspca_dev, 0xe0, 0x01);
  1092. set_led(gspca_dev, 0);
  1093. reg_w(gspca_dev, 0xe0, 0x00);
  1094. }
  1095. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1096. #define UVC_STREAM_EOH (1 << 7)
  1097. #define UVC_STREAM_ERR (1 << 6)
  1098. #define UVC_STREAM_STI (1 << 5)
  1099. #define UVC_STREAM_RES (1 << 4)
  1100. #define UVC_STREAM_SCR (1 << 3)
  1101. #define UVC_STREAM_PTS (1 << 2)
  1102. #define UVC_STREAM_EOF (1 << 1)
  1103. #define UVC_STREAM_FID (1 << 0)
  1104. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1105. u8 *data, int len)
  1106. {
  1107. struct sd *sd = (struct sd *) gspca_dev;
  1108. __u32 this_pts;
  1109. u8 this_fid;
  1110. int remaining_len = len;
  1111. do {
  1112. len = min(remaining_len, 2040);
  1113. /* Payloads are prefixed with a UVC-style header. We
  1114. consider a frame to start when the FID toggles, or the PTS
  1115. changes. A frame ends when EOF is set, and we've received
  1116. the correct number of bytes. */
  1117. /* Verify UVC header. Header length is always 12 */
  1118. if (data[0] != 12 || len < 12) {
  1119. PDEBUG(D_PACK, "bad header");
  1120. goto discard;
  1121. }
  1122. /* Check errors */
  1123. if (data[1] & UVC_STREAM_ERR) {
  1124. PDEBUG(D_PACK, "payload error");
  1125. goto discard;
  1126. }
  1127. /* Extract PTS and FID */
  1128. if (!(data[1] & UVC_STREAM_PTS)) {
  1129. PDEBUG(D_PACK, "PTS not present");
  1130. goto discard;
  1131. }
  1132. this_pts = (data[5] << 24) | (data[4] << 16)
  1133. | (data[3] << 8) | data[2];
  1134. this_fid = data[1] & UVC_STREAM_FID;
  1135. /* If PTS or FID has changed, start a new frame. */
  1136. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1137. if (gspca_dev->last_packet_type == INTER_PACKET)
  1138. gspca_frame_add(gspca_dev, LAST_PACKET,
  1139. NULL, 0);
  1140. sd->last_pts = this_pts;
  1141. sd->last_fid = this_fid;
  1142. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1143. data + 12, len - 12);
  1144. /* If this packet is marked as EOF, end the frame */
  1145. } else if (data[1] & UVC_STREAM_EOF) {
  1146. sd->last_pts = 0;
  1147. gspca_frame_add(gspca_dev, LAST_PACKET,
  1148. data + 12, len - 12);
  1149. } else {
  1150. /* Add the data from this payload */
  1151. gspca_frame_add(gspca_dev, INTER_PACKET,
  1152. data + 12, len - 12);
  1153. }
  1154. /* Done this payload */
  1155. goto scan_next;
  1156. discard:
  1157. /* Discard data until a new frame starts. */
  1158. gspca_dev->last_packet_type = DISCARD_PACKET;
  1159. scan_next:
  1160. remaining_len -= len;
  1161. data += len;
  1162. } while (remaining_len > 0);
  1163. }
  1164. /* controls */
  1165. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1166. {
  1167. struct sd *sd = (struct sd *) gspca_dev;
  1168. sd->brightness = val;
  1169. if (gspca_dev->streaming)
  1170. setbrightness(gspca_dev);
  1171. return gspca_dev->usb_err;
  1172. }
  1173. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1174. {
  1175. struct sd *sd = (struct sd *) gspca_dev;
  1176. *val = sd->brightness;
  1177. return 0;
  1178. }
  1179. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1180. {
  1181. struct sd *sd = (struct sd *) gspca_dev;
  1182. sd->contrast = val;
  1183. if (gspca_dev->streaming)
  1184. setcontrast(gspca_dev);
  1185. return gspca_dev->usb_err;
  1186. }
  1187. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1188. {
  1189. struct sd *sd = (struct sd *) gspca_dev;
  1190. *val = sd->contrast;
  1191. return 0;
  1192. }
  1193. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1194. {
  1195. struct sd *sd = (struct sd *) gspca_dev;
  1196. sd->autogain = val;
  1197. if (gspca_dev->streaming) {
  1198. if (val)
  1199. gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
  1200. else
  1201. gspca_dev->ctrl_inac &= ~(1 << EXPO_IDX);
  1202. setautogain(gspca_dev);
  1203. }
  1204. return gspca_dev->usb_err;
  1205. }
  1206. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1207. {
  1208. struct sd *sd = (struct sd *) gspca_dev;
  1209. *val = sd->autogain;
  1210. return 0;
  1211. }
  1212. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  1213. {
  1214. struct sd *sd = (struct sd *) gspca_dev;
  1215. sd->exposure = val;
  1216. if (gspca_dev->streaming)
  1217. setexposure(gspca_dev);
  1218. return gspca_dev->usb_err;
  1219. }
  1220. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  1221. {
  1222. struct sd *sd = (struct sd *) gspca_dev;
  1223. *val = sd->exposure;
  1224. return 0;
  1225. }
  1226. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1227. {
  1228. struct sd *sd = (struct sd *) gspca_dev;
  1229. sd->sharpness = val;
  1230. if (gspca_dev->streaming)
  1231. setsharpness(gspca_dev);
  1232. return gspca_dev->usb_err;
  1233. }
  1234. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1235. {
  1236. struct sd *sd = (struct sd *) gspca_dev;
  1237. *val = sd->sharpness;
  1238. return 0;
  1239. }
  1240. static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val)
  1241. {
  1242. struct sd *sd = (struct sd *) gspca_dev;
  1243. sd->satur = val;
  1244. if (gspca_dev->streaming)
  1245. setsatur(gspca_dev);
  1246. return gspca_dev->usb_err;
  1247. }
  1248. static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val)
  1249. {
  1250. struct sd *sd = (struct sd *) gspca_dev;
  1251. *val = sd->satur;
  1252. return 0;
  1253. }
  1254. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  1255. {
  1256. struct sd *sd = (struct sd *) gspca_dev;
  1257. sd->freq = val;
  1258. if (gspca_dev->streaming)
  1259. setfreq(gspca_dev);
  1260. return gspca_dev->usb_err;
  1261. }
  1262. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  1263. {
  1264. struct sd *sd = (struct sd *) gspca_dev;
  1265. *val = sd->freq;
  1266. return 0;
  1267. }
  1268. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1269. struct v4l2_querymenu *menu)
  1270. {
  1271. switch (menu->id) {
  1272. case V4L2_CID_POWER_LINE_FREQUENCY:
  1273. switch (menu->index) {
  1274. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  1275. strcpy((char *) menu->name, "NoFliker");
  1276. return 0;
  1277. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  1278. strcpy((char *) menu->name, "50 Hz");
  1279. return 0;
  1280. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  1281. strcpy((char *) menu->name, "60 Hz");
  1282. return 0;
  1283. }
  1284. break;
  1285. }
  1286. return -EINVAL;
  1287. }
  1288. /* sub-driver description */
  1289. static const struct sd_desc sd_desc = {
  1290. .name = MODULE_NAME,
  1291. .ctrls = sd_ctrls,
  1292. .nctrls = ARRAY_SIZE(sd_ctrls),
  1293. .config = sd_config,
  1294. .init = sd_init,
  1295. .start = sd_start,
  1296. .stopN = sd_stopN,
  1297. .pkt_scan = sd_pkt_scan,
  1298. .querymenu = sd_querymenu,
  1299. };
  1300. /* -- module initialisation -- */
  1301. static const struct usb_device_id device_table[] = {
  1302. {USB_DEVICE(0x06f8, 0x3003)},
  1303. {}
  1304. };
  1305. MODULE_DEVICE_TABLE(usb, device_table);
  1306. /* -- device connect -- */
  1307. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1308. {
  1309. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1310. THIS_MODULE);
  1311. }
  1312. static struct usb_driver sd_driver = {
  1313. .name = MODULE_NAME,
  1314. .id_table = device_table,
  1315. .probe = sd_probe,
  1316. .disconnect = gspca_disconnect,
  1317. #ifdef CONFIG_PM
  1318. .suspend = gspca_suspend,
  1319. .resume = gspca_resume,
  1320. #endif
  1321. };
  1322. /* -- module insert / remove -- */
  1323. static int __init sd_mod_init(void)
  1324. {
  1325. return usb_register(&sd_driver);
  1326. }
  1327. static void __exit sd_mod_exit(void)
  1328. {
  1329. usb_deregister(&sd_driver);
  1330. }
  1331. module_init(sd_mod_init);
  1332. module_exit(sd_mod_exit);