ov519.c 58 KB

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