sonixj.c 93 KB

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