sonixj.c 66 KB

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