sonixj.c 80 KB

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