sn9c20x.c 71 KB

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