2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(0, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_GC2015
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_GC2015
48 #define SENSOR_ID 0x2005
49 #define SENSOR_MIN_WIDTH 640
50 #define SENSOR_MIN_HEIGHT 480
51 #define SENSOR_MAX_WIDTH 1600
52 #define SENSOR_MAX_HEIGHT 1200
53 #define SENSOR_INIT_WIDTH 800//1024 /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT 600//768
55 #define SENSOR_INIT_WINSEQADR sensor_svga
56 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
58 #define CONFIG_SENSOR_WhiteBalance 1
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 1
63 #define CONFIG_SENSOR_Scene 1
64 #define CONFIG_SENSOR_DigitalZoom 0
65 #define CONFIG_SENSOR_Focus 0
66 #define CONFIG_SENSOR_Exposure 0
67 #define CONFIG_SENSOR_Flash 1
68 #define CONFIG_SENSOR_Mirror 0
69 #define CONFIG_SENSOR_Flip 0
71 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
72 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
73 #define CONFIG_SENSOR_I2C_NOSCHED 0
74 #define CONFIG_SENSOR_I2C_RDWRCHK 0
76 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|\
77 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
78 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
80 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
81 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
82 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
83 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
84 #define COLOR_TEMPERATURE_OFFICE_DN 3500
85 #define COLOR_TEMPERATURE_OFFICE_UP 5000
86 #define COLOR_TEMPERATURE_HOME_DN 2500
87 #define COLOR_TEMPERATURE_HOME_UP 3500
89 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
90 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
92 #define SENSOR_AF_IS_ERR (0x00<<0)
93 #define SENSOR_AF_IS_OK (0x01<<0)
94 #define SENSOR_INIT_IS_ERR (0x00<<28)
95 #define SENSOR_INIT_IS_OK (0x01<<28)
103 //flash off in fixed time to prevent from too hot , zyc
105 struct soc_camera_device *icd;
106 struct hrtimer timer;
108 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
110 static struct flash_timer flash_off_timer;
111 //for user defined if user want to customize the series , zyc
112 #ifdef CONFIG_GC2015_USER_DEFINED_SERIES
113 #include "gc2015_user_series.c"
115 /* init SVGA preview */
116 static struct reginfo sensor_init_data[] =
119 {0xfe, 0x80}, //soft reset
120 {0xfe, 0x80}, //soft reset
121 {0xfe, 0x80}, //soft reset
123 {0xfe, 0x00}, //page0
124 {0x45, 0x00}, //output_disable
126 //////////////////////////////////////////////////////////////////////////////////////
127 //////////////////////////preview capture switch /////////////////////////////////////
128 //////////////////////////////////////////////////////////////////////////////////////
130 {0x02, 0x01}, //preview mode
131 {0x2a, 0xca}, //[7]col_binning, 0x[6]even skip
132 {0x48, 0x40}, //manual_gain
134 ////////////////////////////////////////////////////////////////////////
135 ////////////////////////// preview LSC /////////////////////////////////
136 ////////////////////////////////////////////////////////////////////////
137 {0xfe, 0x01}, //page1
138 {0xb0, 0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
139 {0xb1, 0x46}, //P_LSC_red_b2
140 {0xb2, 0x40}, //P_LSC_green_b2
141 {0xb3, 0x40}, //P_LSC_blue_b2
142 {0xb4, 0x24}, //P_LSC_red_b4
143 {0xb5, 0x20}, //P_LSC_green_b4
144 {0xb6, 0x22}, //P_LSC_blue_b4
145 {0xb7, 0x00}, //P_LSC_compensate_b2
146 {0xb8, 0x80}, //P_LSC_row_center, 0x344, 0x (1200/2-344)/2=128, 0x, 0x
147 {0xb9, 0x80}, //P_LSC_col_center, 0x544, 0x (1600/2-544)/2=128
150 ////////////////////////////////////////////////////////////////////////
151 ////////////////////////// capture LSC /////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////
153 {0xba, 0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
154 {0xbb, 0x46}, //C_LSC_red_b2
155 {0xbc, 0x40}, //C_LSC_green_b2
156 {0xbd, 0x40}, //C_LSC_blue_b2
157 {0xbe, 0x24}, //C_LSC_red_b4
158 {0xbf, 0x20}, //C_LSC_green_b4
159 {0xc0, 0x22}, //C_LSC_blue_b4
160 {0xc1, 0x00}, //C_Lsc_compensate_b2
161 {0xc2, 0x80}, //C_LSC_row_center, 0x344, 0x (1200/2-344)/2=128
162 {0xc3, 0x80}, //C_LSC_col_center, 0x544, 0x (1600/2-544)/2=128
163 {0xfe, 0x00}, //page0
165 ////////////////////////////////////////////////////////////////////////
166 ////////////////////////// analog configure ///////////////////////////
167 ////////////////////////////////////////////////////////////////////////
168 {0xfe, 0x00}, //page0
169 {0x29, 0x00}, //cisctl mode 1
170 {0x2b, 0x06}, //cisctl mode 3
171 {0x32, 0x1c}, //analog mode 1
172 {0x33, 0x0f}, //analog mode 2
173 {0x34, 0x30}, //[6:4]da_rsg
175 {0x35, 0x88}, //Vref_A25
176 {0x37, 0x16}, //Drive Current
178 /////////////////////////////////////////////////////////////////////
179 /////////////////////////// ISP Related /////////////////////////////
180 /////////////////////////////////////////////////////////////////////
182 {0x41, 0x20}, //[5]skin_detectionenable[2]auto_gray, 0x[1]y_gamma
183 {0x42, 0xf6}, //[7]auto_sa[6]auto_ee[5]auto_dndd[4]auto_lsc[3]na[2]abs, 0x[1]awb
184 {0x4b, 0xe8}, //[1]AWB_gain_mode, 0x1:atpregain0:atpostgain
185 {0x4d, 0x03}, //[1]inbf_en
186 {0x4f, 0x01}, //AEC enable
188 ////////////////////////////////////////////////////////////////////
189 /////////////////////////// BLK //////////////////////////////////
190 ////////////////////////////////////////////////////////////////////
191 {0x63, 0x77}, //BLK mode 1
192 {0x66, 0x00}, //BLK global offset
194 {0x6e, 0x1a}, //BLK offset submode,offset R
203 ////////////////////////////////////////////////////////////////////
204 /////////////////////////// DNDD ///////////////////////////////////
205 ////////////////////////////////////////////////////////////////////
206 {0x80, 0x07}, //[7]dn_inc_or_dec [4]zero_weight_mode[3]share [2]c_weight_adap [1]dn_lsc_mode [0]dn_b
207 {0x82, 0x0c}, //DN lilat b base
210 ////////////////////////////////////////////////////////////////////
211 /////////////////////////// EEINTP ////////////////////////////////
212 ////////////////////////////////////////////////////////////////////
219 /////////////////////////////////////////////////////////////////////
220 /////////////////////////// CC_t ////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////
222 {0xb0, 0x40}, // 0x48
233 /////////////////////////////////////////////////////////////////////
234 /////////////////////////// GAMMA ///////////////////////////////////
235 /////////////////////////////////////////////////////////////////////
273 /////////////////////////////////////////////////////////////////////
274 /////////////////////////// YCP_t ///////////////////////////////////
275 /////////////////////////////////////////////////////////////////////
276 {0xd1, 0x40}, //saturation 38
277 {0xd2, 0x40}, //saturation 38
279 {0xd3, 0x46}, // 2011-08-11 kim add
281 {0xde, 0x21}, //auto_gray
283 ////////////////////////////////////////////////////////////////////
284 /////////////////////////// ASDE ///////////////////////////////////
285 ////////////////////////////////////////////////////////////////////
293 {0xfe, 0x01}, //page1
299 ////////////////////////////////////////////////////////////////////
300 /////////////////////////// AEC ////////////////////////////////////
301 ////////////////////////////////////////////////////////////////////
302 {0x10, 0x09}, //AEC mode 1
303 {0x11, 0x92}, //[7]fix target // 0xb2 2011-08-11 kim
305 {0x13, 0x78}, // 0x78 2011-08-11 kim
308 {0x1d, 0x04}, // sunlight step
310 {0x21, 0xc0}, //max_post_gain
311 {0x22, 0x40}, //max_pre_gain // 0x60 2011-08-11 kim
312 {0x2d, 0x06}, //P_N_AEC_exp_level_1[12:8]
313 {0x2e, 0x00}, //P_N_AEC_exp_level_1[7:0]
315 {0x33, 0x00}, //[6:5]max_exp_level [4:0]min_exp_level
316 {0x34, 0x04}, // min exp
318 ////////////////////////////////////////////////////////////////////
319 /////////////////////////// Measure Window /////////////////////////
320 ////////////////////////////////////////////////////////////////////
326 ////////////////////////////////////////////////////////////////////
327 /////////////////////////// AWB ////////////////////////////////////
328 ////////////////////////////////////////////////////////////////////
329 {0x57, 0x40}, //number limit
331 {0x5c, 0x35}, //show mode,close dark_mode
332 {0x5e, 0x29}, //close color temp
336 ////////////////////////////////////////////////////////////////////
337 /////////////////////////// ABS ////////////////////////////////////
338 ////////////////////////////////////////////////////////////////////
344 {0x83, 0x10}, //ABS Y stretch limit
346 ////////////////////////////////////////////////////////////////////
347 /////////////////////////// OUT ////////////////////////////////////
348 ////////////////////////////////////////////////////////////////////
361 {0x44, 0xa0}, //YUV sequence
362 {0x45, 0x0f}, //output enable
363 {0x46, 0x02}, //sync mode
389 {0x29, 0x00},//Anti Step 128
392 {0x2b, 0x05},//Level_0 10.00fps
394 {0x2d, 0x06},//Level_1 8.33fps
396 {0x2f, 0x08},//Level_2 6.25fps
398 {0x31, 0x09},//Level_3 5.55fps
403 //--------------------Updated By Mormo 2011/08/08 Start --------------------//
407 //--------------------Updated By Mormo 2011/08/08 End ---------------------//
416 /* 1600X1200 UXGA capture */
417 static struct reginfo sensor_uxga[] =
423 {0x4f, 0x00}, // aec off
454 static struct reginfo sensor_sxga[] =
460 {0x4f, 0x00}, // aec off
490 static struct reginfo sensor_xga[] =
496 {0x4f, 0x00}, // aec off
500 //subsample 1600x1200 to 1066x800
501 {0x59 , 0x33},//out window
512 {0x50 , 0x01},//out window
523 /* 800X600 SVGA,30fps*/
524 static struct reginfo sensor_svga[] =
529 {0x4f, 0x01}, // aec on
546 {0x50 , 0x01},//out window
559 static struct reginfo sensor_vga[] =
566 {0x4f, 0x01}, // aec on
572 {0x59 , 0x55},//out window
583 {0x50 , 0x01},//out window
592 {0x45 , 0x0f}, //output enable
597 static struct reginfo sensor_cif[] =
601 static struct reginfo sensor_qvga[] =
605 static struct reginfo sensor_qcif[] =
610 static struct reginfo ov2655_qqvga[] =
617 static struct reginfo ov2655_Sharpness_auto[] =
623 static struct reginfo ov2655_Sharpness1[] =
629 static struct reginfo ov2655_Sharpness2[][3] =
636 static struct reginfo ov2655_Sharpness3[] =
642 static struct reginfo ov2655_Sharpness4[]=
649 static struct reginfo ov2655_Sharpness5[] =
657 static struct reginfo sensor_ClrFmt_YUYV[]=
663 static struct reginfo sensor_ClrFmt_UYVY[]=
669 #if CONFIG_SENSOR_WhiteBalance
670 static struct reginfo sensor_WhiteB_Auto[]=
675 /* Cloudy Colour Temperature : 6500K - 8000K */
676 static struct reginfo sensor_WhiteB_Cloudy[]=
679 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
680 {0x7a , 0x8c}, //AWB_R_gain
681 {0x7b , 0x50}, //AWB_G_gain
682 {0x7c , 0x40}, //AWB_B_gain
685 /* ClearDay Colour Temperature : 5000K - 6500K */
686 static struct reginfo sensor_WhiteB_ClearDay[]=
689 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
690 {0x7a , 0x74}, //AWB_R_gain
691 {0x7b , 0x52}, //AWB_G_gain
692 {0x7c , 0x40}, //AWB_B_gain
695 /* Office Colour Temperature : 3500K - 5000K */
696 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
699 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
700 {0x7a , 0x48}, //AWB_R_gain
701 {0x7b , 0x40}, //AWB_G_gain
702 {0x7c , 0x5c}, //AWB_B_gain
706 /* Home Colour Temperature : 2500K - 3500K */
707 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
710 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
711 {0x7a , 0x40}, //AWB_R_gain
712 {0x7b , 0x54}, //AWB_G_gain
713 {0x7c , 0x70}, //AWB_B_gain
716 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
717 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
721 #if CONFIG_SENSOR_Brightness
722 static struct reginfo sensor_Brightness0[]=
727 {0x13, 0x68}, //AEC_target_Y
729 {0xd5, 0xe0},// Luma_offset
733 static struct reginfo sensor_Brightness1[]=
737 {0x13, 0x70}, //AEC_target_Y
739 {0xd5, 0xf0},// Luma_offset
744 static struct reginfo sensor_Brightness2[]=
749 {0x13, 0x78}, //AEC_target_Y 48
751 {0xd5, 0x00},// Luma_offset c0
756 static struct reginfo sensor_Brightness3[]=
760 {0x13, 0x80}, //AEC_target_Y
762 {0xd5, 0x10},// Luma_offset
767 static struct reginfo sensor_Brightness4[]=
771 {0x13, 0x88}, //AEC_target_Y
773 {0xd5, 0x20},// Luma_offset
778 static struct reginfo sensor_Brightness5[]=
782 {0x13, 0x90}, //AEC_target_Y
784 {0xd5, 0x30},// Luma_offset
787 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
788 sensor_Brightness4, sensor_Brightness5,NULL,
793 #if CONFIG_SENSOR_Effect
794 static struct reginfo sensor_Effect_Normal[] =
801 static struct reginfo sensor_Effect_WandB[] =
809 static struct reginfo sensor_Effect_Sepia[] =
817 static struct reginfo sensor_Effect_Negative[] =
825 static struct reginfo sensor_Effect_Bluish[] =
835 static struct reginfo sensor_Effect_Green[] =
843 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
844 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
847 #if CONFIG_SENSOR_Exposure
848 static struct reginfo sensor_Exposure0[]=
854 static struct reginfo sensor_Exposure1[]=
861 static struct reginfo sensor_Exposure2[]=
868 static struct reginfo sensor_Exposure3[]=
875 static struct reginfo sensor_Exposure4[]=
882 static struct reginfo sensor_Exposure5[]=
889 static struct reginfo sensor_Exposure6[]=
896 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
897 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
900 #if CONFIG_SENSOR_Saturation
901 static struct reginfo sensor_Saturation0[]=
907 static struct reginfo sensor_Saturation1[]=
913 static struct reginfo sensor_Saturation2[]=
918 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
921 #if CONFIG_SENSOR_Contrast
922 static struct reginfo sensor_Contrast0[]=
930 static struct reginfo sensor_Contrast1[]=
938 static struct reginfo sensor_Contrast2[]=
946 static struct reginfo sensor_Contrast3[]=
954 static struct reginfo sensor_Contrast4[]=
963 static struct reginfo sensor_Contrast5[]=
971 static struct reginfo sensor_Contrast6[]=
978 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
979 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
983 #if CONFIG_SENSOR_Mirror
984 static struct reginfo sensor_MirrorOn[]=
990 static struct reginfo sensor_MirrorOff[]=
995 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
997 #if CONFIG_SENSOR_Flip
998 static struct reginfo sensor_FlipOn[]=
1004 static struct reginfo sensor_FlipOff[]=
1009 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1012 #if CONFIG_SENSOR_Scene
1013 static struct reginfo sensor_SceneAuto[] =
1015 /* ddl@rock-chips.com : */
1024 static struct reginfo sensor_SceneNight[] =
1027 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1034 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1037 #if CONFIG_SENSOR_DigitalZoom
1038 static struct reginfo sensor_Zoom0[] =
1043 static struct reginfo sensor_Zoom1[] =
1048 static struct reginfo sensor_Zoom2[] =
1054 static struct reginfo sensor_Zoom3[] =
1058 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1060 static const struct v4l2_querymenu sensor_menus[] =
1062 #if CONFIG_SENSOR_WhiteBalance
1063 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1064 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1065 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1068 #if CONFIG_SENSOR_Effect
1069 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1070 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1071 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1074 #if CONFIG_SENSOR_Scene
1075 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1078 #if CONFIG_SENSOR_Flash
1079 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1080 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1084 static struct v4l2_queryctrl sensor_controls[] =
1086 #if CONFIG_SENSOR_WhiteBalance
1088 .id = V4L2_CID_DO_WHITE_BALANCE,
1089 .type = V4L2_CTRL_TYPE_MENU,
1090 .name = "White Balance Control",
1098 #if CONFIG_SENSOR_Brightness
1100 .id = V4L2_CID_BRIGHTNESS,
1101 .type = V4L2_CTRL_TYPE_INTEGER,
1102 .name = "Brightness Control",
1110 #if CONFIG_SENSOR_Effect
1112 .id = V4L2_CID_EFFECT,
1113 .type = V4L2_CTRL_TYPE_MENU,
1114 .name = "Effect Control",
1122 #if CONFIG_SENSOR_Exposure
1124 .id = V4L2_CID_EXPOSURE,
1125 .type = V4L2_CTRL_TYPE_INTEGER,
1126 .name = "Exposure Control",
1134 #if CONFIG_SENSOR_Saturation
1136 .id = V4L2_CID_SATURATION,
1137 .type = V4L2_CTRL_TYPE_INTEGER,
1138 .name = "Saturation Control",
1146 #if CONFIG_SENSOR_Contrast
1148 .id = V4L2_CID_CONTRAST,
1149 .type = V4L2_CTRL_TYPE_INTEGER,
1150 .name = "Contrast Control",
1158 #if CONFIG_SENSOR_Mirror
1160 .id = V4L2_CID_HFLIP,
1161 .type = V4L2_CTRL_TYPE_BOOLEAN,
1162 .name = "Mirror Control",
1170 #if CONFIG_SENSOR_Flip
1172 .id = V4L2_CID_VFLIP,
1173 .type = V4L2_CTRL_TYPE_BOOLEAN,
1174 .name = "Flip Control",
1182 #if CONFIG_SENSOR_Scene
1184 .id = V4L2_CID_SCENE,
1185 .type = V4L2_CTRL_TYPE_MENU,
1186 .name = "Scene Control",
1194 #if CONFIG_SENSOR_DigitalZoom
1196 .id = V4L2_CID_ZOOM_RELATIVE,
1197 .type = V4L2_CTRL_TYPE_INTEGER,
1198 .name = "DigitalZoom Control",
1204 .id = V4L2_CID_ZOOM_ABSOLUTE,
1205 .type = V4L2_CTRL_TYPE_INTEGER,
1206 .name = "DigitalZoom Control",
1214 #if CONFIG_SENSOR_Focus
1216 .id = V4L2_CID_FOCUS_RELATIVE,
1217 .type = V4L2_CTRL_TYPE_INTEGER,
1218 .name = "Focus Control",
1224 .id = V4L2_CID_FOCUS_ABSOLUTE,
1225 .type = V4L2_CTRL_TYPE_INTEGER,
1226 .name = "Focus Control",
1230 .default_value = 125,
1234 #if CONFIG_SENSOR_Flash
1236 .id = V4L2_CID_FLASH,
1237 .type = V4L2_CTRL_TYPE_MENU,
1238 .name = "Flash Control",
1247 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1248 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1249 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1250 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1251 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1252 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1253 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1254 static int sensor_resume(struct soc_camera_device *icd);
1255 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1256 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1257 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1258 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1259 static int sensor_deactivate(struct i2c_client *client);
1260 static int sensor_write(struct i2c_client *client, u8 reg, u8 val);
1261 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val);
1264 static u16 GC2015_read_shutter(struct i2c_client *client); // add 2011-08-11 kim
1265 static void GC2015_set_shutter(struct i2c_client *client, u16 shutter); // add 2011-08-11 kim
1268 ////// add 2011-08-11 kim
1269 static u16 GC2015_read_shutter(struct i2c_client *client)
1271 u8 temp_reg1, temp_reg2;
1274 /* Backup the preview mode last shutter & sensor gain. */
1275 sensor_read(client, 0x03, &temp_reg1);
1276 sensor_read(client, 0x04, &temp_reg2);
1278 shutter = (temp_reg1 << 8) | (temp_reg2 & 0xFF);
1281 } /* GC2015_read_shutter */
1283 static void GC2015_set_shutter(struct i2c_client *client, u16 shutter)
1287 temp_reg = shutter * 10 / 20; ////
1289 /*Set Shutter start*/
1290 if(temp_reg < 1) temp_reg = 1;
1291 sensor_write(client ,0x03 , (temp_reg>>8)&0xff);
1292 sensor_write(client ,0x04 , temp_reg&0xff);
1295 //////// end add kim
1297 static struct soc_camera_ops sensor_ops =
1299 .suspend = sensor_suspend,
1300 .resume = sensor_resume,
1301 .set_bus_param = sensor_set_bus_param,
1302 .query_bus_param = sensor_query_bus_param,
1303 .controls = sensor_controls,
1304 .menus = sensor_menus,
1305 .num_controls = ARRAY_SIZE(sensor_controls),
1306 .num_menus = ARRAY_SIZE(sensor_menus),
1309 /* only one fixed colorspace per pixelcode */
1310 struct sensor_datafmt {
1311 enum v4l2_mbus_pixelcode code;
1312 enum v4l2_colorspace colorspace;
1315 /* Find a data format by a pixel code in an array */
1316 static const struct sensor_datafmt *sensor_find_datafmt(
1317 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1321 for (i = 0; i < n; i++)
1322 if (fmt[i].code == code)
1328 static const struct sensor_datafmt sensor_colour_fmts[] = {
1329 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1330 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1333 typedef struct sensor_info_priv_s
1347 unsigned char mirror; /* HFLIP */
1348 unsigned char flip; /* VFLIP */
1349 unsigned int winseqe_cur_addr;
1350 struct sensor_datafmt fmt;
1351 unsigned int funmodule_state;
1352 } sensor_info_priv_t;
1356 struct v4l2_subdev subdev;
1357 struct i2c_client *client;
1358 sensor_info_priv_t info_priv;
1359 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1360 #if CONFIG_SENSOR_I2C_NOSCHED
1361 atomic_t tasklock_cnt;
1363 struct rk29camera_platform_data *sensor_io_request;
1364 struct rk29camera_gpio_res *sensor_gpio_res;
1367 static struct sensor* to_sensor(const struct i2c_client *client)
1369 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1372 static int sensor_task_lock(struct i2c_client *client, int lock)
1374 #if CONFIG_SENSOR_I2C_NOSCHED
1376 struct sensor *sensor = to_sensor(client);
1379 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1380 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1381 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1385 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1386 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1387 goto sensor_task_lock_err;
1392 atomic_add(1, &sensor->tasklock_cnt);
1394 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1395 atomic_sub(1, &sensor->tasklock_cnt);
1397 if (atomic_read(&sensor->tasklock_cnt) == 0)
1402 sensor_task_lock_err:
1411 /* sensor register */
1412 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1416 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1418 return (ret > 0)? 0 : ret;
1421 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1425 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1427 return (ret > 0)? 0 : ret;
1430 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1434 struct i2c_msg msg[1];
1442 msg->addr = client->addr;
1443 msg->flags = client->flags;
1445 msg->len = sizeof(buf);
1446 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1447 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1452 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1453 err = i2c_transfer(client->adapter, msg, 1);
1458 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1466 /* sensor register read */
1467 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1471 struct i2c_msg msg[2];
1475 msg[0].addr = client->addr;
1476 msg[0].flags = client->flags;
1478 msg[0].len = sizeof(buf);
1479 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1480 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1482 msg[1].addr = client->addr;
1483 msg[1].flags = client->flags|I2C_M_RD;
1486 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1487 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1491 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1492 err = i2c_transfer(client->adapter, msg, 2);
1498 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1508 /* write a array of registers */
1509 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1513 #if CONFIG_SENSOR_I2C_RDWRCHK
1518 if (sensor_task_lock(client, 1) < 0)
1519 goto sensor_write_array_end;
1520 while (regarray[i].reg != 0)
1522 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1526 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1530 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1532 goto sensor_write_array_end;
1535 #if CONFIG_SENSOR_I2C_RDWRCHK
1537 sensor_read(client, regarray[i].reg, &valchk);
1538 if (valchk != regarray[i].val)
1539 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1545 sensor_write_array_end:
1546 sensor_task_lock(client,0);
1549 #if CONFIG_SENSOR_I2C_RDWRCHK
1550 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1558 while (regarray[i].reg != 0)
1560 sensor_read(client, regarray[i].reg, &valchk);
1561 if (valchk != regarray[i].val)
1562 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1569 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1571 struct soc_camera_link *icl = to_soc_camera_link(icd);
1574 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1577 case Sensor_PowerDown:
1579 if (icl->powerdown) {
1580 ret = icl->powerdown(icd->pdev, on);
1581 if (ret == RK29_CAM_IO_SUCCESS) {
1585 icl->reset(icd->pdev);
1587 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1589 goto sensor_power_end;
1596 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1597 struct sensor *sensor = to_sensor(client);
1599 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1600 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1602 //flash off after 2 secs
1603 hrtimer_cancel(&(flash_off_timer.timer));
1604 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1611 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1619 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1620 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1621 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1622 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1626 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1628 struct i2c_client *client = v4l2_get_subdevdata(sd);
1629 struct soc_camera_device *icd = client->dev.platform_data;
1630 struct sensor *sensor = to_sensor(client);
1631 const struct v4l2_queryctrl *qctrl;
1632 const struct sensor_datafmt *fmt;
1636 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1638 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1640 goto sensor_INIT_ERR;
1644 if (sensor_task_lock(client,1)<0)
1645 goto sensor_INIT_ERR;
1646 ret = sensor_write(client, 0xfe, 0x80);
1649 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1651 goto sensor_INIT_ERR;
1654 mdelay(5); //delay 5 microseconds
1655 /* check if it is an sensor sensor */
1656 ret = sensor_read(client, 0x00, &value);
1658 SENSOR_TR("read chip id high byte failed\n");
1660 goto sensor_INIT_ERR;
1663 pid |= (value << 8);
1665 ret = sensor_read(client, 0x01, &value);
1667 SENSOR_TR("read chip id low byte failed\n");
1669 goto sensor_INIT_ERR;
1672 pid |= (value & 0xff);
1673 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1674 if (pid == SENSOR_ID) {
1675 sensor->model = SENSOR_V4L2_IDENT;
1677 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1679 goto sensor_INIT_ERR;
1682 ret = sensor_write_array(client, sensor_init_data);
1685 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1686 goto sensor_INIT_ERR;
1688 sensor_task_lock(client,0);
1690 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1691 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1693 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1695 goto sensor_INIT_ERR;
1697 sensor->info_priv.fmt = *fmt;
1699 /* sensor sensor information for initialization */
1700 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1702 sensor->info_priv.whiteBalance = qctrl->default_value;
1703 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1705 sensor->info_priv.brightness = qctrl->default_value;
1706 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1708 sensor->info_priv.effect = qctrl->default_value;
1709 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1711 sensor->info_priv.exposure = qctrl->default_value;
1713 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1715 sensor->info_priv.saturation = qctrl->default_value;
1716 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1718 sensor->info_priv.contrast = qctrl->default_value;
1719 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1721 sensor->info_priv.mirror = qctrl->default_value;
1722 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1724 sensor->info_priv.flip = qctrl->default_value;
1725 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1727 sensor->info_priv.scene = qctrl->default_value;
1728 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1730 sensor->info_priv.digitalzoom = qctrl->default_value;
1732 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1733 #if CONFIG_SENSOR_Focus
1735 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1737 sensor->info_priv.focus = qctrl->default_value;
1740 #if CONFIG_SENSOR_Flash
1741 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1743 sensor->info_priv.flash = qctrl->default_value;
1744 flash_off_timer.icd = icd;
1745 flash_off_timer.timer.function = flash_off_func;
1748 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),((val == 0)?__FUNCTION__:"sensor_reinit"),icd->user_width,icd->user_height);
1749 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1752 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1753 sensor_task_lock(client,0);
1754 sensor_deactivate(client);
1758 static int sensor_deactivate(struct i2c_client *client)
1760 struct soc_camera_device *icd = client->dev.platform_data;
1762 struct sensor *sensor = to_sensor(client);
1763 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1765 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1766 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1769 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1770 icd->user_width = SENSOR_INIT_WIDTH;
1771 icd->user_height = SENSOR_INIT_HEIGHT;
1772 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1777 static struct reginfo sensor_power_down_sequence[]=
1781 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1784 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1786 if (pm_msg.event == PM_EVENT_SUSPEND) {
1787 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1788 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1790 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1793 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1795 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1800 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1806 static int sensor_resume(struct soc_camera_device *icd)
1810 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1812 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1816 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1822 static int sensor_set_bus_param(struct soc_camera_device *icd,
1823 unsigned long flags)
1829 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1831 struct soc_camera_link *icl = to_soc_camera_link(icd);
1832 unsigned long flags = SENSOR_BUS_PARAM;
1834 return soc_camera_apply_sensor_flags(icl, flags);
1837 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1839 struct i2c_client *client = v4l2_get_subdevdata(sd);
1840 struct soc_camera_device *icd = client->dev.platform_data;
1841 struct sensor *sensor = to_sensor(client);
1843 mf->width = icd->user_width;
1844 mf->height = icd->user_height;
1845 mf->code = sensor->info_priv.fmt.code;
1846 mf->colorspace = sensor->info_priv.fmt.colorspace;
1847 mf->field = V4L2_FIELD_NONE;
1851 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1855 if ((mf->width == 1024) && (mf->height == 768)) {
1857 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1859 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1861 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1863 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1868 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1872 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1876 if ((mf->width == 1280) && (mf->height == 720)) {
1878 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1883 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1886 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1888 struct i2c_client *client = v4l2_get_subdevdata(sd);
1889 const struct sensor_datafmt *fmt;
1890 struct sensor *sensor = to_sensor(client);
1891 const struct v4l2_queryctrl *qctrl;
1892 struct soc_camera_device *icd = client->dev.platform_data;
1893 struct reginfo *winseqe_set_addr=NULL;
1894 int ret=0, set_w,set_h;
1898 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1899 ARRAY_SIZE(sensor_colour_fmts));
1902 goto sensor_s_fmt_end;
1905 if (sensor->info_priv.fmt.code != mf->code) {
1908 case V4L2_MBUS_FMT_YUYV8_2X8:
1910 winseqe_set_addr = sensor_ClrFmt_YUYV;
1913 case V4L2_MBUS_FMT_UYVY8_2X8:
1915 winseqe_set_addr = sensor_ClrFmt_UYVY;
1921 if (winseqe_set_addr != NULL) {
1922 sensor_write_array(client, winseqe_set_addr);
1923 sensor->info_priv.fmt.code = mf->code;
1924 sensor->info_priv.fmt.colorspace= mf->colorspace;
1925 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1927 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1934 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1936 winseqe_set_addr = sensor_qcif;
1940 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1942 winseqe_set_addr = sensor_qvga;
1946 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1948 winseqe_set_addr = sensor_cif;
1952 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1954 winseqe_set_addr = sensor_vga;
1958 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1960 winseqe_set_addr = sensor_svga;
1964 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1966 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1968 winseqe_set_addr = sensor_xga;
1972 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1974 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1976 winseqe_set_addr = sensor_sxga;
1980 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1983 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1985 winseqe_set_addr = sensor_uxga;
1991 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1992 set_w = SENSOR_INIT_WIDTH;
1993 set_h = SENSOR_INIT_HEIGHT;
1994 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1997 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1998 #if CONFIG_SENSOR_Flash
1999 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2000 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2001 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2002 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2004 } else { /* ddl@rock-chips.com : Video */
2005 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2006 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2007 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2011 ret |= sensor_write_array(client, winseqe_set_addr);
2013 if(set_w >= 1024) GC2015_set_shutter(client, gc2015_shutter); // add 2011-08-11 kim
2016 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2017 #if CONFIG_SENSOR_Flash
2018 if (sensor_fmt_capturechk(sd,mf) == true) {
2019 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2020 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2021 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2025 goto sensor_s_fmt_end;
2028 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2030 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2031 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2032 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2033 if (sensor->info_priv.whiteBalance != 0) {
2034 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2035 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2037 sensor->info_priv.snap2preview = true;
2038 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2039 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2040 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2041 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2042 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2043 sensor->info_priv.video2preview = true;
2044 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2045 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2046 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2047 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2048 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2049 sensor->info_priv.video2preview = false;
2050 sensor->info_priv.snap2preview = false;
2052 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2056 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2066 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2068 struct i2c_client *client = v4l2_get_subdevdata(sd);
2069 struct sensor *sensor = to_sensor(client);
2070 const struct sensor_datafmt *fmt;
2071 int ret = 0,set_w,set_h;
2073 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2074 ARRAY_SIZE(sensor_colour_fmts));
2076 fmt = &sensor->info_priv.fmt;
2077 mf->code = fmt->code;
2080 if (mf->height > SENSOR_MAX_HEIGHT)
2081 mf->height = SENSOR_MAX_HEIGHT;
2082 else if (mf->height < SENSOR_MIN_HEIGHT)
2083 mf->height = SENSOR_MIN_HEIGHT;
2085 if (mf->width > SENSOR_MAX_WIDTH)
2086 mf->width = SENSOR_MAX_WIDTH;
2087 else if (mf->width < SENSOR_MIN_WIDTH)
2088 mf->width = SENSOR_MIN_WIDTH;
2093 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2098 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2103 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2108 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2113 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2118 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
2123 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2128 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2135 set_w = SENSOR_INIT_WIDTH;
2136 set_h = SENSOR_INIT_HEIGHT;
2140 mf->colorspace = fmt->colorspace;
2145 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2147 struct i2c_client *client = v4l2_get_subdevdata(sd);
2149 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2152 if (id->match.addr != client->addr)
2155 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2160 #if CONFIG_SENSOR_Brightness
2161 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2163 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2165 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2167 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2169 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2171 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2174 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2178 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2182 #if CONFIG_SENSOR_Effect
2183 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2185 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2187 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2189 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2191 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2193 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2196 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2200 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2204 #if CONFIG_SENSOR_Exposure
2205 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2207 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2209 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2211 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2213 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2215 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2218 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2222 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2226 #if CONFIG_SENSOR_Saturation
2227 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2229 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2231 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2233 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2235 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2237 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2240 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2244 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2248 #if CONFIG_SENSOR_Contrast
2249 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2251 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2253 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2255 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2257 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2259 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2262 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2266 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2270 #if CONFIG_SENSOR_Mirror
2271 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2273 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2275 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2277 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2279 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2281 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2284 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2288 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2292 #if CONFIG_SENSOR_Flip
2293 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2295 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2297 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2299 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2301 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2303 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2306 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2310 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2314 #if CONFIG_SENSOR_Scene
2315 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2317 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2319 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2321 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2323 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2325 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2328 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2332 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2336 #if CONFIG_SENSOR_WhiteBalance
2337 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2339 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2341 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2343 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2345 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2347 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2350 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2354 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2358 #if CONFIG_SENSOR_DigitalZoom
2359 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2361 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2362 struct sensor *sensor = to_sensor(client);
2363 const struct v4l2_queryctrl *qctrl_info;
2364 int digitalzoom_cur, digitalzoom_total;
2366 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2370 digitalzoom_cur = sensor->info_priv.digitalzoom;
2371 digitalzoom_total = qctrl_info->maximum;
2373 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2375 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2379 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2381 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2385 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2387 value = digitalzoom_total - digitalzoom_cur;
2390 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2392 value = 0 - digitalzoom_cur;
2395 digitalzoom_cur += value;
2397 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2399 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2401 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2404 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2411 #if CONFIG_SENSOR_Flash
2412 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2414 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2415 if (value == 3) { /* ddl@rock-chips.com: torch */
2416 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2418 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2420 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2424 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2429 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2431 struct i2c_client *client = v4l2_get_subdevdata(sd);
2432 struct sensor *sensor = to_sensor(client);
2433 const struct v4l2_queryctrl *qctrl;
2435 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2439 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2445 case V4L2_CID_BRIGHTNESS:
2447 ctrl->value = sensor->info_priv.brightness;
2450 case V4L2_CID_SATURATION:
2452 ctrl->value = sensor->info_priv.saturation;
2455 case V4L2_CID_CONTRAST:
2457 ctrl->value = sensor->info_priv.contrast;
2460 case V4L2_CID_DO_WHITE_BALANCE:
2462 ctrl->value = sensor->info_priv.whiteBalance;
2465 case V4L2_CID_EXPOSURE:
2467 ctrl->value = sensor->info_priv.exposure;
2470 case V4L2_CID_HFLIP:
2472 ctrl->value = sensor->info_priv.mirror;
2475 case V4L2_CID_VFLIP:
2477 ctrl->value = sensor->info_priv.flip;
2488 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2490 struct i2c_client *client = v4l2_get_subdevdata(sd);
2491 struct sensor *sensor = to_sensor(client);
2492 struct soc_camera_device *icd = client->dev.platform_data;
2493 const struct v4l2_queryctrl *qctrl;
2496 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2500 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2506 #if CONFIG_SENSOR_Brightness
2507 case V4L2_CID_BRIGHTNESS:
2509 if (ctrl->value != sensor->info_priv.brightness)
2511 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2515 sensor->info_priv.brightness = ctrl->value;
2520 #if CONFIG_SENSOR_Exposure
2521 case V4L2_CID_EXPOSURE:
2523 if (ctrl->value != sensor->info_priv.exposure)
2525 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2529 sensor->info_priv.exposure = ctrl->value;
2534 #if CONFIG_SENSOR_Saturation
2535 case V4L2_CID_SATURATION:
2537 if (ctrl->value != sensor->info_priv.saturation)
2539 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2543 sensor->info_priv.saturation = ctrl->value;
2548 #if CONFIG_SENSOR_Contrast
2549 case V4L2_CID_CONTRAST:
2551 if (ctrl->value != sensor->info_priv.contrast)
2553 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2557 sensor->info_priv.contrast = ctrl->value;
2562 #if CONFIG_SENSOR_WhiteBalance
2563 case V4L2_CID_DO_WHITE_BALANCE:
2565 if (ctrl->value != sensor->info_priv.whiteBalance)
2567 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2571 sensor->info_priv.whiteBalance = ctrl->value;
2576 #if CONFIG_SENSOR_Mirror
2577 case V4L2_CID_HFLIP:
2579 if (ctrl->value != sensor->info_priv.mirror)
2581 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2583 sensor->info_priv.mirror = ctrl->value;
2588 #if CONFIG_SENSOR_Flip
2589 case V4L2_CID_VFLIP:
2591 if (ctrl->value != sensor->info_priv.flip)
2593 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2595 sensor->info_priv.flip = ctrl->value;
2606 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2608 const struct v4l2_queryctrl *qctrl;
2609 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2610 struct sensor *sensor = to_sensor(client);
2612 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2616 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2620 switch (ext_ctrl->id)
2622 case V4L2_CID_SCENE:
2624 ext_ctrl->value = sensor->info_priv.scene;
2627 case V4L2_CID_EFFECT:
2629 ext_ctrl->value = sensor->info_priv.effect;
2632 case V4L2_CID_ZOOM_ABSOLUTE:
2634 ext_ctrl->value = sensor->info_priv.digitalzoom;
2637 case V4L2_CID_ZOOM_RELATIVE:
2641 case V4L2_CID_FOCUS_ABSOLUTE:
2643 ext_ctrl->value = sensor->info_priv.focus;
2646 case V4L2_CID_FOCUS_RELATIVE:
2650 case V4L2_CID_FLASH:
2652 ext_ctrl->value = sensor->info_priv.flash;
2660 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2662 const struct v4l2_queryctrl *qctrl;
2663 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2664 struct sensor *sensor = to_sensor(client);
2667 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2671 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2676 switch (ext_ctrl->id)
2678 #if CONFIG_SENSOR_Scene
2679 case V4L2_CID_SCENE:
2681 if (ext_ctrl->value != sensor->info_priv.scene)
2683 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2685 sensor->info_priv.scene = ext_ctrl->value;
2690 #if CONFIG_SENSOR_Effect
2691 case V4L2_CID_EFFECT:
2693 if (ext_ctrl->value != sensor->info_priv.effect)
2695 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2697 sensor->info_priv.effect= ext_ctrl->value;
2702 #if CONFIG_SENSOR_DigitalZoom
2703 case V4L2_CID_ZOOM_ABSOLUTE:
2705 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2708 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2710 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2712 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2714 sensor->info_priv.digitalzoom += val_offset;
2716 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2721 case V4L2_CID_ZOOM_RELATIVE:
2723 if (ext_ctrl->value)
2725 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2727 sensor->info_priv.digitalzoom += ext_ctrl->value;
2729 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2734 #if CONFIG_SENSOR_Focus
2735 case V4L2_CID_FOCUS_ABSOLUTE:
2737 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2740 if (ext_ctrl->value != sensor->info_priv.focus)
2742 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2744 sensor->info_priv.focus += val_offset;
2749 case V4L2_CID_FOCUS_RELATIVE:
2751 if (ext_ctrl->value)
2753 sensor->info_priv.focus += ext_ctrl->value;
2755 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2760 #if CONFIG_SENSOR_Flash
2761 case V4L2_CID_FLASH:
2763 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2765 sensor->info_priv.flash = ext_ctrl->value;
2767 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2778 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2780 struct i2c_client *client = v4l2_get_subdevdata(sd);
2781 struct soc_camera_device *icd = client->dev.platform_data;
2782 int i, error_cnt=0, error_idx=-1;
2785 for (i=0; i<ext_ctrl->count; i++) {
2786 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2793 error_idx = ext_ctrl->count;
2795 if (error_idx != -1) {
2796 ext_ctrl->error_idx = error_idx;
2803 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2805 struct i2c_client *client = v4l2_get_subdevdata(sd);
2806 struct soc_camera_device *icd = client->dev.platform_data;
2807 int i, error_cnt=0, error_idx=-1;
2810 for (i=0; i<ext_ctrl->count; i++) {
2811 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2818 error_idx = ext_ctrl->count;
2820 if (error_idx != -1) {
2821 ext_ctrl->error_idx = error_idx;
2828 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2829 * this wasn't our capture interface, so, we wait for the right one */
2830 static int sensor_video_probe(struct soc_camera_device *icd,
2831 struct i2c_client *client)
2835 struct sensor *sensor = to_sensor(client);
2837 /* We must have a parent by now. And it cannot be a wrong one.
2838 * So this entire test is completely redundant. */
2839 if (!icd->dev.parent ||
2840 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2843 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2845 goto sensor_video_probe_err;
2849 ret = sensor_write(client, 0xfe, 0x80);
2852 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2855 mdelay(5); //delay 5 microseconds
2857 /* check if it is an sensor sensor */
2858 ret = sensor_read(client, 0x00, &value);
2860 SENSOR_TR("read chip id high byte failed\n");
2862 goto sensor_video_probe_err;
2865 pid |= (value << 8);
2867 ret = sensor_read(client, 0x01, &value);
2869 SENSOR_TR("read chip id low byte failed\n");
2871 goto sensor_video_probe_err;
2874 pid |= (value & 0xff);
2875 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2876 if (pid == SENSOR_ID) {
2877 sensor->model = SENSOR_V4L2_IDENT;
2879 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2881 goto sensor_video_probe_err;
2886 sensor_video_probe_err:
2890 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2892 struct i2c_client *client = v4l2_get_subdevdata(sd);
2893 struct soc_camera_device *icd = client->dev.platform_data;
2894 struct sensor *sensor = to_sensor(client);
2896 #if CONFIG_SENSOR_Flash
2900 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2903 case RK29_CAM_SUBDEV_DEACTIVATE:
2905 sensor_deactivate(client);
2909 case RK29_CAM_SUBDEV_IOREQUEST:
2911 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2912 if (sensor->sensor_io_request != NULL) {
2913 sensor->sensor_gpio_res = NULL;
2914 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2915 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2916 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2917 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2920 if (sensor->sensor_gpio_res == NULL) {
2921 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2923 goto sensor_ioctl_end;
2926 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2928 goto sensor_ioctl_end;
2930 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2932 #if CONFIG_SENSOR_Flash
2933 if (sensor->sensor_gpio_res) {
2934 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2935 for (i = 0; i < icd->ops->num_controls; i++) {
2936 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2937 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2938 sensor_controls[i].id=0xffff;
2941 sensor->info_priv.flash = 0xff;
2942 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2943 }else{ //two cameras are the same,need to deal diffrently ,zyc
2944 for (i = 0; i < icd->ops->num_controls; i++) {
2945 if(0xffff == icd->ops->controls[i].id){
2946 sensor_controls[i].id=V4L2_CID_FLASH;
2956 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2964 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2965 enum v4l2_mbus_pixelcode *code)
2967 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2970 *code = sensor_colour_fmts[index].code;
2973 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2974 .init = sensor_init,
2975 .g_ctrl = sensor_g_control,
2976 .s_ctrl = sensor_s_control,
2977 .g_ext_ctrls = sensor_g_ext_controls,
2978 .s_ext_ctrls = sensor_s_ext_controls,
2979 .g_chip_ident = sensor_g_chip_ident,
2980 .ioctl = sensor_ioctl,
2983 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2984 .s_mbus_fmt = sensor_s_fmt,
2985 .g_mbus_fmt = sensor_g_fmt,
2986 .try_mbus_fmt = sensor_try_fmt,
2987 .enum_mbus_fmt = sensor_enum_fmt,
2990 static struct v4l2_subdev_ops sensor_subdev_ops = {
2991 .core = &sensor_subdev_core_ops,
2992 .video = &sensor_subdev_video_ops,
2995 static int sensor_probe(struct i2c_client *client,
2996 const struct i2c_device_id *did)
2998 struct sensor *sensor;
2999 struct soc_camera_device *icd = client->dev.platform_data;
3000 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3001 struct soc_camera_link *icl;
3004 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3006 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3010 icl = to_soc_camera_link(icd);
3012 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3016 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3017 dev_warn(&adapter->dev,
3018 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3022 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3026 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3028 /* Second stage probe - when a capture adapter is there */
3029 icd->ops = &sensor_ops;
3031 sensor->info_priv.fmt = sensor_colour_fmts[0];
3033 #if CONFIG_SENSOR_I2C_NOSCHED
3034 atomic_set(&sensor->tasklock_cnt,0);
3037 ret = sensor_video_probe(icd, client);
3040 i2c_set_clientdata(client, NULL);
3044 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3045 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3049 static int sensor_remove(struct i2c_client *client)
3051 struct sensor *sensor = to_sensor(client);
3052 struct soc_camera_device *icd = client->dev.platform_data;
3055 i2c_set_clientdata(client, NULL);
3056 client->driver = NULL;
3062 static const struct i2c_device_id sensor_id[] = {
3063 {SENSOR_NAME_STRING(), 0 },
3066 MODULE_DEVICE_TABLE(i2c, sensor_id);
3068 static struct i2c_driver sensor_i2c_driver = {
3070 .name = SENSOR_NAME_STRING(),
3072 .probe = sensor_probe,
3073 .remove = sensor_remove,
3074 .id_table = sensor_id,
3077 static int __init sensor_mod_init(void)
3079 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3080 return i2c_add_driver(&sensor_i2c_driver);
3083 static void __exit sensor_mod_exit(void)
3085 i2c_del_driver(&sensor_i2c_driver);
3088 device_initcall_sync(sensor_mod_init);
3089 module_exit(sensor_mod_exit);
3091 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3092 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3093 MODULE_LICENSE("GPL");