sonixj.c 93 KB

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