ov519.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. /**
  2. * OV519 driver
  3. *
  4. * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
  5. *
  6. * This module is adapted from the ov51x-jpeg package, which itself
  7. * was adapted from the ov511 driver.
  8. *
  9. * Original copyright for the ov511 driver is:
  10. *
  11. * Copyright (c) 1999-2004 Mark W. McClelland
  12. * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
  13. *
  14. * ov51x-jpeg original copyright is:
  15. *
  16. * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
  17. * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  32. *
  33. */
  34. #define MODULE_NAME "ov519"
  35. #include "gspca.h"
  36. MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
  37. MODULE_DESCRIPTION("OV519 USB Camera Driver");
  38. MODULE_LICENSE("GPL");
  39. /* global parameters */
  40. static int frame_rate;
  41. /* Number of times to retry a failed I2C transaction. Increase this if you
  42. * are getting "Failed to read sensor ID..." */
  43. static int i2c_detect_tries = 10;
  44. /* ov519 device descriptor */
  45. struct sd {
  46. struct gspca_dev gspca_dev; /* !! must be the first item */
  47. /* Determined by sensor type */
  48. __u8 sif;
  49. __u8 brightness;
  50. __u8 contrast;
  51. __u8 colors;
  52. __u8 hflip;
  53. __u8 vflip;
  54. __u8 stopped; /* Streaming is temporarily paused */
  55. __u8 frame_rate; /* current Framerate (OV519 only) */
  56. __u8 clockdiv; /* clockdiv override for OV519 only */
  57. char sensor; /* Type of image sensor chip (SEN_*) */
  58. #define SEN_UNKNOWN 0
  59. #define SEN_OV6620 1
  60. #define SEN_OV6630 2
  61. #define SEN_OV7610 3
  62. #define SEN_OV7620 4
  63. #define SEN_OV7640 5
  64. #define SEN_OV7670 6
  65. #define SEN_OV76BE 7
  66. #define SEN_OV8610 8
  67. };
  68. /* V4L2 controls supported by the driver */
  69. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  70. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  71. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  72. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  73. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  74. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  75. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  76. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  77. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  78. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  79. static struct ctrl sd_ctrls[] = {
  80. {
  81. {
  82. .id = V4L2_CID_BRIGHTNESS,
  83. .type = V4L2_CTRL_TYPE_INTEGER,
  84. .name = "Brightness",
  85. .minimum = 0,
  86. .maximum = 255,
  87. .step = 1,
  88. #define BRIGHTNESS_DEF 127
  89. .default_value = BRIGHTNESS_DEF,
  90. },
  91. .set = sd_setbrightness,
  92. .get = sd_getbrightness,
  93. },
  94. {
  95. {
  96. .id = V4L2_CID_CONTRAST,
  97. .type = V4L2_CTRL_TYPE_INTEGER,
  98. .name = "Contrast",
  99. .minimum = 0,
  100. .maximum = 255,
  101. .step = 1,
  102. #define CONTRAST_DEF 127
  103. .default_value = CONTRAST_DEF,
  104. },
  105. .set = sd_setcontrast,
  106. .get = sd_getcontrast,
  107. },
  108. {
  109. {
  110. .id = V4L2_CID_SATURATION,
  111. .type = V4L2_CTRL_TYPE_INTEGER,
  112. .name = "Color",
  113. .minimum = 0,
  114. .maximum = 255,
  115. .step = 1,
  116. #define COLOR_DEF 127
  117. .default_value = COLOR_DEF,
  118. },
  119. .set = sd_setcolors,
  120. .get = sd_getcolors,
  121. },
  122. /* next controls work with ov7670 only */
  123. #define HFLIP_IDX 3
  124. {
  125. {
  126. .id = V4L2_CID_HFLIP,
  127. .type = V4L2_CTRL_TYPE_BOOLEAN,
  128. .name = "Mirror",
  129. .minimum = 0,
  130. .maximum = 1,
  131. .step = 1,
  132. #define HFLIP_DEF 0
  133. .default_value = HFLIP_DEF,
  134. },
  135. .set = sd_sethflip,
  136. .get = sd_gethflip,
  137. },
  138. #define VFLIP_IDX 4
  139. {
  140. {
  141. .id = V4L2_CID_VFLIP,
  142. .type = V4L2_CTRL_TYPE_BOOLEAN,
  143. .name = "Vflip",
  144. .minimum = 0,
  145. .maximum = 1,
  146. .step = 1,
  147. #define VFLIP_DEF 0
  148. .default_value = VFLIP_DEF,
  149. },
  150. .set = sd_setvflip,
  151. .get = sd_getvflip,
  152. },
  153. };
  154. static struct v4l2_pix_format vga_mode[] = {
  155. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  156. .bytesperline = 320,
  157. .sizeimage = 320 * 240 * 3 / 8 + 590,
  158. .colorspace = V4L2_COLORSPACE_JPEG,
  159. .priv = 1},
  160. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  161. .bytesperline = 640,
  162. .sizeimage = 640 * 480 * 3 / 8 + 590,
  163. .colorspace = V4L2_COLORSPACE_JPEG,
  164. .priv = 0},
  165. };
  166. static struct v4l2_pix_format sif_mode[] = {
  167. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  168. .bytesperline = 176,
  169. .sizeimage = 176 * 144 * 3 / 8 + 590,
  170. .colorspace = V4L2_COLORSPACE_JPEG,
  171. .priv = 1},
  172. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  173. .bytesperline = 352,
  174. .sizeimage = 352 * 288 * 3 / 8 + 590,
  175. .colorspace = V4L2_COLORSPACE_JPEG,
  176. .priv = 0},
  177. };
  178. /* OV519 Camera interface register numbers */
  179. #define OV519_R10_H_SIZE 0x10
  180. #define OV519_R11_V_SIZE 0x11
  181. #define OV519_R12_X_OFFSETL 0x12
  182. #define OV519_R13_X_OFFSETH 0x13
  183. #define OV519_R14_Y_OFFSETL 0x14
  184. #define OV519_R15_Y_OFFSETH 0x15
  185. #define OV519_R16_DIVIDER 0x16
  186. #define OV519_R20_DFR 0x20
  187. #define OV519_R25_FORMAT 0x25
  188. /* OV519 System Controller register numbers */
  189. #define OV519_SYS_RESET1 0x51
  190. #define OV519_SYS_EN_CLK1 0x54
  191. #define OV519_GPIO_DATA_OUT0 0x71
  192. #define OV519_GPIO_IO_CTRL0 0x72
  193. #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
  194. /* I2C registers */
  195. #define R51x_I2C_W_SID 0x41
  196. #define R51x_I2C_SADDR_3 0x42
  197. #define R51x_I2C_SADDR_2 0x43
  198. #define R51x_I2C_R_SID 0x44
  199. #define R51x_I2C_DATA 0x45
  200. #define R518_I2C_CTL 0x47 /* OV518(+) only */
  201. /* I2C ADDRESSES */
  202. #define OV7xx0_SID 0x42
  203. #define OV8xx0_SID 0xa0
  204. #define OV6xx0_SID 0xc0
  205. /* OV7610 registers */
  206. #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
  207. #define OV7610_REG_SAT 0x03 /* saturation */
  208. #define OV8610_REG_HUE 0x04 /* 04 reserved */
  209. #define OV7610_REG_CNT 0x05 /* Y contrast */
  210. #define OV7610_REG_BRT 0x06 /* Y brightness */
  211. #define OV7610_REG_COM_C 0x14 /* misc common regs */
  212. #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
  213. #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
  214. #define OV7610_REG_COM_I 0x29 /* misc settings */
  215. /* OV7670 registers */
  216. #define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
  217. #define OV7670_REG_BLUE 0x01 /* blue gain */
  218. #define OV7670_REG_RED 0x02 /* red gain */
  219. #define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
  220. #define OV7670_REG_COM1 0x04 /* Control 1 */
  221. #define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
  222. #define OV7670_REG_COM3 0x0c /* Control 3 */
  223. #define OV7670_REG_COM4 0x0d /* Control 4 */
  224. #define OV7670_REG_COM5 0x0e /* All "reserved" */
  225. #define OV7670_REG_COM6 0x0f /* Control 6 */
  226. #define OV7670_REG_AECH 0x10 /* More bits of AEC value */
  227. #define OV7670_REG_CLKRC 0x11 /* Clock control */
  228. #define OV7670_REG_COM7 0x12 /* Control 7 */
  229. #define OV7670_COM7_FMT_VGA 0x00
  230. #define OV7670_COM7_YUV 0x00 /* YUV */
  231. #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
  232. #define OV7670_COM7_FMT_MASK 0x38
  233. #define OV7670_COM7_RESET 0x80 /* Register reset */
  234. #define OV7670_REG_COM8 0x13 /* Control 8 */
  235. #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
  236. #define OV7670_COM8_AWB 0x02 /* White balance enable */
  237. #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
  238. #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
  239. #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
  240. #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
  241. #define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
  242. #define OV7670_REG_COM10 0x15 /* Control 10 */
  243. #define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
  244. #define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
  245. #define OV7670_REG_VSTART 0x19 /* Vert start high bits */
  246. #define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
  247. #define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
  248. #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
  249. #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
  250. #define OV7670_REG_AEW 0x24 /* AGC upper limit */
  251. #define OV7670_REG_AEB 0x25 /* AGC lower limit */
  252. #define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
  253. #define OV7670_REG_HREF 0x32 /* HREF pieces */
  254. #define OV7670_REG_TSLB 0x3a /* lots of stuff */
  255. #define OV7670_REG_COM11 0x3b /* Control 11 */
  256. #define OV7670_COM11_EXP 0x02
  257. #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
  258. #define OV7670_REG_COM12 0x3c /* Control 12 */
  259. #define OV7670_REG_COM13 0x3d /* Control 13 */
  260. #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
  261. #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
  262. #define OV7670_REG_COM14 0x3e /* Control 14 */
  263. #define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
  264. #define OV7670_REG_COM15 0x40 /* Control 15 */
  265. #define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
  266. #define OV7670_REG_COM16 0x41 /* Control 16 */
  267. #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
  268. #define OV7670_REG_BRIGHT 0x55 /* Brightness */
  269. #define OV7670_REG_CONTRAS 0x56 /* Contrast control */
  270. #define OV7670_REG_GFIX 0x69 /* Fix gain control */
  271. #define OV7670_REG_RGB444 0x8c /* RGB 444 control */
  272. #define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
  273. #define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
  274. #define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
  275. #define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
  276. #define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
  277. #define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
  278. #define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
  279. #define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
  280. #define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
  281. struct ov_regvals {
  282. __u8 reg;
  283. __u8 val;
  284. };
  285. struct ov_i2c_regvals {
  286. __u8 reg;
  287. __u8 val;
  288. };
  289. static const struct ov_i2c_regvals norm_6x20[] = {
  290. { 0x12, 0x80 }, /* reset */
  291. { 0x11, 0x01 },
  292. { 0x03, 0x60 },
  293. { 0x05, 0x7f }, /* For when autoadjust is off */
  294. { 0x07, 0xa8 },
  295. /* The ratio of 0x0c and 0x0d controls the white point */
  296. { 0x0c, 0x24 },
  297. { 0x0d, 0x24 },
  298. { 0x0f, 0x15 }, /* COMS */
  299. { 0x10, 0x75 }, /* AEC Exposure time */
  300. { 0x12, 0x24 }, /* Enable AGC */
  301. { 0x14, 0x04 },
  302. /* 0x16: 0x06 helps frame stability with moving objects */
  303. { 0x16, 0x06 },
  304. /* { 0x20, 0x30 }, * Aperture correction enable */
  305. { 0x26, 0xb2 }, /* BLC enable */
  306. /* 0x28: 0x05 Selects RGB format if RGB on */
  307. { 0x28, 0x05 },
  308. { 0x2a, 0x04 }, /* Disable framerate adjust */
  309. /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
  310. { 0x2d, 0x99 },
  311. { 0x33, 0xa0 }, /* Color Processing Parameter */
  312. { 0x34, 0xd2 }, /* Max A/D range */
  313. { 0x38, 0x8b },
  314. { 0x39, 0x40 },
  315. { 0x3c, 0x39 }, /* Enable AEC mode changing */
  316. { 0x3c, 0x3c }, /* Change AEC mode */
  317. { 0x3c, 0x24 }, /* Disable AEC mode changing */
  318. { 0x3d, 0x80 },
  319. /* These next two registers (0x4a, 0x4b) are undocumented.
  320. * They control the color balance */
  321. { 0x4a, 0x80 },
  322. { 0x4b, 0x80 },
  323. { 0x4d, 0xd2 }, /* This reduces noise a bit */
  324. { 0x4e, 0xc1 },
  325. { 0x4f, 0x04 },
  326. /* Do 50-53 have any effect? */
  327. /* Toggle 0x12[2] off and on here? */
  328. };
  329. static const struct ov_i2c_regvals norm_6x30[] = {
  330. { 0x12, 0x80 }, /* Reset */
  331. { 0x00, 0x1f }, /* Gain */
  332. { 0x01, 0x99 }, /* Blue gain */
  333. { 0x02, 0x7c }, /* Red gain */
  334. { 0x03, 0xc0 }, /* Saturation */
  335. { 0x05, 0x0a }, /* Contrast */
  336. { 0x06, 0x95 }, /* Brightness */
  337. { 0x07, 0x2d }, /* Sharpness */
  338. { 0x0c, 0x20 },
  339. { 0x0d, 0x20 },
  340. { 0x0e, 0x20 },
  341. { 0x0f, 0x05 },
  342. { 0x10, 0x9a },
  343. { 0x11, 0x00 }, /* Pixel clock = fastest */
  344. { 0x12, 0x24 }, /* Enable AGC and AWB */
  345. { 0x13, 0x21 },
  346. { 0x14, 0x80 },
  347. { 0x15, 0x01 },
  348. { 0x16, 0x03 },
  349. { 0x17, 0x38 },
  350. { 0x18, 0xea },
  351. { 0x19, 0x04 },
  352. { 0x1a, 0x93 },
  353. { 0x1b, 0x00 },
  354. { 0x1e, 0xc4 },
  355. { 0x1f, 0x04 },
  356. { 0x20, 0x20 },
  357. { 0x21, 0x10 },
  358. { 0x22, 0x88 },
  359. { 0x23, 0xc0 }, /* Crystal circuit power level */
  360. { 0x25, 0x9a }, /* Increase AEC black ratio */
  361. { 0x26, 0xb2 }, /* BLC enable */
  362. { 0x27, 0xa2 },
  363. { 0x28, 0x00 },
  364. { 0x29, 0x00 },
  365. { 0x2a, 0x84 }, /* 60 Hz power */
  366. { 0x2b, 0xa8 }, /* 60 Hz power */
  367. { 0x2c, 0xa0 },
  368. { 0x2d, 0x95 }, /* Enable auto-brightness */
  369. { 0x2e, 0x88 },
  370. { 0x33, 0x26 },
  371. { 0x34, 0x03 },
  372. { 0x36, 0x8f },
  373. { 0x37, 0x80 },
  374. { 0x38, 0x83 },
  375. { 0x39, 0x80 },
  376. { 0x3a, 0x0f },
  377. { 0x3b, 0x3c },
  378. { 0x3c, 0x1a },
  379. { 0x3d, 0x80 },
  380. { 0x3e, 0x80 },
  381. { 0x3f, 0x0e },
  382. { 0x40, 0x00 }, /* White bal */
  383. { 0x41, 0x00 }, /* White bal */
  384. { 0x42, 0x80 },
  385. { 0x43, 0x3f }, /* White bal */
  386. { 0x44, 0x80 },
  387. { 0x45, 0x20 },
  388. { 0x46, 0x20 },
  389. { 0x47, 0x80 },
  390. { 0x48, 0x7f },
  391. { 0x49, 0x00 },
  392. { 0x4a, 0x00 },
  393. { 0x4b, 0x80 },
  394. { 0x4c, 0xd0 },
  395. { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
  396. { 0x4e, 0x40 },
  397. { 0x4f, 0x07 }, /* UV avg., col. killer: max */
  398. { 0x50, 0xff },
  399. { 0x54, 0x23 }, /* Max AGC gain: 18dB */
  400. { 0x55, 0xff },
  401. { 0x56, 0x12 },
  402. { 0x57, 0x81 },
  403. { 0x58, 0x75 },
  404. { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
  405. { 0x5a, 0x2c },
  406. { 0x5b, 0x0f }, /* AWB chrominance levels */
  407. { 0x5c, 0x10 },
  408. { 0x3d, 0x80 },
  409. { 0x27, 0xa6 },
  410. { 0x12, 0x20 }, /* Toggle AWB */
  411. { 0x12, 0x24 },
  412. };
  413. /* Lawrence Glaister <lg@jfm.bc.ca> reports:
  414. *
  415. * Register 0x0f in the 7610 has the following effects:
  416. *
  417. * 0x85 (AEC method 1): Best overall, good contrast range
  418. * 0x45 (AEC method 2): Very overexposed
  419. * 0xa5 (spec sheet default): Ok, but the black level is
  420. * shifted resulting in loss of contrast
  421. * 0x05 (old driver setting): very overexposed, too much
  422. * contrast
  423. */
  424. static const struct ov_i2c_regvals norm_7610[] = {
  425. { 0x10, 0xff },
  426. { 0x16, 0x06 },
  427. { 0x28, 0x24 },
  428. { 0x2b, 0xac },
  429. { 0x12, 0x00 },
  430. { 0x38, 0x81 },
  431. { 0x28, 0x24 }, /* 0c */
  432. { 0x0f, 0x85 }, /* lg's setting */
  433. { 0x15, 0x01 },
  434. { 0x20, 0x1c },
  435. { 0x23, 0x2a },
  436. { 0x24, 0x10 },
  437. { 0x25, 0x8a },
  438. { 0x26, 0xa2 },
  439. { 0x27, 0xc2 },
  440. { 0x2a, 0x04 },
  441. { 0x2c, 0xfe },
  442. { 0x2d, 0x93 },
  443. { 0x30, 0x71 },
  444. { 0x31, 0x60 },
  445. { 0x32, 0x26 },
  446. { 0x33, 0x20 },
  447. { 0x34, 0x48 },
  448. { 0x12, 0x24 },
  449. { 0x11, 0x01 },
  450. { 0x0c, 0x24 },
  451. { 0x0d, 0x24 },
  452. };
  453. static const struct ov_i2c_regvals norm_7620[] = {
  454. { 0x00, 0x00 }, /* gain */
  455. { 0x01, 0x80 }, /* blue gain */
  456. { 0x02, 0x80 }, /* red gain */
  457. { 0x03, 0xc0 }, /* OV7670_REG_VREF */
  458. { 0x06, 0x60 },
  459. { 0x07, 0x00 },
  460. { 0x0c, 0x24 },
  461. { 0x0c, 0x24 },
  462. { 0x0d, 0x24 },
  463. { 0x11, 0x01 },
  464. { 0x12, 0x24 },
  465. { 0x13, 0x01 },
  466. { 0x14, 0x84 },
  467. { 0x15, 0x01 },
  468. { 0x16, 0x03 },
  469. { 0x17, 0x2f },
  470. { 0x18, 0xcf },
  471. { 0x19, 0x06 },
  472. { 0x1a, 0xf5 },
  473. { 0x1b, 0x00 },
  474. { 0x20, 0x18 },
  475. { 0x21, 0x80 },
  476. { 0x22, 0x80 },
  477. { 0x23, 0x00 },
  478. { 0x26, 0xa2 },
  479. { 0x27, 0xea },
  480. { 0x28, 0x20 },
  481. { 0x29, 0x00 },
  482. { 0x2a, 0x10 },
  483. { 0x2b, 0x00 },
  484. { 0x2c, 0x88 },
  485. { 0x2d, 0x91 },
  486. { 0x2e, 0x80 },
  487. { 0x2f, 0x44 },
  488. { 0x60, 0x27 },
  489. { 0x61, 0x02 },
  490. { 0x62, 0x5f },
  491. { 0x63, 0xd5 },
  492. { 0x64, 0x57 },
  493. { 0x65, 0x83 },
  494. { 0x66, 0x55 },
  495. { 0x67, 0x92 },
  496. { 0x68, 0xcf },
  497. { 0x69, 0x76 },
  498. { 0x6a, 0x22 },
  499. { 0x6b, 0x00 },
  500. { 0x6c, 0x02 },
  501. { 0x6d, 0x44 },
  502. { 0x6e, 0x80 },
  503. { 0x6f, 0x1d },
  504. { 0x70, 0x8b },
  505. { 0x71, 0x00 },
  506. { 0x72, 0x14 },
  507. { 0x73, 0x54 },
  508. { 0x74, 0x00 },
  509. { 0x75, 0x8e },
  510. { 0x76, 0x00 },
  511. { 0x77, 0xff },
  512. { 0x78, 0x80 },
  513. { 0x79, 0x80 },
  514. { 0x7a, 0x80 },
  515. { 0x7b, 0xe2 },
  516. { 0x7c, 0x00 },
  517. };
  518. /* 7640 and 7648. The defaults should be OK for most registers. */
  519. static const struct ov_i2c_regvals norm_7640[] = {
  520. { 0x12, 0x80 },
  521. { 0x12, 0x14 },
  522. };
  523. /* 7670. Defaults taken from OmniVision provided data,
  524. * as provided by Jonathan Corbet of OLPC */
  525. static const struct ov_i2c_regvals norm_7670[] = {
  526. { OV7670_REG_COM7, OV7670_COM7_RESET },
  527. { OV7670_REG_TSLB, 0x04 }, /* OV */
  528. { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
  529. { OV7670_REG_CLKRC, 0x01 },
  530. /*
  531. * Set the hardware window. These values from OV don't entirely
  532. * make sense - hstop is less than hstart. But they work...
  533. */
  534. { OV7670_REG_HSTART, 0x13 },
  535. { OV7670_REG_HSTOP, 0x01 },
  536. { OV7670_REG_HREF, 0xb6 },
  537. { OV7670_REG_VSTART, 0x02 },
  538. { OV7670_REG_VSTOP, 0x7a },
  539. { OV7670_REG_VREF, 0x0a },
  540. { OV7670_REG_COM3, 0x00 },
  541. { OV7670_REG_COM14, 0x00 },
  542. /* Mystery scaling numbers */
  543. { 0x70, 0x3a },
  544. { 0x71, 0x35 },
  545. { 0x72, 0x11 },
  546. { 0x73, 0xf0 },
  547. { 0xa2, 0x02 },
  548. /* { OV7670_REG_COM10, 0x0 }, */
  549. /* Gamma curve values */
  550. { 0x7a, 0x20 },
  551. { 0x7b, 0x10 },
  552. { 0x7c, 0x1e },
  553. { 0x7d, 0x35 },
  554. { 0x7e, 0x5a },
  555. { 0x7f, 0x69 },
  556. { 0x80, 0x76 },
  557. { 0x81, 0x80 },
  558. { 0x82, 0x88 },
  559. { 0x83, 0x8f },
  560. { 0x84, 0x96 },
  561. { 0x85, 0xa3 },
  562. { 0x86, 0xaf },
  563. { 0x87, 0xc4 },
  564. { 0x88, 0xd7 },
  565. { 0x89, 0xe8 },
  566. /* AGC and AEC parameters. Note we start by disabling those features,
  567. then turn them only after tweaking the values. */
  568. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  569. | OV7670_COM8_AECSTEP
  570. | OV7670_COM8_BFILT },
  571. { OV7670_REG_GAIN, 0x00 },
  572. { OV7670_REG_AECH, 0x00 },
  573. { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
  574. { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
  575. { OV7670_REG_BD50MAX, 0x05 },
  576. { OV7670_REG_BD60MAX, 0x07 },
  577. { OV7670_REG_AEW, 0x95 },
  578. { OV7670_REG_AEB, 0x33 },
  579. { OV7670_REG_VPT, 0xe3 },
  580. { OV7670_REG_HAECC1, 0x78 },
  581. { OV7670_REG_HAECC2, 0x68 },
  582. { 0xa1, 0x03 }, /* magic */
  583. { OV7670_REG_HAECC3, 0xd8 },
  584. { OV7670_REG_HAECC4, 0xd8 },
  585. { OV7670_REG_HAECC5, 0xf0 },
  586. { OV7670_REG_HAECC6, 0x90 },
  587. { OV7670_REG_HAECC7, 0x94 },
  588. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  589. | OV7670_COM8_AECSTEP
  590. | OV7670_COM8_BFILT
  591. | OV7670_COM8_AGC
  592. | OV7670_COM8_AEC },
  593. /* Almost all of these are magic "reserved" values. */
  594. { OV7670_REG_COM5, 0x61 },
  595. { OV7670_REG_COM6, 0x4b },
  596. { 0x16, 0x02 },
  597. { OV7670_REG_MVFP, 0x07 },
  598. { 0x21, 0x02 },
  599. { 0x22, 0x91 },
  600. { 0x29, 0x07 },
  601. { 0x33, 0x0b },
  602. { 0x35, 0x0b },
  603. { 0x37, 0x1d },
  604. { 0x38, 0x71 },
  605. { 0x39, 0x2a },
  606. { OV7670_REG_COM12, 0x78 },
  607. { 0x4d, 0x40 },
  608. { 0x4e, 0x20 },
  609. { OV7670_REG_GFIX, 0x00 },
  610. { 0x6b, 0x4a },
  611. { 0x74, 0x10 },
  612. { 0x8d, 0x4f },
  613. { 0x8e, 0x00 },
  614. { 0x8f, 0x00 },
  615. { 0x90, 0x00 },
  616. { 0x91, 0x00 },
  617. { 0x96, 0x00 },
  618. { 0x9a, 0x00 },
  619. { 0xb0, 0x84 },
  620. { 0xb1, 0x0c },
  621. { 0xb2, 0x0e },
  622. { 0xb3, 0x82 },
  623. { 0xb8, 0x0a },
  624. /* More reserved magic, some of which tweaks white balance */
  625. { 0x43, 0x0a },
  626. { 0x44, 0xf0 },
  627. { 0x45, 0x34 },
  628. { 0x46, 0x58 },
  629. { 0x47, 0x28 },
  630. { 0x48, 0x3a },
  631. { 0x59, 0x88 },
  632. { 0x5a, 0x88 },
  633. { 0x5b, 0x44 },
  634. { 0x5c, 0x67 },
  635. { 0x5d, 0x49 },
  636. { 0x5e, 0x0e },
  637. { 0x6c, 0x0a },
  638. { 0x6d, 0x55 },
  639. { 0x6e, 0x11 },
  640. { 0x6f, 0x9f },
  641. /* "9e for advance AWB" */
  642. { 0x6a, 0x40 },
  643. { OV7670_REG_BLUE, 0x40 },
  644. { OV7670_REG_RED, 0x60 },
  645. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  646. | OV7670_COM8_AECSTEP
  647. | OV7670_COM8_BFILT
  648. | OV7670_COM8_AGC
  649. | OV7670_COM8_AEC
  650. | OV7670_COM8_AWB },
  651. /* Matrix coefficients */
  652. { 0x4f, 0x80 },
  653. { 0x50, 0x80 },
  654. { 0x51, 0x00 },
  655. { 0x52, 0x22 },
  656. { 0x53, 0x5e },
  657. { 0x54, 0x80 },
  658. { 0x58, 0x9e },
  659. { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
  660. { OV7670_REG_EDGE, 0x00 },
  661. { 0x75, 0x05 },
  662. { 0x76, 0xe1 },
  663. { 0x4c, 0x00 },
  664. { 0x77, 0x01 },
  665. { OV7670_REG_COM13, OV7670_COM13_GAMMA
  666. | OV7670_COM13_UVSAT
  667. | 2}, /* was 3 */
  668. { 0x4b, 0x09 },
  669. { 0xc9, 0x60 },
  670. { OV7670_REG_COM16, 0x38 },
  671. { 0x56, 0x40 },
  672. { 0x34, 0x11 },
  673. { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
  674. { 0xa4, 0x88 },
  675. { 0x96, 0x00 },
  676. { 0x97, 0x30 },
  677. { 0x98, 0x20 },
  678. { 0x99, 0x30 },
  679. { 0x9a, 0x84 },
  680. { 0x9b, 0x29 },
  681. { 0x9c, 0x03 },
  682. { 0x9d, 0x4c },
  683. { 0x9e, 0x3f },
  684. { 0x78, 0x04 },
  685. /* Extra-weird stuff. Some sort of multiplexor register */
  686. { 0x79, 0x01 },
  687. { 0xc8, 0xf0 },
  688. { 0x79, 0x0f },
  689. { 0xc8, 0x00 },
  690. { 0x79, 0x10 },
  691. { 0xc8, 0x7e },
  692. { 0x79, 0x0a },
  693. { 0xc8, 0x80 },
  694. { 0x79, 0x0b },
  695. { 0xc8, 0x01 },
  696. { 0x79, 0x0c },
  697. { 0xc8, 0x0f },
  698. { 0x79, 0x0d },
  699. { 0xc8, 0x20 },
  700. { 0x79, 0x09 },
  701. { 0xc8, 0x80 },
  702. { 0x79, 0x02 },
  703. { 0xc8, 0xc0 },
  704. { 0x79, 0x03 },
  705. { 0xc8, 0x40 },
  706. { 0x79, 0x05 },
  707. { 0xc8, 0x30 },
  708. { 0x79, 0x26 },
  709. };
  710. static const struct ov_i2c_regvals norm_8610[] = {
  711. { 0x12, 0x80 },
  712. { 0x00, 0x00 },
  713. { 0x01, 0x80 },
  714. { 0x02, 0x80 },
  715. { 0x03, 0xc0 },
  716. { 0x04, 0x30 },
  717. { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
  718. { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
  719. { 0x0a, 0x86 },
  720. { 0x0b, 0xb0 },
  721. { 0x0c, 0x20 },
  722. { 0x0d, 0x20 },
  723. { 0x11, 0x01 },
  724. { 0x12, 0x25 },
  725. { 0x13, 0x01 },
  726. { 0x14, 0x04 },
  727. { 0x15, 0x01 }, /* Lin and Win think different about UV order */
  728. { 0x16, 0x03 },
  729. { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
  730. { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
  731. { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
  732. { 0x1a, 0xf5 },
  733. { 0x1b, 0x00 },
  734. { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
  735. { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
  736. { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
  737. { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
  738. { 0x26, 0xa2 },
  739. { 0x27, 0xea },
  740. { 0x28, 0x00 },
  741. { 0x29, 0x00 },
  742. { 0x2a, 0x80 },
  743. { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
  744. { 0x2c, 0xac },
  745. { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
  746. { 0x2e, 0x80 },
  747. { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
  748. { 0x4c, 0x00 },
  749. { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
  750. { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
  751. { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
  752. { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
  753. { 0x63, 0xff },
  754. { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
  755. * maybe thats wrong */
  756. { 0x65, 0x00 },
  757. { 0x66, 0x55 },
  758. { 0x67, 0xb0 },
  759. { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
  760. { 0x69, 0x02 },
  761. { 0x6a, 0x22 },
  762. { 0x6b, 0x00 },
  763. { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
  764. * deleting bit7 colors the first images red */
  765. { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
  766. { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
  767. { 0x6f, 0x01 },
  768. { 0x70, 0x8b },
  769. { 0x71, 0x00 },
  770. { 0x72, 0x14 },
  771. { 0x73, 0x54 },
  772. { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
  773. { 0x75, 0x0e },
  774. { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
  775. { 0x77, 0xff },
  776. { 0x78, 0x80 },
  777. { 0x79, 0x80 },
  778. { 0x7a, 0x80 },
  779. { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
  780. { 0x7c, 0x00 },
  781. { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
  782. { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
  783. { 0x7f, 0xfb },
  784. { 0x80, 0x28 },
  785. { 0x81, 0x00 },
  786. { 0x82, 0x23 },
  787. { 0x83, 0x0b },
  788. { 0x84, 0x00 },
  789. { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
  790. { 0x86, 0xc9 },
  791. { 0x87, 0x00 },
  792. { 0x88, 0x00 },
  793. { 0x89, 0x01 },
  794. { 0x12, 0x20 },
  795. { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
  796. };
  797. static unsigned char ov7670_abs_to_sm(unsigned char v)
  798. {
  799. if (v > 127)
  800. return v & 0x7f;
  801. return (128 - v) | 0x80;
  802. }
  803. /* Write a OV519 register */
  804. static int reg_w(struct sd *sd, __u16 index, __u8 value)
  805. {
  806. int ret;
  807. sd->gspca_dev.usb_buf[0] = value;
  808. ret = usb_control_msg(sd->gspca_dev.dev,
  809. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  810. 1, /* REQ_IO (ov518/519) */
  811. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  812. 0, index,
  813. sd->gspca_dev.usb_buf, 1, 500);
  814. if (ret < 0)
  815. PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
  816. return ret;
  817. }
  818. /* Read from a OV519 register */
  819. /* returns: negative is error, pos or zero is data */
  820. static int reg_r(struct sd *sd, __u16 index)
  821. {
  822. int ret;
  823. ret = usb_control_msg(sd->gspca_dev.dev,
  824. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  825. 1, /* REQ_IO */
  826. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  827. 0, index, sd->gspca_dev.usb_buf, 1, 500);
  828. if (ret >= 0)
  829. ret = sd->gspca_dev.usb_buf[0];
  830. else
  831. PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
  832. return ret;
  833. }
  834. /* Read 8 values from a OV519 register */
  835. static int reg_r8(struct sd *sd,
  836. __u16 index)
  837. {
  838. int ret;
  839. ret = usb_control_msg(sd->gspca_dev.dev,
  840. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  841. 1, /* REQ_IO */
  842. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  843. 0, index, sd->gspca_dev.usb_buf, 8, 500);
  844. if (ret >= 0)
  845. ret = sd->gspca_dev.usb_buf[0];
  846. else
  847. PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
  848. return ret;
  849. }
  850. /*
  851. * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
  852. * the same position as 1's in "mask" are cleared and set to "value". Bits
  853. * that are in the same position as 0's in "mask" are preserved, regardless
  854. * of their respective state in "value".
  855. */
  856. static int reg_w_mask(struct sd *sd,
  857. __u16 index,
  858. __u8 value,
  859. __u8 mask)
  860. {
  861. int ret;
  862. __u8 oldval;
  863. if (mask != 0xff) {
  864. value &= mask; /* Enforce mask on value */
  865. ret = reg_r(sd, index);
  866. if (ret < 0)
  867. return ret;
  868. oldval = ret & ~mask; /* Clear the masked bits */
  869. value |= oldval; /* Set the desired bits */
  870. }
  871. return reg_w(sd, index, value);
  872. }
  873. /*
  874. * The OV518 I2C I/O procedure is different, hence, this function.
  875. * This is normally only called from i2c_w(). Note that this function
  876. * always succeeds regardless of whether the sensor is present and working.
  877. */
  878. static int i2c_w(struct sd *sd,
  879. __u8 reg,
  880. __u8 value)
  881. {
  882. int rc;
  883. PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
  884. /* Select camera register */
  885. rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
  886. if (rc < 0)
  887. return rc;
  888. /* Write "value" to I2C data port of OV511 */
  889. rc = reg_w(sd, R51x_I2C_DATA, value);
  890. if (rc < 0)
  891. return rc;
  892. /* Initiate 3-byte write cycle */
  893. rc = reg_w(sd, R518_I2C_CTL, 0x01);
  894. if (rc < 0)
  895. return rc;
  896. /* wait for write complete */
  897. msleep(4);
  898. return reg_r8(sd, R518_I2C_CTL);
  899. }
  900. /*
  901. * returns: negative is error, pos or zero is data
  902. *
  903. * The OV518 I2C I/O procedure is different, hence, this function.
  904. * This is normally only called from i2c_r(). Note that this function
  905. * always succeeds regardless of whether the sensor is present and working.
  906. */
  907. static int i2c_r(struct sd *sd, __u8 reg)
  908. {
  909. int rc, value;
  910. /* Select camera register */
  911. rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
  912. if (rc < 0)
  913. return rc;
  914. /* Initiate 2-byte write cycle */
  915. rc = reg_w(sd, R518_I2C_CTL, 0x03);
  916. if (rc < 0)
  917. return rc;
  918. /* Initiate 2-byte read cycle */
  919. rc = reg_w(sd, R518_I2C_CTL, 0x05);
  920. if (rc < 0)
  921. return rc;
  922. value = reg_r(sd, R51x_I2C_DATA);
  923. PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
  924. return value;
  925. }
  926. /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
  927. * the same position as 1's in "mask" are cleared and set to "value". Bits
  928. * that are in the same position as 0's in "mask" are preserved, regardless
  929. * of their respective state in "value".
  930. */
  931. static int i2c_w_mask(struct sd *sd,
  932. __u8 reg,
  933. __u8 value,
  934. __u8 mask)
  935. {
  936. int rc;
  937. __u8 oldval;
  938. value &= mask; /* Enforce mask on value */
  939. rc = i2c_r(sd, reg);
  940. if (rc < 0)
  941. return rc;
  942. oldval = rc & ~mask; /* Clear the masked bits */
  943. value |= oldval; /* Set the desired bits */
  944. return i2c_w(sd, reg, value);
  945. }
  946. /* Temporarily stops OV511 from functioning. Must do this before changing
  947. * registers while the camera is streaming */
  948. static inline int ov51x_stop(struct sd *sd)
  949. {
  950. PDEBUG(D_STREAM, "stopping");
  951. sd->stopped = 1;
  952. return reg_w(sd, OV519_SYS_RESET1, 0x0f);
  953. }
  954. /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
  955. * actually stopped (for performance). */
  956. static inline int ov51x_restart(struct sd *sd)
  957. {
  958. PDEBUG(D_STREAM, "restarting");
  959. if (!sd->stopped)
  960. return 0;
  961. sd->stopped = 0;
  962. /* Reinitialize the stream */
  963. return reg_w(sd, OV519_SYS_RESET1, 0x00);
  964. }
  965. /* This does an initial reset of an OmniVision sensor and ensures that I2C
  966. * is synchronized. Returns <0 on failure.
  967. */
  968. static int init_ov_sensor(struct sd *sd)
  969. {
  970. int i;
  971. /* Reset the sensor */
  972. if (i2c_w(sd, 0x12, 0x80) < 0)
  973. return -EIO;
  974. /* Wait for it to initialize */
  975. msleep(150);
  976. for (i = 0; i < i2c_detect_tries; i++) {
  977. if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
  978. i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
  979. PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
  980. return 0;
  981. }
  982. /* Reset the sensor */
  983. if (i2c_w(sd, 0x12, 0x80) < 0)
  984. return -EIO;
  985. /* Wait for it to initialize */
  986. msleep(150);
  987. /* Dummy read to sync I2C */
  988. if (i2c_r(sd, 0x00) < 0)
  989. return -EIO;
  990. }
  991. return -EIO;
  992. }
  993. /* Set the read and write slave IDs. The "slave" argument is the write slave,
  994. * and the read slave will be set to (slave + 1).
  995. * This should not be called from outside the i2c I/O functions.
  996. * Sets I2C read and write slave IDs. Returns <0 for error
  997. */
  998. static int ov51x_set_slave_ids(struct sd *sd,
  999. __u8 slave)
  1000. {
  1001. int rc;
  1002. rc = reg_w(sd, R51x_I2C_W_SID, slave);
  1003. if (rc < 0)
  1004. return rc;
  1005. return reg_w(sd, R51x_I2C_R_SID, slave + 1);
  1006. }
  1007. static int write_regvals(struct sd *sd,
  1008. const struct ov_regvals *regvals,
  1009. int n)
  1010. {
  1011. int rc;
  1012. while (--n >= 0) {
  1013. rc = reg_w(sd, regvals->reg, regvals->val);
  1014. if (rc < 0)
  1015. return rc;
  1016. regvals++;
  1017. }
  1018. return 0;
  1019. }
  1020. static int write_i2c_regvals(struct sd *sd,
  1021. const struct ov_i2c_regvals *regvals,
  1022. int n)
  1023. {
  1024. int rc;
  1025. while (--n >= 0) {
  1026. rc = i2c_w(sd, regvals->reg, regvals->val);
  1027. if (rc < 0)
  1028. return rc;
  1029. regvals++;
  1030. }
  1031. return 0;
  1032. }
  1033. /****************************************************************************
  1034. *
  1035. * OV511 and sensor configuration
  1036. *
  1037. ***************************************************************************/
  1038. /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
  1039. * the same register settings as the OV8610, since they are very similar.
  1040. */
  1041. static int ov8xx0_configure(struct sd *sd)
  1042. {
  1043. int rc;
  1044. PDEBUG(D_PROBE, "starting ov8xx0 configuration");
  1045. /* Detect sensor (sub)type */
  1046. rc = i2c_r(sd, OV7610_REG_COM_I);
  1047. if (rc < 0) {
  1048. PDEBUG(D_ERR, "Error detecting sensor type");
  1049. return -1;
  1050. }
  1051. if ((rc & 3) == 1) {
  1052. sd->sensor = SEN_OV8610;
  1053. } else {
  1054. PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
  1055. return -1;
  1056. }
  1057. /* Set sensor-specific vars */
  1058. /* sd->sif = 0; already done */
  1059. return 0;
  1060. }
  1061. /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
  1062. * the same register settings as the OV7610, since they are very similar.
  1063. */
  1064. static int ov7xx0_configure(struct sd *sd)
  1065. {
  1066. int rc, high, low;
  1067. PDEBUG(D_PROBE, "starting OV7xx0 configuration");
  1068. /* Detect sensor (sub)type */
  1069. rc = i2c_r(sd, OV7610_REG_COM_I);
  1070. /* add OV7670 here
  1071. * it appears to be wrongly detected as a 7610 by default */
  1072. if (rc < 0) {
  1073. PDEBUG(D_ERR, "Error detecting sensor type");
  1074. return -1;
  1075. }
  1076. if ((rc & 3) == 3) {
  1077. /* quick hack to make OV7670s work */
  1078. high = i2c_r(sd, 0x0a);
  1079. low = i2c_r(sd, 0x0b);
  1080. /* info("%x, %x", high, low); */
  1081. if (high == 0x76 && low == 0x73) {
  1082. PDEBUG(D_PROBE, "Sensor is an OV7670");
  1083. sd->sensor = SEN_OV7670;
  1084. } else {
  1085. PDEBUG(D_PROBE, "Sensor is an OV7610");
  1086. sd->sensor = SEN_OV7610;
  1087. }
  1088. } else if ((rc & 3) == 1) {
  1089. /* I don't know what's different about the 76BE yet. */
  1090. if (i2c_r(sd, 0x15) & 1)
  1091. PDEBUG(D_PROBE, "Sensor is an OV7620AE");
  1092. else
  1093. PDEBUG(D_PROBE, "Sensor is an OV76BE");
  1094. /* OV511+ will return all zero isoc data unless we
  1095. * configure the sensor as a 7620. Someone needs to
  1096. * find the exact reg. setting that causes this. */
  1097. sd->sensor = SEN_OV76BE;
  1098. } else if ((rc & 3) == 0) {
  1099. /* try to read product id registers */
  1100. high = i2c_r(sd, 0x0a);
  1101. if (high < 0) {
  1102. PDEBUG(D_ERR, "Error detecting camera chip PID");
  1103. return high;
  1104. }
  1105. low = i2c_r(sd, 0x0b);
  1106. if (low < 0) {
  1107. PDEBUG(D_ERR, "Error detecting camera chip VER");
  1108. return low;
  1109. }
  1110. if (high == 0x76) {
  1111. switch (low) {
  1112. case 0x30:
  1113. PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
  1114. PDEBUG(D_ERR,
  1115. "7630 is not supported by this driver");
  1116. return -1;
  1117. case 0x40:
  1118. PDEBUG(D_PROBE, "Sensor is an OV7645");
  1119. sd->sensor = SEN_OV7640; /* FIXME */
  1120. break;
  1121. case 0x45:
  1122. PDEBUG(D_PROBE, "Sensor is an OV7645B");
  1123. sd->sensor = SEN_OV7640; /* FIXME */
  1124. break;
  1125. case 0x48:
  1126. PDEBUG(D_PROBE, "Sensor is an OV7648");
  1127. sd->sensor = SEN_OV7640; /* FIXME */
  1128. break;
  1129. default:
  1130. PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
  1131. return -1;
  1132. }
  1133. } else {
  1134. PDEBUG(D_PROBE, "Sensor is an OV7620");
  1135. sd->sensor = SEN_OV7620;
  1136. }
  1137. } else {
  1138. PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
  1139. return -1;
  1140. }
  1141. /* Set sensor-specific vars */
  1142. /* sd->sif = 0; already done */
  1143. return 0;
  1144. }
  1145. /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
  1146. static int ov6xx0_configure(struct sd *sd)
  1147. {
  1148. int rc;
  1149. PDEBUG(D_PROBE, "starting OV6xx0 configuration");
  1150. /* Detect sensor (sub)type */
  1151. rc = i2c_r(sd, OV7610_REG_COM_I);
  1152. if (rc < 0) {
  1153. PDEBUG(D_ERR, "Error detecting sensor type");
  1154. return -1;
  1155. }
  1156. /* Ugh. The first two bits are the version bits, but
  1157. * the entire register value must be used. I guess OVT
  1158. * underestimated how many variants they would make. */
  1159. switch (rc) {
  1160. case 0x00:
  1161. sd->sensor = SEN_OV6630;
  1162. PDEBUG(D_ERR,
  1163. "WARNING: Sensor is an OV66308. Your camera may have");
  1164. PDEBUG(D_ERR, "been misdetected in previous driver versions.");
  1165. break;
  1166. case 0x01:
  1167. sd->sensor = SEN_OV6620;
  1168. break;
  1169. case 0x02:
  1170. sd->sensor = SEN_OV6630;
  1171. PDEBUG(D_PROBE, "Sensor is an OV66308AE");
  1172. break;
  1173. case 0x03:
  1174. sd->sensor = SEN_OV6630;
  1175. PDEBUG(D_PROBE, "Sensor is an OV66308AF");
  1176. break;
  1177. case 0x90:
  1178. sd->sensor = SEN_OV6630;
  1179. PDEBUG(D_ERR,
  1180. "WARNING: Sensor is an OV66307. Your camera may have");
  1181. PDEBUG(D_ERR, "been misdetected in previous driver versions.");
  1182. break;
  1183. default:
  1184. PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
  1185. return -1;
  1186. }
  1187. /* Set sensor-specific vars */
  1188. sd->sif = 1;
  1189. return 0;
  1190. }
  1191. /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
  1192. static void ov51x_led_control(struct sd *sd, int on)
  1193. {
  1194. reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
  1195. }
  1196. /* this function is called at probe time */
  1197. static int sd_config(struct gspca_dev *gspca_dev,
  1198. const struct usb_device_id *id)
  1199. {
  1200. struct sd *sd = (struct sd *) gspca_dev;
  1201. struct cam *cam;
  1202. static const struct ov_regvals init_519[] = {
  1203. { 0x5a, 0x6d }, /* EnableSystem */
  1204. { 0x53, 0x9b },
  1205. { 0x54, 0xff }, /* set bit2 to enable jpeg */
  1206. { 0x5d, 0x03 },
  1207. { 0x49, 0x01 },
  1208. { 0x48, 0x00 },
  1209. /* Set LED pin to output mode. Bit 4 must be cleared or sensor
  1210. * detection will fail. This deserves further investigation. */
  1211. { OV519_GPIO_IO_CTRL0, 0xee },
  1212. { 0x51, 0x0f }, /* SetUsbInit */
  1213. { 0x51, 0x00 },
  1214. { 0x22, 0x00 },
  1215. /* windows reads 0x55 at this point*/
  1216. };
  1217. if (write_regvals(sd, init_519, ARRAY_SIZE(init_519)))
  1218. goto error;
  1219. ov51x_led_control(sd, 0); /* turn LED off */
  1220. /* Test for 76xx */
  1221. if (ov51x_set_slave_ids(sd, OV7xx0_SID) < 0)
  1222. goto error;
  1223. /* The OV519 must be more aggressive about sensor detection since
  1224. * I2C write will never fail if the sensor is not present. We have
  1225. * to try to initialize the sensor to detect its presence */
  1226. if (init_ov_sensor(sd) >= 0) {
  1227. if (ov7xx0_configure(sd) < 0) {
  1228. PDEBUG(D_ERR, "Failed to configure OV7xx0");
  1229. goto error;
  1230. }
  1231. } else {
  1232. /* Test for 6xx0 */
  1233. if (ov51x_set_slave_ids(sd, OV6xx0_SID) < 0)
  1234. goto error;
  1235. if (init_ov_sensor(sd) >= 0) {
  1236. if (ov6xx0_configure(sd) < 0) {
  1237. PDEBUG(D_ERR, "Failed to configure OV6xx0");
  1238. goto error;
  1239. }
  1240. } else {
  1241. /* Test for 8xx0 */
  1242. if (ov51x_set_slave_ids(sd, OV8xx0_SID) < 0)
  1243. goto error;
  1244. if (init_ov_sensor(sd) < 0) {
  1245. PDEBUG(D_ERR,
  1246. "Can't determine sensor slave IDs");
  1247. goto error;
  1248. }
  1249. if (ov8xx0_configure(sd) < 0) {
  1250. PDEBUG(D_ERR,
  1251. "Failed to configure OV8xx0 sensor");
  1252. goto error;
  1253. }
  1254. }
  1255. }
  1256. cam = &gspca_dev->cam;
  1257. cam->epaddr = OV511_ENDPOINT_ADDRESS;
  1258. if (!sd->sif) {
  1259. cam->cam_mode = vga_mode;
  1260. cam->nmodes = ARRAY_SIZE(vga_mode);
  1261. } else {
  1262. cam->cam_mode = sif_mode;
  1263. cam->nmodes = ARRAY_SIZE(sif_mode);
  1264. }
  1265. sd->brightness = BRIGHTNESS_DEF;
  1266. sd->contrast = CONTRAST_DEF;
  1267. sd->colors = COLOR_DEF;
  1268. sd->hflip = HFLIP_DEF;
  1269. sd->vflip = VFLIP_DEF;
  1270. if (sd->sensor != SEN_OV7670)
  1271. gspca_dev->ctrl_dis = (1 << HFLIP_IDX)
  1272. | (1 << VFLIP_IDX);
  1273. return 0;
  1274. error:
  1275. PDEBUG(D_ERR, "OV519 Config failed");
  1276. return -EBUSY;
  1277. }
  1278. /* this function is called at probe and resume time */
  1279. static int sd_init(struct gspca_dev *gspca_dev)
  1280. {
  1281. struct sd *sd = (struct sd *) gspca_dev;
  1282. /* initialize the sensor */
  1283. switch (sd->sensor) {
  1284. case SEN_OV6620:
  1285. if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
  1286. return -EIO;
  1287. break;
  1288. case SEN_OV6630:
  1289. if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
  1290. return -EIO;
  1291. break;
  1292. default:
  1293. /* case SEN_OV7610: */
  1294. /* case SEN_OV76BE: */
  1295. if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
  1296. return -EIO;
  1297. break;
  1298. case SEN_OV7620:
  1299. if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
  1300. return -EIO;
  1301. break;
  1302. case SEN_OV7640:
  1303. if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
  1304. return -EIO;
  1305. break;
  1306. case SEN_OV7670:
  1307. if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
  1308. return -EIO;
  1309. break;
  1310. case SEN_OV8610:
  1311. if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
  1312. return -EIO;
  1313. break;
  1314. }
  1315. return 0;
  1316. }
  1317. /* Sets up the OV519 with the given image parameters
  1318. *
  1319. * OV519 needs a completely different approach, until we can figure out what
  1320. * the individual registers do.
  1321. *
  1322. * Do not put any sensor-specific code in here (including I2C I/O functions)
  1323. */
  1324. static int ov519_mode_init_regs(struct sd *sd)
  1325. {
  1326. static const struct ov_regvals mode_init_519_ov7670[] = {
  1327. { 0x5d, 0x03 }, /* Turn off suspend mode */
  1328. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  1329. { 0x54, 0x0f }, /* bit2 (jpeg enable) */
  1330. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  1331. { 0xa3, 0x18 },
  1332. { 0xa4, 0x04 },
  1333. { 0xa5, 0x28 },
  1334. { 0x37, 0x00 }, /* SetUsbInit */
  1335. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  1336. /* Enable both fields, YUV Input, disable defect comp (why?) */
  1337. { 0x20, 0x0c },
  1338. { 0x21, 0x38 },
  1339. { 0x22, 0x1d },
  1340. { 0x17, 0x50 }, /* undocumented */
  1341. { 0x37, 0x00 }, /* undocumented */
  1342. { 0x40, 0xff }, /* I2C timeout counter */
  1343. { 0x46, 0x00 }, /* I2C clock prescaler */
  1344. { 0x59, 0x04 }, /* new from windrv 090403 */
  1345. { 0xff, 0x00 }, /* undocumented */
  1346. /* windows reads 0x55 at this point, why? */
  1347. };
  1348. static const struct ov_regvals mode_init_519[] = {
  1349. { 0x5d, 0x03 }, /* Turn off suspend mode */
  1350. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  1351. { 0x54, 0x0f }, /* bit2 (jpeg enable) */
  1352. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  1353. { 0xa3, 0x18 },
  1354. { 0xa4, 0x04 },
  1355. { 0xa5, 0x28 },
  1356. { 0x37, 0x00 }, /* SetUsbInit */
  1357. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  1358. /* Enable both fields, YUV Input, disable defect comp (why?) */
  1359. { 0x22, 0x1d },
  1360. { 0x17, 0x50 }, /* undocumented */
  1361. { 0x37, 0x00 }, /* undocumented */
  1362. { 0x40, 0xff }, /* I2C timeout counter */
  1363. { 0x46, 0x00 }, /* I2C clock prescaler */
  1364. { 0x59, 0x04 }, /* new from windrv 090403 */
  1365. { 0xff, 0x00 }, /* undocumented */
  1366. /* windows reads 0x55 at this point, why? */
  1367. };
  1368. /******** Set the mode ********/
  1369. if (sd->sensor != SEN_OV7670) {
  1370. if (write_regvals(sd, mode_init_519,
  1371. ARRAY_SIZE(mode_init_519)))
  1372. return -EIO;
  1373. if (sd->sensor == SEN_OV7640) {
  1374. /* Select 8-bit input mode */
  1375. reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
  1376. }
  1377. } else {
  1378. if (write_regvals(sd, mode_init_519_ov7670,
  1379. ARRAY_SIZE(mode_init_519_ov7670)))
  1380. return -EIO;
  1381. }
  1382. reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
  1383. reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
  1384. reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
  1385. reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
  1386. reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
  1387. reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
  1388. reg_w(sd, OV519_R16_DIVIDER, 0x00);
  1389. reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
  1390. reg_w(sd, 0x26, 0x00); /* Undocumented */
  1391. /******** Set the framerate ********/
  1392. if (frame_rate > 0)
  1393. sd->frame_rate = frame_rate;
  1394. /* FIXME: These are only valid at the max resolution. */
  1395. sd->clockdiv = 0;
  1396. switch (sd->sensor) {
  1397. case SEN_OV7640:
  1398. switch (sd->frame_rate) {
  1399. default:
  1400. /* case 30: */
  1401. reg_w(sd, 0xa4, 0x0c);
  1402. reg_w(sd, 0x23, 0xff);
  1403. break;
  1404. case 25:
  1405. reg_w(sd, 0xa4, 0x0c);
  1406. reg_w(sd, 0x23, 0x1f);
  1407. break;
  1408. case 20:
  1409. reg_w(sd, 0xa4, 0x0c);
  1410. reg_w(sd, 0x23, 0x1b);
  1411. break;
  1412. case 15:
  1413. reg_w(sd, 0xa4, 0x04);
  1414. reg_w(sd, 0x23, 0xff);
  1415. sd->clockdiv = 1;
  1416. break;
  1417. case 10:
  1418. reg_w(sd, 0xa4, 0x04);
  1419. reg_w(sd, 0x23, 0x1f);
  1420. sd->clockdiv = 1;
  1421. break;
  1422. case 5:
  1423. reg_w(sd, 0xa4, 0x04);
  1424. reg_w(sd, 0x23, 0x1b);
  1425. sd->clockdiv = 1;
  1426. break;
  1427. }
  1428. break;
  1429. case SEN_OV8610:
  1430. switch (sd->frame_rate) {
  1431. default: /* 15 fps */
  1432. /* case 15: */
  1433. reg_w(sd, 0xa4, 0x06);
  1434. reg_w(sd, 0x23, 0xff);
  1435. break;
  1436. case 10:
  1437. reg_w(sd, 0xa4, 0x06);
  1438. reg_w(sd, 0x23, 0x1f);
  1439. break;
  1440. case 5:
  1441. reg_w(sd, 0xa4, 0x06);
  1442. reg_w(sd, 0x23, 0x1b);
  1443. break;
  1444. }
  1445. break;
  1446. case SEN_OV7670: /* guesses, based on 7640 */
  1447. PDEBUG(D_STREAM, "Setting framerate to %d fps",
  1448. (sd->frame_rate == 0) ? 15 : sd->frame_rate);
  1449. reg_w(sd, 0xa4, 0x10);
  1450. switch (sd->frame_rate) {
  1451. case 30:
  1452. reg_w(sd, 0x23, 0xff);
  1453. break;
  1454. case 20:
  1455. reg_w(sd, 0x23, 0x1b);
  1456. break;
  1457. default:
  1458. /* case 15: */
  1459. reg_w(sd, 0x23, 0xff);
  1460. sd->clockdiv = 1;
  1461. break;
  1462. }
  1463. break;
  1464. }
  1465. return 0;
  1466. }
  1467. static int mode_init_ov_sensor_regs(struct sd *sd)
  1468. {
  1469. struct gspca_dev *gspca_dev;
  1470. int qvga;
  1471. gspca_dev = &sd->gspca_dev;
  1472. qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  1473. /******** Mode (VGA/QVGA) and sensor specific regs ********/
  1474. switch (sd->sensor) {
  1475. case SEN_OV8610:
  1476. /* For OV8610 qvga means qsvga */
  1477. i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
  1478. break;
  1479. case SEN_OV7610:
  1480. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1481. break;
  1482. case SEN_OV7620:
  1483. /* i2c_w(sd, 0x2b, 0x00); */
  1484. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1485. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  1486. i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
  1487. i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
  1488. i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
  1489. i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
  1490. i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
  1491. break;
  1492. case SEN_OV76BE:
  1493. /* i2c_w(sd, 0x2b, 0x00); */
  1494. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1495. break;
  1496. case SEN_OV7640:
  1497. /* i2c_w(sd, 0x2b, 0x00); */
  1498. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1499. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  1500. /* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
  1501. /* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
  1502. /* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
  1503. /* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
  1504. /* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
  1505. break;
  1506. case SEN_OV7670:
  1507. /* set COM7_FMT_VGA or COM7_FMT_QVGA
  1508. * do we need to set anything else?
  1509. * HSTART etc are set in set_ov_sensor_window itself */
  1510. i2c_w_mask(sd, OV7670_REG_COM7,
  1511. qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
  1512. OV7670_COM7_FMT_MASK);
  1513. break;
  1514. case SEN_OV6620:
  1515. case SEN_OV6630:
  1516. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1517. break;
  1518. default:
  1519. return -EINVAL;
  1520. }
  1521. /******** Palette-specific regs ********/
  1522. if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
  1523. /* not valid on the OV6620/OV7620/6630? */
  1524. i2c_w_mask(sd, 0x0e, 0x00, 0x40);
  1525. }
  1526. /* The OV518 needs special treatment. Although both the OV518
  1527. * and the OV6630 support a 16-bit video bus, only the 8 bit Y
  1528. * bus is actually used. The UV bus is tied to ground.
  1529. * Therefore, the OV6630 needs to be in 8-bit multiplexed
  1530. * output mode */
  1531. /* OV7640 is 8-bit only */
  1532. if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV7640)
  1533. i2c_w_mask(sd, 0x13, 0x00, 0x20);
  1534. /******** Clock programming ********/
  1535. /* The OV6620 needs special handling. This prevents the
  1536. * severe banding that normally occurs */
  1537. if (sd->sensor == SEN_OV6620) {
  1538. /* Clock down */
  1539. i2c_w(sd, 0x2a, 0x04);
  1540. i2c_w(sd, 0x11, sd->clockdiv);
  1541. i2c_w(sd, 0x2a, 0x84);
  1542. /* This next setting is critical. It seems to improve
  1543. * the gain or the contrast. The "reserved" bits seem
  1544. * to have some effect in this case. */
  1545. i2c_w(sd, 0x2d, 0x85);
  1546. } else {
  1547. i2c_w(sd, 0x11, sd->clockdiv);
  1548. }
  1549. /******** Special Features ********/
  1550. /* no evidence this is possible with OV7670, either */
  1551. /* Test Pattern */
  1552. if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670)
  1553. i2c_w_mask(sd, 0x12, 0x00, 0x02);
  1554. /* Enable auto white balance */
  1555. if (sd->sensor == SEN_OV7670)
  1556. i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
  1557. OV7670_COM8_AWB);
  1558. else
  1559. i2c_w_mask(sd, 0x12, 0x04, 0x04);
  1560. /* This will go away as soon as ov51x_mode_init_sensor_regs() */
  1561. /* is fully tested. */
  1562. /* 7620/6620/6630? don't have register 0x35, so play it safe */
  1563. if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
  1564. if (!qvga)
  1565. i2c_w(sd, 0x35, 0x9e);
  1566. else
  1567. i2c_w(sd, 0x35, 0x1e);
  1568. }
  1569. return 0;
  1570. }
  1571. static void sethvflip(struct sd *sd)
  1572. {
  1573. if (sd->sensor != SEN_OV7670)
  1574. return;
  1575. if (sd->gspca_dev.streaming)
  1576. ov51x_stop(sd);
  1577. i2c_w_mask(sd, OV7670_REG_MVFP,
  1578. OV7670_MVFP_MIRROR * sd->hflip
  1579. | OV7670_MVFP_VFLIP * sd->vflip,
  1580. OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
  1581. if (sd->gspca_dev.streaming)
  1582. ov51x_restart(sd);
  1583. }
  1584. static int set_ov_sensor_window(struct sd *sd)
  1585. {
  1586. struct gspca_dev *gspca_dev;
  1587. int qvga;
  1588. int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
  1589. int ret, hstart, hstop, vstop, vstart;
  1590. __u8 v;
  1591. gspca_dev = &sd->gspca_dev;
  1592. qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  1593. /* The different sensor ICs handle setting up of window differently.
  1594. * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
  1595. switch (sd->sensor) {
  1596. case SEN_OV8610:
  1597. hwsbase = 0x1e;
  1598. hwebase = 0x1e;
  1599. vwsbase = 0x02;
  1600. vwebase = 0x02;
  1601. break;
  1602. case SEN_OV7610:
  1603. case SEN_OV76BE:
  1604. hwsbase = 0x38;
  1605. hwebase = 0x3a;
  1606. vwsbase = vwebase = 0x05;
  1607. break;
  1608. case SEN_OV6620:
  1609. case SEN_OV6630:
  1610. hwsbase = 0x38;
  1611. hwebase = 0x3a;
  1612. vwsbase = 0x05;
  1613. vwebase = 0x06;
  1614. break;
  1615. case SEN_OV7620:
  1616. hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
  1617. hwebase = 0x2f;
  1618. vwsbase = vwebase = 0x05;
  1619. break;
  1620. case SEN_OV7640:
  1621. hwsbase = 0x1a;
  1622. hwebase = 0x1a;
  1623. vwsbase = vwebase = 0x03;
  1624. break;
  1625. case SEN_OV7670:
  1626. /*handling of OV7670 hardware sensor start and stop values
  1627. * is very odd, compared to the other OV sensors */
  1628. vwsbase = vwebase = hwebase = hwsbase = 0x00;
  1629. break;
  1630. default:
  1631. return -EINVAL;
  1632. }
  1633. switch (sd->sensor) {
  1634. case SEN_OV6620:
  1635. case SEN_OV6630:
  1636. if (qvga) { /* QCIF */
  1637. hwscale = 0;
  1638. vwscale = 0;
  1639. } else { /* CIF */
  1640. hwscale = 1;
  1641. vwscale = 1; /* The datasheet says 0;
  1642. * it's wrong */
  1643. }
  1644. break;
  1645. case SEN_OV8610:
  1646. if (qvga) { /* QSVGA */
  1647. hwscale = 1;
  1648. vwscale = 1;
  1649. } else { /* SVGA */
  1650. hwscale = 2;
  1651. vwscale = 2;
  1652. }
  1653. break;
  1654. default: /* SEN_OV7xx0 */
  1655. if (qvga) { /* QVGA */
  1656. hwscale = 1;
  1657. vwscale = 0;
  1658. } else { /* VGA */
  1659. hwscale = 2;
  1660. vwscale = 1;
  1661. }
  1662. }
  1663. ret = mode_init_ov_sensor_regs(sd);
  1664. if (ret < 0)
  1665. return ret;
  1666. if (sd->sensor == SEN_OV8610) {
  1667. i2c_w_mask(sd, 0x2d, 0x05, 0x40);
  1668. /* old 0x95, new 0x05 from windrv 090403 */
  1669. /* bits 5-7: reserved */
  1670. i2c_w_mask(sd, 0x28, 0x20, 0x20);
  1671. /* bit 5: progressive mode on */
  1672. }
  1673. /* The below is wrong for OV7670s because their window registers
  1674. * only store the high bits in 0x17 to 0x1a */
  1675. /* SRH Use sd->max values instead of requested win values */
  1676. /* SCS Since we're sticking with only the max hardware widths
  1677. * for a given mode */
  1678. /* I can hard code this for OV7670s */
  1679. /* Yes, these numbers do look odd, but they're tested and work! */
  1680. if (sd->sensor == SEN_OV7670) {
  1681. if (qvga) { /* QVGA from ov7670.c by
  1682. * Jonathan Corbet */
  1683. hstart = 164;
  1684. hstop = 20;
  1685. vstart = 14;
  1686. vstop = 494;
  1687. } else { /* VGA */
  1688. hstart = 158;
  1689. hstop = 14;
  1690. vstart = 10;
  1691. vstop = 490;
  1692. }
  1693. /* OV7670 hardware window registers are split across
  1694. * multiple locations */
  1695. i2c_w(sd, OV7670_REG_HSTART, hstart >> 3);
  1696. i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3);
  1697. v = i2c_r(sd, OV7670_REG_HREF);
  1698. v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07);
  1699. msleep(10); /* need to sleep between read and write to
  1700. * same reg! */
  1701. i2c_w(sd, OV7670_REG_HREF, v);
  1702. i2c_w(sd, OV7670_REG_VSTART, vstart >> 2);
  1703. i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2);
  1704. v = i2c_r(sd, OV7670_REG_VREF);
  1705. v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03);
  1706. msleep(10); /* need to sleep between read and write to
  1707. * same reg! */
  1708. i2c_w(sd, OV7670_REG_VREF, v);
  1709. sethvflip(sd);
  1710. } else {
  1711. i2c_w(sd, 0x17, hwsbase);
  1712. i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale));
  1713. i2c_w(sd, 0x19, vwsbase);
  1714. i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale));
  1715. }
  1716. return 0;
  1717. }
  1718. /* -- start the camera -- */
  1719. static int sd_start(struct gspca_dev *gspca_dev)
  1720. {
  1721. struct sd *sd = (struct sd *) gspca_dev;
  1722. int ret;
  1723. ret = ov519_mode_init_regs(sd);
  1724. if (ret < 0)
  1725. goto out;
  1726. ret = set_ov_sensor_window(sd);
  1727. if (ret < 0)
  1728. goto out;
  1729. ret = ov51x_restart(sd);
  1730. if (ret < 0)
  1731. goto out;
  1732. ov51x_led_control(sd, 1);
  1733. return 0;
  1734. out:
  1735. PDEBUG(D_ERR, "camera start error:%d", ret);
  1736. return ret;
  1737. }
  1738. static void sd_stopN(struct gspca_dev *gspca_dev)
  1739. {
  1740. struct sd *sd = (struct sd *) gspca_dev;
  1741. ov51x_stop(sd);
  1742. ov51x_led_control(sd, 0);
  1743. }
  1744. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1745. struct gspca_frame *frame, /* target */
  1746. __u8 *data, /* isoc packet */
  1747. int len) /* iso packet length */
  1748. {
  1749. /* Header of ov519 is 16 bytes:
  1750. * Byte Value Description
  1751. * 0 0xff magic
  1752. * 1 0xff magic
  1753. * 2 0xff magic
  1754. * 3 0xXX 0x50 = SOF, 0x51 = EOF
  1755. * 9 0xXX 0x01 initial frame without data,
  1756. * 0x00 standard frame with image
  1757. * 14 Lo in EOF: length of image data / 8
  1758. * 15 Hi
  1759. */
  1760. if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
  1761. switch (data[3]) {
  1762. case 0x50: /* start of frame */
  1763. #define HDRSZ 16
  1764. data += HDRSZ;
  1765. len -= HDRSZ;
  1766. #undef HDRSZ
  1767. if (data[0] == 0xff || data[1] == 0xd8)
  1768. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  1769. data, len);
  1770. else
  1771. gspca_dev->last_packet_type = DISCARD_PACKET;
  1772. return;
  1773. case 0x51: /* end of frame */
  1774. if (data[9] != 0)
  1775. gspca_dev->last_packet_type = DISCARD_PACKET;
  1776. gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  1777. data, 0);
  1778. return;
  1779. }
  1780. }
  1781. /* intermediate packet */
  1782. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  1783. data, len);
  1784. }
  1785. /* -- management routines -- */
  1786. static void setbrightness(struct gspca_dev *gspca_dev)
  1787. {
  1788. struct sd *sd = (struct sd *) gspca_dev;
  1789. int val;
  1790. val = sd->brightness;
  1791. switch (sd->sensor) {
  1792. case SEN_OV8610:
  1793. case SEN_OV7610:
  1794. case SEN_OV76BE:
  1795. case SEN_OV6620:
  1796. case SEN_OV6630:
  1797. case SEN_OV7640:
  1798. i2c_w(sd, OV7610_REG_BRT, val);
  1799. break;
  1800. case SEN_OV7620:
  1801. /* 7620 doesn't like manual changes when in auto mode */
  1802. /*fixme
  1803. * if (!sd->auto_brt) */
  1804. i2c_w(sd, OV7610_REG_BRT, val);
  1805. break;
  1806. case SEN_OV7670:
  1807. /*win trace
  1808. * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
  1809. i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
  1810. break;
  1811. }
  1812. }
  1813. static void setcontrast(struct gspca_dev *gspca_dev)
  1814. {
  1815. struct sd *sd = (struct sd *) gspca_dev;
  1816. int val;
  1817. val = sd->contrast;
  1818. switch (sd->sensor) {
  1819. case SEN_OV7610:
  1820. case SEN_OV6620:
  1821. i2c_w(sd, OV7610_REG_CNT, val);
  1822. break;
  1823. case SEN_OV6630:
  1824. i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
  1825. case SEN_OV8610: {
  1826. static const __u8 ctab[] = {
  1827. 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
  1828. };
  1829. /* Use Y gamma control instead. Bit 0 enables it. */
  1830. i2c_w(sd, 0x64, ctab[val >> 5]);
  1831. break;
  1832. }
  1833. case SEN_OV7620: {
  1834. static const __u8 ctab[] = {
  1835. 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
  1836. 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
  1837. };
  1838. /* Use Y gamma control instead. Bit 0 enables it. */
  1839. i2c_w(sd, 0x64, ctab[val >> 4]);
  1840. break;
  1841. }
  1842. case SEN_OV7640:
  1843. /* Use gain control instead. */
  1844. i2c_w(sd, OV7610_REG_GAIN, val >> 2);
  1845. break;
  1846. case SEN_OV7670:
  1847. /* check that this isn't just the same as ov7610 */
  1848. i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
  1849. break;
  1850. }
  1851. }
  1852. static void setcolors(struct gspca_dev *gspca_dev)
  1853. {
  1854. struct sd *sd = (struct sd *) gspca_dev;
  1855. int val;
  1856. val = sd->colors;
  1857. switch (sd->sensor) {
  1858. case SEN_OV8610:
  1859. case SEN_OV7610:
  1860. case SEN_OV76BE:
  1861. case SEN_OV6620:
  1862. case SEN_OV6630:
  1863. i2c_w(sd, OV7610_REG_SAT, val);
  1864. break;
  1865. case SEN_OV7620:
  1866. /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
  1867. /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
  1868. if (rc < 0)
  1869. goto out; */
  1870. i2c_w(sd, OV7610_REG_SAT, val);
  1871. break;
  1872. case SEN_OV7640:
  1873. i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
  1874. break;
  1875. case SEN_OV7670:
  1876. /* supported later once I work out how to do it
  1877. * transparently fail now! */
  1878. /* set REG_COM13 values for UV sat auto mode */
  1879. break;
  1880. }
  1881. }
  1882. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1883. {
  1884. struct sd *sd = (struct sd *) gspca_dev;
  1885. sd->brightness = val;
  1886. if (gspca_dev->streaming)
  1887. setbrightness(gspca_dev);
  1888. return 0;
  1889. }
  1890. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1891. {
  1892. struct sd *sd = (struct sd *) gspca_dev;
  1893. *val = sd->brightness;
  1894. return 0;
  1895. }
  1896. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1897. {
  1898. struct sd *sd = (struct sd *) gspca_dev;
  1899. sd->contrast = val;
  1900. if (gspca_dev->streaming)
  1901. setcontrast(gspca_dev);
  1902. return 0;
  1903. }
  1904. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1905. {
  1906. struct sd *sd = (struct sd *) gspca_dev;
  1907. *val = sd->contrast;
  1908. return 0;
  1909. }
  1910. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1911. {
  1912. struct sd *sd = (struct sd *) gspca_dev;
  1913. sd->colors = val;
  1914. if (gspca_dev->streaming)
  1915. setcolors(gspca_dev);
  1916. return 0;
  1917. }
  1918. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1919. {
  1920. struct sd *sd = (struct sd *) gspca_dev;
  1921. *val = sd->colors;
  1922. return 0;
  1923. }
  1924. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  1925. {
  1926. struct sd *sd = (struct sd *) gspca_dev;
  1927. sd->hflip = val;
  1928. if (gspca_dev->streaming)
  1929. sethvflip(sd);
  1930. return 0;
  1931. }
  1932. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1933. {
  1934. struct sd *sd = (struct sd *) gspca_dev;
  1935. *val = sd->hflip;
  1936. return 0;
  1937. }
  1938. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1939. {
  1940. struct sd *sd = (struct sd *) gspca_dev;
  1941. sd->vflip = val;
  1942. if (gspca_dev->streaming)
  1943. sethvflip(sd);
  1944. return 0;
  1945. }
  1946. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1947. {
  1948. struct sd *sd = (struct sd *) gspca_dev;
  1949. *val = sd->vflip;
  1950. return 0;
  1951. }
  1952. /* sub-driver description */
  1953. static const struct sd_desc sd_desc = {
  1954. .name = MODULE_NAME,
  1955. .ctrls = sd_ctrls,
  1956. .nctrls = ARRAY_SIZE(sd_ctrls),
  1957. .config = sd_config,
  1958. .init = sd_init,
  1959. .start = sd_start,
  1960. .stopN = sd_stopN,
  1961. .pkt_scan = sd_pkt_scan,
  1962. };
  1963. /* -- module initialisation -- */
  1964. static const __devinitdata struct usb_device_id device_table[] = {
  1965. {USB_DEVICE(0x041e, 0x4052)},
  1966. {USB_DEVICE(0x041e, 0x405f)},
  1967. {USB_DEVICE(0x041e, 0x4060)},
  1968. {USB_DEVICE(0x041e, 0x4061)},
  1969. {USB_DEVICE(0x041e, 0x4064)},
  1970. {USB_DEVICE(0x041e, 0x4068)},
  1971. {USB_DEVICE(0x045e, 0x028c)},
  1972. {USB_DEVICE(0x054c, 0x0154)},
  1973. {USB_DEVICE(0x054c, 0x0155)},
  1974. {USB_DEVICE(0x05a9, 0x0519)},
  1975. {USB_DEVICE(0x05a9, 0x0530)},
  1976. {USB_DEVICE(0x05a9, 0x4519)},
  1977. {USB_DEVICE(0x05a9, 0x8519)},
  1978. {}
  1979. };
  1980. MODULE_DEVICE_TABLE(usb, device_table);
  1981. /* -- device connect -- */
  1982. static int sd_probe(struct usb_interface *intf,
  1983. const struct usb_device_id *id)
  1984. {
  1985. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1986. THIS_MODULE);
  1987. }
  1988. static struct usb_driver sd_driver = {
  1989. .name = MODULE_NAME,
  1990. .id_table = device_table,
  1991. .probe = sd_probe,
  1992. .disconnect = gspca_disconnect,
  1993. #ifdef CONFIG_PM
  1994. .suspend = gspca_suspend,
  1995. .resume = gspca_resume,
  1996. #endif
  1997. };
  1998. /* -- module insert / remove -- */
  1999. static int __init sd_mod_init(void)
  2000. {
  2001. if (usb_register(&sd_driver) < 0)
  2002. return -1;
  2003. PDEBUG(D_PROBE, "registered");
  2004. return 0;
  2005. }
  2006. static void __exit sd_mod_exit(void)
  2007. {
  2008. usb_deregister(&sd_driver);
  2009. PDEBUG(D_PROBE, "deregistered");
  2010. }
  2011. module_init(sd_mod_init);
  2012. module_exit(sd_mod_exit);
  2013. module_param(frame_rate, int, 0644);
  2014. MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");