sonixj.c 79 KB

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