sn9c20x.c 69 KB

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