sn9c20x.c 69 KB

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