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