sonixj.c 66 KB

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