sonixj.c 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991
  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. * Make sure the buffer is zeroed to avoid uninitialized
  1114. * values.
  1115. */
  1116. memset(gspca_dev->usb_buf, 0, USB_BUF_SZ);
  1117. }
  1118. }
  1119. static void reg_w1(struct gspca_dev *gspca_dev,
  1120. u16 value,
  1121. u8 data)
  1122. {
  1123. int ret;
  1124. if (gspca_dev->usb_err < 0)
  1125. return;
  1126. gspca_dbg(gspca_dev, D_USBO, "reg_w1 [%04x] = %02x\n", value, data);
  1127. gspca_dev->usb_buf[0] = data;
  1128. ret = usb_control_msg(gspca_dev->dev,
  1129. usb_sndctrlpipe(gspca_dev->dev, 0),
  1130. 0x08,
  1131. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1132. value,
  1133. 0,
  1134. gspca_dev->usb_buf, 1,
  1135. 500);
  1136. if (ret < 0) {
  1137. pr_err("reg_w1 err %d\n", ret);
  1138. gspca_dev->usb_err = ret;
  1139. }
  1140. }
  1141. static void reg_w(struct gspca_dev *gspca_dev,
  1142. u16 value,
  1143. const u8 *buffer,
  1144. int len)
  1145. {
  1146. int ret;
  1147. if (gspca_dev->usb_err < 0)
  1148. return;
  1149. gspca_dbg(gspca_dev, D_USBO, "reg_w [%04x] = %02x %02x ..\n",
  1150. value, buffer[0], buffer[1]);
  1151. if (len > USB_BUF_SZ) {
  1152. gspca_err(gspca_dev, "reg_w: buffer overflow\n");
  1153. return;
  1154. }
  1155. memcpy(gspca_dev->usb_buf, buffer, len);
  1156. ret = usb_control_msg(gspca_dev->dev,
  1157. usb_sndctrlpipe(gspca_dev->dev, 0),
  1158. 0x08,
  1159. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1160. value, 0,
  1161. gspca_dev->usb_buf, len,
  1162. 500);
  1163. if (ret < 0) {
  1164. pr_err("reg_w err %d\n", ret);
  1165. gspca_dev->usb_err = ret;
  1166. }
  1167. }
  1168. /* I2C write 1 byte */
  1169. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1170. {
  1171. struct sd *sd = (struct sd *) gspca_dev;
  1172. int ret;
  1173. if (gspca_dev->usb_err < 0)
  1174. return;
  1175. gspca_dbg(gspca_dev, D_USBO, "i2c_w1 [%02x] = %02x\n", reg, val);
  1176. switch (sd->sensor) {
  1177. case SENSOR_ADCM1700:
  1178. case SENSOR_OM6802:
  1179. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1180. gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
  1181. break;
  1182. default: /* i2c command = a1 (400 kHz) */
  1183. gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
  1184. break;
  1185. }
  1186. gspca_dev->usb_buf[1] = sd->i2c_addr;
  1187. gspca_dev->usb_buf[2] = reg;
  1188. gspca_dev->usb_buf[3] = val;
  1189. gspca_dev->usb_buf[4] = 0;
  1190. gspca_dev->usb_buf[5] = 0;
  1191. gspca_dev->usb_buf[6] = 0;
  1192. gspca_dev->usb_buf[7] = 0x10;
  1193. ret = usb_control_msg(gspca_dev->dev,
  1194. usb_sndctrlpipe(gspca_dev->dev, 0),
  1195. 0x08,
  1196. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1197. 0x08, /* value = i2c */
  1198. 0,
  1199. gspca_dev->usb_buf, 8,
  1200. 500);
  1201. msleep(2);
  1202. if (ret < 0) {
  1203. pr_err("i2c_w1 err %d\n", ret);
  1204. gspca_dev->usb_err = ret;
  1205. }
  1206. }
  1207. /* I2C write 8 bytes */
  1208. static void i2c_w8(struct gspca_dev *gspca_dev,
  1209. const u8 *buffer)
  1210. {
  1211. int ret;
  1212. if (gspca_dev->usb_err < 0)
  1213. return;
  1214. gspca_dbg(gspca_dev, D_USBO, "i2c_w8 [%02x] = %02x ..\n",
  1215. buffer[2], buffer[3]);
  1216. memcpy(gspca_dev->usb_buf, buffer, 8);
  1217. ret = usb_control_msg(gspca_dev->dev,
  1218. usb_sndctrlpipe(gspca_dev->dev, 0),
  1219. 0x08,
  1220. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1221. 0x08, 0, /* value, index */
  1222. gspca_dev->usb_buf, 8,
  1223. 500);
  1224. msleep(2);
  1225. if (ret < 0) {
  1226. pr_err("i2c_w8 err %d\n", ret);
  1227. gspca_dev->usb_err = ret;
  1228. }
  1229. }
  1230. /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
  1231. static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
  1232. {
  1233. struct sd *sd = (struct sd *) gspca_dev;
  1234. u8 mode[8];
  1235. switch (sd->sensor) {
  1236. case SENSOR_ADCM1700:
  1237. case SENSOR_OM6802:
  1238. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1239. mode[0] = 0x80 | 0x10;
  1240. break;
  1241. default: /* i2c command = 91 (400 kHz) */
  1242. mode[0] = 0x81 | 0x10;
  1243. break;
  1244. }
  1245. mode[1] = sd->i2c_addr;
  1246. mode[2] = reg;
  1247. mode[3] = 0;
  1248. mode[4] = 0;
  1249. mode[5] = 0;
  1250. mode[6] = 0;
  1251. mode[7] = 0x10;
  1252. i2c_w8(gspca_dev, mode);
  1253. msleep(2);
  1254. mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
  1255. mode[2] = 0;
  1256. i2c_w8(gspca_dev, mode);
  1257. msleep(2);
  1258. reg_r(gspca_dev, 0x0a, 5);
  1259. }
  1260. static void i2c_w_seq(struct gspca_dev *gspca_dev,
  1261. const u8 (*data)[8])
  1262. {
  1263. while ((*data)[0] != 0) {
  1264. if ((*data)[0] != DELAY)
  1265. i2c_w8(gspca_dev, *data);
  1266. else
  1267. msleep((*data)[1]);
  1268. data++;
  1269. }
  1270. }
  1271. /* check the ID of the hv7131 sensor */
  1272. /* this sequence is needed because it activates the sensor */
  1273. static void hv7131r_probe(struct gspca_dev *gspca_dev)
  1274. {
  1275. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  1276. msleep(10);
  1277. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  1278. msleep(10);
  1279. i2c_r(gspca_dev, 0, 5); /* read sensor id */
  1280. if (gspca_dev->usb_buf[0] == 0x02 /* chip ID (02 is R) */
  1281. && gspca_dev->usb_buf[1] == 0x09
  1282. && gspca_dev->usb_buf[2] == 0x01) {
  1283. gspca_dbg(gspca_dev, D_PROBE, "Sensor HV7131R found\n");
  1284. return;
  1285. }
  1286. pr_warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x\n",
  1287. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  1288. gspca_dev->usb_buf[2]);
  1289. }
  1290. static void mi0360_probe(struct gspca_dev *gspca_dev)
  1291. {
  1292. struct sd *sd = (struct sd *) gspca_dev;
  1293. int i, j;
  1294. u16 val = 0;
  1295. static const u8 probe_tb[][4][8] = {
  1296. { /* mi0360 */
  1297. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  1298. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1299. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1300. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1301. },
  1302. { /* mt9v111 */
  1303. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1304. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1305. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1306. {}
  1307. },
  1308. };
  1309. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1310. reg_w1(gspca_dev, 0x17, 0x62);
  1311. reg_w1(gspca_dev, 0x01, 0x08);
  1312. for (j = 0; j < 3; j++)
  1313. i2c_w8(gspca_dev, probe_tb[i][j]);
  1314. msleep(2);
  1315. reg_r(gspca_dev, 0x0a, 5);
  1316. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1317. if (probe_tb[i][3][0] != 0)
  1318. i2c_w8(gspca_dev, probe_tb[i][3]);
  1319. reg_w1(gspca_dev, 0x01, 0x29);
  1320. reg_w1(gspca_dev, 0x17, 0x42);
  1321. if (val != 0xffff)
  1322. break;
  1323. }
  1324. if (gspca_dev->usb_err < 0)
  1325. return;
  1326. switch (val) {
  1327. case 0x8221:
  1328. gspca_dbg(gspca_dev, D_PROBE, "Sensor mi0360b\n");
  1329. sd->sensor = SENSOR_MI0360B;
  1330. break;
  1331. case 0x823a:
  1332. gspca_dbg(gspca_dev, D_PROBE, "Sensor mt9v111\n");
  1333. sd->sensor = SENSOR_MT9V111;
  1334. break;
  1335. case 0x8243:
  1336. gspca_dbg(gspca_dev, D_PROBE, "Sensor mi0360\n");
  1337. break;
  1338. default:
  1339. gspca_dbg(gspca_dev, D_PROBE, "Unknown sensor %04x - forced to mi0360\n",
  1340. val);
  1341. break;
  1342. }
  1343. }
  1344. static void ov7630_probe(struct gspca_dev *gspca_dev)
  1345. {
  1346. struct sd *sd = (struct sd *) gspca_dev;
  1347. u16 val;
  1348. /* check ov76xx */
  1349. reg_w1(gspca_dev, 0x17, 0x62);
  1350. reg_w1(gspca_dev, 0x01, 0x08);
  1351. sd->i2c_addr = 0x21;
  1352. i2c_r(gspca_dev, 0x0a, 2);
  1353. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1354. reg_w1(gspca_dev, 0x01, 0x29);
  1355. reg_w1(gspca_dev, 0x17, 0x42);
  1356. if (gspca_dev->usb_err < 0)
  1357. return;
  1358. if (val == 0x7628) { /* soi768 */
  1359. sd->sensor = SENSOR_SOI768;
  1360. /*fixme: only valid for 0c45:613e?*/
  1361. gspca_dev->cam.input_flags =
  1362. V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  1363. gspca_dbg(gspca_dev, D_PROBE, "Sensor soi768\n");
  1364. return;
  1365. }
  1366. gspca_dbg(gspca_dev, D_PROBE, "Sensor ov%04x\n", val);
  1367. }
  1368. static void ov7648_probe(struct gspca_dev *gspca_dev)
  1369. {
  1370. struct sd *sd = (struct sd *) gspca_dev;
  1371. u16 val;
  1372. /* check ov76xx */
  1373. reg_w1(gspca_dev, 0x17, 0x62);
  1374. reg_w1(gspca_dev, 0x01, 0x08);
  1375. sd->i2c_addr = 0x21;
  1376. i2c_r(gspca_dev, 0x0a, 2);
  1377. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1378. reg_w1(gspca_dev, 0x01, 0x29);
  1379. reg_w1(gspca_dev, 0x17, 0x42);
  1380. if ((val & 0xff00) == 0x7600) { /* ov76xx */
  1381. gspca_dbg(gspca_dev, D_PROBE, "Sensor ov%04x\n", val);
  1382. return;
  1383. }
  1384. /* check po1030 */
  1385. reg_w1(gspca_dev, 0x17, 0x62);
  1386. reg_w1(gspca_dev, 0x01, 0x08);
  1387. sd->i2c_addr = 0x6e;
  1388. i2c_r(gspca_dev, 0x00, 2);
  1389. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1390. reg_w1(gspca_dev, 0x01, 0x29);
  1391. reg_w1(gspca_dev, 0x17, 0x42);
  1392. if (gspca_dev->usb_err < 0)
  1393. return;
  1394. if (val == 0x1030) { /* po1030 */
  1395. gspca_dbg(gspca_dev, D_PROBE, "Sensor po1030\n");
  1396. sd->sensor = SENSOR_PO1030;
  1397. return;
  1398. }
  1399. pr_err("Unknown sensor %04x\n", val);
  1400. }
  1401. /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
  1402. static void po2030n_probe(struct gspca_dev *gspca_dev)
  1403. {
  1404. struct sd *sd = (struct sd *) gspca_dev;
  1405. u16 val;
  1406. /* check gc0307 */
  1407. reg_w1(gspca_dev, 0x17, 0x62);
  1408. reg_w1(gspca_dev, 0x01, 0x08);
  1409. reg_w1(gspca_dev, 0x02, 0x22);
  1410. sd->i2c_addr = 0x21;
  1411. i2c_r(gspca_dev, 0x00, 1);
  1412. val = gspca_dev->usb_buf[4];
  1413. reg_w1(gspca_dev, 0x01, 0x29); /* reset */
  1414. reg_w1(gspca_dev, 0x17, 0x42);
  1415. if (val == 0x99) { /* gc0307 (?) */
  1416. gspca_dbg(gspca_dev, D_PROBE, "Sensor gc0307\n");
  1417. sd->sensor = SENSOR_GC0307;
  1418. return;
  1419. }
  1420. /* check po2030n */
  1421. reg_w1(gspca_dev, 0x17, 0x62);
  1422. reg_w1(gspca_dev, 0x01, 0x0a);
  1423. sd->i2c_addr = 0x6e;
  1424. i2c_r(gspca_dev, 0x00, 2);
  1425. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1426. reg_w1(gspca_dev, 0x01, 0x29);
  1427. reg_w1(gspca_dev, 0x17, 0x42);
  1428. if (gspca_dev->usb_err < 0)
  1429. return;
  1430. if (val == 0x2030) {
  1431. gspca_dbg(gspca_dev, D_PROBE, "Sensor po2030n\n");
  1432. /* sd->sensor = SENSOR_PO2030N; */
  1433. } else {
  1434. pr_err("Unknown sensor ID %04x\n", val);
  1435. }
  1436. }
  1437. /* this function is called at probe time */
  1438. static int sd_config(struct gspca_dev *gspca_dev,
  1439. const struct usb_device_id *id)
  1440. {
  1441. struct sd *sd = (struct sd *) gspca_dev;
  1442. struct cam *cam;
  1443. sd->bridge = id->driver_info >> 16;
  1444. sd->sensor = id->driver_info >> 8;
  1445. sd->flags = id->driver_info;
  1446. cam = &gspca_dev->cam;
  1447. if (sd->sensor == SENSOR_ADCM1700) {
  1448. cam->cam_mode = cif_mode;
  1449. cam->nmodes = ARRAY_SIZE(cif_mode);
  1450. } else {
  1451. cam->cam_mode = vga_mode;
  1452. cam->nmodes = ARRAY_SIZE(vga_mode);
  1453. }
  1454. cam->npkt = 24; /* 24 packets per ISOC message */
  1455. sd->ag_cnt = -1;
  1456. sd->quality = QUALITY_DEF;
  1457. INIT_WORK(&sd->work, qual_upd);
  1458. return 0;
  1459. }
  1460. /* this function is called at probe and resume time */
  1461. static int sd_init(struct gspca_dev *gspca_dev)
  1462. {
  1463. struct sd *sd = (struct sd *) gspca_dev;
  1464. const u8 *sn9c1xx;
  1465. u8 regGpio[] = { 0x29, 0x70 }; /* no audio */
  1466. u8 regF1;
  1467. /* setup a selector by bridge */
  1468. reg_w1(gspca_dev, 0xf1, 0x01);
  1469. reg_r(gspca_dev, 0x00, 1);
  1470. reg_w1(gspca_dev, 0xf1, 0x00);
  1471. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1472. regF1 = gspca_dev->usb_buf[0];
  1473. if (gspca_dev->usb_err < 0)
  1474. return gspca_dev->usb_err;
  1475. gspca_dbg(gspca_dev, D_PROBE, "Sonix chip id: %02x\n", regF1);
  1476. if (gspca_dev->audio)
  1477. regGpio[1] |= 0x04; /* with audio */
  1478. switch (sd->bridge) {
  1479. case BRIDGE_SN9C102P:
  1480. case BRIDGE_SN9C105:
  1481. if (regF1 != 0x11)
  1482. return -ENODEV;
  1483. break;
  1484. default:
  1485. /* case BRIDGE_SN9C110: */
  1486. /* case BRIDGE_SN9C120: */
  1487. if (regF1 != 0x12)
  1488. return -ENODEV;
  1489. }
  1490. switch (sd->sensor) {
  1491. case SENSOR_MI0360:
  1492. mi0360_probe(gspca_dev);
  1493. break;
  1494. case SENSOR_OV7630:
  1495. ov7630_probe(gspca_dev);
  1496. break;
  1497. case SENSOR_OV7648:
  1498. ov7648_probe(gspca_dev);
  1499. break;
  1500. case SENSOR_PO2030N:
  1501. po2030n_probe(gspca_dev);
  1502. break;
  1503. }
  1504. switch (sd->bridge) {
  1505. case BRIDGE_SN9C102P:
  1506. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1507. break;
  1508. default:
  1509. reg_w(gspca_dev, 0x01, regGpio, 2);
  1510. break;
  1511. }
  1512. /* Note we do not disable the sensor clock here (power saving mode),
  1513. as that also disables the button on the cam. */
  1514. reg_w1(gspca_dev, 0xf1, 0x00);
  1515. /* set the i2c address */
  1516. sn9c1xx = sn_tb[sd->sensor];
  1517. sd->i2c_addr = sn9c1xx[9];
  1518. return gspca_dev->usb_err;
  1519. }
  1520. static int sd_s_ctrl(struct v4l2_ctrl *ctrl);
  1521. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  1522. .s_ctrl = sd_s_ctrl,
  1523. };
  1524. /* this function is called at probe time */
  1525. static int sd_init_controls(struct gspca_dev *gspca_dev)
  1526. {
  1527. struct sd *sd = (struct sd *) gspca_dev;
  1528. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  1529. gspca_dev->vdev.ctrl_handler = hdl;
  1530. v4l2_ctrl_handler_init(hdl, 14);
  1531. sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1532. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  1533. #define CONTRAST_MAX 127
  1534. sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1535. V4L2_CID_CONTRAST, 0, CONTRAST_MAX, 1, 20);
  1536. #define COLORS_DEF 25
  1537. sd->saturation = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1538. V4L2_CID_SATURATION, 0, 40, 1, COLORS_DEF);
  1539. sd->red_bal = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1540. V4L2_CID_RED_BALANCE, 24, 40, 1, 32);
  1541. sd->blue_bal = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1542. V4L2_CID_BLUE_BALANCE, 24, 40, 1, 32);
  1543. #define GAMMA_DEF 20
  1544. sd->gamma = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1545. V4L2_CID_GAMMA, 0, 40, 1, GAMMA_DEF);
  1546. if (sd->sensor == SENSOR_OM6802)
  1547. sd->sharpness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1548. V4L2_CID_SHARPNESS, 0, 255, 1, 16);
  1549. else
  1550. sd->sharpness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1551. V4L2_CID_SHARPNESS, 0, 255, 1, 90);
  1552. if (sd->flags & F_ILLUM)
  1553. sd->illum = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1554. V4L2_CID_ILLUMINATORS_1, 0, 1, 1, 0);
  1555. if (sd->sensor == SENSOR_PO2030N) {
  1556. gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1557. V4L2_CID_EXPOSURE, 500, 1500, 1, 1024);
  1558. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1559. V4L2_CID_GAIN, 4, 49, 1, 15);
  1560. sd->hflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1561. V4L2_CID_HFLIP, 0, 1, 1, 0);
  1562. }
  1563. if (sd->sensor != SENSOR_ADCM1700 && sd->sensor != SENSOR_OV7660 &&
  1564. sd->sensor != SENSOR_PO1030 && sd->sensor != SENSOR_SOI768 &&
  1565. sd->sensor != SENSOR_SP80708)
  1566. gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1567. V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
  1568. if (sd->sensor == SENSOR_HV7131R || sd->sensor == SENSOR_OV7630 ||
  1569. sd->sensor == SENSOR_OV7648 || sd->sensor == SENSOR_PO2030N)
  1570. sd->vflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1571. V4L2_CID_VFLIP, 0, 1, 1, 0);
  1572. if (sd->sensor == SENSOR_OV7630 || sd->sensor == SENSOR_OV7648 ||
  1573. sd->sensor == SENSOR_OV7660)
  1574. sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
  1575. V4L2_CID_POWER_LINE_FREQUENCY,
  1576. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
  1577. V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
  1578. if (hdl->error) {
  1579. pr_err("Could not initialize controls\n");
  1580. return hdl->error;
  1581. }
  1582. v4l2_ctrl_cluster(2, &sd->red_bal);
  1583. if (sd->sensor == SENSOR_PO2030N) {
  1584. v4l2_ctrl_cluster(2, &sd->vflip);
  1585. v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
  1586. }
  1587. return 0;
  1588. }
  1589. static u32 expo_adjust(struct gspca_dev *gspca_dev,
  1590. u32 expo)
  1591. {
  1592. struct sd *sd = (struct sd *) gspca_dev;
  1593. switch (sd->sensor) {
  1594. case SENSOR_GC0307: {
  1595. int a, b;
  1596. /* expo = 0..255 -> a = 19..43 */
  1597. a = 19 + expo * 25 / 256;
  1598. i2c_w1(gspca_dev, 0x68, a);
  1599. a -= 12;
  1600. b = a * a * 4; /* heuristic */
  1601. i2c_w1(gspca_dev, 0x03, b >> 8);
  1602. i2c_w1(gspca_dev, 0x04, b);
  1603. break;
  1604. }
  1605. case SENSOR_HV7131R: {
  1606. u8 Expodoit[] =
  1607. { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1608. Expodoit[3] = expo >> 16;
  1609. Expodoit[4] = expo >> 8;
  1610. Expodoit[5] = expo;
  1611. i2c_w8(gspca_dev, Expodoit);
  1612. break;
  1613. }
  1614. case SENSOR_MI0360:
  1615. case SENSOR_MI0360B: {
  1616. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1617. { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1618. static const u8 doit[] = /* update sensor */
  1619. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1620. static const u8 sensorgo[] = /* sensor on */
  1621. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1622. if (expo > 0x0635)
  1623. expo = 0x0635;
  1624. else if (expo < 0x0001)
  1625. expo = 0x0001;
  1626. expoMi[3] = expo >> 8;
  1627. expoMi[4] = expo;
  1628. i2c_w8(gspca_dev, expoMi);
  1629. i2c_w8(gspca_dev, doit);
  1630. i2c_w8(gspca_dev, sensorgo);
  1631. break;
  1632. }
  1633. case SENSOR_MO4000: {
  1634. u8 expoMof[] =
  1635. { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1636. u8 expoMo10[] =
  1637. { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1638. static const u8 gainMo[] =
  1639. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1640. if (expo > 0x1fff)
  1641. expo = 0x1fff;
  1642. else if (expo < 0x0001)
  1643. expo = 0x0001;
  1644. expoMof[3] = (expo & 0x03fc) >> 2;
  1645. i2c_w8(gspca_dev, expoMof);
  1646. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1647. | ((expo & 0x0003) << 4);
  1648. i2c_w8(gspca_dev, expoMo10);
  1649. i2c_w8(gspca_dev, gainMo);
  1650. gspca_dbg(gspca_dev, D_FRAM, "set exposure %d\n",
  1651. ((expoMo10[3] & 0x07) << 10)
  1652. | (expoMof[3] << 2)
  1653. | ((expoMo10[3] & 0x30) >> 4));
  1654. break;
  1655. }
  1656. case SENSOR_MT9V111: {
  1657. u8 expo_c1[] =
  1658. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1659. if (expo > 0x0390)
  1660. expo = 0x0390;
  1661. else if (expo < 0x0060)
  1662. expo = 0x0060;
  1663. expo_c1[3] = expo >> 8;
  1664. expo_c1[4] = expo;
  1665. i2c_w8(gspca_dev, expo_c1);
  1666. break;
  1667. }
  1668. case SENSOR_OM6802: {
  1669. u8 gainOm[] =
  1670. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1671. /* preset AGC - works when AutoExpo = off */
  1672. if (expo > 0x03ff)
  1673. expo = 0x03ff;
  1674. if (expo < 0x0001)
  1675. expo = 0x0001;
  1676. gainOm[3] = expo >> 2;
  1677. i2c_w8(gspca_dev, gainOm);
  1678. reg_w1(gspca_dev, 0x96, expo >> 5);
  1679. gspca_dbg(gspca_dev, D_FRAM, "set exposure %d\n", gainOm[3]);
  1680. break;
  1681. }
  1682. }
  1683. return expo;
  1684. }
  1685. static void setbrightness(struct gspca_dev *gspca_dev)
  1686. {
  1687. struct sd *sd = (struct sd *) gspca_dev;
  1688. unsigned int expo;
  1689. int brightness = sd->brightness->val;
  1690. u8 k2;
  1691. k2 = (brightness - 0x80) >> 2;
  1692. switch (sd->sensor) {
  1693. case SENSOR_ADCM1700:
  1694. if (k2 > 0x1f)
  1695. k2 = 0; /* only positive Y offset */
  1696. break;
  1697. case SENSOR_HV7131R:
  1698. expo = brightness << 12;
  1699. if (expo > 0x002dc6c0)
  1700. expo = 0x002dc6c0;
  1701. else if (expo < 0x02a0)
  1702. expo = 0x02a0;
  1703. sd->exposure = expo_adjust(gspca_dev, expo);
  1704. break;
  1705. case SENSOR_MI0360:
  1706. case SENSOR_MO4000:
  1707. expo = brightness << 4;
  1708. sd->exposure = expo_adjust(gspca_dev, expo);
  1709. break;
  1710. case SENSOR_MI0360B:
  1711. expo = brightness << 2;
  1712. sd->exposure = expo_adjust(gspca_dev, expo);
  1713. break;
  1714. case SENSOR_GC0307:
  1715. expo = brightness;
  1716. sd->exposure = expo_adjust(gspca_dev, expo);
  1717. return; /* don't set the Y offset */
  1718. case SENSOR_MT9V111:
  1719. expo = brightness << 2;
  1720. sd->exposure = expo_adjust(gspca_dev, expo);
  1721. return; /* don't set the Y offset */
  1722. case SENSOR_OM6802:
  1723. expo = brightness << 2;
  1724. sd->exposure = expo_adjust(gspca_dev, expo);
  1725. return; /* Y offset already set */
  1726. }
  1727. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  1728. }
  1729. static void setcontrast(struct gspca_dev *gspca_dev)
  1730. {
  1731. struct sd *sd = (struct sd *) gspca_dev;
  1732. u8 k2;
  1733. u8 contrast[6];
  1734. k2 = sd->contrast->val * 37 / (CONTRAST_MAX + 1)
  1735. + 37; /* 37..73 */
  1736. contrast[0] = (k2 + 1) / 2; /* red */
  1737. contrast[1] = 0;
  1738. contrast[2] = k2; /* green */
  1739. contrast[3] = 0;
  1740. contrast[4] = k2 / 5; /* blue */
  1741. contrast[5] = 0;
  1742. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  1743. }
  1744. static void setcolors(struct gspca_dev *gspca_dev)
  1745. {
  1746. struct sd *sd = (struct sd *) gspca_dev;
  1747. int i, v, colors;
  1748. const s16 *uv;
  1749. u8 reg8a[12]; /* U & V gains */
  1750. static const s16 uv_com[6] = { /* same as reg84 in signed decimal */
  1751. -24, -38, 64, /* UR UG UB */
  1752. 62, -51, -9 /* VR VG VB */
  1753. };
  1754. static const s16 uv_mi0360b[6] = {
  1755. -20, -38, 64, /* UR UG UB */
  1756. 60, -51, -9 /* VR VG VB */
  1757. };
  1758. colors = sd->saturation->val;
  1759. if (sd->sensor == SENSOR_MI0360B)
  1760. uv = uv_mi0360b;
  1761. else
  1762. uv = uv_com;
  1763. for (i = 0; i < 6; i++) {
  1764. v = uv[i] * colors / COLORS_DEF;
  1765. reg8a[i * 2] = v;
  1766. reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
  1767. }
  1768. reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
  1769. }
  1770. static void setredblue(struct gspca_dev *gspca_dev)
  1771. {
  1772. struct sd *sd = (struct sd *) gspca_dev;
  1773. if (sd->sensor == SENSOR_PO2030N) {
  1774. u8 rg1b[] = /* red green1 blue (no g2) */
  1775. {0xc1, 0x6e, 0x16, 0x00, 0x40, 0x00, 0x00, 0x10};
  1776. /* 0x40 = normal value = gain x 1 */
  1777. rg1b[3] = sd->red_bal->val * 2;
  1778. rg1b[5] = sd->blue_bal->val * 2;
  1779. i2c_w8(gspca_dev, rg1b);
  1780. return;
  1781. }
  1782. reg_w1(gspca_dev, 0x05, sd->red_bal->val);
  1783. /* reg_w1(gspca_dev, 0x07, 32); */
  1784. reg_w1(gspca_dev, 0x06, sd->blue_bal->val);
  1785. }
  1786. static void setgamma(struct gspca_dev *gspca_dev)
  1787. {
  1788. struct sd *sd = (struct sd *) gspca_dev;
  1789. int i, val;
  1790. u8 gamma[17];
  1791. const u8 *gamma_base;
  1792. static const u8 delta[17] = {
  1793. 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
  1794. 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
  1795. };
  1796. switch (sd->sensor) {
  1797. case SENSOR_ADCM1700:
  1798. gamma_base = gamma_spec_0;
  1799. break;
  1800. case SENSOR_HV7131R:
  1801. case SENSOR_MI0360B:
  1802. case SENSOR_MT9V111:
  1803. gamma_base = gamma_spec_1;
  1804. break;
  1805. case SENSOR_GC0307:
  1806. gamma_base = gamma_spec_2;
  1807. break;
  1808. case SENSOR_SP80708:
  1809. gamma_base = gamma_spec_3;
  1810. break;
  1811. default:
  1812. gamma_base = gamma_def;
  1813. break;
  1814. }
  1815. val = sd->gamma->val;
  1816. for (i = 0; i < sizeof gamma; i++)
  1817. gamma[i] = gamma_base[i]
  1818. + delta[i] * (val - GAMMA_DEF) / 32;
  1819. reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
  1820. }
  1821. static void setexposure(struct gspca_dev *gspca_dev)
  1822. {
  1823. struct sd *sd = (struct sd *) gspca_dev;
  1824. if (sd->sensor == SENSOR_PO2030N) {
  1825. u8 rexpo[] = /* 1a: expo H, 1b: expo M */
  1826. {0xa1, 0x6e, 0x1a, 0x00, 0x40, 0x00, 0x00, 0x10};
  1827. rexpo[3] = gspca_dev->exposure->val >> 8;
  1828. i2c_w8(gspca_dev, rexpo);
  1829. msleep(6);
  1830. rexpo[2] = 0x1b;
  1831. rexpo[3] = gspca_dev->exposure->val;
  1832. i2c_w8(gspca_dev, rexpo);
  1833. }
  1834. }
  1835. static void setautogain(struct gspca_dev *gspca_dev)
  1836. {
  1837. struct sd *sd = (struct sd *) gspca_dev;
  1838. switch (sd->sensor) {
  1839. case SENSOR_OV7630:
  1840. case SENSOR_OV7648: {
  1841. u8 comb;
  1842. if (sd->sensor == SENSOR_OV7630)
  1843. comb = 0xc0;
  1844. else
  1845. comb = 0xa0;
  1846. if (gspca_dev->autogain->val)
  1847. comb |= 0x03;
  1848. i2c_w1(&sd->gspca_dev, 0x13, comb);
  1849. return;
  1850. }
  1851. }
  1852. if (gspca_dev->autogain->val)
  1853. sd->ag_cnt = AG_CNT_START;
  1854. else
  1855. sd->ag_cnt = -1;
  1856. }
  1857. static void setgain(struct gspca_dev *gspca_dev)
  1858. {
  1859. struct sd *sd = (struct sd *) gspca_dev;
  1860. if (sd->sensor == SENSOR_PO2030N) {
  1861. u8 rgain[] = /* 15: gain */
  1862. {0xa1, 0x6e, 0x15, 0x00, 0x40, 0x00, 0x00, 0x15};
  1863. rgain[3] = gspca_dev->gain->val;
  1864. i2c_w8(gspca_dev, rgain);
  1865. }
  1866. }
  1867. static void sethvflip(struct gspca_dev *gspca_dev)
  1868. {
  1869. struct sd *sd = (struct sd *) gspca_dev;
  1870. u8 comn;
  1871. switch (sd->sensor) {
  1872. case SENSOR_HV7131R:
  1873. comn = 0x18; /* clkdiv = 1, ablcen = 1 */
  1874. if (sd->vflip->val)
  1875. comn |= 0x01;
  1876. i2c_w1(gspca_dev, 0x01, comn); /* sctra */
  1877. break;
  1878. case SENSOR_OV7630:
  1879. comn = 0x02;
  1880. if (!sd->vflip->val)
  1881. comn |= 0x80;
  1882. i2c_w1(gspca_dev, 0x75, comn);
  1883. break;
  1884. case SENSOR_OV7648:
  1885. comn = 0x06;
  1886. if (sd->vflip->val)
  1887. comn |= 0x80;
  1888. i2c_w1(gspca_dev, 0x75, comn);
  1889. break;
  1890. case SENSOR_PO2030N:
  1891. /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
  1892. * (reset value: 0x0A)
  1893. * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
  1894. * bit6: VM: Vertical Mirror: 0: disable, 1: enable
  1895. * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
  1896. * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
  1897. * bit3-0: X
  1898. */
  1899. comn = 0x0a;
  1900. if (sd->hflip->val)
  1901. comn |= 0x80;
  1902. if (sd->vflip->val)
  1903. comn |= 0x40;
  1904. i2c_w1(&sd->gspca_dev, 0x1e, comn);
  1905. break;
  1906. }
  1907. }
  1908. static void setsharpness(struct gspca_dev *gspca_dev)
  1909. {
  1910. struct sd *sd = (struct sd *) gspca_dev;
  1911. reg_w1(gspca_dev, 0x99, sd->sharpness->val);
  1912. }
  1913. static void setillum(struct gspca_dev *gspca_dev)
  1914. {
  1915. struct sd *sd = (struct sd *) gspca_dev;
  1916. switch (sd->sensor) {
  1917. case SENSOR_ADCM1700:
  1918. reg_w1(gspca_dev, 0x02, /* gpio */
  1919. sd->illum->val ? 0x64 : 0x60);
  1920. break;
  1921. case SENSOR_MT9V111:
  1922. reg_w1(gspca_dev, 0x02,
  1923. sd->illum->val ? 0x77 : 0x74);
  1924. /* should have been: */
  1925. /* 0x55 : 0x54); * 370i */
  1926. /* 0x66 : 0x64); * Clip */
  1927. break;
  1928. }
  1929. }
  1930. static void setfreq(struct gspca_dev *gspca_dev)
  1931. {
  1932. struct sd *sd = (struct sd *) gspca_dev;
  1933. if (sd->sensor == SENSOR_OV7660) {
  1934. u8 com8;
  1935. com8 = 0xdf; /* auto gain/wb/expo */
  1936. switch (sd->freq->val) {
  1937. case 0: /* Banding filter disabled */
  1938. i2c_w1(gspca_dev, 0x13, com8 | 0x20);
  1939. break;
  1940. case 1: /* 50 hz */
  1941. i2c_w1(gspca_dev, 0x13, com8);
  1942. i2c_w1(gspca_dev, 0x3b, 0x0a);
  1943. break;
  1944. case 2: /* 60 hz */
  1945. i2c_w1(gspca_dev, 0x13, com8);
  1946. i2c_w1(gspca_dev, 0x3b, 0x02);
  1947. break;
  1948. }
  1949. } else {
  1950. u8 reg2a = 0, reg2b = 0, reg2d = 0;
  1951. /* Get reg2a / reg2d base values */
  1952. switch (sd->sensor) {
  1953. case SENSOR_OV7630:
  1954. reg2a = 0x08;
  1955. reg2d = 0x01;
  1956. break;
  1957. case SENSOR_OV7648:
  1958. reg2a = 0x11;
  1959. reg2d = 0x81;
  1960. break;
  1961. }
  1962. switch (sd->freq->val) {
  1963. case 0: /* Banding filter disabled */
  1964. break;
  1965. case 1: /* 50 hz (filter on and framerate adj) */
  1966. reg2a |= 0x80;
  1967. reg2b = 0xac;
  1968. reg2d |= 0x04;
  1969. break;
  1970. case 2: /* 60 hz (filter on, no framerate adj) */
  1971. reg2a |= 0x80;
  1972. reg2d |= 0x04;
  1973. break;
  1974. }
  1975. i2c_w1(gspca_dev, 0x2a, reg2a);
  1976. i2c_w1(gspca_dev, 0x2b, reg2b);
  1977. i2c_w1(gspca_dev, 0x2d, reg2d);
  1978. }
  1979. }
  1980. static void setjpegqual(struct gspca_dev *gspca_dev)
  1981. {
  1982. struct sd *sd = (struct sd *) gspca_dev;
  1983. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  1984. #if USB_BUF_SZ < 64
  1985. #error "No room enough in usb_buf for quantization table"
  1986. #endif
  1987. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
  1988. usb_control_msg(gspca_dev->dev,
  1989. usb_sndctrlpipe(gspca_dev->dev, 0),
  1990. 0x08,
  1991. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1992. 0x0100, 0,
  1993. gspca_dev->usb_buf, 64,
  1994. 500);
  1995. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
  1996. usb_control_msg(gspca_dev->dev,
  1997. usb_sndctrlpipe(gspca_dev->dev, 0),
  1998. 0x08,
  1999. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2000. 0x0140, 0,
  2001. gspca_dev->usb_buf, 64,
  2002. 500);
  2003. sd->reg18 ^= 0x40;
  2004. reg_w1(gspca_dev, 0x18, sd->reg18);
  2005. }
  2006. /* JPEG quality update */
  2007. /* This function is executed from a work queue. */
  2008. static void qual_upd(struct work_struct *work)
  2009. {
  2010. struct sd *sd = container_of(work, struct sd, work);
  2011. struct gspca_dev *gspca_dev = &sd->gspca_dev;
  2012. /* To protect gspca_dev->usb_buf and gspca_dev->usb_err */
  2013. mutex_lock(&gspca_dev->usb_lock);
  2014. gspca_dbg(gspca_dev, D_STREAM, "qual_upd %d%%\n", sd->quality);
  2015. gspca_dev->usb_err = 0;
  2016. setjpegqual(gspca_dev);
  2017. mutex_unlock(&gspca_dev->usb_lock);
  2018. }
  2019. /* -- start the camera -- */
  2020. static int sd_start(struct gspca_dev *gspca_dev)
  2021. {
  2022. struct sd *sd = (struct sd *) gspca_dev;
  2023. int i;
  2024. u8 reg01, reg17;
  2025. u8 reg0102[2];
  2026. const u8 *sn9c1xx;
  2027. const u8 (*init)[8];
  2028. const u8 *reg9a;
  2029. int mode;
  2030. static const u8 reg9a_def[] =
  2031. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  2032. static const u8 reg9a_spec[] =
  2033. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  2034. static const u8 regd4[] = {0x60, 0x00, 0x00};
  2035. static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  2036. static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  2037. static const u8 CA_adcm1700[] =
  2038. { 0x14, 0xec, 0x0a, 0xf6 };
  2039. static const u8 CA_po2030n[] =
  2040. { 0x1e, 0xe2, 0x14, 0xec };
  2041. static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  2042. static const u8 CE_gc0307[] =
  2043. { 0x32, 0xce, 0x2d, 0xd3 };
  2044. static const u8 CE_ov76xx[] =
  2045. { 0x32, 0xdd, 0x32, 0xdd };
  2046. static const u8 CE_po2030n[] =
  2047. { 0x14, 0xe7, 0x1e, 0xdd };
  2048. /* create the JPEG header */
  2049. jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
  2050. gspca_dev->pixfmt.width,
  2051. 0x21); /* JPEG 422 */
  2052. /* initialize the bridge */
  2053. sn9c1xx = sn_tb[sd->sensor];
  2054. /* sensor clock already enabled in sd_init */
  2055. /* reg_w1(gspca_dev, 0xf1, 0x00); */
  2056. reg01 = sn9c1xx[1];
  2057. if (sd->flags & F_PDN_INV)
  2058. reg01 ^= S_PDN_INV; /* power down inverted */
  2059. reg_w1(gspca_dev, 0x01, reg01);
  2060. /* configure gpio */
  2061. reg0102[0] = reg01;
  2062. reg0102[1] = sn9c1xx[2];
  2063. if (gspca_dev->audio)
  2064. reg0102[1] |= 0x04; /* keep the audio connection */
  2065. reg_w(gspca_dev, 0x01, reg0102, 2);
  2066. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  2067. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
  2068. switch (sd->sensor) {
  2069. case SENSOR_GC0307:
  2070. case SENSOR_OV7660:
  2071. case SENSOR_PO1030:
  2072. case SENSOR_PO2030N:
  2073. case SENSOR_SOI768:
  2074. case SENSOR_SP80708:
  2075. reg9a = reg9a_spec;
  2076. break;
  2077. default:
  2078. reg9a = reg9a_def;
  2079. break;
  2080. }
  2081. reg_w(gspca_dev, 0x9a, reg9a, 6);
  2082. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
  2083. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  2084. reg17 = sn9c1xx[0x17];
  2085. switch (sd->sensor) {
  2086. case SENSOR_GC0307:
  2087. msleep(50); /*fixme: is it useful? */
  2088. break;
  2089. case SENSOR_OM6802:
  2090. msleep(10);
  2091. reg_w1(gspca_dev, 0x02, 0x73);
  2092. reg17 |= SEN_CLK_EN;
  2093. reg_w1(gspca_dev, 0x17, reg17);
  2094. reg_w1(gspca_dev, 0x01, 0x22);
  2095. msleep(100);
  2096. reg01 = SCL_SEL_OD | S_PDN_INV;
  2097. reg17 &= ~MCK_SIZE_MASK;
  2098. reg17 |= 0x04; /* clock / 4 */
  2099. break;
  2100. }
  2101. reg01 |= SYS_SEL_48M;
  2102. reg_w1(gspca_dev, 0x01, reg01);
  2103. reg17 |= SEN_CLK_EN;
  2104. reg_w1(gspca_dev, 0x17, reg17);
  2105. reg01 &= ~S_PWR_DN; /* sensor power on */
  2106. reg_w1(gspca_dev, 0x01, reg01);
  2107. reg01 &= ~SCL_SEL_OD; /* remove open-drain mode */
  2108. reg_w1(gspca_dev, 0x01, reg01);
  2109. switch (sd->sensor) {
  2110. case SENSOR_HV7131R:
  2111. hv7131r_probe(gspca_dev); /*fixme: is it useful? */
  2112. break;
  2113. case SENSOR_OM6802:
  2114. msleep(10);
  2115. reg_w1(gspca_dev, 0x01, reg01);
  2116. i2c_w8(gspca_dev, om6802_init0[0]);
  2117. i2c_w8(gspca_dev, om6802_init0[1]);
  2118. msleep(15);
  2119. reg_w1(gspca_dev, 0x02, 0x71);
  2120. msleep(150);
  2121. break;
  2122. case SENSOR_SP80708:
  2123. msleep(100);
  2124. reg_w1(gspca_dev, 0x02, 0x62);
  2125. break;
  2126. }
  2127. /* initialize the sensor */
  2128. i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
  2129. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  2130. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  2131. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  2132. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  2133. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2134. if (sd->sensor == SENSOR_ADCM1700) {
  2135. reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
  2136. reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
  2137. } else {
  2138. reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
  2139. reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
  2140. }
  2141. reg_w1(gspca_dev, 0xc6, 0x00);
  2142. reg_w1(gspca_dev, 0xc7, 0x00);
  2143. if (sd->sensor == SENSOR_ADCM1700) {
  2144. reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
  2145. reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
  2146. } else {
  2147. reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
  2148. reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
  2149. }
  2150. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2151. switch (sd->sensor) {
  2152. case SENSOR_OM6802:
  2153. /* case SENSOR_OV7648: * fixme: sometimes */
  2154. break;
  2155. default:
  2156. reg17 |= DEF_EN;
  2157. break;
  2158. }
  2159. reg_w1(gspca_dev, 0x17, reg17);
  2160. reg_w1(gspca_dev, 0x05, 0x00); /* red */
  2161. reg_w1(gspca_dev, 0x07, 0x00); /* green */
  2162. reg_w1(gspca_dev, 0x06, 0x00); /* blue */
  2163. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  2164. setgamma(gspca_dev);
  2165. /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
  2166. for (i = 0; i < 8; i++)
  2167. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2168. switch (sd->sensor) {
  2169. case SENSOR_ADCM1700:
  2170. case SENSOR_OV7660:
  2171. case SENSOR_SP80708:
  2172. reg_w1(gspca_dev, 0x9a, 0x05);
  2173. break;
  2174. case SENSOR_GC0307:
  2175. case SENSOR_MT9V111:
  2176. case SENSOR_MI0360B:
  2177. reg_w1(gspca_dev, 0x9a, 0x07);
  2178. break;
  2179. case SENSOR_OV7630:
  2180. case SENSOR_OV7648:
  2181. reg_w1(gspca_dev, 0x9a, 0x0a);
  2182. break;
  2183. case SENSOR_PO2030N:
  2184. case SENSOR_SOI768:
  2185. reg_w1(gspca_dev, 0x9a, 0x06);
  2186. break;
  2187. default:
  2188. reg_w1(gspca_dev, 0x9a, 0x08);
  2189. break;
  2190. }
  2191. setsharpness(gspca_dev);
  2192. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2193. reg_w1(gspca_dev, 0x05, 0x20); /* red */
  2194. reg_w1(gspca_dev, 0x07, 0x20); /* green */
  2195. reg_w1(gspca_dev, 0x06, 0x20); /* blue */
  2196. init = NULL;
  2197. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  2198. reg01 |= SYS_SEL_48M | V_TX_EN;
  2199. reg17 &= ~MCK_SIZE_MASK;
  2200. reg17 |= 0x02; /* clock / 2 */
  2201. switch (sd->sensor) {
  2202. case SENSOR_ADCM1700:
  2203. init = adcm1700_sensor_param1;
  2204. break;
  2205. case SENSOR_GC0307:
  2206. init = gc0307_sensor_param1;
  2207. break;
  2208. case SENSOR_HV7131R:
  2209. case SENSOR_MI0360:
  2210. if (!mode)
  2211. reg01 &= ~SYS_SEL_48M; /* 640x480: clk 24Mhz */
  2212. reg17 &= ~MCK_SIZE_MASK;
  2213. reg17 |= 0x01; /* clock / 1 */
  2214. break;
  2215. case SENSOR_MI0360B:
  2216. init = mi0360b_sensor_param1;
  2217. break;
  2218. case SENSOR_MO4000:
  2219. if (mode) { /* if 320x240 */
  2220. reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
  2221. reg17 &= ~MCK_SIZE_MASK;
  2222. reg17 |= 0x01; /* clock / 1 */
  2223. }
  2224. break;
  2225. case SENSOR_MT9V111:
  2226. init = mt9v111_sensor_param1;
  2227. break;
  2228. case SENSOR_OM6802:
  2229. init = om6802_sensor_param1;
  2230. if (!mode) { /* if 640x480 */
  2231. reg17 &= ~MCK_SIZE_MASK;
  2232. reg17 |= 0x04; /* clock / 4 */
  2233. } else {
  2234. reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
  2235. reg17 &= ~MCK_SIZE_MASK;
  2236. reg17 |= 0x02; /* clock / 2 */
  2237. }
  2238. break;
  2239. case SENSOR_OV7630:
  2240. init = ov7630_sensor_param1;
  2241. break;
  2242. case SENSOR_OV7648:
  2243. init = ov7648_sensor_param1;
  2244. reg17 &= ~MCK_SIZE_MASK;
  2245. reg17 |= 0x01; /* clock / 1 */
  2246. break;
  2247. case SENSOR_OV7660:
  2248. init = ov7660_sensor_param1;
  2249. break;
  2250. case SENSOR_PO1030:
  2251. init = po1030_sensor_param1;
  2252. break;
  2253. case SENSOR_PO2030N:
  2254. init = po2030n_sensor_param1;
  2255. break;
  2256. case SENSOR_SOI768:
  2257. init = soi768_sensor_param1;
  2258. break;
  2259. case SENSOR_SP80708:
  2260. init = sp80708_sensor_param1;
  2261. break;
  2262. }
  2263. /* more sensor initialization - param1 */
  2264. if (init != NULL) {
  2265. i2c_w_seq(gspca_dev, init);
  2266. /* init = NULL; */
  2267. }
  2268. reg_w(gspca_dev, 0xc0, C0, 6);
  2269. switch (sd->sensor) {
  2270. case SENSOR_ADCM1700:
  2271. case SENSOR_GC0307:
  2272. case SENSOR_SOI768:
  2273. reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
  2274. break;
  2275. case SENSOR_PO2030N:
  2276. reg_w(gspca_dev, 0xca, CA_po2030n, 4);
  2277. break;
  2278. default:
  2279. reg_w(gspca_dev, 0xca, CA, 4);
  2280. break;
  2281. }
  2282. switch (sd->sensor) {
  2283. case SENSOR_ADCM1700:
  2284. case SENSOR_OV7630:
  2285. case SENSOR_OV7648:
  2286. case SENSOR_OV7660:
  2287. case SENSOR_SOI768:
  2288. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  2289. break;
  2290. case SENSOR_GC0307:
  2291. reg_w(gspca_dev, 0xce, CE_gc0307, 4);
  2292. break;
  2293. case SENSOR_PO2030N:
  2294. reg_w(gspca_dev, 0xce, CE_po2030n, 4);
  2295. break;
  2296. default:
  2297. reg_w(gspca_dev, 0xce, CE, 4);
  2298. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  2299. break;
  2300. }
  2301. /* here change size mode 0 -> VGA; 1 -> CIF */
  2302. sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
  2303. reg_w1(gspca_dev, 0x18, sd->reg18);
  2304. setjpegqual(gspca_dev);
  2305. reg_w1(gspca_dev, 0x17, reg17);
  2306. reg_w1(gspca_dev, 0x01, reg01);
  2307. sd->reg01 = reg01;
  2308. sd->reg17 = reg17;
  2309. sd->pktsz = sd->npkt = 0;
  2310. sd->nchg = sd->short_mark = 0;
  2311. return gspca_dev->usb_err;
  2312. }
  2313. static void sd_stopN(struct gspca_dev *gspca_dev)
  2314. {
  2315. struct sd *sd = (struct sd *) gspca_dev;
  2316. static const u8 stophv7131[] =
  2317. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  2318. static const u8 stopmi0360[] =
  2319. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  2320. static const u8 stopov7648[] =
  2321. { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
  2322. static const u8 stopsoi768[] =
  2323. { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
  2324. u8 reg01;
  2325. u8 reg17;
  2326. reg01 = sd->reg01;
  2327. reg17 = sd->reg17 & ~SEN_CLK_EN;
  2328. switch (sd->sensor) {
  2329. case SENSOR_ADCM1700:
  2330. case SENSOR_GC0307:
  2331. case SENSOR_PO2030N:
  2332. case SENSOR_SP80708:
  2333. reg01 |= LED;
  2334. reg_w1(gspca_dev, 0x01, reg01);
  2335. reg01 &= ~(LED | V_TX_EN);
  2336. reg_w1(gspca_dev, 0x01, reg01);
  2337. /* reg_w1(gspca_dev, 0x02, 0x??); * LED off ? */
  2338. break;
  2339. case SENSOR_HV7131R:
  2340. reg01 &= ~V_TX_EN;
  2341. reg_w1(gspca_dev, 0x01, reg01);
  2342. i2c_w8(gspca_dev, stophv7131);
  2343. break;
  2344. case SENSOR_MI0360:
  2345. case SENSOR_MI0360B:
  2346. reg01 &= ~V_TX_EN;
  2347. reg_w1(gspca_dev, 0x01, reg01);
  2348. /* reg_w1(gspca_dev, 0x02, 0x40); * LED off ? */
  2349. i2c_w8(gspca_dev, stopmi0360);
  2350. break;
  2351. case SENSOR_MT9V111:
  2352. case SENSOR_OM6802:
  2353. case SENSOR_PO1030:
  2354. reg01 &= ~V_TX_EN;
  2355. reg_w1(gspca_dev, 0x01, reg01);
  2356. break;
  2357. case SENSOR_OV7630:
  2358. case SENSOR_OV7648:
  2359. reg01 &= ~V_TX_EN;
  2360. reg_w1(gspca_dev, 0x01, reg01);
  2361. i2c_w8(gspca_dev, stopov7648);
  2362. break;
  2363. case SENSOR_OV7660:
  2364. reg01 &= ~V_TX_EN;
  2365. reg_w1(gspca_dev, 0x01, reg01);
  2366. break;
  2367. case SENSOR_SOI768:
  2368. i2c_w8(gspca_dev, stopsoi768);
  2369. break;
  2370. }
  2371. reg01 |= SCL_SEL_OD;
  2372. reg_w1(gspca_dev, 0x01, reg01);
  2373. reg01 |= S_PWR_DN; /* sensor power down */
  2374. reg_w1(gspca_dev, 0x01, reg01);
  2375. reg_w1(gspca_dev, 0x17, reg17);
  2376. reg01 &= ~SYS_SEL_48M; /* clock 24MHz */
  2377. reg_w1(gspca_dev, 0x01, reg01);
  2378. reg01 |= LED;
  2379. reg_w1(gspca_dev, 0x01, reg01);
  2380. /* Don't disable sensor clock as that disables the button on the cam */
  2381. /* reg_w1(gspca_dev, 0xf1, 0x01); */
  2382. }
  2383. /* called on streamoff with alt==0 and on disconnect */
  2384. /* the usb_lock is held at entry - restore on exit */
  2385. static void sd_stop0(struct gspca_dev *gspca_dev)
  2386. {
  2387. struct sd *sd = (struct sd *) gspca_dev;
  2388. mutex_unlock(&gspca_dev->usb_lock);
  2389. flush_work(&sd->work);
  2390. mutex_lock(&gspca_dev->usb_lock);
  2391. }
  2392. static void do_autogain(struct gspca_dev *gspca_dev)
  2393. {
  2394. struct sd *sd = (struct sd *) gspca_dev;
  2395. int delta;
  2396. int expotimes;
  2397. u8 luma_mean = 130;
  2398. u8 luma_delta = 20;
  2399. /* Thanks S., without your advice, autobright should not work :) */
  2400. if (sd->ag_cnt < 0)
  2401. return;
  2402. if (--sd->ag_cnt >= 0)
  2403. return;
  2404. sd->ag_cnt = AG_CNT_START;
  2405. delta = atomic_read(&sd->avg_lum);
  2406. gspca_dbg(gspca_dev, D_FRAM, "mean lum %d\n", delta);
  2407. if (sd->sensor == SENSOR_PO2030N) {
  2408. gspca_expo_autogain(gspca_dev, delta, luma_mean, luma_delta,
  2409. 15, 1024);
  2410. return;
  2411. }
  2412. if (delta < luma_mean - luma_delta ||
  2413. delta > luma_mean + luma_delta) {
  2414. switch (sd->sensor) {
  2415. case SENSOR_GC0307:
  2416. expotimes = sd->exposure;
  2417. expotimes += (luma_mean - delta) >> 6;
  2418. if (expotimes < 0)
  2419. expotimes = 0;
  2420. sd->exposure = expo_adjust(gspca_dev,
  2421. (unsigned int) expotimes);
  2422. break;
  2423. case SENSOR_HV7131R:
  2424. expotimes = sd->exposure >> 8;
  2425. expotimes += (luma_mean - delta) >> 4;
  2426. if (expotimes < 0)
  2427. expotimes = 0;
  2428. sd->exposure = expo_adjust(gspca_dev,
  2429. (unsigned int) (expotimes << 8));
  2430. break;
  2431. case SENSOR_OM6802:
  2432. case SENSOR_MT9V111:
  2433. expotimes = sd->exposure;
  2434. expotimes += (luma_mean - delta) >> 2;
  2435. if (expotimes < 0)
  2436. expotimes = 0;
  2437. sd->exposure = expo_adjust(gspca_dev,
  2438. (unsigned int) expotimes);
  2439. setredblue(gspca_dev);
  2440. break;
  2441. default:
  2442. /* case SENSOR_MO4000: */
  2443. /* case SENSOR_MI0360: */
  2444. /* case SENSOR_MI0360B: */
  2445. expotimes = sd->exposure;
  2446. expotimes += (luma_mean - delta) >> 6;
  2447. if (expotimes < 0)
  2448. expotimes = 0;
  2449. sd->exposure = expo_adjust(gspca_dev,
  2450. (unsigned int) expotimes);
  2451. setredblue(gspca_dev);
  2452. break;
  2453. }
  2454. }
  2455. }
  2456. /* set the average luminosity from an isoc marker */
  2457. static void set_lum(struct sd *sd,
  2458. u8 *data)
  2459. {
  2460. int avg_lum;
  2461. /* w0 w1 w2
  2462. * w3 w4 w5
  2463. * w6 w7 w8
  2464. */
  2465. avg_lum = (data[27] << 8) + data[28] /* w3 */
  2466. + (data[31] << 8) + data[32] /* w5 */
  2467. + (data[23] << 8) + data[24] /* w1 */
  2468. + (data[35] << 8) + data[36] /* w7 */
  2469. + (data[29] << 10) + (data[30] << 2); /* w4 * 4 */
  2470. avg_lum >>= 10;
  2471. atomic_set(&sd->avg_lum, avg_lum);
  2472. }
  2473. /* scan the URB packets */
  2474. /* This function is run at interrupt level. */
  2475. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2476. u8 *data, /* isoc packet */
  2477. int len) /* iso packet length */
  2478. {
  2479. struct sd *sd = (struct sd *) gspca_dev;
  2480. int i, new_qual;
  2481. /*
  2482. * A frame ends on the marker
  2483. * ff ff 00 c4 c4 96 ..
  2484. * which is 62 bytes long and is followed by various information
  2485. * including statuses and luminosity.
  2486. *
  2487. * A marker may be splitted on two packets.
  2488. *
  2489. * The 6th byte of a marker contains the bits:
  2490. * 0x08: USB full
  2491. * 0xc0: frame sequence
  2492. * When the bit 'USB full' is set, the frame must be discarded;
  2493. * this is also the case when the 2 bytes before the marker are
  2494. * not the JPEG end of frame ('ff d9').
  2495. */
  2496. /* count the packets and their size */
  2497. sd->npkt++;
  2498. sd->pktsz += len;
  2499. /*fixme: assumption about the following code:
  2500. * - there can be only one marker in a packet
  2501. */
  2502. /* skip the remaining bytes of a short marker */
  2503. i = sd->short_mark;
  2504. if (i != 0) {
  2505. sd->short_mark = 0;
  2506. if (i < 0 /* if 'ff' at end of previous packet */
  2507. && data[0] == 0xff
  2508. && data[1] == 0x00)
  2509. goto marker_found;
  2510. if (data[0] == 0xff && data[1] == 0xff) {
  2511. i = 0;
  2512. goto marker_found;
  2513. }
  2514. len -= i;
  2515. if (len <= 0)
  2516. return;
  2517. data += i;
  2518. }
  2519. /* search backwards if there is a marker in the packet */
  2520. for (i = len - 1; --i >= 0; ) {
  2521. if (data[i] != 0xff) {
  2522. i--;
  2523. continue;
  2524. }
  2525. if (data[i + 1] == 0xff) {
  2526. /* (there may be 'ff ff' inside a marker) */
  2527. if (i + 2 >= len || data[i + 2] == 0x00)
  2528. goto marker_found;
  2529. }
  2530. }
  2531. /* no marker found */
  2532. /* add the JPEG header if first fragment */
  2533. if (data[len - 1] == 0xff)
  2534. sd->short_mark = -1;
  2535. if (gspca_dev->last_packet_type == LAST_PACKET)
  2536. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2537. sd->jpeg_hdr, JPEG_HDR_SZ);
  2538. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2539. return;
  2540. /* marker found */
  2541. /* if some error, discard the frame and decrease the quality */
  2542. marker_found:
  2543. new_qual = 0;
  2544. if (i > 2) {
  2545. if (data[i - 2] != 0xff || data[i - 1] != 0xd9) {
  2546. gspca_dev->last_packet_type = DISCARD_PACKET;
  2547. new_qual = -3;
  2548. }
  2549. } else if (i + 6 < len) {
  2550. if (data[i + 6] & 0x08) {
  2551. gspca_dev->last_packet_type = DISCARD_PACKET;
  2552. new_qual = -5;
  2553. }
  2554. }
  2555. gspca_frame_add(gspca_dev, LAST_PACKET, data, i);
  2556. /* compute the filling rate and a new JPEG quality */
  2557. if (new_qual == 0) {
  2558. int r;
  2559. r = (sd->pktsz * 100) /
  2560. (sd->npkt *
  2561. gspca_dev->urb[0]->iso_frame_desc[0].length);
  2562. if (r >= 85)
  2563. new_qual = -3;
  2564. else if (r < 75)
  2565. new_qual = 2;
  2566. }
  2567. if (new_qual != 0) {
  2568. sd->nchg += new_qual;
  2569. if (sd->nchg < -6 || sd->nchg >= 12) {
  2570. sd->nchg = 0;
  2571. new_qual += sd->quality;
  2572. if (new_qual < QUALITY_MIN)
  2573. new_qual = QUALITY_MIN;
  2574. else if (new_qual > QUALITY_MAX)
  2575. new_qual = QUALITY_MAX;
  2576. if (new_qual != sd->quality) {
  2577. sd->quality = new_qual;
  2578. schedule_work(&sd->work);
  2579. }
  2580. }
  2581. } else {
  2582. sd->nchg = 0;
  2583. }
  2584. sd->pktsz = sd->npkt = 0;
  2585. /* if the marker is smaller than 62 bytes,
  2586. * memorize the number of bytes to skip in the next packet */
  2587. if (i + 62 > len) { /* no more usable data */
  2588. sd->short_mark = i + 62 - len;
  2589. return;
  2590. }
  2591. if (sd->ag_cnt >= 0)
  2592. set_lum(sd, data + i);
  2593. /* if more data, start a new frame */
  2594. i += 62;
  2595. if (i < len) {
  2596. data += i;
  2597. len -= i;
  2598. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2599. sd->jpeg_hdr, JPEG_HDR_SZ);
  2600. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2601. }
  2602. }
  2603. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  2604. {
  2605. struct gspca_dev *gspca_dev =
  2606. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  2607. gspca_dev->usb_err = 0;
  2608. if (!gspca_dev->streaming)
  2609. return 0;
  2610. switch (ctrl->id) {
  2611. case V4L2_CID_BRIGHTNESS:
  2612. setbrightness(gspca_dev);
  2613. break;
  2614. case V4L2_CID_CONTRAST:
  2615. setcontrast(gspca_dev);
  2616. break;
  2617. case V4L2_CID_SATURATION:
  2618. setcolors(gspca_dev);
  2619. break;
  2620. case V4L2_CID_RED_BALANCE:
  2621. setredblue(gspca_dev);
  2622. break;
  2623. case V4L2_CID_GAMMA:
  2624. setgamma(gspca_dev);
  2625. break;
  2626. case V4L2_CID_AUTOGAIN:
  2627. setautogain(gspca_dev);
  2628. setexposure(gspca_dev);
  2629. setgain(gspca_dev);
  2630. break;
  2631. case V4L2_CID_VFLIP:
  2632. sethvflip(gspca_dev);
  2633. break;
  2634. case V4L2_CID_SHARPNESS:
  2635. setsharpness(gspca_dev);
  2636. break;
  2637. case V4L2_CID_ILLUMINATORS_1:
  2638. setillum(gspca_dev);
  2639. break;
  2640. case V4L2_CID_POWER_LINE_FREQUENCY:
  2641. setfreq(gspca_dev);
  2642. break;
  2643. default:
  2644. return -EINVAL;
  2645. }
  2646. return gspca_dev->usb_err;
  2647. }
  2648. #if IS_ENABLED(CONFIG_INPUT)
  2649. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2650. u8 *data, /* interrupt packet data */
  2651. int len) /* interrupt packet length */
  2652. {
  2653. int ret = -EINVAL;
  2654. if (len == 1 && data[0] == 1) {
  2655. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2656. input_sync(gspca_dev->input_dev);
  2657. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2658. input_sync(gspca_dev->input_dev);
  2659. ret = 0;
  2660. }
  2661. return ret;
  2662. }
  2663. #endif
  2664. /* sub-driver description */
  2665. static const struct sd_desc sd_desc = {
  2666. .name = MODULE_NAME,
  2667. .config = sd_config,
  2668. .init = sd_init,
  2669. .init_controls = sd_init_controls,
  2670. .start = sd_start,
  2671. .stopN = sd_stopN,
  2672. .stop0 = sd_stop0,
  2673. .pkt_scan = sd_pkt_scan,
  2674. .dq_callback = do_autogain,
  2675. #if IS_ENABLED(CONFIG_INPUT)
  2676. .int_pkt_scan = sd_int_pkt_scan,
  2677. #endif
  2678. };
  2679. /* -- module initialisation -- */
  2680. #define BS(bridge, sensor) \
  2681. .driver_info = (BRIDGE_ ## bridge << 16) \
  2682. | (SENSOR_ ## sensor << 8)
  2683. #define BSF(bridge, sensor, flags) \
  2684. .driver_info = (BRIDGE_ ## bridge << 16) \
  2685. | (SENSOR_ ## sensor << 8) \
  2686. | (flags)
  2687. static const struct usb_device_id device_table[] = {
  2688. {USB_DEVICE(0x0458, 0x7025), BSF(SN9C120, MI0360B, F_PDN_INV)},
  2689. {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
  2690. {USB_DEVICE(0x045e, 0x00f5), BSF(SN9C105, OV7660, F_PDN_INV)},
  2691. {USB_DEVICE(0x045e, 0x00f7), BSF(SN9C105, OV7660, F_PDN_INV)},
  2692. {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
  2693. {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
  2694. {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
  2695. {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
  2696. {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
  2697. /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
  2698. {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
  2699. /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
  2700. /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
  2701. {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
  2702. /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
  2703. {USB_DEVICE(0x0c45, 0x60c0), BSF(SN9C105, MI0360, F_ILLUM)},
  2704. /* or MT9V111 */
  2705. /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
  2706. /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
  2707. /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
  2708. {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
  2709. {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
  2710. /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
  2711. /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
  2712. /* {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
  2713. {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
  2714. {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
  2715. {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
  2716. {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
  2717. {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)}, /* /GC0305*/
  2718. /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
  2719. {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
  2720. {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
  2721. {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
  2722. {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
  2723. /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
  2724. /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
  2725. /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
  2726. {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
  2727. /*bw600.inf:*/
  2728. {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
  2729. {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
  2730. {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
  2731. {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
  2732. /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
  2733. {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
  2734. /* or MT9V111 / MI0360B */
  2735. /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
  2736. {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
  2737. {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
  2738. {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
  2739. {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
  2740. {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
  2741. {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
  2742. /* or GC0305 / GC0307 */
  2743. {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
  2744. {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
  2745. {USB_DEVICE(0x0c45, 0x614a), BSF(SN9C120, ADCM1700, F_ILLUM)},
  2746. /* {USB_DEVICE(0x0c45, 0x614c), BS(SN9C120, GC0306)}, */ /*sn9c120b*/
  2747. {}
  2748. };
  2749. MODULE_DEVICE_TABLE(usb, device_table);
  2750. /* -- device connect -- */
  2751. static int sd_probe(struct usb_interface *intf,
  2752. const struct usb_device_id *id)
  2753. {
  2754. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2755. THIS_MODULE);
  2756. }
  2757. static struct usb_driver sd_driver = {
  2758. .name = MODULE_NAME,
  2759. .id_table = device_table,
  2760. .probe = sd_probe,
  2761. .disconnect = gspca_disconnect,
  2762. #ifdef CONFIG_PM
  2763. .suspend = gspca_suspend,
  2764. .resume = gspca_resume,
  2765. .reset_resume = gspca_resume,
  2766. #endif
  2767. };
  2768. module_usb_driver(sd_driver);