sonixj.c 97 KB

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