sonixj.c 64 KB

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