sonixj.c 65 KB

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