sonixj.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059
  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  3. *
  4. * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define MODULE_NAME "sonixj"
  22. #include <linux/input.h>
  23. #include "gspca.h"
  24. #include "jpeg.h"
  25. #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
  26. MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
  27. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  28. MODULE_LICENSE("GPL");
  29. /* controls */
  30. enum e_ctrl {
  31. BRIGHTNESS,
  32. CONTRAST,
  33. COLORS,
  34. BLUE,
  35. RED,
  36. GAMMA,
  37. AUTOGAIN,
  38. HFLIP,
  39. VFLIP,
  40. SHARPNESS,
  41. INFRARED,
  42. FREQ,
  43. NCTRLS /* number of controls */
  44. };
  45. /* specific webcam descriptor */
  46. struct sd {
  47. struct gspca_dev gspca_dev; /* !! must be the first item */
  48. struct gspca_ctrl ctrls[NCTRLS];
  49. atomic_t avg_lum;
  50. u32 exposure;
  51. u8 quality; /* image quality */
  52. #define QUALITY_MIN 60
  53. #define QUALITY_MAX 95
  54. #define QUALITY_DEF 80
  55. u8 jpegqual; /* webcam quality */
  56. u8 reg18;
  57. u8 flags;
  58. s8 ag_cnt;
  59. #define AG_CNT_START 13
  60. u8 bridge;
  61. #define BRIDGE_SN9C102P 0
  62. #define BRIDGE_SN9C105 1
  63. #define BRIDGE_SN9C110 2
  64. #define BRIDGE_SN9C120 3
  65. u8 sensor; /* Type of image sensor chip */
  66. u8 i2c_addr;
  67. u8 jpeg_hdr[JPEG_HDR_SZ];
  68. };
  69. enum sensors {
  70. SENSOR_ADCM1700,
  71. SENSOR_GC0307,
  72. SENSOR_HV7131R,
  73. SENSOR_MI0360,
  74. SENSOR_MI0360B,
  75. SENSOR_MO4000,
  76. SENSOR_MT9V111,
  77. SENSOR_OM6802,
  78. SENSOR_OV7630,
  79. SENSOR_OV7648,
  80. SENSOR_OV7660,
  81. SENSOR_PO1030,
  82. SENSOR_PO2030N,
  83. SENSOR_SOI768,
  84. SENSOR_SP80708,
  85. };
  86. /* device flags */
  87. #define PDN_INV 1 /* inverse pin S_PWR_DN / sn_xxx tables */
  88. /* V4L2 controls supported by the driver */
  89. static void setbrightness(struct gspca_dev *gspca_dev);
  90. static void setcontrast(struct gspca_dev *gspca_dev);
  91. static void setcolors(struct gspca_dev *gspca_dev);
  92. static void setredblue(struct gspca_dev *gspca_dev);
  93. static void setgamma(struct gspca_dev *gspca_dev);
  94. static void setautogain(struct gspca_dev *gspca_dev);
  95. static void sethvflip(struct gspca_dev *gspca_dev);
  96. static void setsharpness(struct gspca_dev *gspca_dev);
  97. static void setinfrared(struct gspca_dev *gspca_dev);
  98. static void setfreq(struct gspca_dev *gspca_dev);
  99. static const struct ctrl sd_ctrls[NCTRLS] = {
  100. [BRIGHTNESS] = {
  101. {
  102. .id = V4L2_CID_BRIGHTNESS,
  103. .type = V4L2_CTRL_TYPE_INTEGER,
  104. .name = "Brightness",
  105. .minimum = 0,
  106. .maximum = 0xff,
  107. .step = 1,
  108. .default_value = 0x80,
  109. },
  110. .set_control = setbrightness
  111. },
  112. [CONTRAST] = {
  113. {
  114. .id = V4L2_CID_CONTRAST,
  115. .type = V4L2_CTRL_TYPE_INTEGER,
  116. .name = "Contrast",
  117. .minimum = 0,
  118. #define CONTRAST_MAX 127
  119. .maximum = CONTRAST_MAX,
  120. .step = 1,
  121. .default_value = 63,
  122. },
  123. .set_control = setcontrast
  124. },
  125. [COLORS] = {
  126. {
  127. .id = V4L2_CID_SATURATION,
  128. .type = V4L2_CTRL_TYPE_INTEGER,
  129. .name = "Saturation",
  130. .minimum = 0,
  131. .maximum = 40,
  132. .step = 1,
  133. #define COLORS_DEF 25
  134. .default_value = COLORS_DEF,
  135. },
  136. .set_control = setcolors
  137. },
  138. [BLUE] = {
  139. {
  140. .id = V4L2_CID_BLUE_BALANCE,
  141. .type = V4L2_CTRL_TYPE_INTEGER,
  142. .name = "Blue Balance",
  143. .minimum = 24,
  144. .maximum = 40,
  145. .step = 1,
  146. .default_value = 32,
  147. },
  148. .set_control = setredblue
  149. },
  150. [RED] = {
  151. {
  152. .id = V4L2_CID_RED_BALANCE,
  153. .type = V4L2_CTRL_TYPE_INTEGER,
  154. .name = "Red Balance",
  155. .minimum = 24,
  156. .maximum = 40,
  157. .step = 1,
  158. .default_value = 32,
  159. },
  160. .set_control = setredblue
  161. },
  162. [GAMMA] = {
  163. {
  164. .id = V4L2_CID_GAMMA,
  165. .type = V4L2_CTRL_TYPE_INTEGER,
  166. .name = "Gamma",
  167. .minimum = 0,
  168. .maximum = 40,
  169. .step = 1,
  170. #define GAMMA_DEF 20
  171. .default_value = GAMMA_DEF,
  172. },
  173. .set_control = setgamma
  174. },
  175. [AUTOGAIN] = {
  176. {
  177. .id = V4L2_CID_AUTOGAIN,
  178. .type = V4L2_CTRL_TYPE_BOOLEAN,
  179. .name = "Auto Gain",
  180. .minimum = 0,
  181. .maximum = 1,
  182. .step = 1,
  183. .default_value = 1
  184. },
  185. .set_control = setautogain
  186. },
  187. [HFLIP] = {
  188. {
  189. .id = V4L2_CID_HFLIP,
  190. .type = V4L2_CTRL_TYPE_BOOLEAN,
  191. .name = "Mirror",
  192. .minimum = 0,
  193. .maximum = 1,
  194. .step = 1,
  195. .default_value = 0,
  196. },
  197. .set_control = sethvflip
  198. },
  199. [VFLIP] = {
  200. {
  201. .id = V4L2_CID_VFLIP,
  202. .type = V4L2_CTRL_TYPE_BOOLEAN,
  203. .name = "Vflip",
  204. .minimum = 0,
  205. .maximum = 1,
  206. .step = 1,
  207. .default_value = 0,
  208. },
  209. .set_control = sethvflip
  210. },
  211. [SHARPNESS] = {
  212. {
  213. .id = V4L2_CID_SHARPNESS,
  214. .type = V4L2_CTRL_TYPE_INTEGER,
  215. .name = "Sharpness",
  216. .minimum = 0,
  217. .maximum = 255,
  218. .step = 1,
  219. .default_value = 90,
  220. },
  221. .set_control = setsharpness
  222. },
  223. /* mt9v111 only */
  224. [INFRARED] = {
  225. {
  226. .id = V4L2_CID_INFRARED,
  227. .type = V4L2_CTRL_TYPE_BOOLEAN,
  228. .name = "Infrared",
  229. .minimum = 0,
  230. .maximum = 1,
  231. .step = 1,
  232. .default_value = 0,
  233. },
  234. .set_control = setinfrared
  235. },
  236. /* ov7630/ov7648/ov7660 only */
  237. [FREQ] = {
  238. {
  239. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  240. .type = V4L2_CTRL_TYPE_MENU,
  241. .name = "Light frequency filter",
  242. .minimum = 0,
  243. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  244. .step = 1,
  245. .default_value = 1,
  246. },
  247. .set_control = setfreq
  248. },
  249. };
  250. /* table of the disabled controls */
  251. static const __u32 ctrl_dis[] = {
  252. [SENSOR_ADCM1700] = (1 << AUTOGAIN) |
  253. (1 << INFRARED) |
  254. (1 << HFLIP) |
  255. (1 << VFLIP) |
  256. (1 << FREQ),
  257. [SENSOR_GC0307] = (1 << INFRARED) |
  258. (1 << HFLIP) |
  259. (1 << VFLIP) |
  260. (1 << FREQ),
  261. [SENSOR_HV7131R] = (1 << INFRARED) |
  262. (1 << HFLIP) |
  263. (1 << FREQ),
  264. [SENSOR_MI0360] = (1 << INFRARED) |
  265. (1 << HFLIP) |
  266. (1 << VFLIP) |
  267. (1 << FREQ),
  268. [SENSOR_MI0360B] = (1 << INFRARED) |
  269. (1 << HFLIP) |
  270. (1 << VFLIP) |
  271. (1 << FREQ),
  272. [SENSOR_MO4000] = (1 << INFRARED) |
  273. (1 << HFLIP) |
  274. (1 << VFLIP) |
  275. (1 << FREQ),
  276. [SENSOR_MT9V111] = (1 << HFLIP) |
  277. (1 << VFLIP) |
  278. (1 << FREQ),
  279. [SENSOR_OM6802] = (1 << INFRARED) |
  280. (1 << HFLIP) |
  281. (1 << VFLIP) |
  282. (1 << FREQ),
  283. [SENSOR_OV7630] = (1 << INFRARED) |
  284. (1 << HFLIP),
  285. [SENSOR_OV7648] = (1 << INFRARED) |
  286. (1 << HFLIP),
  287. [SENSOR_OV7660] = (1 << AUTOGAIN) |
  288. (1 << INFRARED) |
  289. (1 << HFLIP) |
  290. (1 << VFLIP),
  291. [SENSOR_PO1030] = (1 << AUTOGAIN) |
  292. (1 << INFRARED) |
  293. (1 << HFLIP) |
  294. (1 << VFLIP) |
  295. (1 << FREQ),
  296. [SENSOR_PO2030N] = (1 << AUTOGAIN) |
  297. (1 << INFRARED) |
  298. (1 << FREQ),
  299. [SENSOR_SOI768] = (1 << AUTOGAIN) |
  300. (1 << INFRARED) |
  301. (1 << HFLIP) |
  302. (1 << VFLIP) |
  303. (1 << FREQ),
  304. [SENSOR_SP80708] = (1 << AUTOGAIN) |
  305. (1 << INFRARED) |
  306. (1 << HFLIP) |
  307. (1 << VFLIP) |
  308. (1 << FREQ),
  309. };
  310. static const struct v4l2_pix_format cif_mode[] = {
  311. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  312. .bytesperline = 352,
  313. .sizeimage = 352 * 288 * 4 / 8 + 590,
  314. .colorspace = V4L2_COLORSPACE_JPEG,
  315. .priv = 0},
  316. };
  317. static const struct v4l2_pix_format vga_mode[] = {
  318. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  319. .bytesperline = 160,
  320. .sizeimage = 160 * 120 * 4 / 8 + 590,
  321. .colorspace = V4L2_COLORSPACE_JPEG,
  322. .priv = 2},
  323. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  324. .bytesperline = 320,
  325. .sizeimage = 320 * 240 * 3 / 8 + 590,
  326. .colorspace = V4L2_COLORSPACE_JPEG,
  327. .priv = 1},
  328. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  329. .bytesperline = 640,
  330. /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
  331. .sizeimage = 640 * 480 * 3 / 4 + 590,
  332. .colorspace = V4L2_COLORSPACE_JPEG,
  333. .priv = 0},
  334. };
  335. static const u8 sn_adcm1700[0x1c] = {
  336. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  337. 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
  338. /* reg8 reg9 rega regb regc regd rege regf */
  339. 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  340. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  341. 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
  342. /* reg18 reg19 reg1a reg1b */
  343. 0x06, 0x00, 0x00, 0x00
  344. };
  345. static const u8 sn_gc0307[0x1c] = {
  346. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  347. 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00,
  348. /* reg8 reg9 rega regb regc regd rege regf */
  349. 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  350. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  351. 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02,
  352. /* reg18 reg19 reg1a reg1b */
  353. 0x06, 0x00, 0x00, 0x00
  354. };
  355. static const u8 sn_hv7131[0x1c] = {
  356. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  357. 0x00, 0x03, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  358. /* reg8 reg9 rega regb regc regd rege regf */
  359. 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  360. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  361. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  362. /* reg18 reg19 reg1a reg1b */
  363. 0x0a, 0x00, 0x00, 0x00
  364. };
  365. static const u8 sn_mi0360[0x1c] = {
  366. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  367. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  368. /* reg8 reg9 rega regb regc regd rege regf */
  369. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  370. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  371. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  372. /* reg18 reg19 reg1a reg1b */
  373. 0x06, 0x00, 0x00, 0x00
  374. };
  375. static const u8 sn_mi0360b[0x1c] = {
  376. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  377. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  378. /* reg8 reg9 rega regb regc regd rege regf */
  379. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  380. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  381. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x40,
  382. /* reg18 reg19 reg1a reg1b */
  383. 0x06, 0x00, 0x00, 0x00
  384. };
  385. static const u8 sn_mo4000[0x1c] = {
  386. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  387. 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  388. /* reg8 reg9 rega regb regc regd rege regf */
  389. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  390. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  391. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  392. /* reg18 reg19 reg1a reg1b */
  393. 0x08, 0x00, 0x00, 0x00
  394. };
  395. static const u8 sn_mt9v111[0x1c] = {
  396. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  397. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  398. /* reg8 reg9 rega regb regc regd rege regf */
  399. 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  400. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  401. 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
  402. /* reg18 reg19 reg1a reg1b */
  403. 0x06, 0x00, 0x00, 0x00
  404. };
  405. static const u8 sn_om6802[0x1c] = {
  406. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  407. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
  408. /* reg8 reg9 rega regb regc regd rege regf */
  409. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  410. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  411. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  412. /* reg18 reg19 reg1a reg1b */
  413. 0x05, 0x00, 0x00, 0x00
  414. };
  415. static const u8 sn_ov7630[0x1c] = {
  416. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  417. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  418. /* reg8 reg9 rega regb regc regd rege regf */
  419. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  420. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  421. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  422. /* reg18 reg19 reg1a reg1b */
  423. 0x0b, 0x00, 0x00, 0x00
  424. };
  425. static const u8 sn_ov7648[0x1c] = {
  426. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  427. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  428. /* reg8 reg9 rega regb regc regd rege regf */
  429. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  430. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  431. 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
  432. /* reg18 reg19 reg1a reg1b */
  433. 0x0b, 0x00, 0x00, 0x00
  434. };
  435. static const u8 sn_ov7660[0x1c] = {
  436. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  437. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  438. /* reg8 reg9 rega regb regc regd rege regf */
  439. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  440. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  441. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  442. /* reg18 reg19 reg1a reg1b */
  443. 0x07, 0x00, 0x00, 0x00
  444. };
  445. static const u8 sn_po1030[0x1c] = {
  446. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  447. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  448. /* reg8 reg9 rega regb regc regd rege regf */
  449. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  450. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  451. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
  452. /* reg18 reg19 reg1a reg1b */
  453. 0x07, 0x00, 0x00, 0x00
  454. };
  455. static const u8 sn_po2030n[0x1c] = {
  456. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  457. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  458. /* reg8 reg9 rega regb regc regd rege regf */
  459. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  460. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  461. 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00,
  462. /* reg18 reg19 reg1a reg1b */
  463. 0x07, 0x00, 0x00, 0x00
  464. };
  465. static const u8 sn_soi768[0x1c] = {
  466. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  467. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  468. /* reg8 reg9 rega regb regc regd rege regf */
  469. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  470. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  471. 0x03, 0x00, 0x00, 0x01, 0x08, 0x28, 0x1e, 0x00,
  472. /* reg18 reg19 reg1a reg1b */
  473. 0x07, 0x00, 0x00, 0x00
  474. };
  475. static const u8 sn_sp80708[0x1c] = {
  476. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  477. 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  478. /* reg8 reg9 rega regb regc regd rege regf */
  479. 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  480. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  481. 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
  482. /* reg18 reg19 reg1a reg1b */
  483. 0x07, 0x00, 0x00, 0x00
  484. };
  485. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  486. static const u8 *sn_tb[] = {
  487. [SENSOR_ADCM1700] = sn_adcm1700,
  488. [SENSOR_GC0307] = sn_gc0307,
  489. [SENSOR_HV7131R] = sn_hv7131,
  490. [SENSOR_MI0360] = sn_mi0360,
  491. [SENSOR_MI0360B] = sn_mi0360b,
  492. [SENSOR_MO4000] = sn_mo4000,
  493. [SENSOR_MT9V111] = sn_mt9v111,
  494. [SENSOR_OM6802] = sn_om6802,
  495. [SENSOR_OV7630] = sn_ov7630,
  496. [SENSOR_OV7648] = sn_ov7648,
  497. [SENSOR_OV7660] = sn_ov7660,
  498. [SENSOR_PO1030] = sn_po1030,
  499. [SENSOR_PO2030N] = sn_po2030n,
  500. [SENSOR_SOI768] = sn_soi768,
  501. [SENSOR_SP80708] = sn_sp80708,
  502. };
  503. /* default gamma table */
  504. static const u8 gamma_def[17] = {
  505. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  506. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  507. };
  508. /* gamma for sensor ADCM1700 */
  509. static const u8 gamma_spec_0[17] = {
  510. 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
  511. 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
  512. };
  513. /* gamma for sensors HV7131R and MT9V111 */
  514. static const u8 gamma_spec_1[17] = {
  515. 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
  516. 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
  517. };
  518. /* gamma for sensor GC0307 */
  519. static const u8 gamma_spec_2[17] = {
  520. 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
  521. 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
  522. };
  523. /* gamma for sensor SP80708 */
  524. static const u8 gamma_spec_3[17] = {
  525. 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
  526. 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
  527. };
  528. /* color matrix and offsets */
  529. static const u8 reg84[] = {
  530. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
  531. 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
  532. 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
  533. 0x00, 0x00, 0x00 /* YUV offsets */
  534. };
  535. #define DELAY 0xdd
  536. static const u8 adcm1700_sensor_init[][8] = {
  537. {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
  538. {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
  539. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  540. {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  541. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  542. {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
  543. {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
  544. {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
  545. {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
  546. {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
  547. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  548. {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
  549. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  550. {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
  551. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  552. {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
  553. {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  554. {}
  555. };
  556. static const u8 adcm1700_sensor_param1[][8] = {
  557. {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
  558. {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
  559. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  560. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  561. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  562. {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
  563. {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
  564. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  565. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  566. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  567. {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
  568. {}
  569. };
  570. static const u8 gc0307_sensor_init[][8] = {
  571. {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
  572. {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
  573. {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
  574. {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
  575. {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  576. {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  577. {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  578. {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
  579. {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  580. {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  581. {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
  582. {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
  583. {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
  584. {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
  585. {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
  586. {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
  587. {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
  588. {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
  589. {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
  590. {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
  591. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
  592. {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
  593. {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
  594. {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
  595. {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
  596. {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
  597. {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
  598. {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
  599. {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
  600. {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
  601. {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
  602. {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
  603. {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  604. {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
  605. {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
  606. {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
  607. {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
  608. {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
  609. {}
  610. };
  611. static const u8 gc0307_sensor_param1[][8] = {
  612. {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
  613. {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
  614. {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
  615. {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
  616. /*param3*/
  617. {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
  618. {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
  619. {}
  620. };
  621. static const u8 hv7131r_sensor_init[][8] = {
  622. {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  623. {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
  624. {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
  625. /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  626. {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  627. {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
  628. /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  629. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  630. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  631. {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
  632. {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  633. {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
  634. {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
  635. {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  636. {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  637. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  638. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  639. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  640. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  641. {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  642. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  643. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  644. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  645. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  646. {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  647. {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
  648. /* set sensor clock */
  649. {}
  650. };
  651. static const u8 mi0360_sensor_init[][8] = {
  652. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  653. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  654. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  655. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  656. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  657. {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  658. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  659. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  660. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  661. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  662. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  663. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  664. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  665. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  666. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  667. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  668. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  669. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  670. {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  671. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  672. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  673. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  674. {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
  675. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  676. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  677. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  678. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  679. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  680. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  681. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  682. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  683. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  684. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  685. {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  686. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  687. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  688. {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
  689. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
  690. {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  691. {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  692. {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
  693. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  694. {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
  695. {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
  696. /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  697. /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  698. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  699. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  700. {}
  701. };
  702. static const u8 mi0360b_sensor_init[][8] = {
  703. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  704. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  705. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  706. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  707. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  708. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  709. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  710. {0xd1, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  711. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  712. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  713. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  714. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  715. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  716. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  717. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  718. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  719. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  720. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  721. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  722. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  723. {0xd1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  724. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  725. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  726. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  727. {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
  728. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  729. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  730. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  731. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  732. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  733. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  734. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  735. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  736. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  737. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  738. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  739. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  740. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  741. {0xd1, 0x5d, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10},
  742. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10},
  743. {}
  744. };
  745. static const u8 mi0360b_sensor_param1[][8] = {
  746. {0xb1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  747. {0xb1, 0x5d, 0x06, 0x00, 0x53, 0x00, 0x00, 0x10},
  748. {0xb1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10},
  749. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  750. {0xd1, 0x5d, 0x2b, 0x00, 0xd1, 0x01, 0xc9, 0x10},
  751. {0xd1, 0x5d, 0x2d, 0x00, 0xed, 0x00, 0xd1, 0x10},
  752. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  753. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  754. {}
  755. };
  756. static const u8 mo4000_sensor_init[][8] = {
  757. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  758. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  759. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  760. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  761. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  762. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  763. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  764. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  765. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  766. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  767. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  768. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  769. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  770. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  771. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  772. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  773. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  774. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  775. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  776. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  777. {}
  778. };
  779. static const u8 mt9v111_sensor_init[][8] = {
  780. {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
  781. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  782. {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  783. {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
  784. {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
  785. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
  786. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  787. {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
  788. {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
  789. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  790. {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
  791. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  792. {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
  793. {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
  794. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  795. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  796. {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
  797. {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
  798. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
  799. {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
  800. {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
  801. {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
  802. {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
  803. {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
  804. {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
  805. {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
  806. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
  807. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  808. {}
  809. };
  810. static const u8 mt9v111_sensor_param1[][8] = {
  811. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  812. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  813. {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
  814. {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
  815. {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
  816. /*******/
  817. {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
  818. {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
  819. {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
  820. {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
  821. {}
  822. };
  823. static const u8 om6802_init0[2][8] = {
  824. /*fixme: variable*/
  825. {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
  826. {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
  827. };
  828. static const u8 om6802_sensor_init[][8] = {
  829. {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
  830. /* factory mode */
  831. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  832. /* output raw RGB */
  833. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  834. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  835. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  836. /* auto-exposure speed (0) / white balance mode (auto RGB) */
  837. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  838. * set color mode */
  839. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  840. * max AGC value in AE */
  841. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  842. * preset AGC */
  843. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  844. * preset brightness */
  845. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  846. * preset contrast */
  847. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  848. * preset gamma */
  849. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  850. /* luminance mode (0x4f -> AutoExpo on) */
  851. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  852. /* preset shutter */
  853. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  854. * auto frame rate */
  855. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  856. {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  857. {}
  858. };
  859. static const u8 om6802_sensor_param1[][8] = {
  860. {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
  861. {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
  862. {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
  863. {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
  864. {}
  865. };
  866. static const u8 ov7630_sensor_init[][8] = {
  867. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  868. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  869. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  870. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  871. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  872. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  873. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  874. /* win: i2c_r from 00 to 80 */
  875. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  876. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  877. /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
  878. 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
  879. {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
  880. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  881. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  882. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  883. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  884. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  885. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  886. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  887. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  888. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  889. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  890. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  891. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  892. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  893. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  894. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  895. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  896. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  897. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  898. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  899. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  900. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  901. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  902. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  903. {}
  904. };
  905. static const u8 ov7630_sensor_param1[][8] = {
  906. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  907. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  908. /*fixme: + 0x12, 0x04*/
  909. /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
  910. * set by setvflip */
  911. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  912. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  913. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  914. /* */
  915. /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  916. /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  917. /* */
  918. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  919. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  920. {}
  921. };
  922. static const u8 ov7648_sensor_init[][8] = {
  923. {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
  924. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  925. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  926. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  927. {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
  928. {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
  929. {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
  930. {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
  931. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  932. {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
  933. {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
  934. {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
  935. {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
  936. {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
  937. {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
  938. {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
  939. {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
  940. {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
  941. {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
  942. {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
  943. {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
  944. {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
  945. {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
  946. /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
  947. /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
  948. /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
  949. {}
  950. };
  951. static const u8 ov7648_sensor_param1[][8] = {
  952. /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
  953. /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
  954. * set by setvflip */
  955. {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
  956. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  957. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  958. /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
  959. /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
  960. /*...*/
  961. {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
  962. /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  963. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  964. /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
  965. /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  966. /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
  967. {}
  968. };
  969. static const u8 ov7660_sensor_init[][8] = {
  970. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  971. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  972. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  973. /* Outformat = rawRGB */
  974. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  975. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
  976. /* GAIN BLUE RED VREF */
  977. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  978. /* COM 1 BAVE GEAVE AECHH */
  979. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  980. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  981. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  982. /* AECH CLKRC COM7 COM8 */
  983. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  984. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  985. /* HSTART HSTOP VSTRT VSTOP */
  986. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  987. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  988. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  989. /* BOS GBOS GROS ROS (BGGR offset) */
  990. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  991. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  992. /* AEW AEB VPT BBIAS */
  993. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  994. /* GbBIAS RSVD EXHCH EXHCL */
  995. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  996. /* RBIAS ADVFL ASDVFH YAVE */
  997. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  998. /* HSYST HSYEN HREF */
  999. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  1000. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  1001. /* ADC ACOM OFON TSLB */
  1002. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  1003. /* COM11 COM12 COM13 COM14 */
  1004. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  1005. /* EDGE COM15 COM16 COM17 */
  1006. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  1007. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  1008. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  1009. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  1010. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  1011. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  1012. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  1013. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  1014. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  1015. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  1016. /* LCC1 LCC2 LCC3 LCC4 */
  1017. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  1018. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  1019. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1020. /* band gap reference [0:3] DBLV */
  1021. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  1022. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  1023. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  1024. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  1025. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  1026. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  1027. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  1028. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  1029. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  1030. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  1031. /* not in all ms-win traces*/
  1032. {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
  1033. {}
  1034. };
  1035. static const u8 ov7660_sensor_param1[][8] = {
  1036. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  1037. /* bits[3..0]reserved */
  1038. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  1039. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1040. /* VREF vertical frame ctrl */
  1041. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1042. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  1043. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  1044. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  1045. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  1046. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  1047. /****** (some exchanges in the win trace) ******/
  1048. /*fixme:param2*/
  1049. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  1050. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  1051. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  1052. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  1053. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  1054. /****** (some exchanges in the win trace) ******/
  1055. /******!! startsensor KO if changed !!****/
  1056. /*fixme: param3*/
  1057. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  1058. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  1059. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1060. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  1061. {}
  1062. };
  1063. static const u8 po1030_sensor_init[][8] = {
  1064. /* the sensor registers are described in m5602/m5602_po1030.h */
  1065. {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
  1066. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  1067. {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1068. {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1069. {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
  1070. {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  1071. {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
  1072. {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  1073. {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
  1074. {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
  1075. {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
  1076. {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
  1077. {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  1078. {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1079. {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
  1080. {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
  1081. {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
  1082. {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
  1083. {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
  1084. {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
  1085. {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  1086. {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  1087. {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
  1088. {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
  1089. {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
  1090. {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
  1091. {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1092. {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
  1093. {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  1094. {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  1095. {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1096. {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1097. {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
  1098. {}
  1099. };
  1100. static const u8 po1030_sensor_param1[][8] = {
  1101. /* from ms-win traces - these values change with auto gain/expo/wb.. */
  1102. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1103. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1104. /* mean values */
  1105. {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
  1106. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
  1107. {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
  1108. {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
  1109. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
  1110. {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1111. /* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
  1112. {}
  1113. };
  1114. static const u8 po2030n_sensor_init[][8] = {
  1115. {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
  1116. {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
  1117. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1118. {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1119. {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
  1120. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1121. {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
  1122. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1123. {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
  1124. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1125. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1126. {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
  1127. {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
  1128. {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
  1129. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1130. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
  1131. {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
  1132. {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1133. {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  1134. {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
  1135. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
  1136. {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1137. {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
  1138. {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
  1139. {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
  1140. {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
  1141. {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
  1142. {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
  1143. {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
  1144. {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1145. {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
  1146. {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
  1147. {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
  1148. {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1149. {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
  1150. {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
  1151. {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
  1152. {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1153. {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
  1154. {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
  1155. {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
  1156. {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1157. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1158. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
  1159. {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
  1160. {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
  1161. {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
  1162. {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
  1163. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
  1164. {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
  1165. {}
  1166. };
  1167. static const u8 po2030n_sensor_param1[][8] = {
  1168. {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
  1169. {DELAY, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
  1170. {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
  1171. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1172. {0xd1, 0x6e, 0x16, 0x50, 0x40, 0x49, 0x40, 0x10},
  1173. /*param2*/
  1174. {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1175. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1176. {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
  1177. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1178. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1179. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1180. {0xc1, 0x6e, 0x16, 0x52, 0x40, 0x48, 0x00, 0x10},
  1181. /*after start*/
  1182. {0xa1, 0x6e, 0x15, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1183. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1184. {0xa1, 0x6e, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x10},
  1185. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1186. {0xa1, 0x6e, 0x1b, 0x53, 0x00, 0x00, 0x00, 0x10},
  1187. {}
  1188. };
  1189. static const u8 soi768_sensor_init[][8] = {
  1190. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  1191. {DELAY, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
  1192. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  1193. {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
  1194. {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
  1195. {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
  1196. {}
  1197. };
  1198. static const u8 soi768_sensor_param1[][8] = {
  1199. {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
  1200. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1201. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1202. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1203. {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
  1204. /* */
  1205. /* {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1206. /* {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
  1207. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1208. /* {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1209. {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
  1210. /* the next sequence should be used for auto gain */
  1211. {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
  1212. /* global gain ? : 07 - change with 0x15 at the end */
  1213. {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
  1214. {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
  1215. {0xb1, 0x21, 0x2d, 0x00, 0x02, 0x00, 0x00, 0x10},
  1216. /* exposure ? : 0200 - change with 0x1e at the end */
  1217. {}
  1218. };
  1219. static const u8 sp80708_sensor_init[][8] = {
  1220. {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
  1221. {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
  1222. {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1223. {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1224. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1225. {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1226. {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
  1227. {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
  1228. {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
  1229. {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
  1230. {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
  1231. {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
  1232. {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
  1233. {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
  1234. {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
  1235. {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
  1236. {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
  1237. {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
  1238. {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
  1239. {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
  1240. {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
  1241. {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
  1242. {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
  1243. {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
  1244. {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
  1245. {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1246. {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
  1247. {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
  1248. {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
  1249. {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
  1250. {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
  1251. {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
  1252. {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
  1253. {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
  1254. {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
  1255. {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
  1256. {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
  1257. {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
  1258. {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
  1259. {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
  1260. {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
  1261. {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
  1262. {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
  1263. {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1264. {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
  1265. {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
  1266. {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
  1267. {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
  1268. {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
  1269. {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
  1270. {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
  1271. {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
  1272. {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
  1273. {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
  1274. {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
  1275. {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1276. {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
  1277. {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  1278. {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
  1279. {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
  1280. {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
  1281. {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1282. {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
  1283. {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
  1284. {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
  1285. {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
  1286. {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
  1287. {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
  1288. {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
  1289. {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
  1290. {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
  1291. {}
  1292. };
  1293. static const u8 sp80708_sensor_param1[][8] = {
  1294. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1295. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1296. {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
  1297. {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
  1298. {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
  1299. {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  1300. {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
  1301. {}
  1302. };
  1303. static const u8 (*sensor_init[])[8] = {
  1304. [SENSOR_ADCM1700] = adcm1700_sensor_init,
  1305. [SENSOR_GC0307] = gc0307_sensor_init,
  1306. [SENSOR_HV7131R] = hv7131r_sensor_init,
  1307. [SENSOR_MI0360] = mi0360_sensor_init,
  1308. [SENSOR_MI0360B] = mi0360b_sensor_init,
  1309. [SENSOR_MO4000] = mo4000_sensor_init,
  1310. [SENSOR_MT9V111] = mt9v111_sensor_init,
  1311. [SENSOR_OM6802] = om6802_sensor_init,
  1312. [SENSOR_OV7630] = ov7630_sensor_init,
  1313. [SENSOR_OV7648] = ov7648_sensor_init,
  1314. [SENSOR_OV7660] = ov7660_sensor_init,
  1315. [SENSOR_PO1030] = po1030_sensor_init,
  1316. [SENSOR_PO2030N] = po2030n_sensor_init,
  1317. [SENSOR_SOI768] = soi768_sensor_init,
  1318. [SENSOR_SP80708] = sp80708_sensor_init,
  1319. };
  1320. /* read <len> bytes to gspca_dev->usb_buf */
  1321. static void reg_r(struct gspca_dev *gspca_dev,
  1322. u16 value, int len)
  1323. {
  1324. int ret;
  1325. if (gspca_dev->usb_err < 0)
  1326. return;
  1327. #ifdef GSPCA_DEBUG
  1328. if (len > USB_BUF_SZ) {
  1329. err("reg_r: buffer overflow");
  1330. return;
  1331. }
  1332. #endif
  1333. ret = usb_control_msg(gspca_dev->dev,
  1334. usb_rcvctrlpipe(gspca_dev->dev, 0),
  1335. 0,
  1336. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1337. value, 0,
  1338. gspca_dev->usb_buf, len,
  1339. 500);
  1340. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  1341. if (ret < 0) {
  1342. err("reg_r err %d", ret);
  1343. gspca_dev->usb_err = ret;
  1344. }
  1345. }
  1346. static void reg_w1(struct gspca_dev *gspca_dev,
  1347. u16 value,
  1348. u8 data)
  1349. {
  1350. int ret;
  1351. if (gspca_dev->usb_err < 0)
  1352. return;
  1353. PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
  1354. gspca_dev->usb_buf[0] = data;
  1355. ret = usb_control_msg(gspca_dev->dev,
  1356. usb_sndctrlpipe(gspca_dev->dev, 0),
  1357. 0x08,
  1358. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1359. value,
  1360. 0,
  1361. gspca_dev->usb_buf, 1,
  1362. 500);
  1363. if (ret < 0) {
  1364. err("reg_w1 err %d", ret);
  1365. gspca_dev->usb_err = ret;
  1366. }
  1367. }
  1368. static void reg_w(struct gspca_dev *gspca_dev,
  1369. u16 value,
  1370. const u8 *buffer,
  1371. int len)
  1372. {
  1373. int ret;
  1374. if (gspca_dev->usb_err < 0)
  1375. return;
  1376. PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
  1377. value, buffer[0], buffer[1]);
  1378. #ifdef GSPCA_DEBUG
  1379. if (len > USB_BUF_SZ) {
  1380. err("reg_w: buffer overflow");
  1381. return;
  1382. }
  1383. #endif
  1384. memcpy(gspca_dev->usb_buf, buffer, len);
  1385. ret = usb_control_msg(gspca_dev->dev,
  1386. usb_sndctrlpipe(gspca_dev->dev, 0),
  1387. 0x08,
  1388. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1389. value, 0,
  1390. gspca_dev->usb_buf, len,
  1391. 500);
  1392. if (ret < 0) {
  1393. err("reg_w err %d", ret);
  1394. gspca_dev->usb_err = ret;
  1395. }
  1396. }
  1397. /* I2C write 1 byte */
  1398. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1399. {
  1400. struct sd *sd = (struct sd *) gspca_dev;
  1401. int ret;
  1402. if (gspca_dev->usb_err < 0)
  1403. return;
  1404. PDEBUG(D_USBO, "i2c_w1 [%02x] = %02x", reg, val);
  1405. switch (sd->sensor) {
  1406. case SENSOR_ADCM1700:
  1407. case SENSOR_OM6802:
  1408. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1409. gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
  1410. break;
  1411. default: /* i2c command = a1 (400 kHz) */
  1412. gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
  1413. break;
  1414. }
  1415. gspca_dev->usb_buf[1] = sd->i2c_addr;
  1416. gspca_dev->usb_buf[2] = reg;
  1417. gspca_dev->usb_buf[3] = val;
  1418. gspca_dev->usb_buf[4] = 0;
  1419. gspca_dev->usb_buf[5] = 0;
  1420. gspca_dev->usb_buf[6] = 0;
  1421. gspca_dev->usb_buf[7] = 0x10;
  1422. ret = usb_control_msg(gspca_dev->dev,
  1423. usb_sndctrlpipe(gspca_dev->dev, 0),
  1424. 0x08,
  1425. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1426. 0x08, /* value = i2c */
  1427. 0,
  1428. gspca_dev->usb_buf, 8,
  1429. 500);
  1430. if (ret < 0) {
  1431. err("i2c_w1 err %d", ret);
  1432. gspca_dev->usb_err = ret;
  1433. }
  1434. }
  1435. /* I2C write 8 bytes */
  1436. static void i2c_w8(struct gspca_dev *gspca_dev,
  1437. const u8 *buffer)
  1438. {
  1439. int ret;
  1440. if (gspca_dev->usb_err < 0)
  1441. return;
  1442. PDEBUG(D_USBO, "i2c_w8 [%02x] = %02x ..",
  1443. buffer[2], buffer[3]);
  1444. memcpy(gspca_dev->usb_buf, buffer, 8);
  1445. ret = usb_control_msg(gspca_dev->dev,
  1446. usb_sndctrlpipe(gspca_dev->dev, 0),
  1447. 0x08,
  1448. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1449. 0x08, 0, /* value, index */
  1450. gspca_dev->usb_buf, 8,
  1451. 500);
  1452. msleep(2);
  1453. if (ret < 0) {
  1454. err("i2c_w8 err %d", ret);
  1455. gspca_dev->usb_err = ret;
  1456. }
  1457. }
  1458. /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
  1459. static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
  1460. {
  1461. struct sd *sd = (struct sd *) gspca_dev;
  1462. u8 mode[8];
  1463. switch (sd->sensor) {
  1464. case SENSOR_ADCM1700:
  1465. case SENSOR_OM6802:
  1466. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1467. mode[0] = 0x80 | 0x10;
  1468. break;
  1469. default: /* i2c command = 91 (400 kHz) */
  1470. mode[0] = 0x81 | 0x10;
  1471. break;
  1472. }
  1473. mode[1] = sd->i2c_addr;
  1474. mode[2] = reg;
  1475. mode[3] = 0;
  1476. mode[4] = 0;
  1477. mode[5] = 0;
  1478. mode[6] = 0;
  1479. mode[7] = 0x10;
  1480. i2c_w8(gspca_dev, mode);
  1481. msleep(2);
  1482. mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
  1483. mode[2] = 0;
  1484. i2c_w8(gspca_dev, mode);
  1485. msleep(2);
  1486. reg_r(gspca_dev, 0x0a, 5);
  1487. }
  1488. static void i2c_w_seq(struct gspca_dev *gspca_dev,
  1489. const u8 (*data)[8])
  1490. {
  1491. while ((*data)[0] != 0) {
  1492. if ((*data)[0] != DELAY)
  1493. i2c_w8(gspca_dev, *data);
  1494. else
  1495. msleep((*data)[1]);
  1496. data++;
  1497. }
  1498. }
  1499. static void hv7131r_probe(struct gspca_dev *gspca_dev)
  1500. {
  1501. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  1502. msleep(10);
  1503. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  1504. msleep(10);
  1505. i2c_r(gspca_dev, 0, 5); /* read sensor id */
  1506. if (gspca_dev->usb_buf[0] == 0x02
  1507. && gspca_dev->usb_buf[1] == 0x09
  1508. && gspca_dev->usb_buf[2] == 0x01
  1509. && gspca_dev->usb_buf[3] == 0x00
  1510. && gspca_dev->usb_buf[4] == 0x00) {
  1511. PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
  1512. return;
  1513. }
  1514. PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
  1515. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  1516. gspca_dev->usb_buf[2]);
  1517. }
  1518. static void mi0360_probe(struct gspca_dev *gspca_dev)
  1519. {
  1520. struct sd *sd = (struct sd *) gspca_dev;
  1521. int i, j;
  1522. u16 val = 0;
  1523. static const u8 probe_tb[][4][8] = {
  1524. { /* mi0360 */
  1525. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  1526. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1527. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1528. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1529. },
  1530. { /* mt9v111 */
  1531. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1532. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1533. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1534. {}
  1535. },
  1536. };
  1537. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1538. reg_w1(gspca_dev, 0x17, 0x62);
  1539. reg_w1(gspca_dev, 0x01, 0x08);
  1540. for (j = 0; j < 3; j++)
  1541. i2c_w8(gspca_dev, probe_tb[i][j]);
  1542. msleep(2);
  1543. reg_r(gspca_dev, 0x0a, 5);
  1544. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1545. if (probe_tb[i][3][0] != 0)
  1546. i2c_w8(gspca_dev, probe_tb[i][3]);
  1547. reg_w1(gspca_dev, 0x01, 0x29);
  1548. reg_w1(gspca_dev, 0x17, 0x42);
  1549. if (val != 0xffff)
  1550. break;
  1551. }
  1552. if (gspca_dev->usb_err < 0)
  1553. return;
  1554. switch (val) {
  1555. case 0x8221:
  1556. PDEBUG(D_PROBE, "Sensor mi0360b");
  1557. sd->sensor = SENSOR_MI0360B;
  1558. break;
  1559. case 0x823a:
  1560. PDEBUG(D_PROBE, "Sensor mt9v111");
  1561. sd->sensor = SENSOR_MT9V111;
  1562. break;
  1563. case 0x8243:
  1564. PDEBUG(D_PROBE, "Sensor mi0360");
  1565. break;
  1566. default:
  1567. PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
  1568. break;
  1569. }
  1570. }
  1571. static void ov7630_probe(struct gspca_dev *gspca_dev)
  1572. {
  1573. struct sd *sd = (struct sd *) gspca_dev;
  1574. u16 val;
  1575. /* check ov76xx */
  1576. reg_w1(gspca_dev, 0x17, 0x62);
  1577. reg_w1(gspca_dev, 0x01, 0x08);
  1578. sd->i2c_addr = 0x21;
  1579. i2c_r(gspca_dev, 0x0a, 2);
  1580. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1581. reg_w1(gspca_dev, 0x01, 0x29);
  1582. reg_w1(gspca_dev, 0x17, 0x42);
  1583. if (gspca_dev->usb_err < 0)
  1584. return;
  1585. if (val == 0x7628) { /* soi768 */
  1586. sd->sensor = SENSOR_SOI768;
  1587. /*fixme: only valid for 0c45:613e?*/
  1588. gspca_dev->cam.input_flags =
  1589. V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  1590. PDEBUG(D_PROBE, "Sensor soi768");
  1591. return;
  1592. }
  1593. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1594. }
  1595. static void ov7648_probe(struct gspca_dev *gspca_dev)
  1596. {
  1597. struct sd *sd = (struct sd *) gspca_dev;
  1598. u16 val;
  1599. /* check ov76xx */
  1600. reg_w1(gspca_dev, 0x17, 0x62);
  1601. reg_w1(gspca_dev, 0x01, 0x08);
  1602. sd->i2c_addr = 0x21;
  1603. i2c_r(gspca_dev, 0x0a, 2);
  1604. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1605. reg_w1(gspca_dev, 0x01, 0x29);
  1606. reg_w1(gspca_dev, 0x17, 0x42);
  1607. if ((val & 0xff00) == 0x7600) { /* ov76xx */
  1608. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1609. return;
  1610. }
  1611. /* check po1030 */
  1612. reg_w1(gspca_dev, 0x17, 0x62);
  1613. reg_w1(gspca_dev, 0x01, 0x08);
  1614. sd->i2c_addr = 0x6e;
  1615. i2c_r(gspca_dev, 0x00, 2);
  1616. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1617. reg_w1(gspca_dev, 0x01, 0x29);
  1618. reg_w1(gspca_dev, 0x17, 0x42);
  1619. if (gspca_dev->usb_err < 0)
  1620. return;
  1621. if (val == 0x1030) { /* po1030 */
  1622. PDEBUG(D_PROBE, "Sensor po1030");
  1623. sd->sensor = SENSOR_PO1030;
  1624. return;
  1625. }
  1626. err("Unknown sensor %04x", val);
  1627. }
  1628. /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
  1629. static void po2030n_probe(struct gspca_dev *gspca_dev)
  1630. {
  1631. struct sd *sd = (struct sd *) gspca_dev;
  1632. u16 val;
  1633. /* check gc0307 */
  1634. reg_w1(gspca_dev, 0x17, 0x62);
  1635. reg_w1(gspca_dev, 0x01, 0x08);
  1636. reg_w1(gspca_dev, 0x02, 0x22);
  1637. sd->i2c_addr = 0x21;
  1638. i2c_r(gspca_dev, 0x00, 1);
  1639. val = gspca_dev->usb_buf[4];
  1640. reg_w1(gspca_dev, 0x01, 0x29); /* reset */
  1641. reg_w1(gspca_dev, 0x17, 0x42);
  1642. if (val == 0x99) { /* gc0307 (?) */
  1643. PDEBUG(D_PROBE, "Sensor gc0307");
  1644. sd->sensor = SENSOR_GC0307;
  1645. return;
  1646. }
  1647. /* check po2030n */
  1648. reg_w1(gspca_dev, 0x17, 0x62);
  1649. reg_w1(gspca_dev, 0x01, 0x0a);
  1650. sd->i2c_addr = 0x6e;
  1651. i2c_r(gspca_dev, 0x00, 2);
  1652. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1653. reg_w1(gspca_dev, 0x01, 0x29);
  1654. reg_w1(gspca_dev, 0x17, 0x42);
  1655. if (gspca_dev->usb_err < 0)
  1656. return;
  1657. if (val == 0x2030) {
  1658. PDEBUG(D_PROBE, "Sensor po2030n");
  1659. /* sd->sensor = SENSOR_PO2030N; */
  1660. } else {
  1661. err("Unknown sensor ID %04x", val);
  1662. }
  1663. }
  1664. /* this function is called at probe time */
  1665. static int sd_config(struct gspca_dev *gspca_dev,
  1666. const struct usb_device_id *id)
  1667. {
  1668. struct sd *sd = (struct sd *) gspca_dev;
  1669. struct cam *cam;
  1670. sd->bridge = id->driver_info >> 16;
  1671. sd->sensor = id->driver_info >> 8;
  1672. sd->flags = id->driver_info;
  1673. cam = &gspca_dev->cam;
  1674. if (sd->sensor == SENSOR_ADCM1700) {
  1675. cam->cam_mode = cif_mode;
  1676. cam->nmodes = ARRAY_SIZE(cif_mode);
  1677. } else {
  1678. cam->cam_mode = vga_mode;
  1679. cam->nmodes = ARRAY_SIZE(vga_mode);
  1680. }
  1681. cam->npkt = 24; /* 24 packets per ISOC message */
  1682. cam->ctrls = sd->ctrls;
  1683. sd->ag_cnt = -1;
  1684. sd->quality = QUALITY_DEF;
  1685. sd->jpegqual = 80;
  1686. return 0;
  1687. }
  1688. /* this function is called at probe and resume time */
  1689. static int sd_init(struct gspca_dev *gspca_dev)
  1690. {
  1691. struct sd *sd = (struct sd *) gspca_dev;
  1692. const u8 *sn9c1xx;
  1693. u8 regGpio[] = { 0x29, 0x74 }; /* with audio */
  1694. u8 regF1;
  1695. /* setup a selector by bridge */
  1696. reg_w1(gspca_dev, 0xf1, 0x01);
  1697. reg_r(gspca_dev, 0x00, 1);
  1698. reg_w1(gspca_dev, 0xf1, 0x00);
  1699. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1700. regF1 = gspca_dev->usb_buf[0];
  1701. if (gspca_dev->usb_err < 0)
  1702. return gspca_dev->usb_err;
  1703. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  1704. switch (sd->bridge) {
  1705. case BRIDGE_SN9C102P:
  1706. if (regF1 != 0x11)
  1707. return -ENODEV;
  1708. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1709. break;
  1710. case BRIDGE_SN9C105:
  1711. if (regF1 != 0x11)
  1712. return -ENODEV;
  1713. if (sd->sensor == SENSOR_MI0360)
  1714. mi0360_probe(gspca_dev);
  1715. reg_w(gspca_dev, 0x01, regGpio, 2);
  1716. break;
  1717. case BRIDGE_SN9C120:
  1718. if (regF1 != 0x12)
  1719. return -ENODEV;
  1720. switch (sd->sensor) {
  1721. case SENSOR_MI0360:
  1722. mi0360_probe(gspca_dev);
  1723. break;
  1724. case SENSOR_OV7630:
  1725. ov7630_probe(gspca_dev);
  1726. break;
  1727. case SENSOR_OV7648:
  1728. ov7648_probe(gspca_dev);
  1729. break;
  1730. case SENSOR_PO2030N:
  1731. po2030n_probe(gspca_dev);
  1732. break;
  1733. }
  1734. regGpio[1] = 0x70; /* no audio */
  1735. reg_w(gspca_dev, 0x01, regGpio, 2);
  1736. break;
  1737. default:
  1738. /* case BRIDGE_SN9C110: */
  1739. /* case BRIDGE_SN9C325: */
  1740. if (regF1 != 0x12)
  1741. return -ENODEV;
  1742. reg_w1(gspca_dev, 0x02, 0x62);
  1743. break;
  1744. }
  1745. if (sd->sensor == SENSOR_OM6802)
  1746. sd->ctrls[SHARPNESS].def = 0x10;
  1747. /* Note we do not disable the sensor clock here (power saving mode),
  1748. as that also disables the button on the cam. */
  1749. reg_w1(gspca_dev, 0xf1, 0x00);
  1750. /* set the i2c address */
  1751. sn9c1xx = sn_tb[sd->sensor];
  1752. sd->i2c_addr = sn9c1xx[9];
  1753. gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
  1754. return gspca_dev->usb_err;
  1755. }
  1756. static u32 setexposure(struct gspca_dev *gspca_dev,
  1757. u32 expo)
  1758. {
  1759. struct sd *sd = (struct sd *) gspca_dev;
  1760. switch (sd->sensor) {
  1761. case SENSOR_GC0307: {
  1762. int a, b;
  1763. /* expo = 0..255 -> a = 19..43 */
  1764. a = 19 + expo * 25 / 256;
  1765. i2c_w1(gspca_dev, 0x68, a);
  1766. a -= 12;
  1767. b = a * a * 4; /* heuristic */
  1768. i2c_w1(gspca_dev, 0x03, b >> 8);
  1769. i2c_w1(gspca_dev, 0x04, b);
  1770. break;
  1771. }
  1772. case SENSOR_HV7131R: {
  1773. u8 Expodoit[] =
  1774. { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1775. Expodoit[3] = expo >> 16;
  1776. Expodoit[4] = expo >> 8;
  1777. Expodoit[5] = expo;
  1778. i2c_w8(gspca_dev, Expodoit);
  1779. break;
  1780. }
  1781. case SENSOR_MI0360:
  1782. case SENSOR_MI0360B: {
  1783. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1784. { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1785. static const u8 doit[] = /* update sensor */
  1786. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1787. static const u8 sensorgo[] = /* sensor on */
  1788. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1789. if (expo > 0x0635)
  1790. expo = 0x0635;
  1791. else if (expo < 0x0001)
  1792. expo = 0x0001;
  1793. expoMi[3] = expo >> 8;
  1794. expoMi[4] = expo;
  1795. i2c_w8(gspca_dev, expoMi);
  1796. i2c_w8(gspca_dev, doit);
  1797. i2c_w8(gspca_dev, sensorgo);
  1798. break;
  1799. }
  1800. case SENSOR_MO4000: {
  1801. u8 expoMof[] =
  1802. { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1803. u8 expoMo10[] =
  1804. { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1805. static const u8 gainMo[] =
  1806. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1807. if (expo > 0x1fff)
  1808. expo = 0x1fff;
  1809. else if (expo < 0x0001)
  1810. expo = 0x0001;
  1811. expoMof[3] = (expo & 0x03fc) >> 2;
  1812. i2c_w8(gspca_dev, expoMof);
  1813. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1814. | ((expo & 0x0003) << 4);
  1815. i2c_w8(gspca_dev, expoMo10);
  1816. i2c_w8(gspca_dev, gainMo);
  1817. PDEBUG(D_FRAM, "set exposure %d",
  1818. ((expoMo10[3] & 0x07) << 10)
  1819. | (expoMof[3] << 2)
  1820. | ((expoMo10[3] & 0x30) >> 4));
  1821. break;
  1822. }
  1823. case SENSOR_MT9V111: {
  1824. u8 expo_c1[] =
  1825. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1826. if (expo > 0x0280)
  1827. expo = 0x0280;
  1828. else if (expo < 0x0040)
  1829. expo = 0x0040;
  1830. expo_c1[3] = expo >> 8;
  1831. expo_c1[4] = expo;
  1832. i2c_w8(gspca_dev, expo_c1);
  1833. break;
  1834. }
  1835. case SENSOR_OM6802: {
  1836. u8 gainOm[] =
  1837. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1838. /* preset AGC - works when AutoExpo = off */
  1839. if (expo > 0x03ff)
  1840. expo = 0x03ff;
  1841. if (expo < 0x0001)
  1842. expo = 0x0001;
  1843. gainOm[3] = expo >> 2;
  1844. i2c_w8(gspca_dev, gainOm);
  1845. reg_w1(gspca_dev, 0x96, expo >> 5);
  1846. PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
  1847. break;
  1848. }
  1849. }
  1850. return expo;
  1851. }
  1852. static void setbrightness(struct gspca_dev *gspca_dev)
  1853. {
  1854. struct sd *sd = (struct sd *) gspca_dev;
  1855. unsigned int expo;
  1856. int brightness;
  1857. u8 k2;
  1858. brightness = sd->ctrls[BRIGHTNESS].val;
  1859. k2 = (brightness - 0x80) >> 2;
  1860. switch (sd->sensor) {
  1861. case SENSOR_ADCM1700:
  1862. if (k2 > 0x1f)
  1863. k2 = 0; /* only positive Y offset */
  1864. break;
  1865. case SENSOR_HV7131R:
  1866. expo = brightness << 12;
  1867. if (expo > 0x002dc6c0)
  1868. expo = 0x002dc6c0;
  1869. else if (expo < 0x02a0)
  1870. expo = 0x02a0;
  1871. sd->exposure = setexposure(gspca_dev, expo);
  1872. break;
  1873. case SENSOR_MI0360:
  1874. case SENSOR_MO4000:
  1875. expo = brightness << 4;
  1876. sd->exposure = setexposure(gspca_dev, expo);
  1877. break;
  1878. case SENSOR_MI0360B:
  1879. expo = brightness << 2;
  1880. sd->exposure = setexposure(gspca_dev, expo);
  1881. break;
  1882. case SENSOR_GC0307:
  1883. case SENSOR_MT9V111:
  1884. expo = brightness;
  1885. sd->exposure = setexposure(gspca_dev, expo);
  1886. return; /* don't set the Y offset */
  1887. case SENSOR_OM6802:
  1888. expo = brightness << 2;
  1889. sd->exposure = setexposure(gspca_dev, expo);
  1890. k2 = brightness >> 3;
  1891. break;
  1892. }
  1893. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  1894. }
  1895. static void setcontrast(struct gspca_dev *gspca_dev)
  1896. {
  1897. struct sd *sd = (struct sd *) gspca_dev;
  1898. u8 k2;
  1899. u8 contrast[6];
  1900. k2 = sd->ctrls[CONTRAST].val * 0x30 / (CONTRAST_MAX + 1)
  1901. + 0x10; /* 10..40 */
  1902. contrast[0] = (k2 + 1) / 2; /* red */
  1903. contrast[1] = 0;
  1904. contrast[2] = k2; /* green */
  1905. contrast[3] = 0;
  1906. contrast[4] = (k2 + 1) / 5; /* blue */
  1907. contrast[5] = 0;
  1908. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  1909. }
  1910. static void setcolors(struct gspca_dev *gspca_dev)
  1911. {
  1912. struct sd *sd = (struct sd *) gspca_dev;
  1913. int i, v, colors;
  1914. const s16 *uv;
  1915. u8 reg8a[12]; /* U & V gains */
  1916. static const s16 uv_com[6] = { /* same as reg84 in signed decimal */
  1917. -24, -38, 64, /* UR UG UB */
  1918. 62, -51, -9 /* VR VG VB */
  1919. };
  1920. static const s16 uv_mi0360b[6] = {
  1921. -20, -38, 64, /* UR UG UB */
  1922. 60, -51, -9 /* VR VG VB */
  1923. };
  1924. colors = sd->ctrls[COLORS].val;
  1925. if (sd->sensor == SENSOR_MI0360B)
  1926. uv = uv_mi0360b;
  1927. else
  1928. uv = uv_com;
  1929. for (i = 0; i < 6; i++) {
  1930. v = uv[i] * colors / COLORS_DEF;
  1931. reg8a[i * 2] = v;
  1932. reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
  1933. }
  1934. reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
  1935. }
  1936. static void setredblue(struct gspca_dev *gspca_dev)
  1937. {
  1938. struct sd *sd = (struct sd *) gspca_dev;
  1939. reg_w1(gspca_dev, 0x05, sd->ctrls[RED].val);
  1940. /* reg_w1(gspca_dev, 0x07, 32); */
  1941. reg_w1(gspca_dev, 0x06, sd->ctrls[BLUE].val);
  1942. }
  1943. static void setgamma(struct gspca_dev *gspca_dev)
  1944. {
  1945. struct sd *sd = (struct sd *) gspca_dev;
  1946. int i, val;
  1947. u8 gamma[17];
  1948. const u8 *gamma_base;
  1949. static const u8 delta[17] = {
  1950. 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
  1951. 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
  1952. };
  1953. switch (sd->sensor) {
  1954. case SENSOR_ADCM1700:
  1955. gamma_base = gamma_spec_0;
  1956. break;
  1957. case SENSOR_HV7131R:
  1958. case SENSOR_MI0360B:
  1959. case SENSOR_MT9V111:
  1960. gamma_base = gamma_spec_1;
  1961. break;
  1962. case SENSOR_GC0307:
  1963. gamma_base = gamma_spec_2;
  1964. break;
  1965. case SENSOR_SP80708:
  1966. gamma_base = gamma_spec_3;
  1967. break;
  1968. default:
  1969. gamma_base = gamma_def;
  1970. break;
  1971. }
  1972. val = sd->ctrls[GAMMA].val;
  1973. for (i = 0; i < sizeof gamma; i++)
  1974. gamma[i] = gamma_base[i]
  1975. + delta[i] * (val - GAMMA_DEF) / 32;
  1976. reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
  1977. }
  1978. static void setautogain(struct gspca_dev *gspca_dev)
  1979. {
  1980. struct sd *sd = (struct sd *) gspca_dev;
  1981. if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
  1982. return;
  1983. switch (sd->sensor) {
  1984. case SENSOR_OV7630:
  1985. case SENSOR_OV7648: {
  1986. u8 comb;
  1987. if (sd->sensor == SENSOR_OV7630)
  1988. comb = 0xc0;
  1989. else
  1990. comb = 0xa0;
  1991. if (sd->ctrls[AUTOGAIN].val)
  1992. comb |= 0x03;
  1993. i2c_w1(&sd->gspca_dev, 0x13, comb);
  1994. return;
  1995. }
  1996. }
  1997. if (sd->ctrls[AUTOGAIN].val)
  1998. sd->ag_cnt = AG_CNT_START;
  1999. else
  2000. sd->ag_cnt = -1;
  2001. }
  2002. static void sethvflip(struct gspca_dev *gspca_dev)
  2003. {
  2004. struct sd *sd = (struct sd *) gspca_dev;
  2005. u8 comn;
  2006. switch (sd->sensor) {
  2007. case SENSOR_HV7131R:
  2008. comn = 0x18; /* clkdiv = 1, ablcen = 1 */
  2009. if (sd->ctrls[VFLIP].val)
  2010. comn |= 0x01;
  2011. i2c_w1(gspca_dev, 0x01, comn); /* sctra */
  2012. break;
  2013. case SENSOR_OV7630:
  2014. comn = 0x02;
  2015. if (!sd->ctrls[VFLIP].val)
  2016. comn |= 0x80;
  2017. i2c_w1(gspca_dev, 0x75, comn);
  2018. break;
  2019. case SENSOR_OV7648:
  2020. comn = 0x06;
  2021. if (sd->ctrls[VFLIP].val)
  2022. comn |= 0x80;
  2023. i2c_w1(gspca_dev, 0x75, comn);
  2024. break;
  2025. case SENSOR_PO2030N:
  2026. /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
  2027. * (reset value: 0x0A)
  2028. * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
  2029. * bit6: VM: Vertical Mirror: 0: disable, 1: enable
  2030. * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
  2031. * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
  2032. * bit3-0: X
  2033. */
  2034. comn = 0x0a;
  2035. if (sd->ctrls[HFLIP].val)
  2036. comn |= 0x80;
  2037. if (sd->ctrls[VFLIP].val)
  2038. comn |= 0x40;
  2039. i2c_w1(&sd->gspca_dev, 0x1e, comn);
  2040. break;
  2041. }
  2042. }
  2043. static void setsharpness(struct gspca_dev *gspca_dev)
  2044. {
  2045. struct sd *sd = (struct sd *) gspca_dev;
  2046. reg_w1(gspca_dev, 0x99, sd->ctrls[SHARPNESS].val);
  2047. }
  2048. static void setinfrared(struct gspca_dev *gspca_dev)
  2049. {
  2050. struct sd *sd = (struct sd *) gspca_dev;
  2051. if (gspca_dev->ctrl_dis & (1 << INFRARED))
  2052. return;
  2053. /*fixme: different sequence for StarCam Clip and StarCam 370i */
  2054. /* Clip */
  2055. i2c_w1(gspca_dev, 0x02, /* gpio */
  2056. sd->ctrls[INFRARED].val ? 0x66 : 0x64);
  2057. }
  2058. static void setfreq(struct gspca_dev *gspca_dev)
  2059. {
  2060. struct sd *sd = (struct sd *) gspca_dev;
  2061. if (gspca_dev->ctrl_dis & (1 << FREQ))
  2062. return;
  2063. if (sd->sensor == SENSOR_OV7660) {
  2064. u8 com8;
  2065. com8 = 0xdf; /* auto gain/wb/expo */
  2066. switch (sd->ctrls[FREQ].val) {
  2067. case 0: /* Banding filter disabled */
  2068. i2c_w1(gspca_dev, 0x13, com8 | 0x20);
  2069. break;
  2070. case 1: /* 50 hz */
  2071. i2c_w1(gspca_dev, 0x13, com8);
  2072. i2c_w1(gspca_dev, 0x3b, 0x0a);
  2073. break;
  2074. case 2: /* 60 hz */
  2075. i2c_w1(gspca_dev, 0x13, com8);
  2076. i2c_w1(gspca_dev, 0x3b, 0x02);
  2077. break;
  2078. }
  2079. } else {
  2080. u8 reg2a = 0, reg2b = 0, reg2d = 0;
  2081. /* Get reg2a / reg2d base values */
  2082. switch (sd->sensor) {
  2083. case SENSOR_OV7630:
  2084. reg2a = 0x08;
  2085. reg2d = 0x01;
  2086. break;
  2087. case SENSOR_OV7648:
  2088. reg2a = 0x11;
  2089. reg2d = 0x81;
  2090. break;
  2091. }
  2092. switch (sd->ctrls[FREQ].val) {
  2093. case 0: /* Banding filter disabled */
  2094. break;
  2095. case 1: /* 50 hz (filter on and framerate adj) */
  2096. reg2a |= 0x80;
  2097. reg2b = 0xac;
  2098. reg2d |= 0x04;
  2099. break;
  2100. case 2: /* 60 hz (filter on, no framerate adj) */
  2101. reg2a |= 0x80;
  2102. reg2d |= 0x04;
  2103. break;
  2104. }
  2105. i2c_w1(gspca_dev, 0x2a, reg2a);
  2106. i2c_w1(gspca_dev, 0x2b, reg2b);
  2107. i2c_w1(gspca_dev, 0x2d, reg2d);
  2108. }
  2109. }
  2110. static void setjpegqual(struct gspca_dev *gspca_dev)
  2111. {
  2112. struct sd *sd = (struct sd *) gspca_dev;
  2113. int i, sc;
  2114. if (sd->jpegqual < 50)
  2115. sc = 5000 / sd->jpegqual;
  2116. else
  2117. sc = 200 - sd->jpegqual * 2;
  2118. #if USB_BUF_SZ < 64
  2119. #error "No room enough in usb_buf for quantization table"
  2120. #endif
  2121. for (i = 0; i < 64; i++)
  2122. gspca_dev->usb_buf[i] =
  2123. (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
  2124. usb_control_msg(gspca_dev->dev,
  2125. usb_sndctrlpipe(gspca_dev->dev, 0),
  2126. 0x08,
  2127. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2128. 0x0100, 0,
  2129. gspca_dev->usb_buf, 64,
  2130. 500);
  2131. for (i = 0; i < 64; i++)
  2132. gspca_dev->usb_buf[i] =
  2133. (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
  2134. usb_control_msg(gspca_dev->dev,
  2135. usb_sndctrlpipe(gspca_dev->dev, 0),
  2136. 0x08,
  2137. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2138. 0x0140, 0,
  2139. gspca_dev->usb_buf, 64,
  2140. 500);
  2141. sd->reg18 ^= 0x40;
  2142. reg_w1(gspca_dev, 0x18, sd->reg18);
  2143. }
  2144. /* -- start the camera -- */
  2145. static int sd_start(struct gspca_dev *gspca_dev)
  2146. {
  2147. struct sd *sd = (struct sd *) gspca_dev;
  2148. int i;
  2149. u8 reg0102[2];
  2150. u8 reg1, reg17;
  2151. const u8 *sn9c1xx;
  2152. const u8 (*init)[8];
  2153. const u8 *reg9a;
  2154. int mode;
  2155. static const u8 reg9a_def[] =
  2156. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  2157. static const u8 reg9a_spec[] =
  2158. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  2159. static const u8 regd4[] = {0x60, 0x00, 0x00};
  2160. static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  2161. static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  2162. static const u8 CA_adcm1700[] =
  2163. { 0x14, 0xec, 0x0a, 0xf6 };
  2164. static const u8 CA_po2030n[] =
  2165. { 0x1e, 0xe2, 0x14, 0xec };
  2166. static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  2167. static const u8 CE_gc0307[] =
  2168. { 0x32, 0xce, 0x2d, 0xd3 };
  2169. static const u8 CE_ov76xx[] =
  2170. { 0x32, 0xdd, 0x32, 0xdd };
  2171. static const u8 CE_po2030n[] =
  2172. { 0x14, 0xe7, 0x1e, 0xdd };
  2173. /* create the JPEG header */
  2174. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  2175. 0x21); /* JPEG 422 */
  2176. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2177. /* initialize the bridge */
  2178. sn9c1xx = sn_tb[sd->sensor];
  2179. /* sensor clock already enabled in sd_init */
  2180. /* reg_w1(gspca_dev, 0xf1, 0x00); */
  2181. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  2182. /* configure gpio */
  2183. reg0102[0] = sn9c1xx[1];
  2184. reg0102[1] = sn9c1xx[2];
  2185. if (gspca_dev->audio)
  2186. reg0102[1] |= 0x04; /* keep the audio connection */
  2187. reg_w(gspca_dev, 0x01, reg0102, 2);
  2188. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  2189. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
  2190. switch (sd->sensor) {
  2191. case SENSOR_GC0307:
  2192. case SENSOR_OV7660:
  2193. case SENSOR_PO1030:
  2194. case SENSOR_PO2030N:
  2195. case SENSOR_SOI768:
  2196. case SENSOR_SP80708:
  2197. reg9a = reg9a_spec;
  2198. break;
  2199. default:
  2200. reg9a = reg9a_def;
  2201. break;
  2202. }
  2203. reg_w(gspca_dev, 0x9a, reg9a, 6);
  2204. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
  2205. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  2206. switch (sd->sensor) {
  2207. case SENSOR_ADCM1700:
  2208. reg_w1(gspca_dev, 0x01, 0x43);
  2209. reg_w1(gspca_dev, 0x17, 0x62);
  2210. reg_w1(gspca_dev, 0x01, 0x42);
  2211. reg_w1(gspca_dev, 0x01, 0x42);
  2212. break;
  2213. case SENSOR_GC0307:
  2214. msleep(50);
  2215. reg_w1(gspca_dev, 0x01, 0x61);
  2216. reg_w1(gspca_dev, 0x17, 0x22);
  2217. reg_w1(gspca_dev, 0x01, 0x60);
  2218. reg_w1(gspca_dev, 0x01, 0x40);
  2219. msleep(50);
  2220. break;
  2221. case SENSOR_MI0360B:
  2222. reg_w1(gspca_dev, 0x01, 0x61);
  2223. reg_w1(gspca_dev, 0x17, 0x60);
  2224. reg_w1(gspca_dev, 0x01, 0x60);
  2225. reg_w1(gspca_dev, 0x01, 0x40);
  2226. break;
  2227. case SENSOR_MT9V111:
  2228. reg_w1(gspca_dev, 0x01, 0x61);
  2229. reg_w1(gspca_dev, 0x17, 0x61);
  2230. reg_w1(gspca_dev, 0x01, 0x60);
  2231. reg_w1(gspca_dev, 0x01, 0x40);
  2232. break;
  2233. case SENSOR_OM6802:
  2234. msleep(10);
  2235. reg_w1(gspca_dev, 0x02, 0x73);
  2236. reg_w1(gspca_dev, 0x17, 0x60);
  2237. reg_w1(gspca_dev, 0x01, 0x22);
  2238. msleep(100);
  2239. reg_w1(gspca_dev, 0x01, 0x62);
  2240. reg_w1(gspca_dev, 0x17, 0x64);
  2241. reg_w1(gspca_dev, 0x17, 0x64);
  2242. reg_w1(gspca_dev, 0x01, 0x42);
  2243. msleep(10);
  2244. reg_w1(gspca_dev, 0x01, 0x42);
  2245. i2c_w8(gspca_dev, om6802_init0[0]);
  2246. i2c_w8(gspca_dev, om6802_init0[1]);
  2247. msleep(15);
  2248. reg_w1(gspca_dev, 0x02, 0x71);
  2249. msleep(150);
  2250. break;
  2251. case SENSOR_OV7630:
  2252. reg_w1(gspca_dev, 0x01, 0x61);
  2253. reg_w1(gspca_dev, 0x17, 0xe2);
  2254. reg_w1(gspca_dev, 0x01, 0x60);
  2255. reg_w1(gspca_dev, 0x01, 0x40);
  2256. break;
  2257. case SENSOR_OV7648:
  2258. reg_w1(gspca_dev, 0x01, 0x63);
  2259. reg_w1(gspca_dev, 0x17, 0x20);
  2260. reg_w1(gspca_dev, 0x01, 0x62);
  2261. reg_w1(gspca_dev, 0x01, 0x42);
  2262. break;
  2263. case SENSOR_PO1030:
  2264. case SENSOR_SOI768:
  2265. reg_w1(gspca_dev, 0x01, 0x61);
  2266. reg_w1(gspca_dev, 0x17, 0x20);
  2267. reg_w1(gspca_dev, 0x01, 0x60);
  2268. reg_w1(gspca_dev, 0x01, 0x40);
  2269. break;
  2270. case SENSOR_PO2030N:
  2271. case SENSOR_OV7660:
  2272. reg_w1(gspca_dev, 0x01, 0x63);
  2273. reg_w1(gspca_dev, 0x17, 0x20);
  2274. reg_w1(gspca_dev, 0x01, 0x62);
  2275. reg_w1(gspca_dev, 0x01, 0x42);
  2276. break;
  2277. case SENSOR_SP80708:
  2278. reg_w1(gspca_dev, 0x01, 0x63);
  2279. reg_w1(gspca_dev, 0x17, 0x20);
  2280. reg_w1(gspca_dev, 0x01, 0x62);
  2281. reg_w1(gspca_dev, 0x01, 0x42);
  2282. msleep(100);
  2283. reg_w1(gspca_dev, 0x02, 0x62);
  2284. break;
  2285. default:
  2286. /* case SENSOR_HV7131R: */
  2287. /* case SENSOR_MI0360: */
  2288. /* case SENSOR_MO4000: */
  2289. reg_w1(gspca_dev, 0x01, 0x43);
  2290. reg_w1(gspca_dev, 0x17, 0x61);
  2291. reg_w1(gspca_dev, 0x01, 0x42);
  2292. if (sd->sensor == SENSOR_HV7131R)
  2293. hv7131r_probe(gspca_dev);
  2294. break;
  2295. }
  2296. /* initialize the sensor */
  2297. i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
  2298. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  2299. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  2300. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  2301. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  2302. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2303. if (sd->sensor == SENSOR_ADCM1700) {
  2304. reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
  2305. reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
  2306. } else {
  2307. reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
  2308. reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
  2309. }
  2310. reg_w1(gspca_dev, 0xc6, 0x00);
  2311. reg_w1(gspca_dev, 0xc7, 0x00);
  2312. if (sd->sensor == SENSOR_ADCM1700) {
  2313. reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
  2314. reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
  2315. } else {
  2316. reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
  2317. reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
  2318. }
  2319. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2320. switch (sd->sensor) {
  2321. case SENSOR_GC0307:
  2322. reg17 = 0xa2;
  2323. break;
  2324. case SENSOR_MT9V111:
  2325. case SENSOR_MI0360B:
  2326. reg17 = 0xe0;
  2327. break;
  2328. case SENSOR_ADCM1700:
  2329. case SENSOR_OV7630:
  2330. reg17 = 0xe2;
  2331. break;
  2332. case SENSOR_OV7648:
  2333. reg17 = 0x20;
  2334. break;
  2335. case SENSOR_OV7660:
  2336. case SENSOR_SOI768:
  2337. reg17 = 0xa0;
  2338. break;
  2339. case SENSOR_PO1030:
  2340. case SENSOR_PO2030N:
  2341. reg17 = 0xa0;
  2342. break;
  2343. default:
  2344. reg17 = 0x60;
  2345. break;
  2346. }
  2347. reg_w1(gspca_dev, 0x17, reg17);
  2348. reg_w1(gspca_dev, 0x05, 0x00); /* red */
  2349. reg_w1(gspca_dev, 0x07, 0x00); /* green */
  2350. reg_w1(gspca_dev, 0x06, 0x00); /* blue */
  2351. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  2352. setgamma(gspca_dev);
  2353. /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
  2354. for (i = 0; i < 8; i++)
  2355. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2356. switch (sd->sensor) {
  2357. case SENSOR_ADCM1700:
  2358. case SENSOR_OV7660:
  2359. case SENSOR_SP80708:
  2360. reg_w1(gspca_dev, 0x9a, 0x05);
  2361. break;
  2362. case SENSOR_GC0307:
  2363. case SENSOR_MT9V111:
  2364. case SENSOR_MI0360B:
  2365. reg_w1(gspca_dev, 0x9a, 0x07);
  2366. break;
  2367. case SENSOR_OV7630:
  2368. case SENSOR_OV7648:
  2369. reg_w1(gspca_dev, 0x9a, 0x0a);
  2370. break;
  2371. case SENSOR_PO2030N:
  2372. case SENSOR_SOI768:
  2373. reg_w1(gspca_dev, 0x9a, 0x06);
  2374. break;
  2375. default:
  2376. reg_w1(gspca_dev, 0x9a, 0x08);
  2377. break;
  2378. }
  2379. setsharpness(gspca_dev);
  2380. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2381. reg_w1(gspca_dev, 0x05, 0x20); /* red */
  2382. reg_w1(gspca_dev, 0x07, 0x20); /* green */
  2383. reg_w1(gspca_dev, 0x06, 0x20); /* blue */
  2384. init = NULL;
  2385. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  2386. if (mode)
  2387. reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
  2388. else
  2389. reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
  2390. reg17 = 0x61; /* 0x:20: enable sensor clock */
  2391. switch (sd->sensor) {
  2392. case SENSOR_ADCM1700:
  2393. init = adcm1700_sensor_param1;
  2394. reg1 = 0x46;
  2395. reg17 = 0xe2;
  2396. break;
  2397. case SENSOR_GC0307:
  2398. init = gc0307_sensor_param1;
  2399. reg17 = 0xa2;
  2400. reg1 = 0x44;
  2401. break;
  2402. case SENSOR_MI0360B:
  2403. init = mi0360b_sensor_param1;
  2404. reg1 &= ~0x02; /* don't inverse pin S_PWR_DN */
  2405. reg17 = 0xe2;
  2406. break;
  2407. case SENSOR_MO4000:
  2408. if (mode) {
  2409. /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
  2410. reg1 = 0x06; /* clk 24Mz */
  2411. } else {
  2412. reg17 = 0x22; /* 640 MCKSIZE */
  2413. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  2414. }
  2415. break;
  2416. case SENSOR_MT9V111:
  2417. init = mt9v111_sensor_param1;
  2418. if (mode) {
  2419. reg1 = 0x04; /* 320 clk 48Mhz */
  2420. } else {
  2421. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  2422. reg17 = 0xc2;
  2423. }
  2424. break;
  2425. case SENSOR_OM6802:
  2426. init = om6802_sensor_param1;
  2427. reg17 = 0x64; /* 640 MCKSIZE */
  2428. break;
  2429. case SENSOR_OV7630:
  2430. init = ov7630_sensor_param1;
  2431. reg17 = 0xe2;
  2432. reg1 = 0x44;
  2433. break;
  2434. case SENSOR_OV7648:
  2435. init = ov7648_sensor_param1;
  2436. reg17 = 0x21;
  2437. /* reg1 = 0x42; * 42 - 46? */
  2438. break;
  2439. case SENSOR_OV7660:
  2440. init = ov7660_sensor_param1;
  2441. if (sd->bridge == BRIDGE_SN9C120) {
  2442. if (mode) { /* 320x240 - 160x120 */
  2443. reg17 = 0xa2;
  2444. reg1 = 0x44; /* 48 Mhz, video trf eneble */
  2445. }
  2446. } else {
  2447. reg17 = 0x22;
  2448. reg1 = 0x06; /* 24 Mhz, video trf eneble
  2449. * inverse power down */
  2450. }
  2451. break;
  2452. case SENSOR_PO1030:
  2453. init = po1030_sensor_param1;
  2454. reg17 = 0xa2;
  2455. reg1 = 0x44;
  2456. break;
  2457. case SENSOR_PO2030N:
  2458. init = po2030n_sensor_param1;
  2459. reg1 = 0x46;
  2460. reg17 = 0xa2;
  2461. break;
  2462. case SENSOR_SOI768:
  2463. init = soi768_sensor_param1;
  2464. reg1 = 0x44;
  2465. reg17 = 0xa2;
  2466. break;
  2467. case SENSOR_SP80708:
  2468. init = sp80708_sensor_param1;
  2469. if (mode) {
  2470. /*?? reg1 = 0x04; * 320 clk 48Mhz */
  2471. } else {
  2472. reg1 = 0x46; /* 640 clk 48Mz */
  2473. reg17 = 0xa2;
  2474. }
  2475. break;
  2476. }
  2477. /* more sensor initialization - param1 */
  2478. if (init != NULL) {
  2479. i2c_w_seq(gspca_dev, init);
  2480. /* init = NULL; */
  2481. }
  2482. reg_w(gspca_dev, 0xc0, C0, 6);
  2483. switch (sd->sensor) {
  2484. case SENSOR_ADCM1700:
  2485. case SENSOR_GC0307:
  2486. case SENSOR_SOI768:
  2487. reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
  2488. break;
  2489. case SENSOR_PO2030N:
  2490. reg_w(gspca_dev, 0xca, CA_po2030n, 4);
  2491. break;
  2492. default:
  2493. reg_w(gspca_dev, 0xca, CA, 4);
  2494. break;
  2495. }
  2496. switch (sd->sensor) {
  2497. case SENSOR_ADCM1700:
  2498. case SENSOR_OV7630:
  2499. case SENSOR_OV7648:
  2500. case SENSOR_OV7660:
  2501. case SENSOR_SOI768:
  2502. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  2503. break;
  2504. case SENSOR_GC0307:
  2505. reg_w(gspca_dev, 0xce, CE_gc0307, 4);
  2506. break;
  2507. case SENSOR_PO2030N:
  2508. reg_w(gspca_dev, 0xce, CE_po2030n, 4);
  2509. break;
  2510. default:
  2511. reg_w(gspca_dev, 0xce, CE, 4);
  2512. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  2513. break;
  2514. }
  2515. /* here change size mode 0 -> VGA; 1 -> CIF */
  2516. sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
  2517. reg_w1(gspca_dev, 0x18, sd->reg18);
  2518. setjpegqual(gspca_dev);
  2519. reg_w1(gspca_dev, 0x17, reg17);
  2520. reg_w1(gspca_dev, 0x01, reg1);
  2521. sethvflip(gspca_dev);
  2522. setbrightness(gspca_dev);
  2523. setcontrast(gspca_dev);
  2524. setcolors(gspca_dev);
  2525. setautogain(gspca_dev);
  2526. setfreq(gspca_dev);
  2527. return gspca_dev->usb_err;
  2528. }
  2529. static void sd_stopN(struct gspca_dev *gspca_dev)
  2530. {
  2531. struct sd *sd = (struct sd *) gspca_dev;
  2532. static const u8 stophv7131[] =
  2533. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  2534. static const u8 stopmi0360[] =
  2535. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  2536. static const u8 stopov7648[] =
  2537. { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
  2538. static const u8 stopsoi768[] =
  2539. { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
  2540. u8 data;
  2541. const u8 *sn9c1xx;
  2542. data = 0x0b;
  2543. switch (sd->sensor) {
  2544. case SENSOR_GC0307:
  2545. data = 0x29;
  2546. break;
  2547. case SENSOR_HV7131R:
  2548. i2c_w8(gspca_dev, stophv7131);
  2549. data = 0x2b;
  2550. break;
  2551. case SENSOR_MI0360:
  2552. case SENSOR_MI0360B:
  2553. i2c_w8(gspca_dev, stopmi0360);
  2554. data = 0x29;
  2555. break;
  2556. case SENSOR_OV7648:
  2557. i2c_w8(gspca_dev, stopov7648);
  2558. /* fall thru */
  2559. case SENSOR_MT9V111:
  2560. case SENSOR_OV7630:
  2561. case SENSOR_PO1030:
  2562. data = 0x29;
  2563. break;
  2564. case SENSOR_SOI768:
  2565. i2c_w8(gspca_dev, stopsoi768);
  2566. data = 0x29;
  2567. break;
  2568. }
  2569. sn9c1xx = sn_tb[sd->sensor];
  2570. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  2571. reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
  2572. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  2573. reg_w1(gspca_dev, 0x01, data);
  2574. /* Don't disable sensor clock as that disables the button on the cam */
  2575. /* reg_w1(gspca_dev, 0xf1, 0x01); */
  2576. }
  2577. static void do_autogain(struct gspca_dev *gspca_dev)
  2578. {
  2579. struct sd *sd = (struct sd *) gspca_dev;
  2580. int delta;
  2581. int expotimes;
  2582. u8 luma_mean = 130;
  2583. u8 luma_delta = 20;
  2584. /* Thanks S., without your advice, autobright should not work :) */
  2585. if (sd->ag_cnt < 0)
  2586. return;
  2587. if (--sd->ag_cnt >= 0)
  2588. return;
  2589. sd->ag_cnt = AG_CNT_START;
  2590. delta = atomic_read(&sd->avg_lum);
  2591. PDEBUG(D_FRAM, "mean lum %d", delta);
  2592. if (delta < luma_mean - luma_delta ||
  2593. delta > luma_mean + luma_delta) {
  2594. switch (sd->sensor) {
  2595. case SENSOR_GC0307:
  2596. expotimes = sd->exposure;
  2597. expotimes += (luma_mean - delta) >> 6;
  2598. if (expotimes < 0)
  2599. expotimes = 0;
  2600. sd->exposure = setexposure(gspca_dev,
  2601. (unsigned int) expotimes);
  2602. break;
  2603. case SENSOR_HV7131R:
  2604. expotimes = sd->exposure >> 8;
  2605. expotimes += (luma_mean - delta) >> 4;
  2606. if (expotimes < 0)
  2607. expotimes = 0;
  2608. sd->exposure = setexposure(gspca_dev,
  2609. (unsigned int) (expotimes << 8));
  2610. break;
  2611. case SENSOR_OM6802:
  2612. expotimes = sd->exposure;
  2613. expotimes += (luma_mean - delta) >> 2;
  2614. if (expotimes < 0)
  2615. expotimes = 0;
  2616. sd->exposure = setexposure(gspca_dev,
  2617. (unsigned int) expotimes);
  2618. setredblue(gspca_dev);
  2619. break;
  2620. default:
  2621. /* case SENSOR_MO4000: */
  2622. /* case SENSOR_MI0360: */
  2623. /* case SENSOR_MI0360B: */
  2624. /* case SENSOR_MT9V111: */
  2625. expotimes = sd->exposure;
  2626. expotimes += (luma_mean - delta) >> 6;
  2627. if (expotimes < 0)
  2628. expotimes = 0;
  2629. sd->exposure = setexposure(gspca_dev,
  2630. (unsigned int) expotimes);
  2631. setredblue(gspca_dev);
  2632. break;
  2633. }
  2634. }
  2635. }
  2636. /* scan the URB packets */
  2637. /* This function is run at interrupt level. */
  2638. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2639. u8 *data, /* isoc packet */
  2640. int len) /* iso packet length */
  2641. {
  2642. struct sd *sd = (struct sd *) gspca_dev;
  2643. int sof, avg_lum;
  2644. /* the image ends on a 64 bytes block starting with
  2645. * ff d9 ff ff 00 c4 c4 96
  2646. * and followed by various information including luminosity */
  2647. /* this block may be splitted between two packets */
  2648. /* a new image always starts in a new packet */
  2649. switch (gspca_dev->last_packet_type) {
  2650. case DISCARD_PACKET: /* restart image building */
  2651. sof = len - 64;
  2652. if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9)
  2653. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  2654. return;
  2655. case LAST_PACKET: /* put the JPEG 422 header */
  2656. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2657. sd->jpeg_hdr, JPEG_HDR_SZ);
  2658. break;
  2659. }
  2660. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2661. data = gspca_dev->image;
  2662. if (data == NULL)
  2663. return;
  2664. sof = gspca_dev->image_len - 64;
  2665. if (data[sof] != 0xff
  2666. || data[sof + 1] != 0xd9)
  2667. return;
  2668. /* end of image found - remove the trailing data */
  2669. gspca_dev->image_len = sof + 2;
  2670. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  2671. if (sd->ag_cnt < 0)
  2672. return;
  2673. /* w1 w2 w3 */
  2674. /* w4 w5 w6 */
  2675. /* w7 w8 */
  2676. /* w4 */
  2677. avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
  2678. /* w6 */
  2679. avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
  2680. /* w2 */
  2681. avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
  2682. /* w8 */
  2683. avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
  2684. /* w5 */
  2685. avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
  2686. avg_lum >>= 4;
  2687. atomic_set(&sd->avg_lum, avg_lum);
  2688. }
  2689. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  2690. struct v4l2_jpegcompression *jcomp)
  2691. {
  2692. struct sd *sd = (struct sd *) gspca_dev;
  2693. if (jcomp->quality < QUALITY_MIN)
  2694. sd->quality = QUALITY_MIN;
  2695. else if (jcomp->quality > QUALITY_MAX)
  2696. sd->quality = QUALITY_MAX;
  2697. else
  2698. sd->quality = jcomp->quality;
  2699. if (gspca_dev->streaming)
  2700. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2701. return 0;
  2702. }
  2703. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  2704. struct v4l2_jpegcompression *jcomp)
  2705. {
  2706. struct sd *sd = (struct sd *) gspca_dev;
  2707. memset(jcomp, 0, sizeof *jcomp);
  2708. jcomp->quality = sd->quality;
  2709. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  2710. | V4L2_JPEG_MARKER_DQT;
  2711. return 0;
  2712. }
  2713. static int sd_querymenu(struct gspca_dev *gspca_dev,
  2714. struct v4l2_querymenu *menu)
  2715. {
  2716. switch (menu->id) {
  2717. case V4L2_CID_POWER_LINE_FREQUENCY:
  2718. switch (menu->index) {
  2719. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  2720. strcpy((char *) menu->name, "NoFliker");
  2721. return 0;
  2722. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  2723. strcpy((char *) menu->name, "50 Hz");
  2724. return 0;
  2725. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  2726. strcpy((char *) menu->name, "60 Hz");
  2727. return 0;
  2728. }
  2729. break;
  2730. }
  2731. return -EINVAL;
  2732. }
  2733. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2734. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2735. u8 *data, /* interrupt packet data */
  2736. int len) /* interrupt packet length */
  2737. {
  2738. int ret = -EINVAL;
  2739. if (len == 1 && data[0] == 1) {
  2740. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2741. input_sync(gspca_dev->input_dev);
  2742. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2743. input_sync(gspca_dev->input_dev);
  2744. ret = 0;
  2745. }
  2746. return ret;
  2747. }
  2748. #endif
  2749. /* sub-driver description */
  2750. static const struct sd_desc sd_desc = {
  2751. .name = MODULE_NAME,
  2752. .ctrls = sd_ctrls,
  2753. .nctrls = NCTRLS,
  2754. .config = sd_config,
  2755. .init = sd_init,
  2756. .start = sd_start,
  2757. .stopN = sd_stopN,
  2758. .pkt_scan = sd_pkt_scan,
  2759. .dq_callback = do_autogain,
  2760. .get_jcomp = sd_get_jcomp,
  2761. .set_jcomp = sd_set_jcomp,
  2762. .querymenu = sd_querymenu,
  2763. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2764. .int_pkt_scan = sd_int_pkt_scan,
  2765. #endif
  2766. };
  2767. /* -- module initialisation -- */
  2768. #define BS(bridge, sensor) \
  2769. .driver_info = (BRIDGE_ ## bridge << 16) \
  2770. | (SENSOR_ ## sensor << 8)
  2771. #define BSF(bridge, sensor, flags) \
  2772. .driver_info = (BRIDGE_ ## bridge << 16) \
  2773. | (SENSOR_ ## sensor << 8) \
  2774. | (flags)
  2775. static const __devinitdata struct usb_device_id device_table[] = {
  2776. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2777. {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
  2778. {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
  2779. #endif
  2780. {USB_DEVICE(0x045e, 0x00f5), BSF(SN9C105, OV7660, PDN_INV)},
  2781. {USB_DEVICE(0x045e, 0x00f7), BSF(SN9C105, OV7660, PDN_INV)},
  2782. {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
  2783. {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
  2784. {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
  2785. {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
  2786. {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
  2787. /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
  2788. {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
  2789. /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
  2790. /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
  2791. {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
  2792. /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
  2793. {USB_DEVICE(0x0c45, 0x60c0), BS(SN9C105, MI0360)},
  2794. /* or MT9V111 */
  2795. /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
  2796. /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
  2797. /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
  2798. {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
  2799. {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
  2800. /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
  2801. /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
  2802. /* {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
  2803. {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
  2804. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2805. {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
  2806. {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
  2807. #endif
  2808. {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
  2809. {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)}, /* /GC0305*/
  2810. /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
  2811. {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
  2812. {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
  2813. {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
  2814. {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
  2815. /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
  2816. /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
  2817. /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
  2818. {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
  2819. /*bw600.inf:*/
  2820. {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
  2821. {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
  2822. {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
  2823. {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
  2824. /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
  2825. {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
  2826. /* or MT9V111 / MI0360B */
  2827. /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
  2828. {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
  2829. {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
  2830. #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
  2831. {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
  2832. #endif
  2833. {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
  2834. {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
  2835. {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
  2836. /* or GC0305 / GC0307 */
  2837. {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
  2838. {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
  2839. {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)}, /*sn9c120b*/
  2840. {}
  2841. };
  2842. MODULE_DEVICE_TABLE(usb, device_table);
  2843. /* -- device connect -- */
  2844. static int sd_probe(struct usb_interface *intf,
  2845. const struct usb_device_id *id)
  2846. {
  2847. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2848. THIS_MODULE);
  2849. }
  2850. static struct usb_driver sd_driver = {
  2851. .name = MODULE_NAME,
  2852. .id_table = device_table,
  2853. .probe = sd_probe,
  2854. .disconnect = gspca_disconnect,
  2855. #ifdef CONFIG_PM
  2856. .suspend = gspca_suspend,
  2857. .resume = gspca_resume,
  2858. #endif
  2859. };
  2860. /* -- module insert / remove -- */
  2861. static int __init sd_mod_init(void)
  2862. {
  2863. return usb_register(&sd_driver);
  2864. }
  2865. static void __exit sd_mod_exit(void)
  2866. {
  2867. usb_deregister(&sd_driver);
  2868. }
  2869. module_init(sd_mod_init);
  2870. module_exit(sd_mod_exit);