sonixj.c 69 KB

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