ov519.c 59 KB

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