sonixj.c 93 KB

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