sonixj.c 70 KB

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