2 * Samsung Exynos5 SoC series Sensor driver
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd
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.
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>
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-imx333.h"
40 #include "fimc-is-cis-imx333-setA.h"
41 #include "fimc-is-cis-imx333-setB.h"
43 #include "fimc-is-helper-i2c.h"
45 #define SENSOR_NAME "IMX333"
46 /* #define DEBUG_IMX333_PLL */
48 static const u32
*sensor_imx333_global
;
49 static u32 sensor_imx333_global_size
;
50 static const u32
**sensor_imx333_setfiles
;
51 static const u32
*sensor_imx333_setfile_sizes
;
52 static const struct sensor_pll_info_compact
**sensor_imx333_pllinfos
;
53 static u32 sensor_imx333_max_setfile_num
;
55 static void sensor_imx333_set_integration_max_margin(u32 mode
, cis_shared_data
*cis_data
)
60 case SENSOR_IMX333_8064X3024_30FPS
:
61 case SENSOR_IMX333_8064X2268_30FPS
:
62 case SENSOR_IMX333_6048X3024_30FPS
:
63 case SENSOR_IMX333_4032X2268_60FPS
:
64 case SENSOR_IMX333_8064X1960_30FPS
:
65 cis_data
->max_margin_coarse_integration_time
= 0x14;
66 dbg_sensor(1, "max_margin_coarse_integration_time(%d)\n",
67 cis_data
->max_margin_coarse_integration_time
);
69 case SENSOR_IMX333_2016X1134_120FPS
:
70 case SENSOR_IMX333_2016X1134_30FPS
:
71 cis_data
->max_margin_coarse_integration_time
= 0x0E;
73 case SENSOR_IMX333_2016X1134_240FPS
:
74 case SENSOR_IMX333_1008X756_120FPS
:
75 case SENSOR_IMX333_2016X1512_30FPS
:
76 case SENSOR_IMX333_1504X1504_30FPS
:
77 cis_data
->max_margin_coarse_integration_time
= 0x0A;
78 dbg_sensor(1, "max_margin_coarse_integration_time(%d)\n",
79 cis_data
->max_margin_coarse_integration_time
);
82 err("[%s] Unsupport imx333 sensor mode\n", __func__
);
83 cis_data
->max_margin_coarse_integration_time
= SENSOR_IMX333_COARSE_INTEGRATION_TIME_MAX_MARGIN
;
84 dbg_sensor(1, "max_margin_coarse_integration_time(%d)\n",
85 cis_data
->max_margin_coarse_integration_time
);
90 static void sensor_imx333_set_integration_min(u32 mode
, cis_shared_data
*cis_data
)
95 case SENSOR_IMX333_8064X3024_30FPS
:
96 case SENSOR_IMX333_8064X2268_30FPS
:
97 case SENSOR_IMX333_6048X3024_30FPS
:
98 case SENSOR_IMX333_8064X1960_30FPS
:
99 cis_data
->min_coarse_integration_time
= 2;
100 dbg_sensor(1, "min_coarse_integration_time(%d)\n",
101 cis_data
->min_coarse_integration_time
);
103 case SENSOR_IMX333_4032X2268_60FPS
:
104 cis_data
->min_coarse_integration_time
= 4;
106 case SENSOR_IMX333_2016X1134_120FPS
:
107 case SENSOR_IMX333_2016X1134_30FPS
:
108 cis_data
->min_coarse_integration_time
= 2;
110 case SENSOR_IMX333_2016X1134_240FPS
:
111 case SENSOR_IMX333_1008X756_120FPS
:
112 case SENSOR_IMX333_2016X1512_30FPS
:
113 case SENSOR_IMX333_1504X1504_30FPS
:
114 cis_data
->min_coarse_integration_time
= 4;
115 dbg_sensor(1, "min_coarse_integration_time(%d)\n",
116 cis_data
->min_coarse_integration_time
);
119 err("[%s] Unsupport imx333 sensor mode\n", __func__
);
120 cis_data
->min_coarse_integration_time
= 2;
121 dbg_sensor(1, "min_coarse_integration_time(%d)\n",
122 cis_data
->min_coarse_integration_time
);
127 static void sensor_imx333_set_integration_time_step(u32 mode
, cis_shared_data
*cis_data
)
132 case SENSOR_IMX333_8064X3024_30FPS
:
133 case SENSOR_IMX333_8064X2268_30FPS
:
134 case SENSOR_IMX333_6048X3024_30FPS
:
135 case SENSOR_IMX333_8064X1960_30FPS
:
136 cis_data
->cur_coarse_integration_time_step
= SENSOR_IMX333_COARSE_STEP_2N
;
137 dbg_sensor(1, "cur_coarse_integration_time_step(%d)\n",
138 cis_data
->cur_coarse_integration_time_step
);
140 case SENSOR_IMX333_4032X2268_60FPS
:
141 cis_data
->cur_coarse_integration_time_step
= SENSOR_IMX333_COARSE_STEP_4N
;
143 case SENSOR_IMX333_2016X1134_120FPS
:
144 case SENSOR_IMX333_2016X1134_30FPS
:
145 cis_data
->cur_coarse_integration_time_step
= SENSOR_IMX333_COARSE_STEP_2N
;
146 dbg_sensor(1, "cur_coarse_integration_time_step(%d)\n",
147 cis_data
->cur_coarse_integration_time_step
);
149 case SENSOR_IMX333_2016X1134_240FPS
:
150 case SENSOR_IMX333_1008X756_120FPS
:
151 case SENSOR_IMX333_2016X1512_30FPS
:
152 case SENSOR_IMX333_1504X1504_30FPS
:
153 cis_data
->cur_coarse_integration_time_step
= SENSOR_IMX333_COARSE_STEP_4N
;
154 dbg_sensor(1, "cur_coarse_integration_time_step(%d)\n",
155 cis_data
->cur_coarse_integration_time_step
);
158 err("[%s] Unsupport imx333 sensor mode\n", __func__
);
159 cis_data
->cur_coarse_integration_time_step
= SENSOR_IMX333_COARSE_STEP_2N
;
160 dbg_sensor(1, "cur_coarse_integration_time_step(%d)\n",
161 cis_data
->cur_coarse_integration_time_step
);
166 static void sensor_imx333_cis_data_calculation(const struct sensor_pll_info_compact
*pll_info
, cis_shared_data
*cis_data
)
168 u32 vt_pix_clk_hz
= 0;
169 u32 frame_rate
= 0, max_fps
= 0, frame_valid_us
= 0;
173 /* 1. get pclk value from pll info */
174 vt_pix_clk_hz
= pll_info
->pclk
;
176 /* 2. the time of processing one frame calculation (us) */
177 cis_data
->min_frame_us_time
= (pll_info
->frame_length_lines
* pll_info
->line_length_pck
178 / (vt_pix_clk_hz
/ (1000 * 1000)));
179 cis_data
->cur_frame_us_time
= cis_data
->min_frame_us_time
;
181 /* 3. FPS calculation */
182 frame_rate
= vt_pix_clk_hz
/ (pll_info
->frame_length_lines
* pll_info
->line_length_pck
);
183 dbg_sensor(1, "frame_rate (%d) = vt_pix_clk_hz(%d) / "
184 KERN_CONT
"(pll_info->frame_length_lines(%d) * pll_info->line_length_pck(%d))\n",
185 frame_rate
, vt_pix_clk_hz
, pll_info
->frame_length_lines
, pll_info
->line_length_pck
);
187 /* calculate max fps */
188 max_fps
= (vt_pix_clk_hz
* 10) / (pll_info
->frame_length_lines
* pll_info
->line_length_pck
);
189 max_fps
= (max_fps
% 10 >= 5 ? frame_rate
+ 1 : frame_rate
);
191 cis_data
->pclk
= vt_pix_clk_hz
;
192 cis_data
->max_fps
= max_fps
;
193 cis_data
->frame_length_lines
= pll_info
->frame_length_lines
;
194 cis_data
->line_length_pck
= pll_info
->line_length_pck
;
195 cis_data
->line_readOut_time
= sensor_cis_do_div64((u64
)cis_data
->line_length_pck
* (u64
)(1000 * 1000 * 1000), cis_data
->pclk
);
196 cis_data
->rolling_shutter_skew
= (cis_data
->cur_height
- 1) * cis_data
->line_readOut_time
;
197 cis_data
->stream_on
= false;
199 /* Frame valid time calcuration */
200 frame_valid_us
= sensor_cis_do_div64((u64
)cis_data
->cur_height
* (u64
)cis_data
->line_length_pck
* (u64
)(1000 * 1000), cis_data
->pclk
);
201 cis_data
->frame_valid_us_time
= (int)frame_valid_us
;
203 dbg_sensor(1, "%s\n", __func__
);
204 dbg_sensor(1, "Sensor size(%d x %d) setting: SUCCESS!\n",
205 cis_data
->cur_width
, cis_data
->cur_height
);
206 dbg_sensor(1, "Frame Valid(us): %d\n", frame_valid_us
);
207 dbg_sensor(1, "rolling_shutter_skew: %lld\n", cis_data
->rolling_shutter_skew
);
209 dbg_sensor(1, "Fps: %d, max fps(%d)\n", frame_rate
, cis_data
->max_fps
);
210 dbg_sensor(1, "min_frame_time(%d us)\n", cis_data
->min_frame_us_time
);
211 dbg_sensor(1, "Pixel rate(Mbps): %d\n", cis_data
->pclk
/ 1000000);
213 /* Frame period calculation */
214 cis_data
->frame_time
= (cis_data
->line_readOut_time
* cis_data
->cur_height
/ 1000);
215 cis_data
->rolling_shutter_skew
= (cis_data
->cur_height
- 1) * cis_data
->line_readOut_time
;
217 dbg_sensor(1, "[%s] frame_time(%d), rolling_shutter_skew(%lld)\n", __func__
,
218 cis_data
->frame_time
, cis_data
->rolling_shutter_skew
);
220 /* Constant values */
221 cis_data
->min_fine_integration_time
= SENSOR_IMX333_FINE_INTEGRATION_TIME_MIN
;
222 cis_data
->max_fine_integration_time
= SENSOR_IMX333_FINE_INTEGRATION_TIME_MAX
;
223 info("%s: done", __func__
);
226 void sensor_imx333_cis_data_calc(struct v4l2_subdev
*subdev
, u32 mode
)
229 struct fimc_is_cis
*cis
= NULL
;
233 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
235 FIMC_BUG(!cis
->cis_data
);
237 if (mode
> sensor_imx333_max_setfile_num
) {
238 err("invalid mode(%d)!!", mode
);
242 /* If check_rev fail when cis_init, one more check_rev in mode_change */
243 if (cis
->rev_flag
== true) {
244 cis
->rev_flag
= false;
245 ret
= sensor_cis_check_rev(cis
);
247 err("sensor_imx333_check_rev is fail: ret(%d)", ret
);
252 sensor_imx333_cis_data_calculation(sensor_imx333_pllinfos
[mode
], cis
->cis_data
);
255 static int sensor_imx333_wait_stream_off_status(cis_shared_data
*cis_data
)
262 #define STREAM_OFF_WAIT_TIME 250
263 while (timeout
< STREAM_OFF_WAIT_TIME
) {
264 if (cis_data
->is_active_area
== false &&
265 cis_data
->stream_on
== false) {
266 pr_debug("actual stream off\n");
272 if (timeout
== STREAM_OFF_WAIT_TIME
) {
273 pr_err("actual stream off wait timeout\n");
280 int sensor_imx333_cis_check_rev(struct fimc_is_cis
*cis
)
283 u8 rev
= 0, status
=0;
284 struct i2c_client
*client
;
287 FIMC_BUG(!cis
->cis_data
);
289 client
= cis
->client
;
290 if (unlikely(!client
)) {
291 err("client is NULL");
295 I2C_MUTEX_LOCK(cis
->i2c_lock
);
296 /* Specify OPT Page Address for READ */
297 fimc_is_sensor_write8(client
, 0x0A02, 0x7F);
299 /* Turn ON OTP Read MODE */
300 fimc_is_sensor_write8(client
, 0x0A00, 0x01);
302 fimc_is_sensor_read8(client
, 0x0A01, &status
);
303 if ((status
& 0x1) == false)
304 err("status fail, (%d)", status
);
306 ret
= fimc_is_sensor_read8(client
, 0x0A21, &rev
);
308 err("fimc_is_sensor_read8 fail (ret %d)", ret
);
309 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
312 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
314 cis
->cis_data
->cis_rev
= rev
;
315 probe_info("imx333 rev:%x", rev
);
321 int sensor_imx333_cis_init(struct v4l2_subdev
*subdev
)
324 struct fimc_is_cis
*cis
;
325 u32 setfile_index
= 0;
326 cis_setting_info setinfo
;
327 setinfo
.param
= NULL
;
328 setinfo
.return_value
= 0;
332 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
339 FIMC_BUG(!cis
->cis_data
);
340 memset(cis
->cis_data
, 0, sizeof(cis_shared_data
));
341 cis
->rev_flag
= false;
343 ret
= sensor_imx333_cis_check_rev(cis
);
345 warn("sensor_imx333_check_rev is fail when cis init, ret(%d)", ret
);
346 cis
->rev_flag
= true;
350 if (cis
->cis_data
->cis_rev
< 0x12) {
351 probe_info("%s setfile_A\n", __func__
);
352 sensor_imx333_global
= sensor_imx333_setfile_A_Global
;
353 sensor_imx333_global_size
= sizeof(sensor_imx333_setfile_A_Global
) / sizeof(sensor_imx333_setfile_A_Global
[0]);
354 sensor_imx333_setfiles
= sensor_imx333_setfiles_A
;
355 sensor_imx333_setfile_sizes
= sensor_imx333_setfile_A_sizes
;
356 sensor_imx333_pllinfos
= sensor_imx333_pllinfos_A
;
357 sensor_imx333_max_setfile_num
= sizeof(sensor_imx333_setfiles_A
) / sizeof(sensor_imx333_setfiles_A
[0]);
359 probe_info("%s setfile_B (retention)\n", __func__
);
360 sensor_imx333_global
= sensor_imx333_setfile_B_Global
;
361 sensor_imx333_global_size
= sizeof(sensor_imx333_setfile_B_Global
) / sizeof(sensor_imx333_setfile_B_Global
[0]);
362 sensor_imx333_setfiles
= sensor_imx333_setfiles_B
;
363 sensor_imx333_setfile_sizes
= sensor_imx333_setfile_B_sizes
;
364 sensor_imx333_pllinfos
= sensor_imx333_pllinfos_B
;
365 sensor_imx333_max_setfile_num
= sizeof(sensor_imx333_setfiles_B
) / sizeof(sensor_imx333_setfiles_B
[0]);
368 cis
->cis_data
->product_name
= cis
->id
;
369 cis
->cis_data
->cur_width
= SENSOR_IMX333_MAX_WIDTH
;
370 cis
->cis_data
->cur_height
= SENSOR_IMX333_MAX_HEIGHT
;
371 cis
->cis_data
->low_expo_start
= 33000;
372 cis
->need_mode_change
= false;
373 cis
->long_term_mode
.sen_strm_off_on_step
= 0;
374 cis
->long_term_mode
.sen_strm_off_on_enable
= false;
376 sensor_imx333_cis_data_calculation(sensor_imx333_pllinfos
[setfile_index
], cis
->cis_data
);
377 sensor_imx333_set_integration_max_margin(setfile_index
, cis
->cis_data
);
378 sensor_imx333_set_integration_min(setfile_index
, cis
->cis_data
);
379 sensor_imx333_set_integration_time_step(setfile_index
, cis
->cis_data
);
381 setinfo
.return_value
= 0;
382 CALL_CISOPS(cis
, cis_get_min_exposure_time
, subdev
, &setinfo
.return_value
);
383 dbg_sensor(1, "[%s] min exposure time : %d\n", __func__
, setinfo
.return_value
);
384 setinfo
.return_value
= 0;
385 CALL_CISOPS(cis
, cis_get_max_exposure_time
, subdev
, &setinfo
.return_value
);
386 dbg_sensor(1, "[%s] max exposure time : %d\n", __func__
, setinfo
.return_value
);
387 setinfo
.return_value
= 0;
388 CALL_CISOPS(cis
, cis_get_min_analog_gain
, subdev
, &setinfo
.return_value
);
389 dbg_sensor(1, "[%s] min again : %d\n", __func__
, setinfo
.return_value
);
390 setinfo
.return_value
= 0;
391 CALL_CISOPS(cis
, cis_get_max_analog_gain
, subdev
, &setinfo
.return_value
);
392 dbg_sensor(1, "[%s] max again : %d\n", __func__
, setinfo
.return_value
);
393 setinfo
.return_value
= 0;
394 CALL_CISOPS(cis
, cis_get_min_digital_gain
, subdev
, &setinfo
.return_value
);
395 dbg_sensor(1, "[%s] min dgain : %d\n", __func__
, setinfo
.return_value
);
396 setinfo
.return_value
= 0;
397 CALL_CISOPS(cis
, cis_get_max_digital_gain
, subdev
, &setinfo
.return_value
);
398 dbg_sensor(1, "[%s] max dgain : %d\n", __func__
, setinfo
.return_value
);
400 #ifdef DEBUG_SENSOR_TIME
401 do_gettimeofday(&end
);
402 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
409 int sensor_imx333_cis_log_status(struct v4l2_subdev
*subdev
)
412 struct fimc_is_cis
*cis
;
413 struct i2c_client
*client
= NULL
;
419 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
426 client
= cis
->client
;
427 if (unlikely(!client
)) {
428 err("client is NULL");
433 I2C_MUTEX_LOCK(cis
->i2c_lock
);
434 pr_err("[SEN:DUMP] *******************************\n");
435 fimc_is_sensor_read16(client
, 0x0000, &data16
);
436 pr_err("[SEN:DUMP] model_id(%x)\n", data16
);
437 fimc_is_sensor_read8(client
, 0x0002, &data8
);
438 pr_err("[SEN:DUMP] revision_number(%x)\n", data8
);
439 fimc_is_sensor_read8(client
, 0x0005, &data8
);
440 pr_err("[SEN:DUMP] frame_count(%x)\n", data8
);
441 fimc_is_sensor_read8(client
, 0x0100, &data8
);
442 pr_err("[SEN:DUMP] mode_select(%x)\n", data8
);
443 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
445 pr_err("[SEN:DUMP] *******************************\n");
451 #if USE_GROUP_PARAM_HOLD
452 static int sensor_imx333_cis_group_param_hold_func(struct v4l2_subdev
*subdev
, unsigned int hold
)
455 struct fimc_is_cis
*cis
= NULL
;
456 struct i2c_client
*client
= NULL
;
460 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
463 FIMC_BUG(!cis
->cis_data
);
465 client
= cis
->client
;
466 if (unlikely(!client
)) {
467 err("client is NULL");
472 if (hold
== cis
->cis_data
->group_param_hold
) {
473 pr_debug("already group_param_hold (%d)\n", cis
->cis_data
->group_param_hold
);
477 ret
= fimc_is_sensor_write8(client
, 0x0104, hold
);
481 cis
->cis_data
->group_param_hold
= hold
;
487 static inline int sensor_imx333_cis_group_param_hold_func(struct v4l2_subdev
*subdev
, unsigned int hold
)
492 * hold : true - hold, flase - no hold
494 * return: 0 - no effect(already hold or no hold)
495 * positive - setted by request
496 * negative - ERROR value
498 int sensor_imx333_cis_group_param_hold(struct v4l2_subdev
*subdev
, bool hold
)
501 struct fimc_is_cis
*cis
= NULL
;
505 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
508 FIMC_BUG(!cis
->cis_data
);
510 I2C_MUTEX_LOCK(cis
->i2c_lock
);
511 ret
= sensor_imx333_cis_group_param_hold_func(subdev
, hold
);
516 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
520 int sensor_imx333_cis_set_global_setting(struct v4l2_subdev
*subdev
)
523 struct fimc_is_cis
*cis
= NULL
;
524 struct fimc_is_module_enum
*module
;
525 struct fimc_is_device_sensor_peri
*sensor_peri
= NULL
;
526 struct sensor_open_extended
*ext_info
;
530 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
533 sensor_peri
= container_of(cis
, struct fimc_is_device_sensor_peri
, cis
);
534 module
= sensor_peri
->module
;
535 ext_info
= &module
->ext
;
537 I2C_MUTEX_LOCK(cis
->i2c_lock
);
538 /* setfile global setting is at camera entrance */
539 ret
= sensor_cis_set_registers(subdev
, sensor_imx333_global
, sensor_imx333_global_size
);
541 err("sensor_imx333_set_registers fail!!");
545 dbg_sensor(1, "[%s] global setting done\n", __func__
);
548 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
552 int sensor_imx333_cis_mode_change(struct v4l2_subdev
*subdev
, u32 mode
)
555 struct fimc_is_cis
*cis
= NULL
;
556 struct fimc_is_device_sensor_peri
*sensor_peri
= NULL
;
557 struct fimc_is_module_enum
*module
;
558 struct sensor_open_extended
*ext_info
;
562 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
564 FIMC_BUG(!cis
->cis_data
);
566 if (mode
> sensor_imx333_max_setfile_num
) {
567 err("invalid mode(%d)!!", mode
);
572 /* If check_rev fail when cis_init, one more check_rev in mode_change */
573 if (cis
->rev_flag
== true) {
574 cis
->rev_flag
= false;
575 ret
= sensor_cis_check_rev(cis
);
577 err("sensor_imx333_check_rev is fail");
582 #if 0 /* cis_data_calculation is called in module_s_format */
583 sensor_imx333_cis_data_calculation(sensor_imx333_pllinfos
[mode
], cis
->cis_data
);
585 sensor_imx333_set_integration_max_margin(mode
, cis
->cis_data
);
587 sensor_peri
= container_of(cis
, struct fimc_is_device_sensor_peri
, cis
);
588 module
= sensor_peri
->module
;
589 ext_info
= &module
->ext
;
591 I2C_MUTEX_LOCK(cis
->i2c_lock
);
593 ret
= sensor_cis_set_registers(subdev
, sensor_imx333_setfiles
[mode
], sensor_imx333_setfile_sizes
[mode
]);
595 err("sensor_imx333_set_registers fail!!");
599 dbg_sensor(1, "[%s] mode changed(%d)\n", __func__
, mode
);
602 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
606 /* TODO: Sensor set size sequence(sensor done, sensor stop, 3AA done in FW case */
607 int sensor_imx333_cis_set_size(struct v4l2_subdev
*subdev
, cis_shared_data
*cis_data
)
610 bool binning
= false;
611 u32 ratio_w
= 0, ratio_h
= 0, start_x
= 0, start_y
= 0, end_x
= 0, end_y
= 0;
612 u32 even_x
= 0, odd_x
= 0, even_y
= 0, odd_y
= 0;
613 struct i2c_client
*client
= NULL
;
614 struct fimc_is_cis
*cis
= NULL
;
615 #ifdef DEBUG_SENSOR_TIME
616 struct timeval st
, end
;
617 do_gettimeofday(&st
);
621 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
624 dbg_sensor(1, "[MOD:D:%d] %s\n", cis
->id
, __func__
);
626 if (unlikely(!cis_data
)) {
627 err("cis data is NULL");
628 if (unlikely(!cis
->cis_data
)) {
632 cis_data
= cis
->cis_data
;
636 client
= cis
->client
;
637 if (unlikely(!client
)) {
638 err("client is NULL");
643 /* Wait actual stream off */
644 ret
= sensor_imx333_wait_stream_off_status(cis_data
);
646 err("Must stream off\n");
651 binning
= cis_data
->binning
;
653 ratio_w
= (SENSOR_IMX333_MAX_WIDTH
/ cis_data
->cur_width
);
654 ratio_h
= (SENSOR_IMX333_MAX_HEIGHT
/ cis_data
->cur_height
);
660 if (((cis_data
->cur_width
* ratio_w
) > SENSOR_IMX333_MAX_WIDTH
) ||
661 ((cis_data
->cur_height
* ratio_h
) > SENSOR_IMX333_MAX_HEIGHT
)) {
662 err("Config max sensor size over~!!\n");
667 I2C_MUTEX_LOCK(cis
->i2c_lock
);
669 ret
= fimc_is_sensor_write16(client
, 0x6028, 0x2000);
673 /* 2. pixel address region setting */
674 start_x
= ((SENSOR_IMX333_MAX_WIDTH
- cis_data
->cur_width
* ratio_w
) / 2) & (~0x1);
675 start_y
= ((SENSOR_IMX333_MAX_HEIGHT
- cis_data
->cur_height
* ratio_h
) / 2) & (~0x1);
676 end_x
= start_x
+ (cis_data
->cur_width
* ratio_w
- 1);
677 end_y
= start_y
+ (cis_data
->cur_height
* ratio_h
- 1);
679 if (!(end_x
& (0x1)) || !(end_y
& (0x1))) {
680 err("Sensor pixel end address must odd\n");
685 ret
= fimc_is_sensor_write16(client
, 0x0344, start_x
);
688 ret
= fimc_is_sensor_write16(client
, 0x0346, start_y
);
691 ret
= fimc_is_sensor_write16(client
, 0x0348, end_x
);
694 ret
= fimc_is_sensor_write16(client
, 0x034A, end_y
);
698 /* 3. output address setting */
699 ret
= fimc_is_sensor_write16(client
, 0x034C, cis_data
->cur_width
);
702 ret
= fimc_is_sensor_write16(client
, 0x034E, cis_data
->cur_height
);
706 /* If not use to binning, sensor image should set only crop */
708 dbg_sensor(1, "Sensor size set is not binning\n");
712 /* 4. sub sampling setting */
713 even_x
= 1; /* 1: not use to even sampling */
715 odd_x
= (ratio_w
* 2) - even_x
;
716 odd_y
= (ratio_h
* 2) - even_y
;
718 ret
= fimc_is_sensor_write16(client
, 0x0380, even_x
);
721 ret
= fimc_is_sensor_write16(client
, 0x0382, odd_x
);
724 ret
= fimc_is_sensor_write16(client
, 0x0384, even_y
);
727 ret
= fimc_is_sensor_write16(client
, 0x0386, odd_y
);
731 /* 5. binnig setting */
732 ret
= fimc_is_sensor_write8(client
, 0x0900, binning
); /* 1: binning enable, 0: disable */
735 ret
= fimc_is_sensor_write8(client
, 0x0901, (ratio_w
<< 4) | ratio_h
);
739 /* 6. scaling setting: but not use */
740 /* scaling_mode (0: No scaling, 1: Horizontal, 2: Full) */
741 ret
= fimc_is_sensor_write16(client
, 0x0400, 0x0000);
744 /* down_scale_m: 1 to 16 upwards (scale_n: 16(fixed))
745 down scale factor = down_scale_m / down_scale_n */
746 ret
= fimc_is_sensor_write16(client
, 0x0404, 0x0010);
750 cis_data
->frame_time
= (cis_data
->line_readOut_time
* cis_data
->cur_height
/ 1000);
751 cis
->cis_data
->rolling_shutter_skew
= (cis
->cis_data
->cur_height
- 1) * cis
->cis_data
->line_readOut_time
;
752 dbg_sensor(1, "[%s] frame_time(%d), rolling_shutter_skew(%lld)\n", __func__
, cis
->cis_data
->frame_time
,
753 cis
->cis_data
->rolling_shutter_skew
);
755 #ifdef DEBUG_SENSOR_TIME
756 do_gettimeofday(&end
);
757 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
) * 1000000 + (end
.tv_usec
- st
.tv_usec
));
761 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
765 int sensor_imx333_cis_stream_on(struct v4l2_subdev
*subdev
)
768 struct fimc_is_cis
*cis
;
769 struct i2c_client
*client
;
770 cis_shared_data
*cis_data
;
771 struct fimc_is_device_sensor_peri
*sensor_peri
= NULL
;
773 #ifdef DEBUG_SENSOR_TIME
774 struct timeval st
, end
;
775 do_gettimeofday(&st
);
780 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
783 FIMC_BUG(!cis
->cis_data
);
785 sensor_peri
= container_of(cis
, struct fimc_is_device_sensor_peri
, cis
);
786 FIMC_BUG(!sensor_peri
);
788 client
= cis
->client
;
789 if (unlikely(!client
)) {
790 err("client is NULL");
795 cis_data
= cis
->cis_data
;
797 dbg_sensor(1, "[MOD:D:%d] %s\n", cis
->id
, __func__
);
799 I2C_MUTEX_LOCK(cis
->i2c_lock
);
800 sensor_imx333_cis_group_param_hold_func(subdev
, 0x01);
802 #ifdef DEBUG_IMX333_PLL
805 fimc_is_sensor_read16(client
, 0x0300, &pll
);
806 dbg_sensor(1, "______ vt_pix_clk_div(%x)\n", pll
);
807 fimc_is_sensor_read16(client
, 0x0302, &pll
);
808 dbg_sensor(1, "______ vt_sys_clk_div(%x)\n", pll
);
809 fimc_is_sensor_read16(client
, 0x0304, &pll
);
810 dbg_sensor(1, "______ pre_pll_clk_div(%x)\n", pll
);
811 fimc_is_sensor_read16(client
, 0x0306, &pll
);
812 dbg_sensor(1, "______ pll_multiplier(%x)\n", pll
);
813 fimc_is_sensor_read16(client
, 0x0308, &pll
);
814 dbg_sensor(1, "______ op_pix_clk_div(%x)\n", pll
);
815 fimc_is_sensor_read16(client
, 0x030a, &pll
);
816 dbg_sensor(1, "______ op_sys_clk_div(%x)\n", pll
);
818 fimc_is_sensor_read16(client
, 0x030c, &pll
);
819 dbg_sensor(1, "______ secnd_pre_pll_clk_div(%x)\n", pll
);
820 fimc_is_sensor_read16(client
, 0x030e, &pll
);
821 dbg_sensor(1, "______ secnd_pll_multiplier(%x)\n", pll
);
822 fimc_is_sensor_read16(client
, 0x0340, &pll
);
823 dbg_sensor(1, "______ frame_length_lines(%x)\n", pll
);
824 fimc_is_sensor_read16(client
, 0x0342, &pll
);
825 dbg_sensor(1, "______ line_length_pck(%x)\n", pll
);
830 * If a companion is used,
831 * then 8 ms waiting is needed before the StreamOn of a sensor (IMX333).
833 if (test_bit(FIMC_IS_SENSOR_PREPROCESSOR_AVAILABLE
, &sensor_peri
->peri_state
)) {
837 /* Sensor stream on */
838 fimc_is_sensor_write8(client
, 0x0100, 0x01);
840 sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
841 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
843 cis_data
->stream_on
= true;
845 #ifdef DEBUG_SENSOR_TIME
846 do_gettimeofday(&end
);
847 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
854 int sensor_imx333_cis_stream_off(struct v4l2_subdev
*subdev
)
857 struct fimc_is_cis
*cis
;
858 struct i2c_client
*client
;
859 cis_shared_data
*cis_data
;
861 #ifdef DEBUG_SENSOR_TIME
862 struct timeval st
, end
;
863 do_gettimeofday(&st
);
868 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
871 FIMC_BUG(!cis
->cis_data
);
873 client
= cis
->client
;
874 if (unlikely(!client
)) {
875 err("client is NULL");
880 cis_data
= cis
->cis_data
;
882 dbg_sensor(1, "[MOD:D:%d] %s\n", cis
->id
, __func__
);
884 I2C_MUTEX_LOCK(cis
->i2c_lock
);
885 ret
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
887 err("group_param_hold_func failed at stream off");
889 fimc_is_sensor_write8(client
, 0x0100, 0x00);
890 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
892 cis_data
->stream_on
= false;
894 #ifdef DEBUG_SENSOR_TIME
895 do_gettimeofday(&end
);
896 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
903 int sensor_imx333_cis_compensate_gain_under_ext_br(struct v4l2_subdev
*subdev
, u32 expo
, u32
*again
, u32
*dgain
)
906 struct fimc_is_cis
*cis
;
907 cis_shared_data
*cis_data
;
910 u32 vt_pic_clk_freq_mhz
= 0;
911 u32 inflated_coarse_int
= 0;
913 u32 line_length_pck
= 0;
914 u32 min_fine_int
= 0;
915 u32 expected_again
= 0;
921 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
927 cis_data
= cis
->cis_data
;
929 vt_pic_clk_freq_mhz
= cis_data
->pclk
/ (1000 * 1000);
930 line_length_pck
= cis_data
->line_length_pck
;
931 min_fine_int
= cis_data
->min_fine_integration_time
;
933 if (line_length_pck
<= 0) {
934 err("[%s] invalid line_length_pck(%d)\n", __func__
, line_length_pck
);
938 inflated_coarse_int
= (u32
)((u64
)(expo
* vt_pic_clk_freq_mhz
- min_fine_int
)
939 * SENSOR_IMX333_DUMMY_MULTIPLIER
/ line_length_pck
);
940 coarse_int
= (u32
)(inflated_coarse_int
/ SENSOR_IMX333_DUMMY_MULTIPLIER
);
942 if (coarse_int
> cis_data
->max_coarse_integration_time
) {
943 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long_coarse(%d) max(%d)\n", cis
->id
, __func__
,
944 cis_data
->sen_vsync_count
, coarse_int
, cis_data
->max_coarse_integration_time
);
945 inflated_coarse_int
= cis_data
->max_coarse_integration_time
* SENSOR_IMX333_DUMMY_MULTIPLIER
;
948 if (coarse_int
< cis_data
->min_coarse_integration_time
) {
949 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long_coarse(%d) min(%d)\n", cis
->id
, __func__
,
950 cis_data
->sen_vsync_count
, coarse_int
, cis_data
->min_coarse_integration_time
);
951 inflated_coarse_int
= cis_data
->min_coarse_integration_time
* SENSOR_IMX333_DUMMY_MULTIPLIER
;
954 ratio
= inflated_coarse_int
/ coarse_int
;
956 if(coarse_int
<= SENSOR_IMX333_BRIGHT_ILLUMINATION_COMPENSATE_THR
)
958 if(cis_data
->cur_coarse_integration_time_step
== SENSOR_IMX333_COARSE_STEP_2N
)
960 if(coarse_int
% SENSOR_IMX333_COARSE_STEP_2N
== 1)
962 if((coarse_int
% SENSOR_IMX333_COARSE_STEP_2N
) != 0)
964 ratio
= inflated_coarse_int
/ (coarse_int
- 1);
968 else if(cis_data
->cur_coarse_integration_time_step
== SENSOR_IMX333_COARSE_STEP_4N
)
970 if((coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) != 0)
972 if((coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) == 1)
974 ratio
= inflated_coarse_int
/ (coarse_int
- 1);
976 else if((coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) == 2)
978 ratio
= inflated_coarse_int
/ (coarse_int
- 2);
980 else if((coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) == 3)
982 ratio
= inflated_coarse_int
/ (coarse_int
- 3);
988 err("[%s] Unsupported Coarse Integration Time Step Value:%d\n", __func__
, cis_data
->cur_coarse_integration_time_step
);
991 expected_again
= (u32
)((*again
) * ratio
) / SENSOR_IMX333_DUMMY_MULTIPLIER
;
992 if(expected_again
< cis_data
->min_analog_gain
[1])
994 *again
= cis_data
->min_analog_gain
[1];
996 else if(expected_again
> cis_data
->max_analog_gain
[1])
998 *dgain
= (u32
)((*dgain
) * ratio
) / SENSOR_IMX333_DUMMY_MULTIPLIER
;
1002 *again
= expected_again
;
1009 static void sensor_imx333_cis_calc_integration_time_by_step(u16
*coarse_int
, u32 int_time_step
)
1011 if(int_time_step
== SENSOR_IMX333_COARSE_STEP_2N
)
1013 if((*coarse_int
% SENSOR_IMX333_COARSE_STEP_2N
) != 0)
1018 if(*coarse_int
<= SENSOR_IMX333_COARSE_STEP_2N
)
1020 *coarse_int
= SENSOR_IMX333_COARSE_STEP_2N
;
1023 else if(int_time_step
== SENSOR_IMX333_COARSE_STEP_4N
)
1025 if((*coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) != 0)
1027 if((*coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) == 1)
1031 else if((*coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) == 2)
1035 else if((*coarse_int
% SENSOR_IMX333_COARSE_STEP_4N
) == 3)
1041 if(*coarse_int
<= SENSOR_IMX333_COARSE_STEP_4N
)
1043 *coarse_int
= SENSOR_IMX333_COARSE_STEP_4N
;
1048 info("[%s] Unsupported Coarse Integration Time Step: %d\n", __func__
, int_time_step
);
1051 if(*coarse_int
<= SENSOR_IMX333_COARSE_STEP_2N
)
1053 *coarse_int
= SENSOR_IMX333_COARSE_STEP_2N
;
1057 int sensor_imx333_cis_set_exposure_time(struct v4l2_subdev
*subdev
, struct ae_param
*target_exposure
)
1061 struct fimc_is_cis
*cis
;
1062 struct i2c_client
*client
;
1063 cis_shared_data
*cis_data
;
1065 u32 vt_pic_clk_freq_mhz
= 0;
1066 u16 long_coarse_int
= 0;
1067 u16 short_coarse_int
= 0;
1068 u32 line_length_pck
= 0;
1069 u32 min_fine_int
= 0;
1072 #ifdef DEBUG_SENSOR_TIME
1073 struct timeval st
, end
;
1074 do_gettimeofday(&st
);
1078 FIMC_BUG(!target_exposure
);
1080 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1083 FIMC_BUG(!cis
->cis_data
);
1085 client
= cis
->client
;
1086 if (unlikely(!client
)) {
1087 err("client is NULL");
1092 if ((target_exposure
->long_val
<= 0) || (target_exposure
->short_val
<= 0)) {
1093 err("[%s] invalid target exposure(%d, %d)\n", __func__
,
1094 target_exposure
->long_val
, target_exposure
->short_val
);
1099 cis_data
= cis
->cis_data
;
1101 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), target long(%d), short(%d)\n", cis
->id
, __func__
,
1102 cis_data
->sen_vsync_count
, target_exposure
->long_val
, target_exposure
->short_val
);
1104 vt_pic_clk_freq_mhz
= cis_data
->pclk
/ (1000 * 1000);
1105 line_length_pck
= cis_data
->line_length_pck
;
1106 min_fine_int
= cis_data
->min_fine_integration_time
;
1108 long_coarse_int
= ((target_exposure
->long_val
* vt_pic_clk_freq_mhz
) - min_fine_int
) / line_length_pck
;
1109 short_coarse_int
= ((target_exposure
->short_val
* vt_pic_clk_freq_mhz
) - min_fine_int
) / line_length_pck
;
1111 if (long_coarse_int
> cis_data
->max_coarse_integration_time
) {
1112 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long coarse(%d) max(%d)\n", cis
->id
, __func__
,
1113 cis_data
->sen_vsync_count
, long_coarse_int
, cis_data
->max_coarse_integration_time
);
1114 long_coarse_int
= cis_data
->max_coarse_integration_time
;
1117 if (short_coarse_int
> cis_data
->max_coarse_integration_time
) {
1118 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), short coarse(%d) max(%d)\n", cis
->id
, __func__
,
1119 cis_data
->sen_vsync_count
, short_coarse_int
, cis_data
->max_coarse_integration_time
);
1120 short_coarse_int
= cis_data
->max_coarse_integration_time
;
1123 if (long_coarse_int
< cis_data
->min_coarse_integration_time
) {
1124 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), long coarse(%d) min(%d)\n", cis
->id
, __func__
,
1125 cis_data
->sen_vsync_count
, long_coarse_int
, cis_data
->min_coarse_integration_time
);
1126 long_coarse_int
= cis_data
->min_coarse_integration_time
;
1129 if (short_coarse_int
< cis_data
->min_coarse_integration_time
) {
1130 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), short coarse(%d) min(%d)\n", cis
->id
, __func__
,
1131 cis_data
->sen_vsync_count
, short_coarse_int
, cis_data
->min_coarse_integration_time
);
1132 short_coarse_int
= cis_data
->min_coarse_integration_time
;
1135 sensor_imx333_cis_calc_integration_time_by_step(&long_coarse_int
, cis_data
->cur_coarse_integration_time_step
);
1136 sensor_imx333_cis_calc_integration_time_by_step(&short_coarse_int
, cis_data
->cur_coarse_integration_time_step
);
1138 cis_data
->cur_long_exposure_coarse
= long_coarse_int
;
1139 cis_data
->cur_short_exposure_coarse
= short_coarse_int
;
1141 I2C_MUTEX_LOCK(cis
->i2c_lock
);
1142 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x01);
1149 if (fimc_is_vender_wdr_mode_on(cis_data
)) {
1150 fimc_is_sensor_write8(cis
->client
, 0x0220, 0x61);
1152 fimc_is_sensor_write8(cis
->client
, 0x0220, 0x00);
1156 arrayBuf
[0] = (cis_data
->cur_long_exposure_coarse
& 0xFF00) >> 8;
1157 arrayBuf
[1] = cis_data
->cur_long_exposure_coarse
& 0xFF;
1158 ret
= fimc_is_sensor_write8_array(client
, 0x0202, arrayBuf
, 2);
1162 /* Short exposure */
1163 /* if (fimc_is_vender_wdr_mode_on(cis_data)) */
1165 arrayBuf
[0] = (cis_data
->cur_short_exposure_coarse
& 0xFF00) >> 8;
1166 arrayBuf
[1] = cis_data
->cur_short_exposure_coarse
& 0xFF;
1167 ret
= fimc_is_sensor_write8_array(client
, 0x0224, arrayBuf
, 2);
1172 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), vt_pic_clk_freq_mhz (%d),"
1173 KERN_CONT
"line_length_pck(%d), min_fine_int (%d)\n", cis
->id
, __func__
,
1174 cis_data
->sen_vsync_count
, vt_pic_clk_freq_mhz
, line_length_pck
, min_fine_int
);
1175 dbg_sensor(1, "[MOD:D:%d] %s, vsync_cnt(%d), frame_length_lines(%#x),"
1176 KERN_CONT
"long_coarse_int %#x, short_coarse_int %#x\n", cis
->id
, __func__
,
1177 cis_data
->sen_vsync_count
, cis_data
->frame_length_lines
, long_coarse_int
, short_coarse_int
);
1179 #ifdef DEBUG_SENSOR_TIME
1180 do_gettimeofday(&end
);
1181 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1186 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
1190 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
1195 int sensor_imx333_cis_get_min_exposure_time(struct v4l2_subdev
*subdev
, u32
*min_expo
)
1198 struct fimc_is_cis
*cis
= NULL
;
1199 cis_shared_data
*cis_data
= NULL
;
1200 u32 min_integration_time
= 0;
1203 u32 vt_pic_clk_freq_mhz
= 0;
1204 u32 line_length_pck
= 0;
1206 #ifdef DEBUG_SENSOR_TIME
1207 struct timeval st
, end
;
1208 do_gettimeofday(&st
);
1212 FIMC_BUG(!min_expo
);
1214 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1217 FIMC_BUG(!cis
->cis_data
);
1219 cis_data
= cis
->cis_data
;
1221 vt_pic_clk_freq_mhz
= cis_data
->pclk
/ (1000 * 1000);
1222 if (vt_pic_clk_freq_mhz
== 0) {
1223 pr_err("[MOD:D:%d] %s, Invalid vt_pic_clk_freq_mhz(%d)\n", cis
->id
, __func__
, vt_pic_clk_freq_mhz
);
1226 line_length_pck
= cis_data
->line_length_pck
;
1227 min_coarse
= cis_data
->min_coarse_integration_time
;
1228 min_fine
= cis_data
->min_fine_integration_time
;
1230 min_integration_time
= ((line_length_pck
* min_coarse
) + min_fine
) / vt_pic_clk_freq_mhz
;
1231 *min_expo
= min_integration_time
;
1233 dbg_sensor(1, "[%s] min integration time %d\n", __func__
, min_integration_time
);
1235 #ifdef DEBUG_SENSOR_TIME
1236 do_gettimeofday(&end
);
1237 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1244 int sensor_imx333_cis_get_max_exposure_time(struct v4l2_subdev
*subdev
, u32
*max_expo
)
1247 struct fimc_is_cis
*cis
;
1248 cis_shared_data
*cis_data
;
1249 u32 max_integration_time
= 0;
1250 u32 max_coarse_margin
= 0;
1251 u32 max_fine_margin
= 0;
1254 u32 vt_pic_clk_freq_mhz
= 0;
1255 u32 line_length_pck
= 0;
1256 u32 frame_length_lines
= 0;
1258 #ifdef DEBUG_SENSOR_TIME
1259 struct timeval st
, end
;
1260 do_gettimeofday(&st
);
1264 FIMC_BUG(!max_expo
);
1266 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1269 FIMC_BUG(!cis
->cis_data
);
1271 cis_data
= cis
->cis_data
;
1273 vt_pic_clk_freq_mhz
= cis_data
->pclk
/ (1000 * 1000);
1274 if (vt_pic_clk_freq_mhz
== 0) {
1275 pr_err("[MOD:D:%d] %s, Invalid vt_pic_clk_freq_mhz(%d)\n", cis
->id
, __func__
, vt_pic_clk_freq_mhz
);
1278 line_length_pck
= cis_data
->line_length_pck
;
1279 frame_length_lines
= cis_data
->frame_length_lines
;
1281 max_coarse_margin
= cis_data
->max_margin_coarse_integration_time
;
1282 max_fine_margin
= line_length_pck
- cis_data
->min_fine_integration_time
;
1283 max_coarse
= frame_length_lines
- max_coarse_margin
;
1284 max_fine
= cis_data
->max_fine_integration_time
;
1286 max_integration_time
= ((line_length_pck
* max_coarse
) + max_fine
) / vt_pic_clk_freq_mhz
;
1288 *max_expo
= max_integration_time
;
1290 /* TODO: Is this values update hear? */
1291 cis_data
->max_margin_fine_integration_time
= max_fine_margin
;
1292 cis_data
->max_coarse_integration_time
= max_coarse
;
1294 dbg_sensor(1, "[%s] max integration time %d, max margin fine integration %d, max coarse integration %d\n",
1295 __func__
, max_integration_time
, cis_data
->max_margin_fine_integration_time
, cis_data
->max_coarse_integration_time
);
1297 #ifdef DEBUG_SENSOR_TIME
1298 do_gettimeofday(&end
);
1299 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1306 int sensor_imx333_cis_adjust_frame_duration(struct v4l2_subdev
*subdev
,
1307 u32 input_exposure_time
,
1308 u32
*target_duration
)
1311 struct fimc_is_cis
*cis
;
1312 cis_shared_data
*cis_data
;
1314 u32 vt_pic_clk_freq_mhz
= 0;
1315 u32 line_length_pck
= 0;
1316 u32 frame_length_lines
= 0;
1317 u32 frame_duration
= 0;
1319 #ifdef DEBUG_SENSOR_TIME
1320 struct timeval st
, end
;
1321 do_gettimeofday(&st
);
1325 FIMC_BUG(!target_duration
);
1327 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1330 FIMC_BUG(!cis
->cis_data
);
1332 cis_data
= cis
->cis_data
;
1334 vt_pic_clk_freq_mhz
= cis_data
->pclk
/ (1000 * 1000);
1335 line_length_pck
= cis_data
->line_length_pck
;
1336 frame_length_lines
= ((vt_pic_clk_freq_mhz
* input_exposure_time
) / line_length_pck
);
1337 frame_length_lines
+= cis_data
->max_margin_coarse_integration_time
;
1339 frame_duration
= (frame_length_lines
* line_length_pck
) / vt_pic_clk_freq_mhz
;
1341 dbg_sensor(1, "[%s](vsync cnt = %d) input exp(%d), adj duration, frame duraion(%d), min_frame_us(%d)\n",
1342 __func__
, cis_data
->sen_vsync_count
, input_exposure_time
, frame_duration
, cis_data
->min_frame_us_time
);
1343 dbg_sensor(1, "[%s](vsync cnt = %d) adj duration, frame duraion(%d), min_frame_us(%d)\n",
1344 __func__
, cis_data
->sen_vsync_count
, frame_duration
, cis_data
->min_frame_us_time
);
1346 *target_duration
= MAX(frame_duration
, cis_data
->min_frame_us_time
);
1348 #ifdef DEBUG_SENSOR_TIME
1349 do_gettimeofday(&end
);
1350 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1356 int sensor_imx333_cis_set_frame_duration(struct v4l2_subdev
*subdev
, u32 frame_duration
)
1360 struct fimc_is_cis
*cis
;
1361 struct i2c_client
*client
;
1362 cis_shared_data
*cis_data
;
1364 u32 vt_pic_clk_freq_mhz
= 0;
1365 u32 line_length_pck
= 0;
1366 u16 frame_length_lines
= 0;
1368 #ifdef DEBUG_SENSOR_TIME
1369 struct timeval st
, end
;
1370 do_gettimeofday(&st
);
1375 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1378 FIMC_BUG(!cis
->cis_data
);
1380 client
= cis
->client
;
1381 if (unlikely(!client
)) {
1382 err("client is NULL");
1387 cis_data
= cis
->cis_data
;
1389 if (frame_duration
< cis_data
->min_frame_us_time
) {
1390 dbg_sensor(1, "frame duration is less than min(%d)\n", frame_duration
);
1391 frame_duration
= cis_data
->min_frame_us_time
;
1394 vt_pic_clk_freq_mhz
= cis_data
->pclk
/ (1000 * 1000);
1395 line_length_pck
= cis_data
->line_length_pck
;
1397 frame_length_lines
= (u16
)((vt_pic_clk_freq_mhz
* frame_duration
) / line_length_pck
);
1399 dbg_sensor(1, "[MOD:D:%d] %s, vt_pic_clk_freq_mhz(%#x) frame_duration = %d us,"
1400 KERN_CONT
"(line_length_pck%#x), frame_length_lines(%#x)\n",
1401 cis
->id
, __func__
, vt_pic_clk_freq_mhz
, frame_duration
,
1402 line_length_pck
, frame_length_lines
);
1404 I2C_MUTEX_LOCK(cis
->i2c_lock
);
1405 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x01);
1411 ret
= fimc_is_sensor_write16(client
, 0x0340, frame_length_lines
);
1415 cis_data
->cur_frame_us_time
= frame_duration
;
1416 cis_data
->frame_length_lines
= frame_length_lines
;
1417 cis_data
->max_coarse_integration_time
= cis_data
->frame_length_lines
- cis_data
->max_margin_coarse_integration_time
;
1419 #ifdef DEBUG_SENSOR_TIME
1420 do_gettimeofday(&end
);
1421 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1426 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
1430 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
1435 int sensor_imx333_cis_set_frame_rate(struct v4l2_subdev
*subdev
, u32 min_fps
)
1438 struct fimc_is_cis
*cis
;
1439 cis_shared_data
*cis_data
;
1441 u32 frame_duration
= 0;
1443 #ifdef DEBUG_SENSOR_TIME
1444 struct timeval st
, end
;
1445 do_gettimeofday(&st
);
1450 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1453 FIMC_BUG(!cis
->cis_data
);
1455 cis_data
= cis
->cis_data
;
1457 if (min_fps
> cis_data
->max_fps
) {
1458 err("[MOD:D:%d] %s, request FPS is too high(%d), set to max(%d)\n",
1459 cis
->id
, __func__
, min_fps
, cis_data
->max_fps
);
1460 min_fps
= cis_data
->max_fps
;
1464 err("[MOD:D:%d] %s, request FPS is 0, set to min FPS(1)\n",
1469 frame_duration
= (1 * 1000 * 1000) / min_fps
;
1471 dbg_sensor(1, "[MOD:D:%d] %s, set FPS(%d), frame duration(%d)\n",
1472 cis
->id
, __func__
, min_fps
, frame_duration
);
1474 ret
= sensor_imx333_cis_set_frame_duration(subdev
, frame_duration
);
1476 err("[MOD:D:%d] %s, set frame duration is fail(%d)\n",
1477 cis
->id
, __func__
, ret
);
1481 cis_data
->min_frame_us_time
= frame_duration
;
1483 #ifdef DEBUG_SENSOR_TIME
1484 do_gettimeofday(&end
);
1485 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1493 u32
sensor_imx333_cis_calc_again_code(u32 permille
)
1495 return 512 - (512000 / permille
);
1498 u32
sensor_imx333_cis_calc_again_permile(u32 code
)
1500 return 512000 / (512 - code
);
1503 int sensor_imx333_cis_adjust_analog_gain(struct v4l2_subdev
*subdev
, u32 input_again
, u32
*target_permile
)
1506 struct fimc_is_cis
*cis
;
1507 cis_shared_data
*cis_data
;
1510 u32 again_permile
= 0;
1512 #ifdef DEBUG_SENSOR_TIME
1513 struct timeval st
, end
;
1514 do_gettimeofday(&st
);
1518 FIMC_BUG(!target_permile
);
1520 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1523 FIMC_BUG(!cis
->cis_data
);
1525 cis_data
= cis
->cis_data
;
1527 again_code
= sensor_cis_calc_again_code(input_again
);
1529 if (again_code
> cis_data
->max_analog_gain
[0]) {
1530 again_code
= cis_data
->max_analog_gain
[0];
1531 } else if (again_code
< cis_data
->min_analog_gain
[0]) {
1532 again_code
= cis_data
->min_analog_gain
[0];
1535 again_permile
= sensor_imx333_cis_calc_again_permile(again_code
);
1537 dbg_sensor(1, "[%s] min again(%d), max(%d), input_again(%d), code(%d), permile(%d)\n", __func__
,
1538 cis_data
->max_analog_gain
[0],
1539 cis_data
->min_analog_gain
[0],
1544 *target_permile
= again_permile
;
1549 int sensor_imx333_cis_set_analog_gain(struct v4l2_subdev
*subdev
, struct ae_param
*again
)
1553 struct fimc_is_cis
*cis
;
1554 struct i2c_client
*client
;
1556 u16 analog_gain
= 0;
1559 #ifdef DEBUG_SENSOR_TIME
1560 struct timeval st
, end
;
1561 do_gettimeofday(&st
);
1567 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1571 client
= cis
->client
;
1572 if (unlikely(!client
)) {
1573 err("client is NULL");
1578 analog_gain
= (u16
)sensor_imx333_cis_calc_again_code(again
->val
);
1580 if (analog_gain
< cis
->cis_data
->min_analog_gain
[0]) {
1581 analog_gain
= cis
->cis_data
->min_analog_gain
[0];
1584 if (analog_gain
> cis
->cis_data
->max_analog_gain
[0]) {
1585 analog_gain
= cis
->cis_data
->max_analog_gain
[0];
1588 dbg_sensor(1, "[MOD:D:%d] %s(vsync cnt = %d), input_again = %d us, analog_gain(%#x)\n",
1589 cis
->id
, __func__
, cis
->cis_data
->sen_vsync_count
, again
->val
, analog_gain
);
1591 I2C_MUTEX_LOCK(cis
->i2c_lock
);
1592 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x01);
1599 arrayBuf
[0] = (analog_gain
& 0xFF00) >> 8;
1600 arrayBuf
[1] = analog_gain
& 0xFF;
1601 ret
= fimc_is_sensor_write8_array(client
, 0x0204, arrayBuf
, 2);
1605 #ifdef DEBUG_SENSOR_TIME
1606 do_gettimeofday(&end
);
1607 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1612 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
1616 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
1621 int sensor_imx333_cis_get_analog_gain(struct v4l2_subdev
*subdev
, u32
*again
)
1625 struct fimc_is_cis
*cis
;
1626 struct i2c_client
*client
;
1628 u16 analog_gain
= 0;
1630 #ifdef DEBUG_SENSOR_TIME
1631 struct timeval st
, end
;
1632 do_gettimeofday(&st
);
1638 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1642 client
= cis
->client
;
1643 if (unlikely(!client
)) {
1644 err("client is NULL");
1649 I2C_MUTEX_LOCK(cis
->i2c_lock
);
1650 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x01);
1656 ret
= fimc_is_sensor_read16(client
, 0x0204, &analog_gain
);
1660 *again
= sensor_imx333_cis_calc_again_permile(analog_gain
);
1662 dbg_sensor(1, "[MOD:D:%d] %s, cur_again = %d us, analog_gain(%#x)\n",
1663 cis
->id
, __func__
, *again
, analog_gain
);
1665 #ifdef DEBUG_SENSOR_TIME
1666 do_gettimeofday(&end
);
1667 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1672 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
1676 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
1681 int sensor_imx333_cis_get_min_analog_gain(struct v4l2_subdev
*subdev
, u32
*min_again
)
1684 struct fimc_is_cis
*cis
;
1685 struct i2c_client
*client
;
1686 cis_shared_data
*cis_data
;
1688 #ifdef DEBUG_SENSOR_TIME
1689 struct timeval st
, end
;
1690 do_gettimeofday(&st
);
1694 FIMC_BUG(!min_again
);
1696 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1699 FIMC_BUG(!cis
->cis_data
);
1701 client
= cis
->client
;
1702 if (unlikely(!client
)) {
1703 err("client is NULL");
1708 cis_data
= cis
->cis_data
;
1710 cis_data
->min_analog_gain
[0] = 0x0;
1711 cis_data
->min_analog_gain
[1] = sensor_imx333_cis_calc_again_permile(cis_data
->min_analog_gain
[0]);
1712 *min_again
= cis_data
->min_analog_gain
[1];
1714 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__
, cis_data
->min_analog_gain
[0],
1715 cis_data
->min_analog_gain
[1]);
1717 #ifdef DEBUG_SENSOR_TIME
1718 do_gettimeofday(&end
);
1719 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1726 int sensor_imx333_cis_get_max_analog_gain(struct v4l2_subdev
*subdev
, u32
*max_again
)
1729 struct fimc_is_cis
*cis
;
1730 struct i2c_client
*client
;
1731 cis_shared_data
*cis_data
;
1733 #ifdef DEBUG_SENSOR_TIME
1734 struct timeval st
, end
;
1735 do_gettimeofday(&st
);
1739 FIMC_BUG(!max_again
);
1741 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1744 FIMC_BUG(!cis
->cis_data
);
1746 client
= cis
->client
;
1747 if (unlikely(!client
)) {
1748 err("client is NULL");
1753 cis_data
= cis
->cis_data
;
1754 cis_data
->max_analog_gain
[0] = 0x1C0;
1755 cis_data
->max_analog_gain
[1] = sensor_imx333_cis_calc_again_permile(cis_data
->max_analog_gain
[0]);
1756 *max_again
= cis_data
->max_analog_gain
[1];
1758 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__
, cis_data
->max_analog_gain
[0],
1759 cis_data
->max_analog_gain
[1]);
1761 #ifdef DEBUG_SENSOR_TIME
1762 do_gettimeofday(&end
);
1763 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1770 int sensor_imx333_cis_set_digital_gain(struct v4l2_subdev
*subdev
, struct ae_param
*dgain
)
1774 struct fimc_is_cis
*cis
;
1775 struct i2c_client
*client
;
1776 cis_shared_data
*cis_data
;
1782 #ifdef DEBUG_SENSOR_TIME
1783 struct timeval st
, end
;
1784 do_gettimeofday(&st
);
1790 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1793 FIMC_BUG(!cis
->cis_data
);
1795 client
= cis
->client
;
1796 if (unlikely(!client
)) {
1797 err("client is NULL");
1802 cis_data
= cis
->cis_data
;
1804 long_gain
= (u16
)sensor_cis_calc_dgain_code(dgain
->long_val
);
1805 short_gain
= (u16
)sensor_cis_calc_dgain_code(dgain
->short_val
);
1807 if (long_gain
< cis
->cis_data
->min_digital_gain
[0]) {
1808 long_gain
= cis
->cis_data
->min_digital_gain
[0];
1810 if (long_gain
> cis
->cis_data
->max_digital_gain
[0]) {
1811 long_gain
= cis
->cis_data
->max_digital_gain
[0];
1814 if (short_gain
< cis
->cis_data
->min_digital_gain
[0]) {
1815 short_gain
= cis
->cis_data
->min_digital_gain
[0];
1817 if (short_gain
> cis
->cis_data
->max_digital_gain
[0]) {
1818 short_gain
= cis
->cis_data
->max_digital_gain
[0];
1821 dbg_sensor(1, "[MOD:D:%d] %s(vsync cnt = %d), input_dgain = %d/%d us,"
1822 KERN_CONT
"long_gain(%#x), short_gain(%#x)\n",
1823 cis
->id
, __func__
, cis
->cis_data
->sen_vsync_count
,
1824 dgain
->long_val
, dgain
->short_val
, long_gain
, short_gain
);
1826 I2C_MUTEX_LOCK(cis
->i2c_lock
);
1827 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x01);
1833 /* Set current short & long digitial gain */
1834 /* 0x0226 ~ 0x0227 : ST_DIG_GAIN_GLOBAL */
1835 /* 0x020E ~ 0x020F : DIG_GAIN_GLOBAL */
1836 /* if (fimc_is_vender_wdr_mode_on(cis_data)) */
1838 dgains
[0] = (short_gain
& 0xFF00) >> 8;
1839 dgains
[1] = short_gain
& 0xFF;
1840 ret
= fimc_is_sensor_write8_array(client
, 0x0226, dgains
, 2);
1844 dgains
[0] = (long_gain
& 0xFF00) >> 8;
1845 dgains
[1] = long_gain
& 0xFF;
1846 ret
= fimc_is_sensor_write8_array(client
, 0x020E, dgains
, 2);
1850 #ifdef DEBUG_SENSOR_TIME
1851 do_gettimeofday(&end
);
1852 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1857 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
1861 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
1866 int sensor_imx333_cis_get_digital_gain(struct v4l2_subdev
*subdev
, u32
*dgain
)
1870 struct fimc_is_cis
*cis
;
1871 struct i2c_client
*client
;
1873 u16 digital_gain
= 0;
1875 #ifdef DEBUG_SENSOR_TIME
1876 struct timeval st
, end
;
1877 do_gettimeofday(&st
);
1883 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1887 client
= cis
->client
;
1888 if (unlikely(!client
)) {
1889 err("client is NULL");
1894 I2C_MUTEX_LOCK(cis
->i2c_lock
);
1895 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x01);
1901 ret
= fimc_is_sensor_read16(client
, 0x020E, &digital_gain
);
1905 *dgain
= sensor_cis_calc_dgain_permile(digital_gain
);
1907 dbg_sensor(1, "[MOD:D:%d] %s, cur_dgain = %d us, digital_gain(%#x)\n",
1908 cis
->id
, __func__
, *dgain
, digital_gain
);
1910 #ifdef DEBUG_SENSOR_TIME
1911 do_gettimeofday(&end
);
1912 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1917 hold
= sensor_imx333_cis_group_param_hold_func(subdev
, 0x00);
1921 I2C_MUTEX_UNLOCK(cis
->i2c_lock
);
1926 int sensor_imx333_cis_get_min_digital_gain(struct v4l2_subdev
*subdev
, u32
*min_dgain
)
1929 struct fimc_is_cis
*cis
;
1930 struct i2c_client
*client
;
1931 cis_shared_data
*cis_data
;
1933 #ifdef DEBUG_SENSOR_TIME
1934 struct timeval st
, end
;
1935 do_gettimeofday(&st
);
1939 FIMC_BUG(!min_dgain
);
1941 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1944 FIMC_BUG(!cis
->cis_data
);
1946 client
= cis
->client
;
1947 if (unlikely(!client
)) {
1948 err("client is NULL");
1953 cis_data
= cis
->cis_data
;
1954 cis_data
->min_digital_gain
[0] = 0x100;
1955 cis_data
->min_digital_gain
[1] = sensor_cis_calc_dgain_permile(cis_data
->min_digital_gain
[0]);
1957 *min_dgain
= cis_data
->min_digital_gain
[1];
1959 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__
, cis_data
->min_digital_gain
[0],
1960 cis_data
->min_digital_gain
[1]);
1962 #ifdef DEBUG_SENSOR_TIME
1963 do_gettimeofday(&end
);
1964 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
1971 int sensor_imx333_cis_get_max_digital_gain(struct v4l2_subdev
*subdev
, u32
*max_dgain
)
1974 struct fimc_is_cis
*cis
;
1975 struct i2c_client
*client
;
1976 cis_shared_data
*cis_data
;
1978 #ifdef DEBUG_SENSOR_TIME
1979 struct timeval st
, end
;
1980 do_gettimeofday(&st
);
1984 FIMC_BUG(!max_dgain
);
1986 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
1989 FIMC_BUG(!cis
->cis_data
);
1991 client
= cis
->client
;
1992 if (unlikely(!client
)) {
1993 err("client is NULL");
1998 cis_data
= cis
->cis_data
;
1999 cis_data
->max_digital_gain
[0] = 0xfff;
2000 cis_data
->max_digital_gain
[1] = sensor_cis_calc_dgain_permile(cis_data
->max_digital_gain
[0]);
2002 *max_dgain
= cis_data
->max_digital_gain
[1];
2004 dbg_sensor(1, "[%s] code %d, permile %d\n", __func__
, cis_data
->max_digital_gain
[0],
2005 cis_data
->max_digital_gain
[1]);
2007 #ifdef DEBUG_SENSOR_TIME
2008 do_gettimeofday(&end
);
2009 dbg_sensor(1, "[%s] time %lu us\n", __func__
, (end
.tv_sec
- st
.tv_sec
)*1000000 + (end
.tv_usec
- st
.tv_usec
));
2016 int sensor_imx333_cis_long_term_exposure(struct v4l2_subdev
*subdev
)
2019 struct fimc_is_cis
*cis
;
2020 struct fimc_is_long_term_expo_mode
*lte_mode
;
2021 unsigned char cit_lshift_val
= 0;
2025 cis
= (struct fimc_is_cis
*)v4l2_get_subdevdata(subdev
);
2026 lte_mode
= &cis
->long_term_mode
;
2028 /* LTE mode or normal mode set */
2029 if (lte_mode
->sen_strm_off_on_enable
) {
2030 if (lte_mode
->expo
[0] > 500000) {
2031 cit_lshift_val
= (unsigned char)(lte_mode
->expo
[0] / 500000);
2032 cit_lshift_val
= cit_lshift_val
/ 2;
2033 lte_mode
->expo
[0] = 500000;
2034 ret
|= fimc_is_sensor_write8(cis
->client
, 0x3008, cit_lshift_val
);
2038 ret
|= fimc_is_sensor_write8(cis
->client
, 0x3008, cit_lshift_val
);
2041 info("%s enable(%d) %d %d", __func__
, lte_mode
->sen_strm_off_on_enable
, cit_lshift_val
, lte_mode
->expo
[0]);
2044 pr_err("ERR[%s]: LTE register setting fail\n", __func__
);
2050 static struct fimc_is_cis_ops cis_ops_imx333
= {
2051 .cis_init
= sensor_imx333_cis_init
,
2052 .cis_log_status
= sensor_imx333_cis_log_status
,
2053 .cis_group_param_hold
= sensor_imx333_cis_group_param_hold
,
2054 .cis_set_global_setting
= sensor_imx333_cis_set_global_setting
,
2055 .cis_mode_change
= sensor_imx333_cis_mode_change
,
2056 .cis_set_size
= sensor_imx333_cis_set_size
,
2057 .cis_stream_on
= sensor_imx333_cis_stream_on
,
2058 .cis_stream_off
= sensor_imx333_cis_stream_off
,
2059 .cis_set_exposure_time
= sensor_imx333_cis_set_exposure_time
,
2060 .cis_get_min_exposure_time
= sensor_imx333_cis_get_min_exposure_time
,
2061 .cis_get_max_exposure_time
= sensor_imx333_cis_get_max_exposure_time
,
2062 .cis_adjust_frame_duration
= sensor_imx333_cis_adjust_frame_duration
,
2063 .cis_set_frame_duration
= sensor_imx333_cis_set_frame_duration
,
2064 .cis_set_frame_rate
= sensor_imx333_cis_set_frame_rate
,
2065 .cis_adjust_analog_gain
= sensor_imx333_cis_adjust_analog_gain
,
2066 .cis_set_analog_gain
= sensor_imx333_cis_set_analog_gain
,
2067 .cis_get_analog_gain
= sensor_imx333_cis_get_analog_gain
,
2068 .cis_get_min_analog_gain
= sensor_imx333_cis_get_min_analog_gain
,
2069 .cis_get_max_analog_gain
= sensor_imx333_cis_get_max_analog_gain
,
2070 .cis_set_digital_gain
= sensor_imx333_cis_set_digital_gain
,
2071 .cis_get_digital_gain
= sensor_imx333_cis_get_digital_gain
,
2072 .cis_get_min_digital_gain
= sensor_imx333_cis_get_min_digital_gain
,
2073 .cis_get_max_digital_gain
= sensor_imx333_cis_get_max_digital_gain
,
2075 .cis_compensate_gain_for_extremely_br
= sensor_cis_compensate_gain_for_extremely_br
,
2077 .cis_compensate_gain_for_extremely_br
= sensor_imx333_cis_compensate_gain_under_ext_br
,
2079 .cis_wait_streamoff
= sensor_cis_wait_streamoff
,
2080 .cis_data_calculation
= sensor_imx333_cis_data_calc
,
2081 .cis_set_long_term_exposure
= sensor_imx333_cis_long_term_exposure
,
2084 static int cis_imx333_probe(struct i2c_client
*client
,
2085 const struct i2c_device_id
*id
)
2088 struct fimc_is_core
*core
= NULL
;
2089 struct v4l2_subdev
*subdev_cis
= NULL
;
2090 struct fimc_is_cis
*cis
= NULL
;
2091 struct fimc_is_device_sensor
*device
= NULL
;
2092 struct fimc_is_device_sensor_peri
*sensor_peri
= NULL
;
2093 u32 sensor_id
[FIMC_IS_SENSOR_COUNT
] = {0, };
2095 const u32
*sensor_id_spec
;
2096 char const *setfile
;
2098 struct device_node
*dnode
;
2102 FIMC_BUG(!fimc_is_dev
);
2104 core
= (struct fimc_is_core
*)dev_get_drvdata(fimc_is_dev
);
2106 probe_info("core device is not yet probed");
2107 return -EPROBE_DEFER
;
2111 dnode
= dev
->of_node
;
2113 sensor_id_spec
= of_get_property(dnode
, "id", &sensor_id_len
);
2114 if (!sensor_id_spec
) {
2115 err("sensor_id num read is fail(%d)", ret
);
2119 sensor_id_len
/= sizeof(*sensor_id_spec
);
2121 probe_info("%s sensor_id_spec %d, sensor_id_len %d\n", __func__
,
2122 *sensor_id_spec
, sensor_id_len
);
2124 ret
= of_property_read_u32_array(dnode
, "id", sensor_id
, sensor_id_len
);
2126 err("sensor_id read is fail(%d)", ret
);
2130 for (i
= 0; i
< sensor_id_len
; i
++) {
2131 probe_info("%s sensor_id %d\n", __func__
, sensor_id
[i
]);
2132 device
= &core
->sensor
[sensor_id
[i
]];
2134 sensor_peri
= find_peri_by_cis_id(device
, SENSOR_NAME_IMX333
);
2136 probe_info("sensor peri is net yet probed");
2137 return -EPROBE_DEFER
;
2141 for (i
= 0; i
< sensor_id_len
; i
++) {
2142 device
= &core
->sensor
[sensor_id
[i
]];
2143 sensor_peri
= find_peri_by_cis_id(device
, SENSOR_NAME_IMX333
);
2145 cis
= &sensor_peri
->cis
;
2146 subdev_cis
= kzalloc(sizeof(struct v4l2_subdev
), GFP_KERNEL
);
2148 probe_err("subdev_cis is NULL");
2153 sensor_peri
->subdev_cis
= subdev_cis
;
2155 cis
->id
= SENSOR_NAME_IMX333
;
2156 cis
->subdev
= subdev_cis
;
2157 cis
->device
= sensor_id
[i
];
2158 cis
->client
= client
;
2159 sensor_peri
->module
->client
= cis
->client
;
2160 cis
->i2c_lock
= NULL
;
2161 cis
->ctrl_delay
= N_PLUS_TWO_FRAME
;
2163 cis
->cis_data
= kzalloc(sizeof(cis_shared_data
), GFP_KERNEL
);
2164 if (!cis
->cis_data
) {
2165 err("cis_data is NULL");
2170 cis
->cis_ops
= &cis_ops_imx333
;
2172 /* belows are depend on sensor cis. MUST check sensor spec */
2173 cis
->bayer_order
= OTF_INPUT_ORDER_BAYER_GR_BG
;
2175 if (of_property_read_bool(dnode
, "sensor_f_number")) {
2176 ret
= of_property_read_u32(dnode
, "sensor_f_number", &cis
->aperture_num
);
2178 warn("f-number read is fail(%d)",ret
);
2181 cis
->aperture_num
= F2_2
;
2184 probe_info("%s f-number %d\n", __func__
, cis
->aperture_num
);
2186 cis
->use_dgain
= true;
2187 cis
->hdr_ctrl_by_again
= false;
2189 v4l2_set_subdevdata(subdev_cis
, cis
);
2190 v4l2_set_subdev_hostdata(subdev_cis
, device
);
2191 snprintf(subdev_cis
->name
, V4L2_SUBDEV_NAME_SIZE
, "cis-subdev.%d", cis
->id
);
2194 ret
= of_property_read_string(dnode
, "setfile", &setfile
);
2196 err("setfile index read fail(%d), take default setfile!!", ret
);
2197 setfile
= "default";
2200 probe_info("%s done\n", __func__
);
2206 static const struct of_device_id sensor_cis_imx333_match
[] = {
2208 .compatible
= "samsung,exynos5-fimc-is-cis-imx333",
2212 MODULE_DEVICE_TABLE(of
, sensor_cis_imx333_match
);
2214 static const struct i2c_device_id sensor_cis_imx333_idt
[] = {
2219 static struct i2c_driver sensor_cis_imx333_driver
= {
2220 .probe
= cis_imx333_probe
,
2222 .name
= SENSOR_NAME
,
2223 .owner
= THIS_MODULE
,
2224 .of_match_table
= sensor_cis_imx333_match
,
2225 .suppress_bind_attrs
= true,
2227 .id_table
= sensor_cis_imx333_idt
2230 static int __init
sensor_cis_imx333_init(void)
2234 ret
= i2c_add_driver(&sensor_cis_imx333_driver
);
2236 err("failed to add %s driver: %d\n",
2237 sensor_cis_imx333_driver
.driver
.name
, ret
);
2241 late_initcall_sync(sensor_cis_imx333_init
);