sn9c20x.c 71 KB

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