PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/media/video/mt9v113.c

http://github.com/CyanogenMod/lge-kernel-sniper
C | 2437 lines | 1689 code | 318 blank | 430 comment | 172 complexity | 3592eca6c69b9993e0c703844d2bf199 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. //--[[ LGE_UBIQUIX_MODIFIED_START : ymjun@mnbt.co.kr [2011.07.26] - CAM : from justin froyo
  2. /*
  3. * drivers/media/video/mt9v113.c
  4. *
  5. * mt9v113 sensor driver
  6. *
  7. *
  8. * Copyright (C) 2010 MM Solutions AD
  9. *
  10. *
  11. * This file is licensed under the terms of the GNU General Public License
  12. * version 2. This program is licensed "as is" without any warranty of any
  13. * kind, whether express or implied.
  14. */
  15. #include <linux/i2c.h>
  16. #include <linux/delay.h>
  17. #include <media/v4l2-int-device.h>
  18. #include "mt9v113.h"
  19. #include "mt9v113_regs.h"
  20. #include "omap34xxcam.h"
  21. #include "isp/isp.h"
  22. #include "isp/ispcsi2.h"
  23. #define MT9V113_DRIVER_NAME "mt9v113"
  24. #define MT9V113_MOD_NAME "MT9V113: "
  25. #define I2C_M_WR 0
  26. #define CTX_PWR_OFF 0
  27. #define CTX_PWR_ON 1
  28. #define CTX_PWR_DEFAULT CTX_PWR_OFF //OFF
  29. #define CTX_BR_DEFAULT 6 // 20120823 jungyeal@lge.com modify default br 7->6
  30. #define CTX_WB_DEFAULT 0
  31. #define CTX_EF_DEFAULT 0
  32. #define CTX_NM_OFF 0
  33. #define CTX_NM_ON 1
  34. #define CTX_NM_DEFAULT CTX_NM_OFF //OFF
  35. struct mt9v113_status_ctx{
  36. u32 ctx_pwrOnState;
  37. u32 ctx_br;
  38. u32 ctx_wb;
  39. u32 ctx_ef;
  40. u32 ctx_nm;
  41. };
  42. /**
  43. * struct mt9v113_sensor - main structure for storage of sensor information
  44. * @pdata: access functions and data for platform level information
  45. * @v4l2_int_device: V4L2 device structure structure
  46. * @i2c_client: iic client device structure
  47. * @pix: V4L2 pixel format information structure
  48. * @timeperframe: time per frame expressed as V4L fraction
  49. * @scaler:
  50. * @ver: mt9v113 chip version
  51. * @fps: frames per second value
  52. */
  53. struct mt9v113_sensor {
  54. const struct mt9v113_platform_data *pdata;
  55. struct v4l2_int_device *v4l2_int_device;
  56. struct i2c_client *i2c_client;
  57. struct v4l2_pix_format pix;
  58. struct v4l2_fract timeperframe;
  59. int scaler;
  60. int ver;
  61. int fps;
  62. bool resuming;
  63. bool reset_camera;
  64. bool vt_mode;
  65. bool sub_vr_mode;
  66. struct mt9v113_status_ctx ctx;
  67. };
  68. static struct mt9v113_sensor mt9v113;
  69. static struct i2c_driver mt9v113sensor_i2c_driver;
  70. static unsigned long xclk_current = MT9V113_XCLK_NOM_1;
  71. static enum mt9v113_image_size isize_current = MT9V113_VGA;
  72. //KJK. Skip size chage in case of same size
  73. static enum mt9v113_image_size preSize = MT9V113_VGA;
  74. /* list of image formats supported by mt9v113 sensor */
  75. const static struct v4l2_fmtdesc mt9v113_formats[] = {
  76. {
  77. //.description = "YUYV (YUV 4:2:2), packed",
  78. //.pixelformat = V4L2_PIX_FMT_YUYV,
  79. .description = "UYVY (YUV 4:2:2), packed", //change by MMS
  80. .pixelformat = V4L2_PIX_FMT_UYVY,
  81. }
  82. };
  83. #define NUM_CAPTURE_FORMATS ARRAY_SIZE(mt9v113_formats)
  84. static enum v4l2_power current_power_state;
  85. static struct mt9v113_clock_freq current_clk;
  86. struct i2c_list {
  87. struct i2c_msg *reg_list;
  88. unsigned int list_size;
  89. };
  90. /**
  91. * struct vcontrol - Video controls
  92. * @v4l2_queryctrl: V4L2 VIDIOC_QUERYCTRL ioctl structure
  93. * @current_value: current value of this control
  94. */
  95. static struct vcontrol {
  96. struct v4l2_queryctrl qc;
  97. int current_value;
  98. } mt9v113sensor_video_control[] = {
  99. {
  100. {
  101. .id = V4L2_CID_EXPOSURE,
  102. .type = V4L2_CTRL_TYPE_INTEGER,
  103. .name = "Exposure",
  104. .minimum = MT9V113_MIN_EXPOSURE,
  105. .maximum = MT9V113_MAX_EXPOSURE,
  106. .step = MT9V113_EXPOSURE_STEP,
  107. .default_value = MT9V113_DEF_EXPOSURE,
  108. },
  109. .current_value = MT9V113_DEF_EXPOSURE,
  110. },
  111. {
  112. {
  113. .id = V4L2_CID_GAIN,
  114. .type = V4L2_CTRL_TYPE_INTEGER,
  115. .name = "Analog Gain",
  116. .minimum = MT9V113_MIN_GAIN,
  117. .maximum = MT9V113_MAX_GAIN,
  118. .step = MT9V113_GAIN_STEP,
  119. .default_value = MT9V113_DEF_GAIN,
  120. },
  121. .current_value = MT9V113_DEF_GAIN,
  122. },
  123. {
  124. {
  125. .id = V4L2_CID_BRIGHTNESS,
  126. .type = V4L2_CTRL_TYPE_INTEGER,
  127. .name = "brightness",
  128. .minimum = MT9V113_MIN_BRIGHTNESS,
  129. .maximum = MT9V113_MAX_BRIGHTNESS,
  130. .step = MT9V113_BRIGHTNESS_STEP,
  131. .default_value = MT9V113_DEF_BRIGHTNESS,
  132. },
  133. .current_value = MT9V113_DEF_BRIGHTNESS,
  134. },
  135. {
  136. {
  137. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  138. .type = V4L2_CTRL_TYPE_INTEGER,
  139. .name = "antibanding",
  140. .minimum = MT9V113_MIN_FLICKER,
  141. .maximum = MT9V113_MAX_FLICKER,
  142. .step = MT9V113_FLICKER_STEP,
  143. .default_value = MT9V113_DEF_FLICKER,
  144. },
  145. .current_value = MT9V113_DEF_FLICKER,
  146. },
  147. {
  148. {
  149. .id = V4L2_CID_COLORFX,
  150. .type = V4L2_CTRL_TYPE_INTEGER,
  151. .name = "effect",
  152. .minimum = MT9V113_MIN_COLORFX,
  153. .maximum = MT9V113_MAX_COLORFX,
  154. .step = MT9V113_COLORFX_STEP,
  155. .default_value = MT9V113_DEF_COLORFX,
  156. },
  157. .current_value = MT9V113_DEF_COLORFX,
  158. },
  159. {
  160. {
  161. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  162. .type = V4L2_CTRL_TYPE_INTEGER,
  163. .name = "whitebalance",
  164. .minimum = MT9V113_MIN_WB,
  165. .maximum = MT9V113_MAX_WB,
  166. .step = MT9V113_WB_STEP,
  167. .default_value = MT9V113_DEF_WB,
  168. },
  169. .current_value = MT9V113_DEF_WB,
  170. },
  171. {
  172. {
  173. .id = V4L2_CID_ROTATE,
  174. .type = V4L2_CTRL_TYPE_INTEGER,
  175. .name = "mirror",
  176. .minimum = MT9V113_MIN_MIRROR,
  177. .maximum = MT9V113_MAX_MIRROR,
  178. .step = MT9V113_MIRROR_STEP,
  179. .default_value = MT9V113_DEF_MIRROR,
  180. },
  181. .current_value = MT9V113_DEF_MIRROR,
  182. },
  183. {
  184. {
  185. .id = V4L2_CID_HCENTER,//TBD
  186. .type = V4L2_CTRL_TYPE_INTEGER,
  187. .name = "meter-mode",
  188. .minimum = MT9V113_MIN_METERING,
  189. .maximum = MT9V113_MAX_METERING,
  190. .step = MT9V113_METERING_STEP,
  191. .default_value = MT9V113_DEF_METERING,
  192. },
  193. .current_value = MT9V113_DEF_METERING,
  194. },
  195. {
  196. {
  197. .id = V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA,
  198. .type = V4L2_CTRL_TYPE_BOOLEAN,
  199. .name = "reset-camera-module",
  200. .minimum = 0,
  201. .maximum = 1,
  202. .step = 1,
  203. .default_value = 0,
  204. },
  205. .current_value = 0,
  206. },
  207. {
  208. {
  209. .id = V4L2_CID_VCENTER,
  210. .type = V4L2_CTRL_TYPE_INTEGER,
  211. .name = "night-mode",
  212. .minimum = 0,
  213. .maximum = 1,
  214. .step = 1,
  215. .default_value = 0,
  216. },
  217. .current_value = 0,
  218. },
  219. {
  220. {
  221. .id = V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA_VT,
  222. .type = V4L2_CTRL_TYPE_BOOLEAN,
  223. .name = "VT-mode",
  224. .minimum = 0,
  225. .maximum = 1,
  226. .step = 1,
  227. .default_value = 0,
  228. },
  229. .current_value = 0,
  230. },
  231. {
  232. {
  233. .id = V4L2_CID_PRIVATE_OMAP3ISP_APTINA_SUB_VR,
  234. .type = V4L2_CTRL_TYPE_BOOLEAN,
  235. .name = "SubVR-mode",
  236. .minimum = 0,
  237. .maximum = 1,
  238. .step = 1,
  239. .default_value = 0,
  240. },
  241. .current_value = 0,
  242. },
  243. };
  244. /**
  245. * find_vctrl - Finds the requested ID in the video control structure array
  246. * @id: ID of control to search the video control array for
  247. *
  248. * Returns the index of the requested ID from the control structure array
  249. */
  250. static int
  251. find_vctrl(int id)
  252. {
  253. int i;
  254. if (id < V4L2_CID_BASE)
  255. return -EDOM;
  256. for (i = (ARRAY_SIZE(mt9v113sensor_video_control) - 1); i >= 0; i--)
  257. {
  258. //MT9V113_LOGD("i %d | qc.id 0x%x | id 0x%x \n",i, mt9v113sensor_video_control[i].qc.id, id);
  259. if (mt9v113sensor_video_control[i].qc.id == id)
  260. break;
  261. }
  262. if (i < 0)
  263. i = -EINVAL;
  264. return i;
  265. }
  266. /**
  267. * mt9v113_read_reg - Read a value from a register in an mt9v113 sensor device
  268. * @client: i2c driver client structure
  269. * @data_length: length of data to be read
  270. * @reg: register address / offset
  271. * @val: stores the value that gets read
  272. *
  273. * Read a value from a register in an mt9v113 sensor device.
  274. * The value is returned in 'val'.
  275. * Returns zero if successful, or non-zero otherwise.
  276. */
  277. static int
  278. mt9v113_read_reg(struct i2c_client *client, u16 data_length, u16 reg, u32 *val)
  279. {
  280. int err;
  281. struct i2c_msg msg[1];
  282. unsigned char data[4];
  283. if (!client->adapter)
  284. return -ENODEV;
  285. if (data_length != I2C_8BIT && data_length != I2C_16BIT
  286. && data_length != I2C_32BIT)
  287. return -EINVAL;
  288. msg->addr = client->addr;
  289. msg->flags = 0;
  290. msg->len = 2;
  291. msg->buf = data;
  292. /* Write addr - high byte goes out first */
  293. data[0] = (u8) (reg >> 8);;
  294. data[1] = (u8) (reg & 0xff);
  295. err = i2c_transfer(client->adapter, msg, 1);
  296. udelay(2);
  297. /* Read back data */
  298. if (err >= 0) {
  299. msg->len = data_length;
  300. msg->flags = I2C_M_RD;
  301. err = i2c_transfer(client->adapter, msg, 1);
  302. }
  303. else
  304. {
  305. MT9V113_LOGD("-mt9v113_read_reg write error\n");
  306. }
  307. if (err >= 0) {
  308. *val = 0;
  309. /* high byte comes first */
  310. if (data_length == I2C_8BIT)
  311. *val = data[0];
  312. else if (data_length == I2C_16BIT)
  313. *val = data[1] + (data[0] << 8);
  314. else
  315. *val = data[3] + (data[2] << 8) +
  316. (data[1] << 16) + (data[0] << 24);
  317. return 0;
  318. }
  319. MT9V113_LOGD("read from offset 0x%x error %d\n", reg, err);
  320. MT9V113_LOGD("-mt9v113_read_reg, -1\n");
  321. return err;
  322. }
  323. /**
  324. * Write a value to a register in mt9v113 sensor device.
  325. * @client: i2c driver client structure.
  326. * @reg: Address of the register to read value from.
  327. * @val: Value to be written to a specific register.
  328. * Returns zero if successful, or non-zero otherwise.
  329. */
  330. static int mt9v113_write_reg(struct i2c_client *client, u16 reg,
  331. u32 val, u16 data_length)
  332. {
  333. int err = 0;
  334. struct i2c_msg msg[1];
  335. unsigned char data[6];
  336. int retries = 0;
  337. if (!client->adapter)
  338. return -ENODEV;
  339. if (data_length != I2C_16BIT)
  340. return -EINVAL;
  341. retry:
  342. msg->addr = client->addr;
  343. msg->flags = I2C_M_WR;
  344. msg->len = data_length+2; /* add address bytes */
  345. msg->buf = data;
  346. /* high byte goes out first */
  347. data[0] = (u8) (reg >> 8);
  348. data[1] = (u8) (reg & 0xff);
  349. data[2] = (val >> 8) & 0xff;
  350. data[3] = val & 0xff;
  351. err = i2c_transfer(client->adapter, msg, 1);
  352. //MT9V113_LOGD("i2c_transfer retV: %d \n",err);
  353. udelay(50);
  354. if (err >= 0)
  355. return 0;
  356. if (retries <= 5) {
  357. MT9V113_LOGD("Retrying I2C... %d \n", retries);
  358. retries++;
  359. msleep(20);
  360. goto retry;
  361. }
  362. return err;
  363. }
  364. /**
  365. * Initialize a list of mt9v113 registers.
  366. * The list of registers is terminated by the pair of values
  367. * {OV3640_REG_TERM, OV3640_VAL_TERM}.
  368. * @client: i2c driver client structure.
  369. * @reglist[]: List of address of the registers to write data.
  370. * Returns zero if successful, or non-zero otherwise.
  371. */
  372. static int mt9v113_write_regs(struct i2c_client *client,
  373. const struct mt9v113_reg reglist[])
  374. {
  375. int err = 0;
  376. const struct mt9v113_reg *list = reglist;
  377. MT9V113_FUNC_IN;
  378. while (!((list->reg == I2C_REG_TERM) && (list->val == I2C_VAL_TERM)))
  379. {
  380. // _lkh test
  381. if(list->reg == 0xFFFE)
  382. {
  383. msleep(list->val);
  384. list++;
  385. continue;
  386. }
  387. err = mt9v113_write_reg(client, list->reg, list->val, list->length);
  388. if (err)
  389. {
  390. MT9V113_LOGD("mt9v113_write_reg ERROR %d \n", err);
  391. MT9V113_FUNC_OUT;
  392. return err;
  393. }
  394. list++;
  395. }
  396. MT9V113_FUNC_OUT;
  397. return 0;
  398. }
  399. /**
  400. * mt9v113_chk_modeChange - Check Mode Change
  401. */
  402. int mt9v113_chk_modeChange(struct i2c_client *client, u32 reg_val)
  403. {
  404. u32 mode_mon = 0xFFFFFFFF;
  405. int i = 0;
  406. int err = 0;
  407. u32 local_val = reg_val;
  408. struct i2c_client *local_client = client;
  409. msleep(10);
  410. do
  411. {
  412. mt9v113_write_reg(local_client, 0x098C, local_val, REG_VAL_DATA_LEN); // MCU_ADDRESS
  413. mt9v113_read_reg (local_client, REG_VAL_DATA_LEN, 0x0990, &mode_mon); // SEQ_STATE
  414. if(mode_mon == 0)
  415. {
  416. MT9V113_LOGD("=====> VGA MODE Change...OK loop[%d]\n",i);
  417. break;
  418. }
  419. //MT9V113_LOGD("VGA MODE Change. FAIL RETRY result [%d]!!!!!\n", mode_mon);
  420. i++;
  421. msleep(10);
  422. }while(i < 30);
  423. return err;
  424. }
  425. /**
  426. * mt9v113_find_size - Find the best match for a requested image capture size
  427. * @width: requested image width in pixels
  428. * @height: requested image height in pixels
  429. *
  430. * Find the best match for a requested image capture size. The best match
  431. * is chosen as the nearest match that has the same number or fewer pixels
  432. * as the requested size, or the smallest image size if the requested size
  433. * has fewer pixels than the smallest image.
  434. * Since the available sizes are subsampled in the vertical direction only,
  435. * the routine will find the size with a height that is equal to or less
  436. * than the requested height.
  437. */
  438. static enum mt9v113_image_size mt9v113_find_size(unsigned int width,
  439. unsigned int height)
  440. {
  441. enum mt9v113_image_size isize;
  442. //MT9V113_LOGD(" width = %d, height = %d\n",width, height);
  443. for (isize = MT9V113_QCIF; isize <= MT9V113_VGA; isize++) {
  444. if ((mt9v113_sizes[isize].height >= height) &&
  445. (mt9v113_sizes[isize].width >= width)) {
  446. break;
  447. }
  448. }
  449. MT9V113_LOGD(" Req Size=%dx%d, "
  450. "Calc Size=%dx%d\n",
  451. width, height, (int)mt9v113_sizes[isize].width,
  452. (int)mt9v113_sizes[isize].height);
  453. return isize;
  454. }
  455. /**
  456. * mt9v113sensor_calc_xclk - Calculate the required xclk frequency
  457. *
  458. * Xclk is not determined from framerate for the MT9V113
  459. */
  460. static unsigned long mt9v113sensor_calc_xclk(void)
  461. {
  462. xclk_current = MT9V113_XCLK_NOM_1;
  463. return xclk_current;
  464. }
  465. /**
  466. * mt9v113sensor_set_exposure_time - sets exposure time per input value
  467. * @exp_time: exposure time to be set on device (in usec)
  468. * @s: pointer to standard V4L2 device structure
  469. * @lvc: pointer to V4L2 exposure entry in mt9v113sensor_video_controls array
  470. *
  471. * If the requested exposure time is within the allowed limits, the HW
  472. * is configured to use the new exposure time, and the
  473. * mt9v113sensor_video_control[] array is updated with the new current value.
  474. * The function returns 0 upon success. Otherwise an error code is
  475. * returned.
  476. */
  477. int mt9v113sensor_set_exposure_time(u32 exp_time, struct v4l2_int_device *s,
  478. struct vcontrol *lvc)
  479. {
  480. int err = 0;
  481. return err;
  482. }
  483. /**
  484. * mt9v113sensor_set_gain - sets sensor analog gain per input value
  485. * @gain: analog gain value to be set on device
  486. * @s: pointer to standard V4L2 device structure
  487. * @lvc: pointer to V4L2 analog gain entry in mt9v113sensor_video_control array
  488. *
  489. * If the requested analog gain is within the allowed limits, the HW
  490. * is configured to use the new gain value, and the mt9v113sensor_video_control
  491. * array is updated with the new current value.
  492. * The function returns 0 upon success. Otherwise an error code is
  493. * returned.
  494. */
  495. int mt9v113sensor_set_gain(u16 lineargain, struct v4l2_int_device *s,
  496. struct vcontrol *lvc)
  497. {
  498. int err = 0;
  499. return err;
  500. }
  501. int mt9v113sensor_set_brightness(u16 value, struct v4l2_int_device *s,
  502. struct vcontrol *lvc)
  503. {
  504. int err = 0;
  505. struct mt9v113_sensor *sensor = s->priv;
  506. struct i2c_client *client = sensor->i2c_client;
  507. MT9V113_LOGD("Cur %d | Req %d ",sensor->ctx.ctx_br,value);
  508. // 20120823 jungyeal@lge.com check mode code moved this code here
  509. // Org code here...
  510. if(sensor->ctx.ctx_br == value)
  511. {
  512. MT9V113_LOGD("SAME ! Return \n");
  513. return err;
  514. }
  515. else
  516. {
  517. sensor->ctx.ctx_br = value;
  518. MT9V113_LOGD("Different ! Chage BR %d\n",sensor->ctx.ctx_br);
  519. }
  520. // 20120823 jungyeal@lge.com check mode code moved this code here
  521. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  522. mt9v113_write_reg(client, 0x0990, 0x0005, REG_VAL_DATA_LEN);
  523. mt9v113_chk_modeChange(client, 0xA103);
  524. msleep(10);
  525. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  526. mt9v113_write_reg(client, 0x0990, 0x0006, REG_VAL_DATA_LEN);
  527. mt9v113_chk_modeChange(client, 0xA103);
  528. msleep(10);
  529. switch (value) {
  530. case 0:
  531. mt9v113_write_regs(client, Brightness1);
  532. break;
  533. case 1:
  534. mt9v113_write_regs(client, Brightness2);
  535. break;
  536. case 2:
  537. mt9v113_write_regs(client, Brightness3);
  538. break;
  539. case 3:
  540. mt9v113_write_regs(client, Brightness4);
  541. break;
  542. case 4:
  543. mt9v113_write_regs(client, Brightness5);
  544. break;
  545. case 5:
  546. mt9v113_write_regs(client, Brightness6);
  547. break;
  548. case 6:
  549. mt9v113_write_regs(client, Brightness7);
  550. break;
  551. case 7:
  552. mt9v113_write_regs(client, Brightness8);
  553. break;
  554. case 8:
  555. mt9v113_write_regs(client, Brightness9);
  556. break;
  557. case 9:
  558. mt9v113_write_regs(client, Brightness10);
  559. break;
  560. case 10:
  561. mt9v113_write_regs(client, Brightness11);
  562. break;
  563. case 11:
  564. mt9v113_write_regs(client, Brightness12);
  565. break;
  566. case 12:
  567. mt9v113_write_regs(client, Brightness13);
  568. break;
  569. default:
  570. return -EINVAL;
  571. }
  572. /* Not Needed
  573. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  574. mt9v113_write_reg(client, 0x0990, 0x0006, REG_VAL_DATA_LEN);
  575. mt9v113_chk_modeChange(client, 0xA103);
  576. msleep(10);
  577. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  578. mt9v113_write_reg(client, 0x0990, 0x0005, REG_VAL_DATA_LEN);
  579. mt9v113_chk_modeChange(client, 0xA103);
  580. msleep(10);
  581. */
  582. msleep(10);
  583. return err;
  584. }
  585. int mt9v113sensor_set_flicker(u16 value, struct v4l2_int_device *s,
  586. struct vcontrol *lvc)
  587. {
  588. int err = 0;
  589. struct mt9v113_sensor *sensor = s->priv;
  590. struct i2c_client *client = sensor->i2c_client;
  591. MT9V113_LOGD(" %d\n",value);
  592. switch (value) {
  593. case 0:
  594. mt9v113_write_regs(client, Flicker_50Hz);
  595. break;
  596. case 1:
  597. mt9v113_write_regs(client, Flicker_60Hz);
  598. break;
  599. default:
  600. return -EINVAL;
  601. }
  602. return err;
  603. }
  604. int mt9v113sensor_set_effect(u16 value, struct v4l2_int_device *s,
  605. struct vcontrol *lvc)
  606. {
  607. int err = 0;
  608. struct mt9v113_sensor *sensor = s->priv;
  609. struct i2c_client *client = sensor->i2c_client;
  610. MT9V113_LOGD("Cur %d | Req %d ",sensor->ctx.ctx_ef,value);
  611. if(sensor->ctx.ctx_ef == value)
  612. {
  613. MT9V113_LOGD("SAME ! Return \n");
  614. return err;
  615. }
  616. else
  617. {
  618. sensor->ctx.ctx_ef = value;
  619. MT9V113_LOGD("Different ! Chage EF %d\n",sensor->ctx.ctx_ef);
  620. }
  621. switch (value) {
  622. case 0:
  623. mt9v113_write_regs(client, Color_Normal);
  624. break;
  625. case 1:
  626. mt9v113_write_regs(client, Color_Mono);
  627. break;
  628. case 2:
  629. mt9v113_write_regs(client, Color_Sepia);
  630. break;
  631. case 3:
  632. mt9v113_write_regs(client, Color_Negative);
  633. break;
  634. case 4:
  635. mt9v113_write_regs(client, Color_Solarize);
  636. break;
  637. default:
  638. return -EINVAL;
  639. }
  640. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  641. mt9v113_write_reg(client, 0x0990, 0x0006, REG_VAL_DATA_LEN);
  642. mt9v113_chk_modeChange(client, 0xA103);
  643. msleep(10);
  644. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  645. mt9v113_write_reg(client, 0x0990, 0x0005, REG_VAL_DATA_LEN);
  646. mt9v113_chk_modeChange(client, 0xA103);
  647. msleep(10);
  648. return err;
  649. }
  650. int mt9v113sensor_set_wb(u16 value, struct v4l2_int_device *s,
  651. struct vcontrol *lvc)
  652. {
  653. int err = 0;
  654. struct mt9v113_sensor *sensor = s->priv;
  655. struct i2c_client *client = sensor->i2c_client;
  656. MT9V113_LOGD("Cur %d | Req %d ",sensor->ctx.ctx_wb,value);
  657. if(sensor->ctx.ctx_wb == value)
  658. {
  659. MT9V113_LOGD("SAME ! BUT KEEP GOING \n"); //if it is not, BLACK SCREEN occurs
  660. //return err;
  661. }
  662. else
  663. {
  664. sensor->ctx.ctx_wb = value;
  665. MT9V113_LOGD("Different ! Chage WB %d\n",sensor->ctx.ctx_wb);
  666. }
  667. switch (value) {
  668. case 0:
  669. mt9v113_write_regs(client, AWB_auto);
  670. MT9V113_LOGD("CAMERA_WB_AUTO = %d \n", value);
  671. break;
  672. case 1:
  673. mt9v113_write_regs(client, AWB_sun);
  674. MT9V113_LOGD("CAMERA_WB_DAYLIGHT = %d \n", value);
  675. break;
  676. case 2:
  677. mt9v113_write_regs(client, AWB_glow);
  678. MT9V113_LOGD("CAMERA_WB_INCANDESCENT = %d \n", value);
  679. break;
  680. case 3:
  681. mt9v113_write_regs(client, AWB_fluorescent);
  682. MT9V113_LOGD("CAMERA_WB_FLUORESCENT = %d \n", value);
  683. break;
  684. case 4:
  685. mt9v113_write_regs(client, AWB_cloudy);
  686. MT9V113_LOGD("CAMERA_WB_CLOUDY_DAYLIGHT = %d \n", value);
  687. break;
  688. default:
  689. return -EINVAL;
  690. }
  691. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  692. mt9v113_write_reg(client, 0x0990, 0x0006, REG_VAL_DATA_LEN);
  693. mt9v113_chk_modeChange(client, 0xA103);
  694. msleep(10);
  695. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  696. mt9v113_write_reg(client, 0x0990, 0x0005, REG_VAL_DATA_LEN);
  697. mt9v113_chk_modeChange(client, 0xA103);
  698. msleep(10);
  699. return err;
  700. }
  701. int mt9v113sensor_set_mirror(u16 value, struct v4l2_int_device *s,
  702. struct vcontrol *lvc)
  703. {
  704. int err = 0;
  705. struct mt9v113_sensor *sensor = s->priv;
  706. struct i2c_client *client = sensor->i2c_client;
  707. MT9V113_LOGD(" %d\n",value);
  708. switch (value) {
  709. case 0:
  710. mt9v113_write_regs(client, Mirror_Normal);
  711. break;
  712. case 1:
  713. mt9v113_write_regs(client, Horizontal_Mirror);
  714. break;
  715. case 2:
  716. mt9v113_write_regs(client, Vertical_Flip);
  717. break;
  718. case 3:
  719. mt9v113_write_regs(client, Mirror_and_Flip);
  720. break;
  721. default:
  722. return -EINVAL;
  723. }
  724. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  725. mt9v113_write_reg(client, 0x0990, 0x0006, REG_VAL_DATA_LEN);
  726. mt9v113_chk_modeChange(client, 0xA103);
  727. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  728. mt9v113_write_reg(client, 0x0990, 0x0005, REG_VAL_DATA_LEN);
  729. mt9v113_chk_modeChange(client, 0xA103);
  730. msleep(100);
  731. return err;
  732. }
  733. int mt9v113sensor_set_metering(u16 value, struct v4l2_int_device *s,
  734. struct vcontrol *lvc)
  735. {
  736. int err = 0;
  737. struct mt9v113_sensor *sensor = s->priv;
  738. struct i2c_client *client = sensor->i2c_client;
  739. MT9V113_LOGD(" %d\n",value);
  740. switch (value) {
  741. case 0:
  742. mt9v113_write_regs(client, Exposure_mode_multi);
  743. break;
  744. case 1:
  745. mt9v113_write_regs(client, Exposure_mode_cen);
  746. break;
  747. default:
  748. return -EINVAL;
  749. }
  750. return err;
  751. }
  752. int mt9v113sensor_set_nightmode(u16 value, struct v4l2_int_device *s,
  753. struct vcontrol *lvc)
  754. {
  755. int err = 0;
  756. struct mt9v113_sensor *sensor = s->priv;
  757. struct i2c_client *client = sensor->i2c_client;
  758. if(sensor->sub_vr_mode) // if VR, go out.
  759. goto nightmode_out;
  760. MT9V113_LOGD("Cur %d | Req %d ",sensor->ctx.ctx_nm,value);
  761. if(sensor->ctx.ctx_nm == value)
  762. {
  763. MT9V113_LOGD("SAME ! Return \n");
  764. return err;
  765. }
  766. else
  767. {
  768. sensor->ctx.ctx_nm = value;
  769. MT9V113_LOGD("Different ! Chage NM %d \n",sensor->ctx.ctx_nm);
  770. }
  771. switch (value) {
  772. case 0:
  773. if (sensor->vt_mode){
  774. mt9v113_write_regs(client, VT_Night_mode_off);
  775. MT9V113_LOGD( "VT MODE PLL\n");
  776. }
  777. else{
  778. mt9v113_write_regs(client, Night_mode_off);
  779. MT9V113_LOGD( "Normal MODE PLL\n");
  780. }
  781. break;
  782. case 1:
  783. if (sensor->vt_mode){
  784. mt9v113_write_regs(client, VT_Night_mode_on);
  785. MT9V113_LOGD( "VT night MODE PLL\n");
  786. }
  787. else{
  788. mt9v113_write_regs(client, Night_mode_on);
  789. MT9V113_LOGD( "Normal night MODE PLL\n");
  790. }
  791. break;
  792. default:
  793. return -EINVAL;
  794. }
  795. //Hansung Recommend 5->6 Just Night mode setting
  796. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  797. mt9v113_write_reg(client, 0x0990, 0x0005, REG_VAL_DATA_LEN);
  798. mt9v113_chk_modeChange(client, 0xA103);
  799. msleep(10);
  800. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  801. mt9v113_write_reg(client, 0x0990, 0x0006, REG_VAL_DATA_LEN);
  802. mt9v113_chk_modeChange(client, 0xA103);
  803. msleep(10);
  804. nightmode_out:
  805. return err;
  806. }
  807. /**
  808. * mt9v113_update_clocks - calcs sensor clocks based on sensor settings.
  809. * @isize: image size enum
  810. */
  811. int mt9v113_update_clocks(struct v4l2_int_device *s, u32 xclk, enum mt9v113_image_size isize)
  812. {
  813. return 0;
  814. }
  815. /**
  816. * mt9v113_setup_pll - initializes sensor PLL registers.
  817. * @c: i2c client driver structure
  818. * @isize: image size enum
  819. */
  820. int mt9v113_setup_pll(struct i2c_client *client, enum mt9v113_image_size isize)
  821. {
  822. mt9v113_write_regs(client, pll_settings);
  823. MT9V113_LOGD( "PLL Setting\n");
  824. return 0;
  825. }
  826. /**
  827. * mt9v113_setup_mipi - initializes sensor & isp MIPI registers.
  828. * @c: i2c client driver structure
  829. * @isize: image size enum
  830. */
  831. int mt9v113_setup_mipi(struct v4l2_int_device *s,
  832. enum mt9v113_image_size isize)
  833. {
  834. return 0;
  835. }
  836. /**
  837. * mt9v113_configure_frame - initializes image frame registers
  838. * @c: i2c client driver structure
  839. * @isize: image size enum
  840. */
  841. int mt9v113_configure_frame(struct i2c_client *client,
  842. enum mt9v113_image_size isize)
  843. {
  844. return 0;
  845. }
  846. /**
  847. * mt9v113_init_sensor
  848. *
  849. *
  850. */
  851. int mt9v113_init_sensor(struct i2c_client *client)
  852. {
  853. u32 mode_mon = 0xffffffff;
  854. u32 i;
  855. int ret = 0;
  856. ret = mt9v113_write_reg(client, 0x301A, 0x1218, REG_VAL_DATA_LEN);
  857. if (ret < 0)
  858. return ret;
  859. msleep(100);
  860. mt9v113_write_reg(client, 0x301A, 0x121C, REG_VAL_DATA_LEN);
  861. mt9v113_write_reg(client, 0x0018, 0x4028, REG_VAL_DATA_LEN);
  862. mt9v113_write_reg(client, 0x0018, 0x4028, REG_VAL_DATA_LEN); // STANDBY_CONTROL
  863. //POLL_REG=0x0018, 0x4000, !=0, DELAY=10, TIMEOUT=100
  864. mode_mon = 0xffffffff;
  865. ret = -1; //KJK for Fail Case Reset 2011.03.08
  866. //for (i=0; i<100; i++)
  867. for (i=0; i<10; i++)
  868. {
  869. msleep(10);
  870. mt9v113_read_reg(client, REG_VAL_DATA_LEN, 0x0018, &mode_mon); // SEQ_STATE
  871. if(!(mode_mon & 0x4000))
  872. {
  873. MT9V113_LOGD("=====> VGA MODE CHANGE...SUCCESS loop [%d]\n",i);
  874. ret = 0;
  875. break;
  876. }
  877. MT9V113_LOGD( "=====> INIT NEXT LOOP____VGA MODE CHANGE : 0x%x !!!\n", mode_mon);
  878. }
  879. //KJK for Fail Case Reset 2011.03.08
  880. if(ret < 0)
  881. {
  882. MT9V113_LOGD("=====> STANDBY_CONTROL FAIL OUT !!!!!! [%d]\n",i);
  883. return ret;
  884. }
  885. //POLL_REG=0x301A, 0x0004, !=1, DELAY=50, TIMEOUT=20 // Verify streaming bit is high
  886. mode_mon = 0xffffffff;
  887. for (i=0; i<20; i++)
  888. {
  889. msleep(50);
  890. mt9v113_read_reg(client, REG_VAL_DATA_LEN, 0x301A, &mode_mon); // SEQ_STATE
  891. if((mode_mon & 0x0004))
  892. {
  893. MT9V113_LOGD("=====> VGA MODE CHANGE...SUCCESS loop [%d]\n",i);
  894. break;
  895. }
  896. MT9V113_LOGD( "=====> INIT NEXT LOOP____VGA MODE CHANGE : %d !!!\n", mode_mon);
  897. }
  898. mt9v113_write_reg(client, 0x001A, 0x0013, REG_VAL_DATA_LEN); // RESET_AND_MISC_CONTROL
  899. msleep(10);
  900. mt9v113_write_reg(client, 0x001A, 0x0010, REG_VAL_DATA_LEN); // RESET_AND_MISC_CONTROL
  901. msleep(10);
  902. mt9v113_write_reg(client, 0x0018, 0x4028, REG_VAL_DATA_LEN); // STANDBY_CONTROL
  903. //POLL_REG=0x0018, 0x4000, !=0, DELAY=10, TIMEOUT=100
  904. mode_mon = 0xffffffff;
  905. for (i=0; i<100; i++)
  906. {
  907. msleep(10);
  908. mt9v113_read_reg(client, REG_VAL_DATA_LEN, 0x0018, &mode_mon); // SEQ_STATE
  909. if(!(mode_mon & 0x4000))
  910. {
  911. MT9V113_LOGD("=====> VGA MODE CHANGE...SUCCESS loop [%d]\n",i);
  912. break;
  913. }
  914. MT9V113_LOGD( "=====> INIT NEXT LOOP____VGA MODE CHANGE : %d !!!\n", mode_mon);
  915. }
  916. //POLL_REG=0x301A, 0x0004, !=1, DELAY=50, TIMEOUT=20 // Verify streaming bit is high
  917. mode_mon = 0xffffffff;
  918. for (i=0; i<20; i++)
  919. {
  920. msleep(10);
  921. mt9v113_read_reg(client, REG_VAL_DATA_LEN, 0x301A, &mode_mon); // SEQ_STATE
  922. if((mode_mon & 0x0004))
  923. {
  924. MT9V113_LOGD("=====> VGA MODE CHANGE...SUCCESS loop [%d]\n",i);
  925. break;
  926. }
  927. MT9V113_LOGD( "=====> INIT NEXT LOOP____VGA MODE CHANGE : %d !!!\n", mode_mon);
  928. }
  929. //reduce_IO_current
  930. mt9v113_write_reg(client, 0x098C, 0x02F0, REG_VAL_DATA_LEN); // MCU_ADDRESS
  931. mt9v113_write_reg(client, 0x0990, 0x0000, REG_VAL_DATA_LEN); // MCU_DATA_0
  932. mt9v113_write_reg(client, 0x098C, 0x02F2, REG_VAL_DATA_LEN); // MCU_ADDRESS
  933. mt9v113_write_reg(client, 0x0990, 0x0210, REG_VAL_DATA_LEN); // MCU_DATA_0
  934. mt9v113_write_reg(client, 0x098C, 0x02F4, REG_VAL_DATA_LEN); // MCU_ADDRESS
  935. mt9v113_write_reg(client, 0x0990, 0x001A, REG_VAL_DATA_LEN); // MCU_DATA_0
  936. mt9v113_write_reg(client, 0x098C, 0x2145, REG_VAL_DATA_LEN); // MCU_ADDRESS
  937. mt9v113_write_reg(client, 0x0990, 0x02F4, REG_VAL_DATA_LEN); // MCU_DATA_0
  938. mt9v113_write_reg(client, 0x098C, 0xA134, REG_VAL_DATA_LEN); // MCU_ADDRESS
  939. mt9v113_write_reg(client, 0x0990, 0x0001, REG_VAL_DATA_LEN); // MCU_DATA_0
  940. mt9v113_write_reg(client, 0x31E0, 0x0001, REG_VAL_DATA_LEN); // RESERVED_CORE_31E0
  941. mt9v113_write_reg(client, 0x31E0, 0x0001, REG_VAL_DATA_LEN); // BITFIELD= 0x31E0 , 2, 0 // core only tags defects. SOC will correct them.
  942. mt9v113_write_reg(client, 0x001A, 0x0210, REG_VAL_DATA_LEN); // RESET_AND_MISC_CONTROL
  943. ret = mt9v113_write_reg(client, 0x0016, 0x42DF, REG_VAL_DATA_LEN); // CLOCKS_CONTROL
  944. if (ret < 0)
  945. return ret;
  946. return 0;
  947. }
  948. /**
  949. * mt9v113_configure - Configure the mt9v113 for the specified image mode
  950. * @s: pointer to standard V4L2 device structure
  951. *
  952. * Configure the mt9v113 for a specified image size, pixel format, and frame
  953. * period. xclk is the frequency (in Hz) of the xclk input to the mt9v113.
  954. * fper is the frame period (in seconds) expressed as a fraction.
  955. * Returns zero if successful, or non-zero otherwise.
  956. * The actual frame period is returned in fper.
  957. */
  958. static int mt9v113_configure(struct v4l2_int_device *s)
  959. {
  960. struct mt9v113_sensor *sensor = s->priv;
  961. struct v4l2_pix_format *pix = &sensor->pix;
  962. struct i2c_client *client = sensor->i2c_client;
  963. enum mt9v113_image_size isize;
  964. int err = 0;
  965. u32 temp = 0, k = 0; //insert by MMS
  966. u32 w_set = 0x280;//640;
  967. u32 h_set = 0x1E0;//480;
  968. isize = mt9v113_find_size(pix->width, pix->height);
  969. isize_current = isize;
  970. preSize = isize;
  971. //KJK for STANDBY_CONTROL fail
  972. #if 0
  973. while(1)
  974. {
  975. err = mt9v113_init_sensor(client);
  976. if (err >= 0)
  977. {
  978. MT9V113_LOGD(" ==================> mt9v113_init_sensor Success I'm Happy\n");
  979. err = 0;
  980. break;
  981. }
  982. else
  983. {
  984. MT9V113_LOGD(" ==================> mt9v113_init_sensor Fail Keep Going until die\n");
  985. mt9v113_power_reset(s);
  986. }
  987. }
  988. #else
  989. err = mt9v113_init_sensor(client);
  990. if (err < 0) {
  991. MT9V113_LOGD(" ==================> mt9v113_init_sensor Fail Keep Going until die ^^, No Just One\n");
  992. mt9v113_power_reset(s);
  993. err = mt9v113_init_sensor(client);
  994. }else {
  995. MT9V113_LOGD(" ==================> mt9v113_init_sensor Success I'm Happy\n");
  996. err = 0;
  997. }
  998. #endif
  999. mt9v113_setup_pll(client, isize);
  1000. if(sensor->sub_vr_mode){
  1001. mt9v113_write_regs(client, VR_core_settings);
  1002. MT9V113_LOGD( "===== VR MODE PLL =====\n");
  1003. }else if(sensor->vt_mode){
  1004. mt9v113_write_regs(client, VT_core_settings);
  1005. MT9V113_LOGD( "===== VT MODE PLL =====\n");
  1006. }else{
  1007. mt9v113_write_regs(client, Normal_core_settings);
  1008. MT9V113_LOGD( "===== NORMAL MODE PLL =====\n");
  1009. }
  1010. if(0 == isize_current)
  1011. {
  1012. mt9v113_write_regs(client, set_preview_qcif_config);
  1013. w_set = 0x00B0; //176
  1014. h_set = 0x0090; //144;
  1015. MT9V113_LOGD( "QCIF SET 176 144 !!!\n");
  1016. }
  1017. else if (1 == isize_current)
  1018. {
  1019. mt9v113_write_regs(client, set_preview_qvga_config); //insert by MMS
  1020. w_set = 0x0140; //320;
  1021. h_set = 0x00F0; //240;
  1022. MT9V113_LOGD( "QVGA 320 240 SET !!!\n");
  1023. }
  1024. else if (2 == isize_current)
  1025. {
  1026. mt9v113_write_regs(client, set_preview_vga_config); //insert by MMS
  1027. w_set = 0x0280; //640;
  1028. h_set = 0x01E0; //480;
  1029. MT9V113_LOGD( "VGA 640 480 SET !!!\n");
  1030. }
  1031. else
  1032. {
  1033. mt9v113_write_regs(client, set_preview_vga_config); //insert by MMS
  1034. MT9V113_LOGD( "Configure Mode Not Supported : %d !!!\n", isize_current);
  1035. msleep(30);
  1036. }
  1037. msleep(30); //insert by MMS
  1038. #if 0 //Remove by MMS
  1039. mt9v113_write_reg(client, 0x098C, 0x2703, REG_VAL_DATA_LEN); // Output Width (A)
  1040. mt9v113_write_reg(client, 0x0990, w_set, REG_VAL_DATA_LEN); // = 640
  1041. mt9v113_write_reg(client, 0x098C, 0x2705, REG_VAL_DATA_LEN); // Output Height
  1042. mt9v113_write_reg(client, 0x0990, h_set, REG_VAL_DATA_LEN); // = 480
  1043. mt9v113_write_reg(client, 0x098C, 0x2707, REG_VAL_DATA_LEN); // Output Width (B)
  1044. mt9v113_write_reg(client, 0x0990, w_set, REG_VAL_DATA_LEN); // = 640
  1045. mt9v113_write_reg(client, 0x098C, 0x2709, REG_VAL_DATA_LEN); // Output Height
  1046. mt9v113_write_reg(client, 0x0990, h_set, REG_VAL_DATA_LEN); // = 480
  1047. // mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  1048. // mt9v113_write_reg(client, 0x0990, 0x0001, REG_VAL_DATA_LEN); // Go to Preview Mode
  1049. // MT9V113_LOGD( "Go to Preveiw Mode\n");
  1050. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  1051. mt9v113_write_reg(client, 0x098C, 0x0006, REG_VAL_DATA_LEN);
  1052. mt9v113_chk_modeChange(client, 0xA103);
  1053. msleep(10);
  1054. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  1055. mt9v113_write_reg(client, 0x098C, 0x0005, REG_VAL_DATA_LEN);
  1056. mt9v113_chk_modeChange(client, 0xA103);
  1057. //msleep(150);
  1058. msleep(10);
  1059. #endif
  1060. return err;
  1061. }
  1062. /**
  1063. * mt9v113_mode_change - Configure the mt9v113 for capture size change
  1064. * @s: pointer to standard V4L2 device structure
  1065. *
  1066. *
  1067. *
  1068. *
  1069. *
  1070. *
  1071. */
  1072. static int mt9v113_mode_change(struct v4l2_int_device *s)
  1073. {
  1074. struct mt9v113_sensor *sensor = s->priv;
  1075. struct v4l2_pix_format *pix = &sensor->pix;
  1076. struct i2c_client *client = sensor->i2c_client;
  1077. enum mt9v113_image_size isize;
  1078. int err = 0;
  1079. u32 w_set = 0x280;//640;
  1080. u32 h_set = 0x1E0;//480;
  1081. isize = mt9v113_find_size(pix->width, pix->height);
  1082. if(preSize == isize) //If same, go return, not change
  1083. {
  1084. MT9V113_LOGD("Previous %d == Reqest %d, DONT Change Size\n",preSize,isize);
  1085. return err;
  1086. }
  1087. isize_current = isize;
  1088. preSize = isize;
  1089. if(0 == isize_current)
  1090. {
  1091. mt9v113_write_regs(client, set_preview_qcif_config); //insert by MMS
  1092. w_set = 0x00B0; //176
  1093. h_set = 0x0090; //144;
  1094. MT9V113_LOGD( "QCIF SET 176 144 !!!\n");
  1095. }
  1096. else if (1 == isize_current)
  1097. {
  1098. mt9v113_write_regs(client, set_preview_qvga_config); //insert by MMS
  1099. w_set = 0x0140; //320;
  1100. h_set = 0x00F0; //240;
  1101. MT9V113_LOGD( "QVGA 320 240 SET !!!\n");
  1102. }
  1103. else if (2 == isize_current)
  1104. {
  1105. mt9v113_write_regs(client, set_preview_vga_config); //insert by MMS
  1106. w_set = 0x0280; //640;
  1107. h_set = 0x01E0; //480;
  1108. MT9V113_LOGD( "VGA 640 480 SET !!!\n");
  1109. }
  1110. else
  1111. {
  1112. mt9v113_write_regs(client, set_preview_vga_config); //insert by MMS
  1113. MT9V113_LOGD( "Configure Mode Not Supported : %d !!!\n", isize_current);
  1114. msleep(30);
  1115. }
  1116. msleep(30); //insert by MMS
  1117. #if 0 //Remove by MMS
  1118. mt9v113_write_reg(client, 0x098C, 0x2703, REG_VAL_DATA_LEN); // Output Width (A)
  1119. mt9v113_write_reg(client, 0x0990, w_set, REG_VAL_DATA_LEN); // = 640
  1120. mt9v113_write_reg(client, 0x098C, 0x2705, REG_VAL_DATA_LEN); // Output Height
  1121. mt9v113_write_reg(client, 0x0990, h_set, REG_VAL_DATA_LEN); // = 480
  1122. mt9v113_write_reg(client, 0x098C, 0x2707, REG_VAL_DATA_LEN); // Output Width (B)
  1123. mt9v113_write_reg(client, 0x0990, w_set, REG_VAL_DATA_LEN); // = 640
  1124. mt9v113_write_reg(client, 0x098C, 0x2709, REG_VAL_DATA_LEN); // Output Height
  1125. mt9v113_write_reg(client, 0x0990, h_set, REG_VAL_DATA_LEN); // = 480
  1126. MT9V113_LOGD( "Change Preview Size\n");
  1127. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  1128. mt9v113_write_reg(client, 0x0990, 0x0006, REG_VAL_DATA_LEN);
  1129. mt9v113_chk_modeChange(client, 0xA103);
  1130. msleep(10);
  1131. mt9v113_write_reg(client, 0x098C, 0xA103, REG_VAL_DATA_LEN);
  1132. mt9v113_write_reg(client, 0x0990, 0x0005, REG_VAL_DATA_LEN);
  1133. mt9v113_chk_modeChange(client, 0xA103);
  1134. msleep(10);
  1135. #endif
  1136. return err;
  1137. }
  1138. /**
  1139. * mt9v113_detect - Detect if an mt9v113 is present, and if so which revision
  1140. * @client: pointer to the i2c client driver structure
  1141. * Detect if an mt9v113 is present, and if so which revision.
  1142. * A device is considered to be detected if the manufacturer ID (MIDH and MIDL)
  1143. * and the product ID (PID) registers match the expected values.
  1144. * Any value of the version ID (VER) register is accepted.
  1145. * Returns a negative error number if no device is detected, or the
  1146. * non-negative value of the version ID register if a device is detected.
  1147. */
  1148. static int mt9v113_detect(struct i2c_client *client)
  1149. {
  1150. //u32 model_id = 0;
  1151. u32 rev = 0;
  1152. struct mt9v113_sensor *sensor;
  1153. dev_err(&client->dev, "client.addr = 0x%x \n", client->addr);
  1154. if (!client)
  1155. return -ENODEV;
  1156. sensor = i2c_get_clientdata(client);
  1157. #if 0
  1158. mt9v113_write_reg(client, 0x0028, 0x7000, I2C_16BIT);
  1159. mt9v113_write_reg(client, 0x002A, MT9V113_REG_MODEL_ID, I2C_16BIT);
  1160. if (mt9v113_read_reg(client, I2C_16BIT, 0x0F12, &model_id))
  1161. return -ENODEV;
  1162. dev_info(&client->dev, "model id detected, 0x%x\n", model_id);
  1163. if (model_id != MT9V113_FW_SENSOR_ID) {
  1164. dev_warn(&client->dev, "model id mismatch, 0x%x\n", model_id);
  1165. return -ENODEV;
  1166. }
  1167. #endif
  1168. return rev;
  1169. }
  1170. #if 0 // Remove Warning
  1171. /**
  1172. * Sets the correct orientation based on the sensor version.
  1173. * IU046F2-Z version=2 orientation=3
  1174. * IU046F4-2D version>2 orientation=0
  1175. */
  1176. static int mt9v113_set_orientation(struct i2c_client *client, u32 ver)
  1177. {
  1178. int err = 0;
  1179. return err;
  1180. }
  1181. /**
  1182. * Set CSI2 Virtual ID.
  1183. * @client: i2c client driver structure
  1184. * @id: Virtual channel ID.
  1185. *
  1186. * Sets the channel ID which identifies data packets sent by this device
  1187. * on the CSI2 bus.
  1188. **/
  1189. static int mt9v113_set_virtual_id(struct i2c_client *client, u32 id)
  1190. {
  1191. return 0;
  1192. }
  1193. /**
  1194. * mt9v113_set_framerate - Sets framerate by adjusting frame_length_lines reg.
  1195. * @s: pointer to standard V4L2 device structure
  1196. * @fper: frame period numerator and denominator in seconds
  1197. *
  1198. * The maximum exposure time is also updated since it is affected by the
  1199. * frame rate.
  1200. **/
  1201. static int mt9v113_set_framerate(struct v4l2_int_device *s,
  1202. struct v4l2_fract *fper)
  1203. {
  1204. int err = 0;
  1205. return err;
  1206. }
  1207. #endif
  1208. /**
  1209. * ioctl_queryctrl - V4L2 sensor interface handler for VIDIOC_QUERYCTRL ioctl
  1210. * @s: pointer to standard V4L2 device structure
  1211. * @qc: standard V4L2 VIDIOC_QUERYCTRL ioctl structure
  1212. *
  1213. * If the requested control is supported, returns the control information
  1214. * from the mt9v113sensor_video_control[] array.
  1215. * Otherwise, returns -EINVAL if the control is not supported.
  1216. */
  1217. static int ioctl_queryctrl(struct v4l2_int_device *s,
  1218. struct v4l2_queryctrl *qc)
  1219. {
  1220. int i;
  1221. MT9V113_LOGD("+ioctl_queryctrl\n");
  1222. i = find_vctrl(qc->id);
  1223. if (i == -EINVAL)
  1224. qc->flags = V4L2_CTRL_FLAG_DISABLED;
  1225. if (i < 0)
  1226. return -EINVAL;
  1227. *qc = mt9v113sensor_video_control[i].qc;
  1228. return 0;
  1229. }
  1230. /**
  1231. * ioctl_g_ctrl - V4L2 sensor interface handler for VIDIOC_G_CTRL ioctl
  1232. * @s: pointer to standard V4L2 device structure
  1233. * @vc: standard V4L2 VIDIOC_G_CTRL ioctl structure
  1234. *
  1235. * If the requested control is supported, returns the control's current
  1236. * value from the mt9v113sensor_video_control[] array.
  1237. * Otherwise, returns -EINVAL if the control is not supported.
  1238. */
  1239. static int ioctl_g_ctrl(struct v4l2_int_device *s,
  1240. struct v4l2_control *vc)
  1241. {
  1242. struct vcontrol *lvc;
  1243. int i;
  1244. i = find_vctrl(vc->id);
  1245. if (i < 0)
  1246. return -EINVAL;
  1247. lvc = &mt9v113sensor_video_control[i];
  1248. switch (vc->id)
  1249. {
  1250. case V4L2_CID_EXPOSURE:
  1251. vc->value = lvc->current_value;
  1252. break;
  1253. case V4L2_CID_GAIN:
  1254. vc->value = lvc->current_value;
  1255. break;
  1256. case V4L2_CID_BRIGHTNESS:
  1257. vc->value = lvc->current_value;
  1258. break;
  1259. case V4L2_CID_POWER_LINE_FREQUENCY://flicker
  1260. vc->value = lvc->current_value;
  1261. break;
  1262. case V4L2_CID_COLORFX://effect
  1263. vc->value = lvc->current_value;
  1264. break;
  1265. case V4L2_CID_AUTO_WHITE_BALANCE://manual white balance
  1266. vc->value = lvc->current_value;
  1267. break;
  1268. case V4L2_CID_ROTATE://mirror
  1269. vc->value = lvc->current_value;
  1270. break;
  1271. case V4L2_CID_HCENTER://metering
  1272. vc->value = lvc->current_value;
  1273. break;
  1274. case V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA:
  1275. vc->value = lvc->current_value;
  1276. break;
  1277. case V4L2_CID_VCENTER: //night mode
  1278. vc->value = lvc->current_value;
  1279. break;
  1280. case V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA_VT:
  1281. vc->value = lvc->current_value;
  1282. break;
  1283. case V4L2_CID_PRIVATE_OMAP3ISP_APTINA_SUB_VR:
  1284. vc->value = lvc->current_value;
  1285. break;
  1286. }
  1287. return 0;
  1288. }
  1289. /**
  1290. * ioctl_s_ctrl - V4L2 sensor interface handler for VIDIOC_S_CTRL ioctl
  1291. * @s: pointer to standard V4L2 device structure
  1292. * @vc: standard V4L2 VIDIOC_S_CTRL ioctl structure
  1293. *
  1294. * If the requested control is supported, sets the control's current
  1295. * value in HW (and updates the mt9v113sensor_video_control[] array).
  1296. * Otherwise, * returns -EINVAL if the control is not supported.
  1297. */
  1298. static int ioctl_s_ctrl(struct v4l2_int_device *s,
  1299. struct v4l2_control *vc)
  1300. {
  1301. struct mt9v113_sensor *sensor = s->priv;
  1302. int retval = -EINVAL;
  1303. int i;
  1304. struct vcontrol *lvc;
  1305. MT9V113_FUNC_IN;
  1306. i = find_vctrl(vc->id);
  1307. //MT9V113_LOGD("vd->id 0x%x | find_vctrl %d \n", vc->id, i);
  1308. if (i < 0)
  1309. return -EINVAL;
  1310. /* 20120605 jungyeal@lge.com Workaround I2C write error when cam power state off [START] */
  1311. if (sensor->ctx.ctx_pwrOnState == CTX_PWR_OFF &&
  1312. vc->id != V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA_VT &&
  1313. vc->id != V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA &&
  1314. vc->id != V4L2_CID_PRIVATE_OMAP3ISP_APTINA_SUB_VR
  1315. )
  1316. {
  1317. MT9V113_LOGD("Warning Cam power state is OFF !!!\n");
  1318. return -EINVAL;
  1319. }
  1320. /* 20120605 jungyeal@lge.com Workaround I2C write error when cam power state off [START] */
  1321. lvc = &mt9v113sensor_video_control[i];
  1322. switch (vc->id)
  1323. {
  1324. case V4L2_CID_EXPOSURE:
  1325. retval = mt9v113sensor_set_exposure_time(vc->value, s, lvc);
  1326. break;
  1327. case V4L2_CID_GAIN:
  1328. retval = mt9v113sensor_set_gain(vc->value, s, lvc);
  1329. break;
  1330. case V4L2_CID_BRIGHTNESS:
  1331. retval = mt9v113sensor_set_brightness(vc->value, s, lvc);
  1332. break;
  1333. case V4L2_CID_POWER_LINE_FREQUENCY://flicker
  1334. retval = mt9v113sensor_set_flicker(vc->value, s, lvc);
  1335. break;
  1336. case V4L2_CID_COLORFX://effect
  1337. retval = mt9v113sensor_set_effect(vc->value, s, lvc);
  1338. break;
  1339. case V4L2_CID_AUTO_WHITE_BALANCE://manual white balance
  1340. retval = mt9v113sensor_set_wb(vc->value, s, lvc);
  1341. break;
  1342. case V4L2_CID_ROTATE://mirror
  1343. retval = mt9v113sensor_set_mirror(vc->value, s, lvc);
  1344. break;
  1345. case V4L2_CID_HCENTER://metering
  1346. retval = mt9v113sensor_set_metering(vc->value, s, lvc);
  1347. break;
  1348. case V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA:
  1349. sensor->reset_camera = vc->value ? true : false;
  1350. lvc->current_value = vc->value;
  1351. retval = 0;
  1352. break;
  1353. case V4L2_CID_VCENTER: //night mode
  1354. retval = mt9v113sensor_set_nightmode(vc->value, s, lvc);
  1355. break;
  1356. case V4L2_CID_PRIVATE_OMAP3ISP_HYNIX_SMART_CAMERA_VT:
  1357. sensor->vt_mode = vc->value ? true : false;
  1358. lvc->current_value = vc->value;
  1359. retval = 0;
  1360. sensor->sub_vr_mode = false; //KJK mode reset
  1361. break;
  1362. case V4L2_CID_PRIVATE_OMAP3ISP_APTINA_SUB_VR: //Sub VR/Fix 15FPS
  1363. sensor->sub_vr_mode = vc->value ? true : false;
  1364. lvc->current_value = vc->value;
  1365. retval = 0;
  1366. sensor->vt_mode = false; //KJK mode reset
  1367. break;
  1368. default:
  1369. MT9V113_LOGD("Not Supported V4L2 CID!!!! ID: %d \n",vc->id);
  1370. break;
  1371. }
  1372. MT9V113_FUNC_OUT;
  1373. return retval;
  1374. }
  1375. /**
  1376. * ioctl_enum_fmt_cap - Implement the CAPTURE buffer VIDIOC_ENUM_FMT ioctl
  1377. * @s: pointer to standard V4L2 device structure
  1378. * @fmt: standard V4L2 VIDIOC_ENUM_FMT ioctl structure
  1379. *
  1380. * Implement the VIDIOC_ENUM_FMT ioctl for the CAPTURE buffer type.
  1381. */
  1382. static int ioctl_enum_fmt_cap(struct v4l2_int_device *s,
  1383. struct v4l2_fmtdesc *fmt)
  1384. {
  1385. int index = fmt->index;
  1386. enum v4l2_buf_type type = fmt->type;
  1387. memset(fmt, 0, sizeof(*fmt));
  1388. fmt->index = index;
  1389. fmt->type = type;
  1390. switch (fmt->type)
  1391. {
  1392. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  1393. if (index >= NUM_CAPTURE_FORMATS)
  1394. return -EINVAL;
  1395. break;
  1396. default:
  1397. return -EINVAL;
  1398. }
  1399. fmt->flags = mt9v113_formats[index].flags;
  1400. strlcpy(fmt->description, mt9v113_formats[index].description,
  1401. sizeof(fmt->description));
  1402. fmt->pixelformat = mt9v113_formats[index].pixelformat;
  1403. return 0;
  1404. }
  1405. /**
  1406. * ioctl_try_fmt_cap - Implement the CAPTURE buffer VIDIOC_TRY_FMT ioctl
  1407. * @s: pointer to standard V4L2 device structure
  1408. * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure
  1409. *
  1410. * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This
  1411. * ioctl is used to negotiate the image capture size and pixel format
  1412. * without actually making it take effect.
  1413. */
  1414. static int ioctl_try_fmt_cap(struct v4l2_int_device *s,
  1415. struct v4l2_format *f)
  1416. {
  1417. enum mt9v113_image_size isize;
  1418. int ifmt;
  1419. struct v4l2_pix_format *pix = &f->fmt.pix;
  1420. struct mt9v113_sensor *sensor = s->priv;
  1421. struct v4l2_pix_format *pix2 = &sensor->pix;
  1422. isize = mt9v113_find_size(pix->width, pix->height);
  1423. isize_current = isize;
  1424. pix->width = mt9v113_sizes[isize].width;
  1425. pix->height = mt9v113_sizes[isize].height;
  1426. MT9V113_LOGD("ioctl_try_fmt_cap w = %d, h = %d\n", pix->width, pix->height);
  1427. for (ifmt = 0; ifmt < NUM_CAPTURE_FORMATS; ifmt++)
  1428. {
  1429. if (pix->pixelformat == mt9v113_formats[ifmt].pixelformat)
  1430. break;
  1431. }
  1432. if (ifmt == NUM_CAPTURE_FORMATS)
  1433. ifmt = 0;
  1434. pix->pixelformat = mt9v113_formats[ifmt].pixelformat;
  1435. pix->field = V4L2_FIELD_NONE;
  1436. pix->bytesperline = pix->width * 2;
  1437. pix->sizeimage = pix->bytesperline * pix->height;
  1438. pix->priv = 0;
  1439. pix->colorspace = V4L2_COLORSPACE_JPEG;
  1440. *pix2 = *pix;
  1441. return 0;
  1442. }
  1443. /**
  1444. * ioctl_s_fmt_cap - V4L2 sensor interface handler for VIDIOC_S_FMT ioctl
  1445. * @s: pointer to standard V4L2 device structure
  1446. * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure
  1447. *
  1448. * If the requested format is supported, configures the HW to use that
  1449. * format, returns error code if format not supported or HW can't be
  1450. * correctly configured.
  1451. */
  1452. static int ioctl_s_fmt_cap(struct v4l2_int_device *s,
  1453. struct v4l2_format *f)
  1454. {
  1455. struct mt9v113_sensor *sensor = s->priv;
  1456. struct v4l2_pix_format *pix = &f->fmt.pix;
  1457. int rval;
  1458. rval = ioctl_try_fmt_cap(s, f);
  1459. if (rval)
  1460. return rval;
  1461. else
  1462. sensor->pix = *pix;
  1463. return rval;
  1464. }
  1465. /**
  1466. * ioctl_g_fmt_cap - V4L2 sensor interface handler for ioctl_g_fmt_cap
  1467. * @s: pointer to standard V4L2 device structure
  1468. * @f: pointer to standard V4L2 v4l2_format structure
  1469. *
  1470. * Returns the sensor's current pixel format in the v4l2_format
  1471. * parameter.
  1472. */
  1473. static int ioctl_g_fmt_cap(struct v4l2_int_device *s,
  1474. struct v4l2_format *f)
  1475. {
  1476. struct mt9v113_sensor *sensor = s->priv;
  1477. f->fmt.pix = sensor->pix;
  1478. return 0;
  1479. }
  1480. /**
  1481. * ioctl_g_pixclk - V4L2 sensor interface handler for ioctl_g_pixclk
  1482. * @s: pointer to standard V4L2 device structure
  1483. * @pixclk: pointer to unsigned 32 var to store pixelclk in HZ
  1484. *
  1485. * Returns the sensor's current pixel clock in HZ
  1486. */
  1487. static int ioctl_priv_g_pixclk(struct v4l2_int_device *s, u32 *pixclk)
  1488. {
  1489. *pixclk = current_clk.vt_pix_clk;
  1490. return 0;
  1491. }
  1492. /**
  1493. * ioctl_g_activesize - V4L2 sensor interface handler for ioctl_g_activesize
  1494. * @s: pointer to standard V4L2 device structure
  1495. * @pix: pointer to standard V4L2 v4l2_pix_format structure
  1496. *
  1497. * Returns the sensor's current active image basesize.
  1498. */
  1499. static int ioctl_priv_g_activesize(struct v4l2_int_device *s,
  1500. struct v4l2_rect *pix)
  1501. {
  1502. //struct mt9v113_sensor *sensor = s->priv;
  1503. //pix->width = sensor->pix.width;
  1504. //pix->height = sensor->pix.height;
  1505. if(0 == isize_current){
  1506. pix->left = 0;
  1507. pix->top = 0;
  1508. pix->width = 176;
  1509. pix->height = 144;
  1510. }else if (1 == isize_current){
  1511. pix->left = 0;
  1512. pix->top = 0;
  1513. pix->width = 320;
  1514. pix->height = 240;
  1515. }else{
  1516. pix->left = 0;
  1517. pix->top = 0;
  1518. pix->width = 640;
  1519. pix->height = 480;
  1520. }
  1521. return 0;
  1522. }
  1523. /**
  1524. * ioctl_g_fullsize - V4L2 sensor interface handler for ioctl_g_fullsize
  1525. * @s: pointer to standard V4L2 device structure
  1526. * @pix: pointer to standard V4L2 v4l2_pix_format structure
  1527. *
  1528. * Returns the sensor's biggest image basesize.
  1529. */
  1530. static int ioctl_priv_g_fullsize(struct v4l2_int_device *s,
  1531. struct v4l2_rect *pix)
  1532. {
  1533. pix->left = 0;
  1534. pix->top = 0;
  1535. pix->width = mt9v113_sizes[NUM_IMAGE_SIZES - 1].width;
  1536. pix->height = mt9v113_sizes[NUM_IMAGE_SIZES - 1].height;
  1537. return 0;
  1538. }
  1539. /**
  1540. * ioctl_g_pixelsize - V4L2 sensor interface handler for ioctl_g_pixelsize
  1541. * @s: pointer to standard V4L2 device structure
  1542. * @pix: pointer to standard V4L2 v4l2_pix_format structure
  1543. *
  1544. * Returns the sensor's configure pixel size. Just For Sub VT Rotation
  1545. */
  1546. static int ioctl_priv_g_pixelsize(struct v4l2_int_device *s,
  1547. struct v4l2_rect *pix)
  1548. {
  1549. //struct yacd5b1s_frame_settings *frm;
  1550. if(0 == isize_current){
  1551. pix->left = 0;
  1552. pix->top = 0;
  1553. pix->width = 2;
  1554. pix->height = 2;
  1555. }else if (1 == isize_current){
  1556. pix->left = 0;
  1557. pix->top = 0;
  1558. pix->width = 2;
  1559. pix->height = 2;
  1560. }else if (2 == isize_current){
  1561. pix->left = 0;
  1562. pix->top = 0;
  1563. pix->width = 2;
  1564. pix->height = 2;
  1565. }else if (3 == isize_current){
  1566. pix->left = 0;
  1567. pix->top = 0;
  1568. pix->width = 1;
  1569. pix->height = 1;
  1570. }else{
  1571. pix->left = 0;
  1572. pix->top = 0;
  1573. pix->width = 1;
  1574. pix->height = 1;
  1575. }
  1576. return 0;
  1577. }
  1578. /**
  1579. * ioctl_g_parm - V4L2 sensor interface handler for VIDIOC_G_PARM ioctl
  1580. * @s: pointer to standard V4L2 device structure
  1581. * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
  1582. *
  1583. * Returns the sensor's video CAPTURE parameters.
  1584. */
  1585. static int ioctl_g_parm(struct v4l2_int_device *s,
  1586. struct v4l2_streamparm *a)
  1587. {
  1588. struct mt9v113_sensor *sensor = s->priv;
  1589. struct v4l2_captureparm *cparm = &a->parm.capture;
  1590. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1591. re

Large files files are truncated, but you can click here to view the full file