ov519.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422
  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. __u8 packet_nr;
  48. char bridge;
  49. #define BRIDGE_OV511 0
  50. #define BRIDGE_OV511PLUS 1
  51. #define BRIDGE_OV518 2
  52. #define BRIDGE_OV518PLUS 3
  53. #define BRIDGE_OV519 4
  54. #define BRIDGE_MASK 7
  55. char invert_led;
  56. #define BRIDGE_INVERT_LED 8
  57. /* Determined by sensor type */
  58. __u8 sif;
  59. __u8 brightness;
  60. __u8 contrast;
  61. __u8 colors;
  62. __u8 hflip;
  63. __u8 vflip;
  64. __u8 autobrightness;
  65. __u8 freq;
  66. __u8 stopped; /* Streaming is temporarily paused */
  67. __u8 frame_rate; /* current Framerate */
  68. __u8 clockdiv; /* clockdiv override */
  69. char sensor; /* Type of image sensor chip (SEN_*) */
  70. #define SEN_UNKNOWN 0
  71. #define SEN_OV6620 1
  72. #define SEN_OV6630 2
  73. #define SEN_OV66308AF 3
  74. #define SEN_OV7610 4
  75. #define SEN_OV7620 5
  76. #define SEN_OV7640 6
  77. #define SEN_OV7670 7
  78. #define SEN_OV76BE 8
  79. #define SEN_OV8610 9
  80. };
  81. /* V4L2 controls supported by the driver */
  82. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  86. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  87. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  88. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  89. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  90. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  91. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  92. static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val);
  93. static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val);
  94. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  95. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  96. static void setbrightness(struct gspca_dev *gspca_dev);
  97. static void setcontrast(struct gspca_dev *gspca_dev);
  98. static void setcolors(struct gspca_dev *gspca_dev);
  99. static void setautobrightness(struct sd *sd);
  100. static void setfreq(struct sd *sd);
  101. static const struct ctrl sd_ctrls[] = {
  102. {
  103. {
  104. .id = V4L2_CID_BRIGHTNESS,
  105. .type = V4L2_CTRL_TYPE_INTEGER,
  106. .name = "Brightness",
  107. .minimum = 0,
  108. .maximum = 255,
  109. .step = 1,
  110. #define BRIGHTNESS_DEF 127
  111. .default_value = BRIGHTNESS_DEF,
  112. },
  113. .set = sd_setbrightness,
  114. .get = sd_getbrightness,
  115. },
  116. {
  117. {
  118. .id = V4L2_CID_CONTRAST,
  119. .type = V4L2_CTRL_TYPE_INTEGER,
  120. .name = "Contrast",
  121. .minimum = 0,
  122. .maximum = 255,
  123. .step = 1,
  124. #define CONTRAST_DEF 127
  125. .default_value = CONTRAST_DEF,
  126. },
  127. .set = sd_setcontrast,
  128. .get = sd_getcontrast,
  129. },
  130. {
  131. {
  132. .id = V4L2_CID_SATURATION,
  133. .type = V4L2_CTRL_TYPE_INTEGER,
  134. .name = "Color",
  135. .minimum = 0,
  136. .maximum = 255,
  137. .step = 1,
  138. #define COLOR_DEF 127
  139. .default_value = COLOR_DEF,
  140. },
  141. .set = sd_setcolors,
  142. .get = sd_getcolors,
  143. },
  144. /* The flip controls work with ov7670 only */
  145. #define HFLIP_IDX 3
  146. {
  147. {
  148. .id = V4L2_CID_HFLIP,
  149. .type = V4L2_CTRL_TYPE_BOOLEAN,
  150. .name = "Mirror",
  151. .minimum = 0,
  152. .maximum = 1,
  153. .step = 1,
  154. #define HFLIP_DEF 0
  155. .default_value = HFLIP_DEF,
  156. },
  157. .set = sd_sethflip,
  158. .get = sd_gethflip,
  159. },
  160. #define VFLIP_IDX 4
  161. {
  162. {
  163. .id = V4L2_CID_VFLIP,
  164. .type = V4L2_CTRL_TYPE_BOOLEAN,
  165. .name = "Vflip",
  166. .minimum = 0,
  167. .maximum = 1,
  168. .step = 1,
  169. #define VFLIP_DEF 0
  170. .default_value = VFLIP_DEF,
  171. },
  172. .set = sd_setvflip,
  173. .get = sd_getvflip,
  174. },
  175. #define AUTOBRIGHT_IDX 5
  176. {
  177. {
  178. .id = V4L2_CID_AUTOBRIGHTNESS,
  179. .type = V4L2_CTRL_TYPE_BOOLEAN,
  180. .name = "Auto Brightness",
  181. .minimum = 0,
  182. .maximum = 1,
  183. .step = 1,
  184. #define AUTOBRIGHT_DEF 1
  185. .default_value = AUTOBRIGHT_DEF,
  186. },
  187. .set = sd_setautobrightness,
  188. .get = sd_getautobrightness,
  189. },
  190. #define FREQ_IDX 6
  191. {
  192. {
  193. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  194. .type = V4L2_CTRL_TYPE_MENU,
  195. .name = "Light frequency filter",
  196. .minimum = 0,
  197. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  198. .step = 1,
  199. #define FREQ_DEF 0
  200. .default_value = FREQ_DEF,
  201. },
  202. .set = sd_setfreq,
  203. .get = sd_getfreq,
  204. },
  205. #define OV7670_FREQ_IDX 7
  206. {
  207. {
  208. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  209. .type = V4L2_CTRL_TYPE_MENU,
  210. .name = "Light frequency filter",
  211. .minimum = 0,
  212. .maximum = 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */
  213. .step = 1,
  214. #define OV7670_FREQ_DEF 3
  215. .default_value = OV7670_FREQ_DEF,
  216. },
  217. .set = sd_setfreq,
  218. .get = sd_getfreq,
  219. },
  220. };
  221. static const struct v4l2_pix_format ov519_vga_mode[] = {
  222. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  223. .bytesperline = 320,
  224. .sizeimage = 320 * 240 * 3 / 8 + 590,
  225. .colorspace = V4L2_COLORSPACE_JPEG,
  226. .priv = 1},
  227. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  228. .bytesperline = 640,
  229. .sizeimage = 640 * 480 * 3 / 8 + 590,
  230. .colorspace = V4L2_COLORSPACE_JPEG,
  231. .priv = 0},
  232. };
  233. static const struct v4l2_pix_format ov519_sif_mode[] = {
  234. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  235. .bytesperline = 160,
  236. .sizeimage = 160 * 120 * 3 / 8 + 590,
  237. .colorspace = V4L2_COLORSPACE_JPEG,
  238. .priv = 3},
  239. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  240. .bytesperline = 176,
  241. .sizeimage = 176 * 144 * 3 / 8 + 590,
  242. .colorspace = V4L2_COLORSPACE_JPEG,
  243. .priv = 1},
  244. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  245. .bytesperline = 320,
  246. .sizeimage = 320 * 240 * 3 / 8 + 590,
  247. .colorspace = V4L2_COLORSPACE_JPEG,
  248. .priv = 2},
  249. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  250. .bytesperline = 352,
  251. .sizeimage = 352 * 288 * 3 / 8 + 590,
  252. .colorspace = V4L2_COLORSPACE_JPEG,
  253. .priv = 0},
  254. };
  255. static const struct v4l2_pix_format ov518_vga_mode[] = {
  256. {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  257. .bytesperline = 320,
  258. .sizeimage = 320 * 240 * 3 / 8 + 590,
  259. .colorspace = V4L2_COLORSPACE_JPEG,
  260. .priv = 1},
  261. {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  262. .bytesperline = 640,
  263. .sizeimage = 640 * 480 * 3 / 8 + 590,
  264. .colorspace = V4L2_COLORSPACE_JPEG,
  265. .priv = 0},
  266. };
  267. static const struct v4l2_pix_format ov518_sif_mode[] = {
  268. {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  269. .bytesperline = 160,
  270. .sizeimage = 40000,
  271. .colorspace = V4L2_COLORSPACE_JPEG,
  272. .priv = 3},
  273. {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  274. .bytesperline = 176,
  275. .sizeimage = 40000,
  276. .colorspace = V4L2_COLORSPACE_JPEG,
  277. .priv = 1},
  278. {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  279. .bytesperline = 320,
  280. .sizeimage = 320 * 240 * 3 / 8 + 590,
  281. .colorspace = V4L2_COLORSPACE_JPEG,
  282. .priv = 2},
  283. {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  284. .bytesperline = 352,
  285. .sizeimage = 352 * 288 * 3 / 8 + 590,
  286. .colorspace = V4L2_COLORSPACE_JPEG,
  287. .priv = 0},
  288. };
  289. static const struct v4l2_pix_format ov511_vga_mode[] = {
  290. {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  291. .bytesperline = 320,
  292. .sizeimage = 320 * 240 * 3,
  293. .colorspace = V4L2_COLORSPACE_JPEG,
  294. .priv = 1},
  295. {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  296. .bytesperline = 640,
  297. .sizeimage = 640 * 480 * 2,
  298. .colorspace = V4L2_COLORSPACE_JPEG,
  299. .priv = 0},
  300. };
  301. static const struct v4l2_pix_format ov511_sif_mode[] = {
  302. {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  303. .bytesperline = 160,
  304. .sizeimage = 40000,
  305. .colorspace = V4L2_COLORSPACE_JPEG,
  306. .priv = 3},
  307. {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  308. .bytesperline = 176,
  309. .sizeimage = 40000,
  310. .colorspace = V4L2_COLORSPACE_JPEG,
  311. .priv = 1},
  312. {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  313. .bytesperline = 320,
  314. .sizeimage = 320 * 240 * 3,
  315. .colorspace = V4L2_COLORSPACE_JPEG,
  316. .priv = 2},
  317. {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  318. .bytesperline = 352,
  319. .sizeimage = 352 * 288 * 3,
  320. .colorspace = V4L2_COLORSPACE_JPEG,
  321. .priv = 0},
  322. };
  323. /* Registers common to OV511 / OV518 */
  324. #define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
  325. #define R51x_SYS_RESET 0x50
  326. /* Reset type flags */
  327. #define OV511_RESET_OMNICE 0x08
  328. #define R51x_SYS_INIT 0x53
  329. #define R51x_SYS_SNAP 0x52
  330. #define R51x_SYS_CUST_ID 0x5F
  331. #define R51x_COMP_LUT_BEGIN 0x80
  332. /* OV511 Camera interface register numbers */
  333. #define R511_CAM_DELAY 0x10
  334. #define R511_CAM_EDGE 0x11
  335. #define R511_CAM_PXCNT 0x12
  336. #define R511_CAM_LNCNT 0x13
  337. #define R511_CAM_PXDIV 0x14
  338. #define R511_CAM_LNDIV 0x15
  339. #define R511_CAM_UV_EN 0x16
  340. #define R511_CAM_LINE_MODE 0x17
  341. #define R511_CAM_OPTS 0x18
  342. #define R511_SNAP_FRAME 0x19
  343. #define R511_SNAP_PXCNT 0x1A
  344. #define R511_SNAP_LNCNT 0x1B
  345. #define R511_SNAP_PXDIV 0x1C
  346. #define R511_SNAP_LNDIV 0x1D
  347. #define R511_SNAP_UV_EN 0x1E
  348. #define R511_SNAP_UV_EN 0x1E
  349. #define R511_SNAP_OPTS 0x1F
  350. #define R511_DRAM_FLOW_CTL 0x20
  351. #define R511_FIFO_OPTS 0x31
  352. #define R511_I2C_CTL 0x40
  353. #define R511_SYS_LED_CTL 0x55 /* OV511+ only */
  354. #define R511_COMP_EN 0x78
  355. #define R511_COMP_LUT_EN 0x79
  356. /* OV518 Camera interface register numbers */
  357. #define R518_GPIO_OUT 0x56 /* OV518(+) only */
  358. #define R518_GPIO_CTL 0x57 /* OV518(+) only */
  359. /* OV519 Camera interface register numbers */
  360. #define OV519_R10_H_SIZE 0x10
  361. #define OV519_R11_V_SIZE 0x11
  362. #define OV519_R12_X_OFFSETL 0x12
  363. #define OV519_R13_X_OFFSETH 0x13
  364. #define OV519_R14_Y_OFFSETL 0x14
  365. #define OV519_R15_Y_OFFSETH 0x15
  366. #define OV519_R16_DIVIDER 0x16
  367. #define OV519_R20_DFR 0x20
  368. #define OV519_R25_FORMAT 0x25
  369. /* OV519 System Controller register numbers */
  370. #define OV519_SYS_RESET1 0x51
  371. #define OV519_SYS_EN_CLK1 0x54
  372. #define OV519_GPIO_DATA_OUT0 0x71
  373. #define OV519_GPIO_IO_CTRL0 0x72
  374. #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
  375. /* I2C registers */
  376. #define R51x_I2C_W_SID 0x41
  377. #define R51x_I2C_SADDR_3 0x42
  378. #define R51x_I2C_SADDR_2 0x43
  379. #define R51x_I2C_R_SID 0x44
  380. #define R51x_I2C_DATA 0x45
  381. #define R518_I2C_CTL 0x47 /* OV518(+) only */
  382. /* I2C ADDRESSES */
  383. #define OV7xx0_SID 0x42
  384. #define OV8xx0_SID 0xa0
  385. #define OV6xx0_SID 0xc0
  386. /* OV7610 registers */
  387. #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
  388. #define OV7610_REG_BLUE 0x01 /* blue channel balance */
  389. #define OV7610_REG_RED 0x02 /* red channel balance */
  390. #define OV7610_REG_SAT 0x03 /* saturation */
  391. #define OV8610_REG_HUE 0x04 /* 04 reserved */
  392. #define OV7610_REG_CNT 0x05 /* Y contrast */
  393. #define OV7610_REG_BRT 0x06 /* Y brightness */
  394. #define OV7610_REG_COM_C 0x14 /* misc common regs */
  395. #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
  396. #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
  397. #define OV7610_REG_COM_I 0x29 /* misc settings */
  398. /* OV7670 registers */
  399. #define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
  400. #define OV7670_REG_BLUE 0x01 /* blue gain */
  401. #define OV7670_REG_RED 0x02 /* red gain */
  402. #define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
  403. #define OV7670_REG_COM1 0x04 /* Control 1 */
  404. #define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
  405. #define OV7670_REG_COM3 0x0c /* Control 3 */
  406. #define OV7670_REG_COM4 0x0d /* Control 4 */
  407. #define OV7670_REG_COM5 0x0e /* All "reserved" */
  408. #define OV7670_REG_COM6 0x0f /* Control 6 */
  409. #define OV7670_REG_AECH 0x10 /* More bits of AEC value */
  410. #define OV7670_REG_CLKRC 0x11 /* Clock control */
  411. #define OV7670_REG_COM7 0x12 /* Control 7 */
  412. #define OV7670_COM7_FMT_VGA 0x00
  413. #define OV7670_COM7_YUV 0x00 /* YUV */
  414. #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
  415. #define OV7670_COM7_FMT_MASK 0x38
  416. #define OV7670_COM7_RESET 0x80 /* Register reset */
  417. #define OV7670_REG_COM8 0x13 /* Control 8 */
  418. #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
  419. #define OV7670_COM8_AWB 0x02 /* White balance enable */
  420. #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
  421. #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
  422. #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
  423. #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
  424. #define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
  425. #define OV7670_REG_COM10 0x15 /* Control 10 */
  426. #define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
  427. #define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
  428. #define OV7670_REG_VSTART 0x19 /* Vert start high bits */
  429. #define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
  430. #define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
  431. #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
  432. #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
  433. #define OV7670_REG_AEW 0x24 /* AGC upper limit */
  434. #define OV7670_REG_AEB 0x25 /* AGC lower limit */
  435. #define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
  436. #define OV7670_REG_HREF 0x32 /* HREF pieces */
  437. #define OV7670_REG_TSLB 0x3a /* lots of stuff */
  438. #define OV7670_REG_COM11 0x3b /* Control 11 */
  439. #define OV7670_COM11_EXP 0x02
  440. #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
  441. #define OV7670_REG_COM12 0x3c /* Control 12 */
  442. #define OV7670_REG_COM13 0x3d /* Control 13 */
  443. #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
  444. #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
  445. #define OV7670_REG_COM14 0x3e /* Control 14 */
  446. #define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
  447. #define OV7670_REG_COM15 0x40 /* Control 15 */
  448. #define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
  449. #define OV7670_REG_COM16 0x41 /* Control 16 */
  450. #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
  451. #define OV7670_REG_BRIGHT 0x55 /* Brightness */
  452. #define OV7670_REG_CONTRAS 0x56 /* Contrast control */
  453. #define OV7670_REG_GFIX 0x69 /* Fix gain control */
  454. #define OV7670_REG_RGB444 0x8c /* RGB 444 control */
  455. #define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
  456. #define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
  457. #define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
  458. #define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
  459. #define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
  460. #define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
  461. #define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
  462. #define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
  463. #define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
  464. struct ov_regvals {
  465. __u8 reg;
  466. __u8 val;
  467. };
  468. struct ov_i2c_regvals {
  469. __u8 reg;
  470. __u8 val;
  471. };
  472. static const struct ov_i2c_regvals norm_6x20[] = {
  473. { 0x12, 0x80 }, /* reset */
  474. { 0x11, 0x01 },
  475. { 0x03, 0x60 },
  476. { 0x05, 0x7f }, /* For when autoadjust is off */
  477. { 0x07, 0xa8 },
  478. /* The ratio of 0x0c and 0x0d controls the white point */
  479. { 0x0c, 0x24 },
  480. { 0x0d, 0x24 },
  481. { 0x0f, 0x15 }, /* COMS */
  482. { 0x10, 0x75 }, /* AEC Exposure time */
  483. { 0x12, 0x24 }, /* Enable AGC */
  484. { 0x14, 0x04 },
  485. /* 0x16: 0x06 helps frame stability with moving objects */
  486. { 0x16, 0x06 },
  487. /* { 0x20, 0x30 }, * Aperture correction enable */
  488. { 0x26, 0xb2 }, /* BLC enable */
  489. /* 0x28: 0x05 Selects RGB format if RGB on */
  490. { 0x28, 0x05 },
  491. { 0x2a, 0x04 }, /* Disable framerate adjust */
  492. /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
  493. { 0x2d, 0x99 },
  494. { 0x33, 0xa0 }, /* Color Processing Parameter */
  495. { 0x34, 0xd2 }, /* Max A/D range */
  496. { 0x38, 0x8b },
  497. { 0x39, 0x40 },
  498. { 0x3c, 0x39 }, /* Enable AEC mode changing */
  499. { 0x3c, 0x3c }, /* Change AEC mode */
  500. { 0x3c, 0x24 }, /* Disable AEC mode changing */
  501. { 0x3d, 0x80 },
  502. /* These next two registers (0x4a, 0x4b) are undocumented.
  503. * They control the color balance */
  504. { 0x4a, 0x80 },
  505. { 0x4b, 0x80 },
  506. { 0x4d, 0xd2 }, /* This reduces noise a bit */
  507. { 0x4e, 0xc1 },
  508. { 0x4f, 0x04 },
  509. /* Do 50-53 have any effect? */
  510. /* Toggle 0x12[2] off and on here? */
  511. };
  512. static const struct ov_i2c_regvals norm_6x30[] = {
  513. { 0x12, 0x80 }, /* Reset */
  514. { 0x00, 0x1f }, /* Gain */
  515. { 0x01, 0x99 }, /* Blue gain */
  516. { 0x02, 0x7c }, /* Red gain */
  517. { 0x03, 0xc0 }, /* Saturation */
  518. { 0x05, 0x0a }, /* Contrast */
  519. { 0x06, 0x95 }, /* Brightness */
  520. { 0x07, 0x2d }, /* Sharpness */
  521. { 0x0c, 0x20 },
  522. { 0x0d, 0x20 },
  523. { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
  524. { 0x0f, 0x05 },
  525. { 0x10, 0x9a },
  526. { 0x11, 0x00 }, /* Pixel clock = fastest */
  527. { 0x12, 0x24 }, /* Enable AGC and AWB */
  528. { 0x13, 0x21 },
  529. { 0x14, 0x80 },
  530. { 0x15, 0x01 },
  531. { 0x16, 0x03 },
  532. { 0x17, 0x38 },
  533. { 0x18, 0xea },
  534. { 0x19, 0x04 },
  535. { 0x1a, 0x93 },
  536. { 0x1b, 0x00 },
  537. { 0x1e, 0xc4 },
  538. { 0x1f, 0x04 },
  539. { 0x20, 0x20 },
  540. { 0x21, 0x10 },
  541. { 0x22, 0x88 },
  542. { 0x23, 0xc0 }, /* Crystal circuit power level */
  543. { 0x25, 0x9a }, /* Increase AEC black ratio */
  544. { 0x26, 0xb2 }, /* BLC enable */
  545. { 0x27, 0xa2 },
  546. { 0x28, 0x00 },
  547. { 0x29, 0x00 },
  548. { 0x2a, 0x84 }, /* 60 Hz power */
  549. { 0x2b, 0xa8 }, /* 60 Hz power */
  550. { 0x2c, 0xa0 },
  551. { 0x2d, 0x95 }, /* Enable auto-brightness */
  552. { 0x2e, 0x88 },
  553. { 0x33, 0x26 },
  554. { 0x34, 0x03 },
  555. { 0x36, 0x8f },
  556. { 0x37, 0x80 },
  557. { 0x38, 0x83 },
  558. { 0x39, 0x80 },
  559. { 0x3a, 0x0f },
  560. { 0x3b, 0x3c },
  561. { 0x3c, 0x1a },
  562. { 0x3d, 0x80 },
  563. { 0x3e, 0x80 },
  564. { 0x3f, 0x0e },
  565. { 0x40, 0x00 }, /* White bal */
  566. { 0x41, 0x00 }, /* White bal */
  567. { 0x42, 0x80 },
  568. { 0x43, 0x3f }, /* White bal */
  569. { 0x44, 0x80 },
  570. { 0x45, 0x20 },
  571. { 0x46, 0x20 },
  572. { 0x47, 0x80 },
  573. { 0x48, 0x7f },
  574. { 0x49, 0x00 },
  575. { 0x4a, 0x00 },
  576. { 0x4b, 0x80 },
  577. { 0x4c, 0xd0 },
  578. { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
  579. { 0x4e, 0x40 },
  580. { 0x4f, 0x07 }, /* UV avg., col. killer: max */
  581. { 0x50, 0xff },
  582. { 0x54, 0x23 }, /* Max AGC gain: 18dB */
  583. { 0x55, 0xff },
  584. { 0x56, 0x12 },
  585. { 0x57, 0x81 },
  586. { 0x58, 0x75 },
  587. { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
  588. { 0x5a, 0x2c },
  589. { 0x5b, 0x0f }, /* AWB chrominance levels */
  590. { 0x5c, 0x10 },
  591. { 0x3d, 0x80 },
  592. { 0x27, 0xa6 },
  593. { 0x12, 0x20 }, /* Toggle AWB */
  594. { 0x12, 0x24 },
  595. };
  596. /* Lawrence Glaister <lg@jfm.bc.ca> reports:
  597. *
  598. * Register 0x0f in the 7610 has the following effects:
  599. *
  600. * 0x85 (AEC method 1): Best overall, good contrast range
  601. * 0x45 (AEC method 2): Very overexposed
  602. * 0xa5 (spec sheet default): Ok, but the black level is
  603. * shifted resulting in loss of contrast
  604. * 0x05 (old driver setting): very overexposed, too much
  605. * contrast
  606. */
  607. static const struct ov_i2c_regvals norm_7610[] = {
  608. { 0x10, 0xff },
  609. { 0x16, 0x06 },
  610. { 0x28, 0x24 },
  611. { 0x2b, 0xac },
  612. { 0x12, 0x00 },
  613. { 0x38, 0x81 },
  614. { 0x28, 0x24 }, /* 0c */
  615. { 0x0f, 0x85 }, /* lg's setting */
  616. { 0x15, 0x01 },
  617. { 0x20, 0x1c },
  618. { 0x23, 0x2a },
  619. { 0x24, 0x10 },
  620. { 0x25, 0x8a },
  621. { 0x26, 0xa2 },
  622. { 0x27, 0xc2 },
  623. { 0x2a, 0x04 },
  624. { 0x2c, 0xfe },
  625. { 0x2d, 0x93 },
  626. { 0x30, 0x71 },
  627. { 0x31, 0x60 },
  628. { 0x32, 0x26 },
  629. { 0x33, 0x20 },
  630. { 0x34, 0x48 },
  631. { 0x12, 0x24 },
  632. { 0x11, 0x01 },
  633. { 0x0c, 0x24 },
  634. { 0x0d, 0x24 },
  635. };
  636. static const struct ov_i2c_regvals norm_7620[] = {
  637. { 0x00, 0x00 }, /* gain */
  638. { 0x01, 0x80 }, /* blue gain */
  639. { 0x02, 0x80 }, /* red gain */
  640. { 0x03, 0xc0 }, /* OV7670_REG_VREF */
  641. { 0x06, 0x60 },
  642. { 0x07, 0x00 },
  643. { 0x0c, 0x24 },
  644. { 0x0c, 0x24 },
  645. { 0x0d, 0x24 },
  646. { 0x11, 0x01 },
  647. { 0x12, 0x24 },
  648. { 0x13, 0x01 },
  649. { 0x14, 0x84 },
  650. { 0x15, 0x01 },
  651. { 0x16, 0x03 },
  652. { 0x17, 0x2f },
  653. { 0x18, 0xcf },
  654. { 0x19, 0x06 },
  655. { 0x1a, 0xf5 },
  656. { 0x1b, 0x00 },
  657. { 0x20, 0x18 },
  658. { 0x21, 0x80 },
  659. { 0x22, 0x80 },
  660. { 0x23, 0x00 },
  661. { 0x26, 0xa2 },
  662. { 0x27, 0xea },
  663. { 0x28, 0x20 },
  664. { 0x29, 0x00 },
  665. { 0x2a, 0x10 },
  666. { 0x2b, 0x00 },
  667. { 0x2c, 0x88 },
  668. { 0x2d, 0x91 },
  669. { 0x2e, 0x80 },
  670. { 0x2f, 0x44 },
  671. { 0x60, 0x27 },
  672. { 0x61, 0x02 },
  673. { 0x62, 0x5f },
  674. { 0x63, 0xd5 },
  675. { 0x64, 0x57 },
  676. { 0x65, 0x83 },
  677. { 0x66, 0x55 },
  678. { 0x67, 0x92 },
  679. { 0x68, 0xcf },
  680. { 0x69, 0x76 },
  681. { 0x6a, 0x22 },
  682. { 0x6b, 0x00 },
  683. { 0x6c, 0x02 },
  684. { 0x6d, 0x44 },
  685. { 0x6e, 0x80 },
  686. { 0x6f, 0x1d },
  687. { 0x70, 0x8b },
  688. { 0x71, 0x00 },
  689. { 0x72, 0x14 },
  690. { 0x73, 0x54 },
  691. { 0x74, 0x00 },
  692. { 0x75, 0x8e },
  693. { 0x76, 0x00 },
  694. { 0x77, 0xff },
  695. { 0x78, 0x80 },
  696. { 0x79, 0x80 },
  697. { 0x7a, 0x80 },
  698. { 0x7b, 0xe2 },
  699. { 0x7c, 0x00 },
  700. };
  701. /* 7640 and 7648. The defaults should be OK for most registers. */
  702. static const struct ov_i2c_regvals norm_7640[] = {
  703. { 0x12, 0x80 },
  704. { 0x12, 0x14 },
  705. };
  706. /* 7670. Defaults taken from OmniVision provided data,
  707. * as provided by Jonathan Corbet of OLPC */
  708. static const struct ov_i2c_regvals norm_7670[] = {
  709. { OV7670_REG_COM7, OV7670_COM7_RESET },
  710. { OV7670_REG_TSLB, 0x04 }, /* OV */
  711. { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
  712. { OV7670_REG_CLKRC, 0x01 },
  713. /*
  714. * Set the hardware window. These values from OV don't entirely
  715. * make sense - hstop is less than hstart. But they work...
  716. */
  717. { OV7670_REG_HSTART, 0x13 },
  718. { OV7670_REG_HSTOP, 0x01 },
  719. { OV7670_REG_HREF, 0xb6 },
  720. { OV7670_REG_VSTART, 0x02 },
  721. { OV7670_REG_VSTOP, 0x7a },
  722. { OV7670_REG_VREF, 0x0a },
  723. { OV7670_REG_COM3, 0x00 },
  724. { OV7670_REG_COM14, 0x00 },
  725. /* Mystery scaling numbers */
  726. { 0x70, 0x3a },
  727. { 0x71, 0x35 },
  728. { 0x72, 0x11 },
  729. { 0x73, 0xf0 },
  730. { 0xa2, 0x02 },
  731. /* { OV7670_REG_COM10, 0x0 }, */
  732. /* Gamma curve values */
  733. { 0x7a, 0x20 },
  734. { 0x7b, 0x10 },
  735. { 0x7c, 0x1e },
  736. { 0x7d, 0x35 },
  737. { 0x7e, 0x5a },
  738. { 0x7f, 0x69 },
  739. { 0x80, 0x76 },
  740. { 0x81, 0x80 },
  741. { 0x82, 0x88 },
  742. { 0x83, 0x8f },
  743. { 0x84, 0x96 },
  744. { 0x85, 0xa3 },
  745. { 0x86, 0xaf },
  746. { 0x87, 0xc4 },
  747. { 0x88, 0xd7 },
  748. { 0x89, 0xe8 },
  749. /* AGC and AEC parameters. Note we start by disabling those features,
  750. then turn them only after tweaking the values. */
  751. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  752. | OV7670_COM8_AECSTEP
  753. | OV7670_COM8_BFILT },
  754. { OV7670_REG_GAIN, 0x00 },
  755. { OV7670_REG_AECH, 0x00 },
  756. { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
  757. { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
  758. { OV7670_REG_BD50MAX, 0x05 },
  759. { OV7670_REG_BD60MAX, 0x07 },
  760. { OV7670_REG_AEW, 0x95 },
  761. { OV7670_REG_AEB, 0x33 },
  762. { OV7670_REG_VPT, 0xe3 },
  763. { OV7670_REG_HAECC1, 0x78 },
  764. { OV7670_REG_HAECC2, 0x68 },
  765. { 0xa1, 0x03 }, /* magic */
  766. { OV7670_REG_HAECC3, 0xd8 },
  767. { OV7670_REG_HAECC4, 0xd8 },
  768. { OV7670_REG_HAECC5, 0xf0 },
  769. { OV7670_REG_HAECC6, 0x90 },
  770. { OV7670_REG_HAECC7, 0x94 },
  771. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  772. | OV7670_COM8_AECSTEP
  773. | OV7670_COM8_BFILT
  774. | OV7670_COM8_AGC
  775. | OV7670_COM8_AEC },
  776. /* Almost all of these are magic "reserved" values. */
  777. { OV7670_REG_COM5, 0x61 },
  778. { OV7670_REG_COM6, 0x4b },
  779. { 0x16, 0x02 },
  780. { OV7670_REG_MVFP, 0x07 },
  781. { 0x21, 0x02 },
  782. { 0x22, 0x91 },
  783. { 0x29, 0x07 },
  784. { 0x33, 0x0b },
  785. { 0x35, 0x0b },
  786. { 0x37, 0x1d },
  787. { 0x38, 0x71 },
  788. { 0x39, 0x2a },
  789. { OV7670_REG_COM12, 0x78 },
  790. { 0x4d, 0x40 },
  791. { 0x4e, 0x20 },
  792. { OV7670_REG_GFIX, 0x00 },
  793. { 0x6b, 0x4a },
  794. { 0x74, 0x10 },
  795. { 0x8d, 0x4f },
  796. { 0x8e, 0x00 },
  797. { 0x8f, 0x00 },
  798. { 0x90, 0x00 },
  799. { 0x91, 0x00 },
  800. { 0x96, 0x00 },
  801. { 0x9a, 0x00 },
  802. { 0xb0, 0x84 },
  803. { 0xb1, 0x0c },
  804. { 0xb2, 0x0e },
  805. { 0xb3, 0x82 },
  806. { 0xb8, 0x0a },
  807. /* More reserved magic, some of which tweaks white balance */
  808. { 0x43, 0x0a },
  809. { 0x44, 0xf0 },
  810. { 0x45, 0x34 },
  811. { 0x46, 0x58 },
  812. { 0x47, 0x28 },
  813. { 0x48, 0x3a },
  814. { 0x59, 0x88 },
  815. { 0x5a, 0x88 },
  816. { 0x5b, 0x44 },
  817. { 0x5c, 0x67 },
  818. { 0x5d, 0x49 },
  819. { 0x5e, 0x0e },
  820. { 0x6c, 0x0a },
  821. { 0x6d, 0x55 },
  822. { 0x6e, 0x11 },
  823. { 0x6f, 0x9f },
  824. /* "9e for advance AWB" */
  825. { 0x6a, 0x40 },
  826. { OV7670_REG_BLUE, 0x40 },
  827. { OV7670_REG_RED, 0x60 },
  828. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  829. | OV7670_COM8_AECSTEP
  830. | OV7670_COM8_BFILT
  831. | OV7670_COM8_AGC
  832. | OV7670_COM8_AEC
  833. | OV7670_COM8_AWB },
  834. /* Matrix coefficients */
  835. { 0x4f, 0x80 },
  836. { 0x50, 0x80 },
  837. { 0x51, 0x00 },
  838. { 0x52, 0x22 },
  839. { 0x53, 0x5e },
  840. { 0x54, 0x80 },
  841. { 0x58, 0x9e },
  842. { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
  843. { OV7670_REG_EDGE, 0x00 },
  844. { 0x75, 0x05 },
  845. { 0x76, 0xe1 },
  846. { 0x4c, 0x00 },
  847. { 0x77, 0x01 },
  848. { OV7670_REG_COM13, OV7670_COM13_GAMMA
  849. | OV7670_COM13_UVSAT
  850. | 2}, /* was 3 */
  851. { 0x4b, 0x09 },
  852. { 0xc9, 0x60 },
  853. { OV7670_REG_COM16, 0x38 },
  854. { 0x56, 0x40 },
  855. { 0x34, 0x11 },
  856. { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
  857. { 0xa4, 0x88 },
  858. { 0x96, 0x00 },
  859. { 0x97, 0x30 },
  860. { 0x98, 0x20 },
  861. { 0x99, 0x30 },
  862. { 0x9a, 0x84 },
  863. { 0x9b, 0x29 },
  864. { 0x9c, 0x03 },
  865. { 0x9d, 0x4c },
  866. { 0x9e, 0x3f },
  867. { 0x78, 0x04 },
  868. /* Extra-weird stuff. Some sort of multiplexor register */
  869. { 0x79, 0x01 },
  870. { 0xc8, 0xf0 },
  871. { 0x79, 0x0f },
  872. { 0xc8, 0x00 },
  873. { 0x79, 0x10 },
  874. { 0xc8, 0x7e },
  875. { 0x79, 0x0a },
  876. { 0xc8, 0x80 },
  877. { 0x79, 0x0b },
  878. { 0xc8, 0x01 },
  879. { 0x79, 0x0c },
  880. { 0xc8, 0x0f },
  881. { 0x79, 0x0d },
  882. { 0xc8, 0x20 },
  883. { 0x79, 0x09 },
  884. { 0xc8, 0x80 },
  885. { 0x79, 0x02 },
  886. { 0xc8, 0xc0 },
  887. { 0x79, 0x03 },
  888. { 0xc8, 0x40 },
  889. { 0x79, 0x05 },
  890. { 0xc8, 0x30 },
  891. { 0x79, 0x26 },
  892. };
  893. static const struct ov_i2c_regvals norm_8610[] = {
  894. { 0x12, 0x80 },
  895. { 0x00, 0x00 },
  896. { 0x01, 0x80 },
  897. { 0x02, 0x80 },
  898. { 0x03, 0xc0 },
  899. { 0x04, 0x30 },
  900. { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
  901. { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
  902. { 0x0a, 0x86 },
  903. { 0x0b, 0xb0 },
  904. { 0x0c, 0x20 },
  905. { 0x0d, 0x20 },
  906. { 0x11, 0x01 },
  907. { 0x12, 0x25 },
  908. { 0x13, 0x01 },
  909. { 0x14, 0x04 },
  910. { 0x15, 0x01 }, /* Lin and Win think different about UV order */
  911. { 0x16, 0x03 },
  912. { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
  913. { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
  914. { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
  915. { 0x1a, 0xf5 },
  916. { 0x1b, 0x00 },
  917. { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
  918. { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
  919. { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
  920. { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
  921. { 0x26, 0xa2 },
  922. { 0x27, 0xea },
  923. { 0x28, 0x00 },
  924. { 0x29, 0x00 },
  925. { 0x2a, 0x80 },
  926. { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
  927. { 0x2c, 0xac },
  928. { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
  929. { 0x2e, 0x80 },
  930. { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
  931. { 0x4c, 0x00 },
  932. { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
  933. { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
  934. { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
  935. { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
  936. { 0x63, 0xff },
  937. { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
  938. * maybe thats wrong */
  939. { 0x65, 0x00 },
  940. { 0x66, 0x55 },
  941. { 0x67, 0xb0 },
  942. { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
  943. { 0x69, 0x02 },
  944. { 0x6a, 0x22 },
  945. { 0x6b, 0x00 },
  946. { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
  947. * deleting bit7 colors the first images red */
  948. { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
  949. { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
  950. { 0x6f, 0x01 },
  951. { 0x70, 0x8b },
  952. { 0x71, 0x00 },
  953. { 0x72, 0x14 },
  954. { 0x73, 0x54 },
  955. { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
  956. { 0x75, 0x0e },
  957. { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
  958. { 0x77, 0xff },
  959. { 0x78, 0x80 },
  960. { 0x79, 0x80 },
  961. { 0x7a, 0x80 },
  962. { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
  963. { 0x7c, 0x00 },
  964. { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
  965. { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
  966. { 0x7f, 0xfb },
  967. { 0x80, 0x28 },
  968. { 0x81, 0x00 },
  969. { 0x82, 0x23 },
  970. { 0x83, 0x0b },
  971. { 0x84, 0x00 },
  972. { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
  973. { 0x86, 0xc9 },
  974. { 0x87, 0x00 },
  975. { 0x88, 0x00 },
  976. { 0x89, 0x01 },
  977. { 0x12, 0x20 },
  978. { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
  979. };
  980. static unsigned char ov7670_abs_to_sm(unsigned char v)
  981. {
  982. if (v > 127)
  983. return v & 0x7f;
  984. return (128 - v) | 0x80;
  985. }
  986. /* Write a OV519 register */
  987. static int reg_w(struct sd *sd, __u16 index, __u8 value)
  988. {
  989. int ret;
  990. int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 2 : 1;
  991. sd->gspca_dev.usb_buf[0] = value;
  992. ret = usb_control_msg(sd->gspca_dev.dev,
  993. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  994. req,
  995. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  996. 0, index,
  997. sd->gspca_dev.usb_buf, 1, 500);
  998. if (ret < 0)
  999. PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
  1000. return ret;
  1001. }
  1002. /* Read from a OV519 register */
  1003. /* returns: negative is error, pos or zero is data */
  1004. static int reg_r(struct sd *sd, __u16 index)
  1005. {
  1006. int ret;
  1007. int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 3 : 1;
  1008. ret = usb_control_msg(sd->gspca_dev.dev,
  1009. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  1010. req,
  1011. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1012. 0, index, sd->gspca_dev.usb_buf, 1, 500);
  1013. if (ret >= 0)
  1014. ret = sd->gspca_dev.usb_buf[0];
  1015. else
  1016. PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
  1017. return ret;
  1018. }
  1019. /* Read 8 values from a OV519 register */
  1020. static int reg_r8(struct sd *sd,
  1021. __u16 index)
  1022. {
  1023. int ret;
  1024. ret = usb_control_msg(sd->gspca_dev.dev,
  1025. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  1026. 1, /* REQ_IO */
  1027. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1028. 0, index, sd->gspca_dev.usb_buf, 8, 500);
  1029. if (ret >= 0)
  1030. ret = sd->gspca_dev.usb_buf[0];
  1031. else
  1032. PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
  1033. return ret;
  1034. }
  1035. /*
  1036. * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
  1037. * the same position as 1's in "mask" are cleared and set to "value". Bits
  1038. * that are in the same position as 0's in "mask" are preserved, regardless
  1039. * of their respective state in "value".
  1040. */
  1041. static int reg_w_mask(struct sd *sd,
  1042. __u16 index,
  1043. __u8 value,
  1044. __u8 mask)
  1045. {
  1046. int ret;
  1047. __u8 oldval;
  1048. if (mask != 0xff) {
  1049. value &= mask; /* Enforce mask on value */
  1050. ret = reg_r(sd, index);
  1051. if (ret < 0)
  1052. return ret;
  1053. oldval = ret & ~mask; /* Clear the masked bits */
  1054. value |= oldval; /* Set the desired bits */
  1055. }
  1056. return reg_w(sd, index, value);
  1057. }
  1058. /*
  1059. * Writes multiple (n) byte value to a single register. Only valid with certain
  1060. * registers (0x30 and 0xc4 - 0xce).
  1061. */
  1062. static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
  1063. {
  1064. int ret;
  1065. *((u32 *)sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
  1066. ret = usb_control_msg(sd->gspca_dev.dev,
  1067. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  1068. 1 /* REG_IO */,
  1069. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1070. 0, index,
  1071. sd->gspca_dev.usb_buf, n, 500);
  1072. if (ret < 0)
  1073. PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value);
  1074. return ret;
  1075. }
  1076. static int ov511_i2c_w(struct sd *sd, __u8 reg, __u8 value)
  1077. {
  1078. int rc, retries;
  1079. PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
  1080. /* Three byte write cycle */
  1081. for (retries = 6; ; ) {
  1082. /* Select camera register */
  1083. rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
  1084. if (rc < 0)
  1085. return rc;
  1086. /* Write "value" to I2C data port of OV511 */
  1087. rc = reg_w(sd, R51x_I2C_DATA, value);
  1088. if (rc < 0)
  1089. return rc;
  1090. /* Initiate 3-byte write cycle */
  1091. rc = reg_w(sd, R511_I2C_CTL, 0x01);
  1092. if (rc < 0)
  1093. return rc;
  1094. do
  1095. rc = reg_r(sd, R511_I2C_CTL);
  1096. while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
  1097. if (rc < 0)
  1098. return rc;
  1099. if ((rc & 2) == 0) /* Ack? */
  1100. break;
  1101. if (--retries < 0) {
  1102. PDEBUG(D_USBO, "i2c write retries exhausted");
  1103. return -1;
  1104. }
  1105. }
  1106. return 0;
  1107. }
  1108. static int ov511_i2c_r(struct sd *sd, __u8 reg)
  1109. {
  1110. int rc, value, retries;
  1111. /* Two byte write cycle */
  1112. for (retries = 6; ; ) {
  1113. /* Select camera register */
  1114. rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
  1115. if (rc < 0)
  1116. return rc;
  1117. /* Initiate 2-byte write cycle */
  1118. rc = reg_w(sd, R511_I2C_CTL, 0x03);
  1119. if (rc < 0)
  1120. return rc;
  1121. do
  1122. rc = reg_r(sd, R511_I2C_CTL);
  1123. while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
  1124. if (rc < 0)
  1125. return rc;
  1126. if ((rc & 2) == 0) /* Ack? */
  1127. break;
  1128. /* I2C abort */
  1129. reg_w(sd, R511_I2C_CTL, 0x10);
  1130. if (--retries < 0) {
  1131. PDEBUG(D_USBI, "i2c write retries exhausted");
  1132. return -1;
  1133. }
  1134. }
  1135. /* Two byte read cycle */
  1136. for (retries = 6; ; ) {
  1137. /* Initiate 2-byte read cycle */
  1138. rc = reg_w(sd, R511_I2C_CTL, 0x05);
  1139. if (rc < 0)
  1140. return rc;
  1141. do
  1142. rc = reg_r(sd, R511_I2C_CTL);
  1143. while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
  1144. if (rc < 0)
  1145. return rc;
  1146. if ((rc & 2) == 0) /* Ack? */
  1147. break;
  1148. /* I2C abort */
  1149. rc = reg_w(sd, R511_I2C_CTL, 0x10);
  1150. if (rc < 0)
  1151. return rc;
  1152. if (--retries < 0) {
  1153. PDEBUG(D_USBI, "i2c read retries exhausted");
  1154. return -1;
  1155. }
  1156. }
  1157. value = reg_r(sd, R51x_I2C_DATA);
  1158. PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
  1159. /* This is needed to make i2c_w() work */
  1160. rc = reg_w(sd, R511_I2C_CTL, 0x05);
  1161. if (rc < 0)
  1162. return rc;
  1163. return value;
  1164. }
  1165. /*
  1166. * The OV518 I2C I/O procedure is different, hence, this function.
  1167. * This is normally only called from i2c_w(). Note that this function
  1168. * always succeeds regardless of whether the sensor is present and working.
  1169. */
  1170. static int ov518_i2c_w(struct sd *sd,
  1171. __u8 reg,
  1172. __u8 value)
  1173. {
  1174. int rc;
  1175. PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
  1176. /* Select camera register */
  1177. rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
  1178. if (rc < 0)
  1179. return rc;
  1180. /* Write "value" to I2C data port of OV511 */
  1181. rc = reg_w(sd, R51x_I2C_DATA, value);
  1182. if (rc < 0)
  1183. return rc;
  1184. /* Initiate 3-byte write cycle */
  1185. rc = reg_w(sd, R518_I2C_CTL, 0x01);
  1186. if (rc < 0)
  1187. return rc;
  1188. /* wait for write complete */
  1189. msleep(4);
  1190. return reg_r8(sd, R518_I2C_CTL);
  1191. }
  1192. /*
  1193. * returns: negative is error, pos or zero is data
  1194. *
  1195. * The OV518 I2C I/O procedure is different, hence, this function.
  1196. * This is normally only called from i2c_r(). Note that this function
  1197. * always succeeds regardless of whether the sensor is present and working.
  1198. */
  1199. static int ov518_i2c_r(struct sd *sd, __u8 reg)
  1200. {
  1201. int rc, value;
  1202. /* Select camera register */
  1203. rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
  1204. if (rc < 0)
  1205. return rc;
  1206. /* Initiate 2-byte write cycle */
  1207. rc = reg_w(sd, R518_I2C_CTL, 0x03);
  1208. if (rc < 0)
  1209. return rc;
  1210. /* Initiate 2-byte read cycle */
  1211. rc = reg_w(sd, R518_I2C_CTL, 0x05);
  1212. if (rc < 0)
  1213. return rc;
  1214. value = reg_r(sd, R51x_I2C_DATA);
  1215. PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
  1216. return value;
  1217. }
  1218. static int i2c_w(struct sd *sd, __u8 reg, __u8 value)
  1219. {
  1220. switch (sd->bridge) {
  1221. case BRIDGE_OV511:
  1222. case BRIDGE_OV511PLUS:
  1223. return ov511_i2c_w(sd, reg, value);
  1224. case BRIDGE_OV518:
  1225. case BRIDGE_OV518PLUS:
  1226. case BRIDGE_OV519:
  1227. return ov518_i2c_w(sd, reg, value);
  1228. }
  1229. return -1; /* Should never happen */
  1230. }
  1231. static int i2c_r(struct sd *sd, __u8 reg)
  1232. {
  1233. switch (sd->bridge) {
  1234. case BRIDGE_OV511:
  1235. case BRIDGE_OV511PLUS:
  1236. return ov511_i2c_r(sd, reg);
  1237. case BRIDGE_OV518:
  1238. case BRIDGE_OV518PLUS:
  1239. case BRIDGE_OV519:
  1240. return ov518_i2c_r(sd, reg);
  1241. }
  1242. return -1; /* Should never happen */
  1243. }
  1244. /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
  1245. * the same position as 1's in "mask" are cleared and set to "value". Bits
  1246. * that are in the same position as 0's in "mask" are preserved, regardless
  1247. * of their respective state in "value".
  1248. */
  1249. static int i2c_w_mask(struct sd *sd,
  1250. __u8 reg,
  1251. __u8 value,
  1252. __u8 mask)
  1253. {
  1254. int rc;
  1255. __u8 oldval;
  1256. value &= mask; /* Enforce mask on value */
  1257. rc = i2c_r(sd, reg);
  1258. if (rc < 0)
  1259. return rc;
  1260. oldval = rc & ~mask; /* Clear the masked bits */
  1261. value |= oldval; /* Set the desired bits */
  1262. return i2c_w(sd, reg, value);
  1263. }
  1264. /* Temporarily stops OV511 from functioning. Must do this before changing
  1265. * registers while the camera is streaming */
  1266. static inline int ov51x_stop(struct sd *sd)
  1267. {
  1268. PDEBUG(D_STREAM, "stopping");
  1269. sd->stopped = 1;
  1270. switch (sd->bridge) {
  1271. case BRIDGE_OV511:
  1272. case BRIDGE_OV511PLUS:
  1273. return reg_w(sd, R51x_SYS_RESET, 0x3d);
  1274. case BRIDGE_OV518:
  1275. case BRIDGE_OV518PLUS:
  1276. return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
  1277. case BRIDGE_OV519:
  1278. return reg_w(sd, OV519_SYS_RESET1, 0x0f);
  1279. }
  1280. return 0;
  1281. }
  1282. /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
  1283. * actually stopped (for performance). */
  1284. static inline int ov51x_restart(struct sd *sd)
  1285. {
  1286. int rc;
  1287. PDEBUG(D_STREAM, "restarting");
  1288. if (!sd->stopped)
  1289. return 0;
  1290. sd->stopped = 0;
  1291. /* Reinitialize the stream */
  1292. switch (sd->bridge) {
  1293. case BRIDGE_OV511:
  1294. case BRIDGE_OV511PLUS:
  1295. return reg_w(sd, R51x_SYS_RESET, 0x00);
  1296. case BRIDGE_OV518:
  1297. case BRIDGE_OV518PLUS:
  1298. rc = reg_w(sd, 0x2f, 0x80);
  1299. if (rc < 0)
  1300. return rc;
  1301. return reg_w(sd, R51x_SYS_RESET, 0x00);
  1302. case BRIDGE_OV519:
  1303. return reg_w(sd, OV519_SYS_RESET1, 0x00);
  1304. }
  1305. return 0;
  1306. }
  1307. /* This does an initial reset of an OmniVision sensor and ensures that I2C
  1308. * is synchronized. Returns <0 on failure.
  1309. */
  1310. static int init_ov_sensor(struct sd *sd)
  1311. {
  1312. int i;
  1313. /* Reset the sensor */
  1314. if (i2c_w(sd, 0x12, 0x80) < 0)
  1315. return -EIO;
  1316. /* Wait for it to initialize */
  1317. msleep(150);
  1318. for (i = 0; i < i2c_detect_tries; i++) {
  1319. if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
  1320. i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
  1321. PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
  1322. return 0;
  1323. }
  1324. /* Reset the sensor */
  1325. if (i2c_w(sd, 0x12, 0x80) < 0)
  1326. return -EIO;
  1327. /* Wait for it to initialize */
  1328. msleep(150);
  1329. /* Dummy read to sync I2C */
  1330. if (i2c_r(sd, 0x00) < 0)
  1331. return -EIO;
  1332. }
  1333. return -EIO;
  1334. }
  1335. /* Set the read and write slave IDs. The "slave" argument is the write slave,
  1336. * and the read slave will be set to (slave + 1).
  1337. * This should not be called from outside the i2c I/O functions.
  1338. * Sets I2C read and write slave IDs. Returns <0 for error
  1339. */
  1340. static int ov51x_set_slave_ids(struct sd *sd,
  1341. __u8 slave)
  1342. {
  1343. int rc;
  1344. rc = reg_w(sd, R51x_I2C_W_SID, slave);
  1345. if (rc < 0)
  1346. return rc;
  1347. return reg_w(sd, R51x_I2C_R_SID, slave + 1);
  1348. }
  1349. static int write_regvals(struct sd *sd,
  1350. const struct ov_regvals *regvals,
  1351. int n)
  1352. {
  1353. int rc;
  1354. while (--n >= 0) {
  1355. rc = reg_w(sd, regvals->reg, regvals->val);
  1356. if (rc < 0)
  1357. return rc;
  1358. regvals++;
  1359. }
  1360. return 0;
  1361. }
  1362. static int write_i2c_regvals(struct sd *sd,
  1363. const struct ov_i2c_regvals *regvals,
  1364. int n)
  1365. {
  1366. int rc;
  1367. while (--n >= 0) {
  1368. rc = i2c_w(sd, regvals->reg, regvals->val);
  1369. if (rc < 0)
  1370. return rc;
  1371. regvals++;
  1372. }
  1373. return 0;
  1374. }
  1375. /****************************************************************************
  1376. *
  1377. * OV511 and sensor configuration
  1378. *
  1379. ***************************************************************************/
  1380. /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
  1381. * the same register settings as the OV8610, since they are very similar.
  1382. */
  1383. static int ov8xx0_configure(struct sd *sd)
  1384. {
  1385. int rc;
  1386. PDEBUG(D_PROBE, "starting ov8xx0 configuration");
  1387. /* Detect sensor (sub)type */
  1388. rc = i2c_r(sd, OV7610_REG_COM_I);
  1389. if (rc < 0) {
  1390. PDEBUG(D_ERR, "Error detecting sensor type");
  1391. return -1;
  1392. }
  1393. if ((rc & 3) == 1) {
  1394. sd->sensor = SEN_OV8610;
  1395. } else {
  1396. PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
  1397. return -1;
  1398. }
  1399. /* Set sensor-specific vars */
  1400. /* sd->sif = 0; already done */
  1401. return 0;
  1402. }
  1403. /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
  1404. * the same register settings as the OV7610, since they are very similar.
  1405. */
  1406. static int ov7xx0_configure(struct sd *sd)
  1407. {
  1408. int rc, high, low;
  1409. PDEBUG(D_PROBE, "starting OV7xx0 configuration");
  1410. /* Detect sensor (sub)type */
  1411. rc = i2c_r(sd, OV7610_REG_COM_I);
  1412. /* add OV7670 here
  1413. * it appears to be wrongly detected as a 7610 by default */
  1414. if (rc < 0) {
  1415. PDEBUG(D_ERR, "Error detecting sensor type");
  1416. return -1;
  1417. }
  1418. if ((rc & 3) == 3) {
  1419. /* quick hack to make OV7670s work */
  1420. high = i2c_r(sd, 0x0a);
  1421. low = i2c_r(sd, 0x0b);
  1422. /* info("%x, %x", high, low); */
  1423. if (high == 0x76 && low == 0x73) {
  1424. PDEBUG(D_PROBE, "Sensor is an OV7670");
  1425. sd->sensor = SEN_OV7670;
  1426. } else {
  1427. PDEBUG(D_PROBE, "Sensor is an OV7610");
  1428. sd->sensor = SEN_OV7610;
  1429. }
  1430. } else if ((rc & 3) == 1) {
  1431. /* I don't know what's different about the 76BE yet. */
  1432. if (i2c_r(sd, 0x15) & 1)
  1433. PDEBUG(D_PROBE, "Sensor is an OV7620AE");
  1434. else
  1435. PDEBUG(D_PROBE, "Sensor is an OV76BE");
  1436. /* OV511+ will return all zero isoc data unless we
  1437. * configure the sensor as a 7620. Someone needs to
  1438. * find the exact reg. setting that causes this. */
  1439. sd->sensor = SEN_OV76BE;
  1440. } else if ((rc & 3) == 0) {
  1441. /* try to read product id registers */
  1442. high = i2c_r(sd, 0x0a);
  1443. if (high < 0) {
  1444. PDEBUG(D_ERR, "Error detecting camera chip PID");
  1445. return high;
  1446. }
  1447. low = i2c_r(sd, 0x0b);
  1448. if (low < 0) {
  1449. PDEBUG(D_ERR, "Error detecting camera chip VER");
  1450. return low;
  1451. }
  1452. if (high == 0x76) {
  1453. switch (low) {
  1454. case 0x30:
  1455. PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
  1456. PDEBUG(D_ERR,
  1457. "7630 is not supported by this driver");
  1458. return -1;
  1459. case 0x40:
  1460. PDEBUG(D_PROBE, "Sensor is an OV7645");
  1461. sd->sensor = SEN_OV7640; /* FIXME */
  1462. break;
  1463. case 0x45:
  1464. PDEBUG(D_PROBE, "Sensor is an OV7645B");
  1465. sd->sensor = SEN_OV7640; /* FIXME */
  1466. break;
  1467. case 0x48:
  1468. PDEBUG(D_PROBE, "Sensor is an OV7648");
  1469. sd->sensor = SEN_OV7640; /* FIXME */
  1470. break;
  1471. default:
  1472. PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
  1473. return -1;
  1474. }
  1475. } else {
  1476. PDEBUG(D_PROBE, "Sensor is an OV7620");
  1477. sd->sensor = SEN_OV7620;
  1478. }
  1479. } else {
  1480. PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
  1481. return -1;
  1482. }
  1483. /* Set sensor-specific vars */
  1484. /* sd->sif = 0; already done */
  1485. return 0;
  1486. }
  1487. /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
  1488. static int ov6xx0_configure(struct sd *sd)
  1489. {
  1490. int rc;
  1491. PDEBUG(D_PROBE, "starting OV6xx0 configuration");
  1492. /* Detect sensor (sub)type */
  1493. rc = i2c_r(sd, OV7610_REG_COM_I);
  1494. if (rc < 0) {
  1495. PDEBUG(D_ERR, "Error detecting sensor type");
  1496. return -1;
  1497. }
  1498. /* Ugh. The first two bits are the version bits, but
  1499. * the entire register value must be used. I guess OVT
  1500. * underestimated how many variants they would make. */
  1501. switch (rc) {
  1502. case 0x00:
  1503. sd->sensor = SEN_OV6630;
  1504. PDEBUG(D_ERR,
  1505. "WARNING: Sensor is an OV66308. Your camera may have");
  1506. PDEBUG(D_ERR, "been misdetected in previous driver versions.");
  1507. break;
  1508. case 0x01:
  1509. sd->sensor = SEN_OV6620;
  1510. PDEBUG(D_PROBE, "Sensor is an OV6620");
  1511. break;
  1512. case 0x02:
  1513. sd->sensor = SEN_OV6630;
  1514. PDEBUG(D_PROBE, "Sensor is an OV66308AE");
  1515. break;
  1516. case 0x03:
  1517. sd->sensor = SEN_OV66308AF;
  1518. PDEBUG(D_PROBE, "Sensor is an OV66308AF");
  1519. break;
  1520. case 0x90:
  1521. sd->sensor = SEN_OV6630;
  1522. PDEBUG(D_ERR,
  1523. "WARNING: Sensor is an OV66307. Your camera may have");
  1524. PDEBUG(D_ERR, "been misdetected in previous driver versions.");
  1525. break;
  1526. default:
  1527. PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
  1528. return -1;
  1529. }
  1530. /* Set sensor-specific vars */
  1531. sd->sif = 1;
  1532. return 0;
  1533. }
  1534. /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
  1535. static void ov51x_led_control(struct sd *sd, int on)
  1536. {
  1537. if (sd->invert_led)
  1538. on = !on;
  1539. switch (sd->bridge) {
  1540. /* OV511 has no LED control */
  1541. case BRIDGE_OV511PLUS:
  1542. reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
  1543. break;
  1544. case BRIDGE_OV518:
  1545. case BRIDGE_OV518PLUS:
  1546. reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
  1547. break;
  1548. case BRIDGE_OV519:
  1549. reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
  1550. break;
  1551. }
  1552. }
  1553. static int ov51x_upload_quan_tables(struct sd *sd)
  1554. {
  1555. const unsigned char yQuanTable511[] = {
  1556. 0, 1, 1, 2, 2, 3, 3, 4,
  1557. 1, 1, 1, 2, 2, 3, 4, 4,
  1558. 1, 1, 2, 2, 3, 4, 4, 4,
  1559. 2, 2, 2, 3, 4, 4, 4, 4,
  1560. 2, 2, 3, 4, 4, 5, 5, 5,
  1561. 3, 3, 4, 4, 5, 5, 5, 5,
  1562. 3, 4, 4, 4, 5, 5, 5, 5,
  1563. 4, 4, 4, 4, 5, 5, 5, 5
  1564. };
  1565. const unsigned char uvQuanTable511[] = {
  1566. 0, 2, 2, 3, 4, 4, 4, 4,
  1567. 2, 2, 2, 4, 4, 4, 4, 4,
  1568. 2, 2, 3, 4, 4, 4, 4, 4,
  1569. 3, 4, 4, 4, 4, 4, 4, 4,
  1570. 4, 4, 4, 4, 4, 4, 4, 4,
  1571. 4, 4, 4, 4, 4, 4, 4, 4,
  1572. 4, 4, 4, 4, 4, 4, 4, 4,
  1573. 4, 4, 4, 4, 4, 4, 4, 4
  1574. };
  1575. /* OV518 quantization tables are 8x4 (instead of 8x8) */
  1576. const unsigned char yQuanTable518[] = {
  1577. 5, 4, 5, 6, 6, 7, 7, 7,
  1578. 5, 5, 5, 5, 6, 7, 7, 7,
  1579. 6, 6, 6, 6, 7, 7, 7, 8,
  1580. 7, 7, 6, 7, 7, 7, 8, 8
  1581. };
  1582. const unsigned char uvQuanTable518[] = {
  1583. 6, 6, 6, 7, 7, 7, 7, 7,
  1584. 6, 6, 6, 7, 7, 7, 7, 7,
  1585. 6, 6, 6, 7, 7, 7, 7, 8,
  1586. 7, 7, 7, 7, 7, 7, 8, 8
  1587. };
  1588. const unsigned char *pYTable, *pUVTable;
  1589. unsigned char val0, val1;
  1590. int i, size, rc, reg = R51x_COMP_LUT_BEGIN;
  1591. PDEBUG(D_PROBE, "Uploading quantization tables");
  1592. if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
  1593. pYTable = yQuanTable511;
  1594. pUVTable = uvQuanTable511;
  1595. size = 32;
  1596. } else {
  1597. pYTable = yQuanTable518;
  1598. pUVTable = uvQuanTable518;
  1599. size = 16;
  1600. }
  1601. for (i = 0; i < size; i++) {
  1602. val0 = *pYTable++;
  1603. val1 = *pYTable++;
  1604. val0 &= 0x0f;
  1605. val1 &= 0x0f;
  1606. val0 |= val1 << 4;
  1607. rc = reg_w(sd, reg, val0);
  1608. if (rc < 0)
  1609. return rc;
  1610. val0 = *pUVTable++;
  1611. val1 = *pUVTable++;
  1612. val0 &= 0x0f;
  1613. val1 &= 0x0f;
  1614. val0 |= val1 << 4;
  1615. rc = reg_w(sd, reg + size, val0);
  1616. if (rc < 0)
  1617. return rc;
  1618. reg++;
  1619. }
  1620. return 0;
  1621. }
  1622. /* This initializes the OV511/OV511+ and the sensor */
  1623. static int ov511_configure(struct gspca_dev *gspca_dev)
  1624. {
  1625. struct sd *sd = (struct sd *) gspca_dev;
  1626. int rc;
  1627. /* For 511 and 511+ */
  1628. const struct ov_regvals init_511[] = {
  1629. { R51x_SYS_RESET, 0x7f },
  1630. { R51x_SYS_INIT, 0x01 },
  1631. { R51x_SYS_RESET, 0x7f },
  1632. { R51x_SYS_INIT, 0x01 },
  1633. { R51x_SYS_RESET, 0x3f },
  1634. { R51x_SYS_INIT, 0x01 },
  1635. { R51x_SYS_RESET, 0x3d },
  1636. };
  1637. const struct ov_regvals norm_511[] = {
  1638. { R511_DRAM_FLOW_CTL, 0x01 },
  1639. { R51x_SYS_SNAP, 0x00 },
  1640. { R51x_SYS_SNAP, 0x02 },
  1641. { R51x_SYS_SNAP, 0x00 },
  1642. { R511_FIFO_OPTS, 0x1f },
  1643. { R511_COMP_EN, 0x00 },
  1644. { R511_COMP_LUT_EN, 0x03 },
  1645. };
  1646. const struct ov_regvals norm_511_p[] = {
  1647. { R511_DRAM_FLOW_CTL, 0xff },
  1648. { R51x_SYS_SNAP, 0x00 },
  1649. { R51x_SYS_SNAP, 0x02 },
  1650. { R51x_SYS_SNAP, 0x00 },
  1651. { R511_FIFO_OPTS, 0xff },
  1652. { R511_COMP_EN, 0x00 },
  1653. { R511_COMP_LUT_EN, 0x03 },
  1654. };
  1655. const struct ov_regvals compress_511[] = {
  1656. { 0x70, 0x1f },
  1657. { 0x71, 0x05 },
  1658. { 0x72, 0x06 },
  1659. { 0x73, 0x06 },
  1660. { 0x74, 0x14 },
  1661. { 0x75, 0x03 },
  1662. { 0x76, 0x04 },
  1663. { 0x77, 0x04 },
  1664. };
  1665. PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
  1666. rc = write_regvals(sd, init_511, ARRAY_SIZE(init_511));
  1667. if (rc < 0)
  1668. return rc;
  1669. switch (sd->bridge) {
  1670. case BRIDGE_OV511:
  1671. rc = write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
  1672. if (rc < 0)
  1673. return rc;
  1674. break;
  1675. case BRIDGE_OV511PLUS:
  1676. rc = write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
  1677. if (rc < 0)
  1678. return rc;
  1679. break;
  1680. }
  1681. /* Init compression */
  1682. rc = write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
  1683. if (rc < 0)
  1684. return rc;
  1685. rc = ov51x_upload_quan_tables(sd);
  1686. if (rc < 0) {
  1687. PDEBUG(D_ERR, "Error uploading quantization tables");
  1688. return rc;
  1689. }
  1690. return 0;
  1691. }
  1692. /* This initializes the OV518/OV518+ and the sensor */
  1693. static int ov518_configure(struct gspca_dev *gspca_dev)
  1694. {
  1695. struct sd *sd = (struct sd *) gspca_dev;
  1696. int rc;
  1697. /* For 518 and 518+ */
  1698. static struct ov_regvals init_518[] = {
  1699. { R51x_SYS_RESET, 0x40 },
  1700. { R51x_SYS_INIT, 0xe1 },
  1701. { R51x_SYS_RESET, 0x3e },
  1702. { R51x_SYS_INIT, 0xe1 },
  1703. { R51x_SYS_RESET, 0x00 },
  1704. { R51x_SYS_INIT, 0xe1 },
  1705. { 0x46, 0x00 },
  1706. { 0x5d, 0x03 },
  1707. };
  1708. static struct ov_regvals norm_518[] = {
  1709. { R51x_SYS_SNAP, 0x02 }, /* Reset */
  1710. { R51x_SYS_SNAP, 0x01 }, /* Enable */
  1711. { 0x31, 0x0f },
  1712. { 0x5d, 0x03 },
  1713. { 0x24, 0x9f },
  1714. { 0x25, 0x90 },
  1715. { 0x20, 0x00 },
  1716. { 0x51, 0x04 },
  1717. { 0x71, 0x19 },
  1718. { 0x2f, 0x80 },
  1719. };
  1720. static struct ov_regvals norm_518_p[] = {
  1721. { R51x_SYS_SNAP, 0x02 }, /* Reset */
  1722. { R51x_SYS_SNAP, 0x01 }, /* Enable */
  1723. { 0x31, 0x0f },
  1724. { 0x5d, 0x03 },
  1725. { 0x24, 0x9f },
  1726. { 0x25, 0x90 },
  1727. { 0x20, 0x60 },
  1728. { 0x51, 0x02 },
  1729. { 0x71, 0x19 },
  1730. { 0x40, 0xff },
  1731. { 0x41, 0x42 },
  1732. { 0x46, 0x00 },
  1733. { 0x33, 0x04 },
  1734. { 0x21, 0x19 },
  1735. { 0x3f, 0x10 },
  1736. { 0x2f, 0x80 },
  1737. };
  1738. /* First 5 bits of custom ID reg are a revision ID on OV518 */
  1739. PDEBUG(D_PROBE, "Device revision %d",
  1740. 0x1F & reg_r(sd, R51x_SYS_CUST_ID));
  1741. rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518));
  1742. if (rc < 0)
  1743. return rc;
  1744. /* Set LED GPIO pin to output mode */
  1745. rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
  1746. if (rc < 0)
  1747. return rc;
  1748. switch (sd->bridge) {
  1749. case BRIDGE_OV518:
  1750. rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
  1751. if (rc < 0)
  1752. return rc;
  1753. break;
  1754. case BRIDGE_OV518PLUS:
  1755. rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
  1756. if (rc < 0)
  1757. return rc;
  1758. break;
  1759. }
  1760. rc = ov51x_upload_quan_tables(sd);
  1761. if (rc < 0) {
  1762. PDEBUG(D_ERR, "Error uploading quantization tables");
  1763. return rc;
  1764. }
  1765. rc = reg_w(sd, 0x2f, 0x80);
  1766. if (rc < 0)
  1767. return rc;
  1768. return 0;
  1769. }
  1770. static int ov519_configure(struct sd *sd)
  1771. {
  1772. static const struct ov_regvals init_519[] = {
  1773. { 0x5a, 0x6d }, /* EnableSystem */
  1774. { 0x53, 0x9b },
  1775. { 0x54, 0xff }, /* set bit2 to enable jpeg */
  1776. { 0x5d, 0x03 },
  1777. { 0x49, 0x01 },
  1778. { 0x48, 0x00 },
  1779. /* Set LED pin to output mode. Bit 4 must be cleared or sensor
  1780. * detection will fail. This deserves further investigation. */
  1781. { OV519_GPIO_IO_CTRL0, 0xee },
  1782. { 0x51, 0x0f }, /* SetUsbInit */
  1783. { 0x51, 0x00 },
  1784. { 0x22, 0x00 },
  1785. /* windows reads 0x55 at this point*/
  1786. };
  1787. return write_regvals(sd, init_519, ARRAY_SIZE(init_519));
  1788. }
  1789. /* this function is called at probe time */
  1790. static int sd_config(struct gspca_dev *gspca_dev,
  1791. const struct usb_device_id *id)
  1792. {
  1793. struct sd *sd = (struct sd *) gspca_dev;
  1794. struct cam *cam;
  1795. int ret = 0;
  1796. sd->bridge = id->driver_info & BRIDGE_MASK;
  1797. sd->invert_led = id->driver_info & BRIDGE_INVERT_LED;
  1798. switch (sd->bridge) {
  1799. case BRIDGE_OV511:
  1800. case BRIDGE_OV511PLUS:
  1801. ret = ov511_configure(gspca_dev);
  1802. break;
  1803. case BRIDGE_OV518:
  1804. case BRIDGE_OV518PLUS:
  1805. ret = ov518_configure(gspca_dev);
  1806. break;
  1807. case BRIDGE_OV519:
  1808. ret = ov519_configure(sd);
  1809. break;
  1810. }
  1811. if (ret)
  1812. goto error;
  1813. ov51x_led_control(sd, 0); /* turn LED off */
  1814. /* Test for 76xx */
  1815. if (ov51x_set_slave_ids(sd, OV7xx0_SID) < 0)
  1816. goto error;
  1817. /* The OV519 must be more aggressive about sensor detection since
  1818. * I2C write will never fail if the sensor is not present. We have
  1819. * to try to initialize the sensor to detect its presence */
  1820. if (init_ov_sensor(sd) >= 0) {
  1821. if (ov7xx0_configure(sd) < 0) {
  1822. PDEBUG(D_ERR, "Failed to configure OV7xx0");
  1823. goto error;
  1824. }
  1825. } else {
  1826. /* Test for 6xx0 */
  1827. if (ov51x_set_slave_ids(sd, OV6xx0_SID) < 0)
  1828. goto error;
  1829. if (init_ov_sensor(sd) >= 0) {
  1830. if (ov6xx0_configure(sd) < 0) {
  1831. PDEBUG(D_ERR, "Failed to configure OV6xx0");
  1832. goto error;
  1833. }
  1834. } else {
  1835. /* Test for 8xx0 */
  1836. if (ov51x_set_slave_ids(sd, OV8xx0_SID) < 0)
  1837. goto error;
  1838. if (init_ov_sensor(sd) < 0) {
  1839. PDEBUG(D_ERR,
  1840. "Can't determine sensor slave IDs");
  1841. goto error;
  1842. }
  1843. if (ov8xx0_configure(sd) < 0) {
  1844. PDEBUG(D_ERR,
  1845. "Failed to configure OV8xx0 sensor");
  1846. goto error;
  1847. }
  1848. }
  1849. }
  1850. cam = &gspca_dev->cam;
  1851. switch (sd->bridge) {
  1852. case BRIDGE_OV511:
  1853. case BRIDGE_OV511PLUS:
  1854. if (!sd->sif) {
  1855. cam->cam_mode = ov511_vga_mode;
  1856. cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
  1857. } else {
  1858. cam->cam_mode = ov511_sif_mode;
  1859. cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
  1860. }
  1861. break;
  1862. case BRIDGE_OV518:
  1863. case BRIDGE_OV518PLUS:
  1864. if (!sd->sif) {
  1865. cam->cam_mode = ov518_vga_mode;
  1866. cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
  1867. } else {
  1868. cam->cam_mode = ov518_sif_mode;
  1869. cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
  1870. }
  1871. break;
  1872. case BRIDGE_OV519:
  1873. if (!sd->sif) {
  1874. cam->cam_mode = ov519_vga_mode;
  1875. cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
  1876. } else {
  1877. cam->cam_mode = ov519_sif_mode;
  1878. cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
  1879. }
  1880. break;
  1881. }
  1882. sd->brightness = BRIGHTNESS_DEF;
  1883. if (sd->sensor == SEN_OV6630 || sd->sensor == SEN_OV66308AF)
  1884. sd->contrast = 200; /* The default is too low for the ov6630 */
  1885. else
  1886. sd->contrast = CONTRAST_DEF;
  1887. sd->colors = COLOR_DEF;
  1888. sd->hflip = HFLIP_DEF;
  1889. sd->vflip = VFLIP_DEF;
  1890. sd->autobrightness = AUTOBRIGHT_DEF;
  1891. if (sd->sensor == SEN_OV7670) {
  1892. sd->freq = OV7670_FREQ_DEF;
  1893. gspca_dev->ctrl_dis = 1 << FREQ_IDX;
  1894. } else {
  1895. sd->freq = FREQ_DEF;
  1896. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
  1897. (1 << OV7670_FREQ_IDX);
  1898. }
  1899. if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
  1900. gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX;
  1901. /* OV8610 Frequency filter control should work but needs testing */
  1902. if (sd->sensor == SEN_OV8610)
  1903. gspca_dev->ctrl_dis |= 1 << FREQ_IDX;
  1904. return 0;
  1905. error:
  1906. PDEBUG(D_ERR, "OV519 Config failed");
  1907. return -EBUSY;
  1908. }
  1909. /* this function is called at probe and resume time */
  1910. static int sd_init(struct gspca_dev *gspca_dev)
  1911. {
  1912. struct sd *sd = (struct sd *) gspca_dev;
  1913. /* initialize the sensor */
  1914. switch (sd->sensor) {
  1915. case SEN_OV6620:
  1916. if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
  1917. return -EIO;
  1918. break;
  1919. case SEN_OV6630:
  1920. case SEN_OV66308AF:
  1921. if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
  1922. return -EIO;
  1923. break;
  1924. default:
  1925. /* case SEN_OV7610: */
  1926. /* case SEN_OV76BE: */
  1927. if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
  1928. return -EIO;
  1929. break;
  1930. case SEN_OV7620:
  1931. if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
  1932. return -EIO;
  1933. break;
  1934. case SEN_OV7640:
  1935. if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
  1936. return -EIO;
  1937. break;
  1938. case SEN_OV7670:
  1939. if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
  1940. return -EIO;
  1941. break;
  1942. case SEN_OV8610:
  1943. if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
  1944. return -EIO;
  1945. break;
  1946. }
  1947. return 0;
  1948. }
  1949. /* Set up the OV511/OV511+ with the given image parameters.
  1950. *
  1951. * Do not put any sensor-specific code in here (including I2C I/O functions)
  1952. */
  1953. static int ov511_mode_init_regs(struct sd *sd)
  1954. {
  1955. int hsegs, vsegs, packet_size, fps, needed;
  1956. int interlaced = 0;
  1957. struct usb_host_interface *alt;
  1958. struct usb_interface *intf;
  1959. intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
  1960. alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
  1961. if (!alt) {
  1962. PDEBUG(D_ERR, "Couldn't get altsetting");
  1963. return -EIO;
  1964. }
  1965. packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
  1966. reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
  1967. reg_w(sd, R511_CAM_UV_EN, 0x01);
  1968. reg_w(sd, R511_SNAP_UV_EN, 0x01);
  1969. reg_w(sd, R511_SNAP_OPTS, 0x03);
  1970. /* Here I'm assuming that snapshot size == image size.
  1971. * I hope that's always true. --claudio
  1972. */
  1973. hsegs = (sd->gspca_dev.width >> 3) - 1;
  1974. vsegs = (sd->gspca_dev.height >> 3) - 1;
  1975. reg_w(sd, R511_CAM_PXCNT, hsegs);
  1976. reg_w(sd, R511_CAM_LNCNT, vsegs);
  1977. reg_w(sd, R511_CAM_PXDIV, 0x00);
  1978. reg_w(sd, R511_CAM_LNDIV, 0x00);
  1979. /* YUV420, low pass filter on */
  1980. reg_w(sd, R511_CAM_OPTS, 0x03);
  1981. /* Snapshot additions */
  1982. reg_w(sd, R511_SNAP_PXCNT, hsegs);
  1983. reg_w(sd, R511_SNAP_LNCNT, vsegs);
  1984. reg_w(sd, R511_SNAP_PXDIV, 0x00);
  1985. reg_w(sd, R511_SNAP_LNDIV, 0x00);
  1986. /******** Set the framerate ********/
  1987. if (frame_rate > 0)
  1988. sd->frame_rate = frame_rate;
  1989. switch (sd->sensor) {
  1990. case SEN_OV6620:
  1991. /* No framerate control, doesn't like higher rates yet */
  1992. sd->clockdiv = 3;
  1993. break;
  1994. /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
  1995. for more sensors we need to do this for them too */
  1996. case SEN_OV7620:
  1997. case SEN_OV7640:
  1998. if (sd->gspca_dev.width == 320)
  1999. interlaced = 1;
  2000. /* Fall through */
  2001. case SEN_OV6630:
  2002. case SEN_OV76BE:
  2003. case SEN_OV7610:
  2004. case SEN_OV7670:
  2005. switch (sd->frame_rate) {
  2006. case 30:
  2007. case 25:
  2008. /* Not enough bandwidth to do 640x480 @ 30 fps */
  2009. if (sd->gspca_dev.width != 640) {
  2010. sd->clockdiv = 0;
  2011. break;
  2012. }
  2013. /* Fall through for 640x480 case */
  2014. default:
  2015. /* case 20: */
  2016. /* case 15: */
  2017. sd->clockdiv = 1;
  2018. break;
  2019. case 10:
  2020. sd->clockdiv = 2;
  2021. break;
  2022. case 5:
  2023. sd->clockdiv = 5;
  2024. break;
  2025. }
  2026. if (interlaced) {
  2027. sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
  2028. /* Higher then 10 does not work */
  2029. if (sd->clockdiv > 10)
  2030. sd->clockdiv = 10;
  2031. }
  2032. break;
  2033. case SEN_OV8610:
  2034. /* No framerate control ?? */
  2035. sd->clockdiv = 0;
  2036. break;
  2037. }
  2038. /* Check if we have enough bandwidth to disable compression */
  2039. fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
  2040. needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
  2041. /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
  2042. if (needed > 1400 * packet_size) {
  2043. /* Enable Y and UV quantization and compression */
  2044. reg_w(sd, R511_COMP_EN, 0x07);
  2045. reg_w(sd, R511_COMP_LUT_EN, 0x03);
  2046. } else {
  2047. reg_w(sd, R511_COMP_EN, 0x06);
  2048. reg_w(sd, R511_COMP_LUT_EN, 0x00);
  2049. }
  2050. reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
  2051. reg_w(sd, R51x_SYS_RESET, 0);
  2052. return 0;
  2053. }
  2054. /* Sets up the OV518/OV518+ with the given image parameters
  2055. *
  2056. * OV518 needs a completely different approach, until we can figure out what
  2057. * the individual registers do. Also, only 15 FPS is supported now.
  2058. *
  2059. * Do not put any sensor-specific code in here (including I2C I/O functions)
  2060. */
  2061. static int ov518_mode_init_regs(struct sd *sd)
  2062. {
  2063. int hsegs, vsegs;
  2064. /******** Set the mode ********/
  2065. reg_w(sd, 0x2b, 0);
  2066. reg_w(sd, 0x2c, 0);
  2067. reg_w(sd, 0x2d, 0);
  2068. reg_w(sd, 0x2e, 0);
  2069. reg_w(sd, 0x3b, 0);
  2070. reg_w(sd, 0x3c, 0);
  2071. reg_w(sd, 0x3d, 0);
  2072. reg_w(sd, 0x3e, 0);
  2073. if (sd->bridge == BRIDGE_OV518) {
  2074. /* Set 8-bit (YVYU) input format */
  2075. reg_w_mask(sd, 0x20, 0x08, 0x08);
  2076. /* Set 12-bit (4:2:0) output format */
  2077. reg_w_mask(sd, 0x28, 0x80, 0xf0);
  2078. reg_w_mask(sd, 0x38, 0x80, 0xf0);
  2079. } else {
  2080. reg_w(sd, 0x28, 0x80);
  2081. reg_w(sd, 0x38, 0x80);
  2082. }
  2083. hsegs = sd->gspca_dev.width / 16;
  2084. vsegs = sd->gspca_dev.height / 4;
  2085. reg_w(sd, 0x29, hsegs);
  2086. reg_w(sd, 0x2a, vsegs);
  2087. reg_w(sd, 0x39, hsegs);
  2088. reg_w(sd, 0x3a, vsegs);
  2089. /* Windows driver does this here; who knows why */
  2090. reg_w(sd, 0x2f, 0x80);
  2091. /******** Set the framerate (to 30 FPS) ********/
  2092. if (sd->bridge == BRIDGE_OV518PLUS)
  2093. sd->clockdiv = 1;
  2094. else
  2095. sd->clockdiv = 0;
  2096. /* Mode independent, but framerate dependent, regs */
  2097. reg_w(sd, 0x51, 0x04); /* Clock divider; lower==faster */
  2098. reg_w(sd, 0x22, 0x18);
  2099. reg_w(sd, 0x23, 0xff);
  2100. if (sd->bridge == BRIDGE_OV518PLUS)
  2101. reg_w(sd, 0x21, 0x19);
  2102. else
  2103. reg_w(sd, 0x71, 0x17); /* Compression-related? */
  2104. /* FIXME: Sensor-specific */
  2105. /* Bit 5 is what matters here. Of course, it is "reserved" */
  2106. i2c_w(sd, 0x54, 0x23);
  2107. reg_w(sd, 0x2f, 0x80);
  2108. if (sd->bridge == BRIDGE_OV518PLUS) {
  2109. reg_w(sd, 0x24, 0x94);
  2110. reg_w(sd, 0x25, 0x90);
  2111. ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
  2112. ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
  2113. ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
  2114. ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
  2115. ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
  2116. ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
  2117. ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
  2118. ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
  2119. ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
  2120. } else {
  2121. reg_w(sd, 0x24, 0x9f);
  2122. reg_w(sd, 0x25, 0x90);
  2123. ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
  2124. ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
  2125. ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
  2126. ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
  2127. ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
  2128. ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
  2129. ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
  2130. ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
  2131. ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
  2132. }
  2133. reg_w(sd, 0x2f, 0x80);
  2134. return 0;
  2135. }
  2136. /* Sets up the OV519 with the given image parameters
  2137. *
  2138. * OV519 needs a completely different approach, until we can figure out what
  2139. * the individual registers do.
  2140. *
  2141. * Do not put any sensor-specific code in here (including I2C I/O functions)
  2142. */
  2143. static int ov519_mode_init_regs(struct sd *sd)
  2144. {
  2145. static const struct ov_regvals mode_init_519_ov7670[] = {
  2146. { 0x5d, 0x03 }, /* Turn off suspend mode */
  2147. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  2148. { 0x54, 0x0f }, /* bit2 (jpeg enable) */
  2149. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  2150. { 0xa3, 0x18 },
  2151. { 0xa4, 0x04 },
  2152. { 0xa5, 0x28 },
  2153. { 0x37, 0x00 }, /* SetUsbInit */
  2154. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  2155. /* Enable both fields, YUV Input, disable defect comp (why?) */
  2156. { 0x20, 0x0c },
  2157. { 0x21, 0x38 },
  2158. { 0x22, 0x1d },
  2159. { 0x17, 0x50 }, /* undocumented */
  2160. { 0x37, 0x00 }, /* undocumented */
  2161. { 0x40, 0xff }, /* I2C timeout counter */
  2162. { 0x46, 0x00 }, /* I2C clock prescaler */
  2163. { 0x59, 0x04 }, /* new from windrv 090403 */
  2164. { 0xff, 0x00 }, /* undocumented */
  2165. /* windows reads 0x55 at this point, why? */
  2166. };
  2167. static const struct ov_regvals mode_init_519[] = {
  2168. { 0x5d, 0x03 }, /* Turn off suspend mode */
  2169. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  2170. { 0x54, 0x0f }, /* bit2 (jpeg enable) */
  2171. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  2172. { 0xa3, 0x18 },
  2173. { 0xa4, 0x04 },
  2174. { 0xa5, 0x28 },
  2175. { 0x37, 0x00 }, /* SetUsbInit */
  2176. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  2177. /* Enable both fields, YUV Input, disable defect comp (why?) */
  2178. { 0x22, 0x1d },
  2179. { 0x17, 0x50 }, /* undocumented */
  2180. { 0x37, 0x00 }, /* undocumented */
  2181. { 0x40, 0xff }, /* I2C timeout counter */
  2182. { 0x46, 0x00 }, /* I2C clock prescaler */
  2183. { 0x59, 0x04 }, /* new from windrv 090403 */
  2184. { 0xff, 0x00 }, /* undocumented */
  2185. /* windows reads 0x55 at this point, why? */
  2186. };
  2187. /******** Set the mode ********/
  2188. if (sd->sensor != SEN_OV7670) {
  2189. if (write_regvals(sd, mode_init_519,
  2190. ARRAY_SIZE(mode_init_519)))
  2191. return -EIO;
  2192. if (sd->sensor == SEN_OV7640) {
  2193. /* Select 8-bit input mode */
  2194. reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
  2195. }
  2196. } else {
  2197. if (write_regvals(sd, mode_init_519_ov7670,
  2198. ARRAY_SIZE(mode_init_519_ov7670)))
  2199. return -EIO;
  2200. }
  2201. reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
  2202. reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
  2203. if (sd->sensor == SEN_OV7670 &&
  2204. sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
  2205. reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
  2206. else
  2207. reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
  2208. reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
  2209. reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
  2210. reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
  2211. reg_w(sd, OV519_R16_DIVIDER, 0x00);
  2212. reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
  2213. reg_w(sd, 0x26, 0x00); /* Undocumented */
  2214. /******** Set the framerate ********/
  2215. if (frame_rate > 0)
  2216. sd->frame_rate = frame_rate;
  2217. /* FIXME: These are only valid at the max resolution. */
  2218. sd->clockdiv = 0;
  2219. switch (sd->sensor) {
  2220. case SEN_OV7640:
  2221. switch (sd->frame_rate) {
  2222. default:
  2223. /* case 30: */
  2224. reg_w(sd, 0xa4, 0x0c);
  2225. reg_w(sd, 0x23, 0xff);
  2226. break;
  2227. case 25:
  2228. reg_w(sd, 0xa4, 0x0c);
  2229. reg_w(sd, 0x23, 0x1f);
  2230. break;
  2231. case 20:
  2232. reg_w(sd, 0xa4, 0x0c);
  2233. reg_w(sd, 0x23, 0x1b);
  2234. break;
  2235. case 15:
  2236. reg_w(sd, 0xa4, 0x04);
  2237. reg_w(sd, 0x23, 0xff);
  2238. sd->clockdiv = 1;
  2239. break;
  2240. case 10:
  2241. reg_w(sd, 0xa4, 0x04);
  2242. reg_w(sd, 0x23, 0x1f);
  2243. sd->clockdiv = 1;
  2244. break;
  2245. case 5:
  2246. reg_w(sd, 0xa4, 0x04);
  2247. reg_w(sd, 0x23, 0x1b);
  2248. sd->clockdiv = 1;
  2249. break;
  2250. }
  2251. break;
  2252. case SEN_OV8610:
  2253. switch (sd->frame_rate) {
  2254. default: /* 15 fps */
  2255. /* case 15: */
  2256. reg_w(sd, 0xa4, 0x06);
  2257. reg_w(sd, 0x23, 0xff);
  2258. break;
  2259. case 10:
  2260. reg_w(sd, 0xa4, 0x06);
  2261. reg_w(sd, 0x23, 0x1f);
  2262. break;
  2263. case 5:
  2264. reg_w(sd, 0xa4, 0x06);
  2265. reg_w(sd, 0x23, 0x1b);
  2266. break;
  2267. }
  2268. break;
  2269. case SEN_OV7670: /* guesses, based on 7640 */
  2270. PDEBUG(D_STREAM, "Setting framerate to %d fps",
  2271. (sd->frame_rate == 0) ? 15 : sd->frame_rate);
  2272. reg_w(sd, 0xa4, 0x10);
  2273. switch (sd->frame_rate) {
  2274. case 30:
  2275. reg_w(sd, 0x23, 0xff);
  2276. break;
  2277. case 20:
  2278. reg_w(sd, 0x23, 0x1b);
  2279. break;
  2280. default:
  2281. /* case 15: */
  2282. reg_w(sd, 0x23, 0xff);
  2283. sd->clockdiv = 1;
  2284. break;
  2285. }
  2286. break;
  2287. }
  2288. return 0;
  2289. }
  2290. static int mode_init_ov_sensor_regs(struct sd *sd)
  2291. {
  2292. struct gspca_dev *gspca_dev;
  2293. int qvga;
  2294. gspca_dev = &sd->gspca_dev;
  2295. qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
  2296. /******** Mode (VGA/QVGA) and sensor specific regs ********/
  2297. switch (sd->sensor) {
  2298. case SEN_OV8610:
  2299. /* For OV8610 qvga means qsvga */
  2300. i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
  2301. break;
  2302. case SEN_OV7610:
  2303. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  2304. break;
  2305. case SEN_OV7620:
  2306. /* i2c_w(sd, 0x2b, 0x00); */
  2307. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  2308. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  2309. i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
  2310. i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
  2311. i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
  2312. i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
  2313. i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
  2314. break;
  2315. case SEN_OV76BE:
  2316. /* i2c_w(sd, 0x2b, 0x00); */
  2317. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  2318. break;
  2319. case SEN_OV7640:
  2320. /* i2c_w(sd, 0x2b, 0x00); */
  2321. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  2322. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  2323. /* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
  2324. /* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
  2325. /* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
  2326. /* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
  2327. /* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
  2328. break;
  2329. case SEN_OV7670:
  2330. /* set COM7_FMT_VGA or COM7_FMT_QVGA
  2331. * do we need to set anything else?
  2332. * HSTART etc are set in set_ov_sensor_window itself */
  2333. i2c_w_mask(sd, OV7670_REG_COM7,
  2334. qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
  2335. OV7670_COM7_FMT_MASK);
  2336. break;
  2337. case SEN_OV6620:
  2338. case SEN_OV6630:
  2339. case SEN_OV66308AF:
  2340. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  2341. break;
  2342. default:
  2343. return -EINVAL;
  2344. }
  2345. /******** Palette-specific regs ********/
  2346. if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
  2347. /* not valid on the OV6620/OV7620/6630? */
  2348. i2c_w_mask(sd, 0x0e, 0x00, 0x40);
  2349. }
  2350. /* The OV518 needs special treatment. Although both the OV518
  2351. * and the OV6630 support a 16-bit video bus, only the 8 bit Y
  2352. * bus is actually used. The UV bus is tied to ground.
  2353. * Therefore, the OV6630 needs to be in 8-bit multiplexed
  2354. * output mode */
  2355. /* OV7640 is 8-bit only */
  2356. if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV66308AF &&
  2357. sd->sensor != SEN_OV7640)
  2358. i2c_w_mask(sd, 0x13, 0x00, 0x20);
  2359. /******** Clock programming ********/
  2360. /* The OV6620 needs special handling. This prevents the
  2361. * severe banding that normally occurs */
  2362. if (sd->sensor == SEN_OV6620) {
  2363. /* Clock down */
  2364. i2c_w(sd, 0x2a, 0x04);
  2365. i2c_w(sd, 0x11, sd->clockdiv);
  2366. i2c_w(sd, 0x2a, 0x84);
  2367. /* This next setting is critical. It seems to improve
  2368. * the gain or the contrast. The "reserved" bits seem
  2369. * to have some effect in this case. */
  2370. i2c_w(sd, 0x2d, 0x85);
  2371. } else {
  2372. i2c_w(sd, 0x11, sd->clockdiv);
  2373. }
  2374. /******** Special Features ********/
  2375. /* no evidence this is possible with OV7670, either */
  2376. /* Test Pattern */
  2377. if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670)
  2378. i2c_w_mask(sd, 0x12, 0x00, 0x02);
  2379. /* Enable auto white balance */
  2380. if (sd->sensor == SEN_OV7670)
  2381. i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
  2382. OV7670_COM8_AWB);
  2383. else
  2384. i2c_w_mask(sd, 0x12, 0x04, 0x04);
  2385. /* This will go away as soon as ov51x_mode_init_sensor_regs() */
  2386. /* is fully tested. */
  2387. /* 7620/6620/6630? don't have register 0x35, so play it safe */
  2388. if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
  2389. if (!qvga)
  2390. i2c_w(sd, 0x35, 0x9e);
  2391. else
  2392. i2c_w(sd, 0x35, 0x1e);
  2393. }
  2394. return 0;
  2395. }
  2396. static void sethvflip(struct sd *sd)
  2397. {
  2398. if (sd->sensor != SEN_OV7670)
  2399. return;
  2400. if (sd->gspca_dev.streaming)
  2401. ov51x_stop(sd);
  2402. i2c_w_mask(sd, OV7670_REG_MVFP,
  2403. OV7670_MVFP_MIRROR * sd->hflip
  2404. | OV7670_MVFP_VFLIP * sd->vflip,
  2405. OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
  2406. if (sd->gspca_dev.streaming)
  2407. ov51x_restart(sd);
  2408. }
  2409. static int set_ov_sensor_window(struct sd *sd)
  2410. {
  2411. struct gspca_dev *gspca_dev;
  2412. int qvga, crop;
  2413. int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
  2414. int ret, hstart, hstop, vstop, vstart;
  2415. __u8 v;
  2416. gspca_dev = &sd->gspca_dev;
  2417. qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
  2418. crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2;
  2419. /* The different sensor ICs handle setting up of window differently.
  2420. * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
  2421. switch (sd->sensor) {
  2422. case SEN_OV8610:
  2423. hwsbase = 0x1e;
  2424. hwebase = 0x1e;
  2425. vwsbase = 0x02;
  2426. vwebase = 0x02;
  2427. break;
  2428. case SEN_OV7610:
  2429. case SEN_OV76BE:
  2430. hwsbase = 0x38;
  2431. hwebase = 0x3a;
  2432. vwsbase = vwebase = 0x05;
  2433. break;
  2434. case SEN_OV6620:
  2435. case SEN_OV6630:
  2436. case SEN_OV66308AF:
  2437. hwsbase = 0x38;
  2438. hwebase = 0x3a;
  2439. vwsbase = 0x05;
  2440. vwebase = 0x06;
  2441. if (sd->sensor == SEN_OV66308AF && qvga)
  2442. /* HDG: this fixes U and V getting swapped */
  2443. hwsbase++;
  2444. if (crop) {
  2445. hwsbase += 8;
  2446. hwebase += 8;
  2447. vwsbase += 11;
  2448. vwebase += 11;
  2449. }
  2450. break;
  2451. case SEN_OV7620:
  2452. hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
  2453. hwebase = 0x2f;
  2454. vwsbase = vwebase = 0x05;
  2455. break;
  2456. case SEN_OV7640:
  2457. hwsbase = 0x1a;
  2458. hwebase = 0x1a;
  2459. vwsbase = vwebase = 0x03;
  2460. break;
  2461. case SEN_OV7670:
  2462. /*handling of OV7670 hardware sensor start and stop values
  2463. * is very odd, compared to the other OV sensors */
  2464. vwsbase = vwebase = hwebase = hwsbase = 0x00;
  2465. break;
  2466. default:
  2467. return -EINVAL;
  2468. }
  2469. switch (sd->sensor) {
  2470. case SEN_OV6620:
  2471. case SEN_OV6630:
  2472. case SEN_OV66308AF:
  2473. if (qvga) { /* QCIF */
  2474. hwscale = 0;
  2475. vwscale = 0;
  2476. } else { /* CIF */
  2477. hwscale = 1;
  2478. vwscale = 1; /* The datasheet says 0;
  2479. * it's wrong */
  2480. }
  2481. break;
  2482. case SEN_OV8610:
  2483. if (qvga) { /* QSVGA */
  2484. hwscale = 1;
  2485. vwscale = 1;
  2486. } else { /* SVGA */
  2487. hwscale = 2;
  2488. vwscale = 2;
  2489. }
  2490. break;
  2491. default: /* SEN_OV7xx0 */
  2492. if (qvga) { /* QVGA */
  2493. hwscale = 1;
  2494. vwscale = 0;
  2495. } else { /* VGA */
  2496. hwscale = 2;
  2497. vwscale = 1;
  2498. }
  2499. }
  2500. ret = mode_init_ov_sensor_regs(sd);
  2501. if (ret < 0)
  2502. return ret;
  2503. if (sd->sensor == SEN_OV8610) {
  2504. i2c_w_mask(sd, 0x2d, 0x05, 0x40);
  2505. /* old 0x95, new 0x05 from windrv 090403 */
  2506. /* bits 5-7: reserved */
  2507. i2c_w_mask(sd, 0x28, 0x20, 0x20);
  2508. /* bit 5: progressive mode on */
  2509. }
  2510. /* The below is wrong for OV7670s because their window registers
  2511. * only store the high bits in 0x17 to 0x1a */
  2512. /* SRH Use sd->max values instead of requested win values */
  2513. /* SCS Since we're sticking with only the max hardware widths
  2514. * for a given mode */
  2515. /* I can hard code this for OV7670s */
  2516. /* Yes, these numbers do look odd, but they're tested and work! */
  2517. if (sd->sensor == SEN_OV7670) {
  2518. if (qvga) { /* QVGA from ov7670.c by
  2519. * Jonathan Corbet */
  2520. hstart = 164;
  2521. hstop = 28;
  2522. vstart = 14;
  2523. vstop = 494;
  2524. } else { /* VGA */
  2525. hstart = 158;
  2526. hstop = 14;
  2527. vstart = 10;
  2528. vstop = 490;
  2529. }
  2530. /* OV7670 hardware window registers are split across
  2531. * multiple locations */
  2532. i2c_w(sd, OV7670_REG_HSTART, hstart >> 3);
  2533. i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3);
  2534. v = i2c_r(sd, OV7670_REG_HREF);
  2535. v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07);
  2536. msleep(10); /* need to sleep between read and write to
  2537. * same reg! */
  2538. i2c_w(sd, OV7670_REG_HREF, v);
  2539. i2c_w(sd, OV7670_REG_VSTART, vstart >> 2);
  2540. i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2);
  2541. v = i2c_r(sd, OV7670_REG_VREF);
  2542. v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03);
  2543. msleep(10); /* need to sleep between read and write to
  2544. * same reg! */
  2545. i2c_w(sd, OV7670_REG_VREF, v);
  2546. } else {
  2547. i2c_w(sd, 0x17, hwsbase);
  2548. i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale));
  2549. i2c_w(sd, 0x19, vwsbase);
  2550. i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale));
  2551. }
  2552. return 0;
  2553. }
  2554. /* -- start the camera -- */
  2555. static int sd_start(struct gspca_dev *gspca_dev)
  2556. {
  2557. struct sd *sd = (struct sd *) gspca_dev;
  2558. int ret = 0;
  2559. switch (sd->bridge) {
  2560. case BRIDGE_OV511:
  2561. case BRIDGE_OV511PLUS:
  2562. ret = ov511_mode_init_regs(sd);
  2563. break;
  2564. case BRIDGE_OV518:
  2565. case BRIDGE_OV518PLUS:
  2566. ret = ov518_mode_init_regs(sd);
  2567. break;
  2568. case BRIDGE_OV519:
  2569. ret = ov519_mode_init_regs(sd);
  2570. break;
  2571. }
  2572. if (ret < 0)
  2573. goto out;
  2574. ret = set_ov_sensor_window(sd);
  2575. if (ret < 0)
  2576. goto out;
  2577. setcontrast(gspca_dev);
  2578. setbrightness(gspca_dev);
  2579. setcolors(gspca_dev);
  2580. sethvflip(sd);
  2581. setautobrightness(sd);
  2582. setfreq(sd);
  2583. ret = ov51x_restart(sd);
  2584. if (ret < 0)
  2585. goto out;
  2586. ov51x_led_control(sd, 1);
  2587. return 0;
  2588. out:
  2589. PDEBUG(D_ERR, "camera start error:%d", ret);
  2590. return ret;
  2591. }
  2592. static void sd_stopN(struct gspca_dev *gspca_dev)
  2593. {
  2594. struct sd *sd = (struct sd *) gspca_dev;
  2595. ov51x_stop(sd);
  2596. ov51x_led_control(sd, 0);
  2597. }
  2598. static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
  2599. struct gspca_frame *frame, /* target */
  2600. __u8 *in, /* isoc packet */
  2601. int len) /* iso packet length */
  2602. {
  2603. struct sd *sd = (struct sd *) gspca_dev;
  2604. /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
  2605. * byte non-zero. The EOF packet has image width/height in the
  2606. * 10th and 11th bytes. The 9th byte is given as follows:
  2607. *
  2608. * bit 7: EOF
  2609. * 6: compression enabled
  2610. * 5: 422/420/400 modes
  2611. * 4: 422/420/400 modes
  2612. * 3: 1
  2613. * 2: snapshot button on
  2614. * 1: snapshot frame
  2615. * 0: even/odd field
  2616. */
  2617. if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
  2618. (in[8] & 0x08)) {
  2619. if (in[8] & 0x80) {
  2620. /* Frame end */
  2621. if ((in[9] + 1) * 8 != gspca_dev->width ||
  2622. (in[10] + 1) * 8 != gspca_dev->height) {
  2623. PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
  2624. " requested: %dx%d\n",
  2625. (in[9] + 1) * 8, (in[10] + 1) * 8,
  2626. gspca_dev->width, gspca_dev->height);
  2627. gspca_dev->last_packet_type = DISCARD_PACKET;
  2628. return;
  2629. }
  2630. /* Add 11 byte footer to frame, might be usefull */
  2631. gspca_frame_add(gspca_dev, LAST_PACKET, frame, in, 11);
  2632. return;
  2633. } else {
  2634. /* Frame start */
  2635. gspca_frame_add(gspca_dev, FIRST_PACKET, frame, in, 0);
  2636. sd->packet_nr = 0;
  2637. }
  2638. }
  2639. /* Ignore the packet number */
  2640. len--;
  2641. /* intermediate packet */
  2642. gspca_frame_add(gspca_dev, INTER_PACKET, frame, in, len);
  2643. }
  2644. static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
  2645. struct gspca_frame *frame, /* target */
  2646. __u8 *data, /* isoc packet */
  2647. int len) /* iso packet length */
  2648. {
  2649. struct sd *sd = (struct sd *) gspca_dev;
  2650. /* A false positive here is likely, until OVT gives me
  2651. * the definitive SOF/EOF format */
  2652. if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
  2653. gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0);
  2654. gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, 0);
  2655. sd->packet_nr = 0;
  2656. }
  2657. if (gspca_dev->last_packet_type == DISCARD_PACKET)
  2658. return;
  2659. /* Does this device use packet numbers ? */
  2660. if (len & 7) {
  2661. len--;
  2662. if (sd->packet_nr == data[len])
  2663. sd->packet_nr++;
  2664. /* The last few packets of the frame (which are all 0's
  2665. except that they may contain part of the footer), are
  2666. numbered 0 */
  2667. else if (sd->packet_nr == 0 || data[len]) {
  2668. PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
  2669. (int)data[len], (int)sd->packet_nr);
  2670. gspca_dev->last_packet_type = DISCARD_PACKET;
  2671. return;
  2672. }
  2673. }
  2674. /* intermediate packet */
  2675. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  2676. }
  2677. static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
  2678. struct gspca_frame *frame, /* target */
  2679. __u8 *data, /* isoc packet */
  2680. int len) /* iso packet length */
  2681. {
  2682. /* Header of ov519 is 16 bytes:
  2683. * Byte Value Description
  2684. * 0 0xff magic
  2685. * 1 0xff magic
  2686. * 2 0xff magic
  2687. * 3 0xXX 0x50 = SOF, 0x51 = EOF
  2688. * 9 0xXX 0x01 initial frame without data,
  2689. * 0x00 standard frame with image
  2690. * 14 Lo in EOF: length of image data / 8
  2691. * 15 Hi
  2692. */
  2693. if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
  2694. switch (data[3]) {
  2695. case 0x50: /* start of frame */
  2696. #define HDRSZ 16
  2697. data += HDRSZ;
  2698. len -= HDRSZ;
  2699. #undef HDRSZ
  2700. if (data[0] == 0xff || data[1] == 0xd8)
  2701. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  2702. data, len);
  2703. else
  2704. gspca_dev->last_packet_type = DISCARD_PACKET;
  2705. return;
  2706. case 0x51: /* end of frame */
  2707. if (data[9] != 0)
  2708. gspca_dev->last_packet_type = DISCARD_PACKET;
  2709. gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  2710. data, 0);
  2711. return;
  2712. }
  2713. }
  2714. /* intermediate packet */
  2715. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  2716. data, len);
  2717. }
  2718. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2719. struct gspca_frame *frame, /* target */
  2720. __u8 *data, /* isoc packet */
  2721. int len) /* iso packet length */
  2722. {
  2723. struct sd *sd = (struct sd *) gspca_dev;
  2724. switch (sd->bridge) {
  2725. case BRIDGE_OV511:
  2726. case BRIDGE_OV511PLUS:
  2727. ov511_pkt_scan(gspca_dev, frame, data, len);
  2728. break;
  2729. case BRIDGE_OV518:
  2730. case BRIDGE_OV518PLUS:
  2731. ov518_pkt_scan(gspca_dev, frame, data, len);
  2732. break;
  2733. case BRIDGE_OV519:
  2734. ov519_pkt_scan(gspca_dev, frame, data, len);
  2735. break;
  2736. }
  2737. }
  2738. /* -- management routines -- */
  2739. static void setbrightness(struct gspca_dev *gspca_dev)
  2740. {
  2741. struct sd *sd = (struct sd *) gspca_dev;
  2742. int val;
  2743. val = sd->brightness;
  2744. switch (sd->sensor) {
  2745. case SEN_OV8610:
  2746. case SEN_OV7610:
  2747. case SEN_OV76BE:
  2748. case SEN_OV6620:
  2749. case SEN_OV6630:
  2750. case SEN_OV66308AF:
  2751. case SEN_OV7640:
  2752. i2c_w(sd, OV7610_REG_BRT, val);
  2753. break;
  2754. case SEN_OV7620:
  2755. /* 7620 doesn't like manual changes when in auto mode */
  2756. if (!sd->autobrightness)
  2757. i2c_w(sd, OV7610_REG_BRT, val);
  2758. break;
  2759. case SEN_OV7670:
  2760. /*win trace
  2761. * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
  2762. i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
  2763. break;
  2764. }
  2765. }
  2766. static void setcontrast(struct gspca_dev *gspca_dev)
  2767. {
  2768. struct sd *sd = (struct sd *) gspca_dev;
  2769. int val;
  2770. val = sd->contrast;
  2771. switch (sd->sensor) {
  2772. case SEN_OV7610:
  2773. case SEN_OV6620:
  2774. i2c_w(sd, OV7610_REG_CNT, val);
  2775. break;
  2776. case SEN_OV6630:
  2777. case SEN_OV66308AF:
  2778. i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
  2779. break;
  2780. case SEN_OV8610: {
  2781. static const __u8 ctab[] = {
  2782. 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
  2783. };
  2784. /* Use Y gamma control instead. Bit 0 enables it. */
  2785. i2c_w(sd, 0x64, ctab[val >> 5]);
  2786. break;
  2787. }
  2788. case SEN_OV7620: {
  2789. static const __u8 ctab[] = {
  2790. 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
  2791. 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
  2792. };
  2793. /* Use Y gamma control instead. Bit 0 enables it. */
  2794. i2c_w(sd, 0x64, ctab[val >> 4]);
  2795. break;
  2796. }
  2797. case SEN_OV7640:
  2798. /* Use gain control instead. */
  2799. i2c_w(sd, OV7610_REG_GAIN, val >> 2);
  2800. break;
  2801. case SEN_OV7670:
  2802. /* check that this isn't just the same as ov7610 */
  2803. i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
  2804. break;
  2805. }
  2806. }
  2807. static void setcolors(struct gspca_dev *gspca_dev)
  2808. {
  2809. struct sd *sd = (struct sd *) gspca_dev;
  2810. int val;
  2811. val = sd->colors;
  2812. switch (sd->sensor) {
  2813. case SEN_OV8610:
  2814. case SEN_OV7610:
  2815. case SEN_OV76BE:
  2816. case SEN_OV6620:
  2817. case SEN_OV6630:
  2818. case SEN_OV66308AF:
  2819. i2c_w(sd, OV7610_REG_SAT, val);
  2820. break;
  2821. case SEN_OV7620:
  2822. /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
  2823. /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
  2824. if (rc < 0)
  2825. goto out; */
  2826. i2c_w(sd, OV7610_REG_SAT, val);
  2827. break;
  2828. case SEN_OV7640:
  2829. i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
  2830. break;
  2831. case SEN_OV7670:
  2832. /* supported later once I work out how to do it
  2833. * transparently fail now! */
  2834. /* set REG_COM13 values for UV sat auto mode */
  2835. break;
  2836. }
  2837. }
  2838. static void setautobrightness(struct sd *sd)
  2839. {
  2840. if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
  2841. return;
  2842. i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10);
  2843. }
  2844. static void setfreq(struct sd *sd)
  2845. {
  2846. if (sd->sensor == SEN_OV7670) {
  2847. switch (sd->freq) {
  2848. case 0: /* Banding filter disabled */
  2849. i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT);
  2850. break;
  2851. case 1: /* 50 hz */
  2852. i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
  2853. OV7670_COM8_BFILT);
  2854. i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18);
  2855. break;
  2856. case 2: /* 60 hz */
  2857. i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
  2858. OV7670_COM8_BFILT);
  2859. i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18);
  2860. break;
  2861. case 3: /* Auto hz */
  2862. i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
  2863. OV7670_COM8_BFILT);
  2864. i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO,
  2865. 0x18);
  2866. break;
  2867. }
  2868. } else {
  2869. switch (sd->freq) {
  2870. case 0: /* Banding filter disabled */
  2871. i2c_w_mask(sd, 0x2d, 0x00, 0x04);
  2872. i2c_w_mask(sd, 0x2a, 0x00, 0x80);
  2873. break;
  2874. case 1: /* 50 hz (filter on and framerate adj) */
  2875. i2c_w_mask(sd, 0x2d, 0x04, 0x04);
  2876. i2c_w_mask(sd, 0x2a, 0x80, 0x80);
  2877. /* 20 fps -> 16.667 fps */
  2878. if (sd->sensor == SEN_OV6620 ||
  2879. sd->sensor == SEN_OV6630 ||
  2880. sd->sensor == SEN_OV66308AF)
  2881. i2c_w(sd, 0x2b, 0x5e);
  2882. else
  2883. i2c_w(sd, 0x2b, 0xac);
  2884. break;
  2885. case 2: /* 60 hz (filter on, ...) */
  2886. i2c_w_mask(sd, 0x2d, 0x04, 0x04);
  2887. if (sd->sensor == SEN_OV6620 ||
  2888. sd->sensor == SEN_OV6630 ||
  2889. sd->sensor == SEN_OV66308AF) {
  2890. /* 20 fps -> 15 fps */
  2891. i2c_w_mask(sd, 0x2a, 0x80, 0x80);
  2892. i2c_w(sd, 0x2b, 0xa8);
  2893. } else {
  2894. /* no framerate adj. */
  2895. i2c_w_mask(sd, 0x2a, 0x00, 0x80);
  2896. }
  2897. break;
  2898. }
  2899. }
  2900. }
  2901. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  2902. {
  2903. struct sd *sd = (struct sd *) gspca_dev;
  2904. sd->brightness = val;
  2905. if (gspca_dev->streaming)
  2906. setbrightness(gspca_dev);
  2907. return 0;
  2908. }
  2909. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  2910. {
  2911. struct sd *sd = (struct sd *) gspca_dev;
  2912. *val = sd->brightness;
  2913. return 0;
  2914. }
  2915. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  2916. {
  2917. struct sd *sd = (struct sd *) gspca_dev;
  2918. sd->contrast = val;
  2919. if (gspca_dev->streaming)
  2920. setcontrast(gspca_dev);
  2921. return 0;
  2922. }
  2923. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  2924. {
  2925. struct sd *sd = (struct sd *) gspca_dev;
  2926. *val = sd->contrast;
  2927. return 0;
  2928. }
  2929. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  2930. {
  2931. struct sd *sd = (struct sd *) gspca_dev;
  2932. sd->colors = val;
  2933. if (gspca_dev->streaming)
  2934. setcolors(gspca_dev);
  2935. return 0;
  2936. }
  2937. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  2938. {
  2939. struct sd *sd = (struct sd *) gspca_dev;
  2940. *val = sd->colors;
  2941. return 0;
  2942. }
  2943. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  2944. {
  2945. struct sd *sd = (struct sd *) gspca_dev;
  2946. sd->hflip = val;
  2947. if (gspca_dev->streaming)
  2948. sethvflip(sd);
  2949. return 0;
  2950. }
  2951. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  2952. {
  2953. struct sd *sd = (struct sd *) gspca_dev;
  2954. *val = sd->hflip;
  2955. return 0;
  2956. }
  2957. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  2958. {
  2959. struct sd *sd = (struct sd *) gspca_dev;
  2960. sd->vflip = val;
  2961. if (gspca_dev->streaming)
  2962. sethvflip(sd);
  2963. return 0;
  2964. }
  2965. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  2966. {
  2967. struct sd *sd = (struct sd *) gspca_dev;
  2968. *val = sd->vflip;
  2969. return 0;
  2970. }
  2971. static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val)
  2972. {
  2973. struct sd *sd = (struct sd *) gspca_dev;
  2974. sd->autobrightness = val;
  2975. if (gspca_dev->streaming)
  2976. setautobrightness(sd);
  2977. return 0;
  2978. }
  2979. static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val)
  2980. {
  2981. struct sd *sd = (struct sd *) gspca_dev;
  2982. *val = sd->autobrightness;
  2983. return 0;
  2984. }
  2985. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  2986. {
  2987. struct sd *sd = (struct sd *) gspca_dev;
  2988. sd->freq = val;
  2989. if (gspca_dev->streaming)
  2990. setfreq(sd);
  2991. return 0;
  2992. }
  2993. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  2994. {
  2995. struct sd *sd = (struct sd *) gspca_dev;
  2996. *val = sd->freq;
  2997. return 0;
  2998. }
  2999. static int sd_querymenu(struct gspca_dev *gspca_dev,
  3000. struct v4l2_querymenu *menu)
  3001. {
  3002. struct sd *sd = (struct sd *) gspca_dev;
  3003. switch (menu->id) {
  3004. case V4L2_CID_POWER_LINE_FREQUENCY:
  3005. switch (menu->index) {
  3006. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  3007. strcpy((char *) menu->name, "NoFliker");
  3008. return 0;
  3009. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  3010. strcpy((char *) menu->name, "50 Hz");
  3011. return 0;
  3012. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  3013. strcpy((char *) menu->name, "60 Hz");
  3014. return 0;
  3015. case 3:
  3016. if (sd->sensor != SEN_OV7670)
  3017. return -EINVAL;
  3018. strcpy((char *) menu->name, "Automatic");
  3019. return 0;
  3020. }
  3021. break;
  3022. }
  3023. return -EINVAL;
  3024. }
  3025. /* sub-driver description */
  3026. static const struct sd_desc sd_desc = {
  3027. .name = MODULE_NAME,
  3028. .ctrls = sd_ctrls,
  3029. .nctrls = ARRAY_SIZE(sd_ctrls),
  3030. .config = sd_config,
  3031. .init = sd_init,
  3032. .start = sd_start,
  3033. .stopN = sd_stopN,
  3034. .pkt_scan = sd_pkt_scan,
  3035. .querymenu = sd_querymenu,
  3036. };
  3037. /* -- module initialisation -- */
  3038. static const __devinitdata struct usb_device_id device_table[] = {
  3039. {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
  3040. {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
  3041. {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
  3042. {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
  3043. {USB_DEVICE(0x041e, 0x4064),
  3044. .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
  3045. {USB_DEVICE(0x041e, 0x4068),
  3046. .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
  3047. {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
  3048. {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
  3049. {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 },
  3050. {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
  3051. {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
  3052. {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
  3053. {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
  3054. {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
  3055. {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
  3056. {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
  3057. {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
  3058. {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
  3059. {}
  3060. };
  3061. MODULE_DEVICE_TABLE(usb, device_table);
  3062. /* -- device connect -- */
  3063. static int sd_probe(struct usb_interface *intf,
  3064. const struct usb_device_id *id)
  3065. {
  3066. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  3067. THIS_MODULE);
  3068. }
  3069. static struct usb_driver sd_driver = {
  3070. .name = MODULE_NAME,
  3071. .id_table = device_table,
  3072. .probe = sd_probe,
  3073. .disconnect = gspca_disconnect,
  3074. #ifdef CONFIG_PM
  3075. .suspend = gspca_suspend,
  3076. .resume = gspca_resume,
  3077. #endif
  3078. };
  3079. /* -- module insert / remove -- */
  3080. static int __init sd_mod_init(void)
  3081. {
  3082. int ret;
  3083. ret = usb_register(&sd_driver);
  3084. if (ret < 0)
  3085. return ret;
  3086. PDEBUG(D_PROBE, "registered");
  3087. return 0;
  3088. }
  3089. static void __exit sd_mod_exit(void)
  3090. {
  3091. usb_deregister(&sd_driver);
  3092. PDEBUG(D_PROBE, "deregistered");
  3093. }
  3094. module_init(sd_mod_init);
  3095. module_exit(sd_mod_exit);
  3096. module_param(frame_rate, int, 0644);
  3097. MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");