ov519.c 86 KB

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