sonixj.c 54 KB

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