ov519.c 55 KB

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