ov519.c 57 KB

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