sn9c20x.c 70 KB

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