sonixj.c 67 KB

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