[COMMON] fimc-is2: Add pdaf feature to 12a10 sensor
[GitHub/MotorolaMobilityLLC/kernel-slsi.git] / drivers / media / platform / exynos / fimc-is2 / sensor / module_framework / cis / fimc-is-cis-12a10.c
1 /*
2 * Samsung Exynos5 SoC series Sensor driver
3 *
4 *
5 * Copyright (c) 2018 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-12a10.h"
40 #include "fimc-is-cis-12a10-setA.h"
41 #include "fimc-is-helper-i2c.h"
42
43 #define SENSOR_NAME "OV12A10"
44 /* #define DEBUG_12A10_PLL */
45
46 static const struct v4l2_subdev_ops subdev_ops;
47
48 static const u32 *sensor_12a10_global;
49 static u32 sensor_12a10_global_size;
50 static const u32 **sensor_12a10_setfiles;
51 static const u32 *sensor_12a10_setfile_sizes;
52 static const struct sensor_pll_info_compact **sensor_12a10_pllinfos;
53 static const struct sensor_crop_info **sensor_12a10_crop_infos;
54 static u32 sensor_12a10_max_setfile_num;
55
56 static void sensor_12a10_cis_data_calculation(const struct sensor_pll_info_compact *pll_info_compact, cis_shared_data *cis_data)
57 {
58 u32 vt_pix_clk_hz = 0;
59 u32 frame_rate = 0, frame_valid_us = 0;
60 u64 max_fps = 0;
61
62 FIMC_BUG_VOID(!pll_info_compact);
63
64 /* 1. get pclk value from pll info */
65 vt_pix_clk_hz = pll_info_compact->pclk;
66
67 dbg_sensor(1, "ext_clock(%d), mipi_datarate(%d), pclk(%d)\n",
68 pll_info_compact->ext_clk, pll_info_compact->mipi_datarate, pll_info_compact->pclk);
69
70 /* 2. the time of processing one frame calculation (us) */
71 cis_data->min_frame_us_time = (pll_info_compact->frame_length_lines * pll_info_compact->line_length_pck
72 / (vt_pix_clk_hz / (1000 * 1000)));
73 cis_data->cur_frame_us_time = cis_data->min_frame_us_time;
74
75 /* 3. FPS calculation */
76 frame_rate = vt_pix_clk_hz / (pll_info_compact->frame_length_lines * pll_info_compact->line_length_pck);
77 dbg_sensor(1, "frame_rate (%d) = vt_pix_clk_hz(%d) / "
78 KERN_CONT "(pll_info_compact->frame_length_lines(%d) * pll_info_compact->line_length_pck(%d))\n",
79 frame_rate, vt_pix_clk_hz, pll_info_compact->frame_length_lines, pll_info_compact->line_length_pck);
80
81 /* calculate max fps */
82 max_fps = ((u64)vt_pix_clk_hz * 10) / (pll_info_compact->frame_length_lines * pll_info_compact->line_length_pck);
83 max_fps = (max_fps % 10 >= 5 ? frame_rate + 1 : frame_rate);
84
85 cis_data->pclk = vt_pix_clk_hz;
86 cis_data->max_fps = (u32)max_fps;
87 cis_data->frame_length_lines = pll_info_compact->frame_length_lines;
88 cis_data->line_length_pck = pll_info_compact->line_length_pck;
89 cis_data->line_readOut_time = sensor_cis_do_div64((u64)cis_data->line_length_pck * (u64)(1000 * 1000 * 1000), cis_data->pclk);
90 cis_data->rolling_shutter_skew = (cis_data->cur_height - 1) * cis_data->line_readOut_time;
91 cis_data->stream_on = false;
92
93 /* Frame valid time calcuration */
94 frame_valid_us = sensor_cis_do_div64((u64)cis_data->cur_height * (u64)cis_data->line_length_pck * (u64)(1000 * 1000), cis_data->pclk);
95 cis_data->frame_valid_us_time = (int)frame_valid_us;
96
97 dbg_sensor(1, "%s\n", __func__);
98 dbg_sensor(1, "Sensor size(%d x %d) setting: SUCCESS!\n",
99 cis_data->cur_width, cis_data->cur_height);
100 dbg_sensor(1, "Frame Valid(us): %d\n", frame_valid_us);
101 dbg_sensor(1, "rolling_shutter_skew: %lld\n", cis_data->rolling_shutter_skew);
102
103 dbg_sensor(1, "Fps: %d, max fps(%d)\n", frame_rate, cis_data->max_fps);
104 dbg_sensor(1, "min_frame_time(%d us)\n", cis_data->min_frame_us_time);
105 dbg_sensor(1, "Pixel rate(Mbps): %d\n", cis_data->pclk / 1000000);
106
107 /* Frame period calculation */
108 cis_data->frame_time = (cis_data->line_readOut_time * cis_data->cur_height / 1000);
109 cis_data->rolling_shutter_skew = (cis_data->cur_height - 1) * cis_data->line_readOut_time;
110
111 dbg_sensor(1, "[%s] frame_time(%d), rolling_shutter_skew(%lld)\n", __func__,
112 cis_data->frame_time, cis_data->rolling_shutter_skew);
113
114 /* Constant values */
115 cis_data->min_fine_integration_time = SENSOR_12A10_FINE_INTEGRATION_TIME_MIN;
116 cis_data->max_fine_integration_time = cis_data->cur_width;
117 cis_data->min_coarse_integration_time = SENSOR_12A10_COARSE_INTEGRATION_TIME_MIN;
118 cis_data->max_margin_coarse_integration_time = SENSOR_12A10_COARSE_INTEGRATION_TIME_MAX_MARGIN;
119 }
120
121 int sensor_12a10_cis_check_rev(struct v4l2_subdev *subdev)
122 {
123 int ret = 0;
124 u8 rev = 0;
125 struct i2c_client *client;
126 struct fimc_is_cis *cis = NULL;
127
128 WARN_ON(!subdev);
129
130 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
131 WARN_ON(!cis);
132 WARN_ON(!cis->cis_data);
133
134 client = cis->client;
135 if (unlikely(!client)) {
136 err("client is NULL");
137 return -EINVAL;
138 }
139
140 memset(cis->cis_data, 0, sizeof(cis_shared_data));
141 cis->rev_flag = false;
142
143 I2C_MUTEX_LOCK(cis->i2c_lock);
144
145 ret = fimc_is_sensor_read8(client, 0x300B, &rev);
146 if (ret < 0) {
147 cis->rev_flag = true;
148 ret = -EAGAIN;
149 } else {
150 cis->cis_data->cis_rev = rev;
151 pr_info("%s : Rev. 0x%X\n", __func__, rev);
152 }
153
154 I2C_MUTEX_UNLOCK(cis->i2c_lock);
155
156 return ret;
157 }
158 /* CIS OPS */
159 int sensor_12a10_cis_init(struct v4l2_subdev *subdev)
160 {
161 int ret = 0;
162 struct fimc_is_cis *cis;
163 u32 setfile_index = 0;
164 cis_setting_info setinfo;
165
166 setinfo.return_value = 0;
167
168 setinfo.param = NULL;
169
170 FIMC_BUG(!subdev);
171
172 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
173 if (!cis) {
174 err("cis is NULL");
175 ret = -EINVAL;
176 goto p_err;
177 }
178
179 FIMC_BUG(!cis->cis_data);
180 memset(cis->cis_data, 0, sizeof(cis_shared_data));
181
182 cis->cis_data->cur_width = SENSOR_12A10_MAX_WIDTH;
183 cis->cis_data->cur_height = SENSOR_12A10_MAX_HEIGHT;
184 cis->cis_data->low_expo_start = 33000;
185 cis->need_mode_change = false;
186
187 sensor_12a10_cis_data_calculation(sensor_12a10_pllinfos[setfile_index], cis->cis_data);
188
189 setinfo.return_value = 0;
190 CALL_CISOPS(cis, cis_get_min_exposure_time, subdev, &setinfo.return_value);
191 dbg_sensor(1, "[%s] min exposure time : %d\n", __func__, setinfo.return_value);
192 setinfo.return_value = 0;
193 CALL_CISOPS(cis, cis_get_max_exposure_time, subdev, &setinfo.return_value);
194 dbg_sensor(1, "[%s] max exposure time : %d\n", __func__, setinfo.return_value);
195 setinfo.return_value = 0;
196 CALL_CISOPS(cis, cis_get_min_analog_gain, subdev, &setinfo.return_value);
197 dbg_sensor(1, "[%s] min again : %d\n", __func__, setinfo.return_value);
198 setinfo.return_value = 0;
199 CALL_CISOPS(cis, cis_get_max_analog_gain, subdev, &setinfo.return_value);
200 dbg_sensor(1, "[%s] max again : %d\n", __func__, setinfo.return_value);
201 setinfo.return_value = 0;
202 CALL_CISOPS(cis, cis_get_min_digital_gain, subdev, &setinfo.return_value);
203 dbg_sensor(1, "[%s] min dgain : %d\n", __func__, setinfo.return_value);
204 setinfo.return_value = 0;
205 CALL_CISOPS(cis, cis_get_max_digital_gain, subdev, &setinfo.return_value);
206 dbg_sensor(1, "[%s] max dgain : %d\n", __func__, setinfo.return_value);
207
208 #ifdef DEBUG_SENSOR_TIME
209 do_gettimeofday(&end);
210 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec)*1000000 + (end.tv_usec - st.tv_usec));
211 #endif
212
213 p_err:
214 return ret;
215 }
216
217 int sensor_12a10_cis_log_status(struct v4l2_subdev *subdev)
218 {
219 int ret = 0;
220 struct fimc_is_cis *cis;
221 struct i2c_client *client = NULL;
222
223 FIMC_BUG(!subdev);
224
225 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
226 if (!cis) {
227 err("cis is NULL");
228 return -ENODEV;
229 }
230
231 client = cis->client;
232 if (unlikely(!client)) {
233 err("client is NULL");
234 return -ENODEV;
235 }
236
237 I2C_MUTEX_LOCK(cis->i2c_lock);
238
239 pr_err("[SEN:DUMP] *******************************\n");
240 sensor_cis_dump_registers(subdev, sensor_12a10_setfiles[0], sensor_12a10_setfile_sizes[0]);
241
242 I2C_MUTEX_UNLOCK(cis->i2c_lock);
243
244 pr_err("[SEN:DUMP] *******************************\n");
245
246 return ret;
247 }
248
249 #if USE_GROUP_PARAM_HOLD
250 static int sensor_12a10_cis_group_param_hold_func(struct v4l2_subdev *subdev, unsigned int hold)
251 {
252 int ret = 0;
253 struct fimc_is_cis *cis = NULL;
254 struct i2c_client *client = NULL;
255
256 FIMC_BUG(!subdev);
257
258 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
259
260 FIMC_BUG(!cis);
261 FIMC_BUG(!cis->cis_data);
262
263 client = cis->client;
264 if (unlikely(!client)) {
265 err("client is NULL");
266 ret = -EINVAL;
267 goto p_err;
268 }
269
270 if (hold == cis->cis_data->group_param_hold) {
271 pr_debug("already group_param_hold (%d)\n", cis->cis_data->group_param_hold);
272 goto p_err;
273 }
274 if (hold)
275 ret = fimc_is_sensor_write8(client, 0x3208, 0x00);
276 else
277 ret = fimc_is_sensor_write8(client, 0x3208, 0x10);
278 ret = fimc_is_sensor_write8(client, 0x320b, 0x00);
279 ret = fimc_is_sensor_write8(client, 0x3208, 0xa0);
280
281 if (ret < 0)
282 goto p_err;
283
284 cis->cis_data->group_param_hold = hold;
285 ret = 1;
286 p_err:
287 return ret;
288 }
289 #else
290 static inline int sensor_12a10_cis_group_param_hold_func(struct v4l2_subdev *subdev, unsigned int hold)
291 { return 0; }
292 #endif
293
294 /* Input
295 * hold : true - hold, flase - no hold
296 * Output
297 * return: 0 - no effect(already hold or no hold)
298 * positive - setted by request
299 * negative - ERROR value
300 */
301 int sensor_12a10_cis_group_param_hold(struct v4l2_subdev *subdev, bool hold)
302 {
303 int ret = 0;
304 struct fimc_is_cis *cis = NULL;
305
306 FIMC_BUG(!subdev);
307
308 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
309
310 FIMC_BUG(!cis);
311 FIMC_BUG(!cis->cis_data);
312
313 I2C_MUTEX_LOCK(cis->i2c_lock);
314
315 ret = sensor_12a10_cis_group_param_hold_func(subdev, hold);
316 if (ret < 0)
317 goto p_err;
318
319 p_err:
320 I2C_MUTEX_UNLOCK(cis->i2c_lock);
321
322 return ret;
323 }
324
325 int sensor_12a10_cis_set_global_setting(struct v4l2_subdev *subdev)
326 {
327 int ret = 0;
328 struct fimc_is_cis *cis = NULL;
329
330 FIMC_BUG(!subdev);
331
332 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
333 FIMC_BUG(!cis);
334
335 I2C_MUTEX_LOCK(cis->i2c_lock);
336
337 ret = sensor_cis_set_registers(subdev, sensor_12a10_global, sensor_12a10_global_size);
338
339 if (ret < 0) {
340 err("sensor_12a10_set_registers fail!!");
341 goto p_err;
342 }
343
344 dbg_sensor(1, "[%s] global setting done\n", __func__);
345
346 p_err:
347 I2C_MUTEX_UNLOCK(cis->i2c_lock);
348
349 return ret;
350 }
351
352 int sensor_12a10_cis_mode_change(struct v4l2_subdev *subdev, u32 mode)
353 {
354 int ret = 0;
355 struct fimc_is_cis *cis = NULL;
356
357 FIMC_BUG(!subdev);
358
359 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
360 FIMC_BUG(!cis);
361 FIMC_BUG(!cis->cis_data);
362
363 if (mode > sensor_12a10_max_setfile_num) {
364 err("invalid mode(%d)!!", mode);
365 return -EINVAL;
366 }
367
368 sensor_12a10_cis_data_calculation(sensor_12a10_pllinfos[mode], cis->cis_data);
369
370 if (cis->cis_data->is_data.paf_mode) {
371 cis->cis_data->cur_pos_x = 0;
372 cis->cis_data->cur_pos_y = 0;
373 info("get cur_pos_x/y value for MS paf mode x: %d, y: %d\n",
374 cis->cis_data->cur_pos_x, cis->cis_data->cur_pos_y);
375 }
376
377 I2C_MUTEX_LOCK(cis->i2c_lock);
378
379 ret = sensor_cis_set_registers(subdev, sensor_12a10_setfiles[mode], sensor_12a10_setfile_sizes[mode]);
380 if (ret < 0) {
381 err("sensor_12a10_set_registers fail!!");
382 goto p_err;
383 }
384
385 cis->cis_data->frame_time = (cis->cis_data->line_readOut_time * cis->cis_data->cur_height / 1000);
386 cis->cis_data->rolling_shutter_skew = (cis->cis_data->cur_height - 1) * cis->cis_data->line_readOut_time;
387 dbg_sensor(1, "[%s] frame_time(%d), rolling_shutter_skew(%lld)\n", __func__,
388 cis->cis_data->frame_time, cis->cis_data->rolling_shutter_skew);
389
390 dbg_sensor(1, "[%s] mode changed(%d)\n", __func__, mode);
391
392 p_err:
393 I2C_MUTEX_UNLOCK(cis->i2c_lock);
394
395 return ret;
396 }
397
398 /* Deprecated */
399 int sensor_12a10_cis_set_size(struct v4l2_subdev *subdev, cis_shared_data *cis_data)
400 {
401 return 0;
402 }
403
404 int sensor_12a10_cis_stream_on(struct v4l2_subdev *subdev)
405 {
406 int ret = 0;
407 struct fimc_is_cis *cis;
408 struct i2c_client *client;
409 cis_shared_data *cis_data;
410
411 #ifdef DEBUG_SENSOR_TIME
412 struct timeval st, end;
413
414 do_gettimeofday(&st);
415 #endif
416
417 FIMC_BUG(!subdev);
418
419 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
420
421 FIMC_BUG(!cis);
422 FIMC_BUG(!cis->cis_data);
423
424 client = cis->client;
425 if (unlikely(!client)) {
426 err("client is NULL");
427 return -EINVAL;
428 }
429
430 cis_data = cis->cis_data;
431
432 dbg_sensor(1, "[MOD:D:%d] %s\n", cis->id, __func__);
433
434 I2C_MUTEX_LOCK(cis->i2c_lock);
435
436 ret = sensor_12a10_cis_group_param_hold_func(subdev, 0x00);
437 if (ret < 0)
438 err("group_param_hold_func failed at stream on");
439
440 /* Sensor stream on */
441 fimc_is_sensor_write8(client, 0x0100, 0x01);
442 cis_data->stream_on = true;
443
444 #ifdef DEBUG_SENSOR_TIME
445 do_gettimeofday(&end);
446 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
447 #endif
448
449 I2C_MUTEX_UNLOCK(cis->i2c_lock);
450
451 return ret;
452 }
453
454 int sensor_12a10_cis_stream_off(struct v4l2_subdev *subdev)
455 {
456 int ret = 0;
457 struct fimc_is_cis *cis;
458 struct i2c_client *client;
459 cis_shared_data *cis_data;
460
461 #ifdef DEBUG_SENSOR_TIME
462 struct timeval st, end;
463
464 do_gettimeofday(&st);
465 #endif
466
467 FIMC_BUG(!subdev);
468
469 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
470
471 FIMC_BUG(!cis);
472 FIMC_BUG(!cis->cis_data);
473
474 client = cis->client;
475 if (unlikely(!client)) {
476 err("client is NULL");
477 return -EINVAL;
478 }
479
480 cis_data = cis->cis_data;
481
482 dbg_sensor(1, "[MOD:D:%d] %s\n", cis->id, __func__);
483
484 I2C_MUTEX_LOCK(cis->i2c_lock);
485
486 ret = sensor_12a10_cis_group_param_hold_func(subdev, 0x00);
487 if (ret < 0)
488 err("group_param_hold_func failed at stream off");
489
490 /* Sensor stream off */
491 fimc_is_sensor_write8(client, 0x0100, 0x00);
492
493 cis_data->stream_on = false;
494
495 #ifdef DEBUG_SENSOR_TIME
496 do_gettimeofday(&end);
497 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
498 #endif
499
500 I2C_MUTEX_UNLOCK(cis->i2c_lock);
501
502 return ret;
503 }
504
505 int sensor_12a10_cis_set_exposure_time(struct v4l2_subdev *subdev, struct ae_param *target_exposure)
506 {
507 int ret = 0;
508 int hold = 0;
509 struct fimc_is_cis *cis;
510 struct i2c_client *client;
511 cis_shared_data *cis_data;
512
513 u32 vt_pic_clk_freq_mhz = 0;
514 u32 long_coarse_int = 0;
515 u32 short_coarse_int = 0;
516 u32 line_length_pck = 0;
517 u32 min_fine_int = 0;
518 u8 short_coarse_val[3] = {0};
519
520 #ifdef DEBUG_SENSOR_TIME
521 struct timeval st, end;
522
523 do_gettimeofday(&st);
524 #endif
525
526 FIMC_BUG(!subdev);
527 FIMC_BUG(!target_exposure);
528
529 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
530
531 FIMC_BUG(!cis);
532 FIMC_BUG(!cis->cis_data);
533
534 client = cis->client;
535 if (unlikely(!client)) {
536 err("client is NULL");
537 return -EINVAL;
538 }
539
540 if ((target_exposure->long_val <= 0) || (target_exposure->short_val <= 0)) {
541 err("[%s] invalid target exposure(%d, %d)\n", __func__,
542 target_exposure->long_val, target_exposure->short_val);
543 return -EINVAL;
544 }
545
546 cis_data = cis->cis_data;
547
548 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), target long(%d), short(%d)\n", cis->id, __func__,
549 cis_data->sen_vsync_count, target_exposure->long_val, target_exposure->short_val);
550
551 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
552 line_length_pck = cis_data->line_length_pck;
553 min_fine_int = cis_data->min_fine_integration_time;
554
555 long_coarse_int = ((target_exposure->long_val * vt_pic_clk_freq_mhz) - min_fine_int) / line_length_pck;
556 short_coarse_int = ((target_exposure->short_val * vt_pic_clk_freq_mhz) - min_fine_int) / line_length_pck;
557
558 if (cis->long_term_mode.sen_strm_off_on_enable) {
559 u32 reg_long_exp;
560 u8 temp;
561
562 /* Long Exposure Time register caculated by below formula
563 * value = ((Long exp coarse int - normal max coarse int (VTS-8)) / 256) * line_length_pck(HTS)
564 */
565 reg_long_exp = ((long_coarse_int - cis_data->max_coarse_integration_time) / 256) * line_length_pck;
566
567 temp = reg_long_exp & 0xff;
568 ret |= fimc_is_sensor_write8(cis->client, 0x3c95, temp);
569 temp = (reg_long_exp >> 8) & 0xff;
570 ret |= fimc_is_sensor_write8(cis->client, 0x3c94, temp);
571 temp = (reg_long_exp >> 16) & 0xff;
572 ret |= fimc_is_sensor_write8(cis->client, 0x3c93, temp);
573 temp = (reg_long_exp >> 24) & 0xff;
574 ret |= fimc_is_sensor_write8(cis->client, 0x3c92, temp);
575
576 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), reg_val for LTE(%d)\n", cis->id, __func__,
577 cis_data->sen_vsync_count, reg_long_exp);
578
579 /* set normal exposure value to normal max when LTE mode */
580 long_coarse_int = cis_data->max_coarse_integration_time;
581 short_coarse_int = cis_data->max_coarse_integration_time;
582 }
583
584 if (long_coarse_int > cis_data->max_coarse_integration_time) {
585 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long coarse(%d) max(%d)\n", cis->id, __func__,
586 cis_data->sen_vsync_count, long_coarse_int, cis_data->max_coarse_integration_time);
587 long_coarse_int = cis_data->max_coarse_integration_time;
588 }
589
590 if (short_coarse_int > cis_data->max_coarse_integration_time) {
591 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), short coarse(%d) max(%d)\n", cis->id, __func__,
592 cis_data->sen_vsync_count, short_coarse_int, cis_data->max_coarse_integration_time);
593 short_coarse_int = cis_data->max_coarse_integration_time;
594 }
595
596 if (long_coarse_int < cis_data->min_coarse_integration_time) {
597 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long coarse(%d) min(%d)\n", cis->id, __func__,
598 cis_data->sen_vsync_count, long_coarse_int, cis_data->min_coarse_integration_time);
599 long_coarse_int = cis_data->min_coarse_integration_time;
600 }
601
602 if (short_coarse_int < cis_data->min_coarse_integration_time) {
603 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), short coarse(%d) min(%d)\n", cis->id, __func__,
604 cis_data->sen_vsync_count, short_coarse_int, cis_data->min_coarse_integration_time);
605 short_coarse_int = cis_data->min_coarse_integration_time;
606 }
607
608 I2C_MUTEX_LOCK(cis->i2c_lock);
609
610 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x01);
611 if (hold < 0) {
612 ret = hold;
613 goto p_err;
614 }
615
616 /* Short exposure */
617 short_coarse_val[0] = (u8)((short_coarse_int & 0xF000) >> 12);
618 short_coarse_val[1] = (u8)((short_coarse_int & 0x0FF0) >> 4);
619 short_coarse_val[2] = (u8)((short_coarse_int & 0x000F) << 4);
620 ret = fimc_is_sensor_write8_array(client, 0x3500, short_coarse_val, 3);
621 if (ret < 0)
622 goto p_err;
623 #if 0
624 /* Long exposure */
625 if (fimc_is_vender_wdr_mode_on(cis_data)) {
626 ret = fimc_is_sensor_write16(client, 0x3c92, long_coarse_int);
627 if (ret < 0)
628 goto p_err;
629 }
630 #endif
631 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), vt_pic_clk_freq_mhz (%d), line_length_pck(%d), min_fine_int (%d)\n",
632 cis->id, __func__, cis_data->sen_vsync_count, vt_pic_clk_freq_mhz, line_length_pck, min_fine_int);
633 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), frame_length_lines(%#x), long_coarse_int %#x, short_coarse_int %#x\n",
634 cis->id, __func__, cis_data->sen_vsync_count, cis_data->frame_length_lines,
635 long_coarse_int, short_coarse_int);
636
637 #ifdef DEBUG_SENSOR_TIME
638 do_gettimeofday(&end);
639 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
640 #endif
641
642 p_err:
643 if (hold > 0) {
644 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x00);
645 if (hold < 0)
646 ret = hold;
647 }
648
649 I2C_MUTEX_UNLOCK(cis->i2c_lock);
650
651 return ret;
652 }
653
654 int sensor_12a10_cis_get_min_exposure_time(struct v4l2_subdev *subdev, u32 *min_expo)
655 {
656 int ret = 0;
657 struct fimc_is_cis *cis = NULL;
658 cis_shared_data *cis_data = NULL;
659 u32 min_integration_time = 0;
660 u32 min_coarse = 0;
661 u32 min_fine = 0;
662 u32 vt_pic_clk_freq_mhz = 0;
663 u32 line_length_pck = 0;
664
665 #ifdef DEBUG_SENSOR_TIME
666 struct timeval st, end;
667
668 do_gettimeofday(&st);
669 #endif
670
671 FIMC_BUG(!subdev);
672 FIMC_BUG(!min_expo);
673
674 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
675
676 FIMC_BUG(!cis);
677 FIMC_BUG(!cis->cis_data);
678
679 cis_data = cis->cis_data;
680
681 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
682 if (vt_pic_clk_freq_mhz == 0) {
683 pr_err("[MOD:D:%d] %s, Invalid vt_pic_clk_freq_mhz(%d)\n", cis->id, __func__, vt_pic_clk_freq_mhz);
684 goto p_err;
685 }
686 line_length_pck = cis_data->line_length_pck;
687 min_coarse = cis_data->min_coarse_integration_time;
688 min_fine = cis_data->min_fine_integration_time;
689
690 min_integration_time = ((line_length_pck * min_coarse) + min_fine) / vt_pic_clk_freq_mhz;
691 *min_expo = min_integration_time;
692
693 dbg_sensor(1, "[%s] min integration time %d\n", __func__, min_integration_time);
694
695 #ifdef DEBUG_SENSOR_TIME
696 do_gettimeofday(&end);
697 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
698 #endif
699
700 p_err:
701 return ret;
702 }
703
704 int sensor_12a10_cis_get_max_exposure_time(struct v4l2_subdev *subdev, u32 *max_expo)
705 {
706 int ret = 0;
707 struct fimc_is_cis *cis;
708 cis_shared_data *cis_data;
709 u32 max_integration_time = 0;
710 u32 max_coarse_margin = 0;
711 u32 max_fine_margin = 0;
712 u32 max_coarse = 0;
713 u32 max_fine = 0;
714 u32 vt_pic_clk_freq_mhz = 0;
715 u32 line_length_pck = 0;
716 u32 frame_length_lines = 0;
717
718 #ifdef DEBUG_SENSOR_TIME
719 struct timeval st, end;
720
721 do_gettimeofday(&st);
722 #endif
723
724 FIMC_BUG(!subdev);
725 FIMC_BUG(!max_expo);
726
727 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
728
729 FIMC_BUG(!cis);
730 FIMC_BUG(!cis->cis_data);
731
732 cis_data = cis->cis_data;
733
734 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
735 if (vt_pic_clk_freq_mhz == 0) {
736 pr_err("[MOD:D:%d] %s, Invalid vt_pic_clk_freq_mhz(%d)\n", cis->id, __func__, vt_pic_clk_freq_mhz);
737 goto p_err;
738 }
739 line_length_pck = cis_data->line_length_pck;
740 frame_length_lines = cis_data->frame_length_lines;
741
742 max_coarse_margin = cis_data->max_margin_coarse_integration_time;
743 max_fine_margin = line_length_pck - cis_data->min_fine_integration_time;
744 max_coarse = frame_length_lines - max_coarse_margin;
745 max_fine = cis_data->max_fine_integration_time;
746
747 max_integration_time = ((line_length_pck * max_coarse) + max_fine) / vt_pic_clk_freq_mhz;
748
749 *max_expo = max_integration_time;
750
751 /* TODO: Is this values update here? */
752 cis_data->max_margin_fine_integration_time = max_fine_margin;
753 cis_data->max_coarse_integration_time = max_coarse;
754
755 dbg_sensor(1, "[%s] max integration time %d, max margin fine integration %d, max coarse integration %d\n",
756 __func__, max_integration_time, cis_data->max_margin_fine_integration_time,
757 cis_data->max_coarse_integration_time);
758
759 #ifdef DEBUG_SENSOR_TIME
760 do_gettimeofday(&end);
761 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
762 #endif
763
764 p_err:
765 return ret;
766 }
767
768 int sensor_12a10_cis_adjust_frame_duration(struct v4l2_subdev *subdev,
769 u32 input_exposure_time,
770 u32 *target_duration)
771 {
772 int ret = 0;
773 struct fimc_is_cis *cis;
774 cis_shared_data *cis_data;
775
776 u32 vt_pic_clk_freq_mhz = 0;
777 u32 line_length_pck = 0;
778 u32 frame_length_lines = 0;
779 u32 frame_duration = 0;
780
781 #ifdef DEBUG_SENSOR_TIME
782 struct timeval st, end;
783
784 do_gettimeofday(&st);
785 #endif
786
787 FIMC_BUG(!subdev);
788 FIMC_BUG(!target_duration);
789
790 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
791
792 FIMC_BUG(!cis);
793 FIMC_BUG(!cis->cis_data);
794
795 cis_data = cis->cis_data;
796
797 if (cis->long_term_mode.sen_strm_off_on_enable) {
798 dbg_sensor(1, "[%s] LTE mode, use exp to input(%d) -> based(%d)\n",
799 __func__, input_exposure_time, cis->long_term_mode.expo[1]);
800 input_exposure_time = cis->long_term_mode.expo[1];
801 }
802
803 vt_pic_clk_freq_mhz = cis_data->pclk / (1000 * 1000);
804 line_length_pck = cis_data->line_length_pck;
805 frame_length_lines = ((vt_pic_clk_freq_mhz * input_exposure_time) / line_length_pck);
806 frame_length_lines += cis_data->max_margin_coarse_integration_time;
807 frame_duration = (frame_length_lines * line_length_pck) / vt_pic_clk_freq_mhz;
808
809 dbg_sensor(1, "[%s](vsync cnt = %d) input exp(%d), adj duration, frame duraion(%d), min_frame_us(%d)\n",
810 __func__, cis_data->sen_vsync_count, input_exposure_time,
811 frame_duration, cis_data->min_frame_us_time);
812 dbg_sensor(1, "[%s](vsync cnt = %d) adj duration, frame duraion(%d), min_frame_us(%d)\n",
813 __func__, cis_data->sen_vsync_count, frame_duration, cis_data->min_frame_us_time);
814
815 *target_duration = MAX(frame_duration, cis_data->min_frame_us_time);
816
817 #ifdef DEBUG_SENSOR_TIME
818 do_gettimeofday(&end);
819 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
820 #endif
821
822 return ret;
823 }
824
825 int sensor_12a10_cis_set_frame_duration(struct v4l2_subdev *subdev, u32 frame_duration)
826 {
827 int ret = 0;
828 int hold = 0;
829 struct fimc_is_cis *cis;
830 struct i2c_client *client;
831 cis_shared_data *cis_data;
832
833 u32 line_length_pck = 0;
834 u16 frame_length_lines = 0;
835 u64 numerator;
836 u32 max_coarse_integration_time = 0;
837
838 #ifdef DEBUG_SENSOR_TIME
839 struct timeval st, end;
840
841 do_gettimeofday(&st);
842 #endif
843
844 FIMC_BUG(!subdev);
845
846 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
847
848 FIMC_BUG(!cis);
849 FIMC_BUG(!cis->cis_data);
850
851 client = cis->client;
852 if (unlikely(!client)) {
853 err("client is NULL");
854 return -EINVAL;
855 }
856
857 cis_data = cis->cis_data;
858
859 if (frame_duration < cis_data->min_frame_us_time) {
860 dbg_sensor(1, "frame duration is less than min(%d)\n", frame_duration);
861 frame_duration = cis_data->min_frame_us_time;
862 }
863
864 line_length_pck = cis_data->line_length_pck;
865 numerator = (u64)cis_data->pclk * frame_duration;
866 frame_length_lines = (u16)((numerator / line_length_pck) / (1000 * 1000));
867
868 dbg_sensor(1, "[MOD:D:%d] %s, vt_pic_clk(%#x) frame_duration = %d us,"
869 KERN_CONT "(line_length_pck%#x), frame_length_lines(%#x)\n",
870 cis->id, __func__, cis_data->pclk, frame_duration, line_length_pck, frame_length_lines);
871
872 I2C_MUTEX_LOCK(cis->i2c_lock);
873
874 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x01);
875 if (hold < 0) {
876 ret = hold;
877 goto p_err;
878 }
879
880 ret = fimc_is_sensor_write16(client, 0x380e, frame_length_lines);
881 if (ret < 0)
882 goto p_err;
883
884 cis_data->cur_frame_us_time = frame_duration;
885 cis_data->frame_length_lines = frame_length_lines;
886
887 max_coarse_integration_time = cis_data->frame_length_lines - cis_data->max_margin_coarse_integration_time;
888 cis_data->max_coarse_integration_time = max_coarse_integration_time;
889
890 #ifdef DEBUG_SENSOR_TIME
891 do_gettimeofday(&end);
892 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
893 #endif
894
895 p_err:
896 if (hold > 0) {
897 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x00);
898 if (hold < 0)
899 ret = hold;
900 }
901
902 I2C_MUTEX_UNLOCK(cis->i2c_lock);
903
904 return ret;
905 }
906
907 int sensor_12a10_cis_set_frame_rate(struct v4l2_subdev *subdev, u32 min_fps)
908 {
909 int ret = 0;
910 struct fimc_is_cis *cis;
911 cis_shared_data *cis_data;
912
913 u32 frame_duration = 0;
914
915 #ifdef DEBUG_SENSOR_TIME
916 struct timeval st, end;
917
918 do_gettimeofday(&st);
919 #endif
920
921 FIMC_BUG(!subdev);
922
923 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
924
925 FIMC_BUG(!cis);
926 FIMC_BUG(!cis->cis_data);
927
928 cis_data = cis->cis_data;
929
930 if (min_fps > cis_data->max_fps) {
931 err("[MOD:D:%d] %s, request FPS is too high(%d), set to max(%d)\n",
932 cis->id, __func__, min_fps, cis_data->max_fps);
933 min_fps = cis_data->max_fps;
934 }
935
936 if (min_fps == 0) {
937 err("[MOD:D:%d] %s, request FPS is 0, set to min FPS(1)\n",
938 cis->id, __func__);
939 min_fps = 1;
940 }
941
942 frame_duration = (1 * 1000 * 1000) / min_fps;
943
944 dbg_sensor(1, "[MOD:D:%d] %s, set FPS(%d), frame duration(%d)\n",
945 cis->id, __func__, min_fps, frame_duration);
946
947 ret = sensor_12a10_cis_set_frame_duration(subdev, frame_duration);
948 if (ret < 0) {
949 err("[MOD:D:%d] %s, set frame duration is fail(%d)\n",
950 cis->id, __func__, ret);
951 goto p_err;
952 }
953
954 cis_data->min_frame_us_time = frame_duration;
955
956 #ifdef DEBUG_SENSOR_TIME
957 do_gettimeofday(&end);
958 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
959 #endif
960
961 p_err:
962
963 return ret;
964 }
965
966 #define REG_1X_BASE_VALUE 1000
967 #define REG_1X_BASE 0x0080
968 #define REG_2X_BASE_VALUE 2000
969 #define REG_2X_BASE 0x0100
970 #define REG_4X_BASE_VALUE 4000
971 #define REG_4X_BASE 0x0200
972 #define REG_8X_BASE_VALUE 8000
973 #define REG_8X_BASE 0x0400
974 #define REG_UPPER_BOUND 15500
975
976 #define REG_1X_MIN_VALUE 0x0080
977 #define REG_1X_MAX_VALUE 0x00F8
978 #define REG_2X_MAX_VALUE 0x01F0
979 #define REG_4X_MAX_VALUE 0x03E0
980 #define REG_8X_MAX_VALUE 0x07F0
981
982 static u32 sensor_12a10_again_to_reg_value(u32 again)
983 {
984 u32 level;
985 u32 reg_value;
986
987 /* 1x ~ 1.9375x: 0x0080 ~ 0x00F8, step = 0.0625x, 0x08 */
988 /* 2x ~ 3.875 x: 0x0100 ~ 0x01F0, step = 0.125x, 0x10 */
989 /* 4x ~ 7.75 x: 0x0200 ~ 0x03E0, step = 0.25x, 0x20 */
990 /* 8x ~ 15.5 x: 0x0400 ~ 0x07F0, step = 0.5x, 0x40 */
991 if (again < REG_2X_BASE_VALUE) {
992 level = ((again - REG_1X_BASE_VALUE) << 4) / 1000; /* step_num */
993 reg_value = REG_1X_BASE + level * 8; /* reg_val = reg_base + step_num * step */
994 } else if (again < REG_4X_BASE_VALUE) {
995 level = ((again - REG_2X_BASE_VALUE) << 3) / 1000;
996 reg_value = REG_2X_BASE + level * 16;
997 } else if (again < REG_8X_BASE_VALUE) {
998 level = ((again - REG_4X_BASE_VALUE) << 2) / 1000;
999 reg_value = REG_4X_BASE + level * 32;
1000 } else if (again < REG_UPPER_BOUND) {
1001 level = ((again - REG_8X_BASE_VALUE) << 1) / 1000;
1002 reg_value = REG_8X_BASE + level * 64;
1003 } else {
1004 reg_value = REG_8X_MAX_VALUE;
1005 }
1006
1007 return reg_value;
1008 }
1009
1010 static u32 sensor_12a10_reg_value_to_again(u32 reg_value)
1011 {
1012 u32 again;
1013
1014 if (reg_value <= REG_1X_MAX_VALUE) {
1015 again = ((((reg_value - REG_1X_BASE) >> 3) * 1000) >> 4) + REG_1X_BASE_VALUE;
1016 } else if (reg_value <= REG_2X_MAX_VALUE) {
1017 again = ((((reg_value - REG_2X_BASE) >> 2) * 1000) >> 4) + REG_2X_BASE_VALUE;
1018 } else if (reg_value <= REG_4X_MAX_VALUE) {
1019 again = ((((reg_value - REG_4X_BASE) >> 1) * 1000) >> 4) + REG_4X_BASE_VALUE;
1020 } else if (reg_value <= REG_8X_MAX_VALUE) {
1021 again = ((((reg_value - REG_8X_BASE) >> 0) * 1000) >> 4) + REG_8X_BASE_VALUE;
1022 } else {
1023 again = REG_1X_BASE_VALUE;
1024 }
1025
1026 return again;
1027 }
1028
1029 int sensor_12a10_cis_adjust_analog_gain(struct v4l2_subdev *subdev, u32 input_again, u32 *target_permile)
1030 {
1031 int ret = 0;
1032 struct fimc_is_cis *cis;
1033 cis_shared_data *cis_data;
1034
1035 u32 again_code = 0;
1036 u32 again_permile = 0;
1037
1038 #ifdef DEBUG_SENSOR_TIME
1039 struct timeval st, end;
1040
1041 do_gettimeofday(&st);
1042 #endif
1043
1044 FIMC_BUG(!subdev);
1045 FIMC_BUG(!target_permile);
1046
1047 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1048
1049 FIMC_BUG(!cis);
1050 FIMC_BUG(!cis->cis_data);
1051
1052 cis_data = cis->cis_data;
1053
1054 again_code = sensor_12a10_again_to_reg_value(input_again);
1055
1056 if (again_code > cis_data->max_analog_gain[0])
1057 again_code = cis_data->max_analog_gain[0];
1058 else if (again_code < cis_data->min_analog_gain[0])
1059 again_code = cis_data->min_analog_gain[0];
1060
1061 again_permile = sensor_12a10_reg_value_to_again(again_code);
1062
1063 dbg_sensor(1, "[%s] min again(%d), max(%d), input_again(%d), code(%d), permile(%d)\n", __func__,
1064 cis_data->max_analog_gain[0],
1065 cis_data->min_analog_gain[0],
1066 input_again,
1067 again_code,
1068 again_permile);
1069
1070 *target_permile = again_permile;
1071
1072 return ret;
1073 }
1074
1075 int sensor_12a10_cis_set_analog_gain(struct v4l2_subdev *subdev, struct ae_param *again)
1076 {
1077 int ret = 0;
1078 int hold = 0;
1079 struct fimc_is_cis *cis;
1080 struct i2c_client *client;
1081
1082 u16 analog_gain = 0;
1083 u8 analog_val[2] = {0};
1084
1085 #ifdef DEBUG_SENSOR_TIME
1086 struct timeval st, end;
1087
1088 do_gettimeofday(&st);
1089 #endif
1090
1091 FIMC_BUG(!subdev);
1092 FIMC_BUG(!again);
1093
1094 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1095
1096 FIMC_BUG(!cis);
1097
1098 client = cis->client;
1099 if (unlikely(!client)) {
1100 err("client is NULL");
1101 return -EINVAL;
1102 }
1103
1104 analog_gain = (u16)sensor_12a10_again_to_reg_value(again->val);
1105
1106 if (analog_gain < cis->cis_data->min_analog_gain[0])
1107 analog_gain = cis->cis_data->min_analog_gain[0];
1108
1109 if (analog_gain > cis->cis_data->max_analog_gain[0])
1110 analog_gain = cis->cis_data->max_analog_gain[0];
1111
1112 dbg_sensor(1, "[MOD:D:%d] %s(vsync cnt = %d), input_again = %d us, analog_gain(%#x)\n",
1113 cis->id, __func__, cis->cis_data->sen_vsync_count, again->val, analog_gain);
1114
1115 I2C_MUTEX_LOCK(cis->i2c_lock);
1116
1117 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x01);
1118 if (hold < 0) {
1119 ret = hold;
1120 goto p_err;
1121 }
1122
1123 analog_val[0] = (analog_gain & 0xFF00) >> 8;
1124 analog_val[1] = (analog_gain & 0x00FF);
1125 ret = fimc_is_sensor_write8_array(client, 0x3508, analog_val, 2);
1126 ret = fimc_is_sensor_write8_array(client, 0x350c, analog_val, 2);
1127 if (ret < 0)
1128 goto p_err;
1129
1130 #ifdef DEBUG_SENSOR_TIME
1131 do_gettimeofday(&end);
1132 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1133 #endif
1134
1135 p_err:
1136 if (hold > 0) {
1137 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x00);
1138 if (hold < 0)
1139 ret = hold;
1140 }
1141
1142 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1143
1144 return ret;
1145 }
1146
1147 int sensor_12a10_cis_get_analog_gain(struct v4l2_subdev *subdev, u32 *again)
1148 {
1149 int ret = 0;
1150 int hold = 0;
1151 struct fimc_is_cis *cis;
1152 struct i2c_client *client;
1153
1154 u16 analog_gain = 0;
1155
1156 #ifdef DEBUG_SENSOR_TIME
1157 struct timeval st, end;
1158
1159 do_gettimeofday(&st);
1160 #endif
1161
1162 FIMC_BUG(!subdev);
1163 FIMC_BUG(!again);
1164
1165 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1166
1167 FIMC_BUG(!cis);
1168
1169 client = cis->client;
1170 if (unlikely(!client)) {
1171 err("client is NULL");
1172 return -EINVAL;
1173 }
1174
1175 I2C_MUTEX_LOCK(cis->i2c_lock);
1176
1177 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x01);
1178 if (hold < 0) {
1179 ret = hold;
1180 goto p_err;
1181 }
1182
1183 ret = fimc_is_sensor_read16(client, 0x3508, &analog_gain);
1184 if (ret < 0)
1185 goto p_err;
1186
1187 *again = sensor_12a10_reg_value_to_again(analog_gain);
1188
1189 dbg_sensor(1, "[MOD:D:%d] %s, cur_again = %d us, analog_gain(%#x)\n",
1190 cis->id, __func__, *again, analog_gain);
1191
1192 #ifdef DEBUG_SENSOR_TIME
1193 do_gettimeofday(&end);
1194 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1195 #endif
1196
1197 p_err:
1198 if (hold > 0) {
1199 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x00);
1200 if (hold < 0)
1201 ret = hold;
1202 }
1203
1204 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1205
1206 return ret;
1207 }
1208
1209 int sensor_12a10_cis_get_min_analog_gain(struct v4l2_subdev *subdev, u32 *min_again)
1210 {
1211 int ret = 0;
1212 struct fimc_is_cis *cis;
1213 struct i2c_client *client;
1214 cis_shared_data *cis_data;
1215
1216 #ifdef DEBUG_SENSOR_TIME
1217 struct timeval st, end;
1218
1219 do_gettimeofday(&st);
1220 #endif
1221
1222 FIMC_BUG(!subdev);
1223 FIMC_BUG(!min_again);
1224
1225 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1226
1227 FIMC_BUG(!cis);
1228 FIMC_BUG(!cis->cis_data);
1229
1230 client = cis->client;
1231 if (unlikely(!client)) {
1232 err("client is NULL");
1233 return -EINVAL;
1234 }
1235
1236 cis_data = cis->cis_data;
1237 cis_data->min_analog_gain[0] = REG_1X_MIN_VALUE;
1238 cis_data->min_analog_gain[1] = 1000;
1239 *min_again = cis_data->min_analog_gain[1];
1240
1241 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__, cis_data->min_analog_gain[0], cis_data->min_analog_gain[1]);
1242
1243 #ifdef DEBUG_SENSOR_TIME
1244 do_gettimeofday(&end);
1245 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1246 #endif
1247
1248 return ret;
1249 }
1250
1251 int sensor_12a10_cis_get_max_analog_gain(struct v4l2_subdev *subdev, u32 *max_again)
1252 {
1253 int ret = 0;
1254 struct fimc_is_cis *cis;
1255 struct i2c_client *client;
1256 cis_shared_data *cis_data;
1257
1258 #ifdef DEBUG_SENSOR_TIME
1259 struct timeval st, end;
1260
1261 do_gettimeofday(&st);
1262 #endif
1263
1264 FIMC_BUG(!subdev);
1265 FIMC_BUG(!max_again);
1266
1267 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1268
1269 FIMC_BUG(!cis);
1270 FIMC_BUG(!cis->cis_data);
1271
1272 client = cis->client;
1273 if (unlikely(!client)) {
1274 err("client is NULL");
1275 return -EINVAL;
1276 }
1277
1278 cis_data = cis->cis_data;
1279 cis_data->max_analog_gain[0] = REG_8X_MAX_VALUE;
1280 cis_data->max_analog_gain[1] = 15500;
1281 *max_again = cis_data->max_analog_gain[1];
1282
1283 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__, cis_data->max_analog_gain[0], cis_data->max_analog_gain[1]);
1284
1285 #ifdef DEBUG_SENSOR_TIME
1286 do_gettimeofday(&end);
1287 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1288 #endif
1289
1290 return ret;
1291 }
1292
1293 #define REG_1X_BASE_DGAIN_VALUE 1000
1294 #define REG_1X_BASE_DGAIN 0x0400
1295
1296 u32 sensor_12a10_dgain_to_reg_value(u32 permile)
1297 {
1298 u32 reg_dgain;
1299 reg_dgain = permile * REG_1X_BASE_DGAIN / REG_1X_BASE_DGAIN_VALUE;
1300
1301 return reg_dgain;
1302 }
1303
1304 int sensor_12a10_cis_set_digital_gain(struct v4l2_subdev *subdev, struct ae_param *dgain)
1305 {
1306 int ret = 0;
1307 struct fimc_is_cis *cis;
1308 struct i2c_client *client;
1309 cis_shared_data *cis_data;
1310
1311 u16 long_gain = 0;
1312 u16 short_gain = 0;
1313 u8 reg_short_gain[2] = {0};
1314
1315 #ifdef DEBUG_SENSOR_TIME
1316 struct timeval st, end;
1317
1318 do_gettimeofday(&st);
1319 #endif
1320
1321 FIMC_BUG(!subdev);
1322 FIMC_BUG(!dgain);
1323
1324 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1325
1326 FIMC_BUG(!cis);
1327 FIMC_BUG(!cis->cis_data);
1328
1329 client = cis->client;
1330 if (unlikely(!client)) {
1331 err("client is NULL");
1332 return -EINVAL;
1333 }
1334
1335 cis_data = cis->cis_data;
1336
1337 long_gain = (u16)sensor_12a10_dgain_to_reg_value(dgain->long_val);
1338 short_gain = (u16)sensor_12a10_dgain_to_reg_value(dgain->short_val);
1339
1340 if (long_gain < cis->cis_data->min_digital_gain[0])
1341 long_gain = cis->cis_data->min_digital_gain[0];
1342
1343 if (long_gain > cis->cis_data->max_digital_gain[0])
1344 long_gain = cis->cis_data->max_digital_gain[0];
1345
1346 if (short_gain < cis->cis_data->min_digital_gain[0])
1347 short_gain = cis->cis_data->min_digital_gain[0];
1348
1349 if (short_gain > cis->cis_data->max_digital_gain[0])
1350 short_gain = cis->cis_data->max_digital_gain[0];
1351
1352 reg_short_gain[0] = (short_gain & 0x3FFF) >> 8;
1353 reg_short_gain[1] = (short_gain & 0xFF);
1354 fimc_is_sensor_write8(client, 0x350A, reg_short_gain[0]);
1355 fimc_is_sensor_write8(client, 0x350B, reg_short_gain[1]);
1356
1357 dbg_sensor(1, "[MOD:D:%d] %s(vsync cnt = %d), input_dgain = %d/%d us, long_gain(%#x), short_gain(%#x)\n",
1358 cis->id, __func__, cis->cis_data->sen_vsync_count, dgain->long_val,
1359 dgain->short_val, long_gain, short_gain);
1360
1361 #ifdef DEBUG_SENSOR_TIME
1362 do_gettimeofday(&end);
1363 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1364 #endif
1365
1366 return ret;
1367 }
1368
1369 int sensor_12a10_cis_get_digital_gain(struct v4l2_subdev *subdev, u32 *dgain)
1370 {
1371 int ret = 0;
1372 int hold = 0;
1373 struct fimc_is_cis *cis;
1374 struct i2c_client *client;
1375
1376 u16 digital_gain = 0;
1377
1378 #ifdef DEBUG_SENSOR_TIME
1379 struct timeval st, end;
1380
1381 do_gettimeofday(&st);
1382 #endif
1383
1384 FIMC_BUG(!subdev);
1385 FIMC_BUG(!dgain);
1386
1387 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1388
1389 FIMC_BUG(!cis);
1390
1391 client = cis->client;
1392 if (unlikely(!client)) {
1393 err("client is NULL");
1394 return -EINVAL;
1395 }
1396
1397 I2C_MUTEX_LOCK(cis->i2c_lock);
1398
1399 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x01);
1400 if (hold < 0) {
1401 ret = hold;
1402 goto p_err;
1403 }
1404
1405 ret = fimc_is_sensor_read16(client, 0x350a, &digital_gain);
1406 if (ret < 0)
1407 goto p_err;
1408
1409 *dgain = sensor_cis_calc_dgain_permile(digital_gain);
1410
1411 dbg_sensor(1, "[MOD:D:%d] %s, cur_dgain = %d us, digital_gain(%#x)\n",
1412 cis->id, __func__, *dgain, digital_gain);
1413
1414 #ifdef DEBUG_SENSOR_TIME
1415 do_gettimeofday(&end);
1416 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1417 #endif
1418
1419 p_err:
1420 if (hold > 0) {
1421 hold = sensor_12a10_cis_group_param_hold_func(subdev, 0x00);
1422 if (hold < 0)
1423 ret = hold;
1424 }
1425
1426 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1427
1428 return ret;
1429 }
1430
1431 int sensor_12a10_cis_get_min_digital_gain(struct v4l2_subdev *subdev, u32 *min_dgain)
1432 {
1433 int ret = 0;
1434 struct fimc_is_cis *cis;
1435 struct i2c_client *client;
1436 cis_shared_data *cis_data;
1437
1438 #ifdef DEBUG_SENSOR_TIME
1439 struct timeval st, end;
1440
1441 do_gettimeofday(&st);
1442 #endif
1443
1444 FIMC_BUG(!subdev);
1445 FIMC_BUG(!min_dgain);
1446
1447 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1448
1449 FIMC_BUG(!cis);
1450 FIMC_BUG(!cis->cis_data);
1451
1452 client = cis->client;
1453 if (unlikely(!client)) {
1454 err("client is NULL");
1455 return -EINVAL;
1456 }
1457
1458 cis_data = cis->cis_data;
1459 cis_data->min_digital_gain[0] = REG_1X_BASE_DGAIN;
1460 cis_data->min_digital_gain[1] = REG_1X_BASE_DGAIN_VALUE;
1461 *min_dgain = cis_data->min_digital_gain[1];
1462
1463 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__,
1464 cis_data->min_digital_gain[0], cis_data->min_digital_gain[1]);
1465
1466 #ifdef DEBUG_SENSOR_TIME
1467 do_gettimeofday(&end);
1468 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1469 #endif
1470
1471 return ret;
1472 }
1473
1474 int sensor_12a10_cis_get_max_digital_gain(struct v4l2_subdev *subdev, u32 *max_dgain)
1475 {
1476 int ret = 0;
1477 struct fimc_is_cis *cis;
1478 struct i2c_client *client;
1479 cis_shared_data *cis_data;
1480
1481 #ifdef DEBUG_SENSOR_TIME
1482 struct timeval st, end;
1483
1484 do_gettimeofday(&st);
1485 #endif
1486
1487 FIMC_BUG(!subdev);
1488 FIMC_BUG(!max_dgain);
1489
1490 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1491
1492 FIMC_BUG(!cis);
1493 FIMC_BUG(!cis->cis_data);
1494
1495 client = cis->client;
1496 if (unlikely(!client)) {
1497 err("client is NULL");
1498 return -EINVAL;
1499 }
1500
1501 cis_data = cis->cis_data;
1502 cis_data->max_digital_gain[0] = 0x3FFF;
1503 cis_data->max_digital_gain[1] = 16000;
1504 *max_dgain = cis_data->max_digital_gain[1];
1505
1506 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__,
1507 cis_data->max_digital_gain[0], cis_data->max_digital_gain[1]);
1508
1509 #ifdef DEBUG_SENSOR_TIME
1510 do_gettimeofday(&end);
1511 dbg_sensor(1, "[%s] time %lu us\n", __func__, (end.tv_sec - st.tv_sec) * 1000000 + (end.tv_usec - st.tv_usec));
1512 #endif
1513
1514 return ret;
1515 }
1516
1517 int sensor_12a10_cis_wait_streamon(struct v4l2_subdev *subdev)
1518 {
1519 int ret = 0;
1520 struct fimc_is_cis *cis;
1521 struct i2c_client *client;
1522 cis_shared_data *cis_data;
1523 u32 wait_cnt = 0, time_out_cnt = 2500;
1524 u8 sensor_fcount = 0;
1525
1526 FIMC_BUG(!subdev);
1527
1528 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1529 if (unlikely(!cis)) {
1530 err("cis is NULL");
1531 ret = -EINVAL;
1532 goto p_err;
1533 }
1534
1535 cis_data = cis->cis_data;
1536 if (unlikely(!cis_data)) {
1537 err("cis_data is NULL");
1538 ret = -EINVAL;
1539 goto p_err;
1540 }
1541
1542 client = cis->client;
1543 if (unlikely(!client)) {
1544 err("client is NULL");
1545 ret = -EINVAL;
1546 goto p_err;
1547 }
1548
1549 ret = fimc_is_sensor_read8(client, 0x483F, &sensor_fcount);
1550 if (ret < 0)
1551 err("i2c transfer fail addr(%x), val(%x), ret = %d\n", 0x483F, sensor_fcount, ret);
1552
1553 /*
1554 * Read sensor frame counter (sensor_fcount address = 0x483F)
1555 * stream on (0x00 ~ 0xFE), stream off (0xFF)
1556 */
1557 while (sensor_fcount == 0x00) {
1558 usleep_range(CIS_STREAM_ON_WAIT_TIME, CIS_STREAM_ON_WAIT_TIME);
1559 wait_cnt++;
1560
1561 ret = fimc_is_sensor_read8(client, 0x483F, &sensor_fcount);
1562 if (ret < 0)
1563 err("i2c transfer fail addr(%x), val(%x), ret = %d\n", 0x483F, sensor_fcount, ret);
1564
1565 if (wait_cnt >= time_out_cnt) {
1566 err("[MOD:D:%d] %s, Don't sensor stream on and time out, wait_limit(%d) > time_out(%d), sensor_fcount(%d)",
1567 cis->id, __func__, wait_cnt, time_out_cnt, sensor_fcount);
1568 ret = -EINVAL;
1569 goto p_err;
1570 }
1571
1572 dbg_sensor(1, "[MOD:D:%d] %s, sensor_fcount(%d), (wait_limit(%d) < time_out(%d))\n",
1573 cis->id, __func__, sensor_fcount, wait_cnt, time_out_cnt);
1574 }
1575
1576 #ifdef CONFIG_SENSOR_RETENTION_USE
1577 /* retention mode CRC wait calculation */
1578 usleep_range(1000, 1000);
1579 #endif
1580
1581 p_err:
1582 return ret;
1583 }
1584
1585 int sensor_12a10_cis_wait_streamoff(struct v4l2_subdev *subdev)
1586 {
1587 int ret = 0;
1588 struct fimc_is_cis *cis;
1589 struct i2c_client *client;
1590 cis_shared_data *cis_data;
1591 u32 wait_cnt = 0, time_out_cnt = 250;
1592 u8 sensor_fcount = 0;
1593
1594 BUG_ON(!subdev);
1595
1596 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1597 cis_data = cis->cis_data;
1598 client = cis->client;
1599
1600 I2C_MUTEX_LOCK(cis->i2c_lock);
1601 ret = fimc_is_sensor_read8(client, 0x483F, &sensor_fcount);
1602 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1603
1604 if (ret < 0)
1605 err("i2c transfer fail addr(%x), val(%x), ret = %d\n", 0x483F, sensor_fcount, ret);
1606
1607 while (sensor_fcount != 0x00) {
1608 I2C_MUTEX_LOCK(cis->i2c_lock);
1609 ret = fimc_is_sensor_read8(client, 0x483F, &sensor_fcount);
1610 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1611 if (ret < 0)
1612 err("i2c transfer fail addr(%x), val(%x), ret = %d\n", 0x483F, sensor_fcount, ret);
1613
1614 usleep_range(CIS_STREAM_OFF_WAIT_TIME, CIS_STREAM_OFF_WAIT_TIME);
1615 wait_cnt++;
1616
1617 if (wait_cnt >= time_out_cnt) {
1618 err("[MOD:D:%d] %s, time out, wait_limit(%d) > time_out(%d), sensor_fcount(%d)",
1619 cis->id, __func__, wait_cnt, time_out_cnt, sensor_fcount);
1620 ret = -EINVAL;
1621 goto p_err;
1622 }
1623
1624 dbg_sensor(1, "[MOD:D:%d] %s, sensor_fcount(%d), (wait_limit(%d) < time_out(%d))\n",
1625 cis->id, __func__, sensor_fcount, wait_cnt, time_out_cnt);
1626 }
1627
1628 p_err:
1629 return ret;
1630 }
1631
1632 static int sensor_12a10_cis_set_dual_slave_setting(struct fimc_is_cis *cis)
1633 {
1634 int ret = 0;
1635 struct i2c_client *client;
1636
1637 cis_shared_data *cis_data;
1638 FIMC_BUG(!cis);
1639
1640 client = cis->client;
1641 if (unlikely(!client)) {
1642 err("client is NULL");
1643 ret = -EINVAL;
1644 goto p_err;
1645 }
1646
1647 dbg_sensor(1, "[MOD:D:%d] %s\n", cis->id, __func__);
1648
1649 cis_data = cis->cis_data;
1650
1651 /* Vsync Input Source Select */
1652 fimc_is_sensor_write8(client, 0x3002, 0x21);
1653 fimc_is_sensor_write8(client, 0x3643, 0x22);
1654 fimc_is_sensor_write8(client, 0x3822, 0xa1);
1655 fimc_is_sensor_write8(client, 0x3823, 0x78);
1656 fimc_is_sensor_write8(client, 0x3824, 0x00);// frame start sync
1657 fimc_is_sensor_write8(client, 0x3825, 0x20);
1658 fimc_is_sensor_write8(client, 0x3826, 0x00);
1659 fimc_is_sensor_write8(client, 0x3827, 0x08);
1660 fimc_is_sensor_write8(client, 0x3c80, 0x08);
1661
1662 p_err:
1663 return ret;
1664 }
1665
1666 int sensor_12a10_cis_set_dual_setting(struct v4l2_subdev *subdev)
1667 {
1668 int ret = 0;
1669 struct fimc_is_cis *cis;
1670 struct i2c_client *client;
1671
1672 FIMC_BUG(!subdev);
1673
1674 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1675
1676 FIMC_BUG(!cis);
1677
1678 client = cis->client;
1679 if (unlikely(!client)) {
1680 err("client is NULL");
1681 ret = -EINVAL;
1682 goto p_err;
1683 }
1684
1685 switch (cis->dual_sync_mode) {
1686 case DUAL_SYNC_MASTER:
1687 break;
1688 case DUAL_SYNC_SLAVE:
1689 ret = sensor_12a10_cis_set_dual_slave_setting(cis);
1690 if (ret)
1691 err("12a10 dual slave setting fail");
1692 break;
1693 default:
1694 err("invalid cis->dual_sync_mode(%d)\n", cis->dual_sync_mode);
1695 ret = -EINVAL;
1696 }
1697
1698 p_err:
1699 return ret;
1700 }
1701
1702 int sensor_12a10_cis_long_term_exposure(struct v4l2_subdev *subdev)
1703 {
1704 int ret = 0;
1705 struct fimc_is_cis *cis;
1706 struct fimc_is_long_term_expo_mode *lte_mode;
1707
1708 WARN_ON(!subdev);
1709
1710 cis = (struct fimc_is_cis *)v4l2_get_subdevdata(subdev);
1711 lte_mode = &cis->long_term_mode;
1712
1713 I2C_MUTEX_LOCK(cis->i2c_lock);
1714 /* LTE mode or normal mode set */
1715 if (lte_mode->sen_strm_off_on_enable) {
1716 ret |= fimc_is_sensor_write8(cis->client, 0x3c80, 0x0c);
1717 ret |= fimc_is_sensor_write8(cis->client, 0x3c90, 0x01);
1718 ret |= fimc_is_sensor_write8(cis->client, 0x3826, 0X0d);
1719 ret |= fimc_is_sensor_write8(cis->client, 0x3827, 0x04);
1720 ret |= fimc_is_sensor_write8(cis->client, 0x401a, 0x40);
1721 ret |= fimc_is_sensor_write8(cis->client, 0x4902, 0x01);
1722 ret |= fimc_is_sensor_write8(cis->client, 0x3640, 0x14);
1723 ret |= fimc_is_sensor_write8(cis->client, 0x3714, 0x20);
1724 ret |= fimc_is_sensor_write8(cis->client, 0x5203, 0x0c);
1725 ret |= fimc_is_sensor_write8(cis->client, 0x5204, 0x11);
1726 ret |= fimc_is_sensor_write8(cis->client, 0x520d, 0xf5);
1727 ret |= fimc_is_sensor_write8(cis->client, 0x520e, 0xf5);
1728 ret |= fimc_is_sensor_write8(cis->client, 0x5208, 0xff);
1729 ret |= fimc_is_sensor_write8(cis->client, 0x5201, 0xa8);
1730 ret |= fimc_is_sensor_write8(cis->client, 0x5200, 0x01);
1731 } else {
1732 ret |= fimc_is_sensor_write8(cis->client, 0x3c80, 0x00);
1733 ret |= fimc_is_sensor_write8(cis->client, 0x3c90, 0x00);
1734 ret |= fimc_is_sensor_write8(cis->client, 0x3827, 0x00);
1735 ret |= fimc_is_sensor_write8(cis->client, 0x3826, 0x00);
1736 ret |= fimc_is_sensor_write8(cis->client, 0x401a, 0x58);
1737 ret |= fimc_is_sensor_write8(cis->client, 0x4902, 0x00);
1738 ret |= fimc_is_sensor_write8(cis->client, 0x3714, 0x24);
1739 ret |= fimc_is_sensor_write8(cis->client, 0x5203, 0x24);
1740 ret |= fimc_is_sensor_write8(cis->client, 0x5204, 0x12);
1741 ret |= fimc_is_sensor_write8(cis->client, 0x520d, 0x0f);
1742 ret |= fimc_is_sensor_write8(cis->client, 0x520e, 0xfd);
1743 ret |= fimc_is_sensor_write8(cis->client, 0x5208, 0x40);
1744 ret |= fimc_is_sensor_write8(cis->client, 0x5201, 0x94);
1745 ret |= fimc_is_sensor_write8(cis->client, 0x5200, 0x03);
1746 }
1747
1748 I2C_MUTEX_UNLOCK(cis->i2c_lock);
1749
1750 info("%s enable(%d)", __func__, lte_mode->sen_strm_off_on_enable);
1751
1752 if (ret < 0) {
1753 pr_err("ERR[%s]: LTE register setting fail\n", __func__);
1754 return ret;
1755 }
1756
1757 return ret;
1758 }
1759
1760 static struct fimc_is_cis_ops cis_ops = {
1761 .cis_init = sensor_12a10_cis_init,
1762 .cis_log_status = sensor_12a10_cis_log_status,
1763 .cis_group_param_hold = sensor_12a10_cis_group_param_hold,
1764 .cis_set_global_setting = sensor_12a10_cis_set_global_setting,
1765 .cis_mode_change = sensor_12a10_cis_mode_change,
1766 .cis_set_size = sensor_12a10_cis_set_size,
1767 .cis_stream_on = sensor_12a10_cis_stream_on,
1768 .cis_stream_off = sensor_12a10_cis_stream_off,
1769 .cis_set_exposure_time = sensor_12a10_cis_set_exposure_time,
1770 .cis_get_min_exposure_time = sensor_12a10_cis_get_min_exposure_time,
1771 .cis_get_max_exposure_time = sensor_12a10_cis_get_max_exposure_time,
1772 .cis_adjust_frame_duration = sensor_12a10_cis_adjust_frame_duration,
1773 .cis_set_frame_duration = sensor_12a10_cis_set_frame_duration,
1774 .cis_set_frame_rate = sensor_12a10_cis_set_frame_rate,
1775 .cis_adjust_analog_gain = sensor_12a10_cis_adjust_analog_gain,
1776 .cis_set_analog_gain = sensor_12a10_cis_set_analog_gain,
1777 .cis_get_analog_gain = sensor_12a10_cis_get_analog_gain,
1778 .cis_get_min_analog_gain = sensor_12a10_cis_get_min_analog_gain,
1779 .cis_get_max_analog_gain = sensor_12a10_cis_get_max_analog_gain,
1780 .cis_set_digital_gain = sensor_12a10_cis_set_digital_gain,
1781 .cis_get_digital_gain = sensor_12a10_cis_get_digital_gain,
1782 .cis_get_min_digital_gain = sensor_12a10_cis_get_min_digital_gain,
1783 .cis_get_max_digital_gain = sensor_12a10_cis_get_max_digital_gain,
1784 .cis_compensate_gain_for_extremely_br = sensor_cis_compensate_gain_for_extremely_br,
1785 .cis_set_initial_exposure = sensor_cis_set_initial_exposure,
1786 .cis_check_rev = sensor_12a10_cis_check_rev,
1787 .cis_factory_test = sensor_cis_factory_test,
1788 .cis_wait_streamoff = sensor_12a10_cis_wait_streamoff,
1789 .cis_wait_streamon = sensor_12a10_cis_wait_streamon,
1790 .cis_set_dual_setting = sensor_12a10_cis_set_dual_setting,
1791 .cis_set_long_term_exposure = sensor_12a10_cis_long_term_exposure,
1792 };
1793
1794 static int cis_12a10_probe(struct i2c_client *client,
1795 const struct i2c_device_id *id)
1796 {
1797 int ret = 0;
1798 struct fimc_is_core *core = NULL;
1799 struct v4l2_subdev *subdev_cis = NULL;
1800 struct fimc_is_cis *cis = NULL;
1801 struct fimc_is_device_sensor *device = NULL;
1802 struct fimc_is_device_sensor_peri *sensor_peri = NULL;
1803 u32 sensor_id = 0;
1804 char const *setfile;
1805 struct device *dev;
1806 struct device_node *dnode;
1807
1808 FIMC_BUG(!client);
1809 FIMC_BUG(!fimc_is_dev);
1810
1811 core = (struct fimc_is_core *)dev_get_drvdata(fimc_is_dev);
1812 if (!core) {
1813 probe_info("core device is not yet probed");
1814 return -EPROBE_DEFER;
1815 }
1816
1817 dev = &client->dev;
1818 dnode = dev->of_node;
1819
1820 ret = of_property_read_u32(dnode, "id", &sensor_id);
1821 if (ret) {
1822 err("sensor id read is fail(%d)", ret);
1823 goto p_err;
1824 }
1825
1826 probe_info("%s sensor id %d\n", __func__, sensor_id);
1827
1828 device = &core->sensor[sensor_id];
1829
1830 sensor_peri = find_peri_by_cis_id(device, SENSOR_NAME_OV12A10);
1831 if (!sensor_peri) {
1832 probe_info("sensor peri is net yet probed");
1833 return -EPROBE_DEFER;
1834 }
1835
1836 cis = &sensor_peri->cis;
1837 if (!cis) {
1838 err("cis is NULL");
1839 ret = -ENOMEM;
1840 goto p_err;
1841 }
1842
1843 subdev_cis = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
1844 if (!subdev_cis) {
1845 probe_err("subdev_cis NULL");
1846 ret = -ENOMEM;
1847 goto p_err;
1848 }
1849 sensor_peri->subdev_cis = subdev_cis;
1850
1851 cis->id = SENSOR_NAME_OV12A10;
1852 cis->subdev = subdev_cis;
1853 cis->device = 0;
1854 cis->client = client;
1855 sensor_peri->module->client = cis->client;
1856 cis->ctrl_delay = N_PLUS_TWO_FRAME;
1857
1858 cis->cis_data = kzalloc(sizeof(cis_shared_data), GFP_KERNEL);
1859 if (!cis->cis_data) {
1860 err("cis_data is NULL");
1861 ret = -ENOMEM;
1862 goto p_err;
1863 }
1864 cis->cis_ops = &cis_ops;
1865
1866 /* belows are depend on sensor cis. MUST check sensor spec */
1867 cis->bayer_order = OTF_INPUT_ORDER_BAYER_BG_GR;
1868
1869 if (of_property_read_bool(dnode, "sensor_f_number")) {
1870 ret = of_property_read_u32(dnode, "sensor_f_number", &cis->aperture_num);
1871 if (ret)
1872 warn("f-number read is fail(%d)", ret);
1873 } else {
1874 cis->aperture_num = F2_2;
1875 }
1876
1877 probe_info("%s f-number %d\n", __func__, cis->aperture_num);
1878
1879 if (of_property_read_bool(dnode, "dual_sync_mode")) {
1880 ret = of_property_read_u32(dnode, "dual_sync_mode", &cis->dual_sync_mode);
1881 if (ret)
1882 warn("dual_sync_mode read is fail(%d)", ret);
1883 } else {
1884 cis->dual_sync_mode = DUAL_SYNC_NONE;
1885 }
1886
1887 probe_info("%s dual_sync_mode %d\n", __func__, cis->dual_sync_mode);
1888
1889 cis->use_dgain = true;
1890 cis->hdr_ctrl_by_again = false;
1891
1892 ret = of_property_read_string(dnode, "setfile", &setfile);
1893 if (ret) {
1894 err("setfile index read fail(%d), take default setfile!!", ret);
1895 setfile = "default";
1896 }
1897
1898 if (strcmp(setfile, "default") == 0 ||
1899 strcmp(setfile, "setA") == 0) {
1900 probe_info("%s setfile_A\n", __func__);
1901 sensor_12a10_global = sensor_12a10_setfile_A_Global;
1902 sensor_12a10_global_size = ARRAY_SIZE(sensor_12a10_setfile_A_Global);
1903 sensor_12a10_setfiles = sensor_12a10_setfiles_A;
1904 sensor_12a10_setfile_sizes = sensor_12a10_setfile_A_sizes;
1905 sensor_12a10_pllinfos = sensor_12a10_pllinfos_A;
1906 sensor_12a10_max_setfile_num = ARRAY_SIZE(sensor_12a10_setfiles_A);
1907 sensor_12a10_crop_infos = sensor_12a10_crop_infos_A;
1908 }
1909
1910 cis->use_initial_ae = of_property_read_bool(dnode, "use_initial_ae");
1911 probe_info("%s use initial_ae(%d)\n", __func__, cis->use_initial_ae);
1912
1913 v4l2_i2c_subdev_init(subdev_cis, client, &subdev_ops);
1914 v4l2_set_subdevdata(subdev_cis, cis);
1915 v4l2_set_subdev_hostdata(subdev_cis, device);
1916 snprintf(subdev_cis->name, V4L2_SUBDEV_NAME_SIZE, "cis-subdev.%d", cis->id);
1917
1918 probe_info("%s done\n", __func__);
1919
1920 p_err:
1921 return ret;
1922 }
1923
1924 static const struct of_device_id sensor_cis_12a10_match[] = {
1925 {
1926 .compatible = "samsung,exynos5-fimc-is-cis-12a10",
1927 },
1928 {},
1929 };
1930 MODULE_DEVICE_TABLE(of, sensor_cis_12a10_match);
1931
1932 static const struct i2c_device_id sensor_cis_12a10_idt[] = {
1933 { SENSOR_NAME, 0 },
1934 {},
1935 };
1936
1937 static struct i2c_driver sensor_cis_12a10_driver = {
1938 .probe = cis_12a10_probe,
1939 .driver = {
1940 .name = SENSOR_NAME,
1941 .owner = THIS_MODULE,
1942 .of_match_table = sensor_cis_12a10_match,
1943 .suppress_bind_attrs = true,
1944 },
1945 .id_table = sensor_cis_12a10_idt
1946 };
1947
1948 static int __init sensor_cis_12a10_init(void)
1949 {
1950 int ret;
1951
1952 ret = i2c_add_driver(&sensor_cis_12a10_driver);
1953 if (ret)
1954 err("failed to add %s driver: %d\n",
1955 sensor_cis_12a10_driver.driver.name, ret);
1956
1957 return ret;
1958 }
1959 late_initcall_sync(sensor_cis_12a10_init);