sn9c20x.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559
  1. /*
  2. * Sonix sn9c201 sn9c202 library
  3. * Copyright (C) 2008-2009 microdia project <microdia@googlegroups.com>
  4. * Copyright (C) 2009 Brian Johnson <brijohn@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/input.h>
  21. #include "gspca.h"
  22. #include "jpeg.h"
  23. #include <media/v4l2-chip-ident.h>
  24. #include <linux/dmi.h>
  25. MODULE_AUTHOR("Brian Johnson <brijohn@gmail.com>, "
  26. "microdia project <microdia@googlegroups.com>");
  27. MODULE_DESCRIPTION("GSPCA/SN9C20X USB Camera Driver");
  28. MODULE_LICENSE("GPL");
  29. #define MODULE_NAME "sn9c20x"
  30. /*
  31. * Pixel format private data
  32. */
  33. #define SCALE_MASK 0x0f
  34. #define SCALE_160x120 0
  35. #define SCALE_320x240 1
  36. #define SCALE_640x480 2
  37. #define SCALE_1280x1024 3
  38. #define MODE_RAW 0x10
  39. #define MODE_JPEG 0x20
  40. #define MODE_SXGA 0x80
  41. #define SENSOR_OV9650 0
  42. #define SENSOR_OV9655 1
  43. #define SENSOR_SOI968 2
  44. #define SENSOR_OV7660 3
  45. #define SENSOR_OV7670 4
  46. #define SENSOR_MT9V011 5
  47. #define SENSOR_MT9V111 6
  48. #define SENSOR_MT9V112 7
  49. #define SENSOR_MT9M001 8
  50. #define SENSOR_MT9M111 9
  51. #define SENSOR_MT9M112 10
  52. #define SENSOR_HV7131R 11
  53. #define SENSOR_MT9VPRB 20
  54. /* camera flags */
  55. #define HAS_NO_BUTTON 0x1
  56. #define LED_REVERSE 0x2 /* some cameras unset gpio to turn on leds */
  57. #define FLIP_DETECT 0x4
  58. /* specific webcam descriptor */
  59. struct sd {
  60. struct gspca_dev gspca_dev;
  61. #define MIN_AVG_LUM 80
  62. #define MAX_AVG_LUM 130
  63. atomic_t avg_lum;
  64. u8 old_step;
  65. u8 older_step;
  66. u8 exposure_step;
  67. u8 brightness;
  68. u8 contrast;
  69. u8 saturation;
  70. s16 hue;
  71. u8 gamma;
  72. u8 red;
  73. u8 blue;
  74. u8 hflip;
  75. u8 vflip;
  76. u8 gain;
  77. u16 exposure;
  78. u8 auto_exposure;
  79. u8 i2c_addr;
  80. u8 sensor;
  81. u8 hstart;
  82. u8 vstart;
  83. u8 jpeg_hdr[JPEG_HDR_SZ];
  84. u8 quality;
  85. u8 flags;
  86. };
  87. struct i2c_reg_u8 {
  88. u8 reg;
  89. u8 val;
  90. };
  91. struct i2c_reg_u16 {
  92. u8 reg;
  93. u16 val;
  94. };
  95. static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val);
  96. static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val);
  97. static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val);
  98. static int sd_getcontrast(struct gspca_dev *gspca_dev, s32 *val);
  99. static int sd_setsaturation(struct gspca_dev *gspca_dev, s32 val);
  100. static int sd_getsaturation(struct gspca_dev *gspca_dev, s32 *val);
  101. static int sd_sethue(struct gspca_dev *gspca_dev, s32 val);
  102. static int sd_gethue(struct gspca_dev *gspca_dev, s32 *val);
  103. static int sd_setgamma(struct gspca_dev *gspca_dev, s32 val);
  104. static int sd_getgamma(struct gspca_dev *gspca_dev, s32 *val);
  105. static int sd_setredbalance(struct gspca_dev *gspca_dev, s32 val);
  106. static int sd_getredbalance(struct gspca_dev *gspca_dev, s32 *val);
  107. static int sd_setbluebalance(struct gspca_dev *gspca_dev, s32 val);
  108. static int sd_getbluebalance(struct gspca_dev *gspca_dev, s32 *val);
  109. static int sd_setvflip(struct gspca_dev *gspca_dev, s32 val);
  110. static int sd_getvflip(struct gspca_dev *gspca_dev, s32 *val);
  111. static int sd_sethflip(struct gspca_dev *gspca_dev, s32 val);
  112. static int sd_gethflip(struct gspca_dev *gspca_dev, s32 *val);
  113. static int sd_setgain(struct gspca_dev *gspca_dev, s32 val);
  114. static int sd_getgain(struct gspca_dev *gspca_dev, s32 *val);
  115. static int sd_setexposure(struct gspca_dev *gspca_dev, s32 val);
  116. static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val);
  117. static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val);
  118. static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val);
  119. static const struct dmi_system_id flip_dmi_table[] = {
  120. {
  121. .ident = "MSI MS-1034",
  122. .matches = {
  123. DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD."),
  124. DMI_MATCH(DMI_PRODUCT_NAME, "MS-1034"),
  125. DMI_MATCH(DMI_PRODUCT_VERSION, "0341")
  126. }
  127. },
  128. {
  129. .ident = "MSI MS-1632",
  130. .matches = {
  131. DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
  132. DMI_MATCH(DMI_BOARD_NAME, "MS-1632")
  133. }
  134. },
  135. {
  136. .ident = "MSI MS-1635X",
  137. .matches = {
  138. DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
  139. DMI_MATCH(DMI_BOARD_NAME, "MS-1635X")
  140. }
  141. },
  142. {
  143. .ident = "ASUSTeK W7J",
  144. .matches = {
  145. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc."),
  146. DMI_MATCH(DMI_BOARD_NAME, "W7J ")
  147. }
  148. },
  149. {}
  150. };
  151. static const struct ctrl sd_ctrls[] = {
  152. {
  153. #define BRIGHTNESS_IDX 0
  154. {
  155. .id = V4L2_CID_BRIGHTNESS,
  156. .type = V4L2_CTRL_TYPE_INTEGER,
  157. .name = "Brightness",
  158. .minimum = 0,
  159. .maximum = 0xff,
  160. .step = 1,
  161. #define BRIGHTNESS_DEFAULT 0x7f
  162. .default_value = BRIGHTNESS_DEFAULT,
  163. },
  164. .set = sd_setbrightness,
  165. .get = sd_getbrightness,
  166. },
  167. {
  168. #define CONTRAST_IDX 1
  169. {
  170. .id = V4L2_CID_CONTRAST,
  171. .type = V4L2_CTRL_TYPE_INTEGER,
  172. .name = "Contrast",
  173. .minimum = 0,
  174. .maximum = 0xff,
  175. .step = 1,
  176. #define CONTRAST_DEFAULT 0x7f
  177. .default_value = CONTRAST_DEFAULT,
  178. },
  179. .set = sd_setcontrast,
  180. .get = sd_getcontrast,
  181. },
  182. {
  183. #define SATURATION_IDX 2
  184. {
  185. .id = V4L2_CID_SATURATION,
  186. .type = V4L2_CTRL_TYPE_INTEGER,
  187. .name = "Saturation",
  188. .minimum = 0,
  189. .maximum = 0xff,
  190. .step = 1,
  191. #define SATURATION_DEFAULT 0x7f
  192. .default_value = SATURATION_DEFAULT,
  193. },
  194. .set = sd_setsaturation,
  195. .get = sd_getsaturation,
  196. },
  197. {
  198. #define HUE_IDX 3
  199. {
  200. .id = V4L2_CID_HUE,
  201. .type = V4L2_CTRL_TYPE_INTEGER,
  202. .name = "Hue",
  203. .minimum = -180,
  204. .maximum = 180,
  205. .step = 1,
  206. #define HUE_DEFAULT 0
  207. .default_value = HUE_DEFAULT,
  208. },
  209. .set = sd_sethue,
  210. .get = sd_gethue,
  211. },
  212. {
  213. #define GAMMA_IDX 4
  214. {
  215. .id = V4L2_CID_GAMMA,
  216. .type = V4L2_CTRL_TYPE_INTEGER,
  217. .name = "Gamma",
  218. .minimum = 0,
  219. .maximum = 0xff,
  220. .step = 1,
  221. #define GAMMA_DEFAULT 0x10
  222. .default_value = GAMMA_DEFAULT,
  223. },
  224. .set = sd_setgamma,
  225. .get = sd_getgamma,
  226. },
  227. {
  228. #define BLUE_IDX 5
  229. {
  230. .id = V4L2_CID_BLUE_BALANCE,
  231. .type = V4L2_CTRL_TYPE_INTEGER,
  232. .name = "Blue Balance",
  233. .minimum = 0,
  234. .maximum = 0x7f,
  235. .step = 1,
  236. #define BLUE_DEFAULT 0x28
  237. .default_value = BLUE_DEFAULT,
  238. },
  239. .set = sd_setbluebalance,
  240. .get = sd_getbluebalance,
  241. },
  242. {
  243. #define RED_IDX 6
  244. {
  245. .id = V4L2_CID_RED_BALANCE,
  246. .type = V4L2_CTRL_TYPE_INTEGER,
  247. .name = "Red Balance",
  248. .minimum = 0,
  249. .maximum = 0x7f,
  250. .step = 1,
  251. #define RED_DEFAULT 0x28
  252. .default_value = RED_DEFAULT,
  253. },
  254. .set = sd_setredbalance,
  255. .get = sd_getredbalance,
  256. },
  257. {
  258. #define HFLIP_IDX 7
  259. {
  260. .id = V4L2_CID_HFLIP,
  261. .type = V4L2_CTRL_TYPE_BOOLEAN,
  262. .name = "Horizontal Flip",
  263. .minimum = 0,
  264. .maximum = 1,
  265. .step = 1,
  266. #define HFLIP_DEFAULT 0
  267. .default_value = HFLIP_DEFAULT,
  268. },
  269. .set = sd_sethflip,
  270. .get = sd_gethflip,
  271. },
  272. {
  273. #define VFLIP_IDX 8
  274. {
  275. .id = V4L2_CID_VFLIP,
  276. .type = V4L2_CTRL_TYPE_BOOLEAN,
  277. .name = "Vertical Flip",
  278. .minimum = 0,
  279. .maximum = 1,
  280. .step = 1,
  281. #define VFLIP_DEFAULT 0
  282. .default_value = VFLIP_DEFAULT,
  283. },
  284. .set = sd_setvflip,
  285. .get = sd_getvflip,
  286. },
  287. {
  288. #define EXPOSURE_IDX 9
  289. {
  290. .id = V4L2_CID_EXPOSURE,
  291. .type = V4L2_CTRL_TYPE_INTEGER,
  292. .name = "Exposure",
  293. .minimum = 0,
  294. .maximum = 0x1780,
  295. .step = 1,
  296. #define EXPOSURE_DEFAULT 0x33
  297. .default_value = EXPOSURE_DEFAULT,
  298. },
  299. .set = sd_setexposure,
  300. .get = sd_getexposure,
  301. },
  302. {
  303. #define GAIN_IDX 10
  304. {
  305. .id = V4L2_CID_GAIN,
  306. .type = V4L2_CTRL_TYPE_INTEGER,
  307. .name = "Gain",
  308. .minimum = 0,
  309. .maximum = 28,
  310. .step = 1,
  311. #define GAIN_DEFAULT 0x00
  312. .default_value = GAIN_DEFAULT,
  313. },
  314. .set = sd_setgain,
  315. .get = sd_getgain,
  316. },
  317. {
  318. #define AUTOGAIN_IDX 11
  319. {
  320. .id = V4L2_CID_AUTOGAIN,
  321. .type = V4L2_CTRL_TYPE_BOOLEAN,
  322. .name = "Auto Exposure",
  323. .minimum = 0,
  324. .maximum = 1,
  325. .step = 1,
  326. #define AUTO_EXPOSURE_DEFAULT 1
  327. .default_value = AUTO_EXPOSURE_DEFAULT,
  328. },
  329. .set = sd_setautoexposure,
  330. .get = sd_getautoexposure,
  331. },
  332. };
  333. static const struct v4l2_pix_format vga_mode[] = {
  334. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  335. .bytesperline = 160,
  336. .sizeimage = 160 * 120 * 4 / 8 + 590,
  337. .colorspace = V4L2_COLORSPACE_JPEG,
  338. .priv = SCALE_160x120 | MODE_JPEG},
  339. {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  340. .bytesperline = 160,
  341. .sizeimage = 160 * 120,
  342. .colorspace = V4L2_COLORSPACE_SRGB,
  343. .priv = SCALE_160x120 | MODE_RAW},
  344. {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  345. .bytesperline = 160,
  346. .sizeimage = 240 * 120,
  347. .colorspace = V4L2_COLORSPACE_SRGB,
  348. .priv = SCALE_160x120},
  349. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  350. .bytesperline = 320,
  351. .sizeimage = 320 * 240 * 3 / 8 + 590,
  352. .colorspace = V4L2_COLORSPACE_JPEG,
  353. .priv = SCALE_320x240 | MODE_JPEG},
  354. {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  355. .bytesperline = 320,
  356. .sizeimage = 320 * 240 ,
  357. .colorspace = V4L2_COLORSPACE_SRGB,
  358. .priv = SCALE_320x240 | MODE_RAW},
  359. {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  360. .bytesperline = 320,
  361. .sizeimage = 480 * 240 ,
  362. .colorspace = V4L2_COLORSPACE_SRGB,
  363. .priv = SCALE_320x240},
  364. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  365. .bytesperline = 640,
  366. .sizeimage = 640 * 480 * 3 / 8 + 590,
  367. .colorspace = V4L2_COLORSPACE_JPEG,
  368. .priv = SCALE_640x480 | MODE_JPEG},
  369. {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  370. .bytesperline = 640,
  371. .sizeimage = 640 * 480,
  372. .colorspace = V4L2_COLORSPACE_SRGB,
  373. .priv = SCALE_640x480 | MODE_RAW},
  374. {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  375. .bytesperline = 640,
  376. .sizeimage = 960 * 480,
  377. .colorspace = V4L2_COLORSPACE_SRGB,
  378. .priv = SCALE_640x480},
  379. };
  380. static const struct v4l2_pix_format sxga_mode[] = {
  381. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  382. .bytesperline = 160,
  383. .sizeimage = 160 * 120 * 4 / 8 + 590,
  384. .colorspace = V4L2_COLORSPACE_JPEG,
  385. .priv = SCALE_160x120 | MODE_JPEG},
  386. {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  387. .bytesperline = 160,
  388. .sizeimage = 160 * 120,
  389. .colorspace = V4L2_COLORSPACE_SRGB,
  390. .priv = SCALE_160x120 | MODE_RAW},
  391. {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  392. .bytesperline = 160,
  393. .sizeimage = 240 * 120,
  394. .colorspace = V4L2_COLORSPACE_SRGB,
  395. .priv = SCALE_160x120},
  396. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  397. .bytesperline = 320,
  398. .sizeimage = 320 * 240 * 3 / 8 + 590,
  399. .colorspace = V4L2_COLORSPACE_JPEG,
  400. .priv = SCALE_320x240 | MODE_JPEG},
  401. {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  402. .bytesperline = 320,
  403. .sizeimage = 320 * 240 ,
  404. .colorspace = V4L2_COLORSPACE_SRGB,
  405. .priv = SCALE_320x240 | MODE_RAW},
  406. {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  407. .bytesperline = 320,
  408. .sizeimage = 480 * 240 ,
  409. .colorspace = V4L2_COLORSPACE_SRGB,
  410. .priv = SCALE_320x240},
  411. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  412. .bytesperline = 640,
  413. .sizeimage = 640 * 480 * 3 / 8 + 590,
  414. .colorspace = V4L2_COLORSPACE_JPEG,
  415. .priv = SCALE_640x480 | MODE_JPEG},
  416. {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  417. .bytesperline = 640,
  418. .sizeimage = 640 * 480,
  419. .colorspace = V4L2_COLORSPACE_SRGB,
  420. .priv = SCALE_640x480 | MODE_RAW},
  421. {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
  422. .bytesperline = 640,
  423. .sizeimage = 960 * 480,
  424. .colorspace = V4L2_COLORSPACE_SRGB,
  425. .priv = SCALE_640x480},
  426. {1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  427. .bytesperline = 1280,
  428. .sizeimage = 1280 * 1024,
  429. .colorspace = V4L2_COLORSPACE_SRGB,
  430. .priv = SCALE_1280x1024 | MODE_RAW | MODE_SXGA},
  431. };
  432. static const struct v4l2_pix_format mono_mode[] = {
  433. {160, 120, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
  434. .bytesperline = 160,
  435. .sizeimage = 160 * 120,
  436. .colorspace = V4L2_COLORSPACE_SRGB,
  437. .priv = SCALE_160x120 | MODE_RAW},
  438. {320, 240, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
  439. .bytesperline = 320,
  440. .sizeimage = 320 * 240 ,
  441. .colorspace = V4L2_COLORSPACE_SRGB,
  442. .priv = SCALE_320x240 | MODE_RAW},
  443. {640, 480, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
  444. .bytesperline = 640,
  445. .sizeimage = 640 * 480,
  446. .colorspace = V4L2_COLORSPACE_SRGB,
  447. .priv = SCALE_640x480 | MODE_RAW},
  448. {1280, 1024, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
  449. .bytesperline = 1280,
  450. .sizeimage = 1280 * 1024,
  451. .colorspace = V4L2_COLORSPACE_SRGB,
  452. .priv = SCALE_1280x1024 | MODE_RAW | MODE_SXGA},
  453. };
  454. static const s16 hsv_red_x[] = {
  455. 41, 44, 46, 48, 50, 52, 54, 56,
  456. 58, 60, 62, 64, 66, 68, 70, 72,
  457. 74, 76, 78, 80, 81, 83, 85, 87,
  458. 88, 90, 92, 93, 95, 97, 98, 100,
  459. 101, 102, 104, 105, 107, 108, 109, 110,
  460. 112, 113, 114, 115, 116, 117, 118, 119,
  461. 120, 121, 122, 123, 123, 124, 125, 125,
  462. 126, 127, 127, 128, 128, 129, 129, 129,
  463. 130, 130, 130, 130, 131, 131, 131, 131,
  464. 131, 131, 131, 131, 130, 130, 130, 130,
  465. 129, 129, 129, 128, 128, 127, 127, 126,
  466. 125, 125, 124, 123, 122, 122, 121, 120,
  467. 119, 118, 117, 116, 115, 114, 112, 111,
  468. 110, 109, 107, 106, 105, 103, 102, 101,
  469. 99, 98, 96, 94, 93, 91, 90, 88,
  470. 86, 84, 83, 81, 79, 77, 75, 74,
  471. 72, 70, 68, 66, 64, 62, 60, 58,
  472. 56, 54, 52, 49, 47, 45, 43, 41,
  473. 39, 36, 34, 32, 30, 28, 25, 23,
  474. 21, 19, 16, 14, 12, 9, 7, 5,
  475. 3, 0, -1, -3, -6, -8, -10, -12,
  476. -15, -17, -19, -22, -24, -26, -28, -30,
  477. -33, -35, -37, -39, -41, -44, -46, -48,
  478. -50, -52, -54, -56, -58, -60, -62, -64,
  479. -66, -68, -70, -72, -74, -76, -78, -80,
  480. -81, -83, -85, -87, -88, -90, -92, -93,
  481. -95, -97, -98, -100, -101, -102, -104, -105,
  482. -107, -108, -109, -110, -112, -113, -114, -115,
  483. -116, -117, -118, -119, -120, -121, -122, -123,
  484. -123, -124, -125, -125, -126, -127, -127, -128,
  485. -128, -128, -128, -128, -128, -128, -128, -128,
  486. -128, -128, -128, -128, -128, -128, -128, -128,
  487. -128, -128, -128, -128, -128, -128, -128, -128,
  488. -128, -127, -127, -126, -125, -125, -124, -123,
  489. -122, -122, -121, -120, -119, -118, -117, -116,
  490. -115, -114, -112, -111, -110, -109, -107, -106,
  491. -105, -103, -102, -101, -99, -98, -96, -94,
  492. -93, -91, -90, -88, -86, -84, -83, -81,
  493. -79, -77, -75, -74, -72, -70, -68, -66,
  494. -64, -62, -60, -58, -56, -54, -52, -49,
  495. -47, -45, -43, -41, -39, -36, -34, -32,
  496. -30, -28, -25, -23, -21, -19, -16, -14,
  497. -12, -9, -7, -5, -3, 0, 1, 3,
  498. 6, 8, 10, 12, 15, 17, 19, 22,
  499. 24, 26, 28, 30, 33, 35, 37, 39, 41
  500. };
  501. static const s16 hsv_red_y[] = {
  502. 82, 80, 78, 76, 74, 73, 71, 69,
  503. 67, 65, 63, 61, 58, 56, 54, 52,
  504. 50, 48, 46, 44, 41, 39, 37, 35,
  505. 32, 30, 28, 26, 23, 21, 19, 16,
  506. 14, 12, 10, 7, 5, 3, 0, -1,
  507. -3, -6, -8, -10, -13, -15, -17, -19,
  508. -22, -24, -26, -29, -31, -33, -35, -38,
  509. -40, -42, -44, -46, -48, -51, -53, -55,
  510. -57, -59, -61, -63, -65, -67, -69, -71,
  511. -73, -75, -77, -79, -81, -82, -84, -86,
  512. -88, -89, -91, -93, -94, -96, -98, -99,
  513. -101, -102, -104, -105, -106, -108, -109, -110,
  514. -112, -113, -114, -115, -116, -117, -119, -120,
  515. -120, -121, -122, -123, -124, -125, -126, -126,
  516. -127, -128, -128, -128, -128, -128, -128, -128,
  517. -128, -128, -128, -128, -128, -128, -128, -128,
  518. -128, -128, -128, -128, -128, -128, -128, -128,
  519. -128, -128, -128, -128, -128, -128, -128, -128,
  520. -127, -127, -126, -125, -125, -124, -123, -122,
  521. -121, -120, -119, -118, -117, -116, -115, -114,
  522. -113, -111, -110, -109, -107, -106, -105, -103,
  523. -102, -100, -99, -97, -96, -94, -92, -91,
  524. -89, -87, -85, -84, -82, -80, -78, -76,
  525. -74, -73, -71, -69, -67, -65, -63, -61,
  526. -58, -56, -54, -52, -50, -48, -46, -44,
  527. -41, -39, -37, -35, -32, -30, -28, -26,
  528. -23, -21, -19, -16, -14, -12, -10, -7,
  529. -5, -3, 0, 1, 3, 6, 8, 10,
  530. 13, 15, 17, 19, 22, 24, 26, 29,
  531. 31, 33, 35, 38, 40, 42, 44, 46,
  532. 48, 51, 53, 55, 57, 59, 61, 63,
  533. 65, 67, 69, 71, 73, 75, 77, 79,
  534. 81, 82, 84, 86, 88, 89, 91, 93,
  535. 94, 96, 98, 99, 101, 102, 104, 105,
  536. 106, 108, 109, 110, 112, 113, 114, 115,
  537. 116, 117, 119, 120, 120, 121, 122, 123,
  538. 124, 125, 126, 126, 127, 128, 128, 129,
  539. 129, 130, 130, 131, 131, 131, 131, 132,
  540. 132, 132, 132, 132, 132, 132, 132, 132,
  541. 132, 132, 132, 131, 131, 131, 130, 130,
  542. 130, 129, 129, 128, 127, 127, 126, 125,
  543. 125, 124, 123, 122, 121, 120, 119, 118,
  544. 117, 116, 115, 114, 113, 111, 110, 109,
  545. 107, 106, 105, 103, 102, 100, 99, 97,
  546. 96, 94, 92, 91, 89, 87, 85, 84, 82
  547. };
  548. static const s16 hsv_green_x[] = {
  549. -124, -124, -125, -125, -125, -125, -125, -125,
  550. -125, -126, -126, -125, -125, -125, -125, -125,
  551. -125, -124, -124, -124, -123, -123, -122, -122,
  552. -121, -121, -120, -120, -119, -118, -117, -117,
  553. -116, -115, -114, -113, -112, -111, -110, -109,
  554. -108, -107, -105, -104, -103, -102, -100, -99,
  555. -98, -96, -95, -93, -92, -91, -89, -87,
  556. -86, -84, -83, -81, -79, -77, -76, -74,
  557. -72, -70, -69, -67, -65, -63, -61, -59,
  558. -57, -55, -53, -51, -49, -47, -45, -43,
  559. -41, -39, -37, -35, -33, -30, -28, -26,
  560. -24, -22, -20, -18, -15, -13, -11, -9,
  561. -7, -4, -2, 0, 1, 3, 6, 8,
  562. 10, 12, 14, 17, 19, 21, 23, 25,
  563. 27, 29, 32, 34, 36, 38, 40, 42,
  564. 44, 46, 48, 50, 52, 54, 56, 58,
  565. 60, 62, 64, 66, 68, 70, 71, 73,
  566. 75, 77, 78, 80, 82, 83, 85, 87,
  567. 88, 90, 91, 93, 94, 96, 97, 98,
  568. 100, 101, 102, 104, 105, 106, 107, 108,
  569. 109, 111, 112, 113, 113, 114, 115, 116,
  570. 117, 118, 118, 119, 120, 120, 121, 122,
  571. 122, 123, 123, 124, 124, 124, 125, 125,
  572. 125, 125, 125, 125, 125, 126, 126, 125,
  573. 125, 125, 125, 125, 125, 124, 124, 124,
  574. 123, 123, 122, 122, 121, 121, 120, 120,
  575. 119, 118, 117, 117, 116, 115, 114, 113,
  576. 112, 111, 110, 109, 108, 107, 105, 104,
  577. 103, 102, 100, 99, 98, 96, 95, 93,
  578. 92, 91, 89, 87, 86, 84, 83, 81,
  579. 79, 77, 76, 74, 72, 70, 69, 67,
  580. 65, 63, 61, 59, 57, 55, 53, 51,
  581. 49, 47, 45, 43, 41, 39, 37, 35,
  582. 33, 30, 28, 26, 24, 22, 20, 18,
  583. 15, 13, 11, 9, 7, 4, 2, 0,
  584. -1, -3, -6, -8, -10, -12, -14, -17,
  585. -19, -21, -23, -25, -27, -29, -32, -34,
  586. -36, -38, -40, -42, -44, -46, -48, -50,
  587. -52, -54, -56, -58, -60, -62, -64, -66,
  588. -68, -70, -71, -73, -75, -77, -78, -80,
  589. -82, -83, -85, -87, -88, -90, -91, -93,
  590. -94, -96, -97, -98, -100, -101, -102, -104,
  591. -105, -106, -107, -108, -109, -111, -112, -113,
  592. -113, -114, -115, -116, -117, -118, -118, -119,
  593. -120, -120, -121, -122, -122, -123, -123, -124, -124
  594. };
  595. static const s16 hsv_green_y[] = {
  596. -100, -99, -98, -97, -95, -94, -93, -91,
  597. -90, -89, -87, -86, -84, -83, -81, -80,
  598. -78, -76, -75, -73, -71, -70, -68, -66,
  599. -64, -63, -61, -59, -57, -55, -53, -51,
  600. -49, -48, -46, -44, -42, -40, -38, -36,
  601. -34, -32, -30, -27, -25, -23, -21, -19,
  602. -17, -15, -13, -11, -9, -7, -4, -2,
  603. 0, 1, 3, 5, 7, 9, 11, 14,
  604. 16, 18, 20, 22, 24, 26, 28, 30,
  605. 32, 34, 36, 38, 40, 42, 44, 46,
  606. 48, 50, 52, 54, 56, 58, 59, 61,
  607. 63, 65, 67, 68, 70, 72, 74, 75,
  608. 77, 78, 80, 82, 83, 85, 86, 88,
  609. 89, 90, 92, 93, 95, 96, 97, 98,
  610. 100, 101, 102, 103, 104, 105, 106, 107,
  611. 108, 109, 110, 111, 112, 112, 113, 114,
  612. 115, 115, 116, 116, 117, 117, 118, 118,
  613. 119, 119, 119, 120, 120, 120, 120, 120,
  614. 121, 121, 121, 121, 121, 121, 120, 120,
  615. 120, 120, 120, 119, 119, 119, 118, 118,
  616. 117, 117, 116, 116, 115, 114, 114, 113,
  617. 112, 111, 111, 110, 109, 108, 107, 106,
  618. 105, 104, 103, 102, 100, 99, 98, 97,
  619. 95, 94, 93, 91, 90, 89, 87, 86,
  620. 84, 83, 81, 80, 78, 76, 75, 73,
  621. 71, 70, 68, 66, 64, 63, 61, 59,
  622. 57, 55, 53, 51, 49, 48, 46, 44,
  623. 42, 40, 38, 36, 34, 32, 30, 27,
  624. 25, 23, 21, 19, 17, 15, 13, 11,
  625. 9, 7, 4, 2, 0, -1, -3, -5,
  626. -7, -9, -11, -14, -16, -18, -20, -22,
  627. -24, -26, -28, -30, -32, -34, -36, -38,
  628. -40, -42, -44, -46, -48, -50, -52, -54,
  629. -56, -58, -59, -61, -63, -65, -67, -68,
  630. -70, -72, -74, -75, -77, -78, -80, -82,
  631. -83, -85, -86, -88, -89, -90, -92, -93,
  632. -95, -96, -97, -98, -100, -101, -102, -103,
  633. -104, -105, -106, -107, -108, -109, -110, -111,
  634. -112, -112, -113, -114, -115, -115, -116, -116,
  635. -117, -117, -118, -118, -119, -119, -119, -120,
  636. -120, -120, -120, -120, -121, -121, -121, -121,
  637. -121, -121, -120, -120, -120, -120, -120, -119,
  638. -119, -119, -118, -118, -117, -117, -116, -116,
  639. -115, -114, -114, -113, -112, -111, -111, -110,
  640. -109, -108, -107, -106, -105, -104, -103, -102, -100
  641. };
  642. static const s16 hsv_blue_x[] = {
  643. 112, 113, 114, 114, 115, 116, 117, 117,
  644. 118, 118, 119, 119, 120, 120, 120, 121,
  645. 121, 121, 122, 122, 122, 122, 122, 122,
  646. 122, 122, 122, 122, 122, 122, 121, 121,
  647. 121, 120, 120, 120, 119, 119, 118, 118,
  648. 117, 116, 116, 115, 114, 113, 113, 112,
  649. 111, 110, 109, 108, 107, 106, 105, 104,
  650. 103, 102, 100, 99, 98, 97, 95, 94,
  651. 93, 91, 90, 88, 87, 85, 84, 82,
  652. 80, 79, 77, 76, 74, 72, 70, 69,
  653. 67, 65, 63, 61, 60, 58, 56, 54,
  654. 52, 50, 48, 46, 44, 42, 40, 38,
  655. 36, 34, 32, 30, 28, 26, 24, 22,
  656. 19, 17, 15, 13, 11, 9, 7, 5,
  657. 2, 0, -1, -3, -5, -7, -9, -12,
  658. -14, -16, -18, -20, -22, -24, -26, -28,
  659. -31, -33, -35, -37, -39, -41, -43, -45,
  660. -47, -49, -51, -53, -54, -56, -58, -60,
  661. -62, -64, -66, -67, -69, -71, -73, -74,
  662. -76, -78, -79, -81, -83, -84, -86, -87,
  663. -89, -90, -92, -93, -94, -96, -97, -98,
  664. -99, -101, -102, -103, -104, -105, -106, -107,
  665. -108, -109, -110, -111, -112, -113, -114, -114,
  666. -115, -116, -117, -117, -118, -118, -119, -119,
  667. -120, -120, -120, -121, -121, -121, -122, -122,
  668. -122, -122, -122, -122, -122, -122, -122, -122,
  669. -122, -122, -121, -121, -121, -120, -120, -120,
  670. -119, -119, -118, -118, -117, -116, -116, -115,
  671. -114, -113, -113, -112, -111, -110, -109, -108,
  672. -107, -106, -105, -104, -103, -102, -100, -99,
  673. -98, -97, -95, -94, -93, -91, -90, -88,
  674. -87, -85, -84, -82, -80, -79, -77, -76,
  675. -74, -72, -70, -69, -67, -65, -63, -61,
  676. -60, -58, -56, -54, -52, -50, -48, -46,
  677. -44, -42, -40, -38, -36, -34, -32, -30,
  678. -28, -26, -24, -22, -19, -17, -15, -13,
  679. -11, -9, -7, -5, -2, 0, 1, 3,
  680. 5, 7, 9, 12, 14, 16, 18, 20,
  681. 22, 24, 26, 28, 31, 33, 35, 37,
  682. 39, 41, 43, 45, 47, 49, 51, 53,
  683. 54, 56, 58, 60, 62, 64, 66, 67,
  684. 69, 71, 73, 74, 76, 78, 79, 81,
  685. 83, 84, 86, 87, 89, 90, 92, 93,
  686. 94, 96, 97, 98, 99, 101, 102, 103,
  687. 104, 105, 106, 107, 108, 109, 110, 111, 112
  688. };
  689. static const s16 hsv_blue_y[] = {
  690. -11, -13, -15, -17, -19, -21, -23, -25,
  691. -27, -29, -31, -33, -35, -37, -39, -41,
  692. -43, -45, -46, -48, -50, -52, -54, -55,
  693. -57, -59, -61, -62, -64, -66, -67, -69,
  694. -71, -72, -74, -75, -77, -78, -80, -81,
  695. -83, -84, -86, -87, -88, -90, -91, -92,
  696. -93, -95, -96, -97, -98, -99, -100, -101,
  697. -102, -103, -104, -105, -106, -106, -107, -108,
  698. -109, -109, -110, -111, -111, -112, -112, -113,
  699. -113, -114, -114, -114, -115, -115, -115, -115,
  700. -116, -116, -116, -116, -116, -116, -116, -116,
  701. -116, -115, -115, -115, -115, -114, -114, -114,
  702. -113, -113, -112, -112, -111, -111, -110, -110,
  703. -109, -108, -108, -107, -106, -105, -104, -103,
  704. -102, -101, -100, -99, -98, -97, -96, -95,
  705. -94, -93, -91, -90, -89, -88, -86, -85,
  706. -84, -82, -81, -79, -78, -76, -75, -73,
  707. -71, -70, -68, -67, -65, -63, -62, -60,
  708. -58, -56, -55, -53, -51, -49, -47, -45,
  709. -44, -42, -40, -38, -36, -34, -32, -30,
  710. -28, -26, -24, -22, -20, -18, -16, -14,
  711. -12, -10, -8, -6, -4, -2, 0, 1,
  712. 3, 5, 7, 9, 11, 13, 15, 17,
  713. 19, 21, 23, 25, 27, 29, 31, 33,
  714. 35, 37, 39, 41, 43, 45, 46, 48,
  715. 50, 52, 54, 55, 57, 59, 61, 62,
  716. 64, 66, 67, 69, 71, 72, 74, 75,
  717. 77, 78, 80, 81, 83, 84, 86, 87,
  718. 88, 90, 91, 92, 93, 95, 96, 97,
  719. 98, 99, 100, 101, 102, 103, 104, 105,
  720. 106, 106, 107, 108, 109, 109, 110, 111,
  721. 111, 112, 112, 113, 113, 114, 114, 114,
  722. 115, 115, 115, 115, 116, 116, 116, 116,
  723. 116, 116, 116, 116, 116, 115, 115, 115,
  724. 115, 114, 114, 114, 113, 113, 112, 112,
  725. 111, 111, 110, 110, 109, 108, 108, 107,
  726. 106, 105, 104, 103, 102, 101, 100, 99,
  727. 98, 97, 96, 95, 94, 93, 91, 90,
  728. 89, 88, 86, 85, 84, 82, 81, 79,
  729. 78, 76, 75, 73, 71, 70, 68, 67,
  730. 65, 63, 62, 60, 58, 56, 55, 53,
  731. 51, 49, 47, 45, 44, 42, 40, 38,
  732. 36, 34, 32, 30, 28, 26, 24, 22,
  733. 20, 18, 16, 14, 12, 10, 8, 6,
  734. 4, 2, 0, -1, -3, -5, -7, -9, -11
  735. };
  736. static u16 i2c_ident[] = {
  737. V4L2_IDENT_OV9650,
  738. V4L2_IDENT_OV9655,
  739. V4L2_IDENT_SOI968,
  740. V4L2_IDENT_OV7660,
  741. V4L2_IDENT_OV7670,
  742. V4L2_IDENT_MT9V011,
  743. V4L2_IDENT_MT9V111,
  744. V4L2_IDENT_MT9V112,
  745. V4L2_IDENT_MT9M001C12ST,
  746. V4L2_IDENT_MT9M111,
  747. V4L2_IDENT_MT9M112,
  748. V4L2_IDENT_HV7131R,
  749. };
  750. static u16 bridge_init[][2] = {
  751. {0x1000, 0x78}, {0x1001, 0x40}, {0x1002, 0x1c},
  752. {0x1020, 0x80}, {0x1061, 0x01}, {0x1067, 0x40},
  753. {0x1068, 0x30}, {0x1069, 0x20}, {0x106a, 0x10},
  754. {0x106b, 0x08}, {0x1188, 0x87}, {0x11a1, 0x00},
  755. {0x11a2, 0x00}, {0x11a3, 0x6a}, {0x11a4, 0x50},
  756. {0x11ab, 0x00}, {0x11ac, 0x00}, {0x11ad, 0x50},
  757. {0x11ae, 0x3c}, {0x118a, 0x04}, {0x0395, 0x04},
  758. {0x11b8, 0x3a}, {0x118b, 0x0e}, {0x10f7, 0x05},
  759. {0x10f8, 0x14}, {0x10fa, 0xff}, {0x10f9, 0x00},
  760. {0x11ba, 0x0a}, {0x11a5, 0x2d}, {0x11a6, 0x2d},
  761. {0x11a7, 0x3a}, {0x11a8, 0x05}, {0x11a9, 0x04},
  762. {0x11aa, 0x3f}, {0x11af, 0x28}, {0x11b0, 0xd8},
  763. {0x11b1, 0x14}, {0x11b2, 0xec}, {0x11b3, 0x32},
  764. {0x11b4, 0xdd}, {0x11b5, 0x32}, {0x11b6, 0xdd},
  765. {0x10e0, 0x2c}, {0x11bc, 0x40}, {0x11bd, 0x01},
  766. {0x11be, 0xf0}, {0x11bf, 0x00}, {0x118c, 0x1f},
  767. {0x118d, 0x1f}, {0x118e, 0x1f}, {0x118f, 0x1f},
  768. {0x1180, 0x01}, {0x1181, 0x00}, {0x1182, 0x01},
  769. {0x1183, 0x00}, {0x1184, 0x50}, {0x1185, 0x80},
  770. {0x1007, 0x00}
  771. };
  772. /* Gain = (bit[3:0] / 16 + 1) * (bit[4] + 1) * (bit[5] + 1) * (bit[6] + 1) */
  773. static u8 ov_gain[] = {
  774. 0x00 /* 1x */, 0x04 /* 1.25x */, 0x08 /* 1.5x */, 0x0c /* 1.75x */,
  775. 0x10 /* 2x */, 0x12 /* 2.25x */, 0x14 /* 2.5x */, 0x16 /* 2.75x */,
  776. 0x18 /* 3x */, 0x1a /* 3.25x */, 0x1c /* 3.5x */, 0x1e /* 3.75x */,
  777. 0x30 /* 4x */, 0x31 /* 4.25x */, 0x32 /* 4.5x */, 0x33 /* 4.75x */,
  778. 0x34 /* 5x */, 0x35 /* 5.25x */, 0x36 /* 5.5x */, 0x37 /* 5.75x */,
  779. 0x38 /* 6x */, 0x39 /* 6.25x */, 0x3a /* 6.5x */, 0x3b /* 6.75x */,
  780. 0x3c /* 7x */, 0x3d /* 7.25x */, 0x3e /* 7.5x */, 0x3f /* 7.75x */,
  781. 0x70 /* 8x */
  782. };
  783. /* Gain = (bit[8] + 1) * (bit[7] + 1) * (bit[6:0] * 0.03125) */
  784. static u16 micron1_gain[] = {
  785. /* 1x 1.25x 1.5x 1.75x */
  786. 0x0020, 0x0028, 0x0030, 0x0038,
  787. /* 2x 2.25x 2.5x 2.75x */
  788. 0x00a0, 0x00a4, 0x00a8, 0x00ac,
  789. /* 3x 3.25x 3.5x 3.75x */
  790. 0x00b0, 0x00b4, 0x00b8, 0x00bc,
  791. /* 4x 4.25x 4.5x 4.75x */
  792. 0x00c0, 0x00c4, 0x00c8, 0x00cc,
  793. /* 5x 5.25x 5.5x 5.75x */
  794. 0x00d0, 0x00d4, 0x00d8, 0x00dc,
  795. /* 6x 6.25x 6.5x 6.75x */
  796. 0x00e0, 0x00e4, 0x00e8, 0x00ec,
  797. /* 7x 7.25x 7.5x 7.75x */
  798. 0x00f0, 0x00f4, 0x00f8, 0x00fc,
  799. /* 8x */
  800. 0x01c0
  801. };
  802. /* mt9m001 sensor uses a different gain formula then other micron sensors */
  803. /* Gain = (bit[6] + 1) * (bit[5-0] * 0.125) */
  804. static u16 micron2_gain[] = {
  805. /* 1x 1.25x 1.5x 1.75x */
  806. 0x0008, 0x000a, 0x000c, 0x000e,
  807. /* 2x 2.25x 2.5x 2.75x */
  808. 0x0010, 0x0012, 0x0014, 0x0016,
  809. /* 3x 3.25x 3.5x 3.75x */
  810. 0x0018, 0x001a, 0x001c, 0x001e,
  811. /* 4x 4.25x 4.5x 4.75x */
  812. 0x0020, 0x0051, 0x0052, 0x0053,
  813. /* 5x 5.25x 5.5x 5.75x */
  814. 0x0054, 0x0055, 0x0056, 0x0057,
  815. /* 6x 6.25x 6.5x 6.75x */
  816. 0x0058, 0x0059, 0x005a, 0x005b,
  817. /* 7x 7.25x 7.5x 7.75x */
  818. 0x005c, 0x005d, 0x005e, 0x005f,
  819. /* 8x */
  820. 0x0060
  821. };
  822. /* Gain = .5 + bit[7:0] / 16 */
  823. static u8 hv7131r_gain[] = {
  824. 0x08 /* 1x */, 0x0c /* 1.25x */, 0x10 /* 1.5x */, 0x14 /* 1.75x */,
  825. 0x18 /* 2x */, 0x1c /* 2.25x */, 0x20 /* 2.5x */, 0x24 /* 2.75x */,
  826. 0x28 /* 3x */, 0x2c /* 3.25x */, 0x30 /* 3.5x */, 0x34 /* 3.75x */,
  827. 0x38 /* 4x */, 0x3c /* 4.25x */, 0x40 /* 4.5x */, 0x44 /* 4.75x */,
  828. 0x48 /* 5x */, 0x4c /* 5.25x */, 0x50 /* 5.5x */, 0x54 /* 5.75x */,
  829. 0x58 /* 6x */, 0x5c /* 6.25x */, 0x60 /* 6.5x */, 0x64 /* 6.75x */,
  830. 0x68 /* 7x */, 0x6c /* 7.25x */, 0x70 /* 7.5x */, 0x74 /* 7.75x */,
  831. 0x78 /* 8x */
  832. };
  833. static struct i2c_reg_u8 soi968_init[] = {
  834. {0x12, 0x80}, {0x0c, 0x00}, {0x0f, 0x1f},
  835. {0x11, 0x80}, {0x38, 0x52}, {0x1e, 0x00},
  836. {0x33, 0x08}, {0x35, 0x8c}, {0x36, 0x0c},
  837. {0x37, 0x04}, {0x45, 0x04}, {0x47, 0xff},
  838. {0x3e, 0x00}, {0x3f, 0x00}, {0x3b, 0x20},
  839. {0x3a, 0x96}, {0x3d, 0x0a}, {0x14, 0x8e},
  840. {0x13, 0x8b}, {0x12, 0x40}, {0x17, 0x13},
  841. {0x18, 0x63}, {0x19, 0x01}, {0x1a, 0x79},
  842. {0x32, 0x24}, {0x03, 0x00}, {0x11, 0x40},
  843. {0x2a, 0x10}, {0x2b, 0xe0}, {0x10, 0x32},
  844. {0x00, 0x00}, {0x01, 0x80}, {0x02, 0x80},
  845. };
  846. static struct i2c_reg_u8 ov7660_init[] = {
  847. {0x0e, 0x80}, {0x0d, 0x08}, {0x0f, 0xc3},
  848. {0x04, 0xc3}, {0x10, 0x40}, {0x11, 0x40},
  849. {0x12, 0x05}, {0x13, 0xba}, {0x14, 0x2a},
  850. /* HDG Set hstart and hstop, datasheet default 0x11, 0x61, using
  851. 0x10, 0x61 and sd->hstart, vstart = 3, fixes ugly colored borders */
  852. {0x17, 0x10}, {0x18, 0x61},
  853. {0x37, 0x0f}, {0x38, 0x02}, {0x39, 0x43},
  854. {0x3a, 0x00}, {0x69, 0x90}, {0x2d, 0xf6},
  855. {0x2e, 0x0b}, {0x01, 0x78}, {0x02, 0x50},
  856. };
  857. static struct i2c_reg_u8 ov7670_init[] = {
  858. {0x12, 0x80}, {0x11, 0x80}, {0x3a, 0x04}, {0x12, 0x01},
  859. {0x32, 0xb6}, {0x03, 0x0a}, {0x0c, 0x00}, {0x3e, 0x00},
  860. {0x70, 0x3a}, {0x71, 0x35}, {0x72, 0x11}, {0x73, 0xf0},
  861. {0xa2, 0x02}, {0x13, 0xe0}, {0x00, 0x00}, {0x10, 0x00},
  862. {0x0d, 0x40}, {0x14, 0x28}, {0xa5, 0x05}, {0xab, 0x07},
  863. {0x24, 0x95}, {0x25, 0x33}, {0x26, 0xe3}, {0x9f, 0x75},
  864. {0xa0, 0x65}, {0xa1, 0x0b}, {0xa6, 0xd8}, {0xa7, 0xd8},
  865. {0xa8, 0xf0}, {0xa9, 0x90}, {0xaa, 0x94}, {0x13, 0xe5},
  866. {0x0e, 0x61}, {0x0f, 0x4b}, {0x16, 0x02}, {0x1e, 0x27},
  867. {0x21, 0x02}, {0x22, 0x91}, {0x29, 0x07}, {0x33, 0x0b},
  868. {0x35, 0x0b}, {0x37, 0x1d}, {0x38, 0x71}, {0x39, 0x2a},
  869. {0x3c, 0x78}, {0x4d, 0x40}, {0x4e, 0x20}, {0x69, 0x00},
  870. {0x74, 0x19}, {0x8d, 0x4f}, {0x8e, 0x00}, {0x8f, 0x00},
  871. {0x90, 0x00}, {0x91, 0x00}, {0x96, 0x00}, {0x9a, 0x80},
  872. {0xb0, 0x84}, {0xb1, 0x0c}, {0xb2, 0x0e}, {0xb3, 0x82},
  873. {0xb8, 0x0a}, {0x43, 0x0a}, {0x44, 0xf0}, {0x45, 0x20},
  874. {0x46, 0x7d}, {0x47, 0x29}, {0x48, 0x4a}, {0x59, 0x8c},
  875. {0x5a, 0xa5}, {0x5b, 0xde}, {0x5c, 0x96}, {0x5d, 0x66},
  876. {0x5e, 0x10}, {0x6c, 0x0a}, {0x6d, 0x55}, {0x6e, 0x11},
  877. {0x6f, 0x9e}, {0x6a, 0x40}, {0x01, 0x40}, {0x02, 0x40},
  878. {0x13, 0xe7}, {0x4f, 0x6e}, {0x50, 0x70}, {0x51, 0x02},
  879. {0x52, 0x1d}, {0x53, 0x56}, {0x54, 0x73}, {0x55, 0x0a},
  880. {0x56, 0x55}, {0x57, 0x80}, {0x58, 0x9e}, {0x41, 0x08},
  881. {0x3f, 0x02}, {0x75, 0x03}, {0x76, 0x63}, {0x4c, 0x04},
  882. {0x77, 0x06}, {0x3d, 0x02}, {0x4b, 0x09}, {0xc9, 0x30},
  883. {0x41, 0x08}, {0x56, 0x48}, {0x34, 0x11}, {0xa4, 0x88},
  884. {0x96, 0x00}, {0x97, 0x30}, {0x98, 0x20}, {0x99, 0x30},
  885. {0x9a, 0x84}, {0x9b, 0x29}, {0x9c, 0x03}, {0x9d, 0x99},
  886. {0x9e, 0x7f}, {0x78, 0x04}, {0x79, 0x01}, {0xc8, 0xf0},
  887. {0x79, 0x0f}, {0xc8, 0x00}, {0x79, 0x10}, {0xc8, 0x7e},
  888. {0x79, 0x0a}, {0xc8, 0x80}, {0x79, 0x0b}, {0xc8, 0x01},
  889. {0x79, 0x0c}, {0xc8, 0x0f}, {0x79, 0x0d}, {0xc8, 0x20},
  890. {0x79, 0x09}, {0xc8, 0x80}, {0x79, 0x02}, {0xc8, 0xc0},
  891. {0x79, 0x03}, {0xc8, 0x40}, {0x79, 0x05}, {0xc8, 0x30},
  892. {0x79, 0x26}, {0x62, 0x20}, {0x63, 0x00}, {0x64, 0x06},
  893. {0x65, 0x00}, {0x66, 0x05}, {0x94, 0x05}, {0x95, 0x0a},
  894. {0x17, 0x13}, {0x18, 0x01}, {0x19, 0x02}, {0x1a, 0x7a},
  895. {0x46, 0x59}, {0x47, 0x30}, {0x58, 0x9a}, {0x59, 0x84},
  896. {0x5a, 0x91}, {0x5b, 0x57}, {0x5c, 0x75}, {0x5d, 0x6d},
  897. {0x5e, 0x13}, {0x64, 0x07}, {0x94, 0x07}, {0x95, 0x0d},
  898. {0xa6, 0xdf}, {0xa7, 0xdf}, {0x48, 0x4d}, {0x51, 0x00},
  899. {0x6b, 0x0a}, {0x11, 0x80}, {0x2a, 0x00}, {0x2b, 0x00},
  900. {0x92, 0x00}, {0x93, 0x00}, {0x55, 0x0a}, {0x56, 0x60},
  901. {0x4f, 0x6e}, {0x50, 0x70}, {0x51, 0x00}, {0x52, 0x1d},
  902. {0x53, 0x56}, {0x54, 0x73}, {0x58, 0x9a}, {0x4f, 0x6e},
  903. {0x50, 0x70}, {0x51, 0x00}, {0x52, 0x1d}, {0x53, 0x56},
  904. {0x54, 0x73}, {0x58, 0x9a}, {0x3f, 0x01}, {0x7b, 0x03},
  905. {0x7c, 0x09}, {0x7d, 0x16}, {0x7e, 0x38}, {0x7f, 0x47},
  906. {0x80, 0x53}, {0x81, 0x5e}, {0x82, 0x6a}, {0x83, 0x74},
  907. {0x84, 0x80}, {0x85, 0x8c}, {0x86, 0x9b}, {0x87, 0xb2},
  908. {0x88, 0xcc}, {0x89, 0xe5}, {0x7a, 0x24}, {0x3b, 0x00},
  909. {0x9f, 0x76}, {0xa0, 0x65}, {0x13, 0xe2}, {0x6b, 0x0a},
  910. {0x11, 0x80}, {0x2a, 0x00}, {0x2b, 0x00}, {0x92, 0x00},
  911. {0x93, 0x00},
  912. };
  913. static struct i2c_reg_u8 ov9650_init[] = {
  914. {0x12, 0x80}, {0x00, 0x00}, {0x01, 0x78},
  915. {0x02, 0x78}, {0x03, 0x36}, {0x04, 0x03},
  916. {0x05, 0x00}, {0x06, 0x00}, {0x08, 0x00},
  917. {0x09, 0x01}, {0x0c, 0x00}, {0x0d, 0x00},
  918. {0x0e, 0xa0}, {0x0f, 0x52}, {0x10, 0x7c},
  919. {0x11, 0x80}, {0x12, 0x45}, {0x13, 0xc2},
  920. {0x14, 0x2e}, {0x15, 0x00}, {0x16, 0x07},
  921. {0x17, 0x24}, {0x18, 0xc5}, {0x19, 0x00},
  922. {0x1a, 0x3c}, {0x1b, 0x00}, {0x1e, 0x04},
  923. {0x1f, 0x00}, {0x24, 0x78}, {0x25, 0x68},
  924. {0x26, 0xd4}, {0x27, 0x80}, {0x28, 0x80},
  925. {0x29, 0x30}, {0x2a, 0x00}, {0x2b, 0x00},
  926. {0x2c, 0x80}, {0x2d, 0x00}, {0x2e, 0x00},
  927. {0x2f, 0x00}, {0x30, 0x08}, {0x31, 0x30},
  928. {0x32, 0x84}, {0x33, 0xe2}, {0x34, 0xbf},
  929. {0x35, 0x81}, {0x36, 0xf9}, {0x37, 0x00},
  930. {0x38, 0x93}, {0x39, 0x50}, {0x3a, 0x01},
  931. {0x3b, 0x01}, {0x3c, 0x73}, {0x3d, 0x19},
  932. {0x3e, 0x0b}, {0x3f, 0x80}, {0x40, 0xc1},
  933. {0x41, 0x00}, {0x42, 0x08}, {0x67, 0x80},
  934. {0x68, 0x80}, {0x69, 0x40}, {0x6a, 0x00},
  935. {0x6b, 0x0a}, {0x8b, 0x06}, {0x8c, 0x20},
  936. {0x8d, 0x00}, {0x8e, 0x00}, {0x8f, 0xdf},
  937. {0x92, 0x00}, {0x93, 0x00}, {0x94, 0x88},
  938. {0x95, 0x88}, {0x96, 0x04}, {0xa1, 0x00},
  939. {0xa5, 0x80}, {0xa8, 0x80}, {0xa9, 0xb8},
  940. {0xaa, 0x92}, {0xab, 0x0a},
  941. };
  942. static struct i2c_reg_u8 ov9655_init[] = {
  943. {0x12, 0x80}, {0x0e, 0x61}, {0x11, 0x80}, {0x13, 0xba},
  944. {0x14, 0x2e}, {0x16, 0x24}, {0x1e, 0x04}, {0x27, 0x08},
  945. {0x28, 0x08}, {0x29, 0x15}, {0x2c, 0x08}, {0x34, 0x3d},
  946. {0x35, 0x00}, {0x38, 0x12}, {0x0f, 0x42}, {0x39, 0x57},
  947. {0x3a, 0x00}, {0x3b, 0xcc}, {0x3c, 0x0c}, {0x3d, 0x19},
  948. {0x3e, 0x0c}, {0x3f, 0x01}, {0x41, 0x40}, {0x42, 0x80},
  949. {0x45, 0x46}, {0x46, 0x62}, {0x47, 0x2a}, {0x48, 0x3c},
  950. {0x4a, 0xf0}, {0x4b, 0xdc}, {0x4c, 0xdc}, {0x4d, 0xdc},
  951. {0x4e, 0xdc}, {0x6c, 0x04}, {0x6f, 0x9e}, {0x70, 0x05},
  952. {0x71, 0x78}, {0x77, 0x02}, {0x8a, 0x23}, {0x90, 0x7e},
  953. {0x91, 0x7c}, {0x9f, 0x6e}, {0xa0, 0x6e}, {0xa5, 0x68},
  954. {0xa6, 0x60}, {0xa8, 0xc1}, {0xa9, 0xfa}, {0xaa, 0x92},
  955. {0xab, 0x04}, {0xac, 0x80}, {0xad, 0x80}, {0xae, 0x80},
  956. {0xaf, 0x80}, {0xb2, 0xf2}, {0xb3, 0x20}, {0xb5, 0x00},
  957. {0xb6, 0xaf}, {0xbb, 0xae}, {0xbc, 0x44}, {0xbd, 0x44},
  958. {0xbe, 0x3b}, {0xbf, 0x3a}, {0xc1, 0xc8}, {0xc2, 0x01},
  959. {0xc4, 0x00}, {0xc6, 0x85}, {0xc7, 0x81}, {0xc9, 0xe0},
  960. {0xca, 0xe8}, {0xcc, 0xd8}, {0xcd, 0x93}, {0x2d, 0x00},
  961. {0x2e, 0x00}, {0x01, 0x80}, {0x02, 0x80}, {0x12, 0x61},
  962. {0x36, 0xfa}, {0x8c, 0x8d}, {0xc0, 0xaa}, {0x69, 0x0a},
  963. {0x03, 0x09}, {0x17, 0x16}, {0x18, 0x6e}, {0x19, 0x01},
  964. {0x1a, 0x3e}, {0x32, 0x09}, {0x2a, 0x10}, {0x2b, 0x0a},
  965. {0x92, 0x00}, {0x93, 0x00}, {0xa1, 0x00}, {0x10, 0x7c},
  966. {0x04, 0x03}, {0x00, 0x13},
  967. };
  968. static struct i2c_reg_u16 mt9v112_init[] = {
  969. {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0020},
  970. {0x34, 0xc019}, {0x0a, 0x0011}, {0x0b, 0x000b},
  971. {0x20, 0x0703}, {0x35, 0x2022}, {0xf0, 0x0001},
  972. {0x05, 0x0000}, {0x06, 0x340c}, {0x3b, 0x042a},
  973. {0x3c, 0x0400}, {0xf0, 0x0002}, {0x2e, 0x0c58},
  974. {0x5b, 0x0001}, {0xc8, 0x9f0b}, {0xf0, 0x0001},
  975. {0x9b, 0x5300}, {0xf0, 0x0000}, {0x2b, 0x0020},
  976. {0x2c, 0x002a}, {0x2d, 0x0032}, {0x2e, 0x0020},
  977. {0x09, 0x01dc}, {0x01, 0x000c}, {0x02, 0x0020},
  978. {0x03, 0x01e0}, {0x04, 0x0280}, {0x06, 0x000c},
  979. {0x05, 0x0098}, {0x20, 0x0703}, {0x09, 0x01f2},
  980. {0x2b, 0x00a0}, {0x2c, 0x00a0}, {0x2d, 0x00a0},
  981. {0x2e, 0x00a0}, {0x01, 0x000c}, {0x02, 0x0020},
  982. {0x03, 0x01e0}, {0x04, 0x0280}, {0x06, 0x000c},
  983. {0x05, 0x0098}, {0x09, 0x01c1}, {0x2b, 0x00ae},
  984. {0x2c, 0x00ae}, {0x2d, 0x00ae}, {0x2e, 0x00ae},
  985. };
  986. static struct i2c_reg_u16 mt9v111_init[] = {
  987. {0x01, 0x0004}, {0x0d, 0x0001}, {0x0d, 0x0000},
  988. {0x01, 0x0001}, {0x05, 0x0004}, {0x2d, 0xe0a0},
  989. {0x2e, 0x0c64}, {0x2f, 0x0064}, {0x06, 0x600e},
  990. {0x08, 0x0480}, {0x01, 0x0004}, {0x02, 0x0016},
  991. {0x03, 0x01e7}, {0x04, 0x0287}, {0x05, 0x0004},
  992. {0x06, 0x002d}, {0x07, 0x3002}, {0x08, 0x0008},
  993. {0x0e, 0x0008}, {0x20, 0x0000}
  994. };
  995. static struct i2c_reg_u16 mt9v011_init[] = {
  996. {0x07, 0x0002}, {0x0d, 0x0001}, {0x0d, 0x0000},
  997. {0x01, 0x0008}, {0x02, 0x0016}, {0x03, 0x01e1},
  998. {0x04, 0x0281}, {0x05, 0x0083}, {0x06, 0x0006},
  999. {0x0d, 0x0002}, {0x0a, 0x0000}, {0x0b, 0x0000},
  1000. {0x0c, 0x0000}, {0x0d, 0x0000}, {0x0e, 0x0000},
  1001. {0x0f, 0x0000}, {0x10, 0x0000}, {0x11, 0x0000},
  1002. {0x12, 0x0000}, {0x13, 0x0000}, {0x14, 0x0000},
  1003. {0x15, 0x0000}, {0x16, 0x0000}, {0x17, 0x0000},
  1004. {0x18, 0x0000}, {0x19, 0x0000}, {0x1a, 0x0000},
  1005. {0x1b, 0x0000}, {0x1c, 0x0000}, {0x1d, 0x0000},
  1006. {0x32, 0x0000}, {0x20, 0x1101}, {0x21, 0x0000},
  1007. {0x22, 0x0000}, {0x23, 0x0000}, {0x24, 0x0000},
  1008. {0x25, 0x0000}, {0x26, 0x0000}, {0x27, 0x0024},
  1009. {0x2f, 0xf7b0}, {0x30, 0x0005}, {0x31, 0x0000},
  1010. {0x32, 0x0000}, {0x33, 0x0000}, {0x34, 0x0100},
  1011. {0x3d, 0x068f}, {0x40, 0x01e0}, {0x41, 0x00d1},
  1012. {0x44, 0x0082}, {0x5a, 0x0000}, {0x5b, 0x0000},
  1013. {0x5c, 0x0000}, {0x5d, 0x0000}, {0x5e, 0x0000},
  1014. {0x5f, 0xa31d}, {0x62, 0x0611}, {0x0a, 0x0000},
  1015. {0x06, 0x0029}, {0x05, 0x0009}, {0x20, 0x1101},
  1016. {0x20, 0x1101}, {0x09, 0x0064}, {0x07, 0x0003},
  1017. {0x2b, 0x0033}, {0x2c, 0x00a0}, {0x2d, 0x00a0},
  1018. {0x2e, 0x0033}, {0x07, 0x0002}, {0x06, 0x0000},
  1019. {0x06, 0x0029}, {0x05, 0x0009},
  1020. };
  1021. static struct i2c_reg_u16 mt9m001_init[] = {
  1022. {0x0d, 0x0001},
  1023. {0x0d, 0x0000},
  1024. {0x04, 0x0500}, /* hres = 1280 */
  1025. {0x03, 0x0400}, /* vres = 1024 */
  1026. {0x20, 0x1100},
  1027. {0x06, 0x0010},
  1028. {0x2b, 0x0024},
  1029. {0x2e, 0x0024},
  1030. {0x35, 0x0024},
  1031. {0x2d, 0x0020},
  1032. {0x2c, 0x0020},
  1033. {0x09, 0x0ad4},
  1034. {0x35, 0x0057},
  1035. };
  1036. static struct i2c_reg_u16 mt9m111_init[] = {
  1037. {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0008},
  1038. {0xf0, 0x0001}, {0x3a, 0x4300}, {0x9b, 0x4300},
  1039. {0x06, 0x708e}, {0xf0, 0x0002}, {0x2e, 0x0a1e},
  1040. {0xf0, 0x0000},
  1041. };
  1042. static struct i2c_reg_u16 mt9m112_init[] = {
  1043. {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0008},
  1044. {0xf0, 0x0001}, {0x3a, 0x4300}, {0x9b, 0x4300},
  1045. {0x06, 0x708e}, {0xf0, 0x0002}, {0x2e, 0x0a1e},
  1046. {0xf0, 0x0000},
  1047. };
  1048. static struct i2c_reg_u8 hv7131r_init[] = {
  1049. {0x02, 0x08}, {0x02, 0x00}, {0x01, 0x08},
  1050. {0x02, 0x00}, {0x20, 0x00}, {0x21, 0xd0},
  1051. {0x22, 0x00}, {0x23, 0x09}, {0x01, 0x08},
  1052. {0x01, 0x08}, {0x01, 0x08}, {0x25, 0x07},
  1053. {0x26, 0xc3}, {0x27, 0x50}, {0x30, 0x62},
  1054. {0x31, 0x10}, {0x32, 0x06}, {0x33, 0x10},
  1055. {0x20, 0x00}, {0x21, 0xd0}, {0x22, 0x00},
  1056. {0x23, 0x09}, {0x01, 0x08},
  1057. };
  1058. static int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
  1059. {
  1060. struct usb_device *dev = gspca_dev->dev;
  1061. int result;
  1062. result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  1063. 0x00,
  1064. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1065. reg,
  1066. 0x00,
  1067. gspca_dev->usb_buf,
  1068. length,
  1069. 500);
  1070. if (unlikely(result < 0 || result != length)) {
  1071. err("Read register failed 0x%02X", reg);
  1072. return -EIO;
  1073. }
  1074. return 0;
  1075. }
  1076. static int reg_w(struct gspca_dev *gspca_dev, u16 reg,
  1077. const u8 *buffer, int length)
  1078. {
  1079. struct usb_device *dev = gspca_dev->dev;
  1080. int result;
  1081. memcpy(gspca_dev->usb_buf, buffer, length);
  1082. result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  1083. 0x08,
  1084. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1085. reg,
  1086. 0x00,
  1087. gspca_dev->usb_buf,
  1088. length,
  1089. 500);
  1090. if (unlikely(result < 0 || result != length)) {
  1091. err("Write register failed index 0x%02X", reg);
  1092. return -EIO;
  1093. }
  1094. return 0;
  1095. }
  1096. static int reg_w1(struct gspca_dev *gspca_dev, u16 reg, const u8 value)
  1097. {
  1098. u8 data[1] = {value};
  1099. return reg_w(gspca_dev, reg, data, 1);
  1100. }
  1101. static int i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer)
  1102. {
  1103. int i;
  1104. reg_w(gspca_dev, 0x10c0, buffer, 8);
  1105. for (i = 0; i < 5; i++) {
  1106. reg_r(gspca_dev, 0x10c0, 1);
  1107. if (gspca_dev->usb_buf[0] & 0x04) {
  1108. if (gspca_dev->usb_buf[0] & 0x08)
  1109. return -EIO;
  1110. return 0;
  1111. }
  1112. msleep(1);
  1113. }
  1114. return -EIO;
  1115. }
  1116. static int i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1117. {
  1118. struct sd *sd = (struct sd *) gspca_dev;
  1119. u8 row[8];
  1120. /*
  1121. * from the point of view of the bridge, the length
  1122. * includes the address
  1123. */
  1124. row[0] = 0x81 | (2 << 4);
  1125. row[1] = sd->i2c_addr;
  1126. row[2] = reg;
  1127. row[3] = val;
  1128. row[4] = 0x00;
  1129. row[5] = 0x00;
  1130. row[6] = 0x00;
  1131. row[7] = 0x10;
  1132. return i2c_w(gspca_dev, row);
  1133. }
  1134. static int i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val)
  1135. {
  1136. struct sd *sd = (struct sd *) gspca_dev;
  1137. u8 row[8];
  1138. /*
  1139. * from the point of view of the bridge, the length
  1140. * includes the address
  1141. */
  1142. row[0] = 0x81 | (3 << 4);
  1143. row[1] = sd->i2c_addr;
  1144. row[2] = reg;
  1145. row[3] = (val >> 8) & 0xff;
  1146. row[4] = val & 0xff;
  1147. row[5] = 0x00;
  1148. row[6] = 0x00;
  1149. row[7] = 0x10;
  1150. return i2c_w(gspca_dev, row);
  1151. }
  1152. static int i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val)
  1153. {
  1154. struct sd *sd = (struct sd *) gspca_dev;
  1155. u8 row[8];
  1156. row[0] = 0x81 | (1 << 4);
  1157. row[1] = sd->i2c_addr;
  1158. row[2] = reg;
  1159. row[3] = 0;
  1160. row[4] = 0;
  1161. row[5] = 0;
  1162. row[6] = 0;
  1163. row[7] = 0x10;
  1164. if (i2c_w(gspca_dev, row) < 0)
  1165. return -EIO;
  1166. row[0] = 0x81 | (1 << 4) | 0x02;
  1167. row[2] = 0;
  1168. if (i2c_w(gspca_dev, row) < 0)
  1169. return -EIO;
  1170. if (reg_r(gspca_dev, 0x10c2, 5) < 0)
  1171. return -EIO;
  1172. *val = gspca_dev->usb_buf[4];
  1173. return 0;
  1174. }
  1175. static int i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
  1176. {
  1177. struct sd *sd = (struct sd *) gspca_dev;
  1178. u8 row[8];
  1179. row[0] = 0x81 | (1 << 4);
  1180. row[1] = sd->i2c_addr;
  1181. row[2] = reg;
  1182. row[3] = 0;
  1183. row[4] = 0;
  1184. row[5] = 0;
  1185. row[6] = 0;
  1186. row[7] = 0x10;
  1187. if (i2c_w(gspca_dev, row) < 0)
  1188. return -EIO;
  1189. row[0] = 0x81 | (2 << 4) | 0x02;
  1190. row[2] = 0;
  1191. if (i2c_w(gspca_dev, row) < 0)
  1192. return -EIO;
  1193. if (reg_r(gspca_dev, 0x10c2, 5) < 0)
  1194. return -EIO;
  1195. *val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1196. return 0;
  1197. }
  1198. static int ov9650_init_sensor(struct gspca_dev *gspca_dev)
  1199. {
  1200. int i;
  1201. u16 id;
  1202. struct sd *sd = (struct sd *) gspca_dev;
  1203. if (i2c_r2(gspca_dev, 0x1c, &id) < 0)
  1204. return -EINVAL;
  1205. if (id != 0x7fa2) {
  1206. err("sensor id for ov9650 doesn't match (0x%04x)", id);
  1207. return -ENODEV;
  1208. }
  1209. for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) {
  1210. if (i2c_w1(gspca_dev, ov9650_init[i].reg,
  1211. ov9650_init[i].val) < 0) {
  1212. err("OV9650 sensor initialization failed");
  1213. return -ENODEV;
  1214. }
  1215. }
  1216. sd->hstart = 1;
  1217. sd->vstart = 7;
  1218. return 0;
  1219. }
  1220. static int ov9655_init_sensor(struct gspca_dev *gspca_dev)
  1221. {
  1222. int i;
  1223. struct sd *sd = (struct sd *) gspca_dev;
  1224. for (i = 0; i < ARRAY_SIZE(ov9655_init); i++) {
  1225. if (i2c_w1(gspca_dev, ov9655_init[i].reg,
  1226. ov9655_init[i].val) < 0) {
  1227. err("OV9655 sensor initialization failed");
  1228. return -ENODEV;
  1229. }
  1230. }
  1231. /* disable hflip and vflip */
  1232. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
  1233. sd->hstart = 1;
  1234. sd->vstart = 2;
  1235. return 0;
  1236. }
  1237. static int soi968_init_sensor(struct gspca_dev *gspca_dev)
  1238. {
  1239. int i;
  1240. struct sd *sd = (struct sd *) gspca_dev;
  1241. for (i = 0; i < ARRAY_SIZE(soi968_init); i++) {
  1242. if (i2c_w1(gspca_dev, soi968_init[i].reg,
  1243. soi968_init[i].val) < 0) {
  1244. err("SOI968 sensor initialization failed");
  1245. return -ENODEV;
  1246. }
  1247. }
  1248. /* disable hflip and vflip */
  1249. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX)
  1250. | (1 << EXPOSURE_IDX);
  1251. sd->hstart = 60;
  1252. sd->vstart = 11;
  1253. return 0;
  1254. }
  1255. static int ov7660_init_sensor(struct gspca_dev *gspca_dev)
  1256. {
  1257. int i;
  1258. struct sd *sd = (struct sd *) gspca_dev;
  1259. for (i = 0; i < ARRAY_SIZE(ov7660_init); i++) {
  1260. if (i2c_w1(gspca_dev, ov7660_init[i].reg,
  1261. ov7660_init[i].val) < 0) {
  1262. err("OV7660 sensor initialization failed");
  1263. return -ENODEV;
  1264. }
  1265. }
  1266. sd->hstart = 3;
  1267. sd->vstart = 3;
  1268. return 0;
  1269. }
  1270. static int ov7670_init_sensor(struct gspca_dev *gspca_dev)
  1271. {
  1272. int i;
  1273. struct sd *sd = (struct sd *) gspca_dev;
  1274. for (i = 0; i < ARRAY_SIZE(ov7670_init); i++) {
  1275. if (i2c_w1(gspca_dev, ov7670_init[i].reg,
  1276. ov7670_init[i].val) < 0) {
  1277. err("OV7670 sensor initialization failed");
  1278. return -ENODEV;
  1279. }
  1280. }
  1281. /* disable hflip and vflip */
  1282. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
  1283. sd->hstart = 0;
  1284. sd->vstart = 1;
  1285. return 0;
  1286. }
  1287. static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
  1288. {
  1289. struct sd *sd = (struct sd *) gspca_dev;
  1290. int i;
  1291. u16 value;
  1292. int ret;
  1293. sd->i2c_addr = 0x5d;
  1294. ret = i2c_r2(gspca_dev, 0xff, &value);
  1295. if ((ret == 0) && (value == 0x8243)) {
  1296. for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) {
  1297. if (i2c_w2(gspca_dev, mt9v011_init[i].reg,
  1298. mt9v011_init[i].val) < 0) {
  1299. err("MT9V011 sensor initialization failed");
  1300. return -ENODEV;
  1301. }
  1302. }
  1303. sd->hstart = 2;
  1304. sd->vstart = 2;
  1305. sd->sensor = SENSOR_MT9V011;
  1306. info("MT9V011 sensor detected");
  1307. return 0;
  1308. }
  1309. sd->i2c_addr = 0x5c;
  1310. i2c_w2(gspca_dev, 0x01, 0x0004);
  1311. ret = i2c_r2(gspca_dev, 0xff, &value);
  1312. if ((ret == 0) && (value == 0x823a)) {
  1313. for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) {
  1314. if (i2c_w2(gspca_dev, mt9v111_init[i].reg,
  1315. mt9v111_init[i].val) < 0) {
  1316. err("MT9V111 sensor initialization failed");
  1317. return -ENODEV;
  1318. }
  1319. }
  1320. gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX)
  1321. | (1 << AUTOGAIN_IDX)
  1322. | (1 << GAIN_IDX);
  1323. sd->hstart = 2;
  1324. sd->vstart = 2;
  1325. sd->sensor = SENSOR_MT9V111;
  1326. info("MT9V111 sensor detected");
  1327. return 0;
  1328. }
  1329. sd->i2c_addr = 0x5d;
  1330. ret = i2c_w2(gspca_dev, 0xf0, 0x0000);
  1331. if (ret < 0) {
  1332. sd->i2c_addr = 0x48;
  1333. i2c_w2(gspca_dev, 0xf0, 0x0000);
  1334. }
  1335. ret = i2c_r2(gspca_dev, 0x00, &value);
  1336. if ((ret == 0) && (value == 0x1229)) {
  1337. for (i = 0; i < ARRAY_SIZE(mt9v112_init); i++) {
  1338. if (i2c_w2(gspca_dev, mt9v112_init[i].reg,
  1339. mt9v112_init[i].val) < 0) {
  1340. err("MT9V112 sensor initialization failed");
  1341. return -ENODEV;
  1342. }
  1343. }
  1344. sd->hstart = 6;
  1345. sd->vstart = 2;
  1346. sd->sensor = SENSOR_MT9V112;
  1347. info("MT9V112 sensor detected");
  1348. return 0;
  1349. }
  1350. return -ENODEV;
  1351. }
  1352. static int mt9m112_init_sensor(struct gspca_dev *gspca_dev)
  1353. {
  1354. struct sd *sd = (struct sd *) gspca_dev;
  1355. int i;
  1356. for (i = 0; i < ARRAY_SIZE(mt9m112_init); i++) {
  1357. if (i2c_w2(gspca_dev, mt9m112_init[i].reg,
  1358. mt9m112_init[i].val) < 0) {
  1359. err("MT9M112 sensor initialization failed");
  1360. return -ENODEV;
  1361. }
  1362. }
  1363. gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX)
  1364. | (1 << GAIN_IDX);
  1365. sd->hstart = 0;
  1366. sd->vstart = 2;
  1367. return 0;
  1368. }
  1369. static int mt9m111_init_sensor(struct gspca_dev *gspca_dev)
  1370. {
  1371. struct sd *sd = (struct sd *) gspca_dev;
  1372. int i;
  1373. for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) {
  1374. if (i2c_w2(gspca_dev, mt9m111_init[i].reg,
  1375. mt9m111_init[i].val) < 0) {
  1376. err("MT9M111 sensor initialization failed");
  1377. return -ENODEV;
  1378. }
  1379. }
  1380. gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX)
  1381. | (1 << GAIN_IDX);
  1382. sd->hstart = 0;
  1383. sd->vstart = 2;
  1384. return 0;
  1385. }
  1386. static int mt9m001_init_sensor(struct gspca_dev *gspca_dev)
  1387. {
  1388. struct sd *sd = (struct sd *) gspca_dev;
  1389. int i;
  1390. u16 id;
  1391. if (i2c_r2(gspca_dev, 0x00, &id) < 0)
  1392. return -EINVAL;
  1393. /* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */
  1394. switch (id) {
  1395. case 0x8411:
  1396. case 0x8421:
  1397. info("MT9M001 color sensor detected");
  1398. break;
  1399. case 0x8431:
  1400. info("MT9M001 mono sensor detected");
  1401. break;
  1402. default:
  1403. err("No MT9M001 chip detected, ID = %x\n", id);
  1404. return -ENODEV;
  1405. }
  1406. for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) {
  1407. if (i2c_w2(gspca_dev, mt9m001_init[i].reg,
  1408. mt9m001_init[i].val) < 0) {
  1409. err("MT9M001 sensor initialization failed");
  1410. return -ENODEV;
  1411. }
  1412. }
  1413. /* disable hflip and vflip */
  1414. gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
  1415. sd->hstart = 1;
  1416. sd->vstart = 1;
  1417. return 0;
  1418. }
  1419. static int hv7131r_init_sensor(struct gspca_dev *gspca_dev)
  1420. {
  1421. int i;
  1422. struct sd *sd = (struct sd *) gspca_dev;
  1423. for (i = 0; i < ARRAY_SIZE(hv7131r_init); i++) {
  1424. if (i2c_w1(gspca_dev, hv7131r_init[i].reg,
  1425. hv7131r_init[i].val) < 0) {
  1426. err("HV7131R Sensor initialization failed");
  1427. return -ENODEV;
  1428. }
  1429. }
  1430. sd->hstart = 0;
  1431. sd->vstart = 1;
  1432. return 0;
  1433. }
  1434. static int set_cmatrix(struct gspca_dev *gspca_dev)
  1435. {
  1436. struct sd *sd = (struct sd *) gspca_dev;
  1437. s32 hue_coord, hue_index = 180 + sd->hue;
  1438. u8 cmatrix[21];
  1439. memset(cmatrix, 0, sizeof cmatrix);
  1440. cmatrix[2] = (sd->contrast * 0x25 / 0x100) + 0x26;
  1441. cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25;
  1442. cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25;
  1443. cmatrix[18] = sd->brightness - 0x80;
  1444. hue_coord = (hsv_red_x[hue_index] * sd->saturation) >> 8;
  1445. cmatrix[6] = hue_coord;
  1446. cmatrix[7] = (hue_coord >> 8) & 0x0f;
  1447. hue_coord = (hsv_red_y[hue_index] * sd->saturation) >> 8;
  1448. cmatrix[8] = hue_coord;
  1449. cmatrix[9] = (hue_coord >> 8) & 0x0f;
  1450. hue_coord = (hsv_green_x[hue_index] * sd->saturation) >> 8;
  1451. cmatrix[10] = hue_coord;
  1452. cmatrix[11] = (hue_coord >> 8) & 0x0f;
  1453. hue_coord = (hsv_green_y[hue_index] * sd->saturation) >> 8;
  1454. cmatrix[12] = hue_coord;
  1455. cmatrix[13] = (hue_coord >> 8) & 0x0f;
  1456. hue_coord = (hsv_blue_x[hue_index] * sd->saturation) >> 8;
  1457. cmatrix[14] = hue_coord;
  1458. cmatrix[15] = (hue_coord >> 8) & 0x0f;
  1459. hue_coord = (hsv_blue_y[hue_index] * sd->saturation) >> 8;
  1460. cmatrix[16] = hue_coord;
  1461. cmatrix[17] = (hue_coord >> 8) & 0x0f;
  1462. return reg_w(gspca_dev, 0x10e1, cmatrix, 21);
  1463. }
  1464. static int set_gamma(struct gspca_dev *gspca_dev)
  1465. {
  1466. struct sd *sd = (struct sd *) gspca_dev;
  1467. u8 gamma[17];
  1468. u8 gval = sd->gamma * 0xb8 / 0x100;
  1469. gamma[0] = 0x0a;
  1470. gamma[1] = 0x13 + (gval * (0xcb - 0x13) / 0xb8);
  1471. gamma[2] = 0x25 + (gval * (0xee - 0x25) / 0xb8);
  1472. gamma[3] = 0x37 + (gval * (0xfa - 0x37) / 0xb8);
  1473. gamma[4] = 0x45 + (gval * (0xfc - 0x45) / 0xb8);
  1474. gamma[5] = 0x55 + (gval * (0xfb - 0x55) / 0xb8);
  1475. gamma[6] = 0x65 + (gval * (0xfc - 0x65) / 0xb8);
  1476. gamma[7] = 0x74 + (gval * (0xfd - 0x74) / 0xb8);
  1477. gamma[8] = 0x83 + (gval * (0xfe - 0x83) / 0xb8);
  1478. gamma[9] = 0x92 + (gval * (0xfc - 0x92) / 0xb8);
  1479. gamma[10] = 0xa1 + (gval * (0xfc - 0xa1) / 0xb8);
  1480. gamma[11] = 0xb0 + (gval * (0xfc - 0xb0) / 0xb8);
  1481. gamma[12] = 0xbf + (gval * (0xfb - 0xbf) / 0xb8);
  1482. gamma[13] = 0xce + (gval * (0xfb - 0xce) / 0xb8);
  1483. gamma[14] = 0xdf + (gval * (0xfd - 0xdf) / 0xb8);
  1484. gamma[15] = 0xea + (gval * (0xf9 - 0xea) / 0xb8);
  1485. gamma[16] = 0xf5;
  1486. return reg_w(gspca_dev, 0x1190, gamma, 17);
  1487. }
  1488. static int set_redblue(struct gspca_dev *gspca_dev)
  1489. {
  1490. struct sd *sd = (struct sd *) gspca_dev;
  1491. reg_w1(gspca_dev, 0x118c, sd->red);
  1492. reg_w1(gspca_dev, 0x118f, sd->blue);
  1493. return 0;
  1494. }
  1495. static int set_hvflip(struct gspca_dev *gspca_dev)
  1496. {
  1497. u8 value, tslb, hflip, vflip;
  1498. u16 value2;
  1499. struct sd *sd = (struct sd *) gspca_dev;
  1500. if ((sd->flags & FLIP_DETECT) && dmi_check_system(flip_dmi_table)) {
  1501. hflip = !sd->hflip;
  1502. vflip = !sd->vflip;
  1503. } else {
  1504. hflip = sd->hflip;
  1505. vflip = sd->vflip;
  1506. }
  1507. switch (sd->sensor) {
  1508. case SENSOR_OV7660:
  1509. value = 0x01;
  1510. if (hflip)
  1511. value |= 0x20;
  1512. if (vflip) {
  1513. value |= 0x10;
  1514. sd->vstart = 2;
  1515. } else
  1516. sd->vstart = 3;
  1517. reg_w1(gspca_dev, 0x1182, sd->vstart);
  1518. i2c_w1(gspca_dev, 0x1e, value);
  1519. break;
  1520. case SENSOR_OV9650:
  1521. i2c_r1(gspca_dev, 0x1e, &value);
  1522. value &= ~0x30;
  1523. tslb = 0x01;
  1524. if (hflip)
  1525. value |= 0x20;
  1526. if (vflip) {
  1527. value |= 0x10;
  1528. tslb = 0x49;
  1529. }
  1530. i2c_w1(gspca_dev, 0x1e, value);
  1531. i2c_w1(gspca_dev, 0x3a, tslb);
  1532. break;
  1533. case SENSOR_MT9V111:
  1534. case SENSOR_MT9V011:
  1535. i2c_r2(gspca_dev, 0x20, &value2);
  1536. value2 &= ~0xc0a0;
  1537. if (hflip)
  1538. value2 |= 0x8080;
  1539. if (vflip)
  1540. value2 |= 0x4020;
  1541. i2c_w2(gspca_dev, 0x20, value2);
  1542. break;
  1543. case SENSOR_MT9M112:
  1544. case SENSOR_MT9M111:
  1545. case SENSOR_MT9V112:
  1546. i2c_r2(gspca_dev, 0x20, &value2);
  1547. value2 &= ~0x0003;
  1548. if (hflip)
  1549. value2 |= 0x0002;
  1550. if (vflip)
  1551. value2 |= 0x0001;
  1552. i2c_w2(gspca_dev, 0x20, value2);
  1553. break;
  1554. case SENSOR_HV7131R:
  1555. i2c_r1(gspca_dev, 0x01, &value);
  1556. value &= ~0x03;
  1557. if (vflip)
  1558. value |= 0x01;
  1559. if (hflip)
  1560. value |= 0x02;
  1561. i2c_w1(gspca_dev, 0x01, value);
  1562. break;
  1563. }
  1564. return 0;
  1565. }
  1566. static int set_exposure(struct gspca_dev *gspca_dev)
  1567. {
  1568. struct sd *sd = (struct sd *) gspca_dev;
  1569. u8 exp[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e};
  1570. switch (sd->sensor) {
  1571. case SENSOR_OV7660:
  1572. case SENSOR_OV7670:
  1573. case SENSOR_OV9655:
  1574. case SENSOR_OV9650:
  1575. exp[0] |= (3 << 4);
  1576. exp[2] = 0x2d;
  1577. exp[3] = sd->exposure & 0xff;
  1578. exp[4] = sd->exposure >> 8;
  1579. break;
  1580. case SENSOR_MT9M001:
  1581. case SENSOR_MT9V112:
  1582. case SENSOR_MT9V011:
  1583. exp[0] |= (3 << 4);
  1584. exp[2] = 0x09;
  1585. exp[3] = sd->exposure >> 8;
  1586. exp[4] = sd->exposure & 0xff;
  1587. break;
  1588. case SENSOR_HV7131R:
  1589. exp[0] |= (4 << 4);
  1590. exp[2] = 0x25;
  1591. exp[3] = (sd->exposure >> 5) & 0xff;
  1592. exp[4] = (sd->exposure << 3) & 0xff;
  1593. exp[5] = 0;
  1594. break;
  1595. default:
  1596. return 0;
  1597. }
  1598. i2c_w(gspca_dev, exp);
  1599. return 0;
  1600. }
  1601. static int set_gain(struct gspca_dev *gspca_dev)
  1602. {
  1603. struct sd *sd = (struct sd *) gspca_dev;
  1604. u8 gain[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d};
  1605. switch (sd->sensor) {
  1606. case SENSOR_OV7660:
  1607. case SENSOR_OV7670:
  1608. case SENSOR_SOI968:
  1609. case SENSOR_OV9655:
  1610. case SENSOR_OV9650:
  1611. gain[0] |= (2 << 4);
  1612. gain[3] = ov_gain[sd->gain];
  1613. break;
  1614. case SENSOR_MT9V011:
  1615. gain[0] |= (3 << 4);
  1616. gain[2] = 0x35;
  1617. gain[3] = micron1_gain[sd->gain] >> 8;
  1618. gain[4] = micron1_gain[sd->gain] & 0xff;
  1619. break;
  1620. case SENSOR_MT9V112:
  1621. gain[0] |= (3 << 4);
  1622. gain[2] = 0x2f;
  1623. gain[3] = micron1_gain[sd->gain] >> 8;
  1624. gain[4] = micron1_gain[sd->gain] & 0xff;
  1625. break;
  1626. case SENSOR_MT9M001:
  1627. gain[0] |= (3 << 4);
  1628. gain[2] = 0x2f;
  1629. gain[3] = micron2_gain[sd->gain] >> 8;
  1630. gain[4] = micron2_gain[sd->gain] & 0xff;
  1631. break;
  1632. case SENSOR_HV7131R:
  1633. gain[0] |= (2 << 4);
  1634. gain[2] = 0x30;
  1635. gain[3] = hv7131r_gain[sd->gain];
  1636. break;
  1637. default:
  1638. return 0;
  1639. }
  1640. i2c_w(gspca_dev, gain);
  1641. return 0;
  1642. }
  1643. static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val)
  1644. {
  1645. struct sd *sd = (struct sd *) gspca_dev;
  1646. sd->brightness = val;
  1647. if (gspca_dev->streaming)
  1648. return set_cmatrix(gspca_dev);
  1649. return 0;
  1650. }
  1651. static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val)
  1652. {
  1653. struct sd *sd = (struct sd *) gspca_dev;
  1654. *val = sd->brightness;
  1655. return 0;
  1656. }
  1657. static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val)
  1658. {
  1659. struct sd *sd = (struct sd *) gspca_dev;
  1660. sd->contrast = val;
  1661. if (gspca_dev->streaming)
  1662. return set_cmatrix(gspca_dev);
  1663. return 0;
  1664. }
  1665. static int sd_getcontrast(struct gspca_dev *gspca_dev, s32 *val)
  1666. {
  1667. struct sd *sd = (struct sd *) gspca_dev;
  1668. *val = sd->contrast;
  1669. return 0;
  1670. }
  1671. static int sd_setsaturation(struct gspca_dev *gspca_dev, s32 val)
  1672. {
  1673. struct sd *sd = (struct sd *) gspca_dev;
  1674. sd->saturation = val;
  1675. if (gspca_dev->streaming)
  1676. return set_cmatrix(gspca_dev);
  1677. return 0;
  1678. }
  1679. static int sd_getsaturation(struct gspca_dev *gspca_dev, s32 *val)
  1680. {
  1681. struct sd *sd = (struct sd *) gspca_dev;
  1682. *val = sd->saturation;
  1683. return 0;
  1684. }
  1685. static int sd_sethue(struct gspca_dev *gspca_dev, s32 val)
  1686. {
  1687. struct sd *sd = (struct sd *) gspca_dev;
  1688. sd->hue = val;
  1689. if (gspca_dev->streaming)
  1690. return set_cmatrix(gspca_dev);
  1691. return 0;
  1692. }
  1693. static int sd_gethue(struct gspca_dev *gspca_dev, s32 *val)
  1694. {
  1695. struct sd *sd = (struct sd *) gspca_dev;
  1696. *val = sd->hue;
  1697. return 0;
  1698. }
  1699. static int sd_setgamma(struct gspca_dev *gspca_dev, s32 val)
  1700. {
  1701. struct sd *sd = (struct sd *) gspca_dev;
  1702. sd->gamma = val;
  1703. if (gspca_dev->streaming)
  1704. return set_gamma(gspca_dev);
  1705. return 0;
  1706. }
  1707. static int sd_getgamma(struct gspca_dev *gspca_dev, s32 *val)
  1708. {
  1709. struct sd *sd = (struct sd *) gspca_dev;
  1710. *val = sd->gamma;
  1711. return 0;
  1712. }
  1713. static int sd_setredbalance(struct gspca_dev *gspca_dev, s32 val)
  1714. {
  1715. struct sd *sd = (struct sd *) gspca_dev;
  1716. sd->red = val;
  1717. if (gspca_dev->streaming)
  1718. return set_redblue(gspca_dev);
  1719. return 0;
  1720. }
  1721. static int sd_getredbalance(struct gspca_dev *gspca_dev, s32 *val)
  1722. {
  1723. struct sd *sd = (struct sd *) gspca_dev;
  1724. *val = sd->red;
  1725. return 0;
  1726. }
  1727. static int sd_setbluebalance(struct gspca_dev *gspca_dev, s32 val)
  1728. {
  1729. struct sd *sd = (struct sd *) gspca_dev;
  1730. sd->blue = val;
  1731. if (gspca_dev->streaming)
  1732. return set_redblue(gspca_dev);
  1733. return 0;
  1734. }
  1735. static int sd_getbluebalance(struct gspca_dev *gspca_dev, s32 *val)
  1736. {
  1737. struct sd *sd = (struct sd *) gspca_dev;
  1738. *val = sd->blue;
  1739. return 0;
  1740. }
  1741. static int sd_sethflip(struct gspca_dev *gspca_dev, s32 val)
  1742. {
  1743. struct sd *sd = (struct sd *) gspca_dev;
  1744. sd->hflip = val;
  1745. if (gspca_dev->streaming)
  1746. return set_hvflip(gspca_dev);
  1747. return 0;
  1748. }
  1749. static int sd_gethflip(struct gspca_dev *gspca_dev, s32 *val)
  1750. {
  1751. struct sd *sd = (struct sd *) gspca_dev;
  1752. *val = sd->hflip;
  1753. return 0;
  1754. }
  1755. static int sd_setvflip(struct gspca_dev *gspca_dev, s32 val)
  1756. {
  1757. struct sd *sd = (struct sd *) gspca_dev;
  1758. sd->vflip = val;
  1759. if (gspca_dev->streaming)
  1760. return set_hvflip(gspca_dev);
  1761. return 0;
  1762. }
  1763. static int sd_getvflip(struct gspca_dev *gspca_dev, s32 *val)
  1764. {
  1765. struct sd *sd = (struct sd *) gspca_dev;
  1766. *val = sd->vflip;
  1767. return 0;
  1768. }
  1769. static int sd_setexposure(struct gspca_dev *gspca_dev, s32 val)
  1770. {
  1771. struct sd *sd = (struct sd *) gspca_dev;
  1772. sd->exposure = val;
  1773. if (gspca_dev->streaming)
  1774. return set_exposure(gspca_dev);
  1775. return 0;
  1776. }
  1777. static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val)
  1778. {
  1779. struct sd *sd = (struct sd *) gspca_dev;
  1780. *val = sd->exposure;
  1781. return 0;
  1782. }
  1783. static int sd_setgain(struct gspca_dev *gspca_dev, s32 val)
  1784. {
  1785. struct sd *sd = (struct sd *) gspca_dev;
  1786. sd->gain = val;
  1787. if (gspca_dev->streaming)
  1788. return set_gain(gspca_dev);
  1789. return 0;
  1790. }
  1791. static int sd_getgain(struct gspca_dev *gspca_dev, s32 *val)
  1792. {
  1793. struct sd *sd = (struct sd *) gspca_dev;
  1794. *val = sd->gain;
  1795. return 0;
  1796. }
  1797. static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val)
  1798. {
  1799. struct sd *sd = (struct sd *) gspca_dev;
  1800. sd->auto_exposure = val;
  1801. return 0;
  1802. }
  1803. static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val)
  1804. {
  1805. struct sd *sd = (struct sd *) gspca_dev;
  1806. *val = sd->auto_exposure;
  1807. return 0;
  1808. }
  1809. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1810. static int sd_dbg_g_register(struct gspca_dev *gspca_dev,
  1811. struct v4l2_dbg_register *reg)
  1812. {
  1813. struct sd *sd = (struct sd *) gspca_dev;
  1814. switch (reg->match.type) {
  1815. case V4L2_CHIP_MATCH_HOST:
  1816. if (reg->match.addr != 0)
  1817. return -EINVAL;
  1818. if (reg->reg < 0x1000 || reg->reg > 0x11ff)
  1819. return -EINVAL;
  1820. if (reg_r(gspca_dev, reg->reg, 1) < 0)
  1821. return -EINVAL;
  1822. reg->val = gspca_dev->usb_buf[0];
  1823. return 0;
  1824. case V4L2_CHIP_MATCH_I2C_ADDR:
  1825. if (reg->match.addr != sd->i2c_addr)
  1826. return -EINVAL;
  1827. if (sd->sensor >= SENSOR_MT9V011 &&
  1828. sd->sensor <= SENSOR_MT9M112) {
  1829. if (i2c_r2(gspca_dev, reg->reg, (u16 *)&reg->val) < 0)
  1830. return -EINVAL;
  1831. } else {
  1832. if (i2c_r1(gspca_dev, reg->reg, (u8 *)&reg->val) < 0)
  1833. return -EINVAL;
  1834. }
  1835. return 0;
  1836. }
  1837. return -EINVAL;
  1838. }
  1839. static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
  1840. struct v4l2_dbg_register *reg)
  1841. {
  1842. struct sd *sd = (struct sd *) gspca_dev;
  1843. switch (reg->match.type) {
  1844. case V4L2_CHIP_MATCH_HOST:
  1845. if (reg->match.addr != 0)
  1846. return -EINVAL;
  1847. if (reg->reg < 0x1000 || reg->reg > 0x11ff)
  1848. return -EINVAL;
  1849. if (reg_w1(gspca_dev, reg->reg, reg->val) < 0)
  1850. return -EINVAL;
  1851. return 0;
  1852. case V4L2_CHIP_MATCH_I2C_ADDR:
  1853. if (reg->match.addr != sd->i2c_addr)
  1854. return -EINVAL;
  1855. if (sd->sensor >= SENSOR_MT9V011 &&
  1856. sd->sensor <= SENSOR_MT9M112) {
  1857. if (i2c_w2(gspca_dev, reg->reg, reg->val) < 0)
  1858. return -EINVAL;
  1859. } else {
  1860. if (i2c_w1(gspca_dev, reg->reg, reg->val) < 0)
  1861. return -EINVAL;
  1862. }
  1863. return 0;
  1864. }
  1865. return -EINVAL;
  1866. }
  1867. #endif
  1868. static int sd_chip_ident(struct gspca_dev *gspca_dev,
  1869. struct v4l2_dbg_chip_ident *chip)
  1870. {
  1871. struct sd *sd = (struct sd *) gspca_dev;
  1872. switch (chip->match.type) {
  1873. case V4L2_CHIP_MATCH_HOST:
  1874. if (chip->match.addr != 0)
  1875. return -EINVAL;
  1876. chip->revision = 0;
  1877. chip->ident = V4L2_IDENT_SN9C20X;
  1878. return 0;
  1879. case V4L2_CHIP_MATCH_I2C_ADDR:
  1880. if (chip->match.addr != sd->i2c_addr)
  1881. return -EINVAL;
  1882. chip->revision = 0;
  1883. chip->ident = i2c_ident[sd->sensor];
  1884. return 0;
  1885. }
  1886. return -EINVAL;
  1887. }
  1888. static int sd_config(struct gspca_dev *gspca_dev,
  1889. const struct usb_device_id *id)
  1890. {
  1891. struct sd *sd = (struct sd *) gspca_dev;
  1892. struct cam *cam;
  1893. cam = &gspca_dev->cam;
  1894. sd->sensor = (id->driver_info >> 8) & 0xff;
  1895. sd->i2c_addr = id->driver_info & 0xff;
  1896. sd->flags = (id->driver_info >> 16) & 0xff;
  1897. switch (sd->sensor) {
  1898. case SENSOR_MT9M112:
  1899. case SENSOR_MT9M111:
  1900. case SENSOR_OV9650:
  1901. case SENSOR_SOI968:
  1902. cam->cam_mode = sxga_mode;
  1903. cam->nmodes = ARRAY_SIZE(sxga_mode);
  1904. break;
  1905. case SENSOR_MT9M001:
  1906. cam->cam_mode = mono_mode;
  1907. cam->nmodes = ARRAY_SIZE(mono_mode);
  1908. break;
  1909. default:
  1910. cam->cam_mode = vga_mode;
  1911. cam->nmodes = ARRAY_SIZE(vga_mode);
  1912. break;
  1913. }
  1914. sd->old_step = 0;
  1915. sd->older_step = 0;
  1916. sd->exposure_step = 16;
  1917. sd->brightness = BRIGHTNESS_DEFAULT;
  1918. sd->contrast = CONTRAST_DEFAULT;
  1919. sd->saturation = SATURATION_DEFAULT;
  1920. sd->hue = HUE_DEFAULT;
  1921. sd->gamma = GAMMA_DEFAULT;
  1922. sd->red = RED_DEFAULT;
  1923. sd->blue = BLUE_DEFAULT;
  1924. sd->hflip = HFLIP_DEFAULT;
  1925. sd->vflip = VFLIP_DEFAULT;
  1926. sd->exposure = EXPOSURE_DEFAULT;
  1927. sd->gain = GAIN_DEFAULT;
  1928. sd->auto_exposure = AUTO_EXPOSURE_DEFAULT;
  1929. sd->quality = 95;
  1930. return 0;
  1931. }
  1932. static int sd_init(struct gspca_dev *gspca_dev)
  1933. {
  1934. struct sd *sd = (struct sd *) gspca_dev;
  1935. int i;
  1936. u8 value;
  1937. u8 i2c_init[9] =
  1938. {0x80, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03};
  1939. for (i = 0; i < ARRAY_SIZE(bridge_init); i++) {
  1940. value = bridge_init[i][1];
  1941. if (reg_w(gspca_dev, bridge_init[i][0], &value, 1) < 0) {
  1942. err("Device initialization failed");
  1943. return -ENODEV;
  1944. }
  1945. }
  1946. if (sd->flags & LED_REVERSE)
  1947. reg_w1(gspca_dev, 0x1006, 0x00);
  1948. else
  1949. reg_w1(gspca_dev, 0x1006, 0x20);
  1950. if (reg_w(gspca_dev, 0x10c0, i2c_init, 9) < 0) {
  1951. err("Device initialization failed");
  1952. return -ENODEV;
  1953. }
  1954. switch (sd->sensor) {
  1955. case SENSOR_OV9650:
  1956. if (ov9650_init_sensor(gspca_dev) < 0)
  1957. return -ENODEV;
  1958. info("OV9650 sensor detected");
  1959. break;
  1960. case SENSOR_OV9655:
  1961. if (ov9655_init_sensor(gspca_dev) < 0)
  1962. return -ENODEV;
  1963. info("OV9655 sensor detected");
  1964. break;
  1965. case SENSOR_SOI968:
  1966. if (soi968_init_sensor(gspca_dev) < 0)
  1967. return -ENODEV;
  1968. info("SOI968 sensor detected");
  1969. break;
  1970. case SENSOR_OV7660:
  1971. if (ov7660_init_sensor(gspca_dev) < 0)
  1972. return -ENODEV;
  1973. info("OV7660 sensor detected");
  1974. break;
  1975. case SENSOR_OV7670:
  1976. if (ov7670_init_sensor(gspca_dev) < 0)
  1977. return -ENODEV;
  1978. info("OV7670 sensor detected");
  1979. break;
  1980. case SENSOR_MT9VPRB:
  1981. if (mt9v_init_sensor(gspca_dev) < 0)
  1982. return -ENODEV;
  1983. break;
  1984. case SENSOR_MT9M111:
  1985. if (mt9m111_init_sensor(gspca_dev) < 0)
  1986. return -ENODEV;
  1987. info("MT9M111 sensor detected");
  1988. break;
  1989. case SENSOR_MT9M112:
  1990. if (mt9m112_init_sensor(gspca_dev) < 0)
  1991. return -ENODEV;
  1992. info("MT9M112 sensor detected");
  1993. break;
  1994. case SENSOR_MT9M001:
  1995. if (mt9m001_init_sensor(gspca_dev) < 0)
  1996. return -ENODEV;
  1997. break;
  1998. case SENSOR_HV7131R:
  1999. if (hv7131r_init_sensor(gspca_dev) < 0)
  2000. return -ENODEV;
  2001. info("HV7131R sensor detected");
  2002. break;
  2003. default:
  2004. info("Unsupported Sensor");
  2005. return -ENODEV;
  2006. }
  2007. return 0;
  2008. }
  2009. static void configure_sensor_output(struct gspca_dev *gspca_dev, int mode)
  2010. {
  2011. struct sd *sd = (struct sd *) gspca_dev;
  2012. u8 value;
  2013. switch (sd->sensor) {
  2014. case SENSOR_SOI968:
  2015. if (mode & MODE_SXGA) {
  2016. i2c_w1(gspca_dev, 0x17, 0x1d);
  2017. i2c_w1(gspca_dev, 0x18, 0xbd);
  2018. i2c_w1(gspca_dev, 0x19, 0x01);
  2019. i2c_w1(gspca_dev, 0x1a, 0x81);
  2020. i2c_w1(gspca_dev, 0x12, 0x00);
  2021. sd->hstart = 140;
  2022. sd->vstart = 19;
  2023. } else {
  2024. i2c_w1(gspca_dev, 0x17, 0x13);
  2025. i2c_w1(gspca_dev, 0x18, 0x63);
  2026. i2c_w1(gspca_dev, 0x19, 0x01);
  2027. i2c_w1(gspca_dev, 0x1a, 0x79);
  2028. i2c_w1(gspca_dev, 0x12, 0x40);
  2029. sd->hstart = 60;
  2030. sd->vstart = 11;
  2031. }
  2032. break;
  2033. case SENSOR_OV9650:
  2034. if (mode & MODE_SXGA) {
  2035. i2c_w1(gspca_dev, 0x17, 0x1b);
  2036. i2c_w1(gspca_dev, 0x18, 0xbc);
  2037. i2c_w1(gspca_dev, 0x19, 0x01);
  2038. i2c_w1(gspca_dev, 0x1a, 0x82);
  2039. i2c_r1(gspca_dev, 0x12, &value);
  2040. i2c_w1(gspca_dev, 0x12, value & 0x07);
  2041. } else {
  2042. i2c_w1(gspca_dev, 0x17, 0x24);
  2043. i2c_w1(gspca_dev, 0x18, 0xc5);
  2044. i2c_w1(gspca_dev, 0x19, 0x00);
  2045. i2c_w1(gspca_dev, 0x1a, 0x3c);
  2046. i2c_r1(gspca_dev, 0x12, &value);
  2047. i2c_w1(gspca_dev, 0x12, (value & 0x7) | 0x40);
  2048. }
  2049. break;
  2050. case SENSOR_MT9M112:
  2051. case SENSOR_MT9M111:
  2052. if (mode & MODE_SXGA) {
  2053. i2c_w2(gspca_dev, 0xf0, 0x0002);
  2054. i2c_w2(gspca_dev, 0xc8, 0x970b);
  2055. i2c_w2(gspca_dev, 0xf0, 0x0000);
  2056. } else {
  2057. i2c_w2(gspca_dev, 0xf0, 0x0002);
  2058. i2c_w2(gspca_dev, 0xc8, 0x8000);
  2059. i2c_w2(gspca_dev, 0xf0, 0x0000);
  2060. }
  2061. break;
  2062. }
  2063. }
  2064. #define HW_WIN(mode, hstart, vstart) \
  2065. ((const u8 []){hstart, 0, vstart, 0, \
  2066. (mode & MODE_SXGA ? 1280 >> 4 : 640 >> 4), \
  2067. (mode & MODE_SXGA ? 1024 >> 3 : 480 >> 3)})
  2068. #define CLR_WIN(width, height) \
  2069. ((const u8 [])\
  2070. {0, width >> 2, 0, height >> 1,\
  2071. ((width >> 10) & 0x01) | ((height >> 8) & 0x6)})
  2072. static int sd_start(struct gspca_dev *gspca_dev)
  2073. {
  2074. struct sd *sd = (struct sd *) gspca_dev;
  2075. int mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  2076. int width = gspca_dev->width;
  2077. int height = gspca_dev->height;
  2078. u8 fmt, scale = 0;
  2079. jpeg_define(sd->jpeg_hdr, height, width,
  2080. 0x21);
  2081. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2082. if (mode & MODE_RAW)
  2083. fmt = 0x2d;
  2084. else if (mode & MODE_JPEG)
  2085. fmt = 0x2c;
  2086. else
  2087. fmt = 0x2f; /* YUV 420 */
  2088. switch (mode & SCALE_MASK) {
  2089. case SCALE_1280x1024:
  2090. scale = 0xc0;
  2091. info("Set 1280x1024");
  2092. break;
  2093. case SCALE_640x480:
  2094. scale = 0x80;
  2095. info("Set 640x480");
  2096. break;
  2097. case SCALE_320x240:
  2098. scale = 0x90;
  2099. info("Set 320x240");
  2100. break;
  2101. case SCALE_160x120:
  2102. scale = 0xa0;
  2103. info("Set 160x120");
  2104. break;
  2105. }
  2106. configure_sensor_output(gspca_dev, mode);
  2107. reg_w(gspca_dev, 0x1100, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
  2108. reg_w(gspca_dev, 0x1140, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
  2109. reg_w(gspca_dev, 0x10fb, CLR_WIN(width, height), 5);
  2110. reg_w(gspca_dev, 0x1180, HW_WIN(mode, sd->hstart, sd->vstart), 6);
  2111. reg_w1(gspca_dev, 0x1189, scale);
  2112. reg_w1(gspca_dev, 0x10e0, fmt);
  2113. set_cmatrix(gspca_dev);
  2114. set_gamma(gspca_dev);
  2115. set_redblue(gspca_dev);
  2116. set_gain(gspca_dev);
  2117. set_exposure(gspca_dev);
  2118. set_hvflip(gspca_dev);
  2119. reg_w1(gspca_dev, 0x1007, 0x20);
  2120. reg_r(gspca_dev, 0x1061, 1);
  2121. reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] | 0x02);
  2122. return 0;
  2123. }
  2124. static void sd_stopN(struct gspca_dev *gspca_dev)
  2125. {
  2126. reg_w1(gspca_dev, 0x1007, 0x00);
  2127. reg_r(gspca_dev, 0x1061, 1);
  2128. reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] & ~0x02);
  2129. }
  2130. static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
  2131. {
  2132. struct sd *sd = (struct sd *) gspca_dev;
  2133. s16 new_exp;
  2134. /*
  2135. * some hardcoded values are present
  2136. * like those for maximal/minimal exposure
  2137. * and exposure steps
  2138. */
  2139. if (avg_lum < MIN_AVG_LUM) {
  2140. if (sd->exposure > 0x1770)
  2141. return;
  2142. new_exp = sd->exposure + sd->exposure_step;
  2143. if (new_exp > 0x1770)
  2144. new_exp = 0x1770;
  2145. if (new_exp < 0x10)
  2146. new_exp = 0x10;
  2147. sd->exposure = new_exp;
  2148. set_exposure(gspca_dev);
  2149. sd->older_step = sd->old_step;
  2150. sd->old_step = 1;
  2151. if (sd->old_step ^ sd->older_step)
  2152. sd->exposure_step /= 2;
  2153. else
  2154. sd->exposure_step += 2;
  2155. }
  2156. if (avg_lum > MAX_AVG_LUM) {
  2157. if (sd->exposure < 0x10)
  2158. return;
  2159. new_exp = sd->exposure - sd->exposure_step;
  2160. if (new_exp > 0x1700)
  2161. new_exp = 0x1770;
  2162. if (new_exp < 0x10)
  2163. new_exp = 0x10;
  2164. sd->exposure = new_exp;
  2165. set_exposure(gspca_dev);
  2166. sd->older_step = sd->old_step;
  2167. sd->old_step = 0;
  2168. if (sd->old_step ^ sd->older_step)
  2169. sd->exposure_step /= 2;
  2170. else
  2171. sd->exposure_step += 2;
  2172. }
  2173. }
  2174. static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum)
  2175. {
  2176. struct sd *sd = (struct sd *) gspca_dev;
  2177. if (avg_lum < MIN_AVG_LUM) {
  2178. if (sd->gain + 1 <= 28) {
  2179. sd->gain++;
  2180. set_gain(gspca_dev);
  2181. }
  2182. }
  2183. if (avg_lum > MAX_AVG_LUM) {
  2184. if (sd->gain > 0) {
  2185. sd->gain--;
  2186. set_gain(gspca_dev);
  2187. }
  2188. }
  2189. }
  2190. static void sd_dqcallback(struct gspca_dev *gspca_dev)
  2191. {
  2192. struct sd *sd = (struct sd *) gspca_dev;
  2193. int avg_lum;
  2194. if (!sd->auto_exposure)
  2195. return;
  2196. avg_lum = atomic_read(&sd->avg_lum);
  2197. if (sd->sensor == SENSOR_SOI968)
  2198. do_autogain(gspca_dev, avg_lum);
  2199. else
  2200. do_autoexposure(gspca_dev, avg_lum);
  2201. }
  2202. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2203. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2204. u8 *data, /* interrupt packet */
  2205. int len) /* interrupt packet length */
  2206. {
  2207. struct sd *sd = (struct sd *) gspca_dev;
  2208. int ret = -EINVAL;
  2209. if (!(sd->flags & HAS_NO_BUTTON) && len == 1) {
  2210. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2211. input_sync(gspca_dev->input_dev);
  2212. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2213. input_sync(gspca_dev->input_dev);
  2214. ret = 0;
  2215. }
  2216. return ret;
  2217. }
  2218. #endif
  2219. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2220. u8 *data, /* isoc packet */
  2221. int len) /* iso packet length */
  2222. {
  2223. struct sd *sd = (struct sd *) gspca_dev;
  2224. int avg_lum;
  2225. static u8 frame_header[] =
  2226. {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96};
  2227. if (len == 64 && memcmp(data, frame_header, 6) == 0) {
  2228. avg_lum = ((data[35] >> 2) & 3) |
  2229. (data[20] << 2) |
  2230. (data[19] << 10);
  2231. avg_lum += ((data[35] >> 4) & 3) |
  2232. (data[22] << 2) |
  2233. (data[21] << 10);
  2234. avg_lum += ((data[35] >> 6) & 3) |
  2235. (data[24] << 2) |
  2236. (data[23] << 10);
  2237. avg_lum += (data[36] & 3) |
  2238. (data[26] << 2) |
  2239. (data[25] << 10);
  2240. avg_lum += ((data[36] >> 2) & 3) |
  2241. (data[28] << 2) |
  2242. (data[27] << 10);
  2243. avg_lum += ((data[36] >> 4) & 3) |
  2244. (data[30] << 2) |
  2245. (data[29] << 10);
  2246. avg_lum += ((data[36] >> 6) & 3) |
  2247. (data[32] << 2) |
  2248. (data[31] << 10);
  2249. avg_lum += ((data[44] >> 4) & 3) |
  2250. (data[34] << 2) |
  2251. (data[33] << 10);
  2252. avg_lum >>= 9;
  2253. atomic_set(&sd->avg_lum, avg_lum);
  2254. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  2255. return;
  2256. }
  2257. if (gspca_dev->last_packet_type == LAST_PACKET) {
  2258. if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv
  2259. & MODE_JPEG) {
  2260. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2261. sd->jpeg_hdr, JPEG_HDR_SZ);
  2262. gspca_frame_add(gspca_dev, INTER_PACKET,
  2263. data, len);
  2264. } else {
  2265. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2266. data, len);
  2267. }
  2268. } else {
  2269. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2270. }
  2271. }
  2272. /* sub-driver description */
  2273. static const struct sd_desc sd_desc = {
  2274. .name = MODULE_NAME,
  2275. .ctrls = sd_ctrls,
  2276. .nctrls = ARRAY_SIZE(sd_ctrls),
  2277. .config = sd_config,
  2278. .init = sd_init,
  2279. .start = sd_start,
  2280. .stopN = sd_stopN,
  2281. .pkt_scan = sd_pkt_scan,
  2282. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2283. .int_pkt_scan = sd_int_pkt_scan,
  2284. #endif
  2285. .dq_callback = sd_dqcallback,
  2286. #ifdef CONFIG_VIDEO_ADV_DEBUG
  2287. .set_register = sd_dbg_s_register,
  2288. .get_register = sd_dbg_g_register,
  2289. #endif
  2290. .get_chip_ident = sd_chip_ident,
  2291. };
  2292. #define SN9C20X(sensor, i2c_addr, flags) \
  2293. .driver_info = ((flags & 0xff) << 16) \
  2294. | (SENSOR_ ## sensor << 8) \
  2295. | (i2c_addr)
  2296. static const struct usb_device_id device_table[] = {
  2297. {USB_DEVICE(0x0c45, 0x6240), SN9C20X(MT9M001, 0x5d, 0)},
  2298. {USB_DEVICE(0x0c45, 0x6242), SN9C20X(MT9M111, 0x5d, 0)},
  2299. {USB_DEVICE(0x0c45, 0x6248), SN9C20X(OV9655, 0x30, 0)},
  2300. {USB_DEVICE(0x0c45, 0x624c), SN9C20X(MT9M112, 0x5d, 0)},
  2301. {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, LED_REVERSE)},
  2302. {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30,
  2303. (FLIP_DETECT | HAS_NO_BUTTON))},
  2304. {USB_DEVICE(0x0c45, 0x6251), SN9C20X(OV9650, 0x30, 0)},
  2305. {USB_DEVICE(0x0c45, 0x6253), SN9C20X(OV9650, 0x30, 0)},
  2306. {USB_DEVICE(0x0c45, 0x6260), SN9C20X(OV7670, 0x21, 0)},
  2307. {USB_DEVICE(0x0c45, 0x6270), SN9C20X(MT9VPRB, 0x00, 0)},
  2308. {USB_DEVICE(0x0c45, 0x627b), SN9C20X(OV7660, 0x21, FLIP_DETECT)},
  2309. {USB_DEVICE(0x0c45, 0x627c), SN9C20X(HV7131R, 0x11, 0)},
  2310. {USB_DEVICE(0x0c45, 0x627f), SN9C20X(OV9650, 0x30, 0)},
  2311. {USB_DEVICE(0x0c45, 0x6280), SN9C20X(MT9M001, 0x5d, 0)},
  2312. {USB_DEVICE(0x0c45, 0x6282), SN9C20X(MT9M111, 0x5d, 0)},
  2313. {USB_DEVICE(0x0c45, 0x6288), SN9C20X(OV9655, 0x30, 0)},
  2314. {USB_DEVICE(0x0c45, 0x628c), SN9C20X(MT9M112, 0x5d, 0)},
  2315. {USB_DEVICE(0x0c45, 0x628e), SN9C20X(SOI968, 0x30, 0)},
  2316. {USB_DEVICE(0x0c45, 0x628f), SN9C20X(OV9650, 0x30, 0)},
  2317. {USB_DEVICE(0x0c45, 0x62a0), SN9C20X(OV7670, 0x21, 0)},
  2318. {USB_DEVICE(0x0c45, 0x62b0), SN9C20X(MT9VPRB, 0x00, 0)},
  2319. {USB_DEVICE(0x0c45, 0x62b3), SN9C20X(OV9655, 0x30, 0)},
  2320. {USB_DEVICE(0x0c45, 0x62bb), SN9C20X(OV7660, 0x21, 0)},
  2321. {USB_DEVICE(0x0c45, 0x62bc), SN9C20X(HV7131R, 0x11, 0)},
  2322. {USB_DEVICE(0x045e, 0x00f4), SN9C20X(OV9650, 0x30, 0)},
  2323. {USB_DEVICE(0x145f, 0x013d), SN9C20X(OV7660, 0x21, 0)},
  2324. {USB_DEVICE(0x0458, 0x7029), SN9C20X(HV7131R, 0x11, 0)},
  2325. {USB_DEVICE(0x0458, 0x704a), SN9C20X(MT9M112, 0x5d, 0)},
  2326. {USB_DEVICE(0x0458, 0x704c), SN9C20X(MT9M112, 0x5d, 0)},
  2327. {USB_DEVICE(0xa168, 0x0610), SN9C20X(HV7131R, 0x11, 0)},
  2328. {USB_DEVICE(0xa168, 0x0611), SN9C20X(HV7131R, 0x11, 0)},
  2329. {USB_DEVICE(0xa168, 0x0613), SN9C20X(HV7131R, 0x11, 0)},
  2330. {USB_DEVICE(0xa168, 0x0618), SN9C20X(HV7131R, 0x11, 0)},
  2331. {USB_DEVICE(0xa168, 0x0614), SN9C20X(MT9M111, 0x5d, 0)},
  2332. {USB_DEVICE(0xa168, 0x0615), SN9C20X(MT9M111, 0x5d, 0)},
  2333. {USB_DEVICE(0xa168, 0x0617), SN9C20X(MT9M111, 0x5d, 0)},
  2334. {}
  2335. };
  2336. MODULE_DEVICE_TABLE(usb, device_table);
  2337. /* -- device connect -- */
  2338. static int sd_probe(struct usb_interface *intf,
  2339. const struct usb_device_id *id)
  2340. {
  2341. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2342. THIS_MODULE);
  2343. }
  2344. static struct usb_driver sd_driver = {
  2345. .name = MODULE_NAME,
  2346. .id_table = device_table,
  2347. .probe = sd_probe,
  2348. .disconnect = gspca_disconnect,
  2349. #ifdef CONFIG_PM
  2350. .suspend = gspca_suspend,
  2351. .resume = gspca_resume,
  2352. .reset_resume = gspca_resume,
  2353. #endif
  2354. };
  2355. /* -- module insert / remove -- */
  2356. static int __init sd_mod_init(void)
  2357. {
  2358. return usb_register(&sd_driver);
  2359. }
  2360. static void __exit sd_mod_exit(void)
  2361. {
  2362. usb_deregister(&sd_driver);
  2363. }
  2364. module_init(sd_mod_init);
  2365. module_exit(sd_mod_exit);