sn9c20x.c 72 KB

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