ov772x.c 34 KB

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