ov9650.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  1. /*
  2. * Omnivision OV9650/OV9652 CMOS Image Sensor driver
  3. *
  4. * Copyright (C) 2013, Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
  5. *
  6. * Register definitions and initial settings based on a driver written
  7. * by Vladimir Fonov.
  8. * Copyright (c) 2010, Vladimir Fonov
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/delay.h>
  16. #include <linux/gpio.h>
  17. #include <linux/gpio/consumer.h>
  18. #include <linux/i2c.h>
  19. #include <linux/kernel.h>
  20. #include <linux/media.h>
  21. #include <linux/module.h>
  22. #include <linux/ratelimit.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <linux/videodev2.h>
  26. #include <media/media-entity.h>
  27. #include <media/v4l2-async.h>
  28. #include <media/v4l2-ctrls.h>
  29. #include <media/v4l2-device.h>
  30. #include <media/v4l2-event.h>
  31. #include <media/v4l2-image-sizes.h>
  32. #include <media/v4l2-subdev.h>
  33. #include <media/v4l2-mediabus.h>
  34. #include <media/i2c/ov9650.h>
  35. static int debug;
  36. module_param(debug, int, 0644);
  37. MODULE_PARM_DESC(debug, "Debug level (0-2)");
  38. #define DRIVER_NAME "OV9650"
  39. /*
  40. * OV9650/OV9652 register definitions
  41. */
  42. #define REG_GAIN 0x00 /* Gain control, AGC[7:0] */
  43. #define REG_BLUE 0x01 /* AWB - Blue chanel gain */
  44. #define REG_RED 0x02 /* AWB - Red chanel gain */
  45. #define REG_VREF 0x03 /* [7:6] - AGC[9:8], [5:3]/[2:0] */
  46. #define VREF_GAIN_MASK 0xc0 /* - VREF end/start low 3 bits */
  47. #define REG_COM1 0x04
  48. #define COM1_CCIR656 0x40
  49. #define REG_B_AVE 0x05
  50. #define REG_GB_AVE 0x06
  51. #define REG_GR_AVE 0x07
  52. #define REG_R_AVE 0x08
  53. #define REG_COM2 0x09
  54. #define REG_PID 0x0a /* Product ID MSB */
  55. #define REG_VER 0x0b /* Product ID LSB */
  56. #define REG_COM3 0x0c
  57. #define COM3_SWAP 0x40
  58. #define COM3_VARIOPIXEL1 0x04
  59. #define REG_COM4 0x0d /* Vario Pixels */
  60. #define COM4_VARIOPIXEL2 0x80
  61. #define REG_COM5 0x0e /* System clock options */
  62. #define COM5_SLAVE_MODE 0x10
  63. #define COM5_SYSTEMCLOCK48MHZ 0x80
  64. #define REG_COM6 0x0f /* HREF & ADBLC options */
  65. #define REG_AECH 0x10 /* Exposure value, AEC[9:2] */
  66. #define REG_CLKRC 0x11 /* Clock control */
  67. #define CLK_EXT 0x40 /* Use external clock directly */
  68. #define CLK_SCALE 0x3f /* Mask for internal clock scale */
  69. #define REG_COM7 0x12 /* SCCB reset, output format */
  70. #define COM7_RESET 0x80
  71. #define COM7_FMT_MASK 0x38
  72. #define COM7_FMT_VGA 0x40
  73. #define COM7_FMT_CIF 0x20
  74. #define COM7_FMT_QVGA 0x10
  75. #define COM7_FMT_QCIF 0x08
  76. #define COM7_RGB 0x04
  77. #define COM7_YUV 0x00
  78. #define COM7_BAYER 0x01
  79. #define COM7_PBAYER 0x05
  80. #define REG_COM8 0x13 /* AGC/AEC options */
  81. #define COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
  82. #define COM8_AECSTEP 0x40 /* Unlimited AEC step size */
  83. #define COM8_BFILT 0x20 /* Band filter enable */
  84. #define COM8_AGC 0x04 /* Auto gain enable */
  85. #define COM8_AWB 0x02 /* White balance enable */
  86. #define COM8_AEC 0x01 /* Auto exposure enable */
  87. #define REG_COM9 0x14 /* Gain ceiling */
  88. #define COM9_GAIN_CEIL_MASK 0x70 /* */
  89. #define REG_COM10 0x15 /* PCLK, HREF, HSYNC signals polarity */
  90. #define COM10_HSYNC 0x40 /* HSYNC instead of HREF */
  91. #define COM10_PCLK_HB 0x20 /* Suppress PCLK on horiz blank */
  92. #define COM10_HREF_REV 0x08 /* Reverse HREF */
  93. #define COM10_VS_LEAD 0x04 /* VSYNC on clock leading edge */
  94. #define COM10_VS_NEG 0x02 /* VSYNC negative */
  95. #define COM10_HS_NEG 0x01 /* HSYNC negative */
  96. #define REG_HSTART 0x17 /* Horiz start high bits */
  97. #define REG_HSTOP 0x18 /* Horiz stop high bits */
  98. #define REG_VSTART 0x19 /* Vert start high bits */
  99. #define REG_VSTOP 0x1a /* Vert stop high bits */
  100. #define REG_PSHFT 0x1b /* Pixel delay after HREF */
  101. #define REG_MIDH 0x1c /* Manufacturer ID MSB */
  102. #define REG_MIDL 0x1d /* Manufufacturer ID LSB */
  103. #define REG_MVFP 0x1e /* Image mirror/flip */
  104. #define MVFP_MIRROR 0x20 /* Mirror image */
  105. #define MVFP_FLIP 0x10 /* Vertical flip */
  106. #define REG_BOS 0x20 /* B channel Offset */
  107. #define REG_GBOS 0x21 /* Gb channel Offset */
  108. #define REG_GROS 0x22 /* Gr channel Offset */
  109. #define REG_ROS 0x23 /* R channel Offset */
  110. #define REG_AEW 0x24 /* AGC upper limit */
  111. #define REG_AEB 0x25 /* AGC lower limit */
  112. #define REG_VPT 0x26 /* AGC/AEC fast mode op region */
  113. #define REG_BBIAS 0x27 /* B channel output bias */
  114. #define REG_GBBIAS 0x28 /* Gb channel output bias */
  115. #define REG_GRCOM 0x29 /* Analog BLC & regulator */
  116. #define REG_EXHCH 0x2a /* Dummy pixel insert MSB */
  117. #define REG_EXHCL 0x2b /* Dummy pixel insert LSB */
  118. #define REG_RBIAS 0x2c /* R channel output bias */
  119. #define REG_ADVFL 0x2d /* LSB of dummy line insert */
  120. #define REG_ADVFH 0x2e /* MSB of dummy line insert */
  121. #define REG_YAVE 0x2f /* Y/G channel average value */
  122. #define REG_HSYST 0x30 /* HSYNC rising edge delay LSB*/
  123. #define REG_HSYEN 0x31 /* HSYNC falling edge delay LSB*/
  124. #define REG_HREF 0x32 /* HREF pieces */
  125. #define REG_CHLF 0x33 /* reserved */
  126. #define REG_ADC 0x37 /* reserved */
  127. #define REG_ACOM 0x38 /* reserved */
  128. #define REG_OFON 0x39 /* Power down register */
  129. #define OFON_PWRDN 0x08 /* Power down bit */
  130. #define REG_TSLB 0x3a /* YUVU format */
  131. #define TSLB_YUYV_MASK 0x0c /* UYVY or VYUY - see com13 */
  132. #define REG_COM11 0x3b /* Night mode, banding filter enable */
  133. #define COM11_NIGHT 0x80 /* Night mode enable */
  134. #define COM11_NMFR 0x60 /* Two bit NM frame rate */
  135. #define COM11_BANDING 0x01 /* Banding filter */
  136. #define COM11_AEC_REF_MASK 0x18 /* AEC reference area selection */
  137. #define REG_COM12 0x3c /* HREF option, UV average */
  138. #define COM12_HREF 0x80 /* HREF always */
  139. #define REG_COM13 0x3d /* Gamma selection, Color matrix en. */
  140. #define COM13_GAMMA 0x80 /* Gamma enable */
  141. #define COM13_UVSAT 0x40 /* UV saturation auto adjustment */
  142. #define COM13_UVSWAP 0x01 /* V before U - w/TSLB */
  143. #define REG_COM14 0x3e /* Edge enhancement options */
  144. #define COM14_EDGE_EN 0x02
  145. #define COM14_EEF_X2 0x01
  146. #define REG_EDGE 0x3f /* Edge enhancement factor */
  147. #define EDGE_FACTOR_MASK 0x0f
  148. #define REG_COM15 0x40 /* Output range, RGB 555/565 */
  149. #define COM15_R10F0 0x00 /* Data range 10 to F0 */
  150. #define COM15_R01FE 0x80 /* 01 to FE */
  151. #define COM15_R00FF 0xc0 /* 00 to FF */
  152. #define COM15_RGB565 0x10 /* RGB565 output */
  153. #define COM15_RGB555 0x30 /* RGB555 output */
  154. #define COM15_SWAPRB 0x04 /* Swap R&B */
  155. #define REG_COM16 0x41 /* Color matrix coeff options */
  156. #define REG_COM17 0x42 /* Single frame out, banding filter */
  157. /* n = 1...9, 0x4f..0x57 */
  158. #define REG_MTX(__n) (0x4f + (__n) - 1)
  159. #define REG_MTXS 0x58
  160. /* Lens Correction Option 1...5, __n = 0...5 */
  161. #define REG_LCC(__n) (0x62 + (__n) - 1)
  162. #define LCC5_LCC_ENABLE 0x01 /* LCC5, enable lens correction */
  163. #define LCC5_LCC_COLOR 0x04
  164. #define REG_MANU 0x67 /* Manual U value */
  165. #define REG_MANV 0x68 /* Manual V value */
  166. #define REG_HV 0x69 /* Manual banding filter MSB */
  167. #define REG_MBD 0x6a /* Manual banding filter value */
  168. #define REG_DBLV 0x6b /* reserved */
  169. #define REG_GSP 0x6c /* Gamma curve */
  170. #define GSP_LEN 15
  171. #define REG_GST 0x7c /* Gamma curve */
  172. #define GST_LEN 15
  173. #define REG_COM21 0x8b
  174. #define REG_COM22 0x8c /* Edge enhancement, denoising */
  175. #define COM22_WHTPCOR 0x02 /* White pixel correction enable */
  176. #define COM22_WHTPCOROPT 0x01 /* White pixel correction option */
  177. #define COM22_DENOISE 0x10 /* White pixel correction option */
  178. #define REG_COM23 0x8d /* Color bar test, color gain */
  179. #define COM23_TEST_MODE 0x10
  180. #define REG_DBLC1 0x8f /* Digital BLC */
  181. #define REG_DBLC_B 0x90 /* Digital BLC B channel offset */
  182. #define REG_DBLC_R 0x91 /* Digital BLC R channel offset */
  183. #define REG_DM_LNL 0x92 /* Dummy line low 8 bits */
  184. #define REG_DM_LNH 0x93 /* Dummy line high 8 bits */
  185. #define REG_LCCFB 0x9d /* Lens Correction B channel */
  186. #define REG_LCCFR 0x9e /* Lens Correction R channel */
  187. #define REG_DBLC_GB 0x9f /* Digital BLC GB chan offset */
  188. #define REG_DBLC_GR 0xa0 /* Digital BLC GR chan offset */
  189. #define REG_AECHM 0xa1 /* Exposure value - bits AEC[15:10] */
  190. #define REG_BD50ST 0xa2 /* Banding filter value for 50Hz */
  191. #define REG_BD60ST 0xa3 /* Banding filter value for 60Hz */
  192. #define REG_NULL 0xff /* Array end token */
  193. #define DEF_CLKRC 0x80
  194. #define OV965X_ID(_msb, _lsb) ((_msb) << 8 | (_lsb))
  195. #define OV9650_ID 0x9650
  196. #define OV9652_ID 0x9652
  197. struct ov965x_ctrls {
  198. struct v4l2_ctrl_handler handler;
  199. struct {
  200. struct v4l2_ctrl *auto_exp;
  201. struct v4l2_ctrl *exposure;
  202. };
  203. struct {
  204. struct v4l2_ctrl *auto_wb;
  205. struct v4l2_ctrl *blue_balance;
  206. struct v4l2_ctrl *red_balance;
  207. };
  208. struct {
  209. struct v4l2_ctrl *hflip;
  210. struct v4l2_ctrl *vflip;
  211. };
  212. struct {
  213. struct v4l2_ctrl *auto_gain;
  214. struct v4l2_ctrl *gain;
  215. };
  216. struct v4l2_ctrl *brightness;
  217. struct v4l2_ctrl *saturation;
  218. struct v4l2_ctrl *sharpness;
  219. struct v4l2_ctrl *light_freq;
  220. u8 update;
  221. };
  222. struct ov965x_framesize {
  223. u16 width;
  224. u16 height;
  225. u16 max_exp_lines;
  226. const u8 *regs;
  227. };
  228. struct ov965x_interval {
  229. struct v4l2_fract interval;
  230. /* Maximum resolution for this interval */
  231. struct v4l2_frmsize_discrete size;
  232. u8 clkrc_div;
  233. };
  234. enum gpio_id {
  235. GPIO_PWDN,
  236. GPIO_RST,
  237. NUM_GPIOS,
  238. };
  239. struct ov965x {
  240. struct v4l2_subdev sd;
  241. struct media_pad pad;
  242. enum v4l2_mbus_type bus_type;
  243. struct gpio_desc *gpios[NUM_GPIOS];
  244. /* External master clock frequency */
  245. unsigned long mclk_frequency;
  246. struct clk *clk;
  247. /* Protects the struct fields below */
  248. struct mutex lock;
  249. struct i2c_client *client;
  250. /* Exposure row interval in us */
  251. unsigned int exp_row_interval;
  252. unsigned short id;
  253. const struct ov965x_framesize *frame_size;
  254. /* YUYV sequence (pixel format) control register */
  255. u8 tslb_reg;
  256. struct v4l2_mbus_framefmt format;
  257. struct ov965x_ctrls ctrls;
  258. /* Pointer to frame rate control data structure */
  259. const struct ov965x_interval *fiv;
  260. int streaming;
  261. int power;
  262. u8 apply_frame_fmt;
  263. };
  264. struct i2c_rv {
  265. u8 addr;
  266. u8 value;
  267. };
  268. static const struct i2c_rv ov965x_init_regs[] = {
  269. { REG_COM2, 0x10 }, /* Set soft sleep mode */
  270. { REG_COM5, 0x00 }, /* System clock options */
  271. { REG_COM2, 0x01 }, /* Output drive, soft sleep mode */
  272. { REG_COM10, 0x00 }, /* Slave mode, HREF vs HSYNC, signals negate */
  273. { REG_EDGE, 0xa6 }, /* Edge enhancement treshhold and factor */
  274. { REG_COM16, 0x02 }, /* Color matrix coeff double option */
  275. { REG_COM17, 0x08 }, /* Single frame out, banding filter */
  276. { 0x16, 0x06 },
  277. { REG_CHLF, 0xc0 }, /* Reserved */
  278. { 0x34, 0xbf },
  279. { 0xa8, 0x80 },
  280. { 0x96, 0x04 },
  281. { 0x8e, 0x00 },
  282. { REG_COM12, 0x77 }, /* HREF option, UV average */
  283. { 0x8b, 0x06 },
  284. { 0x35, 0x91 },
  285. { 0x94, 0x88 },
  286. { 0x95, 0x88 },
  287. { REG_COM15, 0xc1 }, /* Output range, RGB 555/565 */
  288. { REG_GRCOM, 0x2f }, /* Analog BLC & regulator */
  289. { REG_COM6, 0x43 }, /* HREF & ADBLC options */
  290. { REG_COM8, 0xe5 }, /* AGC/AEC options */
  291. { REG_COM13, 0x90 }, /* Gamma selection, colour matrix, UV delay */
  292. { REG_HV, 0x80 }, /* Manual banding filter MSB */
  293. { 0x5c, 0x96 }, /* Reserved up to 0xa5 */
  294. { 0x5d, 0x96 },
  295. { 0x5e, 0x10 },
  296. { 0x59, 0xeb },
  297. { 0x5a, 0x9c },
  298. { 0x5b, 0x55 },
  299. { 0x43, 0xf0 },
  300. { 0x44, 0x10 },
  301. { 0x45, 0x55 },
  302. { 0x46, 0x86 },
  303. { 0x47, 0x64 },
  304. { 0x48, 0x86 },
  305. { 0x5f, 0xe0 },
  306. { 0x60, 0x8c },
  307. { 0x61, 0x20 },
  308. { 0xa5, 0xd9 },
  309. { 0xa4, 0x74 }, /* reserved */
  310. { REG_COM23, 0x02 }, /* Color gain analog/_digital_ */
  311. { REG_COM8, 0xe7 }, /* Enable AEC, AWB, AEC */
  312. { REG_COM22, 0x23 }, /* Edge enhancement, denoising */
  313. { 0xa9, 0xb8 },
  314. { 0xaa, 0x92 },
  315. { 0xab, 0x0a },
  316. { REG_DBLC1, 0xdf }, /* Digital BLC */
  317. { REG_DBLC_B, 0x00 }, /* Digital BLC B chan offset */
  318. { REG_DBLC_R, 0x00 }, /* Digital BLC R chan offset */
  319. { REG_DBLC_GB, 0x00 }, /* Digital BLC GB chan offset */
  320. { REG_DBLC_GR, 0x00 },
  321. { REG_COM9, 0x3a }, /* Gain ceiling 16x */
  322. { REG_NULL, 0 }
  323. };
  324. #define NUM_FMT_REGS 14
  325. /*
  326. * COM7, COM3, COM4, HSTART, HSTOP, HREF, VSTART, VSTOP, VREF,
  327. * EXHCH, EXHCL, ADC, OCOM, OFON
  328. */
  329. static const u8 frame_size_reg_addr[NUM_FMT_REGS] = {
  330. 0x12, 0x0c, 0x0d, 0x17, 0x18, 0x32, 0x19, 0x1a, 0x03,
  331. 0x2a, 0x2b, 0x37, 0x38, 0x39,
  332. };
  333. static const u8 ov965x_sxga_regs[NUM_FMT_REGS] = {
  334. 0x00, 0x00, 0x00, 0x1e, 0xbe, 0xbf, 0x01, 0x81, 0x12,
  335. 0x10, 0x34, 0x81, 0x93, 0x51,
  336. };
  337. static const u8 ov965x_vga_regs[NUM_FMT_REGS] = {
  338. 0x40, 0x04, 0x80, 0x26, 0xc6, 0xed, 0x01, 0x3d, 0x00,
  339. 0x10, 0x40, 0x91, 0x12, 0x43,
  340. };
  341. /* Determined empirically. */
  342. static const u8 ov965x_qvga_regs[NUM_FMT_REGS] = {
  343. 0x10, 0x04, 0x80, 0x25, 0xc5, 0xbf, 0x00, 0x80, 0x12,
  344. 0x10, 0x40, 0x91, 0x12, 0x43,
  345. };
  346. static const struct ov965x_framesize ov965x_framesizes[] = {
  347. {
  348. .width = SXGA_WIDTH,
  349. .height = SXGA_HEIGHT,
  350. .regs = ov965x_sxga_regs,
  351. .max_exp_lines = 1048,
  352. }, {
  353. .width = VGA_WIDTH,
  354. .height = VGA_HEIGHT,
  355. .regs = ov965x_vga_regs,
  356. .max_exp_lines = 498,
  357. }, {
  358. .width = QVGA_WIDTH,
  359. .height = QVGA_HEIGHT,
  360. .regs = ov965x_qvga_regs,
  361. .max_exp_lines = 248,
  362. },
  363. };
  364. struct ov965x_pixfmt {
  365. u32 code;
  366. u32 colorspace;
  367. /* REG_TSLB value, only bits [3:2] may be set. */
  368. u8 tslb_reg;
  369. };
  370. static const struct ov965x_pixfmt ov965x_formats[] = {
  371. { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG, 0x00},
  372. { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_COLORSPACE_JPEG, 0x04},
  373. { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG, 0x0c},
  374. { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_COLORSPACE_JPEG, 0x08},
  375. };
  376. /*
  377. * This table specifies possible frame resolution and interval
  378. * combinations. Default CLKRC[5:0] divider values are valid
  379. * only for 24 MHz external clock frequency.
  380. */
  381. static struct ov965x_interval ov965x_intervals[] = {
  382. {{ 100, 625 }, { SXGA_WIDTH, SXGA_HEIGHT }, 0 }, /* 6.25 fps */
  383. {{ 10, 125 }, { VGA_WIDTH, VGA_HEIGHT }, 1 }, /* 12.5 fps */
  384. {{ 10, 125 }, { QVGA_WIDTH, QVGA_HEIGHT }, 3 }, /* 12.5 fps */
  385. {{ 1, 25 }, { VGA_WIDTH, VGA_HEIGHT }, 0 }, /* 25 fps */
  386. {{ 1, 25 }, { QVGA_WIDTH, QVGA_HEIGHT }, 1 }, /* 25 fps */
  387. };
  388. static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
  389. {
  390. return &container_of(ctrl->handler, struct ov965x, ctrls.handler)->sd;
  391. }
  392. static inline struct ov965x *to_ov965x(struct v4l2_subdev *sd)
  393. {
  394. return container_of(sd, struct ov965x, sd);
  395. }
  396. static int ov965x_read(struct i2c_client *client, u8 addr, u8 *val)
  397. {
  398. u8 buf = addr;
  399. struct i2c_msg msg = {
  400. .addr = client->addr,
  401. .flags = 0,
  402. .len = 1,
  403. .buf = &buf
  404. };
  405. int ret;
  406. ret = i2c_transfer(client->adapter, &msg, 1);
  407. if (ret == 1) {
  408. msg.flags = I2C_M_RD;
  409. ret = i2c_transfer(client->adapter, &msg, 1);
  410. if (ret == 1)
  411. *val = buf;
  412. }
  413. v4l2_dbg(2, debug, client, "%s: 0x%02x @ 0x%02x. (%d)\n",
  414. __func__, *val, addr, ret);
  415. return ret == 1 ? 0 : ret;
  416. }
  417. static int ov965x_write(struct i2c_client *client, u8 addr, u8 val)
  418. {
  419. u8 buf[2] = { addr, val };
  420. int ret = i2c_master_send(client, buf, 2);
  421. v4l2_dbg(2, debug, client, "%s: 0x%02x @ 0x%02X (%d)\n",
  422. __func__, val, addr, ret);
  423. return ret == 2 ? 0 : ret;
  424. }
  425. static int ov965x_write_array(struct i2c_client *client,
  426. const struct i2c_rv *regs)
  427. {
  428. int i, ret = 0;
  429. for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++)
  430. ret = ov965x_write(client, regs[i].addr, regs[i].value);
  431. return ret;
  432. }
  433. static int ov965x_set_default_gamma_curve(struct ov965x *ov965x)
  434. {
  435. static const u8 gamma_curve[] = {
  436. /* Values taken from OV application note. */
  437. 0x40, 0x30, 0x4b, 0x60, 0x70, 0x70, 0x70, 0x70,
  438. 0x60, 0x60, 0x50, 0x48, 0x3a, 0x2e, 0x28, 0x22,
  439. 0x04, 0x07, 0x10, 0x28, 0x36, 0x44, 0x52, 0x60,
  440. 0x6c, 0x78, 0x8c, 0x9e, 0xbb, 0xd2, 0xe6
  441. };
  442. u8 addr = REG_GSP;
  443. unsigned int i;
  444. for (i = 0; i < ARRAY_SIZE(gamma_curve); i++) {
  445. int ret = ov965x_write(ov965x->client, addr, gamma_curve[i]);
  446. if (ret < 0)
  447. return ret;
  448. addr++;
  449. }
  450. return 0;
  451. };
  452. static int ov965x_set_color_matrix(struct ov965x *ov965x)
  453. {
  454. static const u8 mtx[] = {
  455. /* MTX1..MTX9, MTXS */
  456. 0x3a, 0x3d, 0x03, 0x12, 0x26, 0x38, 0x40, 0x40, 0x40, 0x0d
  457. };
  458. u8 addr = REG_MTX(1);
  459. unsigned int i;
  460. for (i = 0; i < ARRAY_SIZE(mtx); i++) {
  461. int ret = ov965x_write(ov965x->client, addr, mtx[i]);
  462. if (ret < 0)
  463. return ret;
  464. addr++;
  465. }
  466. return 0;
  467. }
  468. static int __ov965x_set_power(struct ov965x *ov965x, int on)
  469. {
  470. if (on) {
  471. int ret = clk_prepare_enable(ov965x->clk);
  472. if (ret)
  473. return ret;
  474. gpiod_set_value_cansleep(ov965x->gpios[GPIO_PWDN], 0);
  475. gpiod_set_value_cansleep(ov965x->gpios[GPIO_RST], 0);
  476. msleep(25);
  477. } else {
  478. gpiod_set_value_cansleep(ov965x->gpios[GPIO_RST], 1);
  479. gpiod_set_value_cansleep(ov965x->gpios[GPIO_PWDN], 1);
  480. clk_disable_unprepare(ov965x->clk);
  481. }
  482. ov965x->streaming = 0;
  483. return 0;
  484. }
  485. static int ov965x_s_power(struct v4l2_subdev *sd, int on)
  486. {
  487. struct ov965x *ov965x = to_ov965x(sd);
  488. struct i2c_client *client = ov965x->client;
  489. int ret = 0;
  490. v4l2_dbg(1, debug, client, "%s: on: %d\n", __func__, on);
  491. mutex_lock(&ov965x->lock);
  492. if (ov965x->power == !on) {
  493. ret = __ov965x_set_power(ov965x, on);
  494. if (!ret && on) {
  495. ret = ov965x_write_array(client,
  496. ov965x_init_regs);
  497. ov965x->apply_frame_fmt = 1;
  498. ov965x->ctrls.update = 1;
  499. }
  500. }
  501. if (!ret)
  502. ov965x->power += on ? 1 : -1;
  503. WARN_ON(ov965x->power < 0);
  504. mutex_unlock(&ov965x->lock);
  505. return ret;
  506. }
  507. /*
  508. * V4L2 controls
  509. */
  510. static void ov965x_update_exposure_ctrl(struct ov965x *ov965x)
  511. {
  512. struct v4l2_ctrl *ctrl = ov965x->ctrls.exposure;
  513. unsigned long fint, trow;
  514. int min, max, def;
  515. u8 clkrc;
  516. mutex_lock(&ov965x->lock);
  517. if (WARN_ON(!ctrl || !ov965x->frame_size)) {
  518. mutex_unlock(&ov965x->lock);
  519. return;
  520. }
  521. clkrc = DEF_CLKRC + ov965x->fiv->clkrc_div;
  522. /* Calculate internal clock frequency */
  523. fint = ov965x->mclk_frequency * ((clkrc >> 7) + 1) /
  524. ((2 * ((clkrc & 0x3f) + 1)));
  525. /* and the row interval (in us). */
  526. trow = (2 * 1520 * 1000000UL) / fint;
  527. max = ov965x->frame_size->max_exp_lines * trow;
  528. ov965x->exp_row_interval = trow;
  529. mutex_unlock(&ov965x->lock);
  530. v4l2_dbg(1, debug, &ov965x->sd, "clkrc: %#x, fi: %lu, tr: %lu, %d\n",
  531. clkrc, fint, trow, max);
  532. /* Update exposure time range to match current frame format. */
  533. min = (trow + 100) / 100;
  534. max = (max - 100) / 100;
  535. def = min + (max - min) / 2;
  536. if (v4l2_ctrl_modify_range(ctrl, min, max, 1, def))
  537. v4l2_err(&ov965x->sd, "Exposure ctrl range update failed\n");
  538. }
  539. static int ov965x_set_banding_filter(struct ov965x *ov965x, int value)
  540. {
  541. unsigned long mbd, light_freq;
  542. int ret;
  543. u8 reg;
  544. ret = ov965x_read(ov965x->client, REG_COM8, &reg);
  545. if (!ret) {
  546. if (value == V4L2_CID_POWER_LINE_FREQUENCY_DISABLED)
  547. reg &= ~COM8_BFILT;
  548. else
  549. reg |= COM8_BFILT;
  550. ret = ov965x_write(ov965x->client, REG_COM8, reg);
  551. }
  552. if (value == V4L2_CID_POWER_LINE_FREQUENCY_DISABLED)
  553. return 0;
  554. if (WARN_ON(!ov965x->fiv))
  555. return -EINVAL;
  556. /* Set minimal exposure time for 50/60 HZ lighting */
  557. if (value == V4L2_CID_POWER_LINE_FREQUENCY_50HZ)
  558. light_freq = 50;
  559. else
  560. light_freq = 60;
  561. mbd = (1000UL * ov965x->fiv->interval.denominator *
  562. ov965x->frame_size->max_exp_lines) /
  563. ov965x->fiv->interval.numerator;
  564. mbd = ((mbd / (light_freq * 2)) + 500) / 1000UL;
  565. return ov965x_write(ov965x->client, REG_MBD, mbd);
  566. }
  567. static int ov965x_set_white_balance(struct ov965x *ov965x, int awb)
  568. {
  569. int ret;
  570. u8 reg;
  571. ret = ov965x_read(ov965x->client, REG_COM8, &reg);
  572. if (!ret) {
  573. reg = awb ? reg | REG_COM8 : reg & ~REG_COM8;
  574. ret = ov965x_write(ov965x->client, REG_COM8, reg);
  575. }
  576. if (!ret && !awb) {
  577. ret = ov965x_write(ov965x->client, REG_BLUE,
  578. ov965x->ctrls.blue_balance->val);
  579. if (ret < 0)
  580. return ret;
  581. ret = ov965x_write(ov965x->client, REG_RED,
  582. ov965x->ctrls.red_balance->val);
  583. }
  584. return ret;
  585. }
  586. #define NUM_BR_LEVELS 7
  587. #define NUM_BR_REGS 3
  588. static int ov965x_set_brightness(struct ov965x *ov965x, int val)
  589. {
  590. static const u8 regs[NUM_BR_LEVELS + 1][NUM_BR_REGS] = {
  591. { REG_AEW, REG_AEB, REG_VPT },
  592. { 0x1c, 0x12, 0x50 }, /* -3 */
  593. { 0x3d, 0x30, 0x71 }, /* -2 */
  594. { 0x50, 0x44, 0x92 }, /* -1 */
  595. { 0x70, 0x64, 0xc3 }, /* 0 */
  596. { 0x90, 0x84, 0xd4 }, /* +1 */
  597. { 0xc4, 0xbf, 0xf9 }, /* +2 */
  598. { 0xd8, 0xd0, 0xfa }, /* +3 */
  599. };
  600. int i, ret = 0;
  601. val += (NUM_BR_LEVELS / 2 + 1);
  602. if (val > NUM_BR_LEVELS)
  603. return -EINVAL;
  604. for (i = 0; i < NUM_BR_REGS && !ret; i++)
  605. ret = ov965x_write(ov965x->client, regs[0][i],
  606. regs[val][i]);
  607. return ret;
  608. }
  609. static int ov965x_set_gain(struct ov965x *ov965x, int auto_gain)
  610. {
  611. struct i2c_client *client = ov965x->client;
  612. struct ov965x_ctrls *ctrls = &ov965x->ctrls;
  613. int ret = 0;
  614. u8 reg;
  615. /*
  616. * For manual mode we need to disable AGC first, so
  617. * gain value in REG_VREF, REG_GAIN is not overwritten.
  618. */
  619. if (ctrls->auto_gain->is_new) {
  620. ret = ov965x_read(client, REG_COM8, &reg);
  621. if (ret < 0)
  622. return ret;
  623. if (ctrls->auto_gain->val)
  624. reg |= COM8_AGC;
  625. else
  626. reg &= ~COM8_AGC;
  627. ret = ov965x_write(client, REG_COM8, reg);
  628. if (ret < 0)
  629. return ret;
  630. }
  631. if (ctrls->gain->is_new && !auto_gain) {
  632. unsigned int gain = ctrls->gain->val;
  633. unsigned int rgain;
  634. int m;
  635. /*
  636. * Convert gain control value to the sensor's gain
  637. * registers (VREF[7:6], GAIN[7:0]) format.
  638. */
  639. for (m = 6; m >= 0; m--)
  640. if (gain >= (1 << m) * 16)
  641. break;
  642. /* Sanity check: don't adjust the gain with a negative value */
  643. if (m < 0)
  644. return -EINVAL;
  645. rgain = (gain - ((1 << m) * 16)) / (1 << m);
  646. rgain |= (((1 << m) - 1) << 4);
  647. ret = ov965x_write(client, REG_GAIN, rgain & 0xff);
  648. if (ret < 0)
  649. return ret;
  650. ret = ov965x_read(client, REG_VREF, &reg);
  651. if (ret < 0)
  652. return ret;
  653. reg &= ~VREF_GAIN_MASK;
  654. reg |= (((rgain >> 8) & 0x3) << 6);
  655. ret = ov965x_write(client, REG_VREF, reg);
  656. if (ret < 0)
  657. return ret;
  658. /* Return updated control's value to userspace */
  659. ctrls->gain->val = (1 << m) * (16 + (rgain & 0xf));
  660. }
  661. return ret;
  662. }
  663. static int ov965x_set_sharpness(struct ov965x *ov965x, unsigned int value)
  664. {
  665. u8 com14, edge;
  666. int ret;
  667. ret = ov965x_read(ov965x->client, REG_COM14, &com14);
  668. if (ret < 0)
  669. return ret;
  670. ret = ov965x_read(ov965x->client, REG_EDGE, &edge);
  671. if (ret < 0)
  672. return ret;
  673. com14 = value ? com14 | COM14_EDGE_EN : com14 & ~COM14_EDGE_EN;
  674. value--;
  675. if (value > 0x0f) {
  676. com14 |= COM14_EEF_X2;
  677. value >>= 1;
  678. } else {
  679. com14 &= ~COM14_EEF_X2;
  680. }
  681. ret = ov965x_write(ov965x->client, REG_COM14, com14);
  682. if (ret < 0)
  683. return ret;
  684. edge &= ~EDGE_FACTOR_MASK;
  685. edge |= ((u8)value & 0x0f);
  686. return ov965x_write(ov965x->client, REG_EDGE, edge);
  687. }
  688. static int ov965x_set_exposure(struct ov965x *ov965x, int exp)
  689. {
  690. struct i2c_client *client = ov965x->client;
  691. struct ov965x_ctrls *ctrls = &ov965x->ctrls;
  692. bool auto_exposure = (exp == V4L2_EXPOSURE_AUTO);
  693. int ret;
  694. u8 reg;
  695. if (ctrls->auto_exp->is_new) {
  696. ret = ov965x_read(client, REG_COM8, &reg);
  697. if (ret < 0)
  698. return ret;
  699. if (auto_exposure)
  700. reg |= (COM8_AEC | COM8_AGC);
  701. else
  702. reg &= ~(COM8_AEC | COM8_AGC);
  703. ret = ov965x_write(client, REG_COM8, reg);
  704. if (ret < 0)
  705. return ret;
  706. }
  707. if (!auto_exposure && ctrls->exposure->is_new) {
  708. unsigned int exposure = (ctrls->exposure->val * 100)
  709. / ov965x->exp_row_interval;
  710. /*
  711. * Manual exposure value
  712. * [b15:b0] - AECHM (b15:b10), AECH (b9:b2), COM1 (b1:b0)
  713. */
  714. ret = ov965x_write(client, REG_COM1, exposure & 0x3);
  715. if (!ret)
  716. ret = ov965x_write(client, REG_AECH,
  717. (exposure >> 2) & 0xff);
  718. if (!ret)
  719. ret = ov965x_write(client, REG_AECHM,
  720. (exposure >> 10) & 0x3f);
  721. /* Update the value to minimize rounding errors */
  722. ctrls->exposure->val = ((exposure * ov965x->exp_row_interval)
  723. + 50) / 100;
  724. if (ret < 0)
  725. return ret;
  726. }
  727. v4l2_ctrl_activate(ov965x->ctrls.brightness, !exp);
  728. return 0;
  729. }
  730. static int ov965x_set_flip(struct ov965x *ov965x)
  731. {
  732. u8 mvfp = 0;
  733. if (ov965x->ctrls.hflip->val)
  734. mvfp |= MVFP_MIRROR;
  735. if (ov965x->ctrls.vflip->val)
  736. mvfp |= MVFP_FLIP;
  737. return ov965x_write(ov965x->client, REG_MVFP, mvfp);
  738. }
  739. #define NUM_SAT_LEVELS 5
  740. #define NUM_SAT_REGS 6
  741. static int ov965x_set_saturation(struct ov965x *ov965x, int val)
  742. {
  743. static const u8 regs[NUM_SAT_LEVELS][NUM_SAT_REGS] = {
  744. /* MTX(1)...MTX(6) */
  745. { 0x1d, 0x1f, 0x02, 0x09, 0x13, 0x1c }, /* -2 */
  746. { 0x2e, 0x31, 0x02, 0x0e, 0x1e, 0x2d }, /* -1 */
  747. { 0x3a, 0x3d, 0x03, 0x12, 0x26, 0x38 }, /* 0 */
  748. { 0x46, 0x49, 0x04, 0x16, 0x2e, 0x43 }, /* +1 */
  749. { 0x57, 0x5c, 0x05, 0x1b, 0x39, 0x54 }, /* +2 */
  750. };
  751. u8 addr = REG_MTX(1);
  752. int i, ret = 0;
  753. val += (NUM_SAT_LEVELS / 2);
  754. if (val >= NUM_SAT_LEVELS)
  755. return -EINVAL;
  756. for (i = 0; i < NUM_SAT_REGS && !ret; i++)
  757. ret = ov965x_write(ov965x->client, addr + i, regs[val][i]);
  758. return ret;
  759. }
  760. static int ov965x_set_test_pattern(struct ov965x *ov965x, int value)
  761. {
  762. int ret;
  763. u8 reg;
  764. ret = ov965x_read(ov965x->client, REG_COM23, &reg);
  765. if (ret < 0)
  766. return ret;
  767. reg = value ? reg | COM23_TEST_MODE : reg & ~COM23_TEST_MODE;
  768. return ov965x_write(ov965x->client, REG_COM23, reg);
  769. }
  770. static int __g_volatile_ctrl(struct ov965x *ov965x, struct v4l2_ctrl *ctrl)
  771. {
  772. struct i2c_client *client = ov965x->client;
  773. unsigned int exposure, gain, m;
  774. u8 reg0, reg1, reg2;
  775. int ret;
  776. if (!ov965x->power)
  777. return 0;
  778. switch (ctrl->id) {
  779. case V4L2_CID_AUTOGAIN:
  780. if (!ctrl->val)
  781. return 0;
  782. ret = ov965x_read(client, REG_GAIN, &reg0);
  783. if (ret < 0)
  784. return ret;
  785. ret = ov965x_read(client, REG_VREF, &reg1);
  786. if (ret < 0)
  787. return ret;
  788. gain = ((reg1 >> 6) << 8) | reg0;
  789. m = 0x01 << fls(gain >> 4);
  790. ov965x->ctrls.gain->val = m * (16 + (gain & 0xf));
  791. break;
  792. case V4L2_CID_EXPOSURE_AUTO:
  793. if (ctrl->val == V4L2_EXPOSURE_MANUAL)
  794. return 0;
  795. ret = ov965x_read(client, REG_COM1, &reg0);
  796. if (ret < 0)
  797. return ret;
  798. ret = ov965x_read(client, REG_AECH, &reg1);
  799. if (ret < 0)
  800. return ret;
  801. ret = ov965x_read(client, REG_AECHM, &reg2);
  802. if (ret < 0)
  803. return ret;
  804. exposure = ((reg2 & 0x3f) << 10) | (reg1 << 2) |
  805. (reg0 & 0x3);
  806. ov965x->ctrls.exposure->val = ((exposure *
  807. ov965x->exp_row_interval) + 50) / 100;
  808. break;
  809. }
  810. return 0;
  811. }
  812. static int ov965x_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  813. {
  814. struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
  815. struct ov965x *ov965x = to_ov965x(sd);
  816. int ret;
  817. v4l2_dbg(1, debug, sd, "g_ctrl: %s\n", ctrl->name);
  818. mutex_lock(&ov965x->lock);
  819. ret = __g_volatile_ctrl(ov965x, ctrl);
  820. mutex_unlock(&ov965x->lock);
  821. return ret;
  822. }
  823. static int ov965x_s_ctrl(struct v4l2_ctrl *ctrl)
  824. {
  825. struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
  826. struct ov965x *ov965x = to_ov965x(sd);
  827. int ret = -EINVAL;
  828. v4l2_dbg(1, debug, sd, "s_ctrl: %s, value: %d. power: %d\n",
  829. ctrl->name, ctrl->val, ov965x->power);
  830. mutex_lock(&ov965x->lock);
  831. /*
  832. * If the device is not powered up now postpone applying control's
  833. * value to the hardware, until it is ready to accept commands.
  834. */
  835. if (ov965x->power == 0) {
  836. mutex_unlock(&ov965x->lock);
  837. return 0;
  838. }
  839. switch (ctrl->id) {
  840. case V4L2_CID_AUTO_WHITE_BALANCE:
  841. ret = ov965x_set_white_balance(ov965x, ctrl->val);
  842. break;
  843. case V4L2_CID_BRIGHTNESS:
  844. ret = ov965x_set_brightness(ov965x, ctrl->val);
  845. break;
  846. case V4L2_CID_EXPOSURE_AUTO:
  847. ret = ov965x_set_exposure(ov965x, ctrl->val);
  848. break;
  849. case V4L2_CID_AUTOGAIN:
  850. ret = ov965x_set_gain(ov965x, ctrl->val);
  851. break;
  852. case V4L2_CID_HFLIP:
  853. ret = ov965x_set_flip(ov965x);
  854. break;
  855. case V4L2_CID_POWER_LINE_FREQUENCY:
  856. ret = ov965x_set_banding_filter(ov965x, ctrl->val);
  857. break;
  858. case V4L2_CID_SATURATION:
  859. ret = ov965x_set_saturation(ov965x, ctrl->val);
  860. break;
  861. case V4L2_CID_SHARPNESS:
  862. ret = ov965x_set_sharpness(ov965x, ctrl->val);
  863. break;
  864. case V4L2_CID_TEST_PATTERN:
  865. ret = ov965x_set_test_pattern(ov965x, ctrl->val);
  866. break;
  867. }
  868. mutex_unlock(&ov965x->lock);
  869. return ret;
  870. }
  871. static const struct v4l2_ctrl_ops ov965x_ctrl_ops = {
  872. .g_volatile_ctrl = ov965x_g_volatile_ctrl,
  873. .s_ctrl = ov965x_s_ctrl,
  874. };
  875. static const char * const test_pattern_menu[] = {
  876. "Disabled",
  877. "Color bars",
  878. };
  879. static int ov965x_initialize_controls(struct ov965x *ov965x)
  880. {
  881. const struct v4l2_ctrl_ops *ops = &ov965x_ctrl_ops;
  882. struct ov965x_ctrls *ctrls = &ov965x->ctrls;
  883. struct v4l2_ctrl_handler *hdl = &ctrls->handler;
  884. int ret;
  885. ret = v4l2_ctrl_handler_init(hdl, 16);
  886. if (ret < 0)
  887. return ret;
  888. /* Auto/manual white balance */
  889. ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
  890. V4L2_CID_AUTO_WHITE_BALANCE,
  891. 0, 1, 1, 1);
  892. ctrls->blue_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BLUE_BALANCE,
  893. 0, 0xff, 1, 0x80);
  894. ctrls->red_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_RED_BALANCE,
  895. 0, 0xff, 1, 0x80);
  896. /* Auto/manual exposure */
  897. ctrls->auto_exp =
  898. v4l2_ctrl_new_std_menu(hdl, ops,
  899. V4L2_CID_EXPOSURE_AUTO,
  900. V4L2_EXPOSURE_MANUAL, 0,
  901. V4L2_EXPOSURE_AUTO);
  902. /* Exposure time, in 100 us units. min/max is updated dynamically. */
  903. ctrls->exposure = v4l2_ctrl_new_std(hdl, ops,
  904. V4L2_CID_EXPOSURE_ABSOLUTE,
  905. 2, 1500, 1, 500);
  906. /* Auto/manual gain */
  907. ctrls->auto_gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTOGAIN,
  908. 0, 1, 1, 1);
  909. ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN,
  910. 16, 64 * (16 + 15), 1, 64 * 16);
  911. ctrls->saturation = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION,
  912. -2, 2, 1, 0);
  913. ctrls->brightness = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS,
  914. -3, 3, 1, 0);
  915. ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SHARPNESS,
  916. 0, 32, 1, 6);
  917. ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
  918. ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
  919. ctrls->light_freq =
  920. v4l2_ctrl_new_std_menu(hdl, ops,
  921. V4L2_CID_POWER_LINE_FREQUENCY,
  922. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, ~0x7,
  923. V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
  924. v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN,
  925. ARRAY_SIZE(test_pattern_menu) - 1, 0, 0,
  926. test_pattern_menu);
  927. if (hdl->error) {
  928. ret = hdl->error;
  929. v4l2_ctrl_handler_free(hdl);
  930. return ret;
  931. }
  932. ctrls->gain->flags |= V4L2_CTRL_FLAG_VOLATILE;
  933. ctrls->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE;
  934. v4l2_ctrl_auto_cluster(3, &ctrls->auto_wb, 0, false);
  935. v4l2_ctrl_auto_cluster(2, &ctrls->auto_gain, 0, true);
  936. v4l2_ctrl_auto_cluster(2, &ctrls->auto_exp, 1, true);
  937. v4l2_ctrl_cluster(2, &ctrls->hflip);
  938. ov965x->sd.ctrl_handler = hdl;
  939. return 0;
  940. }
  941. /*
  942. * V4L2 subdev video and pad level operations
  943. */
  944. static void ov965x_get_default_format(struct v4l2_mbus_framefmt *mf)
  945. {
  946. mf->width = ov965x_framesizes[0].width;
  947. mf->height = ov965x_framesizes[0].height;
  948. mf->colorspace = ov965x_formats[0].colorspace;
  949. mf->code = ov965x_formats[0].code;
  950. mf->field = V4L2_FIELD_NONE;
  951. }
  952. static int ov965x_enum_mbus_code(struct v4l2_subdev *sd,
  953. struct v4l2_subdev_pad_config *cfg,
  954. struct v4l2_subdev_mbus_code_enum *code)
  955. {
  956. if (code->index >= ARRAY_SIZE(ov965x_formats))
  957. return -EINVAL;
  958. code->code = ov965x_formats[code->index].code;
  959. return 0;
  960. }
  961. static int ov965x_enum_frame_sizes(struct v4l2_subdev *sd,
  962. struct v4l2_subdev_pad_config *cfg,
  963. struct v4l2_subdev_frame_size_enum *fse)
  964. {
  965. int i = ARRAY_SIZE(ov965x_formats);
  966. if (fse->index >= ARRAY_SIZE(ov965x_framesizes))
  967. return -EINVAL;
  968. while (--i)
  969. if (fse->code == ov965x_formats[i].code)
  970. break;
  971. fse->code = ov965x_formats[i].code;
  972. fse->min_width = ov965x_framesizes[fse->index].width;
  973. fse->max_width = fse->min_width;
  974. fse->max_height = ov965x_framesizes[fse->index].height;
  975. fse->min_height = fse->max_height;
  976. return 0;
  977. }
  978. static int ov965x_g_frame_interval(struct v4l2_subdev *sd,
  979. struct v4l2_subdev_frame_interval *fi)
  980. {
  981. struct ov965x *ov965x = to_ov965x(sd);
  982. mutex_lock(&ov965x->lock);
  983. fi->interval = ov965x->fiv->interval;
  984. mutex_unlock(&ov965x->lock);
  985. return 0;
  986. }
  987. static int __ov965x_set_frame_interval(struct ov965x *ov965x,
  988. struct v4l2_subdev_frame_interval *fi)
  989. {
  990. struct v4l2_mbus_framefmt *mbus_fmt = &ov965x->format;
  991. const struct ov965x_interval *fiv = &ov965x_intervals[0];
  992. u64 req_int, err, min_err = ~0ULL;
  993. unsigned int i;
  994. if (fi->interval.denominator == 0)
  995. return -EINVAL;
  996. req_int = (u64)fi->interval.numerator * 10000;
  997. do_div(req_int, fi->interval.denominator);
  998. for (i = 0; i < ARRAY_SIZE(ov965x_intervals); i++) {
  999. const struct ov965x_interval *iv = &ov965x_intervals[i];
  1000. if (mbus_fmt->width != iv->size.width ||
  1001. mbus_fmt->height != iv->size.height)
  1002. continue;
  1003. err = abs((u64)(iv->interval.numerator * 10000) /
  1004. iv->interval.denominator - req_int);
  1005. if (err < min_err) {
  1006. fiv = iv;
  1007. min_err = err;
  1008. }
  1009. }
  1010. ov965x->fiv = fiv;
  1011. v4l2_dbg(1, debug, &ov965x->sd, "Changed frame interval to %u us\n",
  1012. fiv->interval.numerator * 1000000 / fiv->interval.denominator);
  1013. return 0;
  1014. }
  1015. static int ov965x_s_frame_interval(struct v4l2_subdev *sd,
  1016. struct v4l2_subdev_frame_interval *fi)
  1017. {
  1018. struct ov965x *ov965x = to_ov965x(sd);
  1019. int ret;
  1020. v4l2_dbg(1, debug, sd, "Setting %d/%d frame interval\n",
  1021. fi->interval.numerator, fi->interval.denominator);
  1022. mutex_lock(&ov965x->lock);
  1023. ret = __ov965x_set_frame_interval(ov965x, fi);
  1024. ov965x->apply_frame_fmt = 1;
  1025. mutex_unlock(&ov965x->lock);
  1026. return ret;
  1027. }
  1028. static int ov965x_get_fmt(struct v4l2_subdev *sd,
  1029. struct v4l2_subdev_pad_config *cfg,
  1030. struct v4l2_subdev_format *fmt)
  1031. {
  1032. struct ov965x *ov965x = to_ov965x(sd);
  1033. struct v4l2_mbus_framefmt *mf;
  1034. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  1035. mf = v4l2_subdev_get_try_format(sd, cfg, 0);
  1036. fmt->format = *mf;
  1037. return 0;
  1038. }
  1039. mutex_lock(&ov965x->lock);
  1040. fmt->format = ov965x->format;
  1041. mutex_unlock(&ov965x->lock);
  1042. return 0;
  1043. }
  1044. static void __ov965x_try_frame_size(struct v4l2_mbus_framefmt *mf,
  1045. const struct ov965x_framesize **size)
  1046. {
  1047. const struct ov965x_framesize *fsize = &ov965x_framesizes[0],
  1048. *match = NULL;
  1049. int i = ARRAY_SIZE(ov965x_framesizes);
  1050. unsigned int min_err = UINT_MAX;
  1051. while (i--) {
  1052. int err = abs(fsize->width - mf->width)
  1053. + abs(fsize->height - mf->height);
  1054. if (err < min_err) {
  1055. min_err = err;
  1056. match = fsize;
  1057. }
  1058. fsize++;
  1059. }
  1060. if (!match)
  1061. match = &ov965x_framesizes[0];
  1062. mf->width = match->width;
  1063. mf->height = match->height;
  1064. if (size)
  1065. *size = match;
  1066. }
  1067. static int ov965x_set_fmt(struct v4l2_subdev *sd,
  1068. struct v4l2_subdev_pad_config *cfg,
  1069. struct v4l2_subdev_format *fmt)
  1070. {
  1071. unsigned int index = ARRAY_SIZE(ov965x_formats);
  1072. struct v4l2_mbus_framefmt *mf = &fmt->format;
  1073. struct ov965x *ov965x = to_ov965x(sd);
  1074. const struct ov965x_framesize *size = NULL;
  1075. int ret = 0;
  1076. __ov965x_try_frame_size(mf, &size);
  1077. while (--index)
  1078. if (ov965x_formats[index].code == mf->code)
  1079. break;
  1080. mf->colorspace = V4L2_COLORSPACE_JPEG;
  1081. mf->code = ov965x_formats[index].code;
  1082. mf->field = V4L2_FIELD_NONE;
  1083. mutex_lock(&ov965x->lock);
  1084. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  1085. if (cfg) {
  1086. mf = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
  1087. *mf = fmt->format;
  1088. }
  1089. } else {
  1090. if (ov965x->streaming) {
  1091. ret = -EBUSY;
  1092. } else {
  1093. ov965x->frame_size = size;
  1094. ov965x->format = fmt->format;
  1095. ov965x->tslb_reg = ov965x_formats[index].tslb_reg;
  1096. ov965x->apply_frame_fmt = 1;
  1097. }
  1098. }
  1099. if (!ret && fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
  1100. struct v4l2_subdev_frame_interval fiv = {
  1101. .interval = { 0, 1 }
  1102. };
  1103. /* Reset to minimum possible frame interval */
  1104. __ov965x_set_frame_interval(ov965x, &fiv);
  1105. }
  1106. mutex_unlock(&ov965x->lock);
  1107. if (!ret)
  1108. ov965x_update_exposure_ctrl(ov965x);
  1109. return ret;
  1110. }
  1111. static int ov965x_set_frame_size(struct ov965x *ov965x)
  1112. {
  1113. int i, ret = 0;
  1114. for (i = 0; ret == 0 && i < NUM_FMT_REGS; i++)
  1115. ret = ov965x_write(ov965x->client, frame_size_reg_addr[i],
  1116. ov965x->frame_size->regs[i]);
  1117. return ret;
  1118. }
  1119. static int __ov965x_set_params(struct ov965x *ov965x)
  1120. {
  1121. struct i2c_client *client = ov965x->client;
  1122. struct ov965x_ctrls *ctrls = &ov965x->ctrls;
  1123. int ret = 0;
  1124. u8 reg;
  1125. if (ov965x->apply_frame_fmt) {
  1126. reg = DEF_CLKRC + ov965x->fiv->clkrc_div;
  1127. ret = ov965x_write(client, REG_CLKRC, reg);
  1128. if (ret < 0)
  1129. return ret;
  1130. ret = ov965x_set_frame_size(ov965x);
  1131. if (ret < 0)
  1132. return ret;
  1133. ret = ov965x_read(client, REG_TSLB, &reg);
  1134. if (ret < 0)
  1135. return ret;
  1136. reg &= ~TSLB_YUYV_MASK;
  1137. reg |= ov965x->tslb_reg;
  1138. ret = ov965x_write(client, REG_TSLB, reg);
  1139. if (ret < 0)
  1140. return ret;
  1141. }
  1142. ret = ov965x_set_default_gamma_curve(ov965x);
  1143. if (ret < 0)
  1144. return ret;
  1145. ret = ov965x_set_color_matrix(ov965x);
  1146. if (ret < 0)
  1147. return ret;
  1148. /*
  1149. * Select manual banding filter, the filter will
  1150. * be enabled further if required.
  1151. */
  1152. ret = ov965x_read(client, REG_COM11, &reg);
  1153. if (!ret)
  1154. reg |= COM11_BANDING;
  1155. ret = ov965x_write(client, REG_COM11, reg);
  1156. if (ret < 0)
  1157. return ret;
  1158. /*
  1159. * Banding filter (REG_MBD value) needs to match selected
  1160. * resolution and frame rate, so it's always updated here.
  1161. */
  1162. return ov965x_set_banding_filter(ov965x, ctrls->light_freq->val);
  1163. }
  1164. static int ov965x_s_stream(struct v4l2_subdev *sd, int on)
  1165. {
  1166. struct i2c_client *client = v4l2_get_subdevdata(sd);
  1167. struct ov965x *ov965x = to_ov965x(sd);
  1168. struct ov965x_ctrls *ctrls = &ov965x->ctrls;
  1169. int ret = 0;
  1170. v4l2_dbg(1, debug, client, "%s: on: %d\n", __func__, on);
  1171. mutex_lock(&ov965x->lock);
  1172. if (ov965x->streaming == !on) {
  1173. if (on)
  1174. ret = __ov965x_set_params(ov965x);
  1175. if (!ret && ctrls->update) {
  1176. /*
  1177. * ov965x_s_ctrl callback takes the mutex
  1178. * so it needs to be released here.
  1179. */
  1180. mutex_unlock(&ov965x->lock);
  1181. ret = v4l2_ctrl_handler_setup(&ctrls->handler);
  1182. mutex_lock(&ov965x->lock);
  1183. if (!ret)
  1184. ctrls->update = 0;
  1185. }
  1186. if (!ret)
  1187. ret = ov965x_write(client, REG_COM2,
  1188. on ? 0x01 : 0x11);
  1189. }
  1190. if (!ret)
  1191. ov965x->streaming += on ? 1 : -1;
  1192. WARN_ON(ov965x->streaming < 0);
  1193. mutex_unlock(&ov965x->lock);
  1194. return ret;
  1195. }
  1196. /*
  1197. * V4L2 subdev internal operations
  1198. */
  1199. static int ov965x_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  1200. {
  1201. struct v4l2_mbus_framefmt *mf =
  1202. v4l2_subdev_get_try_format(sd, fh->pad, 0);
  1203. ov965x_get_default_format(mf);
  1204. return 0;
  1205. }
  1206. static const struct v4l2_subdev_pad_ops ov965x_pad_ops = {
  1207. .enum_mbus_code = ov965x_enum_mbus_code,
  1208. .enum_frame_size = ov965x_enum_frame_sizes,
  1209. .get_fmt = ov965x_get_fmt,
  1210. .set_fmt = ov965x_set_fmt,
  1211. };
  1212. static const struct v4l2_subdev_video_ops ov965x_video_ops = {
  1213. .s_stream = ov965x_s_stream,
  1214. .g_frame_interval = ov965x_g_frame_interval,
  1215. .s_frame_interval = ov965x_s_frame_interval,
  1216. };
  1217. static const struct v4l2_subdev_internal_ops ov965x_sd_internal_ops = {
  1218. .open = ov965x_open,
  1219. };
  1220. static const struct v4l2_subdev_core_ops ov965x_core_ops = {
  1221. .s_power = ov965x_s_power,
  1222. .log_status = v4l2_ctrl_subdev_log_status,
  1223. .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
  1224. .unsubscribe_event = v4l2_event_subdev_unsubscribe,
  1225. };
  1226. static const struct v4l2_subdev_ops ov965x_subdev_ops = {
  1227. .core = &ov965x_core_ops,
  1228. .pad = &ov965x_pad_ops,
  1229. .video = &ov965x_video_ops,
  1230. };
  1231. /*
  1232. * Reset and power down GPIOs configuration
  1233. */
  1234. static int ov965x_configure_gpios_pdata(struct ov965x *ov965x,
  1235. const struct ov9650_platform_data *pdata)
  1236. {
  1237. int ret, i;
  1238. int gpios[NUM_GPIOS];
  1239. gpios[GPIO_PWDN] = pdata->gpio_pwdn;
  1240. gpios[GPIO_RST] = pdata->gpio_reset;
  1241. for (i = 0; i < ARRAY_SIZE(ov965x->gpios); i++) {
  1242. int gpio = gpios[i];
  1243. if (!gpio_is_valid(gpio))
  1244. continue;
  1245. ret = devm_gpio_request_one(&ov965x->client->dev, gpio,
  1246. GPIOF_OUT_INIT_HIGH, "OV965X");
  1247. if (ret < 0)
  1248. return ret;
  1249. v4l2_dbg(1, debug, &ov965x->sd, "set gpio %d to 1\n", gpio);
  1250. gpio_set_value_cansleep(gpio, 1);
  1251. gpio_export(gpio, 0);
  1252. ov965x->gpios[i] = gpio_to_desc(gpio);
  1253. }
  1254. return 0;
  1255. }
  1256. static int ov965x_configure_gpios(struct ov965x *ov965x)
  1257. {
  1258. struct device *dev = &ov965x->client->dev;
  1259. ov965x->gpios[GPIO_PWDN] = devm_gpiod_get_optional(dev, "powerdown",
  1260. GPIOD_OUT_HIGH);
  1261. if (IS_ERR(ov965x->gpios[GPIO_PWDN])) {
  1262. dev_info(dev, "can't get %s GPIO\n", "powerdown");
  1263. return PTR_ERR(ov965x->gpios[GPIO_PWDN]);
  1264. }
  1265. ov965x->gpios[GPIO_RST] = devm_gpiod_get_optional(dev, "reset",
  1266. GPIOD_OUT_HIGH);
  1267. if (IS_ERR(ov965x->gpios[GPIO_RST])) {
  1268. dev_info(dev, "can't get %s GPIO\n", "reset");
  1269. return PTR_ERR(ov965x->gpios[GPIO_RST]);
  1270. }
  1271. return 0;
  1272. }
  1273. static int ov965x_detect_sensor(struct v4l2_subdev *sd)
  1274. {
  1275. struct i2c_client *client = v4l2_get_subdevdata(sd);
  1276. struct ov965x *ov965x = to_ov965x(sd);
  1277. u8 pid, ver;
  1278. int ret;
  1279. mutex_lock(&ov965x->lock);
  1280. ret = __ov965x_set_power(ov965x, 1);
  1281. if (ret)
  1282. goto out;
  1283. msleep(25);
  1284. /* Check sensor revision */
  1285. ret = ov965x_read(client, REG_PID, &pid);
  1286. if (!ret)
  1287. ret = ov965x_read(client, REG_VER, &ver);
  1288. __ov965x_set_power(ov965x, 0);
  1289. if (!ret) {
  1290. ov965x->id = OV965X_ID(pid, ver);
  1291. if (ov965x->id == OV9650_ID || ov965x->id == OV9652_ID) {
  1292. v4l2_info(sd, "Found OV%04X sensor\n", ov965x->id);
  1293. } else {
  1294. v4l2_err(sd, "Sensor detection failed (%04X, %d)\n",
  1295. ov965x->id, ret);
  1296. ret = -ENODEV;
  1297. }
  1298. }
  1299. out:
  1300. mutex_unlock(&ov965x->lock);
  1301. return ret;
  1302. }
  1303. static int ov965x_probe(struct i2c_client *client,
  1304. const struct i2c_device_id *id)
  1305. {
  1306. const struct ov9650_platform_data *pdata = client->dev.platform_data;
  1307. struct v4l2_subdev *sd;
  1308. struct ov965x *ov965x;
  1309. int ret;
  1310. ov965x = devm_kzalloc(&client->dev, sizeof(*ov965x), GFP_KERNEL);
  1311. if (!ov965x)
  1312. return -ENOMEM;
  1313. ov965x->client = client;
  1314. if (pdata) {
  1315. if (pdata->mclk_frequency == 0) {
  1316. dev_err(&client->dev, "MCLK frequency not specified\n");
  1317. return -EINVAL;
  1318. }
  1319. ov965x->mclk_frequency = pdata->mclk_frequency;
  1320. ret = ov965x_configure_gpios_pdata(ov965x, pdata);
  1321. if (ret < 0)
  1322. return ret;
  1323. } else if (dev_fwnode(&client->dev)) {
  1324. ov965x->clk = devm_clk_get(&ov965x->client->dev, NULL);
  1325. if (IS_ERR(ov965x->clk))
  1326. return PTR_ERR(ov965x->clk);
  1327. ov965x->mclk_frequency = clk_get_rate(ov965x->clk);
  1328. ret = ov965x_configure_gpios(ov965x);
  1329. if (ret < 0)
  1330. return ret;
  1331. } else {
  1332. dev_err(&client->dev,
  1333. "Neither platform data nor device property specified\n");
  1334. return -EINVAL;
  1335. }
  1336. mutex_init(&ov965x->lock);
  1337. sd = &ov965x->sd;
  1338. v4l2_i2c_subdev_init(sd, client, &ov965x_subdev_ops);
  1339. strlcpy(sd->name, DRIVER_NAME, sizeof(sd->name));
  1340. sd->internal_ops = &ov965x_sd_internal_ops;
  1341. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
  1342. V4L2_SUBDEV_FL_HAS_EVENTS;
  1343. ov965x->pad.flags = MEDIA_PAD_FL_SOURCE;
  1344. sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
  1345. ret = media_entity_pads_init(&sd->entity, 1, &ov965x->pad);
  1346. if (ret < 0)
  1347. goto err_mutex;
  1348. ret = ov965x_initialize_controls(ov965x);
  1349. if (ret < 0)
  1350. goto err_me;
  1351. ov965x_get_default_format(&ov965x->format);
  1352. ov965x->frame_size = &ov965x_framesizes[0];
  1353. ov965x->fiv = &ov965x_intervals[0];
  1354. ret = ov965x_detect_sensor(sd);
  1355. if (ret < 0)
  1356. goto err_ctrls;
  1357. /* Update exposure time min/max to match frame format */
  1358. ov965x_update_exposure_ctrl(ov965x);
  1359. ret = v4l2_async_register_subdev(sd);
  1360. if (ret < 0)
  1361. goto err_ctrls;
  1362. return 0;
  1363. err_ctrls:
  1364. v4l2_ctrl_handler_free(sd->ctrl_handler);
  1365. err_me:
  1366. media_entity_cleanup(&sd->entity);
  1367. err_mutex:
  1368. mutex_destroy(&ov965x->lock);
  1369. return ret;
  1370. }
  1371. static int ov965x_remove(struct i2c_client *client)
  1372. {
  1373. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1374. struct ov965x *ov965x = to_ov965x(sd);
  1375. v4l2_async_unregister_subdev(sd);
  1376. v4l2_ctrl_handler_free(sd->ctrl_handler);
  1377. media_entity_cleanup(&sd->entity);
  1378. mutex_destroy(&ov965x->lock);
  1379. return 0;
  1380. }
  1381. static const struct i2c_device_id ov965x_id[] = {
  1382. { "OV9650", 0 },
  1383. { "OV9652", 0 },
  1384. { /* sentinel */ }
  1385. };
  1386. MODULE_DEVICE_TABLE(i2c, ov965x_id);
  1387. #if IS_ENABLED(CONFIG_OF)
  1388. static const struct of_device_id ov965x_of_match[] = {
  1389. { .compatible = "ovti,ov9650", },
  1390. { .compatible = "ovti,ov9652", },
  1391. { /* sentinel */ }
  1392. };
  1393. MODULE_DEVICE_TABLE(of, ov965x_of_match);
  1394. #endif
  1395. static struct i2c_driver ov965x_i2c_driver = {
  1396. .driver = {
  1397. .name = DRIVER_NAME,
  1398. .of_match_table = of_match_ptr(ov965x_of_match),
  1399. },
  1400. .probe = ov965x_probe,
  1401. .remove = ov965x_remove,
  1402. .id_table = ov965x_id,
  1403. };
  1404. module_i2c_driver(ov965x_i2c_driver);
  1405. MODULE_AUTHOR("Sylwester Nawrocki <sylvester.nawrocki@gmail.com>");
  1406. MODULE_DESCRIPTION("OV9650/OV9652 CMOS Image Sensor driver");
  1407. MODULE_LICENSE("GPL");