ov772x.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. /*
  2. * ov772x Camera Driver
  3. *
  4. * Copyright (C) 2008 Renesas Solutions Corp.
  5. * Kuninori Morimoto <morimoto.kuninori@renesas.com>
  6. *
  7. * Based on ov7670 and soc_camera_platform driver,
  8. *
  9. * Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
  10. * Copyright (C) 2008 Magnus Damm
  11. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/i2c.h>
  21. #include <linux/slab.h>
  22. #include <linux/delay.h>
  23. #include <linux/v4l2-mediabus.h>
  24. #include <linux/videodev2.h>
  25. #include <media/ov772x.h>
  26. #include <media/soc_camera.h>
  27. #include <media/v4l2-ctrls.h>
  28. #include <media/v4l2-chip-ident.h>
  29. #include <media/v4l2-subdev.h>
  30. /*
  31. * register offset
  32. */
  33. #define GAIN 0x00 /* AGC - Gain control gain setting */
  34. #define BLUE 0x01 /* AWB - Blue channel gain setting */
  35. #define RED 0x02 /* AWB - Red channel gain setting */
  36. #define GREEN 0x03 /* AWB - Green channel gain setting */
  37. #define COM1 0x04 /* Common control 1 */
  38. #define BAVG 0x05 /* U/B Average Level */
  39. #define GAVG 0x06 /* Y/Gb Average Level */
  40. #define RAVG 0x07 /* V/R Average Level */
  41. #define AECH 0x08 /* Exposure Value - AEC MSBs */
  42. #define COM2 0x09 /* Common control 2 */
  43. #define PID 0x0A /* Product ID Number MSB */
  44. #define VER 0x0B /* Product ID Number LSB */
  45. #define COM3 0x0C /* Common control 3 */
  46. #define COM4 0x0D /* Common control 4 */
  47. #define COM5 0x0E /* Common control 5 */
  48. #define COM6 0x0F /* Common control 6 */
  49. #define AEC 0x10 /* Exposure Value */
  50. #define CLKRC 0x11 /* Internal clock */
  51. #define COM7 0x12 /* Common control 7 */
  52. #define COM8 0x13 /* Common control 8 */
  53. #define COM9 0x14 /* Common control 9 */
  54. #define COM10 0x15 /* Common control 10 */
  55. #define REG16 0x16 /* Register 16 */
  56. #define HSTART 0x17 /* Horizontal sensor size */
  57. #define HSIZE 0x18 /* Horizontal frame (HREF column) end high 8-bit */
  58. #define VSTART 0x19 /* Vertical frame (row) start high 8-bit */
  59. #define VSIZE 0x1A /* Vertical sensor size */
  60. #define PSHFT 0x1B /* Data format - pixel delay select */
  61. #define MIDH 0x1C /* Manufacturer ID byte - high */
  62. #define MIDL 0x1D /* Manufacturer ID byte - low */
  63. #define LAEC 0x1F /* Fine AEC value */
  64. #define COM11 0x20 /* Common control 11 */
  65. #define BDBASE 0x22 /* Banding filter Minimum AEC value */
  66. #define DBSTEP 0x23 /* Banding filter Maximum Setp */
  67. #define AEW 0x24 /* AGC/AEC - Stable operating region (upper limit) */
  68. #define AEB 0x25 /* AGC/AEC - Stable operating region (lower limit) */
  69. #define VPT 0x26 /* AGC/AEC Fast mode operating region */
  70. #define REG28 0x28 /* Register 28 */
  71. #define HOUTSIZE 0x29 /* Horizontal data output size MSBs */
  72. #define EXHCH 0x2A /* Dummy pixel insert MSB */
  73. #define EXHCL 0x2B /* Dummy pixel insert LSB */
  74. #define VOUTSIZE 0x2C /* Vertical data output size MSBs */
  75. #define ADVFL 0x2D /* LSB of insert dummy lines in Vertical direction */
  76. #define ADVFH 0x2E /* MSG of insert dummy lines in Vertical direction */
  77. #define YAVE 0x2F /* Y/G Channel Average value */
  78. #define LUMHTH 0x30 /* Histogram AEC/AGC Luminance high level threshold */
  79. #define LUMLTH 0x31 /* Histogram AEC/AGC Luminance low level threshold */
  80. #define HREF 0x32 /* Image start and size control */
  81. #define DM_LNL 0x33 /* Dummy line low 8 bits */
  82. #define DM_LNH 0x34 /* Dummy line high 8 bits */
  83. #define ADOFF_B 0x35 /* AD offset compensation value for B channel */
  84. #define ADOFF_R 0x36 /* AD offset compensation value for R channel */
  85. #define ADOFF_GB 0x37 /* AD offset compensation value for Gb channel */
  86. #define ADOFF_GR 0x38 /* AD offset compensation value for Gr channel */
  87. #define OFF_B 0x39 /* Analog process B channel offset value */
  88. #define OFF_R 0x3A /* Analog process R channel offset value */
  89. #define OFF_GB 0x3B /* Analog process Gb channel offset value */
  90. #define OFF_GR 0x3C /* Analog process Gr channel offset value */
  91. #define COM12 0x3D /* Common control 12 */
  92. #define COM13 0x3E /* Common control 13 */
  93. #define COM14 0x3F /* Common control 14 */
  94. #define COM15 0x40 /* Common control 15*/
  95. #define COM16 0x41 /* Common control 16 */
  96. #define TGT_B 0x42 /* BLC blue channel target value */
  97. #define TGT_R 0x43 /* BLC red channel target value */
  98. #define TGT_GB 0x44 /* BLC Gb channel target value */
  99. #define TGT_GR 0x45 /* BLC Gr channel target value */
  100. /* for ov7720 */
  101. #define LCC0 0x46 /* Lens correction control 0 */
  102. #define LCC1 0x47 /* Lens correction option 1 - X coordinate */
  103. #define LCC2 0x48 /* Lens correction option 2 - Y coordinate */
  104. #define LCC3 0x49 /* Lens correction option 3 */
  105. #define LCC4 0x4A /* Lens correction option 4 - radius of the circular */
  106. #define LCC5 0x4B /* Lens correction option 5 */
  107. #define LCC6 0x4C /* Lens correction option 6 */
  108. /* for ov7725 */
  109. #define LC_CTR 0x46 /* Lens correction control */
  110. #define LC_XC 0x47 /* X coordinate of lens correction center relative */
  111. #define LC_YC 0x48 /* Y coordinate of lens correction center relative */
  112. #define LC_COEF 0x49 /* Lens correction coefficient */
  113. #define LC_RADI 0x4A /* Lens correction radius */
  114. #define LC_COEFB 0x4B /* Lens B channel compensation coefficient */
  115. #define LC_COEFR 0x4C /* Lens R channel compensation coefficient */
  116. #define FIXGAIN 0x4D /* Analog fix gain amplifer */
  117. #define AREF0 0x4E /* Sensor reference control */
  118. #define AREF1 0x4F /* Sensor reference current control */
  119. #define AREF2 0x50 /* Analog reference control */
  120. #define AREF3 0x51 /* ADC reference control */
  121. #define AREF4 0x52 /* ADC reference control */
  122. #define AREF5 0x53 /* ADC reference control */
  123. #define AREF6 0x54 /* Analog reference control */
  124. #define AREF7 0x55 /* Analog reference control */
  125. #define UFIX 0x60 /* U channel fixed value output */
  126. #define VFIX 0x61 /* V channel fixed value output */
  127. #define AWBB_BLK 0x62 /* AWB option for advanced AWB */
  128. #define AWB_CTRL0 0x63 /* AWB control byte 0 */
  129. #define DSP_CTRL1 0x64 /* DSP control byte 1 */
  130. #define DSP_CTRL2 0x65 /* DSP control byte 2 */
  131. #define DSP_CTRL3 0x66 /* DSP control byte 3 */
  132. #define DSP_CTRL4 0x67 /* DSP control byte 4 */
  133. #define AWB_BIAS 0x68 /* AWB BLC level clip */
  134. #define AWB_CTRL1 0x69 /* AWB control 1 */
  135. #define AWB_CTRL2 0x6A /* AWB control 2 */
  136. #define AWB_CTRL3 0x6B /* AWB control 3 */
  137. #define AWB_CTRL4 0x6C /* AWB control 4 */
  138. #define AWB_CTRL5 0x6D /* AWB control 5 */
  139. #define AWB_CTRL6 0x6E /* AWB control 6 */
  140. #define AWB_CTRL7 0x6F /* AWB control 7 */
  141. #define AWB_CTRL8 0x70 /* AWB control 8 */
  142. #define AWB_CTRL9 0x71 /* AWB control 9 */
  143. #define AWB_CTRL10 0x72 /* AWB control 10 */
  144. #define AWB_CTRL11 0x73 /* AWB control 11 */
  145. #define AWB_CTRL12 0x74 /* AWB control 12 */
  146. #define AWB_CTRL13 0x75 /* AWB control 13 */
  147. #define AWB_CTRL14 0x76 /* AWB control 14 */
  148. #define AWB_CTRL15 0x77 /* AWB control 15 */
  149. #define AWB_CTRL16 0x78 /* AWB control 16 */
  150. #define AWB_CTRL17 0x79 /* AWB control 17 */
  151. #define AWB_CTRL18 0x7A /* AWB control 18 */
  152. #define AWB_CTRL19 0x7B /* AWB control 19 */
  153. #define AWB_CTRL20 0x7C /* AWB control 20 */
  154. #define AWB_CTRL21 0x7D /* AWB control 21 */
  155. #define GAM1 0x7E /* Gamma Curve 1st segment input end point */
  156. #define GAM2 0x7F /* Gamma Curve 2nd segment input end point */
  157. #define GAM3 0x80 /* Gamma Curve 3rd segment input end point */
  158. #define GAM4 0x81 /* Gamma Curve 4th segment input end point */
  159. #define GAM5 0x82 /* Gamma Curve 5th segment input end point */
  160. #define GAM6 0x83 /* Gamma Curve 6th segment input end point */
  161. #define GAM7 0x84 /* Gamma Curve 7th segment input end point */
  162. #define GAM8 0x85 /* Gamma Curve 8th segment input end point */
  163. #define GAM9 0x86 /* Gamma Curve 9th segment input end point */
  164. #define GAM10 0x87 /* Gamma Curve 10th segment input end point */
  165. #define GAM11 0x88 /* Gamma Curve 11th segment input end point */
  166. #define GAM12 0x89 /* Gamma Curve 12th segment input end point */
  167. #define GAM13 0x8A /* Gamma Curve 13th segment input end point */
  168. #define GAM14 0x8B /* Gamma Curve 14th segment input end point */
  169. #define GAM15 0x8C /* Gamma Curve 15th segment input end point */
  170. #define SLOP 0x8D /* Gamma curve highest segment slope */
  171. #define DNSTH 0x8E /* De-noise threshold */
  172. #define EDGE_STRNGT 0x8F /* Edge strength control when manual mode */
  173. #define EDGE_TRSHLD 0x90 /* Edge threshold control when manual mode */
  174. #define DNSOFF 0x91 /* Auto De-noise threshold control */
  175. #define EDGE_UPPER 0x92 /* Edge strength upper limit when Auto mode */
  176. #define EDGE_LOWER 0x93 /* Edge strength lower limit when Auto mode */
  177. #define MTX1 0x94 /* Matrix coefficient 1 */
  178. #define MTX2 0x95 /* Matrix coefficient 2 */
  179. #define MTX3 0x96 /* Matrix coefficient 3 */
  180. #define MTX4 0x97 /* Matrix coefficient 4 */
  181. #define MTX5 0x98 /* Matrix coefficient 5 */
  182. #define MTX6 0x99 /* Matrix coefficient 6 */
  183. #define MTX_CTRL 0x9A /* Matrix control */
  184. #define BRIGHT 0x9B /* Brightness control */
  185. #define CNTRST 0x9C /* Contrast contrast */
  186. #define CNTRST_CTRL 0x9D /* Contrast contrast center */
  187. #define UVAD_J0 0x9E /* Auto UV adjust contrast 0 */
  188. #define UVAD_J1 0x9F /* Auto UV adjust contrast 1 */
  189. #define SCAL0 0xA0 /* Scaling control 0 */
  190. #define SCAL1 0xA1 /* Scaling control 1 */
  191. #define SCAL2 0xA2 /* Scaling control 2 */
  192. #define FIFODLYM 0xA3 /* FIFO manual mode delay control */
  193. #define FIFODLYA 0xA4 /* FIFO auto mode delay control */
  194. #define SDE 0xA6 /* Special digital effect control */
  195. #define USAT 0xA7 /* U component saturation control */
  196. #define VSAT 0xA8 /* V component saturation control */
  197. /* for ov7720 */
  198. #define HUE0 0xA9 /* Hue control 0 */
  199. #define HUE1 0xAA /* Hue control 1 */
  200. /* for ov7725 */
  201. #define HUECOS 0xA9 /* Cosine value */
  202. #define HUESIN 0xAA /* Sine value */
  203. #define SIGN 0xAB /* Sign bit for Hue and contrast */
  204. #define DSPAUTO 0xAC /* DSP auto function ON/OFF control */
  205. /*
  206. * register detail
  207. */
  208. /* COM2 */
  209. #define SOFT_SLEEP_MODE 0x10 /* Soft sleep mode */
  210. /* Output drive capability */
  211. #define OCAP_1x 0x00 /* 1x */
  212. #define OCAP_2x 0x01 /* 2x */
  213. #define OCAP_3x 0x02 /* 3x */
  214. #define OCAP_4x 0x03 /* 4x */
  215. /* COM3 */
  216. #define SWAP_MASK (SWAP_RGB | SWAP_YUV | SWAP_ML)
  217. #define IMG_MASK (VFLIP_IMG | HFLIP_IMG)
  218. #define VFLIP_IMG 0x80 /* Vertical flip image ON/OFF selection */
  219. #define HFLIP_IMG 0x40 /* Horizontal mirror image ON/OFF selection */
  220. #define SWAP_RGB 0x20 /* Swap B/R output sequence in RGB mode */
  221. #define SWAP_YUV 0x10 /* Swap Y/UV output sequence in YUV mode */
  222. #define SWAP_ML 0x08 /* Swap output MSB/LSB */
  223. /* Tri-state option for output clock */
  224. #define NOTRI_CLOCK 0x04 /* 0: Tri-state at this period */
  225. /* 1: No tri-state at this period */
  226. /* Tri-state option for output data */
  227. #define NOTRI_DATA 0x02 /* 0: Tri-state at this period */
  228. /* 1: No tri-state at this period */
  229. #define SCOLOR_TEST 0x01 /* Sensor color bar test pattern */
  230. /* COM4 */
  231. /* PLL frequency control */
  232. #define PLL_BYPASS 0x00 /* 00: Bypass PLL */
  233. #define PLL_4x 0x40 /* 01: PLL 4x */
  234. #define PLL_6x 0x80 /* 10: PLL 6x */
  235. #define PLL_8x 0xc0 /* 11: PLL 8x */
  236. /* AEC evaluate window */
  237. #define AEC_FULL 0x00 /* 00: Full window */
  238. #define AEC_1p2 0x10 /* 01: 1/2 window */
  239. #define AEC_1p4 0x20 /* 10: 1/4 window */
  240. #define AEC_2p3 0x30 /* 11: Low 2/3 window */
  241. /* COM5 */
  242. #define AFR_ON_OFF 0x80 /* Auto frame rate control ON/OFF selection */
  243. #define AFR_SPPED 0x40 /* Auto frame rate control speed selection */
  244. /* Auto frame rate max rate control */
  245. #define AFR_NO_RATE 0x00 /* No reduction of frame rate */
  246. #define AFR_1p2 0x10 /* Max reduction to 1/2 frame rate */
  247. #define AFR_1p4 0x20 /* Max reduction to 1/4 frame rate */
  248. #define AFR_1p8 0x30 /* Max reduction to 1/8 frame rate */
  249. /* Auto frame rate active point control */
  250. #define AF_2x 0x00 /* Add frame when AGC reaches 2x gain */
  251. #define AF_4x 0x04 /* Add frame when AGC reaches 4x gain */
  252. #define AF_8x 0x08 /* Add frame when AGC reaches 8x gain */
  253. #define AF_16x 0x0c /* Add frame when AGC reaches 16x gain */
  254. /* AEC max step control */
  255. #define AEC_NO_LIMIT 0x01 /* 0 : AEC incease step has limit */
  256. /* 1 : No limit to AEC increase step */
  257. /* COM7 */
  258. /* SCCB Register Reset */
  259. #define SCCB_RESET 0x80 /* 0 : No change */
  260. /* 1 : Resets all registers to default */
  261. /* Resolution selection */
  262. #define SLCT_MASK 0x40 /* Mask of VGA or QVGA */
  263. #define SLCT_VGA 0x00 /* 0 : VGA */
  264. #define SLCT_QVGA 0x40 /* 1 : QVGA */
  265. #define ITU656_ON_OFF 0x20 /* ITU656 protocol ON/OFF selection */
  266. /* RGB output format control */
  267. #define FMT_MASK 0x0c /* Mask of color format */
  268. #define FMT_GBR422 0x00 /* 00 : GBR 4:2:2 */
  269. #define FMT_RGB565 0x04 /* 01 : RGB 565 */
  270. #define FMT_RGB555 0x08 /* 10 : RGB 555 */
  271. #define FMT_RGB444 0x0c /* 11 : RGB 444 */
  272. /* Output format control */
  273. #define OFMT_MASK 0x03 /* Mask of output format */
  274. #define OFMT_YUV 0x00 /* 00 : YUV */
  275. #define OFMT_P_BRAW 0x01 /* 01 : Processed Bayer RAW */
  276. #define OFMT_RGB 0x02 /* 10 : RGB */
  277. #define OFMT_BRAW 0x03 /* 11 : Bayer RAW */
  278. /* COM8 */
  279. #define FAST_ALGO 0x80 /* Enable fast AGC/AEC algorithm */
  280. /* AEC Setp size limit */
  281. #define UNLMT_STEP 0x40 /* 0 : Step size is limited */
  282. /* 1 : Unlimited step size */
  283. #define BNDF_ON_OFF 0x20 /* Banding filter ON/OFF */
  284. #define AEC_BND 0x10 /* Enable AEC below banding value */
  285. #define AEC_ON_OFF 0x08 /* Fine AEC ON/OFF control */
  286. #define AGC_ON 0x04 /* AGC Enable */
  287. #define AWB_ON 0x02 /* AWB Enable */
  288. #define AEC_ON 0x01 /* AEC Enable */
  289. /* COM9 */
  290. #define BASE_AECAGC 0x80 /* Histogram or average based AEC/AGC */
  291. /* Automatic gain ceiling - maximum AGC value */
  292. #define GAIN_2x 0x00 /* 000 : 2x */
  293. #define GAIN_4x 0x10 /* 001 : 4x */
  294. #define GAIN_8x 0x20 /* 010 : 8x */
  295. #define GAIN_16x 0x30 /* 011 : 16x */
  296. #define GAIN_32x 0x40 /* 100 : 32x */
  297. #define GAIN_64x 0x50 /* 101 : 64x */
  298. #define GAIN_128x 0x60 /* 110 : 128x */
  299. #define DROP_VSYNC 0x04 /* Drop VSYNC output of corrupt frame */
  300. #define DROP_HREF 0x02 /* Drop HREF output of corrupt frame */
  301. /* COM11 */
  302. #define SGLF_ON_OFF 0x02 /* Single frame ON/OFF selection */
  303. #define SGLF_TRIG 0x01 /* Single frame transfer trigger */
  304. /* EXHCH */
  305. #define VSIZE_LSB 0x04 /* Vertical data output size LSB */
  306. /* DSP_CTRL1 */
  307. #define FIFO_ON 0x80 /* FIFO enable/disable selection */
  308. #define UV_ON_OFF 0x40 /* UV adjust function ON/OFF selection */
  309. #define YUV444_2_422 0x20 /* YUV444 to 422 UV channel option selection */
  310. #define CLR_MTRX_ON_OFF 0x10 /* Color matrix ON/OFF selection */
  311. #define INTPLT_ON_OFF 0x08 /* Interpolation ON/OFF selection */
  312. #define GMM_ON_OFF 0x04 /* Gamma function ON/OFF selection */
  313. #define AUTO_BLK_ON_OFF 0x02 /* Black defect auto correction ON/OFF */
  314. #define AUTO_WHT_ON_OFF 0x01 /* White define auto correction ON/OFF */
  315. /* DSP_CTRL3 */
  316. #define UV_MASK 0x80 /* UV output sequence option */
  317. #define UV_ON 0x80 /* ON */
  318. #define UV_OFF 0x00 /* OFF */
  319. #define CBAR_MASK 0x20 /* DSP Color bar mask */
  320. #define CBAR_ON 0x20 /* ON */
  321. #define CBAR_OFF 0x00 /* OFF */
  322. /* HSTART */
  323. #define HST_VGA 0x23
  324. #define HST_QVGA 0x3F
  325. /* HSIZE */
  326. #define HSZ_VGA 0xA0
  327. #define HSZ_QVGA 0x50
  328. /* VSTART */
  329. #define VST_VGA 0x07
  330. #define VST_QVGA 0x03
  331. /* VSIZE */
  332. #define VSZ_VGA 0xF0
  333. #define VSZ_QVGA 0x78
  334. /* HOUTSIZE */
  335. #define HOSZ_VGA 0xA0
  336. #define HOSZ_QVGA 0x50
  337. /* VOUTSIZE */
  338. #define VOSZ_VGA 0xF0
  339. #define VOSZ_QVGA 0x78
  340. /* DSPAUTO (DSP Auto Function ON/OFF Control) */
  341. #define AWB_ACTRL 0x80 /* AWB auto threshold control */
  342. #define DENOISE_ACTRL 0x40 /* De-noise auto threshold control */
  343. #define EDGE_ACTRL 0x20 /* Edge enhancement auto strength control */
  344. #define UV_ACTRL 0x10 /* UV adjust auto slope control */
  345. #define SCAL0_ACTRL 0x08 /* Auto scaling factor control */
  346. #define SCAL1_2_ACTRL 0x04 /* Auto scaling factor control */
  347. /*
  348. * ID
  349. */
  350. #define OV7720 0x7720
  351. #define OV7725 0x7721
  352. #define VERSION(pid, ver) ((pid<<8)|(ver&0xFF))
  353. /*
  354. * struct
  355. */
  356. struct regval_list {
  357. unsigned char reg_num;
  358. unsigned char value;
  359. };
  360. struct ov772x_color_format {
  361. enum v4l2_mbus_pixelcode code;
  362. enum v4l2_colorspace colorspace;
  363. u8 dsp3;
  364. u8 com3;
  365. u8 com7;
  366. };
  367. struct ov772x_win_size {
  368. char *name;
  369. __u32 width;
  370. __u32 height;
  371. unsigned char com7_bit;
  372. const struct regval_list *regs;
  373. };
  374. struct ov772x_priv {
  375. struct v4l2_subdev subdev;
  376. struct v4l2_ctrl_handler hdl;
  377. struct ov772x_camera_info *info;
  378. const struct ov772x_color_format *cfmt;
  379. const struct ov772x_win_size *win;
  380. int model;
  381. unsigned short flag_vflip:1;
  382. unsigned short flag_hflip:1;
  383. /* band_filter = COM8[5] ? 256 - BDBASE : 0 */
  384. unsigned short band_filter;
  385. };
  386. #define ENDMARKER { 0xff, 0xff }
  387. /*
  388. * register setting for window size
  389. */
  390. static const struct regval_list ov772x_qvga_regs[] = {
  391. { HSTART, HST_QVGA },
  392. { HSIZE, HSZ_QVGA },
  393. { VSTART, VST_QVGA },
  394. { VSIZE, VSZ_QVGA },
  395. { HOUTSIZE, HOSZ_QVGA },
  396. { VOUTSIZE, VOSZ_QVGA },
  397. ENDMARKER,
  398. };
  399. static const struct regval_list ov772x_vga_regs[] = {
  400. { HSTART, HST_VGA },
  401. { HSIZE, HSZ_VGA },
  402. { VSTART, VST_VGA },
  403. { VSIZE, VSZ_VGA },
  404. { HOUTSIZE, HOSZ_VGA },
  405. { VOUTSIZE, VOSZ_VGA },
  406. ENDMARKER,
  407. };
  408. /*
  409. * supported color format list
  410. */
  411. static const struct ov772x_color_format ov772x_cfmts[] = {
  412. {
  413. .code = V4L2_MBUS_FMT_YUYV8_2X8,
  414. .colorspace = V4L2_COLORSPACE_JPEG,
  415. .dsp3 = 0x0,
  416. .com3 = SWAP_YUV,
  417. .com7 = OFMT_YUV,
  418. },
  419. {
  420. .code = V4L2_MBUS_FMT_YVYU8_2X8,
  421. .colorspace = V4L2_COLORSPACE_JPEG,
  422. .dsp3 = UV_ON,
  423. .com3 = SWAP_YUV,
  424. .com7 = OFMT_YUV,
  425. },
  426. {
  427. .code = V4L2_MBUS_FMT_UYVY8_2X8,
  428. .colorspace = V4L2_COLORSPACE_JPEG,
  429. .dsp3 = 0x0,
  430. .com3 = 0x0,
  431. .com7 = OFMT_YUV,
  432. },
  433. {
  434. .code = V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE,
  435. .colorspace = V4L2_COLORSPACE_SRGB,
  436. .dsp3 = 0x0,
  437. .com3 = SWAP_RGB,
  438. .com7 = FMT_RGB555 | OFMT_RGB,
  439. },
  440. {
  441. .code = V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE,
  442. .colorspace = V4L2_COLORSPACE_SRGB,
  443. .dsp3 = 0x0,
  444. .com3 = 0x0,
  445. .com7 = FMT_RGB555 | OFMT_RGB,
  446. },
  447. {
  448. .code = V4L2_MBUS_FMT_RGB565_2X8_LE,
  449. .colorspace = V4L2_COLORSPACE_SRGB,
  450. .dsp3 = 0x0,
  451. .com3 = SWAP_RGB,
  452. .com7 = FMT_RGB565 | OFMT_RGB,
  453. },
  454. {
  455. .code = V4L2_MBUS_FMT_RGB565_2X8_BE,
  456. .colorspace = V4L2_COLORSPACE_SRGB,
  457. .dsp3 = 0x0,
  458. .com3 = 0x0,
  459. .com7 = FMT_RGB565 | OFMT_RGB,
  460. },
  461. };
  462. /*
  463. * window size list
  464. */
  465. #define VGA_WIDTH 640
  466. #define VGA_HEIGHT 480
  467. #define QVGA_WIDTH 320
  468. #define QVGA_HEIGHT 240
  469. #define MAX_WIDTH VGA_WIDTH
  470. #define MAX_HEIGHT VGA_HEIGHT
  471. static const struct ov772x_win_size ov772x_win_sizes[] = {
  472. {
  473. .name = "VGA",
  474. .width = VGA_WIDTH,
  475. .height = VGA_HEIGHT,
  476. .com7_bit = SLCT_VGA,
  477. .regs = ov772x_vga_regs,
  478. }, {
  479. .name = "QVGA",
  480. .width = QVGA_WIDTH,
  481. .height = QVGA_HEIGHT,
  482. .com7_bit = SLCT_QVGA,
  483. .regs = ov772x_qvga_regs,
  484. },
  485. };
  486. /*
  487. * general function
  488. */
  489. static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd)
  490. {
  491. return container_of(sd, struct ov772x_priv, subdev);
  492. }
  493. static int ov772x_write_array(struct i2c_client *client,
  494. const struct regval_list *vals)
  495. {
  496. while (vals->reg_num != 0xff) {
  497. int ret = i2c_smbus_write_byte_data(client,
  498. vals->reg_num,
  499. vals->value);
  500. if (ret < 0)
  501. return ret;
  502. vals++;
  503. }
  504. return 0;
  505. }
  506. static int ov772x_mask_set(struct i2c_client *client,
  507. u8 command,
  508. u8 mask,
  509. u8 set)
  510. {
  511. s32 val = i2c_smbus_read_byte_data(client, command);
  512. if (val < 0)
  513. return val;
  514. val &= ~mask;
  515. val |= set & mask;
  516. return i2c_smbus_write_byte_data(client, command, val);
  517. }
  518. static int ov772x_reset(struct i2c_client *client)
  519. {
  520. int ret = i2c_smbus_write_byte_data(client, COM7, SCCB_RESET);
  521. msleep(1);
  522. return ret;
  523. }
  524. /*
  525. * soc_camera_ops function
  526. */
  527. static int ov772x_s_stream(struct v4l2_subdev *sd, int enable)
  528. {
  529. struct i2c_client *client = v4l2_get_subdevdata(sd);
  530. struct ov772x_priv *priv = to_ov772x(sd);
  531. if (!enable) {
  532. ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
  533. return 0;
  534. }
  535. ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, 0);
  536. dev_dbg(&client->dev, "format %d, win %s\n",
  537. priv->cfmt->code, priv->win->name);
  538. return 0;
  539. }
  540. static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
  541. {
  542. struct ov772x_priv *priv = container_of(ctrl->handler,
  543. struct ov772x_priv, hdl);
  544. struct v4l2_subdev *sd = &priv->subdev;
  545. struct i2c_client *client = v4l2_get_subdevdata(sd);
  546. int ret = 0;
  547. u8 val;
  548. switch (ctrl->id) {
  549. case V4L2_CID_VFLIP:
  550. val = ctrl->val ? VFLIP_IMG : 0x00;
  551. priv->flag_vflip = ctrl->val;
  552. if (priv->info->flags & OV772X_FLAG_VFLIP)
  553. val ^= VFLIP_IMG;
  554. return ov772x_mask_set(client, COM3, VFLIP_IMG, val);
  555. case V4L2_CID_HFLIP:
  556. val = ctrl->val ? HFLIP_IMG : 0x00;
  557. priv->flag_hflip = ctrl->val;
  558. if (priv->info->flags & OV772X_FLAG_HFLIP)
  559. val ^= HFLIP_IMG;
  560. return ov772x_mask_set(client, COM3, HFLIP_IMG, val);
  561. case V4L2_CID_BAND_STOP_FILTER:
  562. if (!ctrl->val) {
  563. /* Switch the filter off, it is on now */
  564. ret = ov772x_mask_set(client, BDBASE, 0xff, 0xff);
  565. if (!ret)
  566. ret = ov772x_mask_set(client, COM8,
  567. BNDF_ON_OFF, 0);
  568. } else {
  569. /* Switch the filter on, set AEC low limit */
  570. val = 256 - ctrl->val;
  571. ret = ov772x_mask_set(client, COM8,
  572. BNDF_ON_OFF, BNDF_ON_OFF);
  573. if (!ret)
  574. ret = ov772x_mask_set(client, BDBASE,
  575. 0xff, val);
  576. }
  577. if (!ret)
  578. priv->band_filter = ctrl->val;
  579. return ret;
  580. }
  581. return -EINVAL;
  582. }
  583. static int ov772x_g_chip_ident(struct v4l2_subdev *sd,
  584. struct v4l2_dbg_chip_ident *id)
  585. {
  586. struct ov772x_priv *priv = to_ov772x(sd);
  587. id->ident = priv->model;
  588. id->revision = 0;
  589. return 0;
  590. }
  591. #ifdef CONFIG_VIDEO_ADV_DEBUG
  592. static int ov772x_g_register(struct v4l2_subdev *sd,
  593. struct v4l2_dbg_register *reg)
  594. {
  595. struct i2c_client *client = v4l2_get_subdevdata(sd);
  596. int ret;
  597. reg->size = 1;
  598. if (reg->reg > 0xff)
  599. return -EINVAL;
  600. ret = i2c_smbus_read_byte_data(client, reg->reg);
  601. if (ret < 0)
  602. return ret;
  603. reg->val = (__u64)ret;
  604. return 0;
  605. }
  606. static int ov772x_s_register(struct v4l2_subdev *sd,
  607. struct v4l2_dbg_register *reg)
  608. {
  609. struct i2c_client *client = v4l2_get_subdevdata(sd);
  610. if (reg->reg > 0xff ||
  611. reg->val > 0xff)
  612. return -EINVAL;
  613. return i2c_smbus_write_byte_data(client, reg->reg, reg->val);
  614. }
  615. #endif
  616. static int ov772x_s_power(struct v4l2_subdev *sd, int on)
  617. {
  618. struct i2c_client *client = v4l2_get_subdevdata(sd);
  619. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  620. return soc_camera_set_power(&client->dev, icl, on);
  621. }
  622. static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
  623. {
  624. const struct ov772x_win_size *win = &ov772x_win_sizes[0];
  625. u32 best_diff = UINT_MAX;
  626. unsigned int i;
  627. for (i = 0; i < ARRAY_SIZE(ov772x_win_sizes); ++i) {
  628. u32 diff = abs(width - ov772x_win_sizes[i].width)
  629. + abs(height - ov772x_win_sizes[i].height);
  630. if (diff < best_diff) {
  631. best_diff = diff;
  632. win = &ov772x_win_sizes[i];
  633. }
  634. }
  635. return win;
  636. }
  637. static void ov772x_select_params(const struct v4l2_mbus_framefmt *mf,
  638. const struct ov772x_color_format **cfmt,
  639. const struct ov772x_win_size **win)
  640. {
  641. unsigned int i;
  642. /* Select a format. */
  643. *cfmt = &ov772x_cfmts[0];
  644. for (i = 0; i < ARRAY_SIZE(ov772x_cfmts); i++) {
  645. if (mf->code == ov772x_cfmts[i].code) {
  646. *cfmt = &ov772x_cfmts[i];
  647. break;
  648. }
  649. }
  650. /* Select a window size. */
  651. *win = ov772x_select_win(mf->width, mf->height);
  652. }
  653. static int ov772x_set_params(struct ov772x_priv *priv,
  654. const struct ov772x_color_format *cfmt,
  655. const struct ov772x_win_size *win)
  656. {
  657. struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
  658. int ret;
  659. u8 val;
  660. /*
  661. * reset hardware
  662. */
  663. ov772x_reset(client);
  664. /*
  665. * Edge Ctrl
  666. */
  667. if (priv->info->edgectrl.strength & OV772X_MANUAL_EDGE_CTRL) {
  668. /*
  669. * Manual Edge Control Mode
  670. *
  671. * Edge auto strength bit is set by default.
  672. * Remove it when manual mode.
  673. */
  674. ret = ov772x_mask_set(client, DSPAUTO, EDGE_ACTRL, 0x00);
  675. if (ret < 0)
  676. goto ov772x_set_fmt_error;
  677. ret = ov772x_mask_set(client,
  678. EDGE_TRSHLD, OV772X_EDGE_THRESHOLD_MASK,
  679. priv->info->edgectrl.threshold);
  680. if (ret < 0)
  681. goto ov772x_set_fmt_error;
  682. ret = ov772x_mask_set(client,
  683. EDGE_STRNGT, OV772X_EDGE_STRENGTH_MASK,
  684. priv->info->edgectrl.strength);
  685. if (ret < 0)
  686. goto ov772x_set_fmt_error;
  687. } else if (priv->info->edgectrl.upper > priv->info->edgectrl.lower) {
  688. /*
  689. * Auto Edge Control Mode
  690. *
  691. * set upper and lower limit
  692. */
  693. ret = ov772x_mask_set(client,
  694. EDGE_UPPER, OV772X_EDGE_UPPER_MASK,
  695. priv->info->edgectrl.upper);
  696. if (ret < 0)
  697. goto ov772x_set_fmt_error;
  698. ret = ov772x_mask_set(client,
  699. EDGE_LOWER, OV772X_EDGE_LOWER_MASK,
  700. priv->info->edgectrl.lower);
  701. if (ret < 0)
  702. goto ov772x_set_fmt_error;
  703. }
  704. /*
  705. * set size format
  706. */
  707. ret = ov772x_write_array(client, win->regs);
  708. if (ret < 0)
  709. goto ov772x_set_fmt_error;
  710. /*
  711. * set DSP_CTRL3
  712. */
  713. val = cfmt->dsp3;
  714. if (val) {
  715. ret = ov772x_mask_set(client,
  716. DSP_CTRL3, UV_MASK, val);
  717. if (ret < 0)
  718. goto ov772x_set_fmt_error;
  719. }
  720. /*
  721. * set COM3
  722. */
  723. val = cfmt->com3;
  724. if (priv->info->flags & OV772X_FLAG_VFLIP)
  725. val |= VFLIP_IMG;
  726. if (priv->info->flags & OV772X_FLAG_HFLIP)
  727. val |= HFLIP_IMG;
  728. if (priv->flag_vflip)
  729. val ^= VFLIP_IMG;
  730. if (priv->flag_hflip)
  731. val ^= HFLIP_IMG;
  732. ret = ov772x_mask_set(client,
  733. COM3, SWAP_MASK | IMG_MASK, val);
  734. if (ret < 0)
  735. goto ov772x_set_fmt_error;
  736. /*
  737. * set COM7
  738. */
  739. val = win->com7_bit | cfmt->com7;
  740. ret = ov772x_mask_set(client,
  741. COM7, SLCT_MASK | FMT_MASK | OFMT_MASK,
  742. val);
  743. if (ret < 0)
  744. goto ov772x_set_fmt_error;
  745. /*
  746. * set COM8
  747. */
  748. if (priv->band_filter) {
  749. ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, 1);
  750. if (!ret)
  751. ret = ov772x_mask_set(client, BDBASE,
  752. 0xff, 256 - priv->band_filter);
  753. if (ret < 0)
  754. goto ov772x_set_fmt_error;
  755. }
  756. return ret;
  757. ov772x_set_fmt_error:
  758. ov772x_reset(client);
  759. return ret;
  760. }
  761. static int ov772x_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
  762. {
  763. a->c.left = 0;
  764. a->c.top = 0;
  765. a->c.width = VGA_WIDTH;
  766. a->c.height = VGA_HEIGHT;
  767. a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  768. return 0;
  769. }
  770. static int ov772x_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
  771. {
  772. a->bounds.left = 0;
  773. a->bounds.top = 0;
  774. a->bounds.width = VGA_WIDTH;
  775. a->bounds.height = VGA_HEIGHT;
  776. a->defrect = a->bounds;
  777. a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  778. a->pixelaspect.numerator = 1;
  779. a->pixelaspect.denominator = 1;
  780. return 0;
  781. }
  782. static int ov772x_g_fmt(struct v4l2_subdev *sd,
  783. struct v4l2_mbus_framefmt *mf)
  784. {
  785. struct ov772x_priv *priv = to_ov772x(sd);
  786. mf->width = priv->win->width;
  787. mf->height = priv->win->height;
  788. mf->code = priv->cfmt->code;
  789. mf->colorspace = priv->cfmt->colorspace;
  790. mf->field = V4L2_FIELD_NONE;
  791. return 0;
  792. }
  793. static int ov772x_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
  794. {
  795. struct ov772x_priv *priv = to_ov772x(sd);
  796. const struct ov772x_color_format *cfmt;
  797. const struct ov772x_win_size *win;
  798. int ret;
  799. ov772x_select_params(mf, &cfmt, &win);
  800. ret = ov772x_set_params(priv, cfmt, win);
  801. if (ret < 0)
  802. return ret;
  803. priv->win = win;
  804. priv->cfmt = cfmt;
  805. mf->code = cfmt->code;
  806. mf->width = win->width;
  807. mf->height = win->height;
  808. mf->field = V4L2_FIELD_NONE;
  809. mf->colorspace = cfmt->colorspace;
  810. return 0;
  811. }
  812. static int ov772x_try_fmt(struct v4l2_subdev *sd,
  813. struct v4l2_mbus_framefmt *mf)
  814. {
  815. const struct ov772x_color_format *cfmt;
  816. const struct ov772x_win_size *win;
  817. ov772x_select_params(mf, &cfmt, &win);
  818. mf->code = cfmt->code;
  819. mf->width = win->width;
  820. mf->height = win->height;
  821. mf->field = V4L2_FIELD_NONE;
  822. mf->colorspace = cfmt->colorspace;
  823. return 0;
  824. }
  825. static int ov772x_video_probe(struct ov772x_priv *priv)
  826. {
  827. struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
  828. u8 pid, ver;
  829. const char *devname;
  830. int ret;
  831. ret = ov772x_s_power(&priv->subdev, 1);
  832. if (ret < 0)
  833. return ret;
  834. /*
  835. * check and show product ID and manufacturer ID
  836. */
  837. pid = i2c_smbus_read_byte_data(client, PID);
  838. ver = i2c_smbus_read_byte_data(client, VER);
  839. switch (VERSION(pid, ver)) {
  840. case OV7720:
  841. devname = "ov7720";
  842. priv->model = V4L2_IDENT_OV7720;
  843. break;
  844. case OV7725:
  845. devname = "ov7725";
  846. priv->model = V4L2_IDENT_OV7725;
  847. break;
  848. default:
  849. dev_err(&client->dev,
  850. "Product ID error %x:%x\n", pid, ver);
  851. ret = -ENODEV;
  852. goto done;
  853. }
  854. dev_info(&client->dev,
  855. "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
  856. devname,
  857. pid,
  858. ver,
  859. i2c_smbus_read_byte_data(client, MIDH),
  860. i2c_smbus_read_byte_data(client, MIDL));
  861. ret = v4l2_ctrl_handler_setup(&priv->hdl);
  862. done:
  863. ov772x_s_power(&priv->subdev, 0);
  864. return ret;
  865. }
  866. static const struct v4l2_ctrl_ops ov772x_ctrl_ops = {
  867. .s_ctrl = ov772x_s_ctrl,
  868. };
  869. static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
  870. .g_chip_ident = ov772x_g_chip_ident,
  871. #ifdef CONFIG_VIDEO_ADV_DEBUG
  872. .g_register = ov772x_g_register,
  873. .s_register = ov772x_s_register,
  874. #endif
  875. .s_power = ov772x_s_power,
  876. };
  877. static int ov772x_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
  878. enum v4l2_mbus_pixelcode *code)
  879. {
  880. if (index >= ARRAY_SIZE(ov772x_cfmts))
  881. return -EINVAL;
  882. *code = ov772x_cfmts[index].code;
  883. return 0;
  884. }
  885. static int ov772x_g_mbus_config(struct v4l2_subdev *sd,
  886. struct v4l2_mbus_config *cfg)
  887. {
  888. struct i2c_client *client = v4l2_get_subdevdata(sd);
  889. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  890. cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
  891. V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
  892. V4L2_MBUS_DATA_ACTIVE_HIGH;
  893. cfg->type = V4L2_MBUS_PARALLEL;
  894. cfg->flags = soc_camera_apply_board_flags(icl, cfg);
  895. return 0;
  896. }
  897. static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
  898. .s_stream = ov772x_s_stream,
  899. .g_mbus_fmt = ov772x_g_fmt,
  900. .s_mbus_fmt = ov772x_s_fmt,
  901. .try_mbus_fmt = ov772x_try_fmt,
  902. .cropcap = ov772x_cropcap,
  903. .g_crop = ov772x_g_crop,
  904. .enum_mbus_fmt = ov772x_enum_fmt,
  905. .g_mbus_config = ov772x_g_mbus_config,
  906. };
  907. static struct v4l2_subdev_ops ov772x_subdev_ops = {
  908. .core = &ov772x_subdev_core_ops,
  909. .video = &ov772x_subdev_video_ops,
  910. };
  911. /*
  912. * i2c_driver function
  913. */
  914. static int ov772x_probe(struct i2c_client *client,
  915. const struct i2c_device_id *did)
  916. {
  917. struct ov772x_priv *priv;
  918. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  919. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  920. int ret;
  921. if (!icl || !icl->priv) {
  922. dev_err(&client->dev, "OV772X: missing platform data!\n");
  923. return -EINVAL;
  924. }
  925. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  926. dev_err(&adapter->dev,
  927. "I2C-Adapter doesn't support "
  928. "I2C_FUNC_SMBUS_BYTE_DATA\n");
  929. return -EIO;
  930. }
  931. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  932. if (!priv)
  933. return -ENOMEM;
  934. priv->info = icl->priv;
  935. v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops);
  936. v4l2_ctrl_handler_init(&priv->hdl, 3);
  937. v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
  938. V4L2_CID_VFLIP, 0, 1, 1, 0);
  939. v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
  940. V4L2_CID_HFLIP, 0, 1, 1, 0);
  941. v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
  942. V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0);
  943. priv->subdev.ctrl_handler = &priv->hdl;
  944. if (priv->hdl.error) {
  945. ret = priv->hdl.error;
  946. goto done;
  947. }
  948. ret = ov772x_video_probe(priv);
  949. if (ret < 0)
  950. goto done;
  951. priv->cfmt = &ov772x_cfmts[0];
  952. priv->win = &ov772x_win_sizes[0];
  953. done:
  954. if (ret) {
  955. v4l2_ctrl_handler_free(&priv->hdl);
  956. kfree(priv);
  957. }
  958. return ret;
  959. }
  960. static int ov772x_remove(struct i2c_client *client)
  961. {
  962. struct ov772x_priv *priv = to_ov772x(i2c_get_clientdata(client));
  963. v4l2_device_unregister_subdev(&priv->subdev);
  964. v4l2_ctrl_handler_free(&priv->hdl);
  965. kfree(priv);
  966. return 0;
  967. }
  968. static const struct i2c_device_id ov772x_id[] = {
  969. { "ov772x", 0 },
  970. { }
  971. };
  972. MODULE_DEVICE_TABLE(i2c, ov772x_id);
  973. static struct i2c_driver ov772x_i2c_driver = {
  974. .driver = {
  975. .name = "ov772x",
  976. },
  977. .probe = ov772x_probe,
  978. .remove = ov772x_remove,
  979. .id_table = ov772x_id,
  980. };
  981. module_i2c_driver(ov772x_i2c_driver);
  982. MODULE_DESCRIPTION("SoC Camera driver for ov772x");
  983. MODULE_AUTHOR("Kuninori Morimoto");
  984. MODULE_LICENSE("GPL v2");