PageRenderTime 33ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/media/video/sun4i_csi/device/mt9m112.c

https://bitbucket.org/ndreys/linux-sunxi
C | 2056 lines | 1529 code | 272 blank | 255 comment | 97 complexity | 4a1a6ce1e3a8ff10cbabd17db3664c2c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * drivers/media/video/sun4i_csi/device/mt9m112.c
  3. *
  4. * (C) Copyright 2007-2012
  5. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. /*
  23. * A V4L2 driver for Micron mt9m112 cameras.
  24. *
  25. */
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/slab.h>
  29. #include <linux/i2c.h>
  30. #include <linux/delay.h>
  31. #include <linux/videodev2.h>
  32. #include <linux/clk.h>
  33. #include <media/v4l2-device.h>
  34. #include <media/v4l2-chip-ident.h>
  35. #include <media/v4l2-mediabus.h>//linux-3.0
  36. #include <linux/io.h>
  37. //#include <mach/gpio_v2.h>
  38. #include <mach/sys_config.h>
  39. #include <linux/regulator/consumer.h>
  40. #include <mach/system.h>
  41. #include "../include/sun4i_csi_core.h"
  42. #include "../include/sun4i_dev_csi.h"
  43. MODULE_AUTHOR("raymonxiu");
  44. MODULE_DESCRIPTION("A low-level driver for Micron mt9m112 sensors");
  45. MODULE_LICENSE("GPL");
  46. //for internel driver debug
  47. #define DEV_DBG_EN 0
  48. #if(DEV_DBG_EN == 1)
  49. #define csi_dev_dbg(x,arg...) printk(KERN_INFO"[CSI_DEBUG][MT9M112]"x,##arg)
  50. #else
  51. #define csi_dev_dbg(x,arg...)
  52. #endif
  53. #define csi_dev_err(x,arg...) printk(KERN_INFO"[CSI_ERR][MT9M112]"x,##arg)
  54. #define csi_dev_print(x,arg...) printk(KERN_INFO"[CSI][MT9M112]"x,##arg)
  55. #define MCLK (24*1000*1000)
  56. //#define MCLK (49.5*1000*1000)
  57. #define VREF_POL CSI_HIGH
  58. #define HREF_POL CSI_HIGH
  59. #define CLK_POL CSI_RISING
  60. #define IO_CFG 0 //0 for csi0
  61. //define the voltage level of control signal
  62. #define CSI_STBY_ON 1
  63. #define CSI_STBY_OFF 0
  64. #define CSI_RST_ON 0
  65. #define CSI_RST_OFF 1
  66. #define CSI_PWR_ON 1
  67. #define CSI_PWR_OFF 0
  68. #define V4L2_IDENT_SENSOR 0x1320
  69. #define REG_TERM 0xff
  70. #define VAL_TERM 0xff
  71. #define REG_ADDR_STEP 1
  72. #define REG_DATA_STEP 2
  73. #define REG_STEP (REG_ADDR_STEP+REG_DATA_STEP)
  74. /*
  75. * Basic window sizes. These probably belong somewhere more globally
  76. * useful.
  77. */
  78. #define SXGA_WIDTH 1280
  79. #define SXGA_HEIGHT 1024
  80. #define VGA_WIDTH 640
  81. #define VGA_HEIGHT 480
  82. #define QVGA_WIDTH 320
  83. #define QVGA_HEIGHT 240
  84. #define CIF_WIDTH 352
  85. #define CIF_HEIGHT 288
  86. #define QCIF_WIDTH 176
  87. #define QCIF_HEIGHT 144
  88. /*
  89. * Our nominal (default) frame rate.
  90. */
  91. #define SENSOR_FRAME_RATE 25
  92. /*
  93. * The Micron mt9m112 sits on i2c with ID 0xBA
  94. */
  95. #define I2C_ADDR 0xBA
  96. /* Registers */
  97. /*
  98. * Information we maintain about a known sensor.
  99. */
  100. struct sensor_format_struct; /* coming later */
  101. __csi_subdev_info_t ccm_info_con =
  102. {
  103. .mclk = MCLK,
  104. .vref = VREF_POL,
  105. .href = HREF_POL,
  106. .clock = CLK_POL,
  107. .iocfg = IO_CFG,
  108. };
  109. struct sensor_info {
  110. struct v4l2_subdev sd;
  111. struct sensor_format_struct *fmt; /* Current format */
  112. __csi_subdev_info_t *ccm_info;
  113. int width;
  114. int height;
  115. int brightness;
  116. int contrast;
  117. int saturation;
  118. int hue;
  119. int hflip;
  120. int vflip;
  121. int gain;
  122. int autogain;
  123. int exp;
  124. enum v4l2_exposure_auto_type autoexp;
  125. int autowb;
  126. enum v4l2_whiteblance wb;
  127. enum v4l2_colorfx clrfx;
  128. enum v4l2_flash_mode flash_mode;
  129. u8 clkrc; /* Clock divider value */
  130. };
  131. static inline struct sensor_info *to_state(struct v4l2_subdev *sd)
  132. {
  133. return container_of(sd, struct sensor_info, sd);
  134. }
  135. struct regval_list {
  136. unsigned char reg_num[REG_ADDR_STEP];
  137. unsigned char value[REG_DATA_STEP];
  138. };
  139. /*
  140. * The default register settings
  141. *
  142. */
  143. static struct regval_list sensor_default_regs[] = {
  144. #if 1 //MCLK == 24M
  145. {{0xf0},{0x00,0x00}},
  146. {{0x66},{0x10,0x01}},
  147. {{0x67},{0x05,0x01}},
  148. {{0x65},{0xa0,0x00}},
  149. {{0xff},{0x00,0x64}},
  150. {{0x65},{0x20,0x00}},
  151. {{0xff},{0x00,0x64}},
  152. #endif
  153. {{0xf0},{0x00,0x00}},
  154. {{0x0d},{0x00,0x09}},
  155. {{0xff},{0x00,0x20}},
  156. {{0x0d},{0x00,0x08}},
  157. {{0xf0},{0x00,0x00}},
  158. {{0x01},{0x00,0x24}},
  159. {{0x03},{0x04,0x00}},// default value
  160. {{0x30},{0x04,0x2a}},
  161. {{0xf0},{0x00,0x01}},
  162. {{0x05},{0x00,0x0f}},
  163. {{0x25},{0x00,0x4d}},// saturation adjustment, default value 0x4d
  164. {{0x3b},{0x04,0x30}},//0x0436
  165. {{0x3c},{0x04,0x00}},
  166. {{0x47},{0x32,0x2e}},
  167. {{0x9d},{0x3c,0xe0}},
  168. {{0xf0},{0x00,0x02}},
  169. {{0x28},{0xef,0x02}},//0xef3e
  170. {{0x06},{0x74,0x8e}},
  171. {{0x02},{0x00,0xee}},// base matrix signs
  172. {{0x15},{0x00,0xd9}},// delta coefficients signs
  173. {{0x09},{0x00,0x67}},//k1
  174. {{0x0a},{0x00,0x9a}},//k2
  175. {{0x0b},{0x00,0x28}},//k3
  176. {{0x0c},{0x00,0x30}},//k4
  177. {{0x0d},{0x00,0xca}},//k5
  178. {{0x0e},{0x00,0x37}},//k6
  179. {{0x0f},{0x00,0x1a}},//k7
  180. {{0x10},{0x00,0x65}},//k8
  181. {{0x11},{0x00,0x86}},//k9
  182. {{0x16},{0x00,0x5e}},//d1 0x0062
  183. {{0x17},{0x00,0x84}},//d2
  184. {{0x18},{0x00,0x4d}},//d3
  185. {{0x19},{0x00,0x24}},//d4
  186. {{0x1a},{0x00,0x1f}},//d5
  187. {{0x1b},{0x00,0x2f}},//d6
  188. {{0x1c},{0x00,0x04}},//d7
  189. {{0x1d},{0x00,0x23}},//d8
  190. {{0x1e},{0x00,0x10}},//d9
  191. {{0x03},{0x39,0x22}},// base matrix scale k1-k5
  192. {{0x04},{0x05,0x24}},// base matrix scale k6-k9 0x04e4
  193. {{0xf0},{0x00,0x02}},
  194. {{0x1f},{0x01,0x80}},
  195. {{0x20},{0xc8,0x14}},//0xdc0c
  196. {{0x21},{0x80,0x80}},
  197. {{0x22},{0x90,0x80}},
  198. {{0x23},{0x88,0x78}},
  199. {{0x26},{0x80,0x00}},
  200. {{0x27},{0x80,0x08}},
  201. {{0x2e},{0x0c,0x44}},// 0x0d20
  202. {{0x3e},{0x1c,0xff}},
  203. {{0x46},{0x00,0xb0}},
  204. {{0x5b},{0x80,0x02}},
  205. {{0x5c},{0x11,0x0c}},
  206. {{0x5d},{0x15,0x10}},
  207. {{0x5e},{0x53,0x4c}},
  208. {{0x5f},{0x2b,0x21}},
  209. {{0x24},{0x7f,0x40}},
  210. {{0x60},{0x00,0x02}},
  211. {{0x62},{0x10,0x10}},
  212. {{0x65},{0x00,0x00}},
  213. {{0xdc},{0x0f,0xf8}},
  214. {{0xdd},{0x0c,0xe0}},
  215. {{0xf0},{0x00,0x01}},
  216. {{0x47},{0x20,0x2e}},
  217. {{0x80},{0x00,0x06}},// lens correction control
  218. {{0x81},{0x00,0x00}},// vertical red knee 0 and initial value 0x0009
  219. {{0x82},{0xfe,0x05}},// vertical red knees 2 and 1
  220. {{0x83},{0x00,0x00}},// vertical red knees 4 and 30x00ff
  221. {{0x84},{0x0c,0x00}},// vertical green knee 0 and initial value
  222. {{0x85},{0xfe,0x02}},// vertical green knees 2 and 1
  223. {{0x86},{0x00,0xff}},// vertical green knees 4 and 3
  224. {{0x87},{0x07,0x01}},// vertical blue knee 0 and initial value 1003
  225. {{0x88},{0xfc,0x06}},// vertical blue knees 2 and 1
  226. {{0x89},{0x00,0xff}},// vertical blue knees 4 and 3
  227. {{0x8a},{0x08,0x01}},// horizontal red knee 0 and initial value
  228. {{0x8b},{0x03,0x0e}},// horizontal red knees 2 and 1
  229. {{0x8c},{0xfe,0xfd}},// horizontal red knees 4 and 3
  230. {{0x8d},{0x00,0xff}},// horizontal red knee 5
  231. {{0x8e},{0x06,0x01}},// horizontal green knee 0 and initial value
  232. {{0x8f},{0x04,0x0b}},// horizontal green knees 2 and 1
  233. {{0x90},{0xfe,0xfb}},// horizontal green knees 4 and 3
  234. {{0x91},{0x00,0xfe}},// horizontal green knee 5
  235. {{0x92},{0x06,0x00}},// horizontal blue knee 0 and initial value
  236. {{0x93},{0x04,0x0b}},// horizontal blue knees 2 and 1
  237. {{0x94},{0xfe,0xfd}},// horizontal blue knees 4 and 3
  238. {{0x95},{0x00,0xff}},// horizontal blue knees 5
  239. {{0xb6},{0x02,0x04}},// lens vertical red knees 6 and 5
  240. {{0xb7},{0xfb,0xfa}},// lens vertical red knees 8 and 7
  241. {{0xb8},{0x05,0x03}},// lens vertical green knees 6 and 5
  242. {{0xb9},{0xfa,0xf8}},// lens vertical green knees 8 and 7
  243. {{0xba},{0x04,0x01}},// lens vertical blue knees 6 and 5
  244. {{0xbb},{0xfe,0xf8}},// lens vertical blue knees 8 and 7
  245. {{0xbc},{0xff,0x01}},// lens horizontal red knees 7 and 6
  246. {{0xbd},{0xf4,0xff}},// lens horizontal red knees 9 and 8
  247. {{0xbe},{0x00,0xfb}},// lens horizontal red knee 10
  248. {{0xbf},{0x00,0x00}},// lens horizontal green knees 7 and 6
  249. {{0xc0},{0xf8,0xfd}},// lens horizontal green knees 9 and 8
  250. {{0xc1},{0x00,0xf7}},// lens horizontal green knee 10
  251. {{0xc2},{0x01,0xff}},// lens horizontal blue knees 7 and 6
  252. {{0xc3},{0xf5,0xfc}},// lens horizontal blue knees 9 and 8
  253. {{0xc4},{0x00,0xfa}},// lens horizontal blue knee 10
  254. {{0x06},{0x74,0x8e}},
  255. {{0x9d},{0x3c,0xe0}},// defect correction control
  256. {{0xf0},{0x00,0x02}},
  257. {{0x2e},{0x0d,0x3a}},// 0x0d32
  258. {{0x37},{0x00,0x81}},
  259. {{0x36},{0x78,0x10}},
  260. {{0xf0},{0x00,0x01}},
  261. {{0x06},{0xf4,0x8e}},
  262. {{0xf0},{0x00,0x01}},
  263. {{0x06},{0x64,0x8e}},
  264. {{0xf0},{0x00,0x02}},
  265. {{0x5b},{0x00,0x01}},//0x0003
  266. {{0xf0},{0x00,0x00}},
  267. {{0x20},{0x01,0x00}},
  268. {{0x21},{0x80,0x00}},
  269. {{0x22},{0x09,0x0d}},
  270. };
  271. static struct regval_list sensor_oe_disable_regs[] = {
  272. {{0xf0},{0x00,0x00}},
  273. {{0x0d},{0x00,0x18}},
  274. };
  275. static struct regval_list sensor_sxga_regs[] = {
  276. {{0xf0},{0x00,0x00}},
  277. {{0x05},{0x01,0x40}},// horizontal blank
  278. {{0x06},{0x00,0x0d}},
  279. {{0xf0},{0x00,0x02}},
  280. {{0xc8},{0x1f,0x0b}},
  281. {{0x9c},{0xd1,0x00}},// auto exposure speed B
  282. {{0x59},{0x02,0x71}},
  283. {{0x5a},{0x02,0x71}},
  284. {{0xf0},{0x00,0x00}},
  285. //{{0x20},{0x01,0x00}},
  286. //{{0x22},{0x09,0x0d}},
  287. {{0x68},{0x00,0x70}},
  288. {{0xf0},{0x00,0x01}},
  289. {{0xa1},{0x05,0x00}},// horizontal output size B
  290. {{0xa4},{0x04,0x00}},// vertical output size B
  291. {{0x9b},{0x02,0x02}},
  292. {{0xdc},{0x11,0x05}},// gamma start B
  293. {{0xdd},{0x5d,0x33}},
  294. {{0xde},{0xad,0x8d}},
  295. {{0xdf},{0xd6,0xc4}},
  296. {{0xe0},{0xf3,0xe6}},
  297. {{0xe1},{0xff,0x00}},// gamma end B
  298. {{0xf0},{0x00,0x00}},
  299. };
  300. static struct regval_list sensor_vga_regs[] = {
  301. {{0xf0},{0x00,0x00}},
  302. {{0x07},{0x03,0x74}}, //horizontal blank
  303. {{0x08},{0x00,0x09}},
  304. {{0xf0},{0x00,0x02}},
  305. {{0xc8},{0x00,0x00}},
  306. {{0x2f},{0xd1,0x00}},// auto exposure speed A
  307. {{0x57},{0x02,0x71}},
  308. {{0x58},{0x02,0x71}},
  309. {{0xf0},{0x00,0x00}},
  310. //{{0x21},{0x80,0x00}},
  311. //{{0x22},{0x09,0x0d}},
  312. {{0x68},{0x00,0x70}},
  313. {{0xf0},{0x00,0x01}},
  314. {{0xa7},{0x02,0x80}},// horizontal output size A
  315. {{0xaa},{0x02,0x00}},// vertical output size A
  316. {{0x3a},{0x02,0x02}},
  317. {{0x53},{0x11,0x05}},// gamma start A
  318. {{0x54},{0x5d,0x33}},
  319. {{0x55},{0xad,0x8d}},
  320. {{0x56},{0xd6,0xc4}},
  321. {{0x57},{0xf3,0xe6}},
  322. {{0x58},{0xff,0x00}},// gamma end A
  323. {{0xf0},{0x00,0x00}},
  324. };
  325. /*
  326. * The white balance settings
  327. * Here only tune the R G B channel gain.
  328. * The white balance enalbe bit is modified in sensor_s_autowb and sensor_s_wb
  329. */
  330. //static struct regval_list sensor_wb_auto_regs[] = {
  331. // //NULL
  332. //};
  333. static struct regval_list sensor_wb_cloud_regs[] = {
  334. //NULL
  335. };
  336. static struct regval_list sensor_wb_daylight_regs[] = {
  337. //tai yang guang
  338. //NULL
  339. };
  340. static struct regval_list sensor_wb_incandescence_regs[] = {
  341. //bai re guang
  342. //NULL
  343. };
  344. static struct regval_list sensor_wb_fluorescent_regs[] = {
  345. //ri guang deng
  346. //NULL
  347. };
  348. static struct regval_list sensor_wb_tungsten_regs[] = {
  349. //wu si deng
  350. //NULL
  351. };
  352. /*
  353. * The color effect settings
  354. */
  355. static struct regval_list sensor_colorfx_none_regs[] = {
  356. {{0xf0},{0x00,0x01}},
  357. {{0xe2},{0x70,0x00}},
  358. };
  359. static struct regval_list sensor_colorfx_bw_regs[] = {
  360. {{0xf0},{0x00,0x01}},
  361. {{0xe2},{0x70,0x01}},
  362. };
  363. static struct regval_list sensor_colorfx_sepia_regs[] = {
  364. {{0xf0},{0x00,0x01}},
  365. {{0xe2},{0x70,0x02}},
  366. };
  367. static struct regval_list sensor_colorfx_negative_regs[] = {
  368. {{0xf0},{0x00,0x01}},
  369. {{0xe2},{0x70,0x03}},
  370. };
  371. static struct regval_list sensor_colorfx_emboss_regs[] = {
  372. //NULL
  373. };
  374. static struct regval_list sensor_colorfx_sketch_regs[] = {
  375. //NULL
  376. };
  377. static struct regval_list sensor_colorfx_sky_blue_regs[] = {
  378. //NULL
  379. };
  380. static struct regval_list sensor_colorfx_grass_green_regs[] = {
  381. //NULL
  382. };
  383. static struct regval_list sensor_colorfx_skin_whiten_regs[] = {
  384. //NULL
  385. };
  386. static struct regval_list sensor_colorfx_vivid_regs[] = {
  387. //NULL
  388. };
  389. /*
  390. * The brightness setttings
  391. */
  392. static struct regval_list sensor_brightness_neg4_regs[] = {
  393. //NULL
  394. };
  395. static struct regval_list sensor_brightness_neg3_regs[] = {
  396. //NULL
  397. };
  398. static struct regval_list sensor_brightness_neg2_regs[] = {
  399. //NULL
  400. };
  401. static struct regval_list sensor_brightness_neg1_regs[] = {
  402. //NULL
  403. };
  404. static struct regval_list sensor_brightness_zero_regs[] = {
  405. //NULL
  406. };
  407. static struct regval_list sensor_brightness_pos1_regs[] = {
  408. //NULL
  409. };
  410. static struct regval_list sensor_brightness_pos2_regs[] = {
  411. //NULL
  412. };
  413. static struct regval_list sensor_brightness_pos3_regs[] = {
  414. //NULL
  415. };
  416. static struct regval_list sensor_brightness_pos4_regs[] = {
  417. //NULL
  418. };
  419. /*
  420. * The contrast setttings
  421. */
  422. static struct regval_list sensor_contrast_neg4_regs[] = {
  423. //NULL
  424. };
  425. static struct regval_list sensor_contrast_neg3_regs[] = {
  426. //NULL
  427. };
  428. static struct regval_list sensor_contrast_neg2_regs[] = {
  429. //NULL
  430. };
  431. static struct regval_list sensor_contrast_neg1_regs[] = {
  432. //NULL
  433. };
  434. static struct regval_list sensor_contrast_zero_regs[] = {
  435. //NULL
  436. };
  437. static struct regval_list sensor_contrast_pos1_regs[] = {
  438. //NULL
  439. };
  440. static struct regval_list sensor_contrast_pos2_regs[] = {
  441. //NULL
  442. };
  443. static struct regval_list sensor_contrast_pos3_regs[] = {
  444. //NULL
  445. };
  446. static struct regval_list sensor_contrast_pos4_regs[] = {
  447. //NULL
  448. };
  449. /*
  450. * The saturation setttings
  451. */
  452. static struct regval_list sensor_saturation_neg4_regs[] = {
  453. //NULL
  454. };
  455. static struct regval_list sensor_saturation_neg3_regs[] = {
  456. //NULL
  457. };
  458. static struct regval_list sensor_saturation_neg2_regs[] = {
  459. //NULL
  460. };
  461. static struct regval_list sensor_saturation_neg1_regs[] = {
  462. //NULL
  463. };
  464. static struct regval_list sensor_saturation_zero_regs[] = {
  465. //NULL
  466. };
  467. static struct regval_list sensor_saturation_pos1_regs[] = {
  468. //NULL
  469. };
  470. static struct regval_list sensor_saturation_pos2_regs[] = {
  471. //NULL
  472. };
  473. static struct regval_list sensor_saturation_pos3_regs[] = {
  474. //NULL
  475. };
  476. static struct regval_list sensor_saturation_pos4_regs[] = {
  477. //NULL
  478. };
  479. /*
  480. * The exposure target setttings
  481. */
  482. static struct regval_list sensor_ev_neg4_regs[] = {
  483. //NULL
  484. };
  485. static struct regval_list sensor_ev_neg3_regs[] = {
  486. //NULL
  487. };
  488. static struct regval_list sensor_ev_neg2_regs[] = {
  489. //NULL
  490. };
  491. static struct regval_list sensor_ev_neg1_regs[] = {
  492. //NULL
  493. };
  494. static struct regval_list sensor_ev_zero_regs[] = {
  495. //NULL
  496. };
  497. static struct regval_list sensor_ev_pos1_regs[] = {
  498. //NULL
  499. };
  500. static struct regval_list sensor_ev_pos2_regs[] = {
  501. //NULL
  502. };
  503. static struct regval_list sensor_ev_pos3_regs[] = {
  504. //NULL
  505. };
  506. static struct regval_list sensor_ev_pos4_regs[] = {
  507. //NULL
  508. };
  509. /*
  510. * Here we'll try to encapsulate the changes for just the output
  511. * video format.
  512. *
  513. */
  514. static struct regval_list sensor_fmt_yuv422_yuyv[] = {
  515. {{0xf0},{0x00,0x01}}, //Page 1
  516. {{0x9b},{0x02,0x02}}, //Context B YCbYCr
  517. {{0x3a},{0x02,0x02}}, //Context A YCbYCr
  518. };
  519. static struct regval_list sensor_fmt_yuv422_yvyu[] = {
  520. {{0xf0},{0x00,0x01}}, //Page 1
  521. {{0x9b},{0x02,0x03}}, //Context B YCrYCb
  522. {{0x3a},{0x02,0x03}}, //Context A YCrYCb
  523. };
  524. static struct regval_list sensor_fmt_yuv422_vyuy[] = {
  525. {{0xf0},{0x00,0x01}}, //Page 1
  526. {{0x9b},{0x02,0x01}}, //Context B CrYCbY
  527. {{0x3a},{0x02,0x01}}, //Context A CrYCbY
  528. };
  529. static struct regval_list sensor_fmt_yuv422_uyvy[] = {
  530. {{0xf0},{0x00,0x01}}, //Page 1
  531. {{0x9b},{0x02,0x00}}, //Context B CbYCrY
  532. {{0x3a},{0x02,0x00}}, //Context A CbYCrY
  533. };
  534. //static struct regval_list sensor_fmt_raw[] = {
  535. //
  536. //};
  537. /*
  538. * Low-level register I/O.
  539. *
  540. */
  541. /*
  542. * On most platforms, we'd rather do straight i2c I/O.
  543. */
  544. static int sensor_read(struct v4l2_subdev *sd, unsigned char *reg,
  545. unsigned char *value)
  546. {
  547. struct i2c_client *client = v4l2_get_subdevdata(sd);
  548. u8 data[REG_STEP];
  549. struct i2c_msg msg;
  550. int ret,i;
  551. for(i = 0; i < REG_ADDR_STEP; i++)
  552. data[i] = reg[i];
  553. data[REG_ADDR_STEP] = 0xff;
  554. /*
  555. * Send out the register address...
  556. */
  557. msg.addr = client->addr;
  558. msg.flags = 0;
  559. msg.len = REG_ADDR_STEP;
  560. msg.buf = data;
  561. ret = i2c_transfer(client->adapter, &msg, 1);
  562. if (ret < 0) {
  563. csi_dev_err("Error %d on register write\n", ret);
  564. return ret;
  565. }
  566. /*
  567. * ...then read back the result.
  568. */
  569. msg.flags = I2C_M_RD;
  570. msg.len = REG_DATA_STEP;
  571. msg.buf = &data[REG_ADDR_STEP];
  572. ret = i2c_transfer(client->adapter, &msg, 1);
  573. if (ret >= 0) {
  574. for(i = 0; i < REG_DATA_STEP; i++)
  575. value[i] = data[i+REG_ADDR_STEP];
  576. ret = 0;
  577. }
  578. else {
  579. csi_dev_err("Error %d on register read\n", ret);
  580. }
  581. return ret;
  582. }
  583. static int sensor_write(struct v4l2_subdev *sd, unsigned char *reg,
  584. unsigned char *value)
  585. {
  586. struct i2c_client *client = v4l2_get_subdevdata(sd);
  587. struct i2c_msg msg;
  588. unsigned char data[REG_STEP];
  589. int ret,i;
  590. for(i = 0; i < REG_ADDR_STEP; i++)
  591. data[i] = reg[i];
  592. for(i = REG_ADDR_STEP; i < REG_STEP; i++)
  593. data[i] = value[i-REG_ADDR_STEP];
  594. msg.addr = client->addr;
  595. msg.flags = 0;
  596. msg.len = REG_STEP;
  597. msg.buf = data;
  598. ret = i2c_transfer(client->adapter, &msg, 1);
  599. if (ret > 0) {
  600. ret = 0;
  601. }
  602. else if (ret < 0) {
  603. csi_dev_err("sensor_write error!\n");
  604. }
  605. return ret;
  606. }
  607. /*
  608. * Write a list of register settings;
  609. */
  610. static int sensor_write_array(struct v4l2_subdev *sd, struct regval_list *vals , uint size)
  611. {
  612. int i,ret;
  613. if (size == 0)
  614. return -EINVAL;
  615. for(i = 0; i < size ; i++)
  616. {
  617. if(vals->reg_num[0] == 0xff)
  618. msleep(vals->value[0] * 256 + vals->value[1]);
  619. else {
  620. ret = sensor_write(sd, vals->reg_num, vals->value);
  621. if (ret < 0)
  622. {
  623. csi_dev_err("sensor_write_err!\n");
  624. return ret;
  625. }
  626. }
  627. vals++;
  628. }
  629. return 0;
  630. }
  631. /*
  632. * Stuff that knows about the sensor.
  633. */
  634. static int sensor_power(struct v4l2_subdev *sd, int on)
  635. {
  636. struct csi_dev *dev=(struct csi_dev *)dev_get_drvdata(sd->v4l2_dev->dev);
  637. struct sensor_info *info = to_state(sd);
  638. char csi_stby_str[32],csi_power_str[32],csi_reset_str[32];
  639. int ret;
  640. if(info->ccm_info->iocfg == 0) {
  641. strcpy(csi_stby_str,"csi_stby");
  642. strcpy(csi_power_str,"csi_power_en");
  643. strcpy(csi_reset_str,"csi_reset");
  644. } else if(info->ccm_info->iocfg == 1) {
  645. strcpy(csi_stby_str,"csi_stby_b");
  646. strcpy(csi_power_str,"csi_power_en_b");
  647. strcpy(csi_reset_str,"csi_reset_b");
  648. }
  649. switch(on)
  650. {
  651. case CSI_SUBDEV_STBY_ON:
  652. csi_dev_dbg("CSI_SUBDEV_STBY_ON\n");
  653. //reset off io
  654. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  655. msleep(10);
  656. //active mclk before stadby in
  657. clk_enable(dev->csi_module_clk);
  658. msleep(100);
  659. //disable io oe
  660. csi_dev_print("disalbe oe!\n");
  661. ret = sensor_write_array(sd, sensor_oe_disable_regs , ARRAY_SIZE(sensor_oe_disable_regs));
  662. if(ret < 0)
  663. csi_dev_err("disalbe oe falied!\n");
  664. //standby on io
  665. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_ON,csi_stby_str);
  666. msleep(100);
  667. // gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_OFF,csi_stby_str);
  668. // msleep(100);
  669. // gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_ON,csi_stby_str);
  670. // msleep(100);
  671. //inactive mclk after stadby in
  672. clk_disable(dev->csi_module_clk);
  673. // gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
  674. // msleep(10);
  675. break;
  676. case CSI_SUBDEV_STBY_OFF:
  677. csi_dev_dbg("CSI_SUBDEV_STBY_OFF\n");
  678. //active mclk before stadby out
  679. clk_enable(dev->csi_module_clk);
  680. msleep(10);
  681. //reset off io
  682. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  683. msleep(10);
  684. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
  685. msleep(100);
  686. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  687. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_OFF,csi_stby_str);
  688. msleep(10);
  689. break;
  690. case CSI_SUBDEV_PWR_ON:
  691. csi_dev_dbg("CSI_SUBDEV_PWR_ON\n");
  692. //inactive mclk before power on
  693. clk_disable(dev->csi_module_clk);
  694. //power on reset
  695. gpio_set_one_pin_io_status(dev->csi_pin_hd,1,csi_stby_str);//set the gpio to output
  696. gpio_set_one_pin_io_status(dev->csi_pin_hd,1,csi_reset_str);//set the gpio to output
  697. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_ON,csi_stby_str);
  698. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
  699. msleep(1);
  700. //power supply
  701. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_PWR_ON,csi_power_str);
  702. msleep(10);
  703. if(dev->dvdd) {
  704. regulator_enable(dev->dvdd);
  705. msleep(10);
  706. }
  707. if(dev->avdd) {
  708. regulator_enable(dev->avdd);
  709. msleep(10);
  710. }
  711. if(dev->iovdd) {
  712. regulator_enable(dev->iovdd);
  713. msleep(10);
  714. }
  715. //active mclk before power on
  716. clk_enable(dev->csi_module_clk);
  717. //reset after power on
  718. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  719. msleep(10);
  720. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
  721. msleep(100);
  722. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  723. msleep(100);
  724. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_OFF,csi_stby_str);
  725. msleep(10);
  726. break;
  727. case CSI_SUBDEV_PWR_OFF:
  728. csi_dev_dbg("CSI_SUBDEV_PWR_OFF\n");
  729. //power supply off
  730. if(dev->iovdd) {
  731. regulator_disable(dev->iovdd);
  732. msleep(10);
  733. }
  734. if(dev->avdd) {
  735. regulator_disable(dev->avdd);
  736. msleep(10);
  737. }
  738. if(dev->dvdd) {
  739. regulator_disable(dev->dvdd);
  740. msleep(10);
  741. }
  742. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_PWR_OFF,csi_power_str);
  743. msleep(10);
  744. //inactive mclk after power off
  745. clk_disable(dev->csi_module_clk);
  746. //set the io to hi-z
  747. gpio_set_one_pin_io_status(dev->csi_pin_hd,0,csi_reset_str);//set the gpio to input
  748. gpio_set_one_pin_io_status(dev->csi_pin_hd,0,csi_stby_str);//set the gpio to input
  749. break;
  750. default:
  751. return -EINVAL;
  752. }
  753. return 0;
  754. }
  755. static int sensor_reset(struct v4l2_subdev *sd, u32 val)
  756. {
  757. struct csi_dev *dev=(struct csi_dev *)dev_get_drvdata(sd->v4l2_dev->dev);
  758. struct sensor_info *info = to_state(sd);
  759. char csi_reset_str[32];
  760. if(info->ccm_info->iocfg == 0) {
  761. strcpy(csi_reset_str,"csi_reset");
  762. } else if(info->ccm_info->iocfg == 1) {
  763. strcpy(csi_reset_str,"csi_reset_b");
  764. }
  765. switch(val)
  766. {
  767. case CSI_SUBDEV_RST_OFF:
  768. csi_dev_dbg("CSI_SUBDEV_RST_OFF\n");
  769. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  770. msleep(10);
  771. break;
  772. case CSI_SUBDEV_RST_ON:
  773. csi_dev_dbg("CSI_SUBDEV_RST_ON\n");
  774. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
  775. msleep(10);
  776. break;
  777. case CSI_SUBDEV_RST_PUL:
  778. csi_dev_dbg("CSI_SUBDEV_RST_PUL\n");
  779. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  780. msleep(10);
  781. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
  782. msleep(100);
  783. gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
  784. msleep(10);
  785. break;
  786. default:
  787. return -EINVAL;
  788. }
  789. return 0;
  790. }
  791. static int sensor_detect(struct v4l2_subdev *sd)
  792. {
  793. int ret;
  794. struct regval_list regs;
  795. regs.reg_num[0] = 0xfe;
  796. regs.value[0] = 0x00; //PAGE 0x00
  797. regs.value[1] = 0x00;
  798. ret = sensor_write(sd, regs.reg_num, regs.value);
  799. if (ret < 0) {
  800. csi_dev_err("sensor_write err at sensor_detect!\n");
  801. return ret;
  802. }
  803. regs.reg_num[0] = 0x00;
  804. regs.reg_num[1] = 0x00;
  805. ret = sensor_read(sd, regs.reg_num, regs.value);
  806. if (ret < 0) {
  807. csi_dev_err("sensor_read err at sensor_detect!\n");
  808. return ret;
  809. }
  810. if(regs.value[0] != 0x14)
  811. return -ENODEV;
  812. return 0;
  813. }
  814. static int sensor_init(struct v4l2_subdev *sd, u32 val)
  815. {
  816. int ret;
  817. csi_dev_dbg("sensor_init\n");
  818. /*Make sure it is a target sensor*/
  819. ret = sensor_detect(sd);
  820. if (ret) {
  821. csi_dev_err("chip found is not an target chip.\n");
  822. return ret;
  823. }
  824. return sensor_write_array(sd, sensor_default_regs , ARRAY_SIZE(sensor_default_regs));
  825. }
  826. static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
  827. {
  828. int ret=0;
  829. switch(cmd){
  830. case CSI_SUBDEV_CMD_GET_INFO:
  831. {
  832. struct sensor_info *info = to_state(sd);
  833. __csi_subdev_info_t *ccm_info = arg;
  834. csi_dev_dbg("CSI_SUBDEV_CMD_GET_INFO\n");
  835. ccm_info->mclk = info->ccm_info->mclk ;
  836. ccm_info->vref = info->ccm_info->vref ;
  837. ccm_info->href = info->ccm_info->href ;
  838. ccm_info->clock = info->ccm_info->clock;
  839. ccm_info->iocfg = info->ccm_info->iocfg;
  840. csi_dev_dbg("ccm_info.mclk=%x\n ",info->ccm_info->mclk);
  841. csi_dev_dbg("ccm_info.vref=%x\n ",info->ccm_info->vref);
  842. csi_dev_dbg("ccm_info.href=%x\n ",info->ccm_info->href);
  843. csi_dev_dbg("ccm_info.clock=%x\n ",info->ccm_info->clock);
  844. csi_dev_dbg("ccm_info.iocfg=%x\n ",info->ccm_info->iocfg);
  845. break;
  846. }
  847. case CSI_SUBDEV_CMD_SET_INFO:
  848. {
  849. struct sensor_info *info = to_state(sd);
  850. __csi_subdev_info_t *ccm_info = arg;
  851. csi_dev_dbg("CSI_SUBDEV_CMD_SET_INFO\n");
  852. info->ccm_info->mclk = ccm_info->mclk ;
  853. info->ccm_info->vref = ccm_info->vref ;
  854. info->ccm_info->href = ccm_info->href ;
  855. info->ccm_info->clock = ccm_info->clock ;
  856. info->ccm_info->iocfg = ccm_info->iocfg ;
  857. csi_dev_dbg("ccm_info.mclk=%x\n ",info->ccm_info->mclk);
  858. csi_dev_dbg("ccm_info.vref=%x\n ",info->ccm_info->vref);
  859. csi_dev_dbg("ccm_info.href=%x\n ",info->ccm_info->href);
  860. csi_dev_dbg("ccm_info.clock=%x\n ",info->ccm_info->clock);
  861. csi_dev_dbg("ccm_info.iocfg=%x\n ",info->ccm_info->iocfg);
  862. break;
  863. }
  864. default:
  865. return -EINVAL;
  866. }
  867. return ret;
  868. }
  869. /*
  870. * Store information about the video data format.
  871. */
  872. static struct sensor_format_struct {
  873. __u8 *desc;
  874. //__u32 pixelformat;
  875. enum v4l2_mbus_pixelcode mbus_code;//linux-3.0
  876. struct regval_list *regs;
  877. int regs_size;
  878. int bpp; /* Bytes per pixel */
  879. } sensor_formats[] = {
  880. {
  881. .desc = "YUYV 4:2:2",
  882. .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,//linux-3.0
  883. .regs = sensor_fmt_yuv422_yuyv,
  884. .regs_size = ARRAY_SIZE(sensor_fmt_yuv422_yuyv),
  885. .bpp = 2,
  886. },
  887. {
  888. .desc = "YVYU 4:2:2",
  889. .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8,//linux-3.0
  890. .regs = sensor_fmt_yuv422_yvyu,
  891. .regs_size = ARRAY_SIZE(sensor_fmt_yuv422_yvyu),
  892. .bpp = 2,
  893. },
  894. {
  895. .desc = "UYVY 4:2:2",
  896. .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,//linux-3.0
  897. .regs = sensor_fmt_yuv422_uyvy,
  898. .regs_size = ARRAY_SIZE(sensor_fmt_yuv422_uyvy),
  899. .bpp = 2,
  900. },
  901. {
  902. .desc = "VYUY 4:2:2",
  903. .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8,//linux-3.0
  904. .regs = sensor_fmt_yuv422_vyuy,
  905. .regs_size = ARRAY_SIZE(sensor_fmt_yuv422_vyuy),
  906. .bpp = 2,
  907. },
  908. // {
  909. // .desc = "Raw RGB Bayer",
  910. // .mbus_code = V4L2_MBUS_FMT_SBGGR8_1X8,//linux-3.0
  911. // .regs = sensor_fmt_raw,
  912. // .regs_size = ARRAY_SIZE(sensor_fmt_raw),
  913. // .bpp = 1
  914. // },
  915. };
  916. #define N_FMTS ARRAY_SIZE(sensor_formats)
  917. /*
  918. * Then there is the issue of window sizes. Try to capture the info here.
  919. */
  920. static struct sensor_win_size {
  921. int width;
  922. int height;
  923. int hstart; /* Start/stop values for the camera. Note */
  924. int hstop; /* that they do not always make complete */
  925. int vstart; /* sense to humans, but evidently the sensor */
  926. int vstop; /* will do the right thing... */
  927. struct regval_list *regs; /* Regs to tweak */
  928. int regs_size;
  929. int (*set_size) (struct v4l2_subdev *sd);
  930. /* h/vref stuff */
  931. } sensor_win_sizes[] = {
  932. /* SXGA */
  933. {
  934. .width = SXGA_WIDTH,
  935. .height = SXGA_HEIGHT,
  936. .regs = sensor_sxga_regs,
  937. .regs_size = ARRAY_SIZE(sensor_sxga_regs),
  938. .set_size = NULL,
  939. },
  940. /* VGA */
  941. {
  942. .width = VGA_WIDTH,
  943. .height = VGA_HEIGHT,
  944. .regs = sensor_vga_regs,
  945. .regs_size = ARRAY_SIZE(sensor_vga_regs),
  946. .set_size = NULL,
  947. }
  948. };
  949. #define N_WIN_SIZES (ARRAY_SIZE(sensor_win_sizes))
  950. static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned index,
  951. enum v4l2_mbus_pixelcode *code)//linux-3.0
  952. {
  953. // struct sensor_format_struct *ofmt;
  954. if (index >= N_FMTS)//linux-3.0
  955. return -EINVAL;
  956. *code = sensor_formats[index].mbus_code;//linux-3.0
  957. // ofmt = sensor_formats + fmt->index;
  958. // fmt->flags = 0;
  959. // strcpy(fmt->description, ofmt->desc);
  960. // fmt->pixelformat = ofmt->pixelformat;
  961. return 0;
  962. }
  963. static int sensor_try_fmt_internal(struct v4l2_subdev *sd,
  964. //struct v4l2_format *fmt,
  965. struct v4l2_mbus_framefmt *fmt,//linux-3.0
  966. struct sensor_format_struct **ret_fmt,
  967. struct sensor_win_size **ret_wsize)
  968. {
  969. int index;
  970. struct sensor_win_size *wsize;
  971. // struct v4l2_pix_format *pix = &fmt->fmt.pix;//linux-3.0
  972. csi_dev_dbg("sensor_try_fmt_internal\n");
  973. for (index = 0; index < N_FMTS; index++)
  974. if (sensor_formats[index].mbus_code == fmt->code)//linux-3.0
  975. break;
  976. if (index >= N_FMTS) {
  977. /* default to first format */
  978. index = 0;
  979. fmt->code = sensor_formats[0].mbus_code;//linux-3.0
  980. }
  981. if (ret_fmt != NULL)
  982. *ret_fmt = sensor_formats + index;
  983. /*
  984. * Fields: the sensor devices claim to be progressive.
  985. */
  986. fmt->field = V4L2_FIELD_NONE;//linux-3.0
  987. /*
  988. * Round requested image size down to the nearest
  989. * we support, but not below the smallest.
  990. */
  991. for (wsize = sensor_win_sizes; wsize < sensor_win_sizes + N_WIN_SIZES;
  992. wsize++)
  993. if (fmt->width >= wsize->width && fmt->height >= wsize->height)//linux-3.0
  994. break;
  995. if (wsize >= sensor_win_sizes + N_WIN_SIZES)
  996. wsize--; /* Take the smallest one */
  997. if (ret_wsize != NULL)
  998. *ret_wsize = wsize;
  999. /*
  1000. * Note the size we'll actually handle.
  1001. */
  1002. fmt->width = wsize->width;//linux-3.0
  1003. fmt->height = wsize->height;//linux-3.0
  1004. //pix->bytesperline = pix->width*sensor_formats[index].bpp;//linux-3.0
  1005. //pix->sizeimage = pix->height*pix->bytesperline;//linux-3.0
  1006. return 0;
  1007. }
  1008. static int sensor_try_fmt(struct v4l2_subdev *sd,
  1009. struct v4l2_mbus_framefmt *fmt)//linux-3.0
  1010. {
  1011. return sensor_try_fmt_internal(sd, fmt, NULL, NULL);
  1012. }
  1013. /*
  1014. * Set a format.
  1015. */
  1016. static int sensor_s_fmt(struct v4l2_subdev *sd,
  1017. struct v4l2_mbus_framefmt *fmt)//linux-3.0
  1018. {
  1019. int ret;
  1020. struct sensor_format_struct *sensor_fmt;
  1021. struct sensor_win_size *wsize;
  1022. struct sensor_info *info = to_state(sd);
  1023. csi_dev_dbg("sensor_s_fmt\n");
  1024. ret = sensor_try_fmt_internal(sd, fmt, &sensor_fmt, &wsize);
  1025. if (ret)
  1026. return ret;
  1027. sensor_write_array(sd, sensor_fmt->regs , sensor_fmt->regs_size);
  1028. ret = 0;
  1029. if (wsize->regs)
  1030. {
  1031. ret = sensor_write_array(sd, wsize->regs , wsize->regs_size);
  1032. if (ret < 0)
  1033. return ret;
  1034. }
  1035. if (wsize->set_size)
  1036. {
  1037. ret = wsize->set_size(sd);
  1038. if (ret < 0)
  1039. return ret;
  1040. }
  1041. info->fmt = sensor_fmt;
  1042. info->width = wsize->width;
  1043. info->height = wsize->height;
  1044. return 0;
  1045. }
  1046. /*
  1047. * Implement G/S_PARM. There is a "high quality" mode we could try
  1048. * to do someday; for now, we just do the frame rate tweak.
  1049. */
  1050. static int sensor_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
  1051. {
  1052. struct v4l2_captureparm *cp = &parms->parm.capture;
  1053. //struct sensor_info *info = to_state(sd);
  1054. if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1055. return -EINVAL;
  1056. memset(cp, 0, sizeof(struct v4l2_captureparm));
  1057. cp->capability = V4L2_CAP_TIMEPERFRAME;
  1058. cp->timeperframe.numerator = 1;
  1059. cp->timeperframe.denominator = SENSOR_FRAME_RATE;
  1060. return 0;
  1061. }
  1062. static int sensor_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
  1063. {
  1064. return -EINVAL;
  1065. }
  1066. /*
  1067. * Code for dealing with controls.
  1068. * fill with different sensor module
  1069. * different sensor module has different settings here
  1070. * if not support the follow function ,retrun -EINVAL
  1071. */
  1072. /* *********************************************begin of ******************************************** */
  1073. static int sensor_queryctrl(struct v4l2_subdev *sd,
  1074. struct v4l2_queryctrl *qc)
  1075. {
  1076. /* Fill in min, max, step and default value for these controls. */
  1077. /* see include/linux/videodev2.h for details */
  1078. /* see sensor_s_parm and sensor_g_parm for the meaning of value */
  1079. switch (qc->id) {
  1080. // case V4L2_CID_BRIGHTNESS:
  1081. // return v4l2_ctrl_query_fill(qc, -4, 4, 1, 1);
  1082. // case V4L2_CID_CONTRAST:
  1083. // return v4l2_ctrl_query_fill(qc, -4, 4, 1, 1);
  1084. // case V4L2_CID_SATURATION:
  1085. // return v4l2_ctrl_query_fill(qc, -4, 4, 1, 1);
  1086. // case V4L2_CID_HUE:
  1087. // return v4l2_ctrl_query_fill(qc, -180, 180, 5, 0);
  1088. case V4L2_CID_VFLIP:
  1089. case V4L2_CID_HFLIP:
  1090. return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
  1091. // case V4L2_CID_GAIN:
  1092. // return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
  1093. // case V4L2_CID_AUTOGAIN:
  1094. // return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
  1095. // case V4L2_CID_EXPOSURE:
  1096. // return v4l2_ctrl_query_fill(qc, -4, 4, 1, 0);
  1097. // case V4L2_CID_EXPOSURE_AUTO:
  1098. // return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
  1099. // case V4L2_CID_DO_WHITE_BALANCE:
  1100. // return v4l2_ctrl_query_fill(qc, 0, 5, 1, 0);
  1101. // case V4L2_CID_AUTO_WHITE_BALANCE:
  1102. // return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
  1103. case V4L2_CID_COLORFX:
  1104. return v4l2_ctrl_query_fill(qc, 0, 9, 1, 0);
  1105. case V4L2_CID_CAMERA_FLASH_MODE:
  1106. return v4l2_ctrl_query_fill(qc, 0, 4, 1, 0);
  1107. }
  1108. return -EINVAL;
  1109. }
  1110. static int sensor_g_hflip(struct v4l2_subdev *sd, __s32 *value)
  1111. {
  1112. int ret;
  1113. struct sensor_info *info = to_state(sd);
  1114. struct regval_list regs;
  1115. regs.reg_num[0] = 0xf0;
  1116. regs.value[0] = 0x00; //PAGEMODE 0x00
  1117. regs.value[1] = 0x00;
  1118. ret = sensor_write(sd, regs.reg_num, regs.value);
  1119. if (ret < 0) {
  1120. csi_dev_err("sensor_write err at sensor_g_hflip!\n");
  1121. return ret;
  1122. }
  1123. regs.reg_num[0] = 0x20;
  1124. ret = sensor_read(sd, regs.reg_num, regs.value);
  1125. if (ret < 0) {
  1126. csi_dev_err("sensor_read err at sensor_g_hflip!\n");
  1127. return ret;
  1128. }
  1129. regs.value[1] &= (1<<1);
  1130. regs.value[1] = regs.value[1]>>1; //0x20 bit1 is hflip enable
  1131. *value = regs.value[1];
  1132. info->hflip = *value;
  1133. return 0;
  1134. }
  1135. static int sensor_s_hflip(struct v4l2_subdev *sd, int value)
  1136. {
  1137. int ret;
  1138. struct sensor_info *info = to_state(sd);
  1139. struct regval_list regs;
  1140. regs.reg_num[0] = 0xf0;
  1141. regs.value[0] = 0x00; //PAGEMODE 0x00
  1142. regs.value[1] = 0x00;
  1143. ret = sensor_write(sd, regs.reg_num, regs.value);
  1144. if (ret < 0) {
  1145. csi_dev_err("sensor_write err at sensor_s_hflip!\n");
  1146. return ret;
  1147. }
  1148. regs.reg_num[0] = 0x20;
  1149. ret = sensor_read(sd, regs.reg_num, regs.value);
  1150. if (ret < 0) {
  1151. csi_dev_err("sensor_read err at sensor_s_hflip!\n");
  1152. return ret;
  1153. }
  1154. switch(value) {
  1155. case 0:
  1156. regs.value[1] &= 0xfd;
  1157. break;
  1158. case 1:
  1159. regs.value[1] |= 0x02;
  1160. break;
  1161. default:
  1162. return -EINVAL;
  1163. }
  1164. ret = sensor_write(sd, regs.reg_num, regs.value);
  1165. if (ret < 0) {
  1166. csi_dev_err("sensor_write err at sensor_s_hflip!\n");
  1167. return ret;
  1168. }
  1169. msleep(100);
  1170. info->hflip = value;
  1171. return 0;
  1172. }
  1173. static int sensor_g_vflip(struct v4l2_subdev *sd, __s32 *value)
  1174. {
  1175. int ret;
  1176. struct sensor_info *info = to_state(sd);
  1177. struct regval_list regs;
  1178. regs.reg_num[0] = 0xf0;
  1179. regs.value[0] = 0x00; //PAGEMODE 0x00
  1180. regs.value[1] = 0x00;
  1181. ret = sensor_write(sd, regs.reg_num, regs.value);
  1182. if (ret < 0) {
  1183. csi_dev_err("sensor_write err at sensor_g_vflip!\n");
  1184. return ret;
  1185. }
  1186. regs.reg_num[0] = 0x20;
  1187. ret = sensor_read(sd, regs.reg_num, regs.value);
  1188. if (ret < 0) {
  1189. csi_dev_err("sensor_read err at sensor_g_vflip!\n");
  1190. return ret;
  1191. }
  1192. regs.value[1] &= (1<<0);
  1193. regs.value[1] = regs.value[0]>>0; //0x20 bit0 is vflip enable
  1194. *value = regs.value[1];
  1195. info->hflip = *value;
  1196. return 0;
  1197. }
  1198. static int sensor_s_vflip(struct v4l2_subdev *sd, int value)
  1199. {
  1200. int ret;
  1201. struct sensor_info *info = to_state(sd);
  1202. struct regval_list regs;
  1203. regs.reg_num[0] = 0xf0;
  1204. regs.value[0] = 0x00; //PAGEMODE 0x00
  1205. regs.value[1] = 0x00;
  1206. ret = sensor_write(sd, regs.reg_num, regs.value);
  1207. if (ret < 0) {
  1208. csi_dev_err("sensor_write err at sensor_s_vflip!\n");
  1209. return ret;
  1210. }
  1211. regs.reg_num[0] = 0x20;
  1212. ret = sensor_read(sd, regs.reg_num, regs.value);
  1213. if (ret < 0) {
  1214. csi_dev_err("sensor_read err at sensor_s_vflip!\n");
  1215. return ret;
  1216. }
  1217. switch(value) {
  1218. case 0:
  1219. regs.value[1] &= 0xfe;
  1220. break;
  1221. case 1:
  1222. regs.value[1] |= 0x01;
  1223. break;
  1224. default:
  1225. return -EINVAL;
  1226. }
  1227. ret = sensor_write(sd, regs.reg_num, regs.value);
  1228. if (ret < 0) {
  1229. csi_dev_err("sensor_write err at sensor_s_vflip!\n");
  1230. return ret;
  1231. }
  1232. msleep(100);
  1233. info->vflip = value;
  1234. return 0;
  1235. }
  1236. static int sensor_g_autogain(struct v4l2_subdev *sd, __s32 *value)
  1237. {
  1238. return -EINVAL;
  1239. }
  1240. static int sensor_s_autogain(struct v4l2_subdev *sd, int value)
  1241. {
  1242. return -EINVAL;
  1243. }
  1244. static int sensor_g_autoexp(struct v4l2_subdev *sd, __s32 *value)
  1245. {
  1246. return -EINVAL;
  1247. }
  1248. static int sensor_s_autoexp(struct v4l2_subdev *sd,
  1249. enum v4l2_exposure_auto_type value)
  1250. {
  1251. return -EINVAL;
  1252. }
  1253. static int sensor_g_autowb(struct v4l2_subdev *sd, int *value)
  1254. {
  1255. return -EINVAL;
  1256. }
  1257. static int sensor_s_autowb(struct v4l2_subdev *sd, int value)
  1258. {
  1259. return -EINVAL;
  1260. }
  1261. static int sensor_g_hue(struct v4l2_subdev *sd, __s32 *value)
  1262. {
  1263. return -EINVAL;
  1264. }
  1265. static int sensor_s_hue(struct v4l2_subdev *sd, int value)
  1266. {
  1267. return -EINVAL;
  1268. }
  1269. static int sensor_g_gain(struct v4l2_subdev *sd, __s32 *value)
  1270. {
  1271. return -EINVAL;
  1272. }
  1273. static int sensor_s_gain(struct v4l2_subdev *sd, int value)
  1274. {
  1275. return -EINVAL;
  1276. }
  1277. /* *********************************************end of ******************************************** */
  1278. static int sensor_g_brightness(struct v4l2_subdev *sd, __s32 *value)
  1279. {
  1280. struct sensor_info *info = to_state(sd);
  1281. *value = info->brightness;
  1282. return 0;
  1283. }
  1284. static int sensor_s_brightness(struct v4l2_subdev *sd, int value)
  1285. {
  1286. int ret;
  1287. struct sensor_info *info = to_state(sd);
  1288. switch (value) {
  1289. case -4:
  1290. ret = sensor_write_array(sd, sensor_brightness_neg4_regs, ARRAY_SIZE(sensor_brightness_neg4_regs));
  1291. break;
  1292. case -3:
  1293. ret = sensor_write_array(sd, sensor_brightness_neg3_regs, ARRAY_SIZE(sensor_brightness_neg3_regs));
  1294. break;
  1295. case -2:
  1296. ret = sensor_write_array(sd, sensor_brightness_neg2_regs, ARRAY_SIZE(sensor_brightness_neg2_regs));
  1297. break;
  1298. case -1:
  1299. ret = sensor_write_array(sd, sensor_brightness_neg1_regs, ARRAY_SIZE(sensor_brightness_neg1_regs));
  1300. break;
  1301. case 0:
  1302. ret = sensor_write_array(sd, sensor_brightness_zero_regs, ARRAY_SIZE(sensor_brightness_zero_regs));
  1303. break;
  1304. case 1:
  1305. ret = sensor_write_array(sd, sensor_brightness_pos1_regs, ARRAY_SIZE(sensor_brightness_pos1_regs));
  1306. break;
  1307. case 2:
  1308. ret = sensor_write_array(sd, sensor_brightness_pos2_regs, ARRAY_SIZE(sensor_brightness_pos2_regs));
  1309. break;
  1310. case 3:
  1311. ret = sensor_write_array(sd, sensor_brightness_pos3_regs, ARRAY_SIZE(sensor_brightness_pos3_regs));
  1312. break;
  1313. case 4:
  1314. ret = sensor_write_array(sd, sensor_brightness_pos4_regs, ARRAY_SIZE(sensor_brightness_pos4_regs));
  1315. break;
  1316. default:
  1317. return -EINVAL;
  1318. }
  1319. if (ret < 0) {
  1320. csi_dev_err("sensor_write_array err at sensor_s_brightness!\n");
  1321. return ret;
  1322. }
  1323. msleep(10);
  1324. info->brightness = value;
  1325. return 0;
  1326. }
  1327. static int sensor_g_contrast(struct v4l2_subdev *sd, __s32 *value)
  1328. {
  1329. struct sensor_info *info = to_state(sd);
  1330. *value = info->contrast;
  1331. return 0;
  1332. }
  1333. static int sensor_s_contrast(struct v4l2_subdev *sd, int value)
  1334. {
  1335. int ret;
  1336. struct sensor_info *info = to_state(sd);
  1337. switch (value) {
  1338. case -4:
  1339. ret = sensor_write_array(sd, sensor_contrast_neg4_regs, ARRAY_SIZE(sensor_contrast_neg4_regs));
  1340. break;
  1341. case -3:
  1342. ret = sensor_write_array(sd, sensor_contrast_neg3_regs, ARRAY_SIZE(sensor_contrast_neg3_regs));
  1343. break;
  1344. case -2:
  1345. ret = sensor_write_array(sd, sensor_contrast_neg2_regs, ARRAY_SIZE(sensor_contrast_neg2_regs));
  1346. break;
  1347. case -1:
  1348. ret = sensor_write_array(sd, sensor_contrast_neg1_regs, ARRAY_SIZE(sensor_contrast_neg1_regs));
  1349. break;
  1350. case 0:
  1351. ret = sensor_write_array(sd, sensor_contrast_zero_regs, ARRAY_SIZE(sensor_contrast_zero_regs));
  1352. break;
  1353. case 1:
  1354. ret = sensor_write_array(sd, sensor_contrast_pos1_regs, ARRAY_SIZE(sensor_contrast_pos1_regs));
  1355. break;
  1356. case 2:
  1357. ret = sensor_write_array(sd, sensor_contrast_pos2_regs, ARRAY_SIZE(sensor_contrast_pos2_regs));
  1358. break;
  1359. case 3:
  1360. ret = sensor_write_array(sd, sensor_contrast_pos3_regs, ARRAY_SIZE(sensor_contrast_pos3_regs));
  1361. break;
  1362. case 4:
  1363. ret = sensor_write_array(sd, sensor_contrast_pos4_regs, ARRAY_SIZE(sensor_contrast_pos4_regs));
  1364. break;
  1365. default:
  1366. return -EINVAL;
  1367. }
  1368. if (ret < 0) {
  1369. csi_dev_err("sensor_write_array err at sensor_s_contrast!\n");
  1370. return ret;
  1371. }
  1372. msleep(10);
  1373. info->contrast = value;
  1374. return 0;
  1375. }
  1376. static int sensor_g_saturation(struct v4l2_subdev *sd, __s32 *value)
  1377. {
  1378. struct sensor_info *info = to_state(sd);
  1379. *value = info->saturation;
  1380. return 0;
  1381. }
  1382. static int sensor_s_saturation(struct v4l2_subdev *sd, int value)
  1383. {
  1384. int ret;
  1385. struct sensor_info *info = to_state(sd);
  1386. switch (value) {
  1387. case -4:
  1388. ret = sensor_write_array(sd, sensor_saturation_neg4_regs, ARRAY_SIZE(sensor_saturation_neg4_regs));
  1389. break;
  1390. case -3:
  1391. ret = sensor_write_array(sd, sensor_saturation_neg3_regs, ARRAY_SIZE(sensor_saturation_neg3_regs));
  1392. break;
  1393. case -2:
  1394. ret = sensor_write_array(sd, sensor_saturation_neg2_regs, ARRAY_SIZE(sensor_saturation_neg2_regs));
  1395. break;
  1396. case -1:
  1397. ret = sensor_write_array(sd, sensor_saturation_neg1_regs, ARRAY_SIZE(sensor_saturation_neg1_regs));
  1398. break;
  1399. case 0:
  1400. ret = sensor_write_array(sd, sensor_saturation_zero_regs, ARRAY_SIZE(sensor_saturation_zero_regs));
  1401. break;
  1402. case 1:
  1403. ret = sensor_write_array(sd, sensor_saturation_pos1_regs, ARRAY_SIZE(sensor_saturation_pos1_regs));
  1404. break;
  1405. case 2:
  1406. ret = sensor_write_array(sd, sensor_saturation_pos2_regs, ARRAY_SIZE(sensor_saturation_pos2_regs));
  1407. break;
  1408. case 3:
  1409. ret = sensor_write_array(sd, sensor_saturation_pos3_regs, ARRAY_SIZE(sensor_saturation_pos3_regs));
  1410. break;
  1411. case 4:
  1412. ret = sensor_write_array(sd, sensor_saturation_pos4_regs, ARRAY_SIZE(sensor_saturation_pos4_regs));
  1413. break;
  1414. default:
  1415. return -EINVAL;
  1416. }
  1417. if (ret < 0) {
  1418. csi_dev_err("sensor_write_array err at sensor_s_saturation!\n");
  1419. return ret;
  1420. }
  1421. msleep(10);
  1422. info->saturation = value;
  1423. return 0;
  1424. }
  1425. static int sensor_g_exp(struct v4l2_subdev *sd, __s32 *value)
  1426. {
  1427. struct sensor_info *info = to_state(sd);
  1428. *value = info->exp;
  1429. return 0;
  1430. }
  1431. static int sensor_s_exp(struct v4l2_subdev *sd, int value)
  1432. {
  1433. int ret;
  1434. struct sensor_info *info = to_state(sd);
  1435. switch (value) {
  1436. case -4:
  1437. ret = sensor_write_array(sd, sensor_ev_neg4_regs, ARRAY_SIZE(sensor_ev_neg4_regs));
  1438. break;
  1439. case -3:
  1440. ret = sensor_write_array(sd, sensor_ev_neg3_regs, ARRAY_SIZE(sensor_ev_neg3_regs));
  1441. break;
  1442. case -2:
  1443. ret = sensor_write_array(sd, sensor_ev_neg2_regs, ARRAY_SIZE(sensor_ev_neg2_regs));
  1444. break;
  1445. case -1:
  1446. ret = sensor_write_array(sd, sensor_ev_neg1_regs, ARRAY_SIZE(sensor_ev_neg1_regs));
  1447. break;
  1448. case 0:
  1449. ret = sensor_write_array(sd, sensor_ev_zero_regs, ARRAY_SIZE(sensor_ev_zero_regs));
  1450. break;
  1451. case 1:
  1452. ret = sensor_write_array(sd, sensor_ev_pos1_regs, ARRAY_SIZE(sensor_ev_pos1_regs));
  1453. break;
  1454. case 2:
  1455. ret = sensor_write_array(sd, sensor_ev_pos2_regs, ARRAY_SIZE(sensor_ev_pos2_regs));
  1456. break;
  1457. case 3:
  1458. ret = sensor_write_array(sd, sensor_ev_pos3_regs, ARRAY_SIZE(sensor_ev_pos3_regs));
  1459. break;
  1460. case 4:
  1461. ret = sensor_write_array(sd, sensor_ev_pos4_regs, ARRAY_SIZE(sensor_ev_pos4_regs));
  1462. break;
  1463. default:
  1464. return -EINVAL;
  1465. }
  1466. if (ret < 0) {
  1467. csi_dev_err("sensor_write_array err at sensor_s_exp!\n");
  1468. return ret;
  1469. }
  1470. msleep(10);
  1471. info->exp = value;
  1472. return 0;
  1473. }
  1474. static int sensor_g_wb(struct v4l2_subdev *sd, int *value)
  1475. {
  1476. struct sensor_info *info = to_state(sd);
  1477. enum v4l2_whiteblance *wb_type = (enum v4l2_whiteblance*)value;
  1478. *wb_type = info->wb;
  1479. return 0;
  1480. }
  1481. static int sensor_s_wb(struct v4l2_subdev *sd,
  1482. enum v4l2_whiteblance value)
  1483. {
  1484. int ret;
  1485. struct sensor_info *info = to_state(sd);
  1486. if (value == V4L2_WB_AUTO) {
  1487. ret = sensor_s_autowb(sd, 1);
  1488. return ret;
  1489. }
  1490. else {
  1491. ret = sensor_s_autowb(sd, 0);
  1492. if(ret < 0) {
  1493. csi_dev_err("sensor_s_autowb error, return %x!\n",ret);
  1494. return ret;
  1495. }
  1496. switch (value) {
  1497. case V4L2_WB_CLOUD:
  1498. ret = sensor_write_array(sd, sensor_wb_cloud_regs, ARRAY_SIZE(sensor_wb_cloud_regs));
  1499. break;
  1500. case V4L2_WB_DAYLIGHT:
  1501. ret = sensor_write_array(sd, sensor_wb_daylight_regs, ARRAY_SIZE(sensor_wb_daylight_regs));
  1502. break;
  1503. case V4L2_WB_INCANDESCENCE:
  1504. ret = sensor_write_array(sd, sensor_wb_incandescence_regs, ARRAY_SIZE(sensor_wb_incandescence_regs));
  1505. break;
  1506. case V4L2_WB_FLUORESCENT:
  1507. ret = sensor_write_array(sd, sensor_wb_fluorescent_regs, ARRAY_SIZE(sensor_wb_fluorescent_regs));
  1508. break;
  1509. case V4L2_WB_TUNGSTEN:
  1510. ret = sensor_write_array(sd, sensor_wb_tungsten_regs, ARRAY_SIZE(sensor_wb_tungsten_regs));
  1511. break;
  1512. default:
  1513. return -EINVAL;
  1514. }
  1515. }
  1516. if (ret < 0) {
  1517. csi_dev_err("sensor_s_wb error, return %x!\n",ret);
  1518. return ret;
  1519. }
  1520. msleep(10);
  1521. info->wb = value;
  1522. return 0;
  1523. }
  1524. static int sensor_g_colorfx(struct v4l2_subdev *sd,
  1525. __s32 *value)
  1526. {
  1527. struct sensor_info *info = to_state(sd);
  1528. enum v4l2_colorfx *clrfx_type = (enum v4l2_colorfx*)value;
  1529. *clrfx_type = info->clrfx;
  1530. return 0;
  1531. }
  1532. static int sensor_s_colorfx(struct v4l2_subdev *sd,
  1533. enum v4l2_colorfx value)
  1534. {
  1535. int ret;
  1536. struct sensor_info *info = to_state(sd);
  1537. switch (value) {
  1538. case V4L2_COLORFX_NONE:
  1539. ret = sensor_write_array(sd, sensor_colorfx_none_regs, ARRAY_SIZE(sensor_colorfx_none_regs));
  1540. break;
  1541. case V4L2_COLORFX_BW:
  1542. ret = sensor_write_array(sd, sensor_colorfx_bw_regs, ARRAY_SIZE(sensor_colorfx_bw_regs));
  1543. break;
  1544. case V4L2_COLORFX_SEPIA:
  1545. ret = sensor_write_array(sd, sensor_colorfx_sepia_regs, ARRAY_SIZE(sensor_colorfx_sepia_regs));
  1546. break;
  1547. case V4L2_COLORFX_NEGATIVE:
  1548. ret = sensor_write_array(sd, sensor_colorfx_negative_regs, ARRAY_SIZE(sensor_colorfx_negative_regs));
  1549. break;
  1550. case V4L2_COLORFX_EMBOSS:
  1551. ret = sensor_write_array(sd, sensor_colorfx_emboss_regs, ARRAY_SIZE(sensor_colorfx_emboss_regs));
  1552. break;
  1553. case V4L2_COLORFX_SKETCH:
  1554. ret = sensor_write_array(sd, sensor_colorfx_sketch_regs, ARRAY_SIZE(sensor_colorfx_sketch_regs));
  1555. break;
  1556. case V4L2_COLORFX_SKY_BLUE:
  1557. ret = sensor_write_array(sd, sensor_colorfx_sky_blue_regs, ARRAY_SIZE(sensor_colorfx_sky_blue_regs));
  1558. break;
  1559. case V4L2_COLORFX_GRASS_GREEN:
  1560. ret = sensor_write_array(sd, sensor_colorfx_grass_green_regs, ARRAY_SIZE(sensor_colorfx_grass_green_regs));
  1561. break;
  1562. case V4L2_COLORFX_SKIN_WHITEN:
  1563. ret = sensor_write_array(sd, sensor_colorfx_skin_whiten_regs, ARRAY_SIZE(sensor_colorfx_skin_whiten_regs));
  1564. break;
  1565. case V4L2_COLORFX_VIVID:
  1566. ret = sensor_write_array(sd, sensor_colorfx_vivid_regs, ARRAY_SIZE(sensor_colorfx_vivid_regs));
  1567. break;
  1568. default:
  1569. return -EINVAL;
  1570. }
  1571. if (ret < 0) {
  1572. csi_dev_err("sensor_s_colorfx error, return %x!\n",ret);
  1573. return ret;
  1574. }
  1575. msleep(10);
  1576. info->clrfx = value;
  1577. return 0;
  1578. }
  1579. static int sensor_g_flash_mode(struct v4l2_subdev *sd,
  1580. __s32 *value)
  1581. {
  1582. struct sensor_info *info = to_state(sd);
  1583. enum v4l2_flash_mode *flash_mode = (enum v4l2_flash_mode*)value;
  1584. *flash_mode = info->flash_mode;
  1585. return 0;
  1586. }
  1587. static int sensor_s_flash_mode(struct v4l2_subdev *sd,
  1588. enum v4l2_flash_mode value)
  1589. {
  1590. struct sensor_info *info = to_state(sd);
  1591. struct csi_dev *dev=(struct csi_dev *)dev_get_drvdata(sd->v4l2_dev->dev);
  1592. char csi_flash_str[32];
  1593. int flash_on,flash_off;
  1594. if(info->ccm_info->iocfg == 0) {
  1595. strcpy(csi_flash_str,"csi_flash");
  1596. } else if(info->ccm_info->iocfg == 1) {
  1597. strcpy(csi_flash_str,"csi_flash_b");
  1598. }
  1599. flash_on = (dev->flash_pol!=0)?1:0;
  1600. flash_off = (flash_on==1)?0:1;
  1601. switch (value) {
  1602. case V4L2_FLASH_MODE_OFF:
  1603. gpio_write_one_pin_value(dev->csi_pin_hd,flash_off,csi_flash_str);
  1604. break;
  1605. case V4L2_FLASH_MODE_AUTO:
  1606. return -EINVAL;
  1607. break;
  1608. case V4L2_FLASH_MODE_ON:
  1609. gpio_write_one_pin_value(dev->csi_pin_hd,flash_on,csi_flash_str);
  1610. break;
  1611. case V4L2_FLASH_MODE_TORCH:
  1612. return -EINVAL;
  1613. break;
  1614. case V4L2_FLASH_MODE_RED_EYE:
  1615. return -EINVAL;
  1616. break;
  1617. default:
  1618. return -EINVAL;
  1619. }
  1620. info->flash_mode = value;
  1621. return 0;
  1622. }
  1623. static int sensor_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
  1624. {
  1625. switch (ctrl->id) {
  1626. case V4L2_CID_BRIGHTNESS:
  1627. return sensor_g_brightness(sd, &ctrl->value);
  1628. case V4L2_CID_CONTRAST:
  1629. return sensor_g_contrast(sd, &ctrl->value);
  1630. case V4L2_CID_SATURATION:
  1631. return sensor_g_saturation(sd, &ctrl->value);
  1632. case V4L2_CID_HUE:
  1633. return sensor_g_hue(sd, &ctrl->value);
  1634. case V4L2_CID_VFLIP:
  1635. return sensor_g_vflip(sd, &ctrl->value);
  1636. case V4L2_CID_HFLIP:
  1637. return sensor_g_hflip(sd, &ctrl->value);
  1638. case V4L2_CID_GAIN:
  1639. return sensor_g_gain(sd, &ctrl->value);
  1640. case V4L2_CID_AUTOGAIN:
  1641. return sensor_g_autogain(sd, &ctrl->value);
  1642. case V4L2_CID_EXPOSURE:
  1643. return sensor_g_exp(sd, &ctrl->value);
  1644. case V4L2_CID_EXPOSURE_AUTO:
  1645. return sensor_g_autoexp(sd, &ctrl->value);
  1646. case V4L2_CID_DO_WHITE_BALANCE:
  1647. return sensor_g_wb(sd, &ctrl->value);
  1648. case V4L2_CID_AUTO_WHITE_BALANCE:
  1649. return sensor_g_autowb(sd, &ctrl->value);
  1650. case V4L2_CID_COLORFX:
  1651. return sensor_g_colorfx(sd, &ctrl->value);
  1652. case V4L2_CID_CAMERA_FLASH_MODE:
  1653. return sensor_g_flash_mode(sd, &ctrl->value);
  1654. }
  1655. return -EINVAL;
  1656. }
  1657. static int sensor_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
  1658. {
  1659. switch (ctrl->id) {
  1660. case V4L2_CID_BRIGHTNESS:
  1661. return sensor_s_brightness(sd, ctrl->value);
  1662. case V4L2_CID_CONTRAST:
  1663. return sensor_s_contrast(sd, ctrl->value);
  1664. case V4L2_CID_SATURATION:
  1665. return sensor_s_saturation(sd, ctrl->value);
  1666. case V4L2_CID_HUE:
  1667. return sensor_s_hue(sd, ctrl->value);
  1668. case V4L2_CID_VFLIP:
  1669. return sensor_s_vflip(sd, ctrl->value);
  1670. case V4L2_CID_HFLIP:
  1671. return sensor_s_hflip(sd, ctrl->value);
  1672. case V4L2_CID_GAIN:
  1673. return sensor_s_gain(sd, ctrl->value);
  1674. case V4L2_CID_AUTOGAIN:
  1675. return sensor_s_autogain(sd, ctrl->value);
  1676. case V4L2_CID_EXPOSURE:
  1677. return sensor_s_exp(sd, ctrl->value);
  1678. case V4L2_CID_EXPOSURE_AUTO:
  1679. return sensor_s_autoexp(sd,
  1680. (enum v4l2_exposure_auto_type) ctrl->value);
  1681. case V4L2_CID_DO_WHITE_BALANCE:
  1682. return sensor_s_wb(sd,
  1683. (enum v4l2_whiteblance) ctrl->value);
  1684. case V4L2_CID_AUTO_WHITE_BALANCE:
  1685. return sensor_s_autowb(sd, ctrl->value);
  1686. case V4L2_CID_COLORFX:
  1687. return sensor_s_colorfx(sd,
  1688. (enum v4l2_colorfx) ctrl->value);
  1689. case V4L2_CID_CAMERA_FLASH_MODE:
  1690. return sensor_s_flash_mode(sd,
  1691. (enum v4l2_flash_mode) ctrl->value);
  1692. }
  1693. return -EINVAL;
  1694. }
  1695. static int sensor_g_chip_ident(struct v4l2_subdev *sd,
  1696. struct v4l2_dbg_chip_ident *chip)
  1697. {
  1698. struct i2c_client *client = v4l2_get_subdevdata(sd);
  1699. return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SENSOR, 0);
  1700. }
  1701. /* ----------------------------------------------------------------------- */
  1702. static const struct v4l2_subdev_core_ops sensor_core_ops = {
  1703. .g_chip_ident = sensor_g_chip_ident,
  1704. .g_ctrl = sensor_g_ctrl,
  1705. .s_ctrl = sensor_s_ctrl,
  1706. .queryctrl = sensor_queryctrl,
  1707. .reset = sensor_reset,
  1708. .init = sensor_init,
  1709. .s_power = sensor_power,
  1710. .ioctl = sensor_ioctl,
  1711. };
  1712. static const struct v4l2_subdev_video_ops sensor_video_ops = {
  1713. .enum_mbus_fmt = sensor_enum_fmt,//linux-3.0
  1714. .try_mbus_fmt = sensor_try_fmt,//linux-3.0
  1715. .s_mbus_fmt = sensor_s_fmt,//linux-3.0
  1716. .s_parm = sensor_s_parm,//linux-3.0
  1717. .g_parm = sensor_g_parm,//linux-3.0
  1718. };
  1719. static const struct v4l2_subdev_ops sensor_ops = {
  1720. .core = &sensor_core_ops,
  1721. .video = &sensor_video_ops,
  1722. };
  1723. /* ----------------------------------------------------------------------- */
  1724. static int sensor_probe(struct i2c_client *client,
  1725. const struct i2c_device_id *id)
  1726. {
  1727. struct v4l2_subdev *sd;
  1728. struct sensor_info *info;
  1729. // int ret;
  1730. info = kzalloc(sizeof(struct sensor_info), GFP_KERNEL);
  1731. if (info == NULL)
  1732. return -ENOMEM;
  1733. sd = &info->sd;
  1734. v4l2_i2c_subdev_init(sd, client, &sensor_ops);
  1735. info->fmt = &sensor_formats[0];
  1736. info->ccm_info = &ccm_info_con;
  1737. info->brightness = 0;
  1738. info->contrast = 0;
  1739. info->saturation = 0;
  1740. info->hue = 0;
  1741. info->hflip = 0;
  1742. info->vflip = 0;
  1743. info->gain = 0;
  1744. info->autogain = 1;
  1745. info->exp = 0;
  1746. info->autoexp = 0;
  1747. info->autowb = 1;
  1748. info->wb = 0;
  1749. info->clrfx = 0;
  1750. // info->clkrc = 1; /* 30fps */
  1751. return 0;
  1752. }
  1753. static int sensor_remove(struct i2c_client *client)
  1754. {
  1755. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1756. v4l2_device_unregister_subdev(sd);
  1757. kfree(to_state(sd));
  1758. return 0;
  1759. }
  1760. static const struct i2c_device_id sensor_id[] = {
  1761. { "mt9m112", 0 },
  1762. { }
  1763. };
  1764. MODULE_DEVICE_TABLE(i2c, sensor_id);
  1765. //linux-3.0
  1766. static struct i2c_driver sensor_driver = {
  1767. .driver = {
  1768. .owner = THIS_MODULE,
  1769. .name = "mt9m112",
  1770. },
  1771. .probe = sensor_probe,
  1772. .remove = sensor_remove,
  1773. .id_table = sensor_id,
  1774. };
  1775. static __init int init_sensor(void)
  1776. {
  1777. return i2c_add_driver(&sensor_driver);
  1778. }
  1779. static __exit void exit_sensor(void)
  1780. {
  1781. i2c_del_driver(&sensor_driver);
  1782. }
  1783. module_init(init_sensor);
  1784. module_exit(exit_sensor);