ov519.c 58 KB

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