sonixj.c 80 KB

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