ov519.c 59 KB

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