ov519.c 56 KB

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