sonixj.c 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985
  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  3. *
  4. * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #define MODULE_NAME "sonixj"
  19. #include <linux/input.h>
  20. #include "gspca.h"
  21. #include "jpeg.h"
  22. MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
  23. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  24. MODULE_LICENSE("GPL");
  25. /* specific webcam descriptor */
  26. struct sd {
  27. struct gspca_dev gspca_dev; /* !! must be the first item */
  28. atomic_t avg_lum;
  29. struct v4l2_ctrl *brightness;
  30. struct v4l2_ctrl *contrast;
  31. struct v4l2_ctrl *saturation;
  32. struct { /* red/blue balance control cluster */
  33. struct v4l2_ctrl *red_bal;
  34. struct v4l2_ctrl *blue_bal;
  35. };
  36. struct { /* hflip/vflip control cluster */
  37. struct v4l2_ctrl *vflip;
  38. struct v4l2_ctrl *hflip;
  39. };
  40. struct v4l2_ctrl *gamma;
  41. struct v4l2_ctrl *illum;
  42. struct v4l2_ctrl *sharpness;
  43. struct v4l2_ctrl *freq;
  44. u32 exposure;
  45. struct work_struct work;
  46. u32 pktsz; /* (used by pkt_scan) */
  47. u16 npkt;
  48. s8 nchg;
  49. s8 short_mark;
  50. u8 quality; /* image quality */
  51. #define QUALITY_MIN 25
  52. #define QUALITY_MAX 90
  53. #define QUALITY_DEF 70
  54. u8 reg01;
  55. u8 reg17;
  56. u8 reg18;
  57. u8 flags;
  58. s8 ag_cnt;
  59. #define AG_CNT_START 13
  60. u8 bridge;
  61. #define BRIDGE_SN9C102P 0
  62. #define BRIDGE_SN9C105 1
  63. #define BRIDGE_SN9C110 2
  64. #define BRIDGE_SN9C120 3
  65. u8 sensor; /* Type of image sensor chip */
  66. u8 i2c_addr;
  67. u8 jpeg_hdr[JPEG_HDR_SZ];
  68. };
  69. enum sensors {
  70. SENSOR_ADCM1700,
  71. SENSOR_GC0307,
  72. SENSOR_HV7131R,
  73. SENSOR_MI0360,
  74. SENSOR_MI0360B,
  75. SENSOR_MO4000,
  76. SENSOR_MT9V111,
  77. SENSOR_OM6802,
  78. SENSOR_OV7630,
  79. SENSOR_OV7648,
  80. SENSOR_OV7660,
  81. SENSOR_PO1030,
  82. SENSOR_PO2030N,
  83. SENSOR_SOI768,
  84. SENSOR_SP80708,
  85. };
  86. static void qual_upd(struct work_struct *work);
  87. /* device flags */
  88. #define F_PDN_INV 0x01 /* inverse pin S_PWR_DN / sn_xxx tables */
  89. #define F_ILLUM 0x02 /* presence of illuminator */
  90. /* sn9c1xx definitions */
  91. /* register 0x01 */
  92. #define S_PWR_DN 0x01 /* sensor power down */
  93. #define S_PDN_INV 0x02 /* inverse pin S_PWR_DN */
  94. #define V_TX_EN 0x04 /* video transfer enable */
  95. #define LED 0x08 /* output to pin LED */
  96. #define SCL_SEL_OD 0x20 /* open-drain mode */
  97. #define SYS_SEL_48M 0x40 /* system clock 0: 24MHz, 1: 48MHz */
  98. /* register 0x17 */
  99. #define MCK_SIZE_MASK 0x1f /* sensor master clock */
  100. #define SEN_CLK_EN 0x20 /* enable sensor clock */
  101. #define DEF_EN 0x80 /* defect pixel by 0: soft, 1: hard */
  102. static const struct v4l2_pix_format cif_mode[] = {
  103. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  104. .bytesperline = 352,
  105. .sizeimage = 352 * 288 * 4 / 8 + 590,
  106. .colorspace = V4L2_COLORSPACE_JPEG,
  107. .priv = 0},
  108. };
  109. static const struct v4l2_pix_format vga_mode[] = {
  110. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  111. .bytesperline = 160,
  112. .sizeimage = 160 * 120 * 4 / 8 + 590,
  113. .colorspace = V4L2_COLORSPACE_JPEG,
  114. .priv = 2},
  115. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  116. .bytesperline = 320,
  117. .sizeimage = 320 * 240 * 3 / 8 + 590,
  118. .colorspace = V4L2_COLORSPACE_JPEG,
  119. .priv = 1},
  120. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  121. .bytesperline = 640,
  122. /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
  123. .sizeimage = 640 * 480 * 3 / 4 + 590,
  124. .colorspace = V4L2_COLORSPACE_JPEG,
  125. .priv = 0},
  126. };
  127. static const u8 sn_adcm1700[0x1c] = {
  128. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  129. 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
  130. /* reg8 reg9 rega regb regc regd rege regf */
  131. 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  132. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  133. 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
  134. /* reg18 reg19 reg1a reg1b */
  135. 0x06, 0x00, 0x00, 0x00
  136. };
  137. static const u8 sn_gc0307[0x1c] = {
  138. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  139. 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00,
  140. /* reg8 reg9 rega regb regc regd rege regf */
  141. 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  142. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  143. 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02,
  144. /* reg18 reg19 reg1a reg1b */
  145. 0x06, 0x00, 0x00, 0x00
  146. };
  147. static const u8 sn_hv7131[0x1c] = {
  148. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  149. 0x00, 0x03, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  150. /* reg8 reg9 rega regb regc regd rege regf */
  151. 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  152. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  153. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  154. /* reg18 reg19 reg1a reg1b */
  155. 0x0a, 0x00, 0x00, 0x00
  156. };
  157. static const u8 sn_mi0360[0x1c] = {
  158. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  159. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  160. /* reg8 reg9 rega regb regc regd rege regf */
  161. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  162. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  163. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  164. /* reg18 reg19 reg1a reg1b */
  165. 0x06, 0x00, 0x00, 0x00
  166. };
  167. static const u8 sn_mi0360b[0x1c] = {
  168. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  169. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  170. /* reg8 reg9 rega regb regc regd rege regf */
  171. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  172. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  173. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x40,
  174. /* reg18 reg19 reg1a reg1b */
  175. 0x06, 0x00, 0x00, 0x00
  176. };
  177. static const u8 sn_mo4000[0x1c] = {
  178. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  179. 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  180. /* reg8 reg9 rega regb regc regd rege regf */
  181. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  182. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  183. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  184. /* reg18 reg19 reg1a reg1b */
  185. 0x08, 0x00, 0x00, 0x00
  186. };
  187. static const u8 sn_mt9v111[0x1c] = {
  188. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  189. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  190. /* reg8 reg9 rega regb regc regd rege regf */
  191. 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  192. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  193. 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
  194. /* reg18 reg19 reg1a reg1b */
  195. 0x06, 0x00, 0x00, 0x00
  196. };
  197. static const u8 sn_om6802[0x1c] = {
  198. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  199. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
  200. /* reg8 reg9 rega regb regc regd rege regf */
  201. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  202. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  203. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  204. /* reg18 reg19 reg1a reg1b */
  205. 0x05, 0x00, 0x00, 0x00
  206. };
  207. static const u8 sn_ov7630[0x1c] = {
  208. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  209. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  210. /* reg8 reg9 rega regb regc regd rege regf */
  211. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  212. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  213. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  214. /* reg18 reg19 reg1a reg1b */
  215. 0x0b, 0x00, 0x00, 0x00
  216. };
  217. static const u8 sn_ov7648[0x1c] = {
  218. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  219. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  220. /* reg8 reg9 rega regb regc regd rege regf */
  221. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  222. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  223. 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
  224. /* reg18 reg19 reg1a reg1b */
  225. 0x0b, 0x00, 0x00, 0x00
  226. };
  227. static const u8 sn_ov7660[0x1c] = {
  228. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  229. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  230. /* reg8 reg9 rega regb regc regd rege regf */
  231. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  232. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  233. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  234. /* reg18 reg19 reg1a reg1b */
  235. 0x07, 0x00, 0x00, 0x00
  236. };
  237. static const u8 sn_po1030[0x1c] = {
  238. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  239. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  240. /* reg8 reg9 rega regb regc regd rege regf */
  241. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  242. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  243. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
  244. /* reg18 reg19 reg1a reg1b */
  245. 0x07, 0x00, 0x00, 0x00
  246. };
  247. static const u8 sn_po2030n[0x1c] = {
  248. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  249. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  250. /* reg8 reg9 rega regb regc regd rege regf */
  251. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  252. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  253. 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00,
  254. /* reg18 reg19 reg1a reg1b */
  255. 0x07, 0x00, 0x00, 0x00
  256. };
  257. static const u8 sn_soi768[0x1c] = {
  258. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  259. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  260. /* reg8 reg9 rega regb regc regd rege regf */
  261. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  262. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  263. 0x03, 0x00, 0x00, 0x01, 0x08, 0x28, 0x1e, 0x00,
  264. /* reg18 reg19 reg1a reg1b */
  265. 0x07, 0x00, 0x00, 0x00
  266. };
  267. static const u8 sn_sp80708[0x1c] = {
  268. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  269. 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  270. /* reg8 reg9 rega regb regc regd rege regf */
  271. 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  272. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  273. 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
  274. /* reg18 reg19 reg1a reg1b */
  275. 0x07, 0x00, 0x00, 0x00
  276. };
  277. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  278. static const u8 *sn_tb[] = {
  279. [SENSOR_ADCM1700] = sn_adcm1700,
  280. [SENSOR_GC0307] = sn_gc0307,
  281. [SENSOR_HV7131R] = sn_hv7131,
  282. [SENSOR_MI0360] = sn_mi0360,
  283. [SENSOR_MI0360B] = sn_mi0360b,
  284. [SENSOR_MO4000] = sn_mo4000,
  285. [SENSOR_MT9V111] = sn_mt9v111,
  286. [SENSOR_OM6802] = sn_om6802,
  287. [SENSOR_OV7630] = sn_ov7630,
  288. [SENSOR_OV7648] = sn_ov7648,
  289. [SENSOR_OV7660] = sn_ov7660,
  290. [SENSOR_PO1030] = sn_po1030,
  291. [SENSOR_PO2030N] = sn_po2030n,
  292. [SENSOR_SOI768] = sn_soi768,
  293. [SENSOR_SP80708] = sn_sp80708,
  294. };
  295. /* default gamma table */
  296. static const u8 gamma_def[17] = {
  297. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  298. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  299. };
  300. /* gamma for sensor ADCM1700 */
  301. static const u8 gamma_spec_0[17] = {
  302. 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
  303. 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
  304. };
  305. /* gamma for sensors HV7131R and MT9V111 */
  306. static const u8 gamma_spec_1[17] = {
  307. 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
  308. 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
  309. };
  310. /* gamma for sensor GC0307 */
  311. static const u8 gamma_spec_2[17] = {
  312. 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
  313. 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
  314. };
  315. /* gamma for sensor SP80708 */
  316. static const u8 gamma_spec_3[17] = {
  317. 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
  318. 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
  319. };
  320. /* color matrix and offsets */
  321. static const u8 reg84[] = {
  322. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
  323. 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
  324. 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
  325. 0x00, 0x00, 0x00 /* YUV offsets */
  326. };
  327. #define DELAY 0xdd
  328. static const u8 adcm1700_sensor_init[][8] = {
  329. {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
  330. {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
  331. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  332. {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  333. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  334. {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
  335. {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
  336. {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
  337. {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
  338. {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
  339. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  340. {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
  341. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  342. {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
  343. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  344. {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
  345. {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  346. {}
  347. };
  348. static const u8 adcm1700_sensor_param1[][8] = {
  349. {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
  350. {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
  351. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  352. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  353. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  354. {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
  355. {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
  356. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  357. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  358. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  359. {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
  360. {}
  361. };
  362. static const u8 gc0307_sensor_init[][8] = {
  363. {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
  364. {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
  365. {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
  366. {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
  367. {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  368. {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  369. {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  370. {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
  371. {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  372. {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  373. {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
  374. {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
  375. {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
  376. {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
  377. {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
  378. {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
  379. {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
  380. {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
  381. {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
  382. {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
  383. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
  384. {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
  385. {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
  386. {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
  387. {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
  388. {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
  389. {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
  390. {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
  391. {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
  392. {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
  393. {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
  394. {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
  395. {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  396. {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
  397. {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
  398. {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
  399. {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
  400. {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
  401. {}
  402. };
  403. static const u8 gc0307_sensor_param1[][8] = {
  404. {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
  405. {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
  406. {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
  407. {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
  408. /*param3*/
  409. {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
  410. {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
  411. {}
  412. };
  413. static const u8 hv7131r_sensor_init[][8] = {
  414. {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  415. {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
  416. {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
  417. /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  418. {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  419. {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
  420. /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  421. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  422. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  423. {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
  424. {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  425. {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
  426. {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
  427. {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  428. {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  429. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  430. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  431. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  432. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  433. {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  434. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  435. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  436. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  437. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  438. {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  439. {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
  440. /* set sensor clock */
  441. {}
  442. };
  443. static const u8 mi0360_sensor_init[][8] = {
  444. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  445. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  446. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  447. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  448. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  449. {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  450. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  451. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  452. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  453. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  454. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  455. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  456. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  457. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  458. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  459. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  460. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  461. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  462. {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  463. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  464. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  465. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  466. {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
  467. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  468. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  469. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  470. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  471. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  472. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  473. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  474. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  475. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  476. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  477. {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  478. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  479. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  480. {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
  481. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
  482. {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  483. {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  484. {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
  485. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  486. {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
  487. {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
  488. /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  489. /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  490. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  491. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  492. {}
  493. };
  494. static const u8 mi0360b_sensor_init[][8] = {
  495. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  496. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  497. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  498. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  499. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  500. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  501. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  502. {0xd1, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  503. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  504. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  505. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  506. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  507. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  508. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  509. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  510. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  511. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  512. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  513. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  514. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  515. {0xd1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  516. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  517. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  518. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  519. {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
  520. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  521. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  522. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  523. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  524. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  525. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  526. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  527. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  528. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  529. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  530. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  531. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  532. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  533. {0xd1, 0x5d, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10},
  534. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10},
  535. {}
  536. };
  537. static const u8 mi0360b_sensor_param1[][8] = {
  538. {0xb1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  539. {0xb1, 0x5d, 0x06, 0x00, 0x53, 0x00, 0x00, 0x10},
  540. {0xb1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10},
  541. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  542. {0xd1, 0x5d, 0x2b, 0x00, 0xd1, 0x01, 0xc9, 0x10},
  543. {0xd1, 0x5d, 0x2d, 0x00, 0xed, 0x00, 0xd1, 0x10},
  544. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  545. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  546. {}
  547. };
  548. static const u8 mo4000_sensor_init[][8] = {
  549. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  550. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  551. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  552. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  553. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  554. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  555. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  556. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  557. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  558. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  559. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  560. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  561. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  562. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  563. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  564. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  565. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  566. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  567. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  568. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  569. {}
  570. };
  571. static const u8 mt9v111_sensor_init[][8] = {
  572. {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
  573. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  574. {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  575. {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
  576. {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
  577. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
  578. {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
  579. {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
  580. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
  581. {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
  582. {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
  583. {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
  584. {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
  585. {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
  586. {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
  587. {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
  588. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
  589. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  590. {}
  591. };
  592. static const u8 mt9v111_sensor_param1[][8] = {
  593. {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xad, 0x10}, /* G1 and B gains */
  594. {0xd1, 0x5c, 0x2d, 0x00, 0xad, 0x00, 0x33, 0x10}, /* R and G2 gains */
  595. {0xb1, 0x5c, 0x06, 0x00, 0x40, 0x00, 0x00, 0x10}, /* vert blanking */
  596. {0xb1, 0x5c, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10}, /* horiz blanking */
  597. {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
  598. {}
  599. };
  600. static const u8 om6802_init0[2][8] = {
  601. /*fixme: variable*/
  602. {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
  603. {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
  604. };
  605. static const u8 om6802_sensor_init[][8] = {
  606. {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
  607. /* factory mode */
  608. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  609. /* output raw RGB */
  610. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  611. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  612. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  613. /* auto-exposure speed (0) / white balance mode (auto RGB) */
  614. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  615. * set color mode */
  616. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  617. * max AGC value in AE */
  618. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  619. * preset AGC */
  620. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  621. * preset brightness */
  622. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  623. * preset contrast */
  624. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  625. * preset gamma */
  626. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  627. /* luminance mode (0x4f -> AutoExpo on) */
  628. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  629. /* preset shutter */
  630. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  631. * auto frame rate */
  632. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  633. {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  634. {}
  635. };
  636. static const u8 om6802_sensor_param1[][8] = {
  637. {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
  638. {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
  639. {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
  640. {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
  641. {}
  642. };
  643. static const u8 ov7630_sensor_init[][8] = {
  644. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  645. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  646. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  647. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  648. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  649. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  650. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  651. /* win: i2c_r from 00 to 80 */
  652. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  653. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  654. /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
  655. 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
  656. {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
  657. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  658. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  659. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  660. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  661. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  662. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  663. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  664. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  665. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  666. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  667. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  668. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  669. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  670. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  671. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  672. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  673. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  674. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  675. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  676. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  677. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  678. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  679. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  680. {}
  681. };
  682. static const u8 ov7630_sensor_param1[][8] = {
  683. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  684. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  685. /*fixme: + 0x12, 0x04*/
  686. /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
  687. * set by setvflip */
  688. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  689. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  690. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  691. /* */
  692. /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  693. /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  694. /* */
  695. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  696. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  697. {}
  698. };
  699. static const u8 ov7648_sensor_init[][8] = {
  700. {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
  701. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  702. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  703. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  704. {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
  705. {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
  706. {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
  707. {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
  708. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  709. {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
  710. {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
  711. {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
  712. {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
  713. {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
  714. {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
  715. {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
  716. {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
  717. {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
  718. {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
  719. {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
  720. {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
  721. {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
  722. {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
  723. /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
  724. /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
  725. /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
  726. {}
  727. };
  728. static const u8 ov7648_sensor_param1[][8] = {
  729. /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
  730. /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
  731. * set by setvflip */
  732. {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
  733. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  734. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  735. /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
  736. /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
  737. /*...*/
  738. {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
  739. /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  740. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  741. /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
  742. /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  743. /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
  744. {}
  745. };
  746. static const u8 ov7660_sensor_init[][8] = {
  747. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  748. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  749. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  750. /* Outformat = rawRGB */
  751. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  752. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
  753. /* GAIN BLUE RED VREF */
  754. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  755. /* COM 1 BAVE GEAVE AECHH */
  756. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  757. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  758. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  759. /* AECH CLKRC COM7 COM8 */
  760. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  761. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  762. /* HSTART HSTOP VSTRT VSTOP */
  763. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  764. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  765. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  766. /* BOS GBOS GROS ROS (BGGR offset) */
  767. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  768. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  769. /* AEW AEB VPT BBIAS */
  770. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  771. /* GbBIAS RSVD EXHCH EXHCL */
  772. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  773. /* RBIAS ADVFL ASDVFH YAVE */
  774. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  775. /* HSYST HSYEN HREF */
  776. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  777. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  778. /* ADC ACOM OFON TSLB */
  779. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  780. /* COM11 COM12 COM13 COM14 */
  781. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  782. /* EDGE COM15 COM16 COM17 */
  783. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  784. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  785. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  786. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  787. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  788. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  789. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  790. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  791. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  792. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  793. /* LCC1 LCC2 LCC3 LCC4 */
  794. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  795. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  796. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  797. /* band gap reference [0:3] DBLV */
  798. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  799. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  800. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  801. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  802. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  803. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  804. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  805. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  806. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  807. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  808. /* not in all ms-win traces*/
  809. {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
  810. {}
  811. };
  812. static const u8 ov7660_sensor_param1[][8] = {
  813. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  814. /* bits[3..0]reserved */
  815. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  816. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  817. /* VREF vertical frame ctrl */
  818. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  819. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  820. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  821. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  822. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  823. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  824. /****** (some exchanges in the win trace) ******/
  825. /*fixme:param2*/
  826. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  827. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  828. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  829. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  830. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  831. /****** (some exchanges in the win trace) ******/
  832. /******!! startsensor KO if changed !!****/
  833. /*fixme: param3*/
  834. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  835. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  836. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  837. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  838. {}
  839. };
  840. static const u8 po1030_sensor_init[][8] = {
  841. /* the sensor registers are described in m5602/m5602_po1030.h */
  842. {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
  843. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  844. {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
  845. {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
  846. {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
  847. {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  848. {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
  849. {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  850. {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
  851. {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
  852. {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
  853. {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
  854. {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  855. {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  856. {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
  857. {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
  858. {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
  859. {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
  860. {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
  861. {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
  862. {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  863. {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  864. {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
  865. {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
  866. {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
  867. {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
  868. {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
  869. {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
  870. {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  871. {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  872. {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
  873. {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
  874. {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
  875. {}
  876. };
  877. static const u8 po1030_sensor_param1[][8] = {
  878. /* from ms-win traces - these values change with auto gain/expo/wb.. */
  879. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  880. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  881. /* mean values */
  882. {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
  883. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
  884. {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
  885. {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
  886. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
  887. {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
  888. /* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
  889. {}
  890. };
  891. static const u8 po2030n_sensor_init[][8] = {
  892. {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
  893. {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
  894. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  895. {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
  896. {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
  897. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  898. {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
  899. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  900. {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
  901. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  902. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  903. {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
  904. {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
  905. {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
  906. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  907. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
  908. {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
  909. {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  910. {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  911. {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
  912. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
  913. {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
  914. {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
  915. {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
  916. {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
  917. {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
  918. {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
  919. {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
  920. {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
  921. {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
  922. {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
  923. {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
  924. {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
  925. {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
  926. {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
  927. {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
  928. {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
  929. {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
  930. {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
  931. {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
  932. {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
  933. {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
  934. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  935. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
  936. {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
  937. {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
  938. {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
  939. {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
  940. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
  941. {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
  942. {}
  943. };
  944. static const u8 po2030n_sensor_param1[][8] = {
  945. {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
  946. {DELAY, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
  947. {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
  948. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  949. {0xd1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x40, 0x10}, /* RGBG gains */
  950. /*param2*/
  951. {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  952. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  953. {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
  954. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  955. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  956. {}
  957. };
  958. static const u8 soi768_sensor_init[][8] = {
  959. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  960. {DELAY, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
  961. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  962. {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
  963. {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
  964. {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
  965. {}
  966. };
  967. static const u8 soi768_sensor_param1[][8] = {
  968. {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
  969. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  970. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  971. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  972. {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
  973. /* */
  974. /* {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  975. /* {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
  976. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  977. /* {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  978. {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
  979. /* the next sequence should be used for auto gain */
  980. {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
  981. /* global gain ? : 07 - change with 0x15 at the end */
  982. {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
  983. {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
  984. {0xb1, 0x21, 0x2d, 0x63, 0x03, 0x00, 0x00, 0x10},
  985. /* exposure ? : 0200 - change with 0x1e at the end */
  986. {}
  987. };
  988. static const u8 sp80708_sensor_init[][8] = {
  989. {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
  990. {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
  991. {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  992. {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
  993. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  994. {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
  995. {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
  996. {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
  997. {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
  998. {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
  999. {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
  1000. {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
  1001. {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
  1002. {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
  1003. {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
  1004. {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
  1005. {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
  1006. {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
  1007. {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
  1008. {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
  1009. {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
  1010. {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
  1011. {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
  1012. {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
  1013. {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
  1014. {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1015. {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
  1016. {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
  1017. {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
  1018. {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
  1019. {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
  1020. {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
  1021. {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
  1022. {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
  1023. {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
  1024. {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
  1025. {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
  1026. {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
  1027. {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
  1028. {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
  1029. {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
  1030. {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
  1031. {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
  1032. {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1033. {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
  1034. {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
  1035. {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
  1036. {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
  1037. {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
  1038. {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
  1039. {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
  1040. {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
  1041. {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
  1042. {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
  1043. {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
  1044. {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1045. {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
  1046. {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  1047. {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
  1048. {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
  1049. {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
  1050. {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1051. {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
  1052. {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
  1053. {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
  1054. {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
  1055. {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
  1056. {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
  1057. {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
  1058. {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
  1059. {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
  1060. {}
  1061. };
  1062. static const u8 sp80708_sensor_param1[][8] = {
  1063. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1064. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1065. {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
  1066. {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
  1067. {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
  1068. {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  1069. {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
  1070. {}
  1071. };
  1072. static const u8 (*sensor_init[])[8] = {
  1073. [SENSOR_ADCM1700] = adcm1700_sensor_init,
  1074. [SENSOR_GC0307] = gc0307_sensor_init,
  1075. [SENSOR_HV7131R] = hv7131r_sensor_init,
  1076. [SENSOR_MI0360] = mi0360_sensor_init,
  1077. [SENSOR_MI0360B] = mi0360b_sensor_init,
  1078. [SENSOR_MO4000] = mo4000_sensor_init,
  1079. [SENSOR_MT9V111] = mt9v111_sensor_init,
  1080. [SENSOR_OM6802] = om6802_sensor_init,
  1081. [SENSOR_OV7630] = ov7630_sensor_init,
  1082. [SENSOR_OV7648] = ov7648_sensor_init,
  1083. [SENSOR_OV7660] = ov7660_sensor_init,
  1084. [SENSOR_PO1030] = po1030_sensor_init,
  1085. [SENSOR_PO2030N] = po2030n_sensor_init,
  1086. [SENSOR_SOI768] = soi768_sensor_init,
  1087. [SENSOR_SP80708] = sp80708_sensor_init,
  1088. };
  1089. /* read <len> bytes to gspca_dev->usb_buf */
  1090. static void reg_r(struct gspca_dev *gspca_dev,
  1091. u16 value, int len)
  1092. {
  1093. int ret;
  1094. if (gspca_dev->usb_err < 0)
  1095. return;
  1096. if (len > USB_BUF_SZ) {
  1097. gspca_err(gspca_dev, "reg_r: buffer overflow\n");
  1098. return;
  1099. }
  1100. ret = usb_control_msg(gspca_dev->dev,
  1101. usb_rcvctrlpipe(gspca_dev->dev, 0),
  1102. 0,
  1103. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1104. value, 0,
  1105. gspca_dev->usb_buf, len,
  1106. 500);
  1107. gspca_dbg(gspca_dev, D_USBI, "reg_r [%02x] -> %02x\n",
  1108. value, gspca_dev->usb_buf[0]);
  1109. if (ret < 0) {
  1110. pr_err("reg_r err %d\n", ret);
  1111. gspca_dev->usb_err = ret;
  1112. }
  1113. }
  1114. static void reg_w1(struct gspca_dev *gspca_dev,
  1115. u16 value,
  1116. u8 data)
  1117. {
  1118. int ret;
  1119. if (gspca_dev->usb_err < 0)
  1120. return;
  1121. gspca_dbg(gspca_dev, D_USBO, "reg_w1 [%04x] = %02x\n", value, data);
  1122. gspca_dev->usb_buf[0] = data;
  1123. ret = usb_control_msg(gspca_dev->dev,
  1124. usb_sndctrlpipe(gspca_dev->dev, 0),
  1125. 0x08,
  1126. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1127. value,
  1128. 0,
  1129. gspca_dev->usb_buf, 1,
  1130. 500);
  1131. if (ret < 0) {
  1132. pr_err("reg_w1 err %d\n", ret);
  1133. gspca_dev->usb_err = ret;
  1134. }
  1135. }
  1136. static void reg_w(struct gspca_dev *gspca_dev,
  1137. u16 value,
  1138. const u8 *buffer,
  1139. int len)
  1140. {
  1141. int ret;
  1142. if (gspca_dev->usb_err < 0)
  1143. return;
  1144. gspca_dbg(gspca_dev, D_USBO, "reg_w [%04x] = %02x %02x ..\n",
  1145. value, buffer[0], buffer[1]);
  1146. if (len > USB_BUF_SZ) {
  1147. gspca_err(gspca_dev, "reg_w: buffer overflow\n");
  1148. return;
  1149. }
  1150. memcpy(gspca_dev->usb_buf, buffer, len);
  1151. ret = usb_control_msg(gspca_dev->dev,
  1152. usb_sndctrlpipe(gspca_dev->dev, 0),
  1153. 0x08,
  1154. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1155. value, 0,
  1156. gspca_dev->usb_buf, len,
  1157. 500);
  1158. if (ret < 0) {
  1159. pr_err("reg_w err %d\n", ret);
  1160. gspca_dev->usb_err = ret;
  1161. }
  1162. }
  1163. /* I2C write 1 byte */
  1164. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1165. {
  1166. struct sd *sd = (struct sd *) gspca_dev;
  1167. int ret;
  1168. if (gspca_dev->usb_err < 0)
  1169. return;
  1170. gspca_dbg(gspca_dev, D_USBO, "i2c_w1 [%02x] = %02x\n", reg, val);
  1171. switch (sd->sensor) {
  1172. case SENSOR_ADCM1700:
  1173. case SENSOR_OM6802:
  1174. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1175. gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
  1176. break;
  1177. default: /* i2c command = a1 (400 kHz) */
  1178. gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
  1179. break;
  1180. }
  1181. gspca_dev->usb_buf[1] = sd->i2c_addr;
  1182. gspca_dev->usb_buf[2] = reg;
  1183. gspca_dev->usb_buf[3] = val;
  1184. gspca_dev->usb_buf[4] = 0;
  1185. gspca_dev->usb_buf[5] = 0;
  1186. gspca_dev->usb_buf[6] = 0;
  1187. gspca_dev->usb_buf[7] = 0x10;
  1188. ret = usb_control_msg(gspca_dev->dev,
  1189. usb_sndctrlpipe(gspca_dev->dev, 0),
  1190. 0x08,
  1191. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1192. 0x08, /* value = i2c */
  1193. 0,
  1194. gspca_dev->usb_buf, 8,
  1195. 500);
  1196. msleep(2);
  1197. if (ret < 0) {
  1198. pr_err("i2c_w1 err %d\n", ret);
  1199. gspca_dev->usb_err = ret;
  1200. }
  1201. }
  1202. /* I2C write 8 bytes */
  1203. static void i2c_w8(struct gspca_dev *gspca_dev,
  1204. const u8 *buffer)
  1205. {
  1206. int ret;
  1207. if (gspca_dev->usb_err < 0)
  1208. return;
  1209. gspca_dbg(gspca_dev, D_USBO, "i2c_w8 [%02x] = %02x ..\n",
  1210. buffer[2], buffer[3]);
  1211. memcpy(gspca_dev->usb_buf, buffer, 8);
  1212. ret = usb_control_msg(gspca_dev->dev,
  1213. usb_sndctrlpipe(gspca_dev->dev, 0),
  1214. 0x08,
  1215. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1216. 0x08, 0, /* value, index */
  1217. gspca_dev->usb_buf, 8,
  1218. 500);
  1219. msleep(2);
  1220. if (ret < 0) {
  1221. pr_err("i2c_w8 err %d\n", ret);
  1222. gspca_dev->usb_err = ret;
  1223. }
  1224. }
  1225. /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
  1226. static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
  1227. {
  1228. struct sd *sd = (struct sd *) gspca_dev;
  1229. u8 mode[8];
  1230. switch (sd->sensor) {
  1231. case SENSOR_ADCM1700:
  1232. case SENSOR_OM6802:
  1233. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1234. mode[0] = 0x80 | 0x10;
  1235. break;
  1236. default: /* i2c command = 91 (400 kHz) */
  1237. mode[0] = 0x81 | 0x10;
  1238. break;
  1239. }
  1240. mode[1] = sd->i2c_addr;
  1241. mode[2] = reg;
  1242. mode[3] = 0;
  1243. mode[4] = 0;
  1244. mode[5] = 0;
  1245. mode[6] = 0;
  1246. mode[7] = 0x10;
  1247. i2c_w8(gspca_dev, mode);
  1248. msleep(2);
  1249. mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
  1250. mode[2] = 0;
  1251. i2c_w8(gspca_dev, mode);
  1252. msleep(2);
  1253. reg_r(gspca_dev, 0x0a, 5);
  1254. }
  1255. static void i2c_w_seq(struct gspca_dev *gspca_dev,
  1256. const u8 (*data)[8])
  1257. {
  1258. while ((*data)[0] != 0) {
  1259. if ((*data)[0] != DELAY)
  1260. i2c_w8(gspca_dev, *data);
  1261. else
  1262. msleep((*data)[1]);
  1263. data++;
  1264. }
  1265. }
  1266. /* check the ID of the hv7131 sensor */
  1267. /* this sequence is needed because it activates the sensor */
  1268. static void hv7131r_probe(struct gspca_dev *gspca_dev)
  1269. {
  1270. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  1271. msleep(10);
  1272. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  1273. msleep(10);
  1274. i2c_r(gspca_dev, 0, 5); /* read sensor id */
  1275. if (gspca_dev->usb_buf[0] == 0x02 /* chip ID (02 is R) */
  1276. && gspca_dev->usb_buf[1] == 0x09
  1277. && gspca_dev->usb_buf[2] == 0x01) {
  1278. gspca_dbg(gspca_dev, D_PROBE, "Sensor HV7131R found\n");
  1279. return;
  1280. }
  1281. pr_warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x\n",
  1282. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  1283. gspca_dev->usb_buf[2]);
  1284. }
  1285. static void mi0360_probe(struct gspca_dev *gspca_dev)
  1286. {
  1287. struct sd *sd = (struct sd *) gspca_dev;
  1288. int i, j;
  1289. u16 val = 0;
  1290. static const u8 probe_tb[][4][8] = {
  1291. { /* mi0360 */
  1292. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  1293. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1294. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1295. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1296. },
  1297. { /* mt9v111 */
  1298. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1299. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1300. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1301. {}
  1302. },
  1303. };
  1304. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1305. reg_w1(gspca_dev, 0x17, 0x62);
  1306. reg_w1(gspca_dev, 0x01, 0x08);
  1307. for (j = 0; j < 3; j++)
  1308. i2c_w8(gspca_dev, probe_tb[i][j]);
  1309. msleep(2);
  1310. reg_r(gspca_dev, 0x0a, 5);
  1311. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1312. if (probe_tb[i][3][0] != 0)
  1313. i2c_w8(gspca_dev, probe_tb[i][3]);
  1314. reg_w1(gspca_dev, 0x01, 0x29);
  1315. reg_w1(gspca_dev, 0x17, 0x42);
  1316. if (val != 0xffff)
  1317. break;
  1318. }
  1319. if (gspca_dev->usb_err < 0)
  1320. return;
  1321. switch (val) {
  1322. case 0x8221:
  1323. gspca_dbg(gspca_dev, D_PROBE, "Sensor mi0360b\n");
  1324. sd->sensor = SENSOR_MI0360B;
  1325. break;
  1326. case 0x823a:
  1327. gspca_dbg(gspca_dev, D_PROBE, "Sensor mt9v111\n");
  1328. sd->sensor = SENSOR_MT9V111;
  1329. break;
  1330. case 0x8243:
  1331. gspca_dbg(gspca_dev, D_PROBE, "Sensor mi0360\n");
  1332. break;
  1333. default:
  1334. gspca_dbg(gspca_dev, D_PROBE, "Unknown sensor %04x - forced to mi0360\n",
  1335. val);
  1336. break;
  1337. }
  1338. }
  1339. static void ov7630_probe(struct gspca_dev *gspca_dev)
  1340. {
  1341. struct sd *sd = (struct sd *) gspca_dev;
  1342. u16 val;
  1343. /* check ov76xx */
  1344. reg_w1(gspca_dev, 0x17, 0x62);
  1345. reg_w1(gspca_dev, 0x01, 0x08);
  1346. sd->i2c_addr = 0x21;
  1347. i2c_r(gspca_dev, 0x0a, 2);
  1348. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1349. reg_w1(gspca_dev, 0x01, 0x29);
  1350. reg_w1(gspca_dev, 0x17, 0x42);
  1351. if (gspca_dev->usb_err < 0)
  1352. return;
  1353. if (val == 0x7628) { /* soi768 */
  1354. sd->sensor = SENSOR_SOI768;
  1355. /*fixme: only valid for 0c45:613e?*/
  1356. gspca_dev->cam.input_flags =
  1357. V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  1358. gspca_dbg(gspca_dev, D_PROBE, "Sensor soi768\n");
  1359. return;
  1360. }
  1361. gspca_dbg(gspca_dev, D_PROBE, "Sensor ov%04x\n", val);
  1362. }
  1363. static void ov7648_probe(struct gspca_dev *gspca_dev)
  1364. {
  1365. struct sd *sd = (struct sd *) gspca_dev;
  1366. u16 val;
  1367. /* check ov76xx */
  1368. reg_w1(gspca_dev, 0x17, 0x62);
  1369. reg_w1(gspca_dev, 0x01, 0x08);
  1370. sd->i2c_addr = 0x21;
  1371. i2c_r(gspca_dev, 0x0a, 2);
  1372. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1373. reg_w1(gspca_dev, 0x01, 0x29);
  1374. reg_w1(gspca_dev, 0x17, 0x42);
  1375. if ((val & 0xff00) == 0x7600) { /* ov76xx */
  1376. gspca_dbg(gspca_dev, D_PROBE, "Sensor ov%04x\n", val);
  1377. return;
  1378. }
  1379. /* check po1030 */
  1380. reg_w1(gspca_dev, 0x17, 0x62);
  1381. reg_w1(gspca_dev, 0x01, 0x08);
  1382. sd->i2c_addr = 0x6e;
  1383. i2c_r(gspca_dev, 0x00, 2);
  1384. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1385. reg_w1(gspca_dev, 0x01, 0x29);
  1386. reg_w1(gspca_dev, 0x17, 0x42);
  1387. if (gspca_dev->usb_err < 0)
  1388. return;
  1389. if (val == 0x1030) { /* po1030 */
  1390. gspca_dbg(gspca_dev, D_PROBE, "Sensor po1030\n");
  1391. sd->sensor = SENSOR_PO1030;
  1392. return;
  1393. }
  1394. pr_err("Unknown sensor %04x\n", val);
  1395. }
  1396. /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
  1397. static void po2030n_probe(struct gspca_dev *gspca_dev)
  1398. {
  1399. struct sd *sd = (struct sd *) gspca_dev;
  1400. u16 val;
  1401. /* check gc0307 */
  1402. reg_w1(gspca_dev, 0x17, 0x62);
  1403. reg_w1(gspca_dev, 0x01, 0x08);
  1404. reg_w1(gspca_dev, 0x02, 0x22);
  1405. sd->i2c_addr = 0x21;
  1406. i2c_r(gspca_dev, 0x00, 1);
  1407. val = gspca_dev->usb_buf[4];
  1408. reg_w1(gspca_dev, 0x01, 0x29); /* reset */
  1409. reg_w1(gspca_dev, 0x17, 0x42);
  1410. if (val == 0x99) { /* gc0307 (?) */
  1411. gspca_dbg(gspca_dev, D_PROBE, "Sensor gc0307\n");
  1412. sd->sensor = SENSOR_GC0307;
  1413. return;
  1414. }
  1415. /* check po2030n */
  1416. reg_w1(gspca_dev, 0x17, 0x62);
  1417. reg_w1(gspca_dev, 0x01, 0x0a);
  1418. sd->i2c_addr = 0x6e;
  1419. i2c_r(gspca_dev, 0x00, 2);
  1420. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1421. reg_w1(gspca_dev, 0x01, 0x29);
  1422. reg_w1(gspca_dev, 0x17, 0x42);
  1423. if (gspca_dev->usb_err < 0)
  1424. return;
  1425. if (val == 0x2030) {
  1426. gspca_dbg(gspca_dev, D_PROBE, "Sensor po2030n\n");
  1427. /* sd->sensor = SENSOR_PO2030N; */
  1428. } else {
  1429. pr_err("Unknown sensor ID %04x\n", val);
  1430. }
  1431. }
  1432. /* this function is called at probe time */
  1433. static int sd_config(struct gspca_dev *gspca_dev,
  1434. const struct usb_device_id *id)
  1435. {
  1436. struct sd *sd = (struct sd *) gspca_dev;
  1437. struct cam *cam;
  1438. sd->bridge = id->driver_info >> 16;
  1439. sd->sensor = id->driver_info >> 8;
  1440. sd->flags = id->driver_info;
  1441. cam = &gspca_dev->cam;
  1442. if (sd->sensor == SENSOR_ADCM1700) {
  1443. cam->cam_mode = cif_mode;
  1444. cam->nmodes = ARRAY_SIZE(cif_mode);
  1445. } else {
  1446. cam->cam_mode = vga_mode;
  1447. cam->nmodes = ARRAY_SIZE(vga_mode);
  1448. }
  1449. cam->npkt = 24; /* 24 packets per ISOC message */
  1450. sd->ag_cnt = -1;
  1451. sd->quality = QUALITY_DEF;
  1452. INIT_WORK(&sd->work, qual_upd);
  1453. return 0;
  1454. }
  1455. /* this function is called at probe and resume time */
  1456. static int sd_init(struct gspca_dev *gspca_dev)
  1457. {
  1458. struct sd *sd = (struct sd *) gspca_dev;
  1459. const u8 *sn9c1xx;
  1460. u8 regGpio[] = { 0x29, 0x70 }; /* no audio */
  1461. u8 regF1;
  1462. /* setup a selector by bridge */
  1463. reg_w1(gspca_dev, 0xf1, 0x01);
  1464. reg_r(gspca_dev, 0x00, 1);
  1465. reg_w1(gspca_dev, 0xf1, 0x00);
  1466. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1467. regF1 = gspca_dev->usb_buf[0];
  1468. if (gspca_dev->usb_err < 0)
  1469. return gspca_dev->usb_err;
  1470. gspca_dbg(gspca_dev, D_PROBE, "Sonix chip id: %02x\n", regF1);
  1471. if (gspca_dev->audio)
  1472. regGpio[1] |= 0x04; /* with audio */
  1473. switch (sd->bridge) {
  1474. case BRIDGE_SN9C102P:
  1475. case BRIDGE_SN9C105:
  1476. if (regF1 != 0x11)
  1477. return -ENODEV;
  1478. break;
  1479. default:
  1480. /* case BRIDGE_SN9C110: */
  1481. /* case BRIDGE_SN9C120: */
  1482. if (regF1 != 0x12)
  1483. return -ENODEV;
  1484. }
  1485. switch (sd->sensor) {
  1486. case SENSOR_MI0360:
  1487. mi0360_probe(gspca_dev);
  1488. break;
  1489. case SENSOR_OV7630:
  1490. ov7630_probe(gspca_dev);
  1491. break;
  1492. case SENSOR_OV7648:
  1493. ov7648_probe(gspca_dev);
  1494. break;
  1495. case SENSOR_PO2030N:
  1496. po2030n_probe(gspca_dev);
  1497. break;
  1498. }
  1499. switch (sd->bridge) {
  1500. case BRIDGE_SN9C102P:
  1501. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1502. break;
  1503. default:
  1504. reg_w(gspca_dev, 0x01, regGpio, 2);
  1505. break;
  1506. }
  1507. /* Note we do not disable the sensor clock here (power saving mode),
  1508. as that also disables the button on the cam. */
  1509. reg_w1(gspca_dev, 0xf1, 0x00);
  1510. /* set the i2c address */
  1511. sn9c1xx = sn_tb[sd->sensor];
  1512. sd->i2c_addr = sn9c1xx[9];
  1513. return gspca_dev->usb_err;
  1514. }
  1515. static int sd_s_ctrl(struct v4l2_ctrl *ctrl);
  1516. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  1517. .s_ctrl = sd_s_ctrl,
  1518. };
  1519. /* this function is called at probe time */
  1520. static int sd_init_controls(struct gspca_dev *gspca_dev)
  1521. {
  1522. struct sd *sd = (struct sd *) gspca_dev;
  1523. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  1524. gspca_dev->vdev.ctrl_handler = hdl;
  1525. v4l2_ctrl_handler_init(hdl, 14);
  1526. sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1527. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  1528. #define CONTRAST_MAX 127
  1529. sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1530. V4L2_CID_CONTRAST, 0, CONTRAST_MAX, 1, 20);
  1531. #define COLORS_DEF 25
  1532. sd->saturation = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1533. V4L2_CID_SATURATION, 0, 40, 1, COLORS_DEF);
  1534. sd->red_bal = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1535. V4L2_CID_RED_BALANCE, 24, 40, 1, 32);
  1536. sd->blue_bal = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1537. V4L2_CID_BLUE_BALANCE, 24, 40, 1, 32);
  1538. #define GAMMA_DEF 20
  1539. sd->gamma = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1540. V4L2_CID_GAMMA, 0, 40, 1, GAMMA_DEF);
  1541. if (sd->sensor == SENSOR_OM6802)
  1542. sd->sharpness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1543. V4L2_CID_SHARPNESS, 0, 255, 1, 16);
  1544. else
  1545. sd->sharpness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1546. V4L2_CID_SHARPNESS, 0, 255, 1, 90);
  1547. if (sd->flags & F_ILLUM)
  1548. sd->illum = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1549. V4L2_CID_ILLUMINATORS_1, 0, 1, 1, 0);
  1550. if (sd->sensor == SENSOR_PO2030N) {
  1551. gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1552. V4L2_CID_EXPOSURE, 500, 1500, 1, 1024);
  1553. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1554. V4L2_CID_GAIN, 4, 49, 1, 15);
  1555. sd->hflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1556. V4L2_CID_HFLIP, 0, 1, 1, 0);
  1557. }
  1558. if (sd->sensor != SENSOR_ADCM1700 && sd->sensor != SENSOR_OV7660 &&
  1559. sd->sensor != SENSOR_PO1030 && sd->sensor != SENSOR_SOI768 &&
  1560. sd->sensor != SENSOR_SP80708)
  1561. gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1562. V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
  1563. if (sd->sensor == SENSOR_HV7131R || sd->sensor == SENSOR_OV7630 ||
  1564. sd->sensor == SENSOR_OV7648 || sd->sensor == SENSOR_PO2030N)
  1565. sd->vflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1566. V4L2_CID_VFLIP, 0, 1, 1, 0);
  1567. if (sd->sensor == SENSOR_OV7630 || sd->sensor == SENSOR_OV7648 ||
  1568. sd->sensor == SENSOR_OV7660)
  1569. sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
  1570. V4L2_CID_POWER_LINE_FREQUENCY,
  1571. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
  1572. V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
  1573. if (hdl->error) {
  1574. pr_err("Could not initialize controls\n");
  1575. return hdl->error;
  1576. }
  1577. v4l2_ctrl_cluster(2, &sd->red_bal);
  1578. if (sd->sensor == SENSOR_PO2030N) {
  1579. v4l2_ctrl_cluster(2, &sd->vflip);
  1580. v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
  1581. }
  1582. return 0;
  1583. }
  1584. static u32 expo_adjust(struct gspca_dev *gspca_dev,
  1585. u32 expo)
  1586. {
  1587. struct sd *sd = (struct sd *) gspca_dev;
  1588. switch (sd->sensor) {
  1589. case SENSOR_GC0307: {
  1590. int a, b;
  1591. /* expo = 0..255 -> a = 19..43 */
  1592. a = 19 + expo * 25 / 256;
  1593. i2c_w1(gspca_dev, 0x68, a);
  1594. a -= 12;
  1595. b = a * a * 4; /* heuristic */
  1596. i2c_w1(gspca_dev, 0x03, b >> 8);
  1597. i2c_w1(gspca_dev, 0x04, b);
  1598. break;
  1599. }
  1600. case SENSOR_HV7131R: {
  1601. u8 Expodoit[] =
  1602. { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1603. Expodoit[3] = expo >> 16;
  1604. Expodoit[4] = expo >> 8;
  1605. Expodoit[5] = expo;
  1606. i2c_w8(gspca_dev, Expodoit);
  1607. break;
  1608. }
  1609. case SENSOR_MI0360:
  1610. case SENSOR_MI0360B: {
  1611. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1612. { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1613. static const u8 doit[] = /* update sensor */
  1614. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1615. static const u8 sensorgo[] = /* sensor on */
  1616. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1617. if (expo > 0x0635)
  1618. expo = 0x0635;
  1619. else if (expo < 0x0001)
  1620. expo = 0x0001;
  1621. expoMi[3] = expo >> 8;
  1622. expoMi[4] = expo;
  1623. i2c_w8(gspca_dev, expoMi);
  1624. i2c_w8(gspca_dev, doit);
  1625. i2c_w8(gspca_dev, sensorgo);
  1626. break;
  1627. }
  1628. case SENSOR_MO4000: {
  1629. u8 expoMof[] =
  1630. { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1631. u8 expoMo10[] =
  1632. { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1633. static const u8 gainMo[] =
  1634. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1635. if (expo > 0x1fff)
  1636. expo = 0x1fff;
  1637. else if (expo < 0x0001)
  1638. expo = 0x0001;
  1639. expoMof[3] = (expo & 0x03fc) >> 2;
  1640. i2c_w8(gspca_dev, expoMof);
  1641. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1642. | ((expo & 0x0003) << 4);
  1643. i2c_w8(gspca_dev, expoMo10);
  1644. i2c_w8(gspca_dev, gainMo);
  1645. gspca_dbg(gspca_dev, D_FRAM, "set exposure %d\n",
  1646. ((expoMo10[3] & 0x07) << 10)
  1647. | (expoMof[3] << 2)
  1648. | ((expoMo10[3] & 0x30) >> 4));
  1649. break;
  1650. }
  1651. case SENSOR_MT9V111: {
  1652. u8 expo_c1[] =
  1653. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1654. if (expo > 0x0390)
  1655. expo = 0x0390;
  1656. else if (expo < 0x0060)
  1657. expo = 0x0060;
  1658. expo_c1[3] = expo >> 8;
  1659. expo_c1[4] = expo;
  1660. i2c_w8(gspca_dev, expo_c1);
  1661. break;
  1662. }
  1663. case SENSOR_OM6802: {
  1664. u8 gainOm[] =
  1665. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1666. /* preset AGC - works when AutoExpo = off */
  1667. if (expo > 0x03ff)
  1668. expo = 0x03ff;
  1669. if (expo < 0x0001)
  1670. expo = 0x0001;
  1671. gainOm[3] = expo >> 2;
  1672. i2c_w8(gspca_dev, gainOm);
  1673. reg_w1(gspca_dev, 0x96, expo >> 5);
  1674. gspca_dbg(gspca_dev, D_FRAM, "set exposure %d\n", gainOm[3]);
  1675. break;
  1676. }
  1677. }
  1678. return expo;
  1679. }
  1680. static void setbrightness(struct gspca_dev *gspca_dev)
  1681. {
  1682. struct sd *sd = (struct sd *) gspca_dev;
  1683. unsigned int expo;
  1684. int brightness = sd->brightness->val;
  1685. u8 k2;
  1686. k2 = (brightness - 0x80) >> 2;
  1687. switch (sd->sensor) {
  1688. case SENSOR_ADCM1700:
  1689. if (k2 > 0x1f)
  1690. k2 = 0; /* only positive Y offset */
  1691. break;
  1692. case SENSOR_HV7131R:
  1693. expo = brightness << 12;
  1694. if (expo > 0x002dc6c0)
  1695. expo = 0x002dc6c0;
  1696. else if (expo < 0x02a0)
  1697. expo = 0x02a0;
  1698. sd->exposure = expo_adjust(gspca_dev, expo);
  1699. break;
  1700. case SENSOR_MI0360:
  1701. case SENSOR_MO4000:
  1702. expo = brightness << 4;
  1703. sd->exposure = expo_adjust(gspca_dev, expo);
  1704. break;
  1705. case SENSOR_MI0360B:
  1706. expo = brightness << 2;
  1707. sd->exposure = expo_adjust(gspca_dev, expo);
  1708. break;
  1709. case SENSOR_GC0307:
  1710. expo = brightness;
  1711. sd->exposure = expo_adjust(gspca_dev, expo);
  1712. return; /* don't set the Y offset */
  1713. case SENSOR_MT9V111:
  1714. expo = brightness << 2;
  1715. sd->exposure = expo_adjust(gspca_dev, expo);
  1716. return; /* don't set the Y offset */
  1717. case SENSOR_OM6802:
  1718. expo = brightness << 2;
  1719. sd->exposure = expo_adjust(gspca_dev, expo);
  1720. return; /* Y offset already set */
  1721. }
  1722. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  1723. }
  1724. static void setcontrast(struct gspca_dev *gspca_dev)
  1725. {
  1726. struct sd *sd = (struct sd *) gspca_dev;
  1727. u8 k2;
  1728. u8 contrast[6];
  1729. k2 = sd->contrast->val * 37 / (CONTRAST_MAX + 1)
  1730. + 37; /* 37..73 */
  1731. contrast[0] = (k2 + 1) / 2; /* red */
  1732. contrast[1] = 0;
  1733. contrast[2] = k2; /* green */
  1734. contrast[3] = 0;
  1735. contrast[4] = k2 / 5; /* blue */
  1736. contrast[5] = 0;
  1737. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  1738. }
  1739. static void setcolors(struct gspca_dev *gspca_dev)
  1740. {
  1741. struct sd *sd = (struct sd *) gspca_dev;
  1742. int i, v, colors;
  1743. const s16 *uv;
  1744. u8 reg8a[12]; /* U & V gains */
  1745. static const s16 uv_com[6] = { /* same as reg84 in signed decimal */
  1746. -24, -38, 64, /* UR UG UB */
  1747. 62, -51, -9 /* VR VG VB */
  1748. };
  1749. static const s16 uv_mi0360b[6] = {
  1750. -20, -38, 64, /* UR UG UB */
  1751. 60, -51, -9 /* VR VG VB */
  1752. };
  1753. colors = sd->saturation->val;
  1754. if (sd->sensor == SENSOR_MI0360B)
  1755. uv = uv_mi0360b;
  1756. else
  1757. uv = uv_com;
  1758. for (i = 0; i < 6; i++) {
  1759. v = uv[i] * colors / COLORS_DEF;
  1760. reg8a[i * 2] = v;
  1761. reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
  1762. }
  1763. reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
  1764. }
  1765. static void setredblue(struct gspca_dev *gspca_dev)
  1766. {
  1767. struct sd *sd = (struct sd *) gspca_dev;
  1768. if (sd->sensor == SENSOR_PO2030N) {
  1769. u8 rg1b[] = /* red green1 blue (no g2) */
  1770. {0xc1, 0x6e, 0x16, 0x00, 0x40, 0x00, 0x00, 0x10};
  1771. /* 0x40 = normal value = gain x 1 */
  1772. rg1b[3] = sd->red_bal->val * 2;
  1773. rg1b[5] = sd->blue_bal->val * 2;
  1774. i2c_w8(gspca_dev, rg1b);
  1775. return;
  1776. }
  1777. reg_w1(gspca_dev, 0x05, sd->red_bal->val);
  1778. /* reg_w1(gspca_dev, 0x07, 32); */
  1779. reg_w1(gspca_dev, 0x06, sd->blue_bal->val);
  1780. }
  1781. static void setgamma(struct gspca_dev *gspca_dev)
  1782. {
  1783. struct sd *sd = (struct sd *) gspca_dev;
  1784. int i, val;
  1785. u8 gamma[17];
  1786. const u8 *gamma_base;
  1787. static const u8 delta[17] = {
  1788. 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
  1789. 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
  1790. };
  1791. switch (sd->sensor) {
  1792. case SENSOR_ADCM1700:
  1793. gamma_base = gamma_spec_0;
  1794. break;
  1795. case SENSOR_HV7131R:
  1796. case SENSOR_MI0360B:
  1797. case SENSOR_MT9V111:
  1798. gamma_base = gamma_spec_1;
  1799. break;
  1800. case SENSOR_GC0307:
  1801. gamma_base = gamma_spec_2;
  1802. break;
  1803. case SENSOR_SP80708:
  1804. gamma_base = gamma_spec_3;
  1805. break;
  1806. default:
  1807. gamma_base = gamma_def;
  1808. break;
  1809. }
  1810. val = sd->gamma->val;
  1811. for (i = 0; i < sizeof gamma; i++)
  1812. gamma[i] = gamma_base[i]
  1813. + delta[i] * (val - GAMMA_DEF) / 32;
  1814. reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
  1815. }
  1816. static void setexposure(struct gspca_dev *gspca_dev)
  1817. {
  1818. struct sd *sd = (struct sd *) gspca_dev;
  1819. if (sd->sensor == SENSOR_PO2030N) {
  1820. u8 rexpo[] = /* 1a: expo H, 1b: expo M */
  1821. {0xa1, 0x6e, 0x1a, 0x00, 0x40, 0x00, 0x00, 0x10};
  1822. rexpo[3] = gspca_dev->exposure->val >> 8;
  1823. i2c_w8(gspca_dev, rexpo);
  1824. msleep(6);
  1825. rexpo[2] = 0x1b;
  1826. rexpo[3] = gspca_dev->exposure->val;
  1827. i2c_w8(gspca_dev, rexpo);
  1828. }
  1829. }
  1830. static void setautogain(struct gspca_dev *gspca_dev)
  1831. {
  1832. struct sd *sd = (struct sd *) gspca_dev;
  1833. switch (sd->sensor) {
  1834. case SENSOR_OV7630:
  1835. case SENSOR_OV7648: {
  1836. u8 comb;
  1837. if (sd->sensor == SENSOR_OV7630)
  1838. comb = 0xc0;
  1839. else
  1840. comb = 0xa0;
  1841. if (gspca_dev->autogain->val)
  1842. comb |= 0x03;
  1843. i2c_w1(&sd->gspca_dev, 0x13, comb);
  1844. return;
  1845. }
  1846. }
  1847. if (gspca_dev->autogain->val)
  1848. sd->ag_cnt = AG_CNT_START;
  1849. else
  1850. sd->ag_cnt = -1;
  1851. }
  1852. static void setgain(struct gspca_dev *gspca_dev)
  1853. {
  1854. struct sd *sd = (struct sd *) gspca_dev;
  1855. if (sd->sensor == SENSOR_PO2030N) {
  1856. u8 rgain[] = /* 15: gain */
  1857. {0xa1, 0x6e, 0x15, 0x00, 0x40, 0x00, 0x00, 0x15};
  1858. rgain[3] = gspca_dev->gain->val;
  1859. i2c_w8(gspca_dev, rgain);
  1860. }
  1861. }
  1862. static void sethvflip(struct gspca_dev *gspca_dev)
  1863. {
  1864. struct sd *sd = (struct sd *) gspca_dev;
  1865. u8 comn;
  1866. switch (sd->sensor) {
  1867. case SENSOR_HV7131R:
  1868. comn = 0x18; /* clkdiv = 1, ablcen = 1 */
  1869. if (sd->vflip->val)
  1870. comn |= 0x01;
  1871. i2c_w1(gspca_dev, 0x01, comn); /* sctra */
  1872. break;
  1873. case SENSOR_OV7630:
  1874. comn = 0x02;
  1875. if (!sd->vflip->val)
  1876. comn |= 0x80;
  1877. i2c_w1(gspca_dev, 0x75, comn);
  1878. break;
  1879. case SENSOR_OV7648:
  1880. comn = 0x06;
  1881. if (sd->vflip->val)
  1882. comn |= 0x80;
  1883. i2c_w1(gspca_dev, 0x75, comn);
  1884. break;
  1885. case SENSOR_PO2030N:
  1886. /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
  1887. * (reset value: 0x0A)
  1888. * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
  1889. * bit6: VM: Vertical Mirror: 0: disable, 1: enable
  1890. * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
  1891. * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
  1892. * bit3-0: X
  1893. */
  1894. comn = 0x0a;
  1895. if (sd->hflip->val)
  1896. comn |= 0x80;
  1897. if (sd->vflip->val)
  1898. comn |= 0x40;
  1899. i2c_w1(&sd->gspca_dev, 0x1e, comn);
  1900. break;
  1901. }
  1902. }
  1903. static void setsharpness(struct gspca_dev *gspca_dev)
  1904. {
  1905. struct sd *sd = (struct sd *) gspca_dev;
  1906. reg_w1(gspca_dev, 0x99, sd->sharpness->val);
  1907. }
  1908. static void setillum(struct gspca_dev *gspca_dev)
  1909. {
  1910. struct sd *sd = (struct sd *) gspca_dev;
  1911. switch (sd->sensor) {
  1912. case SENSOR_ADCM1700:
  1913. reg_w1(gspca_dev, 0x02, /* gpio */
  1914. sd->illum->val ? 0x64 : 0x60);
  1915. break;
  1916. case SENSOR_MT9V111:
  1917. reg_w1(gspca_dev, 0x02,
  1918. sd->illum->val ? 0x77 : 0x74);
  1919. /* should have been: */
  1920. /* 0x55 : 0x54); * 370i */
  1921. /* 0x66 : 0x64); * Clip */
  1922. break;
  1923. }
  1924. }
  1925. static void setfreq(struct gspca_dev *gspca_dev)
  1926. {
  1927. struct sd *sd = (struct sd *) gspca_dev;
  1928. if (sd->sensor == SENSOR_OV7660) {
  1929. u8 com8;
  1930. com8 = 0xdf; /* auto gain/wb/expo */
  1931. switch (sd->freq->val) {
  1932. case 0: /* Banding filter disabled */
  1933. i2c_w1(gspca_dev, 0x13, com8 | 0x20);
  1934. break;
  1935. case 1: /* 50 hz */
  1936. i2c_w1(gspca_dev, 0x13, com8);
  1937. i2c_w1(gspca_dev, 0x3b, 0x0a);
  1938. break;
  1939. case 2: /* 60 hz */
  1940. i2c_w1(gspca_dev, 0x13, com8);
  1941. i2c_w1(gspca_dev, 0x3b, 0x02);
  1942. break;
  1943. }
  1944. } else {
  1945. u8 reg2a = 0, reg2b = 0, reg2d = 0;
  1946. /* Get reg2a / reg2d base values */
  1947. switch (sd->sensor) {
  1948. case SENSOR_OV7630:
  1949. reg2a = 0x08;
  1950. reg2d = 0x01;
  1951. break;
  1952. case SENSOR_OV7648:
  1953. reg2a = 0x11;
  1954. reg2d = 0x81;
  1955. break;
  1956. }
  1957. switch (sd->freq->val) {
  1958. case 0: /* Banding filter disabled */
  1959. break;
  1960. case 1: /* 50 hz (filter on and framerate adj) */
  1961. reg2a |= 0x80;
  1962. reg2b = 0xac;
  1963. reg2d |= 0x04;
  1964. break;
  1965. case 2: /* 60 hz (filter on, no framerate adj) */
  1966. reg2a |= 0x80;
  1967. reg2d |= 0x04;
  1968. break;
  1969. }
  1970. i2c_w1(gspca_dev, 0x2a, reg2a);
  1971. i2c_w1(gspca_dev, 0x2b, reg2b);
  1972. i2c_w1(gspca_dev, 0x2d, reg2d);
  1973. }
  1974. }
  1975. static void setjpegqual(struct gspca_dev *gspca_dev)
  1976. {
  1977. struct sd *sd = (struct sd *) gspca_dev;
  1978. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  1979. #if USB_BUF_SZ < 64
  1980. #error "No room enough in usb_buf for quantization table"
  1981. #endif
  1982. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
  1983. usb_control_msg(gspca_dev->dev,
  1984. usb_sndctrlpipe(gspca_dev->dev, 0),
  1985. 0x08,
  1986. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1987. 0x0100, 0,
  1988. gspca_dev->usb_buf, 64,
  1989. 500);
  1990. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
  1991. usb_control_msg(gspca_dev->dev,
  1992. usb_sndctrlpipe(gspca_dev->dev, 0),
  1993. 0x08,
  1994. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1995. 0x0140, 0,
  1996. gspca_dev->usb_buf, 64,
  1997. 500);
  1998. sd->reg18 ^= 0x40;
  1999. reg_w1(gspca_dev, 0x18, sd->reg18);
  2000. }
  2001. /* JPEG quality update */
  2002. /* This function is executed from a work queue. */
  2003. static void qual_upd(struct work_struct *work)
  2004. {
  2005. struct sd *sd = container_of(work, struct sd, work);
  2006. struct gspca_dev *gspca_dev = &sd->gspca_dev;
  2007. /* To protect gspca_dev->usb_buf and gspca_dev->usb_err */
  2008. mutex_lock(&gspca_dev->usb_lock);
  2009. gspca_dbg(gspca_dev, D_STREAM, "qual_upd %d%%\n", sd->quality);
  2010. gspca_dev->usb_err = 0;
  2011. setjpegqual(gspca_dev);
  2012. mutex_unlock(&gspca_dev->usb_lock);
  2013. }
  2014. /* -- start the camera -- */
  2015. static int sd_start(struct gspca_dev *gspca_dev)
  2016. {
  2017. struct sd *sd = (struct sd *) gspca_dev;
  2018. int i;
  2019. u8 reg01, reg17;
  2020. u8 reg0102[2];
  2021. const u8 *sn9c1xx;
  2022. const u8 (*init)[8];
  2023. const u8 *reg9a;
  2024. int mode;
  2025. static const u8 reg9a_def[] =
  2026. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  2027. static const u8 reg9a_spec[] =
  2028. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  2029. static const u8 regd4[] = {0x60, 0x00, 0x00};
  2030. static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  2031. static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  2032. static const u8 CA_adcm1700[] =
  2033. { 0x14, 0xec, 0x0a, 0xf6 };
  2034. static const u8 CA_po2030n[] =
  2035. { 0x1e, 0xe2, 0x14, 0xec };
  2036. static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  2037. static const u8 CE_gc0307[] =
  2038. { 0x32, 0xce, 0x2d, 0xd3 };
  2039. static const u8 CE_ov76xx[] =
  2040. { 0x32, 0xdd, 0x32, 0xdd };
  2041. static const u8 CE_po2030n[] =
  2042. { 0x14, 0xe7, 0x1e, 0xdd };
  2043. /* create the JPEG header */
  2044. jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
  2045. gspca_dev->pixfmt.width,
  2046. 0x21); /* JPEG 422 */
  2047. /* initialize the bridge */
  2048. sn9c1xx = sn_tb[sd->sensor];
  2049. /* sensor clock already enabled in sd_init */
  2050. /* reg_w1(gspca_dev, 0xf1, 0x00); */
  2051. reg01 = sn9c1xx[1];
  2052. if (sd->flags & F_PDN_INV)
  2053. reg01 ^= S_PDN_INV; /* power down inverted */
  2054. reg_w1(gspca_dev, 0x01, reg01);
  2055. /* configure gpio */
  2056. reg0102[0] = reg01;
  2057. reg0102[1] = sn9c1xx[2];
  2058. if (gspca_dev->audio)
  2059. reg0102[1] |= 0x04; /* keep the audio connection */
  2060. reg_w(gspca_dev, 0x01, reg0102, 2);
  2061. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  2062. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
  2063. switch (sd->sensor) {
  2064. case SENSOR_GC0307:
  2065. case SENSOR_OV7660:
  2066. case SENSOR_PO1030:
  2067. case SENSOR_PO2030N:
  2068. case SENSOR_SOI768:
  2069. case SENSOR_SP80708:
  2070. reg9a = reg9a_spec;
  2071. break;
  2072. default:
  2073. reg9a = reg9a_def;
  2074. break;
  2075. }
  2076. reg_w(gspca_dev, 0x9a, reg9a, 6);
  2077. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
  2078. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  2079. reg17 = sn9c1xx[0x17];
  2080. switch (sd->sensor) {
  2081. case SENSOR_GC0307:
  2082. msleep(50); /*fixme: is it useful? */
  2083. break;
  2084. case SENSOR_OM6802:
  2085. msleep(10);
  2086. reg_w1(gspca_dev, 0x02, 0x73);
  2087. reg17 |= SEN_CLK_EN;
  2088. reg_w1(gspca_dev, 0x17, reg17);
  2089. reg_w1(gspca_dev, 0x01, 0x22);
  2090. msleep(100);
  2091. reg01 = SCL_SEL_OD | S_PDN_INV;
  2092. reg17 &= ~MCK_SIZE_MASK;
  2093. reg17 |= 0x04; /* clock / 4 */
  2094. break;
  2095. }
  2096. reg01 |= SYS_SEL_48M;
  2097. reg_w1(gspca_dev, 0x01, reg01);
  2098. reg17 |= SEN_CLK_EN;
  2099. reg_w1(gspca_dev, 0x17, reg17);
  2100. reg01 &= ~S_PWR_DN; /* sensor power on */
  2101. reg_w1(gspca_dev, 0x01, reg01);
  2102. reg01 &= ~SCL_SEL_OD; /* remove open-drain mode */
  2103. reg_w1(gspca_dev, 0x01, reg01);
  2104. switch (sd->sensor) {
  2105. case SENSOR_HV7131R:
  2106. hv7131r_probe(gspca_dev); /*fixme: is it useful? */
  2107. break;
  2108. case SENSOR_OM6802:
  2109. msleep(10);
  2110. reg_w1(gspca_dev, 0x01, reg01);
  2111. i2c_w8(gspca_dev, om6802_init0[0]);
  2112. i2c_w8(gspca_dev, om6802_init0[1]);
  2113. msleep(15);
  2114. reg_w1(gspca_dev, 0x02, 0x71);
  2115. msleep(150);
  2116. break;
  2117. case SENSOR_SP80708:
  2118. msleep(100);
  2119. reg_w1(gspca_dev, 0x02, 0x62);
  2120. break;
  2121. }
  2122. /* initialize the sensor */
  2123. i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
  2124. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  2125. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  2126. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  2127. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  2128. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2129. if (sd->sensor == SENSOR_ADCM1700) {
  2130. reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
  2131. reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
  2132. } else {
  2133. reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
  2134. reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
  2135. }
  2136. reg_w1(gspca_dev, 0xc6, 0x00);
  2137. reg_w1(gspca_dev, 0xc7, 0x00);
  2138. if (sd->sensor == SENSOR_ADCM1700) {
  2139. reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
  2140. reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
  2141. } else {
  2142. reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
  2143. reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
  2144. }
  2145. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2146. switch (sd->sensor) {
  2147. case SENSOR_OM6802:
  2148. /* case SENSOR_OV7648: * fixme: sometimes */
  2149. break;
  2150. default:
  2151. reg17 |= DEF_EN;
  2152. break;
  2153. }
  2154. reg_w1(gspca_dev, 0x17, reg17);
  2155. reg_w1(gspca_dev, 0x05, 0x00); /* red */
  2156. reg_w1(gspca_dev, 0x07, 0x00); /* green */
  2157. reg_w1(gspca_dev, 0x06, 0x00); /* blue */
  2158. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  2159. setgamma(gspca_dev);
  2160. /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
  2161. for (i = 0; i < 8; i++)
  2162. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2163. switch (sd->sensor) {
  2164. case SENSOR_ADCM1700:
  2165. case SENSOR_OV7660:
  2166. case SENSOR_SP80708:
  2167. reg_w1(gspca_dev, 0x9a, 0x05);
  2168. break;
  2169. case SENSOR_GC0307:
  2170. case SENSOR_MT9V111:
  2171. case SENSOR_MI0360B:
  2172. reg_w1(gspca_dev, 0x9a, 0x07);
  2173. break;
  2174. case SENSOR_OV7630:
  2175. case SENSOR_OV7648:
  2176. reg_w1(gspca_dev, 0x9a, 0x0a);
  2177. break;
  2178. case SENSOR_PO2030N:
  2179. case SENSOR_SOI768:
  2180. reg_w1(gspca_dev, 0x9a, 0x06);
  2181. break;
  2182. default:
  2183. reg_w1(gspca_dev, 0x9a, 0x08);
  2184. break;
  2185. }
  2186. setsharpness(gspca_dev);
  2187. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2188. reg_w1(gspca_dev, 0x05, 0x20); /* red */
  2189. reg_w1(gspca_dev, 0x07, 0x20); /* green */
  2190. reg_w1(gspca_dev, 0x06, 0x20); /* blue */
  2191. init = NULL;
  2192. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  2193. reg01 |= SYS_SEL_48M | V_TX_EN;
  2194. reg17 &= ~MCK_SIZE_MASK;
  2195. reg17 |= 0x02; /* clock / 2 */
  2196. switch (sd->sensor) {
  2197. case SENSOR_ADCM1700:
  2198. init = adcm1700_sensor_param1;
  2199. break;
  2200. case SENSOR_GC0307:
  2201. init = gc0307_sensor_param1;
  2202. break;
  2203. case SENSOR_HV7131R:
  2204. case SENSOR_MI0360:
  2205. if (!mode)
  2206. reg01 &= ~SYS_SEL_48M; /* 640x480: clk 24Mhz */
  2207. reg17 &= ~MCK_SIZE_MASK;
  2208. reg17 |= 0x01; /* clock / 1 */
  2209. break;
  2210. case SENSOR_MI0360B:
  2211. init = mi0360b_sensor_param1;
  2212. break;
  2213. case SENSOR_MO4000:
  2214. if (mode) { /* if 320x240 */
  2215. reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
  2216. reg17 &= ~MCK_SIZE_MASK;
  2217. reg17 |= 0x01; /* clock / 1 */
  2218. }
  2219. break;
  2220. case SENSOR_MT9V111:
  2221. init = mt9v111_sensor_param1;
  2222. break;
  2223. case SENSOR_OM6802:
  2224. init = om6802_sensor_param1;
  2225. if (!mode) { /* if 640x480 */
  2226. reg17 &= ~MCK_SIZE_MASK;
  2227. reg17 |= 0x04; /* clock / 4 */
  2228. } else {
  2229. reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
  2230. reg17 &= ~MCK_SIZE_MASK;
  2231. reg17 |= 0x02; /* clock / 2 */
  2232. }
  2233. break;
  2234. case SENSOR_OV7630:
  2235. init = ov7630_sensor_param1;
  2236. break;
  2237. case SENSOR_OV7648:
  2238. init = ov7648_sensor_param1;
  2239. reg17 &= ~MCK_SIZE_MASK;
  2240. reg17 |= 0x01; /* clock / 1 */
  2241. break;
  2242. case SENSOR_OV7660:
  2243. init = ov7660_sensor_param1;
  2244. break;
  2245. case SENSOR_PO1030:
  2246. init = po1030_sensor_param1;
  2247. break;
  2248. case SENSOR_PO2030N:
  2249. init = po2030n_sensor_param1;
  2250. break;
  2251. case SENSOR_SOI768:
  2252. init = soi768_sensor_param1;
  2253. break;
  2254. case SENSOR_SP80708:
  2255. init = sp80708_sensor_param1;
  2256. break;
  2257. }
  2258. /* more sensor initialization - param1 */
  2259. if (init != NULL) {
  2260. i2c_w_seq(gspca_dev, init);
  2261. /* init = NULL; */
  2262. }
  2263. reg_w(gspca_dev, 0xc0, C0, 6);
  2264. switch (sd->sensor) {
  2265. case SENSOR_ADCM1700:
  2266. case SENSOR_GC0307:
  2267. case SENSOR_SOI768:
  2268. reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
  2269. break;
  2270. case SENSOR_PO2030N:
  2271. reg_w(gspca_dev, 0xca, CA_po2030n, 4);
  2272. break;
  2273. default:
  2274. reg_w(gspca_dev, 0xca, CA, 4);
  2275. break;
  2276. }
  2277. switch (sd->sensor) {
  2278. case SENSOR_ADCM1700:
  2279. case SENSOR_OV7630:
  2280. case SENSOR_OV7648:
  2281. case SENSOR_OV7660:
  2282. case SENSOR_SOI768:
  2283. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  2284. break;
  2285. case SENSOR_GC0307:
  2286. reg_w(gspca_dev, 0xce, CE_gc0307, 4);
  2287. break;
  2288. case SENSOR_PO2030N:
  2289. reg_w(gspca_dev, 0xce, CE_po2030n, 4);
  2290. break;
  2291. default:
  2292. reg_w(gspca_dev, 0xce, CE, 4);
  2293. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  2294. break;
  2295. }
  2296. /* here change size mode 0 -> VGA; 1 -> CIF */
  2297. sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
  2298. reg_w1(gspca_dev, 0x18, sd->reg18);
  2299. setjpegqual(gspca_dev);
  2300. reg_w1(gspca_dev, 0x17, reg17);
  2301. reg_w1(gspca_dev, 0x01, reg01);
  2302. sd->reg01 = reg01;
  2303. sd->reg17 = reg17;
  2304. sd->pktsz = sd->npkt = 0;
  2305. sd->nchg = sd->short_mark = 0;
  2306. return gspca_dev->usb_err;
  2307. }
  2308. static void sd_stopN(struct gspca_dev *gspca_dev)
  2309. {
  2310. struct sd *sd = (struct sd *) gspca_dev;
  2311. static const u8 stophv7131[] =
  2312. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  2313. static const u8 stopmi0360[] =
  2314. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  2315. static const u8 stopov7648[] =
  2316. { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
  2317. static const u8 stopsoi768[] =
  2318. { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
  2319. u8 reg01;
  2320. u8 reg17;
  2321. reg01 = sd->reg01;
  2322. reg17 = sd->reg17 & ~SEN_CLK_EN;
  2323. switch (sd->sensor) {
  2324. case SENSOR_ADCM1700:
  2325. case SENSOR_GC0307:
  2326. case SENSOR_PO2030N:
  2327. case SENSOR_SP80708:
  2328. reg01 |= LED;
  2329. reg_w1(gspca_dev, 0x01, reg01);
  2330. reg01 &= ~(LED | V_TX_EN);
  2331. reg_w1(gspca_dev, 0x01, reg01);
  2332. /* reg_w1(gspca_dev, 0x02, 0x??); * LED off ? */
  2333. break;
  2334. case SENSOR_HV7131R:
  2335. reg01 &= ~V_TX_EN;
  2336. reg_w1(gspca_dev, 0x01, reg01);
  2337. i2c_w8(gspca_dev, stophv7131);
  2338. break;
  2339. case SENSOR_MI0360:
  2340. case SENSOR_MI0360B:
  2341. reg01 &= ~V_TX_EN;
  2342. reg_w1(gspca_dev, 0x01, reg01);
  2343. /* reg_w1(gspca_dev, 0x02, 0x40); * LED off ? */
  2344. i2c_w8(gspca_dev, stopmi0360);
  2345. break;
  2346. case SENSOR_MT9V111:
  2347. case SENSOR_OM6802:
  2348. case SENSOR_PO1030:
  2349. reg01 &= ~V_TX_EN;
  2350. reg_w1(gspca_dev, 0x01, reg01);
  2351. break;
  2352. case SENSOR_OV7630:
  2353. case SENSOR_OV7648:
  2354. reg01 &= ~V_TX_EN;
  2355. reg_w1(gspca_dev, 0x01, reg01);
  2356. i2c_w8(gspca_dev, stopov7648);
  2357. break;
  2358. case SENSOR_OV7660:
  2359. reg01 &= ~V_TX_EN;
  2360. reg_w1(gspca_dev, 0x01, reg01);
  2361. break;
  2362. case SENSOR_SOI768:
  2363. i2c_w8(gspca_dev, stopsoi768);
  2364. break;
  2365. }
  2366. reg01 |= SCL_SEL_OD;
  2367. reg_w1(gspca_dev, 0x01, reg01);
  2368. reg01 |= S_PWR_DN; /* sensor power down */
  2369. reg_w1(gspca_dev, 0x01, reg01);
  2370. reg_w1(gspca_dev, 0x17, reg17);
  2371. reg01 &= ~SYS_SEL_48M; /* clock 24MHz */
  2372. reg_w1(gspca_dev, 0x01, reg01);
  2373. reg01 |= LED;
  2374. reg_w1(gspca_dev, 0x01, reg01);
  2375. /* Don't disable sensor clock as that disables the button on the cam */
  2376. /* reg_w1(gspca_dev, 0xf1, 0x01); */
  2377. }
  2378. /* called on streamoff with alt==0 and on disconnect */
  2379. /* the usb_lock is held at entry - restore on exit */
  2380. static void sd_stop0(struct gspca_dev *gspca_dev)
  2381. {
  2382. struct sd *sd = (struct sd *) gspca_dev;
  2383. mutex_unlock(&gspca_dev->usb_lock);
  2384. flush_work(&sd->work);
  2385. mutex_lock(&gspca_dev->usb_lock);
  2386. }
  2387. static void do_autogain(struct gspca_dev *gspca_dev)
  2388. {
  2389. struct sd *sd = (struct sd *) gspca_dev;
  2390. int delta;
  2391. int expotimes;
  2392. u8 luma_mean = 130;
  2393. u8 luma_delta = 20;
  2394. /* Thanks S., without your advice, autobright should not work :) */
  2395. if (sd->ag_cnt < 0)
  2396. return;
  2397. if (--sd->ag_cnt >= 0)
  2398. return;
  2399. sd->ag_cnt = AG_CNT_START;
  2400. delta = atomic_read(&sd->avg_lum);
  2401. gspca_dbg(gspca_dev, D_FRAM, "mean lum %d\n", delta);
  2402. if (sd->sensor == SENSOR_PO2030N) {
  2403. gspca_expo_autogain(gspca_dev, delta, luma_mean, luma_delta,
  2404. 15, 1024);
  2405. return;
  2406. }
  2407. if (delta < luma_mean - luma_delta ||
  2408. delta > luma_mean + luma_delta) {
  2409. switch (sd->sensor) {
  2410. case SENSOR_GC0307:
  2411. expotimes = sd->exposure;
  2412. expotimes += (luma_mean - delta) >> 6;
  2413. if (expotimes < 0)
  2414. expotimes = 0;
  2415. sd->exposure = expo_adjust(gspca_dev,
  2416. (unsigned int) expotimes);
  2417. break;
  2418. case SENSOR_HV7131R:
  2419. expotimes = sd->exposure >> 8;
  2420. expotimes += (luma_mean - delta) >> 4;
  2421. if (expotimes < 0)
  2422. expotimes = 0;
  2423. sd->exposure = expo_adjust(gspca_dev,
  2424. (unsigned int) (expotimes << 8));
  2425. break;
  2426. case SENSOR_OM6802:
  2427. case SENSOR_MT9V111:
  2428. expotimes = sd->exposure;
  2429. expotimes += (luma_mean - delta) >> 2;
  2430. if (expotimes < 0)
  2431. expotimes = 0;
  2432. sd->exposure = expo_adjust(gspca_dev,
  2433. (unsigned int) expotimes);
  2434. setredblue(gspca_dev);
  2435. break;
  2436. default:
  2437. /* case SENSOR_MO4000: */
  2438. /* case SENSOR_MI0360: */
  2439. /* case SENSOR_MI0360B: */
  2440. expotimes = sd->exposure;
  2441. expotimes += (luma_mean - delta) >> 6;
  2442. if (expotimes < 0)
  2443. expotimes = 0;
  2444. sd->exposure = expo_adjust(gspca_dev,
  2445. (unsigned int) expotimes);
  2446. setredblue(gspca_dev);
  2447. break;
  2448. }
  2449. }
  2450. }
  2451. /* set the average luminosity from an isoc marker */
  2452. static void set_lum(struct sd *sd,
  2453. u8 *data)
  2454. {
  2455. int avg_lum;
  2456. /* w0 w1 w2
  2457. * w3 w4 w5
  2458. * w6 w7 w8
  2459. */
  2460. avg_lum = (data[27] << 8) + data[28] /* w3 */
  2461. + (data[31] << 8) + data[32] /* w5 */
  2462. + (data[23] << 8) + data[24] /* w1 */
  2463. + (data[35] << 8) + data[36] /* w7 */
  2464. + (data[29] << 10) + (data[30] << 2); /* w4 * 4 */
  2465. avg_lum >>= 10;
  2466. atomic_set(&sd->avg_lum, avg_lum);
  2467. }
  2468. /* scan the URB packets */
  2469. /* This function is run at interrupt level. */
  2470. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2471. u8 *data, /* isoc packet */
  2472. int len) /* iso packet length */
  2473. {
  2474. struct sd *sd = (struct sd *) gspca_dev;
  2475. int i, new_qual;
  2476. /*
  2477. * A frame ends on the marker
  2478. * ff ff 00 c4 c4 96 ..
  2479. * which is 62 bytes long and is followed by various information
  2480. * including statuses and luminosity.
  2481. *
  2482. * A marker may be splitted on two packets.
  2483. *
  2484. * The 6th byte of a marker contains the bits:
  2485. * 0x08: USB full
  2486. * 0xc0: frame sequence
  2487. * When the bit 'USB full' is set, the frame must be discarded;
  2488. * this is also the case when the 2 bytes before the marker are
  2489. * not the JPEG end of frame ('ff d9').
  2490. */
  2491. /* count the packets and their size */
  2492. sd->npkt++;
  2493. sd->pktsz += len;
  2494. /*fixme: assumption about the following code:
  2495. * - there can be only one marker in a packet
  2496. */
  2497. /* skip the remaining bytes of a short marker */
  2498. i = sd->short_mark;
  2499. if (i != 0) {
  2500. sd->short_mark = 0;
  2501. if (i < 0 /* if 'ff' at end of previous packet */
  2502. && data[0] == 0xff
  2503. && data[1] == 0x00)
  2504. goto marker_found;
  2505. if (data[0] == 0xff && data[1] == 0xff) {
  2506. i = 0;
  2507. goto marker_found;
  2508. }
  2509. len -= i;
  2510. if (len <= 0)
  2511. return;
  2512. data += i;
  2513. }
  2514. /* search backwards if there is a marker in the packet */
  2515. for (i = len - 1; --i >= 0; ) {
  2516. if (data[i] != 0xff) {
  2517. i--;
  2518. continue;
  2519. }
  2520. if (data[i + 1] == 0xff) {
  2521. /* (there may be 'ff ff' inside a marker) */
  2522. if (i + 2 >= len || data[i + 2] == 0x00)
  2523. goto marker_found;
  2524. }
  2525. }
  2526. /* no marker found */
  2527. /* add the JPEG header if first fragment */
  2528. if (data[len - 1] == 0xff)
  2529. sd->short_mark = -1;
  2530. if (gspca_dev->last_packet_type == LAST_PACKET)
  2531. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2532. sd->jpeg_hdr, JPEG_HDR_SZ);
  2533. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2534. return;
  2535. /* marker found */
  2536. /* if some error, discard the frame and decrease the quality */
  2537. marker_found:
  2538. new_qual = 0;
  2539. if (i > 2) {
  2540. if (data[i - 2] != 0xff || data[i - 1] != 0xd9) {
  2541. gspca_dev->last_packet_type = DISCARD_PACKET;
  2542. new_qual = -3;
  2543. }
  2544. } else if (i + 6 < len) {
  2545. if (data[i + 6] & 0x08) {
  2546. gspca_dev->last_packet_type = DISCARD_PACKET;
  2547. new_qual = -5;
  2548. }
  2549. }
  2550. gspca_frame_add(gspca_dev, LAST_PACKET, data, i);
  2551. /* compute the filling rate and a new JPEG quality */
  2552. if (new_qual == 0) {
  2553. int r;
  2554. r = (sd->pktsz * 100) /
  2555. (sd->npkt *
  2556. gspca_dev->urb[0]->iso_frame_desc[0].length);
  2557. if (r >= 85)
  2558. new_qual = -3;
  2559. else if (r < 75)
  2560. new_qual = 2;
  2561. }
  2562. if (new_qual != 0) {
  2563. sd->nchg += new_qual;
  2564. if (sd->nchg < -6 || sd->nchg >= 12) {
  2565. sd->nchg = 0;
  2566. new_qual += sd->quality;
  2567. if (new_qual < QUALITY_MIN)
  2568. new_qual = QUALITY_MIN;
  2569. else if (new_qual > QUALITY_MAX)
  2570. new_qual = QUALITY_MAX;
  2571. if (new_qual != sd->quality) {
  2572. sd->quality = new_qual;
  2573. schedule_work(&sd->work);
  2574. }
  2575. }
  2576. } else {
  2577. sd->nchg = 0;
  2578. }
  2579. sd->pktsz = sd->npkt = 0;
  2580. /* if the marker is smaller than 62 bytes,
  2581. * memorize the number of bytes to skip in the next packet */
  2582. if (i + 62 > len) { /* no more usable data */
  2583. sd->short_mark = i + 62 - len;
  2584. return;
  2585. }
  2586. if (sd->ag_cnt >= 0)
  2587. set_lum(sd, data + i);
  2588. /* if more data, start a new frame */
  2589. i += 62;
  2590. if (i < len) {
  2591. data += i;
  2592. len -= i;
  2593. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2594. sd->jpeg_hdr, JPEG_HDR_SZ);
  2595. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2596. }
  2597. }
  2598. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  2599. {
  2600. struct gspca_dev *gspca_dev =
  2601. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  2602. gspca_dev->usb_err = 0;
  2603. if (!gspca_dev->streaming)
  2604. return 0;
  2605. switch (ctrl->id) {
  2606. case V4L2_CID_BRIGHTNESS:
  2607. setbrightness(gspca_dev);
  2608. break;
  2609. case V4L2_CID_CONTRAST:
  2610. setcontrast(gspca_dev);
  2611. break;
  2612. case V4L2_CID_SATURATION:
  2613. setcolors(gspca_dev);
  2614. break;
  2615. case V4L2_CID_RED_BALANCE:
  2616. setredblue(gspca_dev);
  2617. break;
  2618. case V4L2_CID_GAMMA:
  2619. setgamma(gspca_dev);
  2620. break;
  2621. case V4L2_CID_AUTOGAIN:
  2622. setautogain(gspca_dev);
  2623. setexposure(gspca_dev);
  2624. setgain(gspca_dev);
  2625. break;
  2626. case V4L2_CID_VFLIP:
  2627. sethvflip(gspca_dev);
  2628. break;
  2629. case V4L2_CID_SHARPNESS:
  2630. setsharpness(gspca_dev);
  2631. break;
  2632. case V4L2_CID_ILLUMINATORS_1:
  2633. setillum(gspca_dev);
  2634. break;
  2635. case V4L2_CID_POWER_LINE_FREQUENCY:
  2636. setfreq(gspca_dev);
  2637. break;
  2638. default:
  2639. return -EINVAL;
  2640. }
  2641. return gspca_dev->usb_err;
  2642. }
  2643. #if IS_ENABLED(CONFIG_INPUT)
  2644. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2645. u8 *data, /* interrupt packet data */
  2646. int len) /* interrupt packet length */
  2647. {
  2648. int ret = -EINVAL;
  2649. if (len == 1 && data[0] == 1) {
  2650. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2651. input_sync(gspca_dev->input_dev);
  2652. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2653. input_sync(gspca_dev->input_dev);
  2654. ret = 0;
  2655. }
  2656. return ret;
  2657. }
  2658. #endif
  2659. /* sub-driver description */
  2660. static const struct sd_desc sd_desc = {
  2661. .name = MODULE_NAME,
  2662. .config = sd_config,
  2663. .init = sd_init,
  2664. .init_controls = sd_init_controls,
  2665. .start = sd_start,
  2666. .stopN = sd_stopN,
  2667. .stop0 = sd_stop0,
  2668. .pkt_scan = sd_pkt_scan,
  2669. .dq_callback = do_autogain,
  2670. #if IS_ENABLED(CONFIG_INPUT)
  2671. .int_pkt_scan = sd_int_pkt_scan,
  2672. #endif
  2673. };
  2674. /* -- module initialisation -- */
  2675. #define BS(bridge, sensor) \
  2676. .driver_info = (BRIDGE_ ## bridge << 16) \
  2677. | (SENSOR_ ## sensor << 8)
  2678. #define BSF(bridge, sensor, flags) \
  2679. .driver_info = (BRIDGE_ ## bridge << 16) \
  2680. | (SENSOR_ ## sensor << 8) \
  2681. | (flags)
  2682. static const struct usb_device_id device_table[] = {
  2683. {USB_DEVICE(0x0458, 0x7025), BSF(SN9C120, MI0360B, F_PDN_INV)},
  2684. {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
  2685. {USB_DEVICE(0x045e, 0x00f5), BSF(SN9C105, OV7660, F_PDN_INV)},
  2686. {USB_DEVICE(0x045e, 0x00f7), BSF(SN9C105, OV7660, F_PDN_INV)},
  2687. {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
  2688. {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
  2689. {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
  2690. {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
  2691. {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
  2692. /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
  2693. {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
  2694. /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
  2695. /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
  2696. {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
  2697. /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
  2698. {USB_DEVICE(0x0c45, 0x60c0), BSF(SN9C105, MI0360, F_ILLUM)},
  2699. /* or MT9V111 */
  2700. /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
  2701. /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
  2702. /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
  2703. {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
  2704. {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
  2705. /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
  2706. /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
  2707. /* {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
  2708. {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
  2709. {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
  2710. {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
  2711. {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
  2712. {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)}, /* /GC0305*/
  2713. /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
  2714. {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
  2715. {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
  2716. {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
  2717. {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
  2718. /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
  2719. /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
  2720. /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
  2721. {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
  2722. /*bw600.inf:*/
  2723. {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
  2724. {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
  2725. {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
  2726. {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
  2727. /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
  2728. {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
  2729. /* or MT9V111 / MI0360B */
  2730. /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
  2731. {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
  2732. {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
  2733. {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
  2734. {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
  2735. {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
  2736. {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
  2737. /* or GC0305 / GC0307 */
  2738. {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
  2739. {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
  2740. {USB_DEVICE(0x0c45, 0x614a), BSF(SN9C120, ADCM1700, F_ILLUM)},
  2741. /* {USB_DEVICE(0x0c45, 0x614c), BS(SN9C120, GC0306)}, */ /*sn9c120b*/
  2742. {}
  2743. };
  2744. MODULE_DEVICE_TABLE(usb, device_table);
  2745. /* -- device connect -- */
  2746. static int sd_probe(struct usb_interface *intf,
  2747. const struct usb_device_id *id)
  2748. {
  2749. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2750. THIS_MODULE);
  2751. }
  2752. static struct usb_driver sd_driver = {
  2753. .name = MODULE_NAME,
  2754. .id_table = device_table,
  2755. .probe = sd_probe,
  2756. .disconnect = gspca_disconnect,
  2757. #ifdef CONFIG_PM
  2758. .suspend = gspca_suspend,
  2759. .resume = gspca_resume,
  2760. .reset_resume = gspca_resume,
  2761. #endif
  2762. };
  2763. module_usb_driver(sd_driver);