-
Notifications
You must be signed in to change notification settings - Fork 1
/
gm7150.c
1110 lines (940 loc) · 25.4 KB
/
gm7150.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "generic_sensor.h"
#include <linux/moduleparam.h>
#include <linux/interrupt.h>
#include <linux/of_gpio.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include "gm7150.h"
static int version = KERNEL_VERSION(9,2,25);
module_param(version, int, S_IRUGO);
#if 0
#define DBG(x...) printk(KERN_INFO x)
#else
#define DBG(x...) do { } while (0)
#endif
static int debug = 7;
module_param(debug, int, S_IRUGO|S_IWUSR);
#define dprintk(level, fmt, arg...) do { \
if (debug >= level) \
printk(KERN_WARNING fmt, ## arg); \
} while (0)
#define debug_printk(format, ...) dprintk(1, format, ## __VA_ARGS__)
/* Sensor Driver Configuration Begin */
#define SENSOR_NAME RK29_CAM_SENSOR_GM7150
#define SENSOR_V4L2_IDENT V4L2_IDENT_GM7150
#define SENSOR_ID 0x71
#define SENSOR_BUS_PARAM (SOCAM_MASTER |\
SOCAM_PCLK_SAMPLE_RISING|\
SOCAM_HSYNC_ACTIVE_HIGH|\
SOCAM_VSYNC_ACTIVE_HIGH | \
SOCAM_DATA_ACTIVE_HIGH |\
SOCAM_DATAWIDTH_8 |\
SOCAM_MCLK_24MHZ)
static int SENSOR_PREVIEW_W = 720;
static int SENSOR_PREVIEW_H = 576;
static volatile v4l2_std_id std_last_g = V4L2_STD_PAL;
static struct rk_camera_device_signal_config dev_info[] = {
{
.type = RK_CAMERA_DEVICE_CVBS_PAL,
.code = V4L2_MBUS_FMT_UYVY8_2X8,
.crop = {
.top = 0,
.left = 0,
.width = 720,
.height = 576,
}
}
};
static struct rk_camera_device_defrect defrects[] = {
{
.width = 720,
.height = 480,
.defrect = {
.top = 2,
.left = 0,
.width = 720,
.height = 480,
},
.interface = "cvbs_ntsc"
},
{
.width = 720,
.height = 576,
.defrect = {
.top = 0,
.left = 0,
.width = 720,
.height = 576
},
.interface = "cvbs_pal"
},
};
static struct rk_camera_device_channel_info channel_infos = {
.channel_total = 1,
.default_id = 0,
.channel_info = {
"cvbs 1",
}
};
static char input_mode[10] = "PAL";
#define SENSOR_PREVIEW_FPS 30000 // 30fps
#define SENSOR_FULLRES_L_FPS 7500 // 7.5fps
#define SENSOR_FULLRES_H_FPS 7500 // 7.5fps
#define SENSOR_720P_FPS 0
#define SENSOR_1080P_FPS 0
#define SENSOR_REGISTER_LEN 1 // sensor register address bytes
#define SENSOR_VALUE_LEN 1 // sensor register value bytes
static unsigned int SensorConfiguration = (CFG_Effect | CFG_Scene);
static unsigned int SensorChipID[] = {SENSOR_ID};
/* Sensor Driver Configuration End */
#define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
#define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
#define SensorRegVal(a,b) CONS4(SensorReg,SENSOR_REGISTER_LEN,Val,SENSOR_VALUE_LEN)(a,b)
#define sensor_write(client,reg,v) CONS4(sensor_write_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
#define sensor_read(client,reg,v) CONS4(sensor_read_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
#define sensor_write_array generic_sensor_write_array
static void gm7150_reinit_parameter(v4l2_std_id std,
struct generic_sensor *sensor);
static void gm7150_send_uevent(struct generic_sensor *sensor);
struct sensor_parameter {
unsigned int PreviewDummyPixels;
unsigned int CaptureDummyPixels;
unsigned int preview_exposure;
unsigned short int preview_line_width;
unsigned short int preview_gain;
unsigned short int PreviewPclk;
unsigned short int CapturePclk;
char awb[6];
};
struct specific_sensor{
struct generic_sensor common_sensor;
//define user data below
struct sensor_parameter parameter;
};
static struct rk_sensor_reg sensor_check_id_data[] = {
SensorRegVal(0x80, 0x0),
SensorEnd
};
/* Sensor initial setting */
static struct rk_sensor_reg sensor_init_data[] = {
SensorEnd
};
/* Senor full resolution setting: recommand for capture */
static struct rk_sensor_reg sensor_fullres_lowfps_data[] = {
SensorEnd
};
/* Senor full resolution setting: recommand for video */
static struct rk_sensor_reg sensor_fullres_highfps_data[] = {
SensorEnd
};
/* Preview resolution setting*/
/* 1280x720 */
static struct rk_sensor_reg sensor_720p[] = {
SensorEnd
};
/* 1920x1080 */
static struct rk_sensor_reg sensor_1080p[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_softreset_data[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_preview_data[] = {
{0x03, 0x0d},
{0x11, 0x04},
{0x12, 0x00},
{0x13, 0x04},
{0x14, 0x00},
{0xa0, 0x55},
{0xa1, 0xaa},
{0x69, 0x40},
{0x6d, 0x90},
SensorEnd
};
static struct rk_sensor_reg sensor_WhiteB_Auto[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_WhiteB_Cloudy[] = {
SensorEnd
};
/* ClearDay Colour Temperature : 5000K - 6500K */
static struct rk_sensor_reg sensor_WhiteB_ClearDay[] = {
SensorEnd
};
/* Office Colour Temperature : 3500K - 5000K */
static struct rk_sensor_reg sensor_WhiteB_TungstenLamp1[] = {
SensorEnd
};
/* Home Colour Temperature : 2500K - 3500K */
static struct rk_sensor_reg sensor_WhiteB_TungstenLamp2[] = {
SensorEnd
};
static struct rk_sensor_reg *sensor_WhiteBalanceSeqe[] = {
sensor_WhiteB_Auto,
sensor_WhiteB_TungstenLamp1,
sensor_WhiteB_TungstenLamp2,
sensor_WhiteB_ClearDay,
sensor_WhiteB_Cloudy,
NULL,
};
static struct rk_sensor_reg sensor_Brightness0[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Brightness1[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Brightness2[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Brightness3[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Brightness4[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Brightness5[] = {
SensorEnd
};
static struct rk_sensor_reg *sensor_BrightnessSeqe[] = {
sensor_Brightness0,
sensor_Brightness1,
sensor_Brightness2,
sensor_Brightness3,
sensor_Brightness4,
sensor_Brightness5,
NULL,
};
static struct rk_sensor_reg sensor_Effect_Normal[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Effect_WandB[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Effect_Sepia[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Effect_Negative[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Effect_Bluish[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Effect_Green[] = {
SensorEnd
};
static struct rk_sensor_reg *sensor_EffectSeqe[] = {
sensor_Effect_Normal,
sensor_Effect_WandB,
sensor_Effect_Negative,
sensor_Effect_Sepia,
sensor_Effect_Bluish,
sensor_Effect_Green,
NULL,
};
static struct rk_sensor_reg sensor_Exposure0[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Exposure1[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Exposure2[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Exposure3[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Exposure4[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Exposure5[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Exposure6[] = {
SensorEnd
};
static struct rk_sensor_reg *sensor_ExposureSeqe[] = {
sensor_Exposure0,
sensor_Exposure1,
sensor_Exposure2,
sensor_Exposure3,
sensor_Exposure4,
sensor_Exposure5,
sensor_Exposure6,
NULL,
};
static struct rk_sensor_reg sensor_Saturation0[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Saturation1[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Saturation2[] = {
SensorEnd
};
static struct rk_sensor_reg *sensor_SaturationSeqe[] = {
sensor_Saturation0,
sensor_Saturation1,
sensor_Saturation2,
NULL,
};
static struct rk_sensor_reg sensor_Contrast0[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Contrast1[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Contrast2[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Contrast3[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Contrast4[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Contrast5[] = {
SensorEnd
};
static struct rk_sensor_reg sensor_Contrast6[] = {
SensorEnd
};
static struct rk_sensor_reg *sensor_ContrastSeqe[] = {
sensor_Contrast0,
sensor_Contrast1,
sensor_Contrast2,
sensor_Contrast3,
sensor_Contrast4,
sensor_Contrast5,
sensor_Contrast6,
NULL,
};
static struct rk_sensor_reg sensor_SceneAuto[] =
{
SensorEnd
};
static struct rk_sensor_reg sensor_SceneNight[] =
{
SensorEnd
};
static struct rk_sensor_reg *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
static struct rk_sensor_reg sensor_Zoom0[] =
{
SensorEnd
};
static struct rk_sensor_reg sensor_Zoom1[] =
{
SensorEnd
};
static struct rk_sensor_reg sensor_Zoom2[] =
{
SensorEnd
};
static struct rk_sensor_reg sensor_Zoom3[] =
{
SensorEnd
};
static struct rk_sensor_reg *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
/*
* User could be add v4l2_querymenu in sensor_controls by new_usr_v4l2menu
*/
static struct v4l2_querymenu sensor_menus[] =
{
};
/*
* User could be add v4l2_queryctrl in sensor_controls by new_user_v4l2ctrl
*/
static inline int gm7150_channel_set(struct i2c_client *client,
struct sensor_v4l2ctrl_info_s *ctrl_info,
struct v4l2_ext_control *ext_ctrl)
{
struct generic_sensor *sensor = to_generic_sensor(client);
struct rk_sensor_sequence *sensor_series =
sensor->info_priv.sensor_series;
int series_num = sensor->info_priv.num_series;
int ret = 0;
int i;
int id;
int channel_ain;
DBG("\n====%s\n",__FUNCTION__);
if ((ext_ctrl->value < ctrl_info->qctrl->minimum) ||
(ext_ctrl->value > ctrl_info->qctrl->maximum)) {
SENSOR_TR("%s(%d):channel(%d) is not support\n",__func__, __LINE__, ext_ctrl->value);
ret = -EINVAL;
goto end;
}
if (sensor->channel_id != ext_ctrl->value) {
SENSOR_TR("%s(%d):set channel(%d)!\n", __func__, __LINE__, ext_ctrl->value);
sensor->channel_id = ext_ctrl->value;
id = sensor->channel_id;
for (i = 0; i < series_num; i++)
if ((sensor_series[i].property == SEQUENCE_PREVIEW) && (sensor_series[i].data[0].reg != SEQCMD_END))
break;
if (strstr(channel_infos.channel_info[id], "cvbs")) {
ret = sscanf(channel_infos.channel_info[id], "%*s %d",&channel_ain);
if (IS_ERR_VALUE(ret)) {
SENSOR_TR("%s(%d): channel_infos err!\n", __func__, __LINE__);
ret = -EINVAL;
goto end;
}
sensor_series[i].data = sensor_preview_data;
sensor->info_priv.dev_sig_cnf.type = RK_CAMERA_DEVICE_CVBS_NTSC;
sensor->info_priv.dev_sig_cnf.code =V4L2_MBUS_FMT_UYVY8_2X8;
gm7150_reinit_parameter(V4L2_STD_NTSC, sensor);
}
generic_sensor_write_array(client, sensor_series[i].data);
}
end:
return ret;
}
static inline int sensor_v4l2ctrl_inside_cb(struct soc_camera_device *icd,
struct sensor_v4l2ctrl_info_s *ctrl_info,
struct v4l2_ext_control *ext_ctrl,
bool is_set)
{
struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
struct generic_sensor *sensor = to_generic_sensor(client);
int ret = 0;
DBG("\n====%s\n",__FUNCTION__);
switch (ctrl_info->qctrl->id) {
case V4L2_CID_DEINTERLACE:
{
if (is_set) {
SENSOR_TR("deinterlace isn't support set!\n");
ret = -EINVAL;
goto cb_end;
} else {
if ((RK_CAMERA_DEVICE_BT601_8 == sensor->info_priv.dev_sig_cnf.type)) {
/* don't need deinterlace process */
ext_ctrl->value = 0;
ctrl_info->cur_value = 0;
} else {
ext_ctrl->value = 1;
ctrl_info->cur_value = 1;
}
}
break;
}
case V4L2_CID_CHANNEL:
{
if (is_set) {
ret = gm7150_channel_set(client, ctrl_info, ext_ctrl);
if (ret)
goto cb_end;
} else {
ext_ctrl->value = sensor->channel_id;
ctrl_info->cur_value = sensor->channel_id;
}
break;
}
case V4L2_CID_BRIGHTNESS:
{
sensor_write(client, GM7150_REG_BRIGHTNESS, ext_ctrl->value);
break;
}
case V4L2_CID_CONTRAST:
{
sensor_write(client, GM7150_REG_CONTRAST, ext_ctrl->value);
break;
}
case V4L2_CID_SATURATION:
{
sensor_write(client, GM7150_REG_SATURATION, ext_ctrl->value);
break;
}
case V4L2_CID_HUE:
{
sensor_write(client, GM7150_REG_HUE, ext_ctrl->value);
break;
}
default:
{
SENSOR_TR("%s(%d): cmd(0x%x) is unknown !\n",__func__, __LINE__, ctrl_info->qctrl->id);
ret = -EINVAL;
}
}
cb_end:
return ret;
}
static struct sensor_v4l2ctrl_usr_s sensor_controls[] = {
{
{
V4L2_CID_DEINTERLACE,
V4L2_CTRL_TYPE_BOOLEAN,
"deinterlace",
0,
1,
1,
0
},
sensor_v4l2ctrl_inside_cb,
NULL
},
{
{
V4L2_CID_CHANNEL,
V4L2_CTRL_TYPE_INTEGER,
"channel",
0,
4,
1,
0
},
sensor_v4l2ctrl_inside_cb,
NULL
},
{
{
V4L2_CID_BRIGHTNESS,
V4L2_CTRL_TYPE_INTEGER,
"brightness",
0,
255,
1,
128
},
sensor_v4l2ctrl_inside_cb,
NULL
},
{
{
V4L2_CID_CONTRAST,
V4L2_CTRL_TYPE_INTEGER,
"contrast",
0,
255,
1,
128
},
sensor_v4l2ctrl_inside_cb,
NULL
},
{
{
V4L2_CID_SATURATION,
V4L2_CTRL_TYPE_INTEGER,
"saturation",
0,
255,
1,
128
},
sensor_v4l2ctrl_inside_cb,
NULL
},
{
{
V4L2_CID_HUE,
V4L2_CTRL_TYPE_INTEGER,
"hue",
-128,
127,
1,
0
},
sensor_v4l2ctrl_inside_cb,
NULL
},
};
//MUST define the current used format as the first item
static struct rk_sensor_datafmt sensor_colour_fmts[] = {
{V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
{V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
};
//static struct soc_camera_ops sensor_ops;
/*
**********************************************************
* Following is local code:
*
* Please codeing your program here
**********************************************************
*/
static int sensor_parameter_record(struct i2c_client *client)
{
DBG("\n====%s\n",__FUNCTION__);
return 0;
}
static int sensor_ae_transfer(struct i2c_client *client)
{
DBG("\n====%s\n",__FUNCTION__);
return 0;
}
static void gm7150_reinit_parameter(v4l2_std_id std,
struct generic_sensor *sensor)
{
struct rk_sensor_sequence *series = sensor->info_priv.sensor_series;
int num_series = sensor->info_priv.num_series;
int i;
switch (std) {
case V4L2_STD_NTSC:
case V4L2_STD_NTSC_443:
SENSOR_PREVIEW_W = 720;
SENSOR_PREVIEW_H = 480;
sensor->info_priv.dev_sig_cnf.type = RK_CAMERA_DEVICE_CVBS_NTSC;
sensor->info_priv.dev_sig_cnf.code =V4L2_MBUS_FMT_UYVY8_2X8;
strcpy(input_mode, "NTSC");
break;
case V4L2_STD_PAL:
case V4L2_STD_PAL_M:
case V4L2_STD_PAL_60:
SENSOR_PREVIEW_W = 720;
SENSOR_PREVIEW_H = 576;
sensor->info_priv.dev_sig_cnf.type = RK_CAMERA_DEVICE_CVBS_PAL;
sensor->info_priv.dev_sig_cnf.code =V4L2_MBUS_FMT_UYVY8_2X8;
strcpy(input_mode, "PAL");
break;
default:
SENSOR_PREVIEW_W = 720;
SENSOR_PREVIEW_H = 576;
sensor->info_priv.dev_sig_cnf.type = RK_CAMERA_DEVICE_CVBS_NTSC;
sensor->info_priv.dev_sig_cnf.code =V4L2_MBUS_FMT_UYVY8_2X8;
strcpy(input_mode, "YUV");
break;
}
for (i = 0; i < ARRAY_SIZE(defrects); i++) {
if ((defrects[i].width == SENSOR_PREVIEW_W) &&
(defrects[i].height == SENSOR_PREVIEW_H)) {
SENSOR_PREVIEW_W = defrects[i].defrect.width;
SENSOR_PREVIEW_H = defrects[i].defrect.height;
printk("=============match %dx%d\n", SENSOR_PREVIEW_W, SENSOR_PREVIEW_H);
memcpy(&sensor->info_priv.dev_sig_cnf.crop,&defrects[i].defrect,sizeof(defrects[i].defrect));
if (!defrects[i].interface) {
SENSOR_TR("%s(%d): interface is NULL\n",
__func__, __LINE__);
printk("=============continue\n");
continue;
}
SENSOR_TR("%s(%d): type 0x%x\n", __func__, __LINE__,sensor->info_priv.dev_sig_cnf.type);
}
}
/*update sensor info_priv*/
for (i = 0; i < num_series; i++) {
series[i].gSeq_info.w = SENSOR_PREVIEW_W;
series[i].gSeq_info.h = SENSOR_PREVIEW_H;
}
generic_sensor_get_max_min_res(sensor->info_priv.sensor_series,sensor->info_priv.num_series,&(sensor->info_priv.max_real_res),&(sensor->info_priv.max_res),&(sensor->info_priv.min_res));
printk("===========max_res.h=%d, max_res.w=%d ,max_real_res.h=%d, max_real_res.w=%d ,\n", sensor->info_priv.max_res.h, sensor->info_priv.max_res.w, sensor->info_priv.max_real_res.h, sensor->info_priv.max_real_res.w );
}
static void gm7150_send_uevent(struct generic_sensor *sensor)
{
char *event_msg = NULL;
char *envp[2];
DBG("\n====%s\n",__FUNCTION__);
event_msg = kasprintf(GFP_KERNEL,
"CVBS_NAME=GM7150 NOW_INPUT_MODE=%s RESOLUTION=%dx%d",
input_mode, SENSOR_PREVIEW_W, SENSOR_PREVIEW_H);
SENSOR_TR("%s(%d): event_msg: %s\n", __func__, __LINE__, event_msg);
envp[0] = event_msg;
envp[1] = NULL;
kobject_uevent_env(&(sensor->subdev.v4l2_dev->dev->kobj),KOBJ_CHANGE, envp);
}
static v4l2_std_id gm7150_std_to_v4l2(u8 status1)
{
/* in case V4L2_IN_ST_NO_SIGNAL */
if (!status1)
return V4L2_STD_UNKNOWN;
switch (status1 & GM7150_STATUS5_AUTOD_MASK) {
case GM7150_STATUS5_AUTOD_NTSC_M_J:
return V4L2_STD_NTSC;
case GM7150_STATUS5_AUTOD_NTSC_4_43:
return V4L2_STD_NTSC_443;
case GM7150_STATUS5_AUTOD_PAL_M:
return V4L2_STD_PAL_M;
case GM7150_STATUS5_AUTOD_PAL_B_D_N:
return V4L2_STD_PAL;
case GM7150_STATUS5_AUTOD_SECAM:
return V4L2_STD_SECAM;
default:
return V4L2_STD_UNKNOWN;
}
}
static u32 gm7150_status_to_v4l2(u8 status1)
{
if (!(status1 & GM7150_STATUS5_IN_LOCK))
return V4L2_IN_ST_NO_SIGNAL;
return 0;
}
static int gm7150_status(struct i2c_client *client, u32 *status,
v4l2_std_id *std)
{
unsigned char status1 = 0;
int ret = 0;
ret = sensor_read(client, GM7150_STATUS5_REG, &status1);
if (IS_ERR_VALUE(ret)) {
SENSOR_TR("%s(%d): register read failed: 0x%x\n",__func__, __LINE__, GM7150_STATUS5_REG);
return status1;
}
if (status1 < 0)
return status1;
if (status)
*status = gm7150_status_to_v4l2(status1);
if (std)
*std = gm7150_std_to_v4l2(status1);
return 0;
}
#define VIDEO_SIGNAL 1
#define VIDEO_NOSIGAL 0
static struct i2c_client *mClientSignal;
int gm7150_check_signal(struct i2c_client *client,bool isCheck)
{
int nRet = -EINVAL, i ;
unsigned char status;
int state = VIDEO_NOSIGAL;
struct generic_sensor *sensor;
struct rk_sensor_sequence *sensor_series;
int series_num;
if (!client)
return nRet;
sensor = to_generic_sensor(client);
sensor_series = sensor->info_priv.sensor_series;
series_num = sensor->info_priv.num_series;
for( i = 0; i < series_num ;i++){
if((sensor_series[i].property == SEQUENCE_INIT)&&(sensor_series[i].data[0].reg != SEQCMD_END ))
break;
}
nRet = sensor_read(client, GM7150_STATUS_REG_1, &status);
if(IS_ERR_VALUE(nRet)){
printk("\n status0 failed = 0x%x\n",status);
}
if((status & 0x06) == 0x06){
state = VIDEO_SIGNAL;
sensor->info_priv.video_state = RK_CAM_INPUT_VIDEO_STATE_LOCKED;
}
else{
state = VIDEO_NOSIGAL;
sensor->info_priv.video_state = RK_CAM_INPUT_VIDEO_STATE_LOSS;
}
return state;
}
typedef int (*fn_cselect_t)(int channel);
typedef unsigned char (*fn_csignal_t)(void);
void register_cselect_fn(fn_cselect_t cselect);
void register_csignal_fn(fn_csignal_t csignal);
#define CVBS_BACK 5
static int gm7150_channel_select(int channel)
{
int rval;
int val;
if (!mClientSignal) {
return -1;
}
val = CVBS_BACK==channel?0x0:0x2;
sensor_preview_data[0].val = val;
rval = sensor_write(mClientSignal, GM7150_VD_IN_SRC_SEL_1, val);
return rval;
}
static unsigned char gm7150_readSignalStatus(void)
{
unsigned char nTemp ;
nTemp = gm7150_check_signal(mClientSignal,true);
return nTemp;
}
/*
* the function is called in open sensor
*/
static int sensor_activate_cb(struct i2c_client *client)
{
struct generic_sensor *sensor = to_generic_sensor(client);
v4l2_std_id std;
mClientSignal = client;
register_csignal_fn(gm7150_readSignalStatus);
register_cselect_fn(gm7150_channel_select);
std = std_last_g;
gm7150_status(client, NULL, &std);
gm7150_reinit_parameter(std, sensor);
gm7150_send_uevent(sensor);
if (std_last_g != std) {
pr_info("STD changed 0x%llx -> 0x%llx\n", std_last_g, std);
std_last_g = std;
}
// sensor->info_priv.video_state = RK_CAM_INPUT_VIDEO_STATE_LOCKED;
if (sensor->state_check_work.state_check_wq) {
SENSOR_DG("sensor_activate_cb: queue_delayed_work 1000ms\n");
printk("sensor_activate_cb: queue_delayed_work 1000ms\n");
queue_delayed_work(sensor->state_check_work.state_check_wq,&sensor->state_check_work.work,200);
}
return 0;
}
/*
* the function is called in close sensor
*/
static int sensor_deactivate_cb(struct i2c_client *client)
{
int ret = 0;
struct generic_sensor *sensor = to_generic_sensor(client);
ret = cancel_delayed_work_sync(&sensor->state_check_work.work);
return ret;
}
/*
* the function is called before sensor register setting in VIDIOC_S_FMT
*/
static int sensor_s_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
{
if (capture) {
sensor_parameter_record(client);
}
return 0;
}
/*
* the function is called after sensor register setting finished in VIDIOC_S_FMT
*/
static int sensor_s_fmt_cb_bh (struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
{
printk("%s, fmt.width=%u, fmt.height=%u, code=%u, field=%u, colorspace=%u\n", __FUNCTION__, mf->width, mf->height, mf->code, mf->field, mf->colorspace);
if (capture) {
sensor_ae_transfer(client);
}
return 0;
}
static int sensor_try_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf)
{
return 0;
}
static int sensor_softrest_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
{
return 0;
}
static int sensor_check_id_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
{
return 0;
}
static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
{
//struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
if (pm_msg.event == PM_EVENT_SUSPEND) {
DBG("Suspend\n");
} else {
SENSOR_TR("pm_msg.event(0x%x) != PM_EVENT_SUSPEND\n",pm_msg.event);
return -EINVAL;
}
return 0;
}
static int sensor_resume(struct soc_camera_device *icd)
{
printk("\n====%s\n",__FUNCTION__);
return 0;
}
static int sensor_mirror_cb (struct i2c_client *client, int mirror)
{
return 0;
}
/*
* the function is v4l2 control V4L2_CID_HFLIP callback
*/
static int sensor_v4l2ctrl_mirror_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info,
struct v4l2_ext_control *ext_ctrl)
{
return 0;
}
static int sensor_flip_cb(struct i2c_client *client, int flip)
{
return 0;
}
/*
* the function is v4l2 control V4L2_CID_VFLIP callback
*/
static int sensor_v4l2ctrl_flip_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info,
struct v4l2_ext_control *ext_ctrl)
{
return 0;
}
/*
* the functions are focus callbacks
*/
static int sensor_focus_init_usr_cb(struct i2c_client *client){
printk("\n====%s\n",__FUNCTION__);
return 0;
}
static int sensor_focus_af_single_usr_cb(struct i2c_client *client){
printk("\n====%s\n",__FUNCTION__);
return 0;
}
static int sensor_focus_af_near_usr_cb(struct i2c_client *client){
printk("\n====%s\n",__FUNCTION__);
return 0;
}