ov772x.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  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. #define SENSOR_RAW 0x10 /* Sensor RAW */
  267. /* RGB output format control */
  268. #define FMT_MASK 0x0c /* Mask of color format */
  269. #define FMT_GBR422 0x00 /* 00 : GBR 4:2:2 */
  270. #define FMT_RGB565 0x04 /* 01 : RGB 565 */
  271. #define FMT_RGB555 0x08 /* 10 : RGB 555 */
  272. #define FMT_RGB444 0x0c /* 11 : RGB 444 */
  273. /* Output format control */
  274. #define OFMT_MASK 0x03 /* Mask of output format */
  275. #define OFMT_YUV 0x00 /* 00 : YUV */
  276. #define OFMT_P_BRAW 0x01 /* 01 : Processed Bayer RAW */
  277. #define OFMT_RGB 0x02 /* 10 : RGB */
  278. #define OFMT_BRAW 0x03 /* 11 : Bayer RAW */
  279. /* COM8 */
  280. #define FAST_ALGO 0x80 /* Enable fast AGC/AEC algorithm */
  281. /* AEC Setp size limit */
  282. #define UNLMT_STEP 0x40 /* 0 : Step size is limited */
  283. /* 1 : Unlimited step size */
  284. #define BNDF_ON_OFF 0x20 /* Banding filter ON/OFF */
  285. #define AEC_BND 0x10 /* Enable AEC below banding value */
  286. #define AEC_ON_OFF 0x08 /* Fine AEC ON/OFF control */
  287. #define AGC_ON 0x04 /* AGC Enable */
  288. #define AWB_ON 0x02 /* AWB Enable */
  289. #define AEC_ON 0x01 /* AEC Enable */
  290. /* COM9 */
  291. #define BASE_AECAGC 0x80 /* Histogram or average based AEC/AGC */
  292. /* Automatic gain ceiling - maximum AGC value */
  293. #define GAIN_2x 0x00 /* 000 : 2x */
  294. #define GAIN_4x 0x10 /* 001 : 4x */
  295. #define GAIN_8x 0x20 /* 010 : 8x */
  296. #define GAIN_16x 0x30 /* 011 : 16x */
  297. #define GAIN_32x 0x40 /* 100 : 32x */
  298. #define GAIN_64x 0x50 /* 101 : 64x */
  299. #define GAIN_128x 0x60 /* 110 : 128x */
  300. #define DROP_VSYNC 0x04 /* Drop VSYNC output of corrupt frame */
  301. #define DROP_HREF 0x02 /* Drop HREF output of corrupt frame */
  302. /* COM11 */
  303. #define SGLF_ON_OFF 0x02 /* Single frame ON/OFF selection */
  304. #define SGLF_TRIG 0x01 /* Single frame transfer trigger */
  305. /* EXHCH */
  306. #define VSIZE_LSB 0x04 /* Vertical data output size LSB */
  307. /* DSP_CTRL1 */
  308. #define FIFO_ON 0x80 /* FIFO enable/disable selection */
  309. #define UV_ON_OFF 0x40 /* UV adjust function ON/OFF selection */
  310. #define YUV444_2_422 0x20 /* YUV444 to 422 UV channel option selection */
  311. #define CLR_MTRX_ON_OFF 0x10 /* Color matrix ON/OFF selection */
  312. #define INTPLT_ON_OFF 0x08 /* Interpolation ON/OFF selection */
  313. #define GMM_ON_OFF 0x04 /* Gamma function ON/OFF selection */
  314. #define AUTO_BLK_ON_OFF 0x02 /* Black defect auto correction ON/OFF */
  315. #define AUTO_WHT_ON_OFF 0x01 /* White define auto correction ON/OFF */
  316. /* DSP_CTRL3 */
  317. #define UV_MASK 0x80 /* UV output sequence option */
  318. #define UV_ON 0x80 /* ON */
  319. #define UV_OFF 0x00 /* OFF */
  320. #define CBAR_MASK 0x20 /* DSP Color bar mask */
  321. #define CBAR_ON 0x20 /* ON */
  322. #define CBAR_OFF 0x00 /* OFF */
  323. /* DSP_CTRL4 */
  324. #define DSP_OFMT_YUV 0x00
  325. #define DSP_OFMT_RGB 0x00
  326. #define DSP_OFMT_RAW8 0x02
  327. #define DSP_OFMT_RAW10 0x03
  328. /* HSTART */
  329. #define HST_VGA 0x23
  330. #define HST_QVGA 0x3F
  331. /* HSIZE */
  332. #define HSZ_VGA 0xA0
  333. #define HSZ_QVGA 0x50
  334. /* VSTART */
  335. #define VST_VGA 0x07
  336. #define VST_QVGA 0x03
  337. /* VSIZE */
  338. #define VSZ_VGA 0xF0
  339. #define VSZ_QVGA 0x78
  340. /* HOUTSIZE */
  341. #define HOSZ_VGA 0xA0
  342. #define HOSZ_QVGA 0x50
  343. /* VOUTSIZE */
  344. #define VOSZ_VGA 0xF0
  345. #define VOSZ_QVGA 0x78
  346. /* DSPAUTO (DSP Auto Function ON/OFF Control) */
  347. #define AWB_ACTRL 0x80 /* AWB auto threshold control */
  348. #define DENOISE_ACTRL 0x40 /* De-noise auto threshold control */
  349. #define EDGE_ACTRL 0x20 /* Edge enhancement auto strength control */
  350. #define UV_ACTRL 0x10 /* UV adjust auto slope control */
  351. #define SCAL0_ACTRL 0x08 /* Auto scaling factor control */
  352. #define SCAL1_2_ACTRL 0x04 /* Auto scaling factor control */
  353. /*
  354. * ID
  355. */
  356. #define OV7720 0x7720
  357. #define OV7725 0x7721
  358. #define VERSION(pid, ver) ((pid<<8)|(ver&0xFF))
  359. /*
  360. * struct
  361. */
  362. struct regval_list {
  363. unsigned char reg_num;
  364. unsigned char value;
  365. };
  366. struct ov772x_color_format {
  367. enum v4l2_mbus_pixelcode code;
  368. enum v4l2_colorspace colorspace;
  369. u8 dsp3;
  370. u8 dsp4;
  371. u8 com3;
  372. u8 com7;
  373. };
  374. struct ov772x_win_size {
  375. char *name;
  376. __u32 width;
  377. __u32 height;
  378. unsigned char com7_bit;
  379. const struct regval_list *regs;
  380. };
  381. struct ov772x_priv {
  382. struct v4l2_subdev subdev;
  383. struct v4l2_ctrl_handler hdl;
  384. struct ov772x_camera_info *info;
  385. const struct ov772x_color_format *cfmt;
  386. const struct ov772x_win_size *win;
  387. int model;
  388. unsigned short flag_vflip:1;
  389. unsigned short flag_hflip:1;
  390. /* band_filter = COM8[5] ? 256 - BDBASE : 0 */
  391. unsigned short band_filter;
  392. };
  393. #define ENDMARKER { 0xff, 0xff }
  394. /*
  395. * register setting for window size
  396. */
  397. static const struct regval_list ov772x_qvga_regs[] = {
  398. { HSTART, HST_QVGA },
  399. { HSIZE, HSZ_QVGA },
  400. { VSTART, VST_QVGA },
  401. { VSIZE, VSZ_QVGA },
  402. { HOUTSIZE, HOSZ_QVGA },
  403. { VOUTSIZE, VOSZ_QVGA },
  404. ENDMARKER,
  405. };
  406. static const struct regval_list ov772x_vga_regs[] = {
  407. { HSTART, HST_VGA },
  408. { HSIZE, HSZ_VGA },
  409. { VSTART, VST_VGA },
  410. { VSIZE, VSZ_VGA },
  411. { HOUTSIZE, HOSZ_VGA },
  412. { VOUTSIZE, VOSZ_VGA },
  413. ENDMARKER,
  414. };
  415. /*
  416. * supported color format list
  417. */
  418. static const struct ov772x_color_format ov772x_cfmts[] = {
  419. {
  420. .code = V4L2_MBUS_FMT_YUYV8_2X8,
  421. .colorspace = V4L2_COLORSPACE_JPEG,
  422. .dsp3 = 0x0,
  423. .dsp4 = DSP_OFMT_YUV,
  424. .com3 = SWAP_YUV,
  425. .com7 = OFMT_YUV,
  426. },
  427. {
  428. .code = V4L2_MBUS_FMT_YVYU8_2X8,
  429. .colorspace = V4L2_COLORSPACE_JPEG,
  430. .dsp3 = UV_ON,
  431. .dsp4 = DSP_OFMT_YUV,
  432. .com3 = SWAP_YUV,
  433. .com7 = OFMT_YUV,
  434. },
  435. {
  436. .code = V4L2_MBUS_FMT_UYVY8_2X8,
  437. .colorspace = V4L2_COLORSPACE_JPEG,
  438. .dsp3 = 0x0,
  439. .dsp4 = DSP_OFMT_YUV,
  440. .com3 = 0x0,
  441. .com7 = OFMT_YUV,
  442. },
  443. {
  444. .code = V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE,
  445. .colorspace = V4L2_COLORSPACE_SRGB,
  446. .dsp3 = 0x0,
  447. .dsp4 = DSP_OFMT_YUV,
  448. .com3 = SWAP_RGB,
  449. .com7 = FMT_RGB555 | OFMT_RGB,
  450. },
  451. {
  452. .code = V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE,
  453. .colorspace = V4L2_COLORSPACE_SRGB,
  454. .dsp3 = 0x0,
  455. .dsp4 = DSP_OFMT_YUV,
  456. .com3 = 0x0,
  457. .com7 = FMT_RGB555 | OFMT_RGB,
  458. },
  459. {
  460. .code = V4L2_MBUS_FMT_RGB565_2X8_LE,
  461. .colorspace = V4L2_COLORSPACE_SRGB,
  462. .dsp3 = 0x0,
  463. .dsp4 = DSP_OFMT_YUV,
  464. .com3 = SWAP_RGB,
  465. .com7 = FMT_RGB565 | OFMT_RGB,
  466. },
  467. {
  468. .code = V4L2_MBUS_FMT_RGB565_2X8_BE,
  469. .colorspace = V4L2_COLORSPACE_SRGB,
  470. .dsp3 = 0x0,
  471. .dsp4 = DSP_OFMT_YUV,
  472. .com3 = 0x0,
  473. .com7 = FMT_RGB565 | OFMT_RGB,
  474. },
  475. {
  476. /* Setting DSP4 to DSP_OFMT_RAW8 still gives 10-bit output,
  477. * regardless of the COM7 value. We can thus only support 10-bit
  478. * Bayer until someone figures it out.
  479. */
  480. .code = V4L2_MBUS_FMT_SBGGR10_1X10,
  481. .colorspace = V4L2_COLORSPACE_SRGB,
  482. .dsp3 = 0x0,
  483. .dsp4 = DSP_OFMT_RAW10,
  484. .com3 = 0x0,
  485. .com7 = SENSOR_RAW | OFMT_BRAW,
  486. },
  487. };
  488. /*
  489. * window size list
  490. */
  491. #define VGA_WIDTH 640
  492. #define VGA_HEIGHT 480
  493. #define QVGA_WIDTH 320
  494. #define QVGA_HEIGHT 240
  495. #define MAX_WIDTH VGA_WIDTH
  496. #define MAX_HEIGHT VGA_HEIGHT
  497. static const struct ov772x_win_size ov772x_win_sizes[] = {
  498. {
  499. .name = "VGA",
  500. .width = VGA_WIDTH,
  501. .height = VGA_HEIGHT,
  502. .com7_bit = SLCT_VGA,
  503. .regs = ov772x_vga_regs,
  504. }, {
  505. .name = "QVGA",
  506. .width = QVGA_WIDTH,
  507. .height = QVGA_HEIGHT,
  508. .com7_bit = SLCT_QVGA,
  509. .regs = ov772x_qvga_regs,
  510. },
  511. };
  512. /*
  513. * general function
  514. */
  515. static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd)
  516. {
  517. return container_of(sd, struct ov772x_priv, subdev);
  518. }
  519. static inline int ov772x_read(struct i2c_client *client, u8 addr)
  520. {
  521. return i2c_smbus_read_byte_data(client, addr);
  522. }
  523. static inline int ov772x_write(struct i2c_client *client, u8 addr, u8 value)
  524. {
  525. return i2c_smbus_write_byte_data(client, addr, value);
  526. }
  527. static int ov772x_write_array(struct i2c_client *client,
  528. const struct regval_list *vals)
  529. {
  530. while (vals->reg_num != 0xff) {
  531. int ret = ov772x_write(client, vals->reg_num, vals->value);
  532. if (ret < 0)
  533. return ret;
  534. vals++;
  535. }
  536. return 0;
  537. }
  538. static int ov772x_mask_set(struct i2c_client *client, u8 command, u8 mask,
  539. u8 set)
  540. {
  541. s32 val = ov772x_read(client, command);
  542. if (val < 0)
  543. return val;
  544. val &= ~mask;
  545. val |= set & mask;
  546. return ov772x_write(client, command, val);
  547. }
  548. static int ov772x_reset(struct i2c_client *client)
  549. {
  550. int ret = ov772x_write(client, COM7, SCCB_RESET);
  551. msleep(1);
  552. return ret;
  553. }
  554. /*
  555. * soc_camera_ops function
  556. */
  557. static int ov772x_s_stream(struct v4l2_subdev *sd, int enable)
  558. {
  559. struct i2c_client *client = v4l2_get_subdevdata(sd);
  560. struct ov772x_priv *priv = to_ov772x(sd);
  561. if (!enable) {
  562. ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
  563. return 0;
  564. }
  565. ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, 0);
  566. dev_dbg(&client->dev, "format %d, win %s\n",
  567. priv->cfmt->code, priv->win->name);
  568. return 0;
  569. }
  570. static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
  571. {
  572. struct ov772x_priv *priv = container_of(ctrl->handler,
  573. struct ov772x_priv, hdl);
  574. struct v4l2_subdev *sd = &priv->subdev;
  575. struct i2c_client *client = v4l2_get_subdevdata(sd);
  576. int ret = 0;
  577. u8 val;
  578. switch (ctrl->id) {
  579. case V4L2_CID_VFLIP:
  580. val = ctrl->val ? VFLIP_IMG : 0x00;
  581. priv->flag_vflip = ctrl->val;
  582. if (priv->info->flags & OV772X_FLAG_VFLIP)
  583. val ^= VFLIP_IMG;
  584. return ov772x_mask_set(client, COM3, VFLIP_IMG, val);
  585. case V4L2_CID_HFLIP:
  586. val = ctrl->val ? HFLIP_IMG : 0x00;
  587. priv->flag_hflip = ctrl->val;
  588. if (priv->info->flags & OV772X_FLAG_HFLIP)
  589. val ^= HFLIP_IMG;
  590. return ov772x_mask_set(client, COM3, HFLIP_IMG, val);
  591. case V4L2_CID_BAND_STOP_FILTER:
  592. if (!ctrl->val) {
  593. /* Switch the filter off, it is on now */
  594. ret = ov772x_mask_set(client, BDBASE, 0xff, 0xff);
  595. if (!ret)
  596. ret = ov772x_mask_set(client, COM8,
  597. BNDF_ON_OFF, 0);
  598. } else {
  599. /* Switch the filter on, set AEC low limit */
  600. val = 256 - ctrl->val;
  601. ret = ov772x_mask_set(client, COM8,
  602. BNDF_ON_OFF, BNDF_ON_OFF);
  603. if (!ret)
  604. ret = ov772x_mask_set(client, BDBASE,
  605. 0xff, val);
  606. }
  607. if (!ret)
  608. priv->band_filter = ctrl->val;
  609. return ret;
  610. }
  611. return -EINVAL;
  612. }
  613. static int ov772x_g_chip_ident(struct v4l2_subdev *sd,
  614. struct v4l2_dbg_chip_ident *id)
  615. {
  616. struct ov772x_priv *priv = to_ov772x(sd);
  617. id->ident = priv->model;
  618. id->revision = 0;
  619. return 0;
  620. }
  621. #ifdef CONFIG_VIDEO_ADV_DEBUG
  622. static int ov772x_g_register(struct v4l2_subdev *sd,
  623. struct v4l2_dbg_register *reg)
  624. {
  625. struct i2c_client *client = v4l2_get_subdevdata(sd);
  626. int ret;
  627. reg->size = 1;
  628. if (reg->reg > 0xff)
  629. return -EINVAL;
  630. ret = ov772x_read(client, reg->reg);
  631. if (ret < 0)
  632. return ret;
  633. reg->val = (__u64)ret;
  634. return 0;
  635. }
  636. static int ov772x_s_register(struct v4l2_subdev *sd,
  637. struct v4l2_dbg_register *reg)
  638. {
  639. struct i2c_client *client = v4l2_get_subdevdata(sd);
  640. if (reg->reg > 0xff ||
  641. reg->val > 0xff)
  642. return -EINVAL;
  643. return ov772x_write(client, reg->reg, reg->val);
  644. }
  645. #endif
  646. static int ov772x_s_power(struct v4l2_subdev *sd, int on)
  647. {
  648. struct i2c_client *client = v4l2_get_subdevdata(sd);
  649. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  650. return soc_camera_set_power(&client->dev, icl, on);
  651. }
  652. static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
  653. {
  654. const struct ov772x_win_size *win = &ov772x_win_sizes[0];
  655. u32 best_diff = UINT_MAX;
  656. unsigned int i;
  657. for (i = 0; i < ARRAY_SIZE(ov772x_win_sizes); ++i) {
  658. u32 diff = abs(width - ov772x_win_sizes[i].width)
  659. + abs(height - ov772x_win_sizes[i].height);
  660. if (diff < best_diff) {
  661. best_diff = diff;
  662. win = &ov772x_win_sizes[i];
  663. }
  664. }
  665. return win;
  666. }
  667. static void ov772x_select_params(const struct v4l2_mbus_framefmt *mf,
  668. const struct ov772x_color_format **cfmt,
  669. const struct ov772x_win_size **win)
  670. {
  671. unsigned int i;
  672. /* Select a format. */
  673. *cfmt = &ov772x_cfmts[0];
  674. for (i = 0; i < ARRAY_SIZE(ov772x_cfmts); i++) {
  675. if (mf->code == ov772x_cfmts[i].code) {
  676. *cfmt = &ov772x_cfmts[i];
  677. break;
  678. }
  679. }
  680. /* Select a window size. */
  681. *win = ov772x_select_win(mf->width, mf->height);
  682. }
  683. static int ov772x_set_params(struct ov772x_priv *priv,
  684. const struct ov772x_color_format *cfmt,
  685. const struct ov772x_win_size *win)
  686. {
  687. struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
  688. int ret;
  689. u8 val;
  690. /*
  691. * reset hardware
  692. */
  693. ov772x_reset(client);
  694. /*
  695. * Edge Ctrl
  696. */
  697. if (priv->info->edgectrl.strength & OV772X_MANUAL_EDGE_CTRL) {
  698. /*
  699. * Manual Edge Control Mode
  700. *
  701. * Edge auto strength bit is set by default.
  702. * Remove it when manual mode.
  703. */
  704. ret = ov772x_mask_set(client, DSPAUTO, EDGE_ACTRL, 0x00);
  705. if (ret < 0)
  706. goto ov772x_set_fmt_error;
  707. ret = ov772x_mask_set(client,
  708. EDGE_TRSHLD, OV772X_EDGE_THRESHOLD_MASK,
  709. priv->info->edgectrl.threshold);
  710. if (ret < 0)
  711. goto ov772x_set_fmt_error;
  712. ret = ov772x_mask_set(client,
  713. EDGE_STRNGT, OV772X_EDGE_STRENGTH_MASK,
  714. priv->info->edgectrl.strength);
  715. if (ret < 0)
  716. goto ov772x_set_fmt_error;
  717. } else if (priv->info->edgectrl.upper > priv->info->edgectrl.lower) {
  718. /*
  719. * Auto Edge Control Mode
  720. *
  721. * set upper and lower limit
  722. */
  723. ret = ov772x_mask_set(client,
  724. EDGE_UPPER, OV772X_EDGE_UPPER_MASK,
  725. priv->info->edgectrl.upper);
  726. if (ret < 0)
  727. goto ov772x_set_fmt_error;
  728. ret = ov772x_mask_set(client,
  729. EDGE_LOWER, OV772X_EDGE_LOWER_MASK,
  730. priv->info->edgectrl.lower);
  731. if (ret < 0)
  732. goto ov772x_set_fmt_error;
  733. }
  734. /*
  735. * set size format
  736. */
  737. ret = ov772x_write_array(client, win->regs);
  738. if (ret < 0)
  739. goto ov772x_set_fmt_error;
  740. /*
  741. * set DSP_CTRL3
  742. */
  743. val = cfmt->dsp3;
  744. if (val) {
  745. ret = ov772x_mask_set(client,
  746. DSP_CTRL3, UV_MASK, val);
  747. if (ret < 0)
  748. goto ov772x_set_fmt_error;
  749. }
  750. /* DSP_CTRL4: AEC reference point and DSP output format. */
  751. if (cfmt->dsp4) {
  752. ret = ov772x_write(client, DSP_CTRL4, cfmt->dsp4);
  753. if (ret < 0)
  754. goto ov772x_set_fmt_error;
  755. }
  756. /*
  757. * set COM3
  758. */
  759. val = cfmt->com3;
  760. if (priv->info->flags & OV772X_FLAG_VFLIP)
  761. val |= VFLIP_IMG;
  762. if (priv->info->flags & OV772X_FLAG_HFLIP)
  763. val |= HFLIP_IMG;
  764. if (priv->flag_vflip)
  765. val ^= VFLIP_IMG;
  766. if (priv->flag_hflip)
  767. val ^= HFLIP_IMG;
  768. ret = ov772x_mask_set(client,
  769. COM3, SWAP_MASK | IMG_MASK, val);
  770. if (ret < 0)
  771. goto ov772x_set_fmt_error;
  772. /* COM7: Sensor resolution and output format control. */
  773. ret = ov772x_write(client, COM7, win->com7_bit | cfmt->com7);
  774. if (ret < 0)
  775. goto ov772x_set_fmt_error;
  776. /*
  777. * set COM8
  778. */
  779. if (priv->band_filter) {
  780. ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, 1);
  781. if (!ret)
  782. ret = ov772x_mask_set(client, BDBASE,
  783. 0xff, 256 - priv->band_filter);
  784. if (ret < 0)
  785. goto ov772x_set_fmt_error;
  786. }
  787. return ret;
  788. ov772x_set_fmt_error:
  789. ov772x_reset(client);
  790. return ret;
  791. }
  792. static int ov772x_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
  793. {
  794. a->c.left = 0;
  795. a->c.top = 0;
  796. a->c.width = VGA_WIDTH;
  797. a->c.height = VGA_HEIGHT;
  798. a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  799. return 0;
  800. }
  801. static int ov772x_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
  802. {
  803. a->bounds.left = 0;
  804. a->bounds.top = 0;
  805. a->bounds.width = VGA_WIDTH;
  806. a->bounds.height = VGA_HEIGHT;
  807. a->defrect = a->bounds;
  808. a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  809. a->pixelaspect.numerator = 1;
  810. a->pixelaspect.denominator = 1;
  811. return 0;
  812. }
  813. static int ov772x_g_fmt(struct v4l2_subdev *sd,
  814. struct v4l2_mbus_framefmt *mf)
  815. {
  816. struct ov772x_priv *priv = to_ov772x(sd);
  817. mf->width = priv->win->width;
  818. mf->height = priv->win->height;
  819. mf->code = priv->cfmt->code;
  820. mf->colorspace = priv->cfmt->colorspace;
  821. mf->field = V4L2_FIELD_NONE;
  822. return 0;
  823. }
  824. static int ov772x_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
  825. {
  826. struct ov772x_priv *priv = to_ov772x(sd);
  827. const struct ov772x_color_format *cfmt;
  828. const struct ov772x_win_size *win;
  829. int ret;
  830. ov772x_select_params(mf, &cfmt, &win);
  831. ret = ov772x_set_params(priv, cfmt, win);
  832. if (ret < 0)
  833. return ret;
  834. priv->win = win;
  835. priv->cfmt = cfmt;
  836. mf->code = cfmt->code;
  837. mf->width = win->width;
  838. mf->height = win->height;
  839. mf->field = V4L2_FIELD_NONE;
  840. mf->colorspace = cfmt->colorspace;
  841. return 0;
  842. }
  843. static int ov772x_try_fmt(struct v4l2_subdev *sd,
  844. struct v4l2_mbus_framefmt *mf)
  845. {
  846. const struct ov772x_color_format *cfmt;
  847. const struct ov772x_win_size *win;
  848. ov772x_select_params(mf, &cfmt, &win);
  849. mf->code = cfmt->code;
  850. mf->width = win->width;
  851. mf->height = win->height;
  852. mf->field = V4L2_FIELD_NONE;
  853. mf->colorspace = cfmt->colorspace;
  854. return 0;
  855. }
  856. static int ov772x_video_probe(struct ov772x_priv *priv)
  857. {
  858. struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
  859. u8 pid, ver;
  860. const char *devname;
  861. int ret;
  862. ret = ov772x_s_power(&priv->subdev, 1);
  863. if (ret < 0)
  864. return ret;
  865. /*
  866. * check and show product ID and manufacturer ID
  867. */
  868. pid = ov772x_read(client, PID);
  869. ver = ov772x_read(client, VER);
  870. switch (VERSION(pid, ver)) {
  871. case OV7720:
  872. devname = "ov7720";
  873. priv->model = V4L2_IDENT_OV7720;
  874. break;
  875. case OV7725:
  876. devname = "ov7725";
  877. priv->model = V4L2_IDENT_OV7725;
  878. break;
  879. default:
  880. dev_err(&client->dev,
  881. "Product ID error %x:%x\n", pid, ver);
  882. ret = -ENODEV;
  883. goto done;
  884. }
  885. dev_info(&client->dev,
  886. "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
  887. devname,
  888. pid,
  889. ver,
  890. ov772x_read(client, MIDH),
  891. ov772x_read(client, MIDL));
  892. ret = v4l2_ctrl_handler_setup(&priv->hdl);
  893. done:
  894. ov772x_s_power(&priv->subdev, 0);
  895. return ret;
  896. }
  897. static const struct v4l2_ctrl_ops ov772x_ctrl_ops = {
  898. .s_ctrl = ov772x_s_ctrl,
  899. };
  900. static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
  901. .g_chip_ident = ov772x_g_chip_ident,
  902. #ifdef CONFIG_VIDEO_ADV_DEBUG
  903. .g_register = ov772x_g_register,
  904. .s_register = ov772x_s_register,
  905. #endif
  906. .s_power = ov772x_s_power,
  907. };
  908. static int ov772x_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
  909. enum v4l2_mbus_pixelcode *code)
  910. {
  911. if (index >= ARRAY_SIZE(ov772x_cfmts))
  912. return -EINVAL;
  913. *code = ov772x_cfmts[index].code;
  914. return 0;
  915. }
  916. static int ov772x_g_mbus_config(struct v4l2_subdev *sd,
  917. struct v4l2_mbus_config *cfg)
  918. {
  919. struct i2c_client *client = v4l2_get_subdevdata(sd);
  920. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  921. cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
  922. V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
  923. V4L2_MBUS_DATA_ACTIVE_HIGH;
  924. cfg->type = V4L2_MBUS_PARALLEL;
  925. cfg->flags = soc_camera_apply_board_flags(icl, cfg);
  926. return 0;
  927. }
  928. static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
  929. .s_stream = ov772x_s_stream,
  930. .g_mbus_fmt = ov772x_g_fmt,
  931. .s_mbus_fmt = ov772x_s_fmt,
  932. .try_mbus_fmt = ov772x_try_fmt,
  933. .cropcap = ov772x_cropcap,
  934. .g_crop = ov772x_g_crop,
  935. .enum_mbus_fmt = ov772x_enum_fmt,
  936. .g_mbus_config = ov772x_g_mbus_config,
  937. };
  938. static struct v4l2_subdev_ops ov772x_subdev_ops = {
  939. .core = &ov772x_subdev_core_ops,
  940. .video = &ov772x_subdev_video_ops,
  941. };
  942. /*
  943. * i2c_driver function
  944. */
  945. static int ov772x_probe(struct i2c_client *client,
  946. const struct i2c_device_id *did)
  947. {
  948. struct ov772x_priv *priv;
  949. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  950. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  951. int ret;
  952. if (!icl || !icl->priv) {
  953. dev_err(&client->dev, "OV772X: missing platform data!\n");
  954. return -EINVAL;
  955. }
  956. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  957. dev_err(&adapter->dev,
  958. "I2C-Adapter doesn't support "
  959. "I2C_FUNC_SMBUS_BYTE_DATA\n");
  960. return -EIO;
  961. }
  962. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  963. if (!priv)
  964. return -ENOMEM;
  965. priv->info = icl->priv;
  966. v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops);
  967. v4l2_ctrl_handler_init(&priv->hdl, 3);
  968. v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
  969. V4L2_CID_VFLIP, 0, 1, 1, 0);
  970. v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
  971. V4L2_CID_HFLIP, 0, 1, 1, 0);
  972. v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
  973. V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0);
  974. priv->subdev.ctrl_handler = &priv->hdl;
  975. if (priv->hdl.error) {
  976. ret = priv->hdl.error;
  977. goto done;
  978. }
  979. ret = ov772x_video_probe(priv);
  980. if (ret < 0)
  981. goto done;
  982. priv->cfmt = &ov772x_cfmts[0];
  983. priv->win = &ov772x_win_sizes[0];
  984. done:
  985. if (ret) {
  986. v4l2_ctrl_handler_free(&priv->hdl);
  987. kfree(priv);
  988. }
  989. return ret;
  990. }
  991. static int ov772x_remove(struct i2c_client *client)
  992. {
  993. struct ov772x_priv *priv = to_ov772x(i2c_get_clientdata(client));
  994. v4l2_device_unregister_subdev(&priv->subdev);
  995. v4l2_ctrl_handler_free(&priv->hdl);
  996. kfree(priv);
  997. return 0;
  998. }
  999. static const struct i2c_device_id ov772x_id[] = {
  1000. { "ov772x", 0 },
  1001. { }
  1002. };
  1003. MODULE_DEVICE_TABLE(i2c, ov772x_id);
  1004. static struct i2c_driver ov772x_i2c_driver = {
  1005. .driver = {
  1006. .name = "ov772x",
  1007. },
  1008. .probe = ov772x_probe,
  1009. .remove = ov772x_remove,
  1010. .id_table = ov772x_id,
  1011. };
  1012. module_i2c_driver(ov772x_i2c_driver);
  1013. MODULE_DESCRIPTION("SoC Camera driver for ov772x");
  1014. MODULE_AUTHOR("Kuninori Morimoto");
  1015. MODULE_LICENSE("GPL v2");