ov519.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196
  1. /**
  2. * OV519 driver
  3. *
  4. * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
  5. *
  6. * This module is adapted from the ov51x-jpeg package, which itself
  7. * was adapted from the ov511 driver.
  8. *
  9. * Original copyright for the ov511 driver is:
  10. *
  11. * Copyright (c) 1999-2004 Mark W. McClelland
  12. * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
  13. *
  14. * ov51x-jpeg original copyright is:
  15. *
  16. * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
  17. * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  32. *
  33. */
  34. #define MODULE_NAME "ov519"
  35. #include "gspca.h"
  36. MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
  37. MODULE_DESCRIPTION("OV519 USB Camera Driver");
  38. MODULE_LICENSE("GPL");
  39. /* global parameters */
  40. static int frame_rate;
  41. /* Number of times to retry a failed I2C transaction. Increase this if you
  42. * are getting "Failed to read sensor ID..." */
  43. static int i2c_detect_tries = 10;
  44. /* ov519 device descriptor */
  45. struct sd {
  46. struct gspca_dev gspca_dev; /* !! must be the first item */
  47. /* Determined by sensor type */
  48. __u8 sif;
  49. __u8 brightness;
  50. __u8 contrast;
  51. __u8 colors;
  52. __u8 hflip;
  53. __u8 vflip;
  54. __u8 stopped; /* Streaming is temporarily paused */
  55. __u8 frame_rate; /* current Framerate (OV519 only) */
  56. __u8 clockdiv; /* clockdiv override for OV519 only */
  57. char sensor; /* Type of image sensor chip (SEN_*) */
  58. #define SEN_UNKNOWN 0
  59. #define SEN_OV6620 1
  60. #define SEN_OV6630 2
  61. #define SEN_OV7610 3
  62. #define SEN_OV7620 4
  63. #define SEN_OV7640 5
  64. #define SEN_OV7670 6
  65. #define SEN_OV76BE 7
  66. #define SEN_OV8610 8
  67. };
  68. /* V4L2 controls supported by the driver */
  69. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  70. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  71. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  72. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  73. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  74. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  75. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  76. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  77. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  78. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  79. static struct ctrl sd_ctrls[] = {
  80. {
  81. {
  82. .id = V4L2_CID_BRIGHTNESS,
  83. .type = V4L2_CTRL_TYPE_INTEGER,
  84. .name = "Brightness",
  85. .minimum = 0,
  86. .maximum = 255,
  87. .step = 1,
  88. #define BRIGHTNESS_DEF 127
  89. .default_value = BRIGHTNESS_DEF,
  90. },
  91. .set = sd_setbrightness,
  92. .get = sd_getbrightness,
  93. },
  94. {
  95. {
  96. .id = V4L2_CID_CONTRAST,
  97. .type = V4L2_CTRL_TYPE_INTEGER,
  98. .name = "Contrast",
  99. .minimum = 0,
  100. .maximum = 255,
  101. .step = 1,
  102. #define CONTRAST_DEF 127
  103. .default_value = CONTRAST_DEF,
  104. },
  105. .set = sd_setcontrast,
  106. .get = sd_getcontrast,
  107. },
  108. {
  109. {
  110. .id = V4L2_CID_SATURATION,
  111. .type = V4L2_CTRL_TYPE_INTEGER,
  112. .name = "Color",
  113. .minimum = 0,
  114. .maximum = 255,
  115. .step = 1,
  116. #define COLOR_DEF 127
  117. .default_value = COLOR_DEF,
  118. },
  119. .set = sd_setcolors,
  120. .get = sd_getcolors,
  121. },
  122. /* next controls work with ov7670 only */
  123. #define HFLIP_IDX 3
  124. {
  125. {
  126. .id = V4L2_CID_HFLIP,
  127. .type = V4L2_CTRL_TYPE_BOOLEAN,
  128. .name = "Mirror",
  129. .minimum = 0,
  130. .maximum = 1,
  131. .step = 1,
  132. #define HFLIP_DEF 0
  133. .default_value = HFLIP_DEF,
  134. },
  135. .set = sd_sethflip,
  136. .get = sd_gethflip,
  137. },
  138. #define VFLIP_IDX 4
  139. {
  140. {
  141. .id = V4L2_CID_VFLIP,
  142. .type = V4L2_CTRL_TYPE_BOOLEAN,
  143. .name = "Vflip",
  144. .minimum = 0,
  145. .maximum = 1,
  146. .step = 1,
  147. #define VFLIP_DEF 0
  148. .default_value = VFLIP_DEF,
  149. },
  150. .set = sd_setvflip,
  151. .get = sd_getvflip,
  152. },
  153. };
  154. static const struct v4l2_pix_format vga_mode[] = {
  155. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  156. .bytesperline = 320,
  157. .sizeimage = 320 * 240 * 3 / 8 + 590,
  158. .colorspace = V4L2_COLORSPACE_JPEG,
  159. .priv = 1},
  160. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  161. .bytesperline = 640,
  162. .sizeimage = 640 * 480 * 3 / 8 + 590,
  163. .colorspace = V4L2_COLORSPACE_JPEG,
  164. .priv = 0},
  165. };
  166. static const struct v4l2_pix_format sif_mode[] = {
  167. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  168. .bytesperline = 176,
  169. .sizeimage = 176 * 144 * 3 / 8 + 590,
  170. .colorspace = V4L2_COLORSPACE_JPEG,
  171. .priv = 1},
  172. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  173. .bytesperline = 352,
  174. .sizeimage = 352 * 288 * 3 / 8 + 590,
  175. .colorspace = V4L2_COLORSPACE_JPEG,
  176. .priv = 0},
  177. };
  178. /* OV519 Camera interface register numbers */
  179. #define OV519_R10_H_SIZE 0x10
  180. #define OV519_R11_V_SIZE 0x11
  181. #define OV519_R12_X_OFFSETL 0x12
  182. #define OV519_R13_X_OFFSETH 0x13
  183. #define OV519_R14_Y_OFFSETL 0x14
  184. #define OV519_R15_Y_OFFSETH 0x15
  185. #define OV519_R16_DIVIDER 0x16
  186. #define OV519_R20_DFR 0x20
  187. #define OV519_R25_FORMAT 0x25
  188. /* OV519 System Controller register numbers */
  189. #define OV519_SYS_RESET1 0x51
  190. #define OV519_SYS_EN_CLK1 0x54
  191. #define OV519_GPIO_DATA_OUT0 0x71
  192. #define OV519_GPIO_IO_CTRL0 0x72
  193. #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
  194. /* I2C registers */
  195. #define R51x_I2C_W_SID 0x41
  196. #define R51x_I2C_SADDR_3 0x42
  197. #define R51x_I2C_SADDR_2 0x43
  198. #define R51x_I2C_R_SID 0x44
  199. #define R51x_I2C_DATA 0x45
  200. #define R518_I2C_CTL 0x47 /* OV518(+) only */
  201. /* I2C ADDRESSES */
  202. #define OV7xx0_SID 0x42
  203. #define OV8xx0_SID 0xa0
  204. #define OV6xx0_SID 0xc0
  205. /* OV7610 registers */
  206. #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
  207. #define OV7610_REG_SAT 0x03 /* saturation */
  208. #define OV8610_REG_HUE 0x04 /* 04 reserved */
  209. #define OV7610_REG_CNT 0x05 /* Y contrast */
  210. #define OV7610_REG_BRT 0x06 /* Y brightness */
  211. #define OV7610_REG_COM_C 0x14 /* misc common regs */
  212. #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
  213. #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
  214. #define OV7610_REG_COM_I 0x29 /* misc settings */
  215. /* OV7670 registers */
  216. #define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
  217. #define OV7670_REG_BLUE 0x01 /* blue gain */
  218. #define OV7670_REG_RED 0x02 /* red gain */
  219. #define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
  220. #define OV7670_REG_COM1 0x04 /* Control 1 */
  221. #define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
  222. #define OV7670_REG_COM3 0x0c /* Control 3 */
  223. #define OV7670_REG_COM4 0x0d /* Control 4 */
  224. #define OV7670_REG_COM5 0x0e /* All "reserved" */
  225. #define OV7670_REG_COM6 0x0f /* Control 6 */
  226. #define OV7670_REG_AECH 0x10 /* More bits of AEC value */
  227. #define OV7670_REG_CLKRC 0x11 /* Clock control */
  228. #define OV7670_REG_COM7 0x12 /* Control 7 */
  229. #define OV7670_COM7_FMT_VGA 0x00
  230. #define OV7670_COM7_YUV 0x00 /* YUV */
  231. #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
  232. #define OV7670_COM7_FMT_MASK 0x38
  233. #define OV7670_COM7_RESET 0x80 /* Register reset */
  234. #define OV7670_REG_COM8 0x13 /* Control 8 */
  235. #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
  236. #define OV7670_COM8_AWB 0x02 /* White balance enable */
  237. #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
  238. #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
  239. #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
  240. #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
  241. #define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
  242. #define OV7670_REG_COM10 0x15 /* Control 10 */
  243. #define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
  244. #define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
  245. #define OV7670_REG_VSTART 0x19 /* Vert start high bits */
  246. #define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
  247. #define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
  248. #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
  249. #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
  250. #define OV7670_REG_AEW 0x24 /* AGC upper limit */
  251. #define OV7670_REG_AEB 0x25 /* AGC lower limit */
  252. #define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
  253. #define OV7670_REG_HREF 0x32 /* HREF pieces */
  254. #define OV7670_REG_TSLB 0x3a /* lots of stuff */
  255. #define OV7670_REG_COM11 0x3b /* Control 11 */
  256. #define OV7670_COM11_EXP 0x02
  257. #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
  258. #define OV7670_REG_COM12 0x3c /* Control 12 */
  259. #define OV7670_REG_COM13 0x3d /* Control 13 */
  260. #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
  261. #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
  262. #define OV7670_REG_COM14 0x3e /* Control 14 */
  263. #define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
  264. #define OV7670_REG_COM15 0x40 /* Control 15 */
  265. #define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
  266. #define OV7670_REG_COM16 0x41 /* Control 16 */
  267. #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
  268. #define OV7670_REG_BRIGHT 0x55 /* Brightness */
  269. #define OV7670_REG_CONTRAS 0x56 /* Contrast control */
  270. #define OV7670_REG_GFIX 0x69 /* Fix gain control */
  271. #define OV7670_REG_RGB444 0x8c /* RGB 444 control */
  272. #define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
  273. #define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
  274. #define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
  275. #define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
  276. #define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
  277. #define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
  278. #define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
  279. #define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
  280. #define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
  281. struct ov_regvals {
  282. __u8 reg;
  283. __u8 val;
  284. };
  285. struct ov_i2c_regvals {
  286. __u8 reg;
  287. __u8 val;
  288. };
  289. static const struct ov_i2c_regvals norm_6x20[] = {
  290. { 0x12, 0x80 }, /* reset */
  291. { 0x11, 0x01 },
  292. { 0x03, 0x60 },
  293. { 0x05, 0x7f }, /* For when autoadjust is off */
  294. { 0x07, 0xa8 },
  295. /* The ratio of 0x0c and 0x0d controls the white point */
  296. { 0x0c, 0x24 },
  297. { 0x0d, 0x24 },
  298. { 0x0f, 0x15 }, /* COMS */
  299. { 0x10, 0x75 }, /* AEC Exposure time */
  300. { 0x12, 0x24 }, /* Enable AGC */
  301. { 0x14, 0x04 },
  302. /* 0x16: 0x06 helps frame stability with moving objects */
  303. { 0x16, 0x06 },
  304. /* { 0x20, 0x30 }, * Aperture correction enable */
  305. { 0x26, 0xb2 }, /* BLC enable */
  306. /* 0x28: 0x05 Selects RGB format if RGB on */
  307. { 0x28, 0x05 },
  308. { 0x2a, 0x04 }, /* Disable framerate adjust */
  309. /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
  310. { 0x2d, 0x99 },
  311. { 0x33, 0xa0 }, /* Color Processing Parameter */
  312. { 0x34, 0xd2 }, /* Max A/D range */
  313. { 0x38, 0x8b },
  314. { 0x39, 0x40 },
  315. { 0x3c, 0x39 }, /* Enable AEC mode changing */
  316. { 0x3c, 0x3c }, /* Change AEC mode */
  317. { 0x3c, 0x24 }, /* Disable AEC mode changing */
  318. { 0x3d, 0x80 },
  319. /* These next two registers (0x4a, 0x4b) are undocumented.
  320. * They control the color balance */
  321. { 0x4a, 0x80 },
  322. { 0x4b, 0x80 },
  323. { 0x4d, 0xd2 }, /* This reduces noise a bit */
  324. { 0x4e, 0xc1 },
  325. { 0x4f, 0x04 },
  326. /* Do 50-53 have any effect? */
  327. /* Toggle 0x12[2] off and on here? */
  328. };
  329. static const struct ov_i2c_regvals norm_6x30[] = {
  330. { 0x12, 0x80 }, /* Reset */
  331. { 0x00, 0x1f }, /* Gain */
  332. { 0x01, 0x99 }, /* Blue gain */
  333. { 0x02, 0x7c }, /* Red gain */
  334. { 0x03, 0xc0 }, /* Saturation */
  335. { 0x05, 0x0a }, /* Contrast */
  336. { 0x06, 0x95 }, /* Brightness */
  337. { 0x07, 0x2d }, /* Sharpness */
  338. { 0x0c, 0x20 },
  339. { 0x0d, 0x20 },
  340. { 0x0e, 0x20 },
  341. { 0x0f, 0x05 },
  342. { 0x10, 0x9a },
  343. { 0x11, 0x00 }, /* Pixel clock = fastest */
  344. { 0x12, 0x24 }, /* Enable AGC and AWB */
  345. { 0x13, 0x21 },
  346. { 0x14, 0x80 },
  347. { 0x15, 0x01 },
  348. { 0x16, 0x03 },
  349. { 0x17, 0x38 },
  350. { 0x18, 0xea },
  351. { 0x19, 0x04 },
  352. { 0x1a, 0x93 },
  353. { 0x1b, 0x00 },
  354. { 0x1e, 0xc4 },
  355. { 0x1f, 0x04 },
  356. { 0x20, 0x20 },
  357. { 0x21, 0x10 },
  358. { 0x22, 0x88 },
  359. { 0x23, 0xc0 }, /* Crystal circuit power level */
  360. { 0x25, 0x9a }, /* Increase AEC black ratio */
  361. { 0x26, 0xb2 }, /* BLC enable */
  362. { 0x27, 0xa2 },
  363. { 0x28, 0x00 },
  364. { 0x29, 0x00 },
  365. { 0x2a, 0x84 }, /* 60 Hz power */
  366. { 0x2b, 0xa8 }, /* 60 Hz power */
  367. { 0x2c, 0xa0 },
  368. { 0x2d, 0x95 }, /* Enable auto-brightness */
  369. { 0x2e, 0x88 },
  370. { 0x33, 0x26 },
  371. { 0x34, 0x03 },
  372. { 0x36, 0x8f },
  373. { 0x37, 0x80 },
  374. { 0x38, 0x83 },
  375. { 0x39, 0x80 },
  376. { 0x3a, 0x0f },
  377. { 0x3b, 0x3c },
  378. { 0x3c, 0x1a },
  379. { 0x3d, 0x80 },
  380. { 0x3e, 0x80 },
  381. { 0x3f, 0x0e },
  382. { 0x40, 0x00 }, /* White bal */
  383. { 0x41, 0x00 }, /* White bal */
  384. { 0x42, 0x80 },
  385. { 0x43, 0x3f }, /* White bal */
  386. { 0x44, 0x80 },
  387. { 0x45, 0x20 },
  388. { 0x46, 0x20 },
  389. { 0x47, 0x80 },
  390. { 0x48, 0x7f },
  391. { 0x49, 0x00 },
  392. { 0x4a, 0x00 },
  393. { 0x4b, 0x80 },
  394. { 0x4c, 0xd0 },
  395. { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
  396. { 0x4e, 0x40 },
  397. { 0x4f, 0x07 }, /* UV avg., col. killer: max */
  398. { 0x50, 0xff },
  399. { 0x54, 0x23 }, /* Max AGC gain: 18dB */
  400. { 0x55, 0xff },
  401. { 0x56, 0x12 },
  402. { 0x57, 0x81 },
  403. { 0x58, 0x75 },
  404. { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
  405. { 0x5a, 0x2c },
  406. { 0x5b, 0x0f }, /* AWB chrominance levels */
  407. { 0x5c, 0x10 },
  408. { 0x3d, 0x80 },
  409. { 0x27, 0xa6 },
  410. { 0x12, 0x20 }, /* Toggle AWB */
  411. { 0x12, 0x24 },
  412. };
  413. /* Lawrence Glaister <lg@jfm.bc.ca> reports:
  414. *
  415. * Register 0x0f in the 7610 has the following effects:
  416. *
  417. * 0x85 (AEC method 1): Best overall, good contrast range
  418. * 0x45 (AEC method 2): Very overexposed
  419. * 0xa5 (spec sheet default): Ok, but the black level is
  420. * shifted resulting in loss of contrast
  421. * 0x05 (old driver setting): very overexposed, too much
  422. * contrast
  423. */
  424. static const struct ov_i2c_regvals norm_7610[] = {
  425. { 0x10, 0xff },
  426. { 0x16, 0x06 },
  427. { 0x28, 0x24 },
  428. { 0x2b, 0xac },
  429. { 0x12, 0x00 },
  430. { 0x38, 0x81 },
  431. { 0x28, 0x24 }, /* 0c */
  432. { 0x0f, 0x85 }, /* lg's setting */
  433. { 0x15, 0x01 },
  434. { 0x20, 0x1c },
  435. { 0x23, 0x2a },
  436. { 0x24, 0x10 },
  437. { 0x25, 0x8a },
  438. { 0x26, 0xa2 },
  439. { 0x27, 0xc2 },
  440. { 0x2a, 0x04 },
  441. { 0x2c, 0xfe },
  442. { 0x2d, 0x93 },
  443. { 0x30, 0x71 },
  444. { 0x31, 0x60 },
  445. { 0x32, 0x26 },
  446. { 0x33, 0x20 },
  447. { 0x34, 0x48 },
  448. { 0x12, 0x24 },
  449. { 0x11, 0x01 },
  450. { 0x0c, 0x24 },
  451. { 0x0d, 0x24 },
  452. };
  453. static const struct ov_i2c_regvals norm_7620[] = {
  454. { 0x00, 0x00 }, /* gain */
  455. { 0x01, 0x80 }, /* blue gain */
  456. { 0x02, 0x80 }, /* red gain */
  457. { 0x03, 0xc0 }, /* OV7670_REG_VREF */
  458. { 0x06, 0x60 },
  459. { 0x07, 0x00 },
  460. { 0x0c, 0x24 },
  461. { 0x0c, 0x24 },
  462. { 0x0d, 0x24 },
  463. { 0x11, 0x01 },
  464. { 0x12, 0x24 },
  465. { 0x13, 0x01 },
  466. { 0x14, 0x84 },
  467. { 0x15, 0x01 },
  468. { 0x16, 0x03 },
  469. { 0x17, 0x2f },
  470. { 0x18, 0xcf },
  471. { 0x19, 0x06 },
  472. { 0x1a, 0xf5 },
  473. { 0x1b, 0x00 },
  474. { 0x20, 0x18 },
  475. { 0x21, 0x80 },
  476. { 0x22, 0x80 },
  477. { 0x23, 0x00 },
  478. { 0x26, 0xa2 },
  479. { 0x27, 0xea },
  480. { 0x28, 0x20 },
  481. { 0x29, 0x00 },
  482. { 0x2a, 0x10 },
  483. { 0x2b, 0x00 },
  484. { 0x2c, 0x88 },
  485. { 0x2d, 0x91 },
  486. { 0x2e, 0x80 },
  487. { 0x2f, 0x44 },
  488. { 0x60, 0x27 },
  489. { 0x61, 0x02 },
  490. { 0x62, 0x5f },
  491. { 0x63, 0xd5 },
  492. { 0x64, 0x57 },
  493. { 0x65, 0x83 },
  494. { 0x66, 0x55 },
  495. { 0x67, 0x92 },
  496. { 0x68, 0xcf },
  497. { 0x69, 0x76 },
  498. { 0x6a, 0x22 },
  499. { 0x6b, 0x00 },
  500. { 0x6c, 0x02 },
  501. { 0x6d, 0x44 },
  502. { 0x6e, 0x80 },
  503. { 0x6f, 0x1d },
  504. { 0x70, 0x8b },
  505. { 0x71, 0x00 },
  506. { 0x72, 0x14 },
  507. { 0x73, 0x54 },
  508. { 0x74, 0x00 },
  509. { 0x75, 0x8e },
  510. { 0x76, 0x00 },
  511. { 0x77, 0xff },
  512. { 0x78, 0x80 },
  513. { 0x79, 0x80 },
  514. { 0x7a, 0x80 },
  515. { 0x7b, 0xe2 },
  516. { 0x7c, 0x00 },
  517. };
  518. /* 7640 and 7648. The defaults should be OK for most registers. */
  519. static const struct ov_i2c_regvals norm_7640[] = {
  520. { 0x12, 0x80 },
  521. { 0x12, 0x14 },
  522. };
  523. /* 7670. Defaults taken from OmniVision provided data,
  524. * as provided by Jonathan Corbet of OLPC */
  525. static const struct ov_i2c_regvals norm_7670[] = {
  526. { OV7670_REG_COM7, OV7670_COM7_RESET },
  527. { OV7670_REG_TSLB, 0x04 }, /* OV */
  528. { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
  529. { OV7670_REG_CLKRC, 0x01 },
  530. /*
  531. * Set the hardware window. These values from OV don't entirely
  532. * make sense - hstop is less than hstart. But they work...
  533. */
  534. { OV7670_REG_HSTART, 0x13 },
  535. { OV7670_REG_HSTOP, 0x01 },
  536. { OV7670_REG_HREF, 0xb6 },
  537. { OV7670_REG_VSTART, 0x02 },
  538. { OV7670_REG_VSTOP, 0x7a },
  539. { OV7670_REG_VREF, 0x0a },
  540. { OV7670_REG_COM3, 0x00 },
  541. { OV7670_REG_COM14, 0x00 },
  542. /* Mystery scaling numbers */
  543. { 0x70, 0x3a },
  544. { 0x71, 0x35 },
  545. { 0x72, 0x11 },
  546. { 0x73, 0xf0 },
  547. { 0xa2, 0x02 },
  548. /* { OV7670_REG_COM10, 0x0 }, */
  549. /* Gamma curve values */
  550. { 0x7a, 0x20 },
  551. { 0x7b, 0x10 },
  552. { 0x7c, 0x1e },
  553. { 0x7d, 0x35 },
  554. { 0x7e, 0x5a },
  555. { 0x7f, 0x69 },
  556. { 0x80, 0x76 },
  557. { 0x81, 0x80 },
  558. { 0x82, 0x88 },
  559. { 0x83, 0x8f },
  560. { 0x84, 0x96 },
  561. { 0x85, 0xa3 },
  562. { 0x86, 0xaf },
  563. { 0x87, 0xc4 },
  564. { 0x88, 0xd7 },
  565. { 0x89, 0xe8 },
  566. /* AGC and AEC parameters. Note we start by disabling those features,
  567. then turn them only after tweaking the values. */
  568. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  569. | OV7670_COM8_AECSTEP
  570. | OV7670_COM8_BFILT },
  571. { OV7670_REG_GAIN, 0x00 },
  572. { OV7670_REG_AECH, 0x00 },
  573. { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
  574. { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
  575. { OV7670_REG_BD50MAX, 0x05 },
  576. { OV7670_REG_BD60MAX, 0x07 },
  577. { OV7670_REG_AEW, 0x95 },
  578. { OV7670_REG_AEB, 0x33 },
  579. { OV7670_REG_VPT, 0xe3 },
  580. { OV7670_REG_HAECC1, 0x78 },
  581. { OV7670_REG_HAECC2, 0x68 },
  582. { 0xa1, 0x03 }, /* magic */
  583. { OV7670_REG_HAECC3, 0xd8 },
  584. { OV7670_REG_HAECC4, 0xd8 },
  585. { OV7670_REG_HAECC5, 0xf0 },
  586. { OV7670_REG_HAECC6, 0x90 },
  587. { OV7670_REG_HAECC7, 0x94 },
  588. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  589. | OV7670_COM8_AECSTEP
  590. | OV7670_COM8_BFILT
  591. | OV7670_COM8_AGC
  592. | OV7670_COM8_AEC },
  593. /* Almost all of these are magic "reserved" values. */
  594. { OV7670_REG_COM5, 0x61 },
  595. { OV7670_REG_COM6, 0x4b },
  596. { 0x16, 0x02 },
  597. { OV7670_REG_MVFP, 0x07 },
  598. { 0x21, 0x02 },
  599. { 0x22, 0x91 },
  600. { 0x29, 0x07 },
  601. { 0x33, 0x0b },
  602. { 0x35, 0x0b },
  603. { 0x37, 0x1d },
  604. { 0x38, 0x71 },
  605. { 0x39, 0x2a },
  606. { OV7670_REG_COM12, 0x78 },
  607. { 0x4d, 0x40 },
  608. { 0x4e, 0x20 },
  609. { OV7670_REG_GFIX, 0x00 },
  610. { 0x6b, 0x4a },
  611. { 0x74, 0x10 },
  612. { 0x8d, 0x4f },
  613. { 0x8e, 0x00 },
  614. { 0x8f, 0x00 },
  615. { 0x90, 0x00 },
  616. { 0x91, 0x00 },
  617. { 0x96, 0x00 },
  618. { 0x9a, 0x00 },
  619. { 0xb0, 0x84 },
  620. { 0xb1, 0x0c },
  621. { 0xb2, 0x0e },
  622. { 0xb3, 0x82 },
  623. { 0xb8, 0x0a },
  624. /* More reserved magic, some of which tweaks white balance */
  625. { 0x43, 0x0a },
  626. { 0x44, 0xf0 },
  627. { 0x45, 0x34 },
  628. { 0x46, 0x58 },
  629. { 0x47, 0x28 },
  630. { 0x48, 0x3a },
  631. { 0x59, 0x88 },
  632. { 0x5a, 0x88 },
  633. { 0x5b, 0x44 },
  634. { 0x5c, 0x67 },
  635. { 0x5d, 0x49 },
  636. { 0x5e, 0x0e },
  637. { 0x6c, 0x0a },
  638. { 0x6d, 0x55 },
  639. { 0x6e, 0x11 },
  640. { 0x6f, 0x9f },
  641. /* "9e for advance AWB" */
  642. { 0x6a, 0x40 },
  643. { OV7670_REG_BLUE, 0x40 },
  644. { OV7670_REG_RED, 0x60 },
  645. { OV7670_REG_COM8, OV7670_COM8_FASTAEC
  646. | OV7670_COM8_AECSTEP
  647. | OV7670_COM8_BFILT
  648. | OV7670_COM8_AGC
  649. | OV7670_COM8_AEC
  650. | OV7670_COM8_AWB },
  651. /* Matrix coefficients */
  652. { 0x4f, 0x80 },
  653. { 0x50, 0x80 },
  654. { 0x51, 0x00 },
  655. { 0x52, 0x22 },
  656. { 0x53, 0x5e },
  657. { 0x54, 0x80 },
  658. { 0x58, 0x9e },
  659. { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
  660. { OV7670_REG_EDGE, 0x00 },
  661. { 0x75, 0x05 },
  662. { 0x76, 0xe1 },
  663. { 0x4c, 0x00 },
  664. { 0x77, 0x01 },
  665. { OV7670_REG_COM13, OV7670_COM13_GAMMA
  666. | OV7670_COM13_UVSAT
  667. | 2}, /* was 3 */
  668. { 0x4b, 0x09 },
  669. { 0xc9, 0x60 },
  670. { OV7670_REG_COM16, 0x38 },
  671. { 0x56, 0x40 },
  672. { 0x34, 0x11 },
  673. { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
  674. { 0xa4, 0x88 },
  675. { 0x96, 0x00 },
  676. { 0x97, 0x30 },
  677. { 0x98, 0x20 },
  678. { 0x99, 0x30 },
  679. { 0x9a, 0x84 },
  680. { 0x9b, 0x29 },
  681. { 0x9c, 0x03 },
  682. { 0x9d, 0x4c },
  683. { 0x9e, 0x3f },
  684. { 0x78, 0x04 },
  685. /* Extra-weird stuff. Some sort of multiplexor register */
  686. { 0x79, 0x01 },
  687. { 0xc8, 0xf0 },
  688. { 0x79, 0x0f },
  689. { 0xc8, 0x00 },
  690. { 0x79, 0x10 },
  691. { 0xc8, 0x7e },
  692. { 0x79, 0x0a },
  693. { 0xc8, 0x80 },
  694. { 0x79, 0x0b },
  695. { 0xc8, 0x01 },
  696. { 0x79, 0x0c },
  697. { 0xc8, 0x0f },
  698. { 0x79, 0x0d },
  699. { 0xc8, 0x20 },
  700. { 0x79, 0x09 },
  701. { 0xc8, 0x80 },
  702. { 0x79, 0x02 },
  703. { 0xc8, 0xc0 },
  704. { 0x79, 0x03 },
  705. { 0xc8, 0x40 },
  706. { 0x79, 0x05 },
  707. { 0xc8, 0x30 },
  708. { 0x79, 0x26 },
  709. };
  710. static const struct ov_i2c_regvals norm_8610[] = {
  711. { 0x12, 0x80 },
  712. { 0x00, 0x00 },
  713. { 0x01, 0x80 },
  714. { 0x02, 0x80 },
  715. { 0x03, 0xc0 },
  716. { 0x04, 0x30 },
  717. { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
  718. { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
  719. { 0x0a, 0x86 },
  720. { 0x0b, 0xb0 },
  721. { 0x0c, 0x20 },
  722. { 0x0d, 0x20 },
  723. { 0x11, 0x01 },
  724. { 0x12, 0x25 },
  725. { 0x13, 0x01 },
  726. { 0x14, 0x04 },
  727. { 0x15, 0x01 }, /* Lin and Win think different about UV order */
  728. { 0x16, 0x03 },
  729. { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
  730. { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
  731. { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
  732. { 0x1a, 0xf5 },
  733. { 0x1b, 0x00 },
  734. { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
  735. { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
  736. { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
  737. { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
  738. { 0x26, 0xa2 },
  739. { 0x27, 0xea },
  740. { 0x28, 0x00 },
  741. { 0x29, 0x00 },
  742. { 0x2a, 0x80 },
  743. { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
  744. { 0x2c, 0xac },
  745. { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
  746. { 0x2e, 0x80 },
  747. { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
  748. { 0x4c, 0x00 },
  749. { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
  750. { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
  751. { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
  752. { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
  753. { 0x63, 0xff },
  754. { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
  755. * maybe thats wrong */
  756. { 0x65, 0x00 },
  757. { 0x66, 0x55 },
  758. { 0x67, 0xb0 },
  759. { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
  760. { 0x69, 0x02 },
  761. { 0x6a, 0x22 },
  762. { 0x6b, 0x00 },
  763. { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
  764. * deleting bit7 colors the first images red */
  765. { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
  766. { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
  767. { 0x6f, 0x01 },
  768. { 0x70, 0x8b },
  769. { 0x71, 0x00 },
  770. { 0x72, 0x14 },
  771. { 0x73, 0x54 },
  772. { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
  773. { 0x75, 0x0e },
  774. { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
  775. { 0x77, 0xff },
  776. { 0x78, 0x80 },
  777. { 0x79, 0x80 },
  778. { 0x7a, 0x80 },
  779. { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
  780. { 0x7c, 0x00 },
  781. { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
  782. { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
  783. { 0x7f, 0xfb },
  784. { 0x80, 0x28 },
  785. { 0x81, 0x00 },
  786. { 0x82, 0x23 },
  787. { 0x83, 0x0b },
  788. { 0x84, 0x00 },
  789. { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
  790. { 0x86, 0xc9 },
  791. { 0x87, 0x00 },
  792. { 0x88, 0x00 },
  793. { 0x89, 0x01 },
  794. { 0x12, 0x20 },
  795. { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
  796. };
  797. static unsigned char ov7670_abs_to_sm(unsigned char v)
  798. {
  799. if (v > 127)
  800. return v & 0x7f;
  801. return (128 - v) | 0x80;
  802. }
  803. /* Write a OV519 register */
  804. static int reg_w(struct sd *sd, __u16 index, __u8 value)
  805. {
  806. int ret;
  807. sd->gspca_dev.usb_buf[0] = value;
  808. ret = usb_control_msg(sd->gspca_dev.dev,
  809. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  810. 1, /* REQ_IO (ov518/519) */
  811. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  812. 0, index,
  813. sd->gspca_dev.usb_buf, 1, 500);
  814. if (ret < 0)
  815. PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
  816. return ret;
  817. }
  818. /* Read from a OV519 register */
  819. /* returns: negative is error, pos or zero is data */
  820. static int reg_r(struct sd *sd, __u16 index)
  821. {
  822. int ret;
  823. ret = usb_control_msg(sd->gspca_dev.dev,
  824. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  825. 1, /* REQ_IO */
  826. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  827. 0, index, sd->gspca_dev.usb_buf, 1, 500);
  828. if (ret >= 0)
  829. ret = sd->gspca_dev.usb_buf[0];
  830. else
  831. PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
  832. return ret;
  833. }
  834. /* Read 8 values from a OV519 register */
  835. static int reg_r8(struct sd *sd,
  836. __u16 index)
  837. {
  838. int ret;
  839. ret = usb_control_msg(sd->gspca_dev.dev,
  840. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  841. 1, /* REQ_IO */
  842. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  843. 0, index, sd->gspca_dev.usb_buf, 8, 500);
  844. if (ret >= 0)
  845. ret = sd->gspca_dev.usb_buf[0];
  846. else
  847. PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
  848. return ret;
  849. }
  850. /*
  851. * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
  852. * the same position as 1's in "mask" are cleared and set to "value". Bits
  853. * that are in the same position as 0's in "mask" are preserved, regardless
  854. * of their respective state in "value".
  855. */
  856. static int reg_w_mask(struct sd *sd,
  857. __u16 index,
  858. __u8 value,
  859. __u8 mask)
  860. {
  861. int ret;
  862. __u8 oldval;
  863. if (mask != 0xff) {
  864. value &= mask; /* Enforce mask on value */
  865. ret = reg_r(sd, index);
  866. if (ret < 0)
  867. return ret;
  868. oldval = ret & ~mask; /* Clear the masked bits */
  869. value |= oldval; /* Set the desired bits */
  870. }
  871. return reg_w(sd, index, value);
  872. }
  873. /*
  874. * The OV518 I2C I/O procedure is different, hence, this function.
  875. * This is normally only called from i2c_w(). Note that this function
  876. * always succeeds regardless of whether the sensor is present and working.
  877. */
  878. static int i2c_w(struct sd *sd,
  879. __u8 reg,
  880. __u8 value)
  881. {
  882. int rc;
  883. PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
  884. /* Select camera register */
  885. rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
  886. if (rc < 0)
  887. return rc;
  888. /* Write "value" to I2C data port of OV511 */
  889. rc = reg_w(sd, R51x_I2C_DATA, value);
  890. if (rc < 0)
  891. return rc;
  892. /* Initiate 3-byte write cycle */
  893. rc = reg_w(sd, R518_I2C_CTL, 0x01);
  894. if (rc < 0)
  895. return rc;
  896. /* wait for write complete */
  897. msleep(4);
  898. return reg_r8(sd, R518_I2C_CTL);
  899. }
  900. /*
  901. * returns: negative is error, pos or zero is data
  902. *
  903. * The OV518 I2C I/O procedure is different, hence, this function.
  904. * This is normally only called from i2c_r(). Note that this function
  905. * always succeeds regardless of whether the sensor is present and working.
  906. */
  907. static int i2c_r(struct sd *sd, __u8 reg)
  908. {
  909. int rc, value;
  910. /* Select camera register */
  911. rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
  912. if (rc < 0)
  913. return rc;
  914. /* Initiate 2-byte write cycle */
  915. rc = reg_w(sd, R518_I2C_CTL, 0x03);
  916. if (rc < 0)
  917. return rc;
  918. /* Initiate 2-byte read cycle */
  919. rc = reg_w(sd, R518_I2C_CTL, 0x05);
  920. if (rc < 0)
  921. return rc;
  922. value = reg_r(sd, R51x_I2C_DATA);
  923. PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
  924. return value;
  925. }
  926. /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
  927. * the same position as 1's in "mask" are cleared and set to "value". Bits
  928. * that are in the same position as 0's in "mask" are preserved, regardless
  929. * of their respective state in "value".
  930. */
  931. static int i2c_w_mask(struct sd *sd,
  932. __u8 reg,
  933. __u8 value,
  934. __u8 mask)
  935. {
  936. int rc;
  937. __u8 oldval;
  938. value &= mask; /* Enforce mask on value */
  939. rc = i2c_r(sd, reg);
  940. if (rc < 0)
  941. return rc;
  942. oldval = rc & ~mask; /* Clear the masked bits */
  943. value |= oldval; /* Set the desired bits */
  944. return i2c_w(sd, reg, value);
  945. }
  946. /* Temporarily stops OV511 from functioning. Must do this before changing
  947. * registers while the camera is streaming */
  948. static inline int ov51x_stop(struct sd *sd)
  949. {
  950. PDEBUG(D_STREAM, "stopping");
  951. sd->stopped = 1;
  952. return reg_w(sd, OV519_SYS_RESET1, 0x0f);
  953. }
  954. /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
  955. * actually stopped (for performance). */
  956. static inline int ov51x_restart(struct sd *sd)
  957. {
  958. PDEBUG(D_STREAM, "restarting");
  959. if (!sd->stopped)
  960. return 0;
  961. sd->stopped = 0;
  962. /* Reinitialize the stream */
  963. return reg_w(sd, OV519_SYS_RESET1, 0x00);
  964. }
  965. /* This does an initial reset of an OmniVision sensor and ensures that I2C
  966. * is synchronized. Returns <0 on failure.
  967. */
  968. static int init_ov_sensor(struct sd *sd)
  969. {
  970. int i;
  971. /* Reset the sensor */
  972. if (i2c_w(sd, 0x12, 0x80) < 0)
  973. return -EIO;
  974. /* Wait for it to initialize */
  975. msleep(150);
  976. for (i = 0; i < i2c_detect_tries; i++) {
  977. if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
  978. i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
  979. PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
  980. return 0;
  981. }
  982. /* Reset the sensor */
  983. if (i2c_w(sd, 0x12, 0x80) < 0)
  984. return -EIO;
  985. /* Wait for it to initialize */
  986. msleep(150);
  987. /* Dummy read to sync I2C */
  988. if (i2c_r(sd, 0x00) < 0)
  989. return -EIO;
  990. }
  991. return -EIO;
  992. }
  993. /* Set the read and write slave IDs. The "slave" argument is the write slave,
  994. * and the read slave will be set to (slave + 1).
  995. * This should not be called from outside the i2c I/O functions.
  996. * Sets I2C read and write slave IDs. Returns <0 for error
  997. */
  998. static int ov51x_set_slave_ids(struct sd *sd,
  999. __u8 slave)
  1000. {
  1001. int rc;
  1002. rc = reg_w(sd, R51x_I2C_W_SID, slave);
  1003. if (rc < 0)
  1004. return rc;
  1005. return reg_w(sd, R51x_I2C_R_SID, slave + 1);
  1006. }
  1007. static int write_regvals(struct sd *sd,
  1008. const struct ov_regvals *regvals,
  1009. int n)
  1010. {
  1011. int rc;
  1012. while (--n >= 0) {
  1013. rc = reg_w(sd, regvals->reg, regvals->val);
  1014. if (rc < 0)
  1015. return rc;
  1016. regvals++;
  1017. }
  1018. return 0;
  1019. }
  1020. static int write_i2c_regvals(struct sd *sd,
  1021. const struct ov_i2c_regvals *regvals,
  1022. int n)
  1023. {
  1024. int rc;
  1025. while (--n >= 0) {
  1026. rc = i2c_w(sd, regvals->reg, regvals->val);
  1027. if (rc < 0)
  1028. return rc;
  1029. regvals++;
  1030. }
  1031. return 0;
  1032. }
  1033. /****************************************************************************
  1034. *
  1035. * OV511 and sensor configuration
  1036. *
  1037. ***************************************************************************/
  1038. /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
  1039. * the same register settings as the OV8610, since they are very similar.
  1040. */
  1041. static int ov8xx0_configure(struct sd *sd)
  1042. {
  1043. int rc;
  1044. PDEBUG(D_PROBE, "starting ov8xx0 configuration");
  1045. /* Detect sensor (sub)type */
  1046. rc = i2c_r(sd, OV7610_REG_COM_I);
  1047. if (rc < 0) {
  1048. PDEBUG(D_ERR, "Error detecting sensor type");
  1049. return -1;
  1050. }
  1051. if ((rc & 3) == 1) {
  1052. sd->sensor = SEN_OV8610;
  1053. } else {
  1054. PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
  1055. return -1;
  1056. }
  1057. /* Set sensor-specific vars */
  1058. /* sd->sif = 0; already done */
  1059. return 0;
  1060. }
  1061. /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
  1062. * the same register settings as the OV7610, since they are very similar.
  1063. */
  1064. static int ov7xx0_configure(struct sd *sd)
  1065. {
  1066. int rc, high, low;
  1067. PDEBUG(D_PROBE, "starting OV7xx0 configuration");
  1068. /* Detect sensor (sub)type */
  1069. rc = i2c_r(sd, OV7610_REG_COM_I);
  1070. /* add OV7670 here
  1071. * it appears to be wrongly detected as a 7610 by default */
  1072. if (rc < 0) {
  1073. PDEBUG(D_ERR, "Error detecting sensor type");
  1074. return -1;
  1075. }
  1076. if ((rc & 3) == 3) {
  1077. /* quick hack to make OV7670s work */
  1078. high = i2c_r(sd, 0x0a);
  1079. low = i2c_r(sd, 0x0b);
  1080. /* info("%x, %x", high, low); */
  1081. if (high == 0x76 && low == 0x73) {
  1082. PDEBUG(D_PROBE, "Sensor is an OV7670");
  1083. sd->sensor = SEN_OV7670;
  1084. } else {
  1085. PDEBUG(D_PROBE, "Sensor is an OV7610");
  1086. sd->sensor = SEN_OV7610;
  1087. }
  1088. } else if ((rc & 3) == 1) {
  1089. /* I don't know what's different about the 76BE yet. */
  1090. if (i2c_r(sd, 0x15) & 1)
  1091. PDEBUG(D_PROBE, "Sensor is an OV7620AE");
  1092. else
  1093. PDEBUG(D_PROBE, "Sensor is an OV76BE");
  1094. /* OV511+ will return all zero isoc data unless we
  1095. * configure the sensor as a 7620. Someone needs to
  1096. * find the exact reg. setting that causes this. */
  1097. sd->sensor = SEN_OV76BE;
  1098. } else if ((rc & 3) == 0) {
  1099. /* try to read product id registers */
  1100. high = i2c_r(sd, 0x0a);
  1101. if (high < 0) {
  1102. PDEBUG(D_ERR, "Error detecting camera chip PID");
  1103. return high;
  1104. }
  1105. low = i2c_r(sd, 0x0b);
  1106. if (low < 0) {
  1107. PDEBUG(D_ERR, "Error detecting camera chip VER");
  1108. return low;
  1109. }
  1110. if (high == 0x76) {
  1111. switch (low) {
  1112. case 0x30:
  1113. PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
  1114. PDEBUG(D_ERR,
  1115. "7630 is not supported by this driver");
  1116. return -1;
  1117. case 0x40:
  1118. PDEBUG(D_PROBE, "Sensor is an OV7645");
  1119. sd->sensor = SEN_OV7640; /* FIXME */
  1120. break;
  1121. case 0x45:
  1122. PDEBUG(D_PROBE, "Sensor is an OV7645B");
  1123. sd->sensor = SEN_OV7640; /* FIXME */
  1124. break;
  1125. case 0x48:
  1126. PDEBUG(D_PROBE, "Sensor is an OV7648");
  1127. sd->sensor = SEN_OV7640; /* FIXME */
  1128. break;
  1129. default:
  1130. PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
  1131. return -1;
  1132. }
  1133. } else {
  1134. PDEBUG(D_PROBE, "Sensor is an OV7620");
  1135. sd->sensor = SEN_OV7620;
  1136. }
  1137. } else {
  1138. PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
  1139. return -1;
  1140. }
  1141. /* Set sensor-specific vars */
  1142. /* sd->sif = 0; already done */
  1143. return 0;
  1144. }
  1145. /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
  1146. static int ov6xx0_configure(struct sd *sd)
  1147. {
  1148. int rc;
  1149. PDEBUG(D_PROBE, "starting OV6xx0 configuration");
  1150. /* Detect sensor (sub)type */
  1151. rc = i2c_r(sd, OV7610_REG_COM_I);
  1152. if (rc < 0) {
  1153. PDEBUG(D_ERR, "Error detecting sensor type");
  1154. return -1;
  1155. }
  1156. /* Ugh. The first two bits are the version bits, but
  1157. * the entire register value must be used. I guess OVT
  1158. * underestimated how many variants they would make. */
  1159. switch (rc) {
  1160. case 0x00:
  1161. sd->sensor = SEN_OV6630;
  1162. PDEBUG(D_ERR,
  1163. "WARNING: Sensor is an OV66308. Your camera may have");
  1164. PDEBUG(D_ERR, "been misdetected in previous driver versions.");
  1165. break;
  1166. case 0x01:
  1167. sd->sensor = SEN_OV6620;
  1168. break;
  1169. case 0x02:
  1170. sd->sensor = SEN_OV6630;
  1171. PDEBUG(D_PROBE, "Sensor is an OV66308AE");
  1172. break;
  1173. case 0x03:
  1174. sd->sensor = SEN_OV6630;
  1175. PDEBUG(D_PROBE, "Sensor is an OV66308AF");
  1176. break;
  1177. case 0x90:
  1178. sd->sensor = SEN_OV6630;
  1179. PDEBUG(D_ERR,
  1180. "WARNING: Sensor is an OV66307. Your camera may have");
  1181. PDEBUG(D_ERR, "been misdetected in previous driver versions.");
  1182. break;
  1183. default:
  1184. PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
  1185. return -1;
  1186. }
  1187. /* Set sensor-specific vars */
  1188. sd->sif = 1;
  1189. return 0;
  1190. }
  1191. /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
  1192. static void ov51x_led_control(struct sd *sd, int on)
  1193. {
  1194. reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
  1195. }
  1196. /* this function is called at probe time */
  1197. static int sd_config(struct gspca_dev *gspca_dev,
  1198. const struct usb_device_id *id)
  1199. {
  1200. struct sd *sd = (struct sd *) gspca_dev;
  1201. struct cam *cam;
  1202. static const struct ov_regvals init_519[] = {
  1203. { 0x5a, 0x6d }, /* EnableSystem */
  1204. { 0x53, 0x9b },
  1205. { 0x54, 0xff }, /* set bit2 to enable jpeg */
  1206. { 0x5d, 0x03 },
  1207. { 0x49, 0x01 },
  1208. { 0x48, 0x00 },
  1209. /* Set LED pin to output mode. Bit 4 must be cleared or sensor
  1210. * detection will fail. This deserves further investigation. */
  1211. { OV519_GPIO_IO_CTRL0, 0xee },
  1212. { 0x51, 0x0f }, /* SetUsbInit */
  1213. { 0x51, 0x00 },
  1214. { 0x22, 0x00 },
  1215. /* windows reads 0x55 at this point*/
  1216. };
  1217. if (write_regvals(sd, init_519, ARRAY_SIZE(init_519)))
  1218. goto error;
  1219. ov51x_led_control(sd, 0); /* turn LED off */
  1220. /* Test for 76xx */
  1221. if (ov51x_set_slave_ids(sd, OV7xx0_SID) < 0)
  1222. goto error;
  1223. /* The OV519 must be more aggressive about sensor detection since
  1224. * I2C write will never fail if the sensor is not present. We have
  1225. * to try to initialize the sensor to detect its presence */
  1226. if (init_ov_sensor(sd) >= 0) {
  1227. if (ov7xx0_configure(sd) < 0) {
  1228. PDEBUG(D_ERR, "Failed to configure OV7xx0");
  1229. goto error;
  1230. }
  1231. } else {
  1232. /* Test for 6xx0 */
  1233. if (ov51x_set_slave_ids(sd, OV6xx0_SID) < 0)
  1234. goto error;
  1235. if (init_ov_sensor(sd) >= 0) {
  1236. if (ov6xx0_configure(sd) < 0) {
  1237. PDEBUG(D_ERR, "Failed to configure OV6xx0");
  1238. goto error;
  1239. }
  1240. } else {
  1241. /* Test for 8xx0 */
  1242. if (ov51x_set_slave_ids(sd, OV8xx0_SID) < 0)
  1243. goto error;
  1244. if (init_ov_sensor(sd) < 0) {
  1245. PDEBUG(D_ERR,
  1246. "Can't determine sensor slave IDs");
  1247. goto error;
  1248. }
  1249. if (ov8xx0_configure(sd) < 0) {
  1250. PDEBUG(D_ERR,
  1251. "Failed to configure OV8xx0 sensor");
  1252. goto error;
  1253. }
  1254. }
  1255. }
  1256. cam = &gspca_dev->cam;
  1257. if (!sd->sif) {
  1258. cam->cam_mode = vga_mode;
  1259. cam->nmodes = ARRAY_SIZE(vga_mode);
  1260. } else {
  1261. cam->cam_mode = sif_mode;
  1262. cam->nmodes = ARRAY_SIZE(sif_mode);
  1263. }
  1264. sd->brightness = BRIGHTNESS_DEF;
  1265. sd->contrast = CONTRAST_DEF;
  1266. sd->colors = COLOR_DEF;
  1267. sd->hflip = HFLIP_DEF;
  1268. sd->vflip = VFLIP_DEF;
  1269. if (sd->sensor != SEN_OV7670)
  1270. gspca_dev->ctrl_dis = (1 << HFLIP_IDX)
  1271. | (1 << VFLIP_IDX);
  1272. return 0;
  1273. error:
  1274. PDEBUG(D_ERR, "OV519 Config failed");
  1275. return -EBUSY;
  1276. }
  1277. /* this function is called at probe and resume time */
  1278. static int sd_init(struct gspca_dev *gspca_dev)
  1279. {
  1280. struct sd *sd = (struct sd *) gspca_dev;
  1281. /* initialize the sensor */
  1282. switch (sd->sensor) {
  1283. case SEN_OV6620:
  1284. if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
  1285. return -EIO;
  1286. break;
  1287. case SEN_OV6630:
  1288. if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
  1289. return -EIO;
  1290. break;
  1291. default:
  1292. /* case SEN_OV7610: */
  1293. /* case SEN_OV76BE: */
  1294. if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
  1295. return -EIO;
  1296. break;
  1297. case SEN_OV7620:
  1298. if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
  1299. return -EIO;
  1300. break;
  1301. case SEN_OV7640:
  1302. if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
  1303. return -EIO;
  1304. break;
  1305. case SEN_OV7670:
  1306. if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
  1307. return -EIO;
  1308. break;
  1309. case SEN_OV8610:
  1310. if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
  1311. return -EIO;
  1312. break;
  1313. }
  1314. return 0;
  1315. }
  1316. /* Sets up the OV519 with the given image parameters
  1317. *
  1318. * OV519 needs a completely different approach, until we can figure out what
  1319. * the individual registers do.
  1320. *
  1321. * Do not put any sensor-specific code in here (including I2C I/O functions)
  1322. */
  1323. static int ov519_mode_init_regs(struct sd *sd)
  1324. {
  1325. static const struct ov_regvals mode_init_519_ov7670[] = {
  1326. { 0x5d, 0x03 }, /* Turn off suspend mode */
  1327. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  1328. { 0x54, 0x0f }, /* bit2 (jpeg enable) */
  1329. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  1330. { 0xa3, 0x18 },
  1331. { 0xa4, 0x04 },
  1332. { 0xa5, 0x28 },
  1333. { 0x37, 0x00 }, /* SetUsbInit */
  1334. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  1335. /* Enable both fields, YUV Input, disable defect comp (why?) */
  1336. { 0x20, 0x0c },
  1337. { 0x21, 0x38 },
  1338. { 0x22, 0x1d },
  1339. { 0x17, 0x50 }, /* undocumented */
  1340. { 0x37, 0x00 }, /* undocumented */
  1341. { 0x40, 0xff }, /* I2C timeout counter */
  1342. { 0x46, 0x00 }, /* I2C clock prescaler */
  1343. { 0x59, 0x04 }, /* new from windrv 090403 */
  1344. { 0xff, 0x00 }, /* undocumented */
  1345. /* windows reads 0x55 at this point, why? */
  1346. };
  1347. static const struct ov_regvals mode_init_519[] = {
  1348. { 0x5d, 0x03 }, /* Turn off suspend mode */
  1349. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  1350. { 0x54, 0x0f }, /* bit2 (jpeg enable) */
  1351. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  1352. { 0xa3, 0x18 },
  1353. { 0xa4, 0x04 },
  1354. { 0xa5, 0x28 },
  1355. { 0x37, 0x00 }, /* SetUsbInit */
  1356. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  1357. /* Enable both fields, YUV Input, disable defect comp (why?) */
  1358. { 0x22, 0x1d },
  1359. { 0x17, 0x50 }, /* undocumented */
  1360. { 0x37, 0x00 }, /* undocumented */
  1361. { 0x40, 0xff }, /* I2C timeout counter */
  1362. { 0x46, 0x00 }, /* I2C clock prescaler */
  1363. { 0x59, 0x04 }, /* new from windrv 090403 */
  1364. { 0xff, 0x00 }, /* undocumented */
  1365. /* windows reads 0x55 at this point, why? */
  1366. };
  1367. /******** Set the mode ********/
  1368. if (sd->sensor != SEN_OV7670) {
  1369. if (write_regvals(sd, mode_init_519,
  1370. ARRAY_SIZE(mode_init_519)))
  1371. return -EIO;
  1372. if (sd->sensor == SEN_OV7640) {
  1373. /* Select 8-bit input mode */
  1374. reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
  1375. }
  1376. } else {
  1377. if (write_regvals(sd, mode_init_519_ov7670,
  1378. ARRAY_SIZE(mode_init_519_ov7670)))
  1379. return -EIO;
  1380. }
  1381. reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
  1382. reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
  1383. reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
  1384. reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
  1385. reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
  1386. reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
  1387. reg_w(sd, OV519_R16_DIVIDER, 0x00);
  1388. reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
  1389. reg_w(sd, 0x26, 0x00); /* Undocumented */
  1390. /******** Set the framerate ********/
  1391. if (frame_rate > 0)
  1392. sd->frame_rate = frame_rate;
  1393. /* FIXME: These are only valid at the max resolution. */
  1394. sd->clockdiv = 0;
  1395. switch (sd->sensor) {
  1396. case SEN_OV7640:
  1397. switch (sd->frame_rate) {
  1398. default:
  1399. /* case 30: */
  1400. reg_w(sd, 0xa4, 0x0c);
  1401. reg_w(sd, 0x23, 0xff);
  1402. break;
  1403. case 25:
  1404. reg_w(sd, 0xa4, 0x0c);
  1405. reg_w(sd, 0x23, 0x1f);
  1406. break;
  1407. case 20:
  1408. reg_w(sd, 0xa4, 0x0c);
  1409. reg_w(sd, 0x23, 0x1b);
  1410. break;
  1411. case 15:
  1412. reg_w(sd, 0xa4, 0x04);
  1413. reg_w(sd, 0x23, 0xff);
  1414. sd->clockdiv = 1;
  1415. break;
  1416. case 10:
  1417. reg_w(sd, 0xa4, 0x04);
  1418. reg_w(sd, 0x23, 0x1f);
  1419. sd->clockdiv = 1;
  1420. break;
  1421. case 5:
  1422. reg_w(sd, 0xa4, 0x04);
  1423. reg_w(sd, 0x23, 0x1b);
  1424. sd->clockdiv = 1;
  1425. break;
  1426. }
  1427. break;
  1428. case SEN_OV8610:
  1429. switch (sd->frame_rate) {
  1430. default: /* 15 fps */
  1431. /* case 15: */
  1432. reg_w(sd, 0xa4, 0x06);
  1433. reg_w(sd, 0x23, 0xff);
  1434. break;
  1435. case 10:
  1436. reg_w(sd, 0xa4, 0x06);
  1437. reg_w(sd, 0x23, 0x1f);
  1438. break;
  1439. case 5:
  1440. reg_w(sd, 0xa4, 0x06);
  1441. reg_w(sd, 0x23, 0x1b);
  1442. break;
  1443. }
  1444. break;
  1445. case SEN_OV7670: /* guesses, based on 7640 */
  1446. PDEBUG(D_STREAM, "Setting framerate to %d fps",
  1447. (sd->frame_rate == 0) ? 15 : sd->frame_rate);
  1448. reg_w(sd, 0xa4, 0x10);
  1449. switch (sd->frame_rate) {
  1450. case 30:
  1451. reg_w(sd, 0x23, 0xff);
  1452. break;
  1453. case 20:
  1454. reg_w(sd, 0x23, 0x1b);
  1455. break;
  1456. default:
  1457. /* case 15: */
  1458. reg_w(sd, 0x23, 0xff);
  1459. sd->clockdiv = 1;
  1460. break;
  1461. }
  1462. break;
  1463. }
  1464. return 0;
  1465. }
  1466. static int mode_init_ov_sensor_regs(struct sd *sd)
  1467. {
  1468. struct gspca_dev *gspca_dev;
  1469. int qvga;
  1470. gspca_dev = &sd->gspca_dev;
  1471. qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  1472. /******** Mode (VGA/QVGA) and sensor specific regs ********/
  1473. switch (sd->sensor) {
  1474. case SEN_OV8610:
  1475. /* For OV8610 qvga means qsvga */
  1476. i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
  1477. break;
  1478. case SEN_OV7610:
  1479. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1480. break;
  1481. case SEN_OV7620:
  1482. /* i2c_w(sd, 0x2b, 0x00); */
  1483. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1484. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  1485. i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
  1486. i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
  1487. i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
  1488. i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
  1489. i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
  1490. break;
  1491. case SEN_OV76BE:
  1492. /* i2c_w(sd, 0x2b, 0x00); */
  1493. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1494. break;
  1495. case SEN_OV7640:
  1496. /* i2c_w(sd, 0x2b, 0x00); */
  1497. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1498. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  1499. /* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
  1500. /* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
  1501. /* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
  1502. /* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
  1503. /* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
  1504. break;
  1505. case SEN_OV7670:
  1506. /* set COM7_FMT_VGA or COM7_FMT_QVGA
  1507. * do we need to set anything else?
  1508. * HSTART etc are set in set_ov_sensor_window itself */
  1509. i2c_w_mask(sd, OV7670_REG_COM7,
  1510. qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
  1511. OV7670_COM7_FMT_MASK);
  1512. break;
  1513. case SEN_OV6620:
  1514. case SEN_OV6630:
  1515. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  1516. break;
  1517. default:
  1518. return -EINVAL;
  1519. }
  1520. /******** Palette-specific regs ********/
  1521. if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
  1522. /* not valid on the OV6620/OV7620/6630? */
  1523. i2c_w_mask(sd, 0x0e, 0x00, 0x40);
  1524. }
  1525. /* The OV518 needs special treatment. Although both the OV518
  1526. * and the OV6630 support a 16-bit video bus, only the 8 bit Y
  1527. * bus is actually used. The UV bus is tied to ground.
  1528. * Therefore, the OV6630 needs to be in 8-bit multiplexed
  1529. * output mode */
  1530. /* OV7640 is 8-bit only */
  1531. if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV7640)
  1532. i2c_w_mask(sd, 0x13, 0x00, 0x20);
  1533. /******** Clock programming ********/
  1534. /* The OV6620 needs special handling. This prevents the
  1535. * severe banding that normally occurs */
  1536. if (sd->sensor == SEN_OV6620) {
  1537. /* Clock down */
  1538. i2c_w(sd, 0x2a, 0x04);
  1539. i2c_w(sd, 0x11, sd->clockdiv);
  1540. i2c_w(sd, 0x2a, 0x84);
  1541. /* This next setting is critical. It seems to improve
  1542. * the gain or the contrast. The "reserved" bits seem
  1543. * to have some effect in this case. */
  1544. i2c_w(sd, 0x2d, 0x85);
  1545. } else {
  1546. i2c_w(sd, 0x11, sd->clockdiv);
  1547. }
  1548. /******** Special Features ********/
  1549. /* no evidence this is possible with OV7670, either */
  1550. /* Test Pattern */
  1551. if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670)
  1552. i2c_w_mask(sd, 0x12, 0x00, 0x02);
  1553. /* Enable auto white balance */
  1554. if (sd->sensor == SEN_OV7670)
  1555. i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
  1556. OV7670_COM8_AWB);
  1557. else
  1558. i2c_w_mask(sd, 0x12, 0x04, 0x04);
  1559. /* This will go away as soon as ov51x_mode_init_sensor_regs() */
  1560. /* is fully tested. */
  1561. /* 7620/6620/6630? don't have register 0x35, so play it safe */
  1562. if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
  1563. if (!qvga)
  1564. i2c_w(sd, 0x35, 0x9e);
  1565. else
  1566. i2c_w(sd, 0x35, 0x1e);
  1567. }
  1568. return 0;
  1569. }
  1570. static void sethvflip(struct sd *sd)
  1571. {
  1572. if (sd->sensor != SEN_OV7670)
  1573. return;
  1574. if (sd->gspca_dev.streaming)
  1575. ov51x_stop(sd);
  1576. i2c_w_mask(sd, OV7670_REG_MVFP,
  1577. OV7670_MVFP_MIRROR * sd->hflip
  1578. | OV7670_MVFP_VFLIP * sd->vflip,
  1579. OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
  1580. if (sd->gspca_dev.streaming)
  1581. ov51x_restart(sd);
  1582. }
  1583. static int set_ov_sensor_window(struct sd *sd)
  1584. {
  1585. struct gspca_dev *gspca_dev;
  1586. int qvga;
  1587. int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
  1588. int ret, hstart, hstop, vstop, vstart;
  1589. __u8 v;
  1590. gspca_dev = &sd->gspca_dev;
  1591. qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  1592. /* The different sensor ICs handle setting up of window differently.
  1593. * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
  1594. switch (sd->sensor) {
  1595. case SEN_OV8610:
  1596. hwsbase = 0x1e;
  1597. hwebase = 0x1e;
  1598. vwsbase = 0x02;
  1599. vwebase = 0x02;
  1600. break;
  1601. case SEN_OV7610:
  1602. case SEN_OV76BE:
  1603. hwsbase = 0x38;
  1604. hwebase = 0x3a;
  1605. vwsbase = vwebase = 0x05;
  1606. break;
  1607. case SEN_OV6620:
  1608. case SEN_OV6630:
  1609. hwsbase = 0x38;
  1610. hwebase = 0x3a;
  1611. vwsbase = 0x05;
  1612. vwebase = 0x06;
  1613. break;
  1614. case SEN_OV7620:
  1615. hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
  1616. hwebase = 0x2f;
  1617. vwsbase = vwebase = 0x05;
  1618. break;
  1619. case SEN_OV7640:
  1620. hwsbase = 0x1a;
  1621. hwebase = 0x1a;
  1622. vwsbase = vwebase = 0x03;
  1623. break;
  1624. case SEN_OV7670:
  1625. /*handling of OV7670 hardware sensor start and stop values
  1626. * is very odd, compared to the other OV sensors */
  1627. vwsbase = vwebase = hwebase = hwsbase = 0x00;
  1628. break;
  1629. default:
  1630. return -EINVAL;
  1631. }
  1632. switch (sd->sensor) {
  1633. case SEN_OV6620:
  1634. case SEN_OV6630:
  1635. if (qvga) { /* QCIF */
  1636. hwscale = 0;
  1637. vwscale = 0;
  1638. } else { /* CIF */
  1639. hwscale = 1;
  1640. vwscale = 1; /* The datasheet says 0;
  1641. * it's wrong */
  1642. }
  1643. break;
  1644. case SEN_OV8610:
  1645. if (qvga) { /* QSVGA */
  1646. hwscale = 1;
  1647. vwscale = 1;
  1648. } else { /* SVGA */
  1649. hwscale = 2;
  1650. vwscale = 2;
  1651. }
  1652. break;
  1653. default: /* SEN_OV7xx0 */
  1654. if (qvga) { /* QVGA */
  1655. hwscale = 1;
  1656. vwscale = 0;
  1657. } else { /* VGA */
  1658. hwscale = 2;
  1659. vwscale = 1;
  1660. }
  1661. }
  1662. ret = mode_init_ov_sensor_regs(sd);
  1663. if (ret < 0)
  1664. return ret;
  1665. if (sd->sensor == SEN_OV8610) {
  1666. i2c_w_mask(sd, 0x2d, 0x05, 0x40);
  1667. /* old 0x95, new 0x05 from windrv 090403 */
  1668. /* bits 5-7: reserved */
  1669. i2c_w_mask(sd, 0x28, 0x20, 0x20);
  1670. /* bit 5: progressive mode on */
  1671. }
  1672. /* The below is wrong for OV7670s because their window registers
  1673. * only store the high bits in 0x17 to 0x1a */
  1674. /* SRH Use sd->max values instead of requested win values */
  1675. /* SCS Since we're sticking with only the max hardware widths
  1676. * for a given mode */
  1677. /* I can hard code this for OV7670s */
  1678. /* Yes, these numbers do look odd, but they're tested and work! */
  1679. if (sd->sensor == SEN_OV7670) {
  1680. if (qvga) { /* QVGA from ov7670.c by
  1681. * Jonathan Corbet */
  1682. hstart = 164;
  1683. hstop = 20;
  1684. vstart = 14;
  1685. vstop = 494;
  1686. } else { /* VGA */
  1687. hstart = 158;
  1688. hstop = 14;
  1689. vstart = 10;
  1690. vstop = 490;
  1691. }
  1692. /* OV7670 hardware window registers are split across
  1693. * multiple locations */
  1694. i2c_w(sd, OV7670_REG_HSTART, hstart >> 3);
  1695. i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3);
  1696. v = i2c_r(sd, OV7670_REG_HREF);
  1697. v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07);
  1698. msleep(10); /* need to sleep between read and write to
  1699. * same reg! */
  1700. i2c_w(sd, OV7670_REG_HREF, v);
  1701. i2c_w(sd, OV7670_REG_VSTART, vstart >> 2);
  1702. i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2);
  1703. v = i2c_r(sd, OV7670_REG_VREF);
  1704. v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03);
  1705. msleep(10); /* need to sleep between read and write to
  1706. * same reg! */
  1707. i2c_w(sd, OV7670_REG_VREF, v);
  1708. sethvflip(sd);
  1709. } else {
  1710. i2c_w(sd, 0x17, hwsbase);
  1711. i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale));
  1712. i2c_w(sd, 0x19, vwsbase);
  1713. i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale));
  1714. }
  1715. return 0;
  1716. }
  1717. /* -- start the camera -- */
  1718. static int sd_start(struct gspca_dev *gspca_dev)
  1719. {
  1720. struct sd *sd = (struct sd *) gspca_dev;
  1721. int ret;
  1722. ret = ov519_mode_init_regs(sd);
  1723. if (ret < 0)
  1724. goto out;
  1725. ret = set_ov_sensor_window(sd);
  1726. if (ret < 0)
  1727. goto out;
  1728. ret = ov51x_restart(sd);
  1729. if (ret < 0)
  1730. goto out;
  1731. ov51x_led_control(sd, 1);
  1732. return 0;
  1733. out:
  1734. PDEBUG(D_ERR, "camera start error:%d", ret);
  1735. return ret;
  1736. }
  1737. static void sd_stopN(struct gspca_dev *gspca_dev)
  1738. {
  1739. struct sd *sd = (struct sd *) gspca_dev;
  1740. ov51x_stop(sd);
  1741. ov51x_led_control(sd, 0);
  1742. }
  1743. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1744. struct gspca_frame *frame, /* target */
  1745. __u8 *data, /* isoc packet */
  1746. int len) /* iso packet length */
  1747. {
  1748. /* Header of ov519 is 16 bytes:
  1749. * Byte Value Description
  1750. * 0 0xff magic
  1751. * 1 0xff magic
  1752. * 2 0xff magic
  1753. * 3 0xXX 0x50 = SOF, 0x51 = EOF
  1754. * 9 0xXX 0x01 initial frame without data,
  1755. * 0x00 standard frame with image
  1756. * 14 Lo in EOF: length of image data / 8
  1757. * 15 Hi
  1758. */
  1759. if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
  1760. switch (data[3]) {
  1761. case 0x50: /* start of frame */
  1762. #define HDRSZ 16
  1763. data += HDRSZ;
  1764. len -= HDRSZ;
  1765. #undef HDRSZ
  1766. if (data[0] == 0xff || data[1] == 0xd8)
  1767. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  1768. data, len);
  1769. else
  1770. gspca_dev->last_packet_type = DISCARD_PACKET;
  1771. return;
  1772. case 0x51: /* end of frame */
  1773. if (data[9] != 0)
  1774. gspca_dev->last_packet_type = DISCARD_PACKET;
  1775. gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  1776. data, 0);
  1777. return;
  1778. }
  1779. }
  1780. /* intermediate packet */
  1781. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  1782. data, len);
  1783. }
  1784. /* -- management routines -- */
  1785. static void setbrightness(struct gspca_dev *gspca_dev)
  1786. {
  1787. struct sd *sd = (struct sd *) gspca_dev;
  1788. int val;
  1789. val = sd->brightness;
  1790. switch (sd->sensor) {
  1791. case SEN_OV8610:
  1792. case SEN_OV7610:
  1793. case SEN_OV76BE:
  1794. case SEN_OV6620:
  1795. case SEN_OV6630:
  1796. case SEN_OV7640:
  1797. i2c_w(sd, OV7610_REG_BRT, val);
  1798. break;
  1799. case SEN_OV7620:
  1800. /* 7620 doesn't like manual changes when in auto mode */
  1801. /*fixme
  1802. * if (!sd->auto_brt) */
  1803. i2c_w(sd, OV7610_REG_BRT, val);
  1804. break;
  1805. case SEN_OV7670:
  1806. /*win trace
  1807. * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
  1808. i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
  1809. break;
  1810. }
  1811. }
  1812. static void setcontrast(struct gspca_dev *gspca_dev)
  1813. {
  1814. struct sd *sd = (struct sd *) gspca_dev;
  1815. int val;
  1816. val = sd->contrast;
  1817. switch (sd->sensor) {
  1818. case SEN_OV7610:
  1819. case SEN_OV6620:
  1820. i2c_w(sd, OV7610_REG_CNT, val);
  1821. break;
  1822. case SEN_OV6630:
  1823. i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
  1824. case SEN_OV8610: {
  1825. static const __u8 ctab[] = {
  1826. 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
  1827. };
  1828. /* Use Y gamma control instead. Bit 0 enables it. */
  1829. i2c_w(sd, 0x64, ctab[val >> 5]);
  1830. break;
  1831. }
  1832. case SEN_OV7620: {
  1833. static const __u8 ctab[] = {
  1834. 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
  1835. 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
  1836. };
  1837. /* Use Y gamma control instead. Bit 0 enables it. */
  1838. i2c_w(sd, 0x64, ctab[val >> 4]);
  1839. break;
  1840. }
  1841. case SEN_OV7640:
  1842. /* Use gain control instead. */
  1843. i2c_w(sd, OV7610_REG_GAIN, val >> 2);
  1844. break;
  1845. case SEN_OV7670:
  1846. /* check that this isn't just the same as ov7610 */
  1847. i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
  1848. break;
  1849. }
  1850. }
  1851. static void setcolors(struct gspca_dev *gspca_dev)
  1852. {
  1853. struct sd *sd = (struct sd *) gspca_dev;
  1854. int val;
  1855. val = sd->colors;
  1856. switch (sd->sensor) {
  1857. case SEN_OV8610:
  1858. case SEN_OV7610:
  1859. case SEN_OV76BE:
  1860. case SEN_OV6620:
  1861. case SEN_OV6630:
  1862. i2c_w(sd, OV7610_REG_SAT, val);
  1863. break;
  1864. case SEN_OV7620:
  1865. /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
  1866. /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
  1867. if (rc < 0)
  1868. goto out; */
  1869. i2c_w(sd, OV7610_REG_SAT, val);
  1870. break;
  1871. case SEN_OV7640:
  1872. i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
  1873. break;
  1874. case SEN_OV7670:
  1875. /* supported later once I work out how to do it
  1876. * transparently fail now! */
  1877. /* set REG_COM13 values for UV sat auto mode */
  1878. break;
  1879. }
  1880. }
  1881. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1882. {
  1883. struct sd *sd = (struct sd *) gspca_dev;
  1884. sd->brightness = val;
  1885. if (gspca_dev->streaming)
  1886. setbrightness(gspca_dev);
  1887. return 0;
  1888. }
  1889. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1890. {
  1891. struct sd *sd = (struct sd *) gspca_dev;
  1892. *val = sd->brightness;
  1893. return 0;
  1894. }
  1895. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1896. {
  1897. struct sd *sd = (struct sd *) gspca_dev;
  1898. sd->contrast = val;
  1899. if (gspca_dev->streaming)
  1900. setcontrast(gspca_dev);
  1901. return 0;
  1902. }
  1903. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1904. {
  1905. struct sd *sd = (struct sd *) gspca_dev;
  1906. *val = sd->contrast;
  1907. return 0;
  1908. }
  1909. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1910. {
  1911. struct sd *sd = (struct sd *) gspca_dev;
  1912. sd->colors = val;
  1913. if (gspca_dev->streaming)
  1914. setcolors(gspca_dev);
  1915. return 0;
  1916. }
  1917. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1918. {
  1919. struct sd *sd = (struct sd *) gspca_dev;
  1920. *val = sd->colors;
  1921. return 0;
  1922. }
  1923. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  1924. {
  1925. struct sd *sd = (struct sd *) gspca_dev;
  1926. sd->hflip = val;
  1927. if (gspca_dev->streaming)
  1928. sethvflip(sd);
  1929. return 0;
  1930. }
  1931. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1932. {
  1933. struct sd *sd = (struct sd *) gspca_dev;
  1934. *val = sd->hflip;
  1935. return 0;
  1936. }
  1937. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1938. {
  1939. struct sd *sd = (struct sd *) gspca_dev;
  1940. sd->vflip = val;
  1941. if (gspca_dev->streaming)
  1942. sethvflip(sd);
  1943. return 0;
  1944. }
  1945. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1946. {
  1947. struct sd *sd = (struct sd *) gspca_dev;
  1948. *val = sd->vflip;
  1949. return 0;
  1950. }
  1951. /* sub-driver description */
  1952. static const struct sd_desc sd_desc = {
  1953. .name = MODULE_NAME,
  1954. .ctrls = sd_ctrls,
  1955. .nctrls = ARRAY_SIZE(sd_ctrls),
  1956. .config = sd_config,
  1957. .init = sd_init,
  1958. .start = sd_start,
  1959. .stopN = sd_stopN,
  1960. .pkt_scan = sd_pkt_scan,
  1961. };
  1962. /* -- module initialisation -- */
  1963. static const __devinitdata struct usb_device_id device_table[] = {
  1964. {USB_DEVICE(0x041e, 0x4052)},
  1965. {USB_DEVICE(0x041e, 0x405f)},
  1966. {USB_DEVICE(0x041e, 0x4060)},
  1967. {USB_DEVICE(0x041e, 0x4061)},
  1968. {USB_DEVICE(0x041e, 0x4064)},
  1969. {USB_DEVICE(0x041e, 0x4068)},
  1970. {USB_DEVICE(0x045e, 0x028c)},
  1971. {USB_DEVICE(0x054c, 0x0154)},
  1972. {USB_DEVICE(0x054c, 0x0155)},
  1973. {USB_DEVICE(0x05a9, 0x0519)},
  1974. {USB_DEVICE(0x05a9, 0x0530)},
  1975. {USB_DEVICE(0x05a9, 0x4519)},
  1976. {USB_DEVICE(0x05a9, 0x8519)},
  1977. {}
  1978. };
  1979. MODULE_DEVICE_TABLE(usb, device_table);
  1980. /* -- device connect -- */
  1981. static int sd_probe(struct usb_interface *intf,
  1982. const struct usb_device_id *id)
  1983. {
  1984. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1985. THIS_MODULE);
  1986. }
  1987. static struct usb_driver sd_driver = {
  1988. .name = MODULE_NAME,
  1989. .id_table = device_table,
  1990. .probe = sd_probe,
  1991. .disconnect = gspca_disconnect,
  1992. #ifdef CONFIG_PM
  1993. .suspend = gspca_suspend,
  1994. .resume = gspca_resume,
  1995. #endif
  1996. };
  1997. /* -- module insert / remove -- */
  1998. static int __init sd_mod_init(void)
  1999. {
  2000. int ret;
  2001. ret = usb_register(&sd_driver);
  2002. if (ret < 0)
  2003. return ret;
  2004. PDEBUG(D_PROBE, "registered");
  2005. return 0;
  2006. }
  2007. static void __exit sd_mod_exit(void)
  2008. {
  2009. usb_deregister(&sd_driver);
  2010. PDEBUG(D_PROBE, "deregistered");
  2011. }
  2012. module_init(sd_mod_init);
  2013. module_exit(sd_mod_exit);
  2014. module_param(frame_rate, int, 0644);
  2015. MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");