[9610] fimc-is2: Buffer modification in case of otp data error at 2x5 module
[GitHub/MotorolaMobilityLLC/kernel-slsi.git] / drivers / media / platform / exynos / fimc-is2 / sensor / module_framework / cis / fimc-is-cis-2l7.c
CommitLineData
d8cd4c5c
WM
1/*
2 * Samsung Exynos5 SoC series Sensor driver
3 *
4 *
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/i2c.h>
13#include <linux/slab.h>
14#include <linux/irq.h>
15#include <linux/interrupt.h>
16#include <linux/delay.h>
17#include <linux/version.h>
18#include <linux/gpio.h>
19#include <linux/clk.h>
20#include <linux/regulator/consumer.h>
21#include <linux/videodev2.h>
22#include <linux/videodev2_exynos_camera.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/platform_device.h>
26#include <linux/of_gpio.h>
27#include <media/v4l2-ctrls.h>
28#include <media/v4l2-device.h>
29#include <media/v4l2-subdev.h>
30
31#include <exynos-fimc-is-sensor.h>
32#include "fimc-is-hw.h"
33#include "fimc-is-core.h"
34#include "fimc-is-param.h"
35#include "fimc-is-device-sensor.h"
36#include "fimc-is-device-sensor-peri.h"
37#include "fimc-is-resourcemgr.h"
38#include "fimc-is-dt.h"
39#include "fimc-is-cis-2l7.h"
40#include "fimc-is-cis-2l7-setA.h"
41#include "fimc-is-cis-2l7-setB.h"
42
43#include "fimc-is-helper-i2c.h"
44
45#define SENSOR_NAME "S5K2L7"
46/* #define DEBUG_2L7_PLL */
47
48static const struct v4l2_subdev_ops subdev_ops;
49
50static const u32 *sensor_2l7_global;
51static u32 sensor_2l7_global_size;
52static const u32 **sensor_2l7_setfiles;
53static const u32 *sensor_2l7_setfile_sizes;
54static const struct sensor_pll_info_compact **sensor_2l7_pllinfos;
55static u32 sensor_2l7_max_setfile_num;
56#ifdef CONFIG_SENSOR_RETENTION_USE
57static const u32 **sensor_2l7_retention;
58static const u32 *sensor_2l7_retention_size;
59static u32 sensor_2l7_max_retention_num;
60#endif
61
62static void sensor_2l7_set_integration_max_margin(u32 mode, cis_shared_data *cis_data)
63{
64 FIMC_BUG_VOID(!cis_data);
65
66 switch (mode) {
67 case SENSOR_2L7_4032X3024_30FPS_MODE3:
68 case SENSOR_2L7_4032X2268_30FPS_MODE3:
69 cis_data->max_margin_coarse_integration_time = 0x04;
70 dbg_sensor(1, "max_margin_coarse_integration_time(%d)\n",
71 cis_data->max_margin_coarse_integration_time);
72 break;
73 case SENSOR_2L7_2016X1512_30FPS_MODE3:
74 case SENSOR_2L7_2016X1136_30FPS_MODE3:
75 cis_data->max_margin_coarse_integration_time = 0x08;
76 dbg_sensor(1, "max_margin_coarse_integration_time(%d)\n",
77 cis_data->max_margin_coarse_integration_time);
78 break;
79 default:
80 err("[%s] Unsupport 2l7 sensor mode\n", __func__);
81 cis_data->max_margin_coarse_integration_time = SENSOR_2L7_COARSE_INTEGRATION_TIME_MAX_MARGIN;
82 dbg_sensor(1, "max_margin_coarse_integration_time(%d)\n",
83 cis_data->max_margin_coarse_integration_time);
84 break;
85 }
86}
87
88static void sensor_2l7_cis_data_calculation(const struct sensor_pll_info_compact *pll_info_compact, cis_shared_data *cis_data)
89{
90 u32 vt_pix_clk_hz = 0;
91 u32 frame_rate = 0, max_fps = 0, frame_valid_us = 0;
92
93 FIMC_BUG_VOID(!pll_info_compact);
94
95 /* 1. get pclk value from pll info */
96 vt_pix_clk_hz = pll_info_compact->pclk;
97
98 dbg_sensor(1, "ext_clock(%d), mipi_datarate(%d), pclk(%d)\n",
99 pll_info_compact->ext_clk, pll_info_compact->mipi_datarate, pll_info_compact->pclk);
100
101 /* 2. the time of processing one frame calculation (us) */
102 cis_data->min_frame_us_time = (pll_info_compact->frame_length_lines * pll_info_compact->line_length_pck
103 / (vt_pix_clk_hz / (1000 * 1000)));
104 cis_data->cur_frame_us_time = cis_data->min_frame_us_time;
105
106 /* 3. FPS calculation */
107 frame_rate = vt_pix_clk_hz / (pll_info_compact->frame_length_lines * pll_info_compact->line_length_pck);
108 dbg_sensor(1, "frame_rate (%d) = vt_pix_clk_hz(%d) / "
109 KERN_CONT "(pll_info_compact->frame_length_lines(%d) * pll_info_compact->line_length_pck(%d))\n",
110 frame_rate, vt_pix_clk_hz, pll_info_compact->frame_length_lines, pll_info_compact->line_length_pck);
111
112 /* calculate max fps */
113 max_fps = (vt_pix_clk_hz * 10) / (pll_info_compact->frame_length_lines * pll_info_compact->line_length_pck);
114 max_fps = (max_fps % 10 >= 5 ? frame_rate + 1 : frame_rate);
115
116 cis_data->pclk = vt_pix_clk_hz;
117 cis_data->max_fps = max_fps;
118 cis_data->frame_length_lines = pll_info_compact->frame_length_lines;
119 cis_data->line_length_pck = pll_info_compact->line_length_pck;
120 cis_data->line_readOut_time = sensor_cis_do_div64((u64)cis_data->line_length_pck * (u64)(1000 * 1000 * 1000), cis_data->pclk);
121 cis_data->rolling_shutter_skew = (cis_data->cur_height - 1) * cis_data->line_readOut_time;
122 cis_data->stream_on = false;
123
124 /* Frame valid time calcuration */
125 frame_valid_us = sensor_cis_do_div64((u64)cis_data->cur_height * (u64)cis_data->line_length_pck * (u64)(1000 * 1000), cis_data->pclk);
126 cis_data->frame_valid_us_time = (int)frame_valid_us;
127
128 dbg_sensor(1, "%s\n", __func__);
129 dbg_sensor(1, "Sensor size(%d x %d) setting: SUCCESS!\n",
130 cis_data->cur_width, cis_data->cur_height);
131 dbg_sensor(1, "Frame Valid(us): %d\n", frame_valid_us);
132 dbg_sensor(1, "rolling_shutter_skew: %lld\n", cis_data->rolling_shutter_skew);
133
134 dbg_sensor(1, "Fps: %d, max fps(%d)\n", frame_rate, cis_data->max_fps);
135 dbg_sensor(1, "min_frame_time(%d us)\n", cis_data->min_frame_us_time);
136 dbg_sensor(1, "Pixel rate(Mbps): %d\n", cis_data->pclk / 1000000);
137
138 /* Frame period calculation */
139 cis_data->frame_time = (cis_data->line_readOut_time * cis_data->cur_height / 1000);
140 cis_data->rolling_shutter_skew = (cis_data->cur_height - 1) * cis_data->line_readOut_time;
141
142 dbg_sensor(1, "[%s] frame_time(%d), rolling_shutter_skew(%lld)\n", __func__,
143 cis_data->frame_time, cis_data->rolling_shutter_skew);
144
145 /* Constant values */
146 cis_data->min_fine_integration_time = SENSOR_2L7_FINE_INTEGRATION_TIME_MIN;
147 cis_data->max_fine_integration_time = SENSOR_2L7_FINE_INTEGRATION_TIME_MAX;
148 cis_data->min_coarse_integration_time = SENSOR_2L7_COARSE_INTEGRATION_TIME_MIN;
149}
150
151void sensor_2l7_cis_data_calc(struct v4l2_subdev *subdev, u32 mode)
152{
153 int ret = 0;
154 struct fimc_is_cis *cis = NULL;
155
156 FIMC_BUG_VOID(!subdev);
157
158 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
159 FIMC_BUG_VOID(!cis);
160 FIMC_BUG_VOID(!cis->cis_data);
161
162 if (mode > sensor_2l7_max_setfile_num) {
163 err("invalid mode(%d)!!", mode);
164 return;
165 }
166
167 /* If check_rev fail when cis_init, one more check_rev in mode_change */
168 if (cis->rev_flag == true) {
169 cis->rev_flag = false;
170 ret = sensor_cis_check_rev(cis);
171 if (ret < 0) {
172 err("sensor_2l7_check_rev is fail: ret(%d)", ret);
173 return;
174 }
175 }
176
177 sensor_2l7_cis_data_calculation(sensor_2l7_pllinfos[mode], cis->cis_data);
178}
179
180int sensor_2l7_cis_check_rev(struct fimc_is_cis *cis)
181{
182 int ret = 0;
183 u8 rev = 0;
184 struct i2c_client *client;
185
186 FIMC_BUG(!cis);
187 FIMC_BUG(!cis->cis_data);
188
189 client = cis->client;
190 if (unlikely(!client)) {
191 err("client is NULL");
192 ret = -EINVAL;
193 }
194
195 I2C_MUTEX_LOCK(cis->i2c_lock);
196 ret = fimc_is_sensor_read8(client, 0x0002, &rev);
197 if (ret < 0) {
198 err("fimc_is_sensor_read8 fail, (ret %d)", ret);
199 return ret;
200 }
201
202 cis->cis_data->cis_rev = rev;
203
204 switch (rev) {
205 case 0xA0:
206 dbg_sensor(1, "2L7 sensor Rev. 0(%d)\n", rev);
207 break;
208 case 0xB1:
209 dbg_sensor(1, "2L7 sensor Rev. 1.1(%d)\n", rev);
210 break;
211 case 0xC0:
212 dbg_sensor(1, "2L7 sensor Rev. 2.0(%d)\n", rev);
213 break;
214 case 0xC:
215 dbg_sensor(1, "2L7 sensor Rev. 2.(%d)\n", rev);
216 break;
217 case 0xD0:
218 dbg_sensor(1, "2L7 sensor Rev. temp\n");
219 break;
220 default:
221 err("Unsupported 2l7 sensor revision(%#x)\n", rev);
222 I2C_MUTEX_UNLOCK(cis->i2c_lock);
223 return -EINVAL;
224 }
225 I2C_MUTEX_UNLOCK(cis->i2c_lock);
226
227 return 0;
228}
229
230/* CIS OPS */
231int sensor_2l7_cis_init(struct v4l2_subdev *subdev)
232{
233 int ret = 0;
234 struct fimc_is_cis *cis;
235 u32 setfile_index = 0;
236 cis_setting_info setinfo;
237 setinfo.param = NULL;
238 setinfo.return_value = 0;
239
240 FIMC_BUG(!subdev);
241
242 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
243 if (!cis) {
244 err("cis is NULL");
245 ret = -EINVAL;
246 goto p_err;
247 }
248
249 FIMC_BUG(!cis->cis_data);
250 memset(cis->cis_data, 0, sizeof(cis_shared_data));
251 cis->rev_flag = false;
252
253 ret = sensor_2l7_cis_check_rev(cis);
254 if (ret < 0) {
255 warn("sensor_2l7_check_rev is fail when cis init");
256 cis->rev_flag = true;
257 ret = 0;
258 }
259
260 cis->cis_data->cur_width = SENSOR_2L7_MAX_WIDTH;
261 cis->cis_data->cur_height = SENSOR_2L7_MAX_HEIGHT;
262 cis->cis_data->low_expo_start = 33000;
263 cis->need_mode_change = false;
264
265 sensor_2l7_cis_data_calculation(sensor_2l7_pllinfos[setfile_index], cis->cis_data);
266 sensor_2l7_set_integration_max_margin(setfile_index, cis->cis_data);
267
268 setinfo.return_value = 0;
269 CALL_CISOPS(cis, cis_get_min_exposure_time, subdev, &setinfo.return_value);
270 dbg_sensor(1, "[%s] min exposure time : %d\n", __func__, setinfo.return_value);
271 setinfo.return_value = 0;
272 CALL_CISOPS(cis, cis_get_max_exposure_time, subdev, &setinfo.return_value);
273 dbg_sensor(1, "[%s] max exposure time : %d\n", __func__, setinfo.return_value);
274 setinfo.return_value = 0;
275 CALL_CISOPS(cis, cis_get_min_analog_gain, subdev, &setinfo.return_value);
276 dbg_sensor(1, "[%s] min again : %d\n", __func__, setinfo.return_value);
277 setinfo.return_value = 0;
278 CALL_CISOPS(cis, cis_get_max_analog_gain, subdev, &setinfo.return_value);
279 dbg_sensor(1, "[%s] max again : %d\n", __func__, setinfo.return_value);
280 setinfo.return_value = 0;
281 CALL_CISOPS(cis, cis_get_min_digital_gain, subdev, &setinfo.return_value);
282 dbg_sensor(1, "[%s] min dgain : %d\n", __func__, setinfo.return_value);
283 setinfo.return_value = 0;
284 CALL_CISOPS(cis, cis_get_max_digital_gain, subdev, &setinfo.return_value);
285 dbg_sensor(1, "[%s] max dgain : %d\n", __func__, setinfo.return_value);
286
287#ifdef DEBUG_SENSOR_TIME
288 do_gettimeofday(&end);
289 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
290#endif
291
292p_err:
293 return ret;
294}
295
296int sensor_2l7_cis_log_status(struct v4l2_subdev *subdev)
297{
298 int ret = 0;
299 struct fimc_is_cis *cis;
300 struct i2c_client *client = NULL;
301 u8 data8 = 0;
302 u16 data16 = 0;
303
304 FIMC_BUG(!subdev);
305
306 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
307 if (!cis) {
308 err("cis is NULL");
309 ret = -ENODEV;
310 goto p_err;
311 }
312
313 client = cis->client;
314 if (unlikely(!client)) {
315 err("client is NULL");
316 ret = -ENODEV;
317 goto p_err;
318 }
319
320 I2C_MUTEX_LOCK(cis->i2c_lock);
321 pr_err("[SEN:DUMP] *******************************\n");
322 fimc_is_sensor_read16(client, 0x0000, &data16);
323 pr_err("[SEN:DUMP] model_id(%x)\n", data16);
324 fimc_is_sensor_read8(client, 0x0002, &data8);
325 pr_err("[SEN:DUMP] revision_number(%x)\n", data8);
326 fimc_is_sensor_read8(client, 0x0005, &data8);
327 pr_err("[SEN:DUMP] frame_count(%x)\n", data8);
328 fimc_is_sensor_read8(client, 0x0100, &data8);
329 pr_err("[SEN:DUMP] mode_select(%x)\n", data8);
330
331 sensor_cis_dump_registers(subdev, sensor_2l7_setfiles[0], sensor_2l7_setfile_sizes[0]);
332 I2C_MUTEX_UNLOCK(cis->i2c_lock);
333
334 pr_err("[SEN:DUMP] *******************************\n");
335
336p_err:
337 return ret;
338}
339
340#if USE_GROUP_PARAM_HOLD
341static int sensor_2l7_cis_group_param_hold_func(struct v4l2_subdev *subdev, unsigned int hold)
342{
343 int ret = 0;
344 struct fimc_is_cis *cis = NULL;
345 struct i2c_client *client = NULL;
346
347 FIMC_BUG(!subdev);
348
349 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
350
351 FIMC_BUG(!cis);
352 FIMC_BUG(!cis->cis_data);
353
354 client = cis->client;
355 if (unlikely(!client)) {
356 err("client is NULL");
357 ret = -EINVAL;
358 goto p_err;
359 }
360
361 if (hold == cis->cis_data->group_param_hold) {
362 pr_debug("already group_param_hold (%d)\n", cis->cis_data->group_param_hold);
363 goto p_err;
364 }
365
366 ret = fimc_is_sensor_write8(client, 0x0104, hold);
367 if (ret < 0)
368 goto p_err;
369
370 cis->cis_data->group_param_hold = hold;
371 ret = 1;
372p_err:
373 return ret;
374}
375#else
376static inline int sensor_2l7_cis_group_param_hold_func(struct v4l2_subdev *subdev, unsigned int hold)
377{ return 0; }
378#endif
379
380/* Input
381 * hold : true - hold, flase - no hold
382 * Output
383 * return: 0 - no effect(already hold or no hold)
384 * positive - setted by request
385 * negative - ERROR value
386 */
387int sensor_2l7_cis_group_param_hold(struct v4l2_subdev *subdev, bool hold)
388{
389 int ret = 0;
390 struct fimc_is_cis *cis = NULL;
391
392 FIMC_BUG(!subdev);
393
394 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
395
396 FIMC_BUG(!cis);
397 FIMC_BUG(!cis->cis_data);
398
399 I2C_MUTEX_LOCK(cis->i2c_lock);
400 ret = sensor_2l7_cis_group_param_hold_func(subdev, hold);
401 if (ret < 0)
402 goto p_err;
403
404p_err:
405 I2C_MUTEX_UNLOCK(cis->i2c_lock);
406 return ret;
407}
408
409int sensor_2l7_cis_set_global_setting(struct v4l2_subdev *subdev)
410{
411 int ret = 0;
412 struct fimc_is_cis *cis = NULL;
413
414 FIMC_BUG(!subdev);
415
416 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
417 FIMC_BUG(!cis);
418
419 I2C_MUTEX_LOCK(cis->i2c_lock);
420 /* setfile global setting is at camera entrance */
421 ret = sensor_cis_set_registers(subdev, sensor_2l7_global, sensor_2l7_global_size);
422 if (ret < 0) {
423 err("sensor_2l7_set_registers fail!!");
424 goto p_err;
425 }
426
427 dbg_sensor(1, "[%s] global setting done\n", __func__);
428
429p_err:
430 I2C_MUTEX_UNLOCK(cis->i2c_lock);
431 return ret;
432}
433
434int sensor_2l7_cis_mode_change(struct v4l2_subdev *subdev, u32 mode)
435{
436 int ret = 0;
437 struct fimc_is_cis *cis = NULL;
438
439 FIMC_BUG(!subdev);
440
441 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
442 FIMC_BUG(!cis);
443 FIMC_BUG(!cis->cis_data);
444
445 if (mode > sensor_2l7_max_setfile_num) {
446 err("invalid mode(%d)!!", mode);
447 ret = -EINVAL;
448 goto p_err;
449 }
450
451 /* If check_rev fail when cis_init, one more check_rev in mode_change */
452 if (cis->rev_flag == true) {
453 cis->rev_flag = false;
454 ret = sensor_cis_check_rev(cis);
455 if (ret < 0) {
456 err("sensor_2l7_check_rev is fail");
457 goto p_err;
458 }
459 }
460
461 I2C_MUTEX_LOCK(cis->i2c_lock);
462#if 0 /* cis_data_calculation is called in module_s_format */
463 sensor_2l7_cis_data_calculation(sensor_2l7_pllinfos[mode], cis->cis_data);
464#endif
465 sensor_2l7_set_integration_max_margin(mode, cis->cis_data);
466
467#if defined(CONFIG_SENSOR_RETENTION_USE)
468 /* Retention mode sensor mode select */
469 switch (mode) {
470 case SENSOR_2L7_8064X3024_30FPS:
471 info("[%s] retention mode: SENSOR_2L7_8064X3024_30FPS\n", __func__);
472 fimc_is_sensor_write16(cis->client, 0x0100, 0x0003);
473 fimc_is_sensor_write16(cis->client, 0x021E, 0x0100);
474 fimc_is_sensor_write16(cis->client, 0x6028, 0x2000);
475 fimc_is_sensor_write16(cis->client, 0x602A, 0x0A78);
476 fimc_is_sensor_write16(cis->client, 0x6F12, 0x2000);
477 fimc_is_sensor_write16(cis->client, 0x6F12, 0x8800);
478 fimc_is_sensor_write16(cis->client, 0x0100, 0x0103);
479 break;
480 case SENSOR_2L7_8064X2268_30FPS:
481 info("[%s] retention mode: SENSOR_2L7_8064X2268_30FPS\n", __func__);
482 fimc_is_sensor_write16(cis->client, 0x0100, 0x0003);
483 fimc_is_sensor_write16(cis->client, 0x021E, 0x0100);
484 fimc_is_sensor_write16(cis->client, 0x6028, 0x2000);
485 fimc_is_sensor_write16(cis->client, 0x602A, 0x0A78);
486 fimc_is_sensor_write16(cis->client, 0x6F12, 0x2000);
487 fimc_is_sensor_write16(cis->client, 0x6F12, 0x8A00);
488 fimc_is_sensor_write16(cis->client, 0x0100, 0x0103);
489 break;
490 case SENSOR_2L7_4032X2268_60FPS:
491 info("[%s] retention mode: SENSOR_2L7_4032X2268_60FPS\n", __func__);
492 fimc_is_sensor_write16(cis->client, 0x0100, 0x0003);
493 fimc_is_sensor_write16(cis->client, 0x021E, 0x0100);
494 fimc_is_sensor_write16(cis->client, 0x6028, 0x2000);
495 fimc_is_sensor_write16(cis->client, 0x602A, 0x0A78);
496 fimc_is_sensor_write16(cis->client, 0x6F12, 0x2000);
497 fimc_is_sensor_write16(cis->client, 0x6F12, 0x8E00);
498 fimc_is_sensor_write16(cis->client, 0x0100, 0x0103);
499 break;
500 case SENSOR_2L7_1008X756_120FPS:
501 info("[%s] retention mode: SENSOR_2L7_1008X756_120FPS\n", __func__);
502 fimc_is_sensor_write16(cis->client, 0x0100, 0x0003);
503 fimc_is_sensor_write16(cis->client, 0x021E, 0x0000);
504 fimc_is_sensor_write16(cis->client, 0x6028, 0x2000);
505 fimc_is_sensor_write16(cis->client, 0x602A, 0x0A78);
506 fimc_is_sensor_write16(cis->client, 0x6F12, 0x2000);
507 fimc_is_sensor_write16(cis->client, 0x6F12, 0x8C00);
508 fimc_is_sensor_write16(cis->client, 0x0100, 0x0103);
509 break;
510 default:
511 info("[%s] not support retention sensor mode(%d)\n", __func__, mode);
512 ret = sensor_cis_set_registers(subdev, sensor_2l7_setfiles[mode], sensor_2l7_setfile_sizes[mode]);
513 if (ret < 0) {
514 err("sensor_2l7_set_registers fail!!");
515 goto p_err;
516 }
517 }
518#else
519 ret = sensor_cis_set_registers(subdev, sensor_2l7_setfiles[mode], sensor_2l7_setfile_sizes[mode]);
520 if (ret < 0) {
521 err("sensor_2l7_set_registers fail!!");
522 goto p_err;
523 }
524
525 /* ISP2 output enable (0x400030CB : ISP2 data_type) */
526 fimc_is_sensor_write16(cis->client, 0x6028, 0x4000);
527 fimc_is_sensor_write16(cis->client, 0x602A, 0x30BC);
528 fimc_is_sensor_write16(cis->client, 0x6F12, 0x012B); //RAW10
529#endif
530 dbg_sensor(1, "[%s] mode changed(%d)\n", __func__, mode);
531
532p_err:
533 I2C_MUTEX_UNLOCK(cis->i2c_lock);
534 return ret;
535}
536
537#ifdef CONFIG_SENSOR_RETENTION_USE
538int sensor_2l7_cis_retention_prepare(struct v4l2_subdev *subdev)
539{
540 int ret = 0, i;
541 struct fimc_is_cis *cis = NULL;
542
543 FIMC_BUG(!subdev);
544
545 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
546 FIMC_BUG(!cis);
547
548 I2C_MUTEX_LOCK(cis->i2c_lock);
549 for (i = 0; i < sensor_2l7_max_retention_num; i++) {
550 ret = sensor_cis_set_registers(subdev, sensor_2l7_retention[i], sensor_2l7_retention_size[i]);
551 if (ret < 0) {
552 err("sensor_2l7_set_registers fail!!");
553 goto p_err;
554 }
555 }
556 info("[%s] retention sensor sram write done\n", __func__);
557
558p_err:
559 I2C_MUTEX_UNLOCK(cis->i2c_lock);
560 return ret;
561}
562
563int sensor_2l7_cis_retention_crc_check(struct v4l2_subdev *subdev)
564{
565 int ret = 0;
566 u8 crc_check = 0, crc_status = 0;
567 struct fimc_is_cis *cis = NULL;
568
569 FIMC_BUG(!subdev);
570
571 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
572 FIMC_BUG(!cis);
573 FIMC_BUG(!cis->cis_data);
574
575 I2C_MUTEX_LOCK(cis->i2c_lock);
576 /* retention mode CRC check */
577 fimc_is_sensor_write16(cis->client, 0x6018, 0x0001);
578 fimc_is_sensor_write16(cis->client, 0x7002, 0x0001);
579 fimc_is_sensor_write16(cis->client, 0x6014, 0x0001);
580 mdelay(4);
581 fimc_is_sensor_write16(cis->client, 0x7002, 0x0000);
582 mdelay(4);
583
584 fimc_is_sensor_read8(cis->client, 0x070B, &crc_check);
585 fimc_is_sensor_read8(cis->client, 0x070F, &crc_status);
586 I2C_MUTEX_UNLOCK(cis->i2c_lock);
587
588 if(crc_check == 0x01) {
589 info("[%s] retention SRAM CRC check: pass!\n", __func__);
590 } else {
591 info("[%s] retention SRAM CRC check: fail!\n", __func__);
592 switch (crc_status) {
593 case 0:
594 info("[%s] CRC check fail Info: checksum PASSED.\n", __func__);
595 break;
596 case 1:
597 info("[%s] CRC check fail Info: tuning and SMIA API RAM checksum failed.\n", __func__);
598 break;
599 case 2:
600 info("[%s] CRC check fail Info: MON_FE RAM checksum failed.\n", __func__);
601 break;
602 case 4:
603 info("[%s] CRC check fail Info: MON_ISP_BPC RAM checksum failed.\n", __func__);
604 break;
605 default:
606 info("[%s] CRC check fail Info: undefined error.\n", __func__);
607 }
608
609 info("[%s] rewrite retention modes to SRAM\n", __func__);
610 ret = sensor_2l7_cis_retention_prepare(subdev);
611 if (ret < 0) {
612 err("sensor sram rewrite fail to CRC fail!!");
613 goto p_err;
614 }
615 }
616
617p_err:
618 return ret;
619}
620#endif
621
622/* TODO: Sensor set size sequence(sensor done, sensor stop, 3AA done in FW case */
623int sensor_2l7_cis_set_size(struct v4l2_subdev *subdev, cis_shared_data *cis_data)
624{
625 int ret = 0;
626 struct fimc_is_cis *cis = NULL;
627#ifdef DEBUG_SENSOR_TIME
628 struct timeval st, end;
629 do_gettimeofday(&st);
630#endif
631 FIMC_BUG(!subdev);
632
633 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
634 FIMC_BUG(!cis);
635
636 dbg_sensor(1, "[MOD:D:%d] %s\n", cis->id, __func__);
637
638 if (unlikely(!cis_data)) {
639 err("cis data is NULL");
640 if (unlikely(!cis->cis_data)) {
641 ret = -EINVAL;
642 goto p_err;
643 } else {
644 cis_data = cis->cis_data;
645 }
646 }
647
648 cis_data->frame_time = (cis_data->line_readOut_time * cis_data->cur_height / 1000);
649 cis->cis_data->rolling_shutter_skew = (cis->cis_data->cur_height - 1) * cis->cis_data->line_readOut_time;
650 dbg_sensor(1, "[%s] frame_time(%d), rolling_shutter_skew(%lld)\n", __func__,
651 cis->cis_data->frame_time, cis->cis_data->rolling_shutter_skew);
652
653#ifdef DEBUG_SENSOR_TIME
654 do_gettimeofday(&end);
655 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
656#endif
657
658p_err:
659 return ret;
660}
661
662int sensor_2l7_cis_stream_on(struct v4l2_subdev *subdev)
663{
664 int ret = 0;
665 struct fimc_is_cis *cis;
666 struct i2c_client *client;
667 cis_shared_data *cis_data;
668 struct fimc_is_device_sensor_peri *sensor_peri = NULL;
669
670#ifdef DEBUG_SENSOR_TIME
671 struct timeval st, end;
672 do_gettimeofday(&st);
673#endif
674
675 FIMC_BUG(!subdev);
676
677 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
678
679 FIMC_BUG(!cis);
680 FIMC_BUG(!cis->cis_data);
681
682 sensor_peri = container_of(cis, struct fimc_is_device_sensor_peri, cis);
683 FIMC_BUG(!sensor_peri);
684
685 client = cis->client;
686 if (unlikely(!client)) {
687 err("client is NULL");
688 ret = -EINVAL;
689 goto p_err;
690 }
691
692 cis_data = cis->cis_data;
693
694 dbg_sensor(1, "[MOD:D:%d] %s\n", cis->id, __func__);
695
696 I2C_MUTEX_LOCK(cis->i2c_lock);
697 ret = sensor_2l7_cis_group_param_hold_func(subdev, 0x01);
698 if (ret < 0)
699 err("group_param_hold_func failed at stream on");
700
701#ifdef DEBUG_2L7_PLL
702 {
703 u16 pll;
704 fimc_is_sensor_read16(client, 0x0300, &pll);
705 dbg_sensor(1, "______ vt_pix_clk_div(%x)\n", pll);
706 fimc_is_sensor_read16(client, 0x0302, &pll);
707 dbg_sensor(1, "______ vt_sys_clk_div(%x)\n", pll);
708 fimc_is_sensor_read16(client, 0x0304, &pll);
709 dbg_sensor(1, "______ pre_pll_clk_div(%x)\n", pll);
710 fimc_is_sensor_read16(client, 0x0306, &pll);
711 dbg_sensor(1, "______ pll_multiplier(%x)\n", pll);
712 fimc_is_sensor_read16(client, 0x0308, &pll);
713 dbg_sensor(1, "______ op_pix_clk_div(%x)\n", pll);
714 fimc_is_sensor_read16(client, 0x030a, &pll);
715 dbg_sensor(1, "______ op_sys_clk_div(%x)\n", pll);
716
717 fimc_is_sensor_read16(client, 0x030c, &pll);
718 dbg_sensor(1, "______ secnd_pre_pll_clk_div(%x)\n", pll);
719 fimc_is_sensor_read16(client, 0x030e, &pll);
720 dbg_sensor(1, "______ secnd_pll_multiplier(%x)\n", pll);
721 fimc_is_sensor_read16(client, 0x0340, &pll);
722 dbg_sensor(1, "______ frame_length_lines(%x)\n", pll);
723 fimc_is_sensor_read16(client, 0x0342, &pll);
724 dbg_sensor(1, "______ line_length_pck(%x)\n", pll);
725 }
726#endif
727
728 /*
729 * If a companion is used,
730 * then 8 ms waiting is needed before the StreamOn of a sensor (S5K2L7).
731 */
732 if (test_bit(FIMC_IS_SENSOR_PREPROCESSOR_AVAILABLE, &sensor_peri->peri_state)) {
733 mdelay(8);
734 }
735
736 /* Sensor stream on */
737 fimc_is_sensor_write16(client, 0x6028, 0x4000);
738 fimc_is_sensor_write8(client, 0x0100, 0x01);
739
740 ret = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
741 if (ret < 0)
742 err("group_param_hold_func failed at stream on");
743
744 I2C_MUTEX_UNLOCK(cis->i2c_lock);
745
746 cis_data->stream_on = true;
747
748#ifdef DEBUG_SENSOR_TIME
749 do_gettimeofday(&end);
750 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
751#endif
752
753p_err:
754 return ret;
755}
756
757int sensor_2l7_cis_stream_off(struct v4l2_subdev *subdev)
758{
759 int ret = 0;
760 struct fimc_is_cis *cis;
761 struct i2c_client *client;
762 cis_shared_data *cis_data;
763
764#ifdef DEBUG_SENSOR_TIME
765 struct timeval st, end;
766 do_gettimeofday(&st);
767#endif
768
769 FIMC_BUG(!subdev);
770
771 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
772
773 FIMC_BUG(!cis);
774 FIMC_BUG(!cis->cis_data);
775
776 client = cis->client;
777 if (unlikely(!client)) {
778 err("client is NULL");
779 ret = -EINVAL;
780 goto p_err;
781 }
782
783 cis_data = cis->cis_data;
784
785 dbg_sensor(1, "[MOD:D:%d] %s\n", cis->id, __func__);
786
787 I2C_MUTEX_LOCK(cis->i2c_lock);
788 ret = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
789 if (ret < 0)
790 err("group_param_hold_func failed at stream off");
791
792#ifdef CONFIG_SENSOR_RETENTION_USE
793 /* retention mode CRC check register enable */
794 fimc_is_sensor_write8(client, 0x070A, 0x01);
795#endif
796
797 fimc_is_sensor_write8(client, 0x0100, 0x00);
798 I2C_MUTEX_UNLOCK(cis->i2c_lock);
799
800 cis_data->stream_on = false;
801
802#ifdef DEBUG_SENSOR_TIME
803 do_gettimeofday(&end);
804 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
805#endif
806
807p_err:
808 return ret;
809}
810
811int sensor_2l7_cis_set_exposure_time(struct v4l2_subdev *subdev, struct ae_param *target_exposure)
812{
813 int ret = 0;
814 int hold = 0;
815 struct fimc_is_cis *cis;
816 struct i2c_client *client;
817 cis_shared_data *cis_data;
818
819 u32 vt_pic_clk_freq_mhz = 0;
820 u16 long_coarse_int = 0;
821 u16 short_coarse_int = 0;
822 u32 line_length_pck = 0;
823 u32 min_fine_int = 0;
824
825#ifdef DEBUG_SENSOR_TIME
826 struct timeval st, end;
827 do_gettimeofday(&st);
828#endif
829
830 FIMC_BUG(!subdev);
831 FIMC_BUG(!target_exposure);
832
833 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
834
835 FIMC_BUG(!cis);
836 FIMC_BUG(!cis->cis_data);
837
838 client = cis->client;
839 if (unlikely(!client)) {
840 err("client is NULL");
841 ret = -EINVAL;
842 goto p_err;
843 }
844
845 if ((target_exposure->long_val <= 0) || (target_exposure->short_val <= 0)) {
846 err("[%s] invalid target exposure(%d, %d)\n", __func__,
847 target_exposure->long_val, target_exposure->short_val);
848 ret = -EINVAL;
849 goto p_err;
850 }
851
852 cis_data = cis->cis_data;
853
854 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), target long(%d), short(%d)\n", cis->id, __func__,
855 cis_data->sen_vsync_count, target_exposure->long_val, target_exposure->short_val);
856
857 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
858 line_length_pck = cis_data->line_length_pck;
859 min_fine_int = cis_data->min_fine_integration_time;
860
861 long_coarse_int = ((target_exposure->long_val * vt_pic_clk_freq_mhz) - min_fine_int) / line_length_pck;
862 short_coarse_int = ((target_exposure->short_val * vt_pic_clk_freq_mhz) - min_fine_int) / line_length_pck;
863
864 if (long_coarse_int > cis_data->max_coarse_integration_time) {
865 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long coarse(%d) max(%d)\n", cis->id, __func__,
866 cis_data->sen_vsync_count, long_coarse_int, cis_data->max_coarse_integration_time);
867 long_coarse_int = cis_data->max_coarse_integration_time;
868 }
869
870 if (short_coarse_int > cis_data->max_coarse_integration_time) {
871 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), short coarse(%d) max(%d)\n", cis->id, __func__,
872 cis_data->sen_vsync_count, short_coarse_int, cis_data->max_coarse_integration_time);
873 short_coarse_int = cis_data->max_coarse_integration_time;
874 }
875
876 if (long_coarse_int < cis_data->min_coarse_integration_time) {
877 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long coarse(%d) min(%d)\n", cis->id, __func__,
878 cis_data->sen_vsync_count, long_coarse_int, cis_data->min_coarse_integration_time);
879 long_coarse_int = cis_data->min_coarse_integration_time;
880 }
881
882 if (short_coarse_int < cis_data->min_coarse_integration_time) {
883 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), short coarse(%d) min(%d)\n", cis->id, __func__,
884 cis_data->sen_vsync_count, short_coarse_int, cis_data->min_coarse_integration_time);
885 short_coarse_int = cis_data->min_coarse_integration_time;
886 }
887
888 I2C_MUTEX_LOCK(cis->i2c_lock);
889 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x01);
890 if (hold < 0) {
891 ret = hold;
892 goto p_err;
893 }
894
895 /* WDR mode off */
896 fimc_is_sensor_write16(cis->client, 0x021E, 0x0000);
897
898 /* Short exposure */
899 ret = fimc_is_sensor_write16(client, 0x0202, short_coarse_int);
900 if (ret < 0)
901 goto p_err;
902
903 /* Long exposure */
904 if (fimc_is_vender_enable_wdr(cis_data)) {
905 ret = fimc_is_sensor_write16(client, 0x0226, long_coarse_int);
906 if (ret < 0)
907 goto p_err;
908 }
909
910 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), vt_pic_clk_freq_mhz (%d),"
911 KERN_CONT "line_length_pck(%d), min_fine_int (%d)\n", cis->id, __func__,
912 cis_data->sen_vsync_count, vt_pic_clk_freq_mhz, line_length_pck, min_fine_int);
913 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), frame_length_lines(%#x),"
914 KERN_CONT "long_coarse_int %#x, short_coarse_int %#x\n", cis->id, __func__,
915 cis_data->sen_vsync_count, cis_data->frame_length_lines, long_coarse_int, short_coarse_int);
916
917#ifdef DEBUG_SENSOR_TIME
918 do_gettimeofday(&end);
919 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
920#endif
921
922p_err:
923 if (hold > 0) {
924 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
925 if (hold < 0)
926 ret = hold;
927 }
928 I2C_MUTEX_UNLOCK(cis->i2c_lock);
929
930 return ret;
931}
932
933int sensor_2l7_cis_get_min_exposure_time(struct v4l2_subdev *subdev, u32 *min_expo)
934{
935 int ret = 0;
936 struct fimc_is_cis *cis = NULL;
937 cis_shared_data *cis_data = NULL;
938 u32 min_integration_time = 0;
939 u32 min_coarse = 0;
940 u32 min_fine = 0;
941 u32 vt_pic_clk_freq_mhz = 0;
942 u32 line_length_pck = 0;
943
944#ifdef DEBUG_SENSOR_TIME
945 struct timeval st, end;
946 do_gettimeofday(&st);
947#endif
948
949 FIMC_BUG(!subdev);
950 FIMC_BUG(!min_expo);
951
952 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
953
954 FIMC_BUG(!cis);
955 FIMC_BUG(!cis->cis_data);
956
957 cis_data = cis->cis_data;
958
959 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
960 if (vt_pic_clk_freq_mhz == 0) {
961 pr_err("[MOD:D:%d] %s, Invalid vt_pic_clk_freq_mhz(%d)\n", cis->id, __func__, vt_pic_clk_freq_mhz);
962 goto p_err;
963 }
964 line_length_pck = cis_data->line_length_pck;
965 min_coarse = cis_data->min_coarse_integration_time;
966 min_fine = cis_data->min_fine_integration_time;
967
968 min_integration_time = ((line_length_pck * min_coarse) + min_fine) / vt_pic_clk_freq_mhz;
969 *min_expo = min_integration_time;
970
971 dbg_sensor(1, "[%s] min integration time %d\n", __func__, min_integration_time);
972
973#ifdef DEBUG_SENSOR_TIME
974 do_gettimeofday(&end);
975 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
976#endif
977
978p_err:
979 return ret;
980}
981
982int sensor_2l7_cis_get_max_exposure_time(struct v4l2_subdev *subdev, u32 *max_expo)
983{
984 int ret = 0;
985 struct fimc_is_cis *cis;
986 cis_shared_data *cis_data;
987 u32 max_integration_time = 0;
988 u32 max_coarse_margin = 0;
989 u32 max_fine_margin = 0;
990 u32 max_coarse = 0;
991 u32 max_fine = 0;
992 u32 vt_pic_clk_freq_mhz = 0;
993 u32 line_length_pck = 0;
994 u32 frame_length_lines = 0;
995
996#ifdef DEBUG_SENSOR_TIME
997 struct timeval st, end;
998 do_gettimeofday(&st);
999#endif
1000
1001 FIMC_BUG(!subdev);
1002 FIMC_BUG(!max_expo);
1003
1004 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1005
1006 FIMC_BUG(!cis);
1007 FIMC_BUG(!cis->cis_data);
1008
1009 cis_data = cis->cis_data;
1010
1011 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
1012 if (vt_pic_clk_freq_mhz == 0) {
1013 pr_err("[MOD:D:%d] %s, Invalid vt_pic_clk_freq_mhz(%d)\n", cis->id, __func__, vt_pic_clk_freq_mhz);
1014 goto p_err;
1015 }
1016 line_length_pck = cis_data->line_length_pck;
1017 frame_length_lines = cis_data->frame_length_lines;
1018
1019 max_coarse_margin = cis_data->max_margin_coarse_integration_time;
1020 max_fine_margin = line_length_pck - cis_data->min_fine_integration_time;
1021 max_coarse = frame_length_lines - max_coarse_margin;
1022 max_fine = cis_data->max_fine_integration_time;
1023
1024 max_integration_time = ((line_length_pck * max_coarse) + max_fine) / vt_pic_clk_freq_mhz;
1025
1026 *max_expo = max_integration_time;
1027
1028 /* TODO: Is this values update hear? */
1029 cis_data->max_margin_fine_integration_time = max_fine_margin;
1030 cis_data->max_coarse_integration_time = max_coarse;
1031
1032 dbg_sensor(1, "[%s] max integration time %d, max margin fine integration %d, max coarse integration %d\n",
1033 __func__, max_integration_time, cis_data->max_margin_fine_integration_time, cis_data->max_coarse_integration_time);
1034
1035#ifdef DEBUG_SENSOR_TIME
1036 do_gettimeofday(&end);
1037 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1038#endif
1039
1040p_err:
1041 return ret;
1042}
1043
1044int sensor_2l7_cis_adjust_frame_duration(struct v4l2_subdev *subdev,
1045 u32 input_exposure_time,
1046 u32 *target_duration)
1047{
1048 int ret = 0;
1049 struct fimc_is_cis *cis;
1050 cis_shared_data *cis_data;
1051
1052 u32 vt_pic_clk_freq_mhz = 0;
1053 u32 line_length_pck = 0;
1054 u32 frame_length_lines = 0;
1055 u32 frame_duration = 0;
1056
1057#ifdef DEBUG_SENSOR_TIME
1058 struct timeval st, end;
1059 do_gettimeofday(&st);
1060#endif
1061
1062 FIMC_BUG(!subdev);
1063 FIMC_BUG(!target_duration);
1064
1065 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1066
1067 FIMC_BUG(!cis);
1068 FIMC_BUG(!cis->cis_data);
1069
1070 cis_data = cis->cis_data;
1071
1072 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
1073 line_length_pck = cis_data->line_length_pck;
1074 frame_length_lines = ((vt_pic_clk_freq_mhz * input_exposure_time) / line_length_pck);
1075 frame_length_lines += cis_data->max_margin_coarse_integration_time;
1076
1077 frame_duration = (frame_length_lines * line_length_pck) / vt_pic_clk_freq_mhz;
1078
1079 dbg_sensor(1, "[%s](vsync cnt = %d) input exp(%d), adj duration, frame duraion(%d), min_frame_us(%d)\n",
1080 __func__, cis_data->sen_vsync_count, input_exposure_time, frame_duration, cis_data->min_frame_us_time);
1081 dbg_sensor(1, "[%s](vsync cnt = %d) adj duration, frame duraion(%d), min_frame_us(%d)\n",
1082 __func__, cis_data->sen_vsync_count, frame_duration, cis_data->min_frame_us_time);
1083
1084 *target_duration = MAX(frame_duration, cis_data->min_frame_us_time);
1085
1086#ifdef DEBUG_SENSOR_TIME
1087 do_gettimeofday(&end);
1088 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1089#endif
1090
1091 return ret;
1092}
1093
1094int sensor_2l7_cis_set_frame_duration(struct v4l2_subdev *subdev, u32 frame_duration)
1095{
1096 int ret = 0;
1097 int hold = 0;
1098 struct fimc_is_cis *cis;
1099 struct i2c_client *client;
1100 cis_shared_data *cis_data;
1101
1102 u32 vt_pic_clk_freq_mhz = 0;
1103 u32 line_length_pck = 0;
1104 u16 frame_length_lines = 0;
1105
1106#ifdef DEBUG_SENSOR_TIME
1107 struct timeval st, end;
1108 do_gettimeofday(&st);
1109#endif
1110
1111 FIMC_BUG(!subdev);
1112
1113 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1114
1115 FIMC_BUG(!cis);
1116 FIMC_BUG(!cis->cis_data);
1117
1118 client = cis->client;
1119 if (unlikely(!client)) {
1120 err("client is NULL");
1121 ret = -EINVAL;
1122 goto p_err;
1123 }
1124
1125 cis_data = cis->cis_data;
1126
1127 if (frame_duration < cis_data->min_frame_us_time) {
1128 dbg_sensor(1, "frame duration is less than min(%d)\n", frame_duration);
1129 frame_duration = cis_data->min_frame_us_time;
1130 }
1131
1132 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
1133 line_length_pck = cis_data->line_length_pck;
1134
1135 frame_length_lines = (u16)((vt_pic_clk_freq_mhz * frame_duration) / line_length_pck);
1136
1137 dbg_sensor(1, "[MOD:D:%d] %s, vt_pic_clk_freq_mhz(%#x) frame_duration = %d us,"
1138 KERN_CONT "(line_length_pck%#x), frame_length_lines(%#x)\n",
1139 cis->id, __func__, vt_pic_clk_freq_mhz, frame_duration, line_length_pck, frame_length_lines);
1140
1141 I2C_MUTEX_LOCK(cis->i2c_lock);
1142 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x01);
1143 if (hold < 0) {
1144 ret = hold;
1145 goto p_err;
1146 }
1147
1148 ret = fimc_is_sensor_write16(client, 0x0340, frame_length_lines);
1149 if (ret < 0)
1150 goto p_err;
1151
1152 cis_data->cur_frame_us_time = frame_duration;
1153 cis_data->frame_length_lines = frame_length_lines;
1154 cis_data->max_coarse_integration_time = cis_data->frame_length_lines - cis_data->max_margin_coarse_integration_time;
1155
1156#ifdef DEBUG_SENSOR_TIME
1157 do_gettimeofday(&end);
1158 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1159#endif
1160
1161p_err:
1162 if (hold > 0) {
1163 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
1164 if (hold < 0)
1165 ret = hold;
1166 }
1167 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1168
1169 return ret;
1170}
1171
1172int sensor_2l7_cis_set_frame_rate(struct v4l2_subdev *subdev, u32 min_fps)
1173{
1174 int ret = 0;
1175 struct fimc_is_cis *cis;
1176 cis_shared_data *cis_data;
1177
1178 u32 frame_duration = 0;
1179
1180#ifdef DEBUG_SENSOR_TIME
1181 struct timeval st, end;
1182 do_gettimeofday(&st);
1183#endif
1184
1185 FIMC_BUG(!subdev);
1186
1187 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1188
1189 FIMC_BUG(!cis);
1190 FIMC_BUG(!cis->cis_data);
1191
1192 cis_data = cis->cis_data;
1193
1194 if (min_fps > cis_data->max_fps) {
1195 err("[MOD:D:%d] %s, request FPS is too high(%d), set to max(%d)\n",
1196 cis->id, __func__, min_fps, cis_data->max_fps);
1197 min_fps = cis_data->max_fps;
1198 }
1199
1200 if (min_fps == 0) {
1201 err("[MOD:D:%d] %s, request FPS is 0, set to min FPS(1)\n",
1202 cis->id, __func__);
1203 min_fps = 1;
1204 }
1205
1206 frame_duration = (1 * 1000 * 1000) / min_fps;
1207
1208 dbg_sensor(1, "[MOD:D:%d] %s, set FPS(%d), frame duration(%d)\n",
1209 cis->id, __func__, min_fps, frame_duration);
1210
1211 ret = sensor_2l7_cis_set_frame_duration(subdev, frame_duration);
1212 if (ret < 0) {
1213 err("[MOD:D:%d] %s, set frame duration is fail(%d)\n",
1214 cis->id, __func__, ret);
1215 goto p_err;
1216 }
1217
1218 cis_data->min_frame_us_time = frame_duration;
1219
1220#ifdef DEBUG_SENSOR_TIME
1221 do_gettimeofday(&end);
1222 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1223#endif
1224
1225p_err:
1226
1227 return ret;
1228}
1229
1230int sensor_2l7_cis_adjust_analog_gain(struct v4l2_subdev *subdev, u32 input_again, u32 *target_permile)
1231{
1232 int ret = 0;
1233 struct fimc_is_cis *cis;
1234 cis_shared_data *cis_data;
1235
1236 u32 again_code = 0;
1237 u32 again_permile = 0;
1238
1239#ifdef DEBUG_SENSOR_TIME
1240 struct timeval st, end;
1241 do_gettimeofday(&st);
1242#endif
1243
1244 FIMC_BUG(!subdev);
1245 FIMC_BUG(!target_permile);
1246
1247 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1248
1249 FIMC_BUG(!cis);
1250 FIMC_BUG(!cis->cis_data);
1251
1252 cis_data = cis->cis_data;
1253
1254 again_code = sensor_cis_calc_again_code(input_again);
1255
1256 if (again_code > cis_data->max_analog_gain[0]) {
1257 again_code = cis_data->max_analog_gain[0];
1258 } else if (again_code < cis_data->min_analog_gain[0]) {
1259 again_code = cis_data->min_analog_gain[0];
1260 }
1261
1262 again_permile = sensor_cis_calc_again_permile(again_code);
1263
1264 dbg_sensor(1, "[%s] min again(%d), max(%d), input_again(%d), code(%d), permile(%d)\n", __func__,
1265 cis_data->max_analog_gain[0],
1266 cis_data->min_analog_gain[0],
1267 input_again,
1268 again_code,
1269 again_permile);
1270
1271 *target_permile = again_permile;
1272
1273 return ret;
1274}
1275
1276int sensor_2l7_cis_set_analog_gain(struct v4l2_subdev *subdev, struct ae_param *again)
1277{
1278 int ret = 0;
1279 int hold = 0;
1280 struct fimc_is_cis *cis;
1281 struct i2c_client *client;
1282
1283 u16 analog_gain = 0;
1284
1285#ifdef DEBUG_SENSOR_TIME
1286 struct timeval st, end;
1287 do_gettimeofday(&st);
1288#endif
1289
1290 FIMC_BUG(!subdev);
1291 FIMC_BUG(!again);
1292
1293 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1294
1295 FIMC_BUG(!cis);
1296
1297 client = cis->client;
1298 if (unlikely(!client)) {
1299 err("client is NULL");
1300 ret = -EINVAL;
1301 goto p_err;
1302 }
1303
1304 analog_gain = (u16)sensor_cis_calc_again_code(again->val);
1305
1306 if (analog_gain < cis->cis_data->min_analog_gain[0]) {
1307 analog_gain = cis->cis_data->min_analog_gain[0];
1308 }
1309
1310 if (analog_gain > cis->cis_data->max_analog_gain[0]) {
1311 analog_gain = cis->cis_data->max_analog_gain[0];
1312 }
1313
1314 dbg_sensor(1, "[MOD:D:%d] %s(vsync cnt = %d), input_again = %d us, analog_gain(%#x)\n",
1315 cis->id, __func__, cis->cis_data->sen_vsync_count, again->val, analog_gain);
1316
1317 I2C_MUTEX_LOCK(cis->i2c_lock);
1318 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x01);
1319 if (hold < 0) {
1320 ret = hold;
1321 goto p_err;
1322 }
1323
1324 ret = fimc_is_sensor_write16(client, 0x0204, analog_gain);
1325 if (ret < 0)
1326 goto p_err;
1327
1328#ifdef DEBUG_SENSOR_TIME
1329 do_gettimeofday(&end);
1330 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1331#endif
1332
1333p_err:
1334 if (hold > 0) {
1335 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
1336 if (hold < 0)
1337 ret = hold;
1338 }
1339 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1340
1341 return ret;
1342}
1343
1344int sensor_2l7_cis_get_analog_gain(struct v4l2_subdev *subdev, u32 *again)
1345{
1346 int ret = 0;
1347 int hold = 0;
1348 struct fimc_is_cis *cis;
1349 struct i2c_client *client;
1350
1351 u16 analog_gain = 0;
1352
1353#ifdef DEBUG_SENSOR_TIME
1354 struct timeval st, end;
1355 do_gettimeofday(&st);
1356#endif
1357
1358 FIMC_BUG(!subdev);
1359 FIMC_BUG(!again);
1360
1361 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1362
1363 FIMC_BUG(!cis);
1364
1365 client = cis->client;
1366 if (unlikely(!client)) {
1367 err("client is NULL");
1368 ret = -EINVAL;
1369 goto p_err;
1370 }
1371
1372 I2C_MUTEX_LOCK(cis->i2c_lock);
1373 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x01);
1374 if (hold < 0) {
1375 ret = hold;
1376 goto p_err;
1377 }
1378
1379 ret = fimc_is_sensor_read16(client, 0x0204, &analog_gain);
1380 if (ret < 0)
1381 goto p_err;
1382
1383 *again = sensor_cis_calc_again_permile(analog_gain);
1384
1385 dbg_sensor(1, "[MOD:D:%d] %s, cur_again = %d us, analog_gain(%#x)\n",
1386 cis->id, __func__, *again, analog_gain);
1387
1388#ifdef DEBUG_SENSOR_TIME
1389 do_gettimeofday(&end);
1390 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1391#endif
1392
1393p_err:
1394 if (hold > 0) {
1395 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
1396 if (hold < 0)
1397 ret = hold;
1398 }
1399 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1400
1401 return ret;
1402}
1403
1404int sensor_2l7_cis_get_min_analog_gain(struct v4l2_subdev *subdev, u32 *min_again)
1405{
1406 int ret = 0;
1407 struct fimc_is_cis *cis;
1408 struct i2c_client *client;
1409 cis_shared_data *cis_data;
1410
1411 u16 read_value = 0;
1412
1413#ifdef DEBUG_SENSOR_TIME
1414 struct timeval st, end;
1415 do_gettimeofday(&st);
1416#endif
1417
1418 FIMC_BUG(!subdev);
1419 FIMC_BUG(!min_again);
1420
1421 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1422
1423 FIMC_BUG(!cis);
1424 FIMC_BUG(!cis->cis_data);
1425
1426 client = cis->client;
1427 if (unlikely(!client)) {
1428 err("client is NULL");
1429 ret = -EINVAL;
1430 goto p_err;
1431 }
1432
1433 cis_data = cis->cis_data;
1434
1435 fimc_is_sensor_read16(client, 0x0084, &read_value);
1436
1437 cis_data->min_analog_gain[0] = read_value;
1438
1439 cis_data->min_analog_gain[1] = sensor_cis_calc_again_permile(read_value);
1440
1441 *min_again = cis_data->min_analog_gain[1];
1442
1443 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__,
1444 cis_data->min_analog_gain[0], cis_data->min_analog_gain[1]);
1445
1446#ifdef DEBUG_SENSOR_TIME
1447 do_gettimeofday(&end);
1448 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1449#endif
1450
1451p_err:
1452 return ret;
1453}
1454
1455int sensor_2l7_cis_get_max_analog_gain(struct v4l2_subdev *subdev, u32 *max_again)
1456{
1457 int ret = 0;
1458 struct fimc_is_cis *cis;
1459 struct i2c_client *client;
1460 cis_shared_data *cis_data;
1461
1462 u16 read_value = 0;
1463
1464#ifdef DEBUG_SENSOR_TIME
1465 struct timeval st, end;
1466 do_gettimeofday(&st);
1467#endif
1468
1469 FIMC_BUG(!subdev);
1470 FIMC_BUG(!max_again);
1471
1472 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1473
1474 FIMC_BUG(!cis);
1475 FIMC_BUG(!cis->cis_data);
1476
1477 client = cis->client;
1478 if (unlikely(!client)) {
1479 err("client is NULL");
1480 ret = -EINVAL;
1481 goto p_err;
1482 }
1483
1484 cis_data = cis->cis_data;
1485
1486 fimc_is_sensor_read16(client, 0x0086, &read_value);
1487
1488 cis_data->max_analog_gain[0] = read_value;
1489
1490 cis_data->max_analog_gain[1] = sensor_cis_calc_again_permile(read_value);
1491
1492 *max_again = cis_data->max_analog_gain[1];
1493
1494 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__,
1495 cis_data->max_analog_gain[0], cis_data->max_analog_gain[1]);
1496
1497#ifdef DEBUG_SENSOR_TIME
1498 do_gettimeofday(&end);
1499 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1500#endif
1501
1502p_err:
1503 return ret;
1504}
1505
1506int sensor_2l7_cis_set_digital_gain(struct v4l2_subdev *subdev, struct ae_param *dgain)
1507{
1508 int ret = 0;
1509 int hold = 0;
1510 struct fimc_is_cis *cis;
1511 struct i2c_client *client;
1512 cis_shared_data *cis_data;
1513
1514 u16 long_gain = 0;
1515 u16 short_gain = 0;
1516 u16 dgains[4] = {0};
1517
1518#ifdef DEBUG_SENSOR_TIME
1519 struct timeval st, end;
1520 do_gettimeofday(&st);
1521#endif
1522
1523 FIMC_BUG(!subdev);
1524 FIMC_BUG(!dgain);
1525
1526 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1527
1528 FIMC_BUG(!cis);
1529 FIMC_BUG(!cis->cis_data);
1530
1531 client = cis->client;
1532 if (unlikely(!client)) {
1533 err("client is NULL");
1534 ret = -EINVAL;
1535 goto p_err;
1536 }
1537
1538 cis_data = cis->cis_data;
1539
1540 long_gain = (u16)sensor_cis_calc_dgain_code(dgain->long_val);
1541 short_gain = (u16)sensor_cis_calc_dgain_code(dgain->short_val);
1542
1543 if (long_gain < cis->cis_data->min_digital_gain[0]) {
1544 long_gain = cis->cis_data->min_digital_gain[0];
1545 }
1546 if (long_gain > cis->cis_data->max_digital_gain[0]) {
1547 long_gain = cis->cis_data->max_digital_gain[0];
1548 }
1549
1550 if (short_gain < cis->cis_data->min_digital_gain[0]) {
1551 short_gain = cis->cis_data->min_digital_gain[0];
1552 }
1553 if (short_gain > cis->cis_data->max_digital_gain[0]) {
1554 short_gain = cis->cis_data->max_digital_gain[0];
1555 }
1556
1557 dbg_sensor(1, "[MOD:D:%d] %s(vsync cnt = %d), input_dgain = %d/%d us, long_gain(%#x), short_gain(%#x)\n",
1558 cis->id, __func__, cis->cis_data->sen_vsync_count, dgain->long_val, dgain->short_val, long_gain, short_gain);
1559
1560 I2C_MUTEX_LOCK(cis->i2c_lock);
1561 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x01);
1562 if (hold < 0) {
1563 ret = hold;
1564 goto p_err;
1565 }
1566
1567 /*
1568 * NOTE : In S5K2L7SX, digital gain is long/short seperated, should set 4 registers like below,
1569 * Write same value to : 0x020E, 0x0216
1570 * Write same value to : 0x3072, 0x307A
1571 */
1572
1573 dgains[0] = dgains[1] = dgains[2] = dgains[3] = short_gain;
1574 /* Short digital gain */
1575 ret = fimc_is_sensor_write16_array(client, 0x020E, dgains, 4);
1576 if (ret < 0)
1577 goto p_err;
1578 ret = fimc_is_sensor_write16_array(client, 0x0216, dgains, 4);
1579 if (ret < 0)
1580 goto p_err;
1581
1582 /* Long digital gain */
1583 if (fimc_is_vender_enable_wdr(cis_data)) {
1584 dgains[0] = dgains[1] = dgains[2] = dgains[3] = long_gain;
1585 ret = fimc_is_sensor_write16_array(client, 0x3072, dgains, 4);
1586 if (ret < 0)
1587 goto p_err;
1588 ret = fimc_is_sensor_write16_array(client, 0x307A, dgains, 4);
1589 if (ret < 0)
1590 goto p_err;
1591 }
1592
1593#ifdef DEBUG_SENSOR_TIME
1594 do_gettimeofday(&end);
1595 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1596#endif
1597
1598p_err:
1599 if (hold > 0) {
1600 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
1601 if (hold < 0)
1602 ret = hold;
1603 }
1604 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1605
1606 return ret;
1607}
1608
1609int sensor_2l7_cis_get_digital_gain(struct v4l2_subdev *subdev, u32 *dgain)
1610{
1611 int ret = 0;
1612 int hold = 0;
1613 struct fimc_is_cis *cis;
1614 struct i2c_client *client;
1615
1616 u16 digital_gain = 0;
1617
1618#ifdef DEBUG_SENSOR_TIME
1619 struct timeval st, end;
1620 do_gettimeofday(&st);
1621#endif
1622
1623 FIMC_BUG(!subdev);
1624 FIMC_BUG(!dgain);
1625
1626 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1627
1628 FIMC_BUG(!cis);
1629
1630 client = cis->client;
1631 if (unlikely(!client)) {
1632 err("client is NULL");
1633 ret = -EINVAL;
1634 goto p_err;
1635 }
1636
1637 I2C_MUTEX_LOCK(cis->i2c_lock);
1638 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x01);
1639 if (hold < 0) {
1640 ret = hold;
1641 goto p_err;
1642 }
1643
1644 ret = fimc_is_sensor_read16(client, 0x020E, &digital_gain);
1645 if (ret < 0)
1646 goto p_err;
1647
1648 *dgain = sensor_cis_calc_dgain_permile(digital_gain);
1649
1650 dbg_sensor(1, "[MOD:D:%d] %s, cur_dgain = %d us, digital_gain(%#x)\n",
1651 cis->id, __func__, *dgain, digital_gain);
1652
1653#ifdef DEBUG_SENSOR_TIME
1654 do_gettimeofday(&end);
1655 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1656#endif
1657
1658p_err:
1659 if (hold > 0) {
1660 hold = sensor_2l7_cis_group_param_hold_func(subdev, 0x00);
1661 if (hold < 0)
1662 ret = hold;
1663 }
1664 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1665
1666 return ret;
1667}
1668
1669int sensor_2l7_cis_get_min_digital_gain(struct v4l2_subdev *subdev, u32 *min_dgain)
1670{
1671 int ret = 0;
1672 struct fimc_is_cis *cis;
1673 struct i2c_client *client;
1674 cis_shared_data *cis_data;
1675
1676 u16 read_value = 0;
1677
1678#ifdef DEBUG_SENSOR_TIME
1679 struct timeval st, end;
1680 do_gettimeofday(&st);
1681#endif
1682
1683 FIMC_BUG(!subdev);
1684 FIMC_BUG(!min_dgain);
1685
1686 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1687
1688 FIMC_BUG(!cis);
1689 FIMC_BUG(!cis->cis_data);
1690
1691 client = cis->client;
1692 if (unlikely(!client)) {
1693 err("client is NULL");
1694 ret = -EINVAL;
1695 goto p_err;
1696 }
1697
1698 cis_data = cis->cis_data;
1699
1700 fimc_is_sensor_read16(client, 0x1084, &read_value);
1701
1702 cis_data->min_digital_gain[0] = read_value;
1703
1704 cis_data->min_digital_gain[1] = sensor_cis_calc_dgain_permile(read_value);
1705
1706 *min_dgain = cis_data->min_digital_gain[1];
1707
1708 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__,
1709 cis_data->min_digital_gain[0], cis_data->min_digital_gain[1]);
1710
1711#ifdef DEBUG_SENSOR_TIME
1712 do_gettimeofday(&end);
1713 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1714#endif
1715
1716p_err:
1717 return ret;
1718}
1719
1720int sensor_2l7_cis_get_max_digital_gain(struct v4l2_subdev *subdev, u32 *max_dgain)
1721{
1722 int ret = 0;
1723 struct fimc_is_cis *cis;
1724 struct i2c_client *client;
1725 cis_shared_data *cis_data;
1726
1727 u16 read_value = 0;
1728
1729#ifdef DEBUG_SENSOR_TIME
1730 struct timeval st, end;
1731 do_gettimeofday(&st);
1732#endif
1733
1734 FIMC_BUG(!subdev);
1735 FIMC_BUG(!max_dgain);
1736
1737 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1738
1739 FIMC_BUG(!cis);
1740 FIMC_BUG(!cis->cis_data);
1741
1742 client = cis->client;
1743 if (unlikely(!client)) {
1744 err("client is NULL");
1745 ret = -EINVAL;
1746 goto p_err;
1747 }
1748
1749 cis_data = cis->cis_data;
1750
1751 fimc_is_sensor_read16(client, 0x1086, &read_value);
1752
1753 cis_data->max_digital_gain[0] = read_value;
1754
1755 cis_data->max_digital_gain[1] = sensor_cis_calc_dgain_permile(read_value);
1756
1757 *max_dgain = cis_data->max_digital_gain[1];
1758
1759 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__,
1760 cis_data->max_digital_gain[0], cis_data->max_digital_gain[1]);
1761
1762#ifdef DEBUG_SENSOR_TIME
1763 do_gettimeofday(&end);
1764 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
1765#endif
1766
1767p_err:
1768 return ret;
1769}
1770
1771static struct fimc_is_cis_ops cis_ops = {
1772 .cis_init = sensor_2l7_cis_init,
1773 .cis_log_status = sensor_2l7_cis_log_status,
1774 .cis_group_param_hold = sensor_2l7_cis_group_param_hold,
1775 .cis_set_global_setting = sensor_2l7_cis_set_global_setting,
1776 .cis_mode_change = sensor_2l7_cis_mode_change,
1777 .cis_set_size = sensor_2l7_cis_set_size,
1778 .cis_stream_on = sensor_2l7_cis_stream_on,
1779 .cis_stream_off = sensor_2l7_cis_stream_off,
1780 .cis_set_exposure_time = sensor_2l7_cis_set_exposure_time,
1781 .cis_get_min_exposure_time = sensor_2l7_cis_get_min_exposure_time,
1782 .cis_get_max_exposure_time = sensor_2l7_cis_get_max_exposure_time,
1783 .cis_adjust_frame_duration = sensor_2l7_cis_adjust_frame_duration,
1784 .cis_set_frame_duration = sensor_2l7_cis_set_frame_duration,
1785 .cis_set_frame_rate = sensor_2l7_cis_set_frame_rate,
1786 .cis_adjust_analog_gain = sensor_2l7_cis_adjust_analog_gain,
1787 .cis_set_analog_gain = sensor_2l7_cis_set_analog_gain,
1788 .cis_get_analog_gain = sensor_2l7_cis_get_analog_gain,
1789 .cis_get_min_analog_gain = sensor_2l7_cis_get_min_analog_gain,
1790 .cis_get_max_analog_gain = sensor_2l7_cis_get_max_analog_gain,
1791 .cis_set_digital_gain = sensor_2l7_cis_set_digital_gain,
1792 .cis_get_digital_gain = sensor_2l7_cis_get_digital_gain,
1793 .cis_get_min_digital_gain = sensor_2l7_cis_get_min_digital_gain,
1794 .cis_get_max_digital_gain = sensor_2l7_cis_get_max_digital_gain,
1795 .cis_compensate_gain_for_extremely_br = sensor_cis_compensate_gain_for_extremely_br,
1796 .cis_wait_streamoff = sensor_cis_wait_streamoff,
1797 .cis_wait_streamon = sensor_cis_wait_streamon,
1798 .cis_data_calculation = sensor_2l7_cis_data_calc,
1799#ifdef CONFIG_SENSOR_RETENTION_USE
1800 .cis_retention_prepare = sensor_2l7_cis_retention_prepare,
1801 .cis_retention_crc_check = sensor_2l7_cis_retention_crc_check,
1802#endif
1803};
1804
1805static int cis_2l7_probe(struct i2c_client *client,
1806 const struct i2c_device_id *id)
1807{
1808 int ret = 0;
1809 struct fimc_is_core *core = NULL;
1810 struct v4l2_subdev *subdev_cis = NULL;
1811 struct fimc_is_cis *cis = NULL;
1812 struct fimc_is_device_sensor *device = NULL;
1813 struct fimc_is_device_sensor_peri *sensor_peri = NULL;
1814 u32 sensor_id = 0;
1815 char const *setfile;
1816 struct device *dev;
1817 struct device_node *dnode;
1818
1819 FIMC_BUG(!client);
1820 FIMC_BUG(!fimc_is_dev);
1821
1822 core = (struct fimc_is_core *)dev_get_drvdata(fimc_is_dev);
1823 if (!core) {
1824 probe_info("core device is not yet probed");
1825 return -EPROBE_DEFER;
1826 }
1827
1828 dev = &client->dev;
1829 dnode = dev->of_node;
1830
1831 ret = of_property_read_u32(dnode, "id", &sensor_id);
1832 if (ret) {
1833 err("sensor id read is fail(%d)", ret);
1834 goto p_err;
1835 }
1836
1837 probe_info("%s sensor id %d\n", __func__, sensor_id);
1838
1839 device = &core->sensor[sensor_id];
1840
1841 sensor_peri = find_peri_by_cis_id(device, SENSOR_NAME_S5K2L7);
1842 if (!sensor_peri) {
1843 probe_info("sensor peri is net yet probed");
1844 return -EPROBE_DEFER;
1845 }
1846
1847 cis = &sensor_peri->cis;
1848 if (!cis) {
1849 err("cis is NULL");
1850 ret = -ENOMEM;
1851 goto p_err;
1852 }
1853
1854 subdev_cis = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
1855 if (!subdev_cis) {
1856 probe_err("subdev_cis is NULL");
1857 ret = -ENOMEM;
1858 goto p_err;
1859 }
1860 sensor_peri->subdev_cis = subdev_cis;
1861
1862 cis->id = SENSOR_NAME_S5K2L7;
1863 cis->subdev = subdev_cis;
1864 cis->device = 0;
1865 cis->client = client;
1866 sensor_peri->module->client = cis->client;
1867 cis->ctrl_delay = N_PLUS_TWO_FRAME;
1868
1869 cis->cis_data = kzalloc(sizeof(cis_shared_data), GFP_KERNEL);
1870 if (!cis->cis_data) {
1871 err("cis_data is NULL");
1872 ret = -ENOMEM;
1873 goto p_err;
1874 }
1875 cis->cis_ops = &cis_ops;
1876
1877 /* belows are depend on sensor cis. MUST check sensor spec */
1878 cis->bayer_order = OTF_INPUT_ORDER_BAYER_GR_BG;
1879
1880 if (of_property_read_bool(dnode, "sensor_f_number")) {
1881 ret = of_property_read_u32(dnode, "sensor_f_number", &cis->aperture_num);
1882 if (ret) {
1883 warn("f-number read is fail(%d)",ret);
1884 }
1885 } else {
1886 cis->aperture_num = F2_2;
1887 }
1888
1889 probe_info("%s f-number %d\n", __func__, cis->aperture_num);
1890
1891 cis->use_dgain = true;
1892 cis->hdr_ctrl_by_again = false;
1893
1894 ret = of_property_read_string(dnode, "setfile", &setfile);
1895 if (ret) {
1896 err("setfile index read fail(%d), take default setfile!!", ret);
1897 setfile = "default";
1898 }
1899
1900 if (strcmp(setfile, "default") == 0 ||
1901 strcmp(setfile, "setA") == 0) {
1902 probe_info("%s setfile_A\n", __func__);
1903 sensor_2l7_global = sensor_2l7_setfile_A_Global;
1904 sensor_2l7_global_size = sizeof(sensor_2l7_setfile_A_Global) / sizeof(sensor_2l7_setfile_A_Global[0]);
1905 sensor_2l7_setfiles = sensor_2l7_setfiles_A;
1906 sensor_2l7_setfile_sizes = sensor_2l7_setfile_A_sizes;
1907 sensor_2l7_pllinfos = sensor_2l7_pllinfos_A;
1908 sensor_2l7_max_setfile_num = sizeof(sensor_2l7_setfiles_A) / sizeof(sensor_2l7_setfiles_A[0]);
1909#ifdef CONFIG_SENSOR_RETENTION_USE
1910 sensor_2l7_retention = sensor_2l7_setfiles_A_retention;
1911 sensor_2l7_retention_size = sensor_2l7_setfile_A_sizes_retention;
1912 sensor_2l7_max_retention_num = sizeof(sensor_2l7_setfiles_A_retention) / sizeof(sensor_2l7_setfiles_A_retention[0]);
1913#endif
1914 } else if (strcmp(setfile, "setB") == 0) {
1915 probe_info("%s setfile_B\n", __func__);
1916 sensor_2l7_global = sensor_2l7_setfile_B_Global;
1917 sensor_2l7_global_size = sizeof(sensor_2l7_setfile_B_Global) / sizeof(sensor_2l7_setfile_B_Global[0]);
1918 sensor_2l7_setfiles = sensor_2l7_setfiles_B;
1919 sensor_2l7_setfile_sizes = sensor_2l7_setfile_B_sizes;
1920 sensor_2l7_pllinfos = sensor_2l7_pllinfos_B;
1921 sensor_2l7_max_setfile_num = sizeof(sensor_2l7_setfiles_B) / sizeof(sensor_2l7_setfiles_B[0]);
1922#ifdef CONFIG_SENSOR_RETENTION_USE
1923 sensor_2l7_retention = sensor_2l7_setfiles_B_retention;
1924 sensor_2l7_retention_size = sensor_2l7_setfile_B_sizes_retention;
1925 sensor_2l7_max_retention_num = sizeof(sensor_2l7_setfiles_B_retention) / sizeof(sensor_2l7_setfiles_B_retention[0]);
1926#endif
1927 } else {
1928 err("%s setfile index out of bound, take default (setfile_A)", __func__);
1929 sensor_2l7_global = sensor_2l7_setfile_A_Global;
1930 sensor_2l7_global_size = sizeof(sensor_2l7_setfile_A_Global) / sizeof(sensor_2l7_setfile_A_Global[0]);
1931 sensor_2l7_setfiles = sensor_2l7_setfiles_A;
1932 sensor_2l7_setfile_sizes = sensor_2l7_setfile_A_sizes;
1933 sensor_2l7_pllinfos = sensor_2l7_pllinfos_A;
1934 sensor_2l7_max_setfile_num = sizeof(sensor_2l7_setfiles_A) / sizeof(sensor_2l7_setfiles_A[0]);
1935#ifdef CONFIG_SENSOR_RETENTION_USE
1936 sensor_2l7_retention = sensor_2l7_setfiles_A_retention;
1937 sensor_2l7_retention_size = sensor_2l7_setfile_A_sizes_retention;
1938 sensor_2l7_max_retention_num = sizeof(sensor_2l7_setfiles_A_retention) / sizeof(sensor_2l7_setfiles_A_retention[0]);
1939#endif
1940 }
1941
1942 v4l2_i2c_subdev_init(subdev_cis, client, &subdev_ops);
1943 v4l2_set_subdevdata(subdev_cis, cis);
1944 v4l2_set_subdev_hostdata(subdev_cis, device);
1945 snprintf(subdev_cis->name, V4L2_SUBDEV_NAME_SIZE, "cis-subdev.%d", cis->id);
1946
1947 probe_info("%s done\n", __func__);
1948
1949p_err:
1950 return ret;
1951}
1952
1953static const struct of_device_id sensor_cis_2l7_match[] = {
1954 {
1955 .compatible = "samsung,exynos5-fimc-is-cis-2l7",
1956 },
1957 {},
1958};
1959MODULE_DEVICE_TABLE(of, sensor_cis_2l7_match);
1960
1961static const struct i2c_device_id sensor_cis_2l7_idt[] = {
1962 { SENSOR_NAME, 0 },
1963 {},
1964};
1965
1966static struct i2c_driver sensor_cis_2l7_driver = {
1967 .probe = cis_2l7_probe,
1968 .driver = {
1969 .name = SENSOR_NAME,
1970 .owner = THIS_MODULE,
1971 .of_match_table = sensor_cis_2l7_match,
1972 .suppress_bind_attrs = true,
1973 },
1974 .id_table = sensor_cis_2l7_idt
1975};
1976
1977static int __init sensor_cis_2l7_init(void)
1978{
1979 int ret;
1980
1981 ret = i2c_add_driver(&sensor_cis_2l7_driver);
1982 if (ret)
1983 err("failed to add %s driver: %d\n",
1984 sensor_cis_2l7_driver.driver.name, ret);
1985
1986 return ret;
1987}
1988late_initcall_sync(sensor_cis_2l7_init);