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