sonixj.c 59 KB

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