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 <mach/rk29_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 0
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 /* init SVGA preview */
104 static struct reginfo sensor_init_data[] =
107 {0xfe, 0x80}, //soft reset
108 {0xfe, 0x80}, //soft reset
109 {0xfe, 0x80}, //soft reset
111 {0xfe, 0x00}, //page0
112 {0x45, 0x00}, //output_disable
114 //////////////////////////////////////////////////////////////////////////////////////
115 //////////////////////////preview capture switch /////////////////////////////////////
116 //////////////////////////////////////////////////////////////////////////////////////
118 {0x02, 0x01}, //preview mode
119 {0x2a, 0xca}, //[7]col_binning, 0x[6]even skip
120 {0x48, 0x40}, //manual_gain
122 ////////////////////////////////////////////////////////////////////////
123 ////////////////////////// preview LSC /////////////////////////////////
124 ////////////////////////////////////////////////////////////////////////
125 {0xfe, 0x01}, //page1
126 {0xb0, 0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
127 {0xb1, 0x46}, //P_LSC_red_b2
128 {0xb2, 0x40}, //P_LSC_green_b2
129 {0xb3, 0x40}, //P_LSC_blue_b2
130 {0xb4, 0x24}, //P_LSC_red_b4
131 {0xb5, 0x20}, //P_LSC_green_b4
132 {0xb6, 0x22}, //P_LSC_blue_b4
133 {0xb7, 0x00}, //P_LSC_compensate_b2
134 {0xb8, 0x80}, //P_LSC_row_center, 0x344, 0x (1200/2-344)/2=128, 0x, 0x
135 {0xb9, 0x80}, //P_LSC_col_center, 0x544, 0x (1600/2-544)/2=128
138 ////////////////////////////////////////////////////////////////////////
139 ////////////////////////// capture LSC /////////////////////////////////
140 ////////////////////////////////////////////////////////////////////////
141 {0xba, 0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
142 {0xbb, 0x46}, //C_LSC_red_b2
143 {0xbc, 0x40}, //C_LSC_green_b2
144 {0xbd, 0x40}, //C_LSC_blue_b2
145 {0xbe, 0x24}, //C_LSC_red_b4
146 {0xbf, 0x20}, //C_LSC_green_b4
147 {0xc0, 0x22}, //C_LSC_blue_b4
148 {0xc1, 0x00}, //C_Lsc_compensate_b2
149 {0xc2, 0x80}, //C_LSC_row_center, 0x344, 0x (1200/2-344)/2=128
150 {0xc3, 0x80}, //C_LSC_col_center, 0x544, 0x (1600/2-544)/2=128
151 {0xfe, 0x00}, //page0
153 ////////////////////////////////////////////////////////////////////////
154 ////////////////////////// analog configure ///////////////////////////
155 ////////////////////////////////////////////////////////////////////////
156 {0xfe, 0x00}, //page0
157 {0x29, 0x00}, //cisctl mode 1
158 {0x2b, 0x06}, //cisctl mode 3
159 {0x32, 0x1c}, //analog mode 1
160 {0x33, 0x0f}, //analog mode 2
161 {0x34, 0x30}, //[6:4]da_rsg
163 {0x35, 0x88}, //Vref_A25
164 {0x37, 0x16}, //Drive Current
166 /////////////////////////////////////////////////////////////////////
167 /////////////////////////// ISP Related /////////////////////////////
168 /////////////////////////////////////////////////////////////////////
170 {0x41, 0x20}, //[5]skin_detectionenable[2]auto_gray, 0x[1]y_gamma
171 {0x42, 0xf6}, //[7]auto_sa[6]auto_ee[5]auto_dndd[4]auto_lsc[3]na[2]abs, 0x[1]awb
172 {0x4b, 0xe8}, //[1]AWB_gain_mode, 0x1:atpregain0:atpostgain
173 {0x4d, 0x03}, //[1]inbf_en
174 {0x4f, 0x01}, //AEC enable
176 ////////////////////////////////////////////////////////////////////
177 /////////////////////////// BLK //////////////////////////////////
178 ////////////////////////////////////////////////////////////////////
179 {0x63, 0x77}, //BLK mode 1
180 {0x66, 0x00}, //BLK global offset
182 {0x6e, 0x1a}, //BLK offset submode,offset R
191 ////////////////////////////////////////////////////////////////////
192 /////////////////////////// DNDD ///////////////////////////////////
193 ////////////////////////////////////////////////////////////////////
194 {0x80, 0x07}, //[7]dn_inc_or_dec [4]zero_weight_mode[3]share [2]c_weight_adap [1]dn_lsc_mode [0]dn_b
195 {0x82, 0x0c}, //DN lilat b base
198 ////////////////////////////////////////////////////////////////////
199 /////////////////////////// EEINTP ////////////////////////////////
200 ////////////////////////////////////////////////////////////////////
207 /////////////////////////////////////////////////////////////////////
208 /////////////////////////// CC_t ////////////////////////////////////
209 /////////////////////////////////////////////////////////////////////
210 {0xb0, 0x40}, // 0x48
221 /////////////////////////////////////////////////////////////////////
222 /////////////////////////// GAMMA ///////////////////////////////////
223 /////////////////////////////////////////////////////////////////////
261 /////////////////////////////////////////////////////////////////////
262 /////////////////////////// YCP_t ///////////////////////////////////
263 /////////////////////////////////////////////////////////////////////
264 {0xd1, 0x40}, //saturation 38
265 {0xd2, 0x40}, //saturation 38
267 {0xd3, 0x46}, // 2011-08-11 kim add
269 {0xde, 0x21}, //auto_gray
271 ////////////////////////////////////////////////////////////////////
272 /////////////////////////// ASDE ///////////////////////////////////
273 ////////////////////////////////////////////////////////////////////
281 {0xfe, 0x01}, //page1
287 ////////////////////////////////////////////////////////////////////
288 /////////////////////////// AEC ////////////////////////////////////
289 ////////////////////////////////////////////////////////////////////
290 {0x10, 0x09}, //AEC mode 1
291 {0x11, 0x92}, //[7]fix target // 0xb2 2011-08-11 kim
293 {0x13, 0x78}, // 0x78 2011-08-11 kim
296 {0x1d, 0x04}, // sunlight step
298 {0x21, 0xc0}, //max_post_gain
299 {0x22, 0x40}, //max_pre_gain // 0x60 2011-08-11 kim
300 {0x2d, 0x06}, //P_N_AEC_exp_level_1[12:8]
301 {0x2e, 0x00}, //P_N_AEC_exp_level_1[7:0]
303 {0x33, 0x00}, //[6:5]max_exp_level [4:0]min_exp_level
304 {0x34, 0x04}, // min exp
306 ////////////////////////////////////////////////////////////////////
307 /////////////////////////// Measure Window /////////////////////////
308 ////////////////////////////////////////////////////////////////////
314 ////////////////////////////////////////////////////////////////////
315 /////////////////////////// AWB ////////////////////////////////////
316 ////////////////////////////////////////////////////////////////////
317 {0x57, 0x40}, //number limit
319 {0x5c, 0x35}, //show mode,close dark_mode
320 {0x5e, 0x29}, //close color temp
324 ////////////////////////////////////////////////////////////////////
325 /////////////////////////// ABS ////////////////////////////////////
326 ////////////////////////////////////////////////////////////////////
332 {0x83, 0x10}, //ABS Y stretch limit
334 ////////////////////////////////////////////////////////////////////
335 /////////////////////////// OUT ////////////////////////////////////
336 ////////////////////////////////////////////////////////////////////
349 {0x44, 0xa0}, //YUV sequence
350 {0x45, 0x0f}, //output enable
351 {0x46, 0x02}, //sync mode
377 {0x29, 0x00},//Anti Step 128
380 {0x2b, 0x05},//Level_0 10.00fps
382 {0x2d, 0x06},//Level_1 8.33fps
384 {0x2f, 0x08},//Level_2 6.25fps
386 {0x31, 0x09},//Level_3 5.55fps
391 //--------------------Updated By Mormo 2011/08/08 Start --------------------//
395 //--------------------Updated By Mormo 2011/08/08 End ---------------------//
404 /* 1600X1200 UXGA capture */
405 static struct reginfo sensor_uxga[] =
411 {0x4f, 0x00}, // aec off
442 static struct reginfo sensor_sxga[] =
448 {0x4f, 0x00}, // aec off
478 static struct reginfo sensor_xga[] =
484 {0x4f, 0x00}, // aec off
488 //subsample 1600x1200 to 1066x800
489 {0x59 , 0x33},//out window
500 {0x50 , 0x01},//out window
511 /* 800X600 SVGA,30fps*/
512 static struct reginfo sensor_svga[] =
517 {0x4f, 0x01}, // aec on
534 {0x50 , 0x01},//out window
547 static struct reginfo sensor_vga[] =
554 {0x4f, 0x01}, // aec on
560 {0x59 , 0x55},//out window
571 {0x50 , 0x01},//out window
580 {0x45 , 0x0f}, //output enable
585 static struct reginfo sensor_cif[] =
589 static struct reginfo sensor_qvga[] =
593 static struct reginfo sensor_qcif[] =
597 static struct reginfo ov2655_qqvga[] =
604 static struct reginfo ov2655_Sharpness_auto[] =
610 static struct reginfo ov2655_Sharpness1[] =
616 static struct reginfo ov2655_Sharpness2[][3] =
623 static struct reginfo ov2655_Sharpness3[] =
629 static struct reginfo ov2655_Sharpness4[]=
636 static struct reginfo ov2655_Sharpness5[] =
644 static struct reginfo sensor_ClrFmt_YUYV[]=
650 static struct reginfo sensor_ClrFmt_UYVY[]=
656 #if CONFIG_SENSOR_WhiteBalance
657 static struct reginfo sensor_WhiteB_Auto[]=
662 /* Cloudy Colour Temperature : 6500K - 8000K */
663 static struct reginfo sensor_WhiteB_Cloudy[]=
666 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
667 {0x7a , 0x8c}, //AWB_R_gain
668 {0x7b , 0x50}, //AWB_G_gain
669 {0x7c , 0x40}, //AWB_B_gain
672 /* ClearDay Colour Temperature : 5000K - 6500K */
673 static struct reginfo sensor_WhiteB_ClearDay[]=
676 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
677 {0x7a , 0x74}, //AWB_R_gain
678 {0x7b , 0x52}, //AWB_G_gain
679 {0x7c , 0x40}, //AWB_B_gain
682 /* Office Colour Temperature : 3500K - 5000K */
683 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
686 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
687 {0x7a , 0x48}, //AWB_R_gain
688 {0x7b , 0x40}, //AWB_G_gain
689 {0x7c , 0x5c}, //AWB_B_gain
693 /* Home Colour Temperature : 2500K - 3500K */
694 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
697 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
698 {0x7a , 0x40}, //AWB_R_gain
699 {0x7b , 0x54}, //AWB_G_gain
700 {0x7c , 0x70}, //AWB_B_gain
703 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
704 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
708 #if CONFIG_SENSOR_Brightness
709 static struct reginfo sensor_Brightness0[]=
714 {0x13, 0x68}, //AEC_target_Y
716 {0xd5, 0xe0},// Luma_offset
720 static struct reginfo sensor_Brightness1[]=
724 {0x13, 0x70}, //AEC_target_Y
726 {0xd5, 0xf0},// Luma_offset
731 static struct reginfo sensor_Brightness2[]=
736 {0x13, 0x78}, //AEC_target_Y 48
738 {0xd5, 0x00},// Luma_offset c0
743 static struct reginfo sensor_Brightness3[]=
747 {0x13, 0x80}, //AEC_target_Y
749 {0xd5, 0x10},// Luma_offset
754 static struct reginfo sensor_Brightness4[]=
758 {0x13, 0x88}, //AEC_target_Y
760 {0xd5, 0x20},// Luma_offset
765 static struct reginfo sensor_Brightness5[]=
769 {0x13, 0x90}, //AEC_target_Y
771 {0xd5, 0x30},// Luma_offset
774 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
775 sensor_Brightness4, sensor_Brightness5,NULL,
780 #if CONFIG_SENSOR_Effect
781 static struct reginfo sensor_Effect_Normal[] =
788 static struct reginfo sensor_Effect_WandB[] =
796 static struct reginfo sensor_Effect_Sepia[] =
804 static struct reginfo sensor_Effect_Negative[] =
812 static struct reginfo sensor_Effect_Bluish[] =
822 static struct reginfo sensor_Effect_Green[] =
830 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
831 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
834 #if CONFIG_SENSOR_Exposure
835 static struct reginfo sensor_Exposure0[]=
841 static struct reginfo sensor_Exposure1[]=
848 static struct reginfo sensor_Exposure2[]=
855 static struct reginfo sensor_Exposure3[]=
862 static struct reginfo sensor_Exposure4[]=
869 static struct reginfo sensor_Exposure5[]=
876 static struct reginfo sensor_Exposure6[]=
883 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
884 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
887 #if CONFIG_SENSOR_Saturation
888 static struct reginfo sensor_Saturation0[]=
894 static struct reginfo sensor_Saturation1[]=
900 static struct reginfo sensor_Saturation2[]=
905 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
908 #if CONFIG_SENSOR_Contrast
909 static struct reginfo sensor_Contrast0[]=
917 static struct reginfo sensor_Contrast1[]=
925 static struct reginfo sensor_Contrast2[]=
933 static struct reginfo sensor_Contrast3[]=
941 static struct reginfo sensor_Contrast4[]=
950 static struct reginfo sensor_Contrast5[]=
958 static struct reginfo sensor_Contrast6[]=
965 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
966 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
970 #if CONFIG_SENSOR_Mirror
971 static struct reginfo sensor_MirrorOn[]=
977 static struct reginfo sensor_MirrorOff[]=
982 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
984 #if CONFIG_SENSOR_Flip
985 static struct reginfo sensor_FlipOn[]=
991 static struct reginfo sensor_FlipOff[]=
996 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
999 #if CONFIG_SENSOR_Scene
1000 static struct reginfo sensor_SceneAuto[] =
1002 /* ddl@rock-chips.com : */
1011 static struct reginfo sensor_SceneNight[] =
1014 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1021 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1024 #if CONFIG_SENSOR_DigitalZoom
1025 static struct reginfo sensor_Zoom0[] =
1030 static struct reginfo sensor_Zoom1[] =
1035 static struct reginfo sensor_Zoom2[] =
1041 static struct reginfo sensor_Zoom3[] =
1045 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1047 static const struct v4l2_querymenu sensor_menus[] =
1049 #if CONFIG_SENSOR_WhiteBalance
1050 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1051 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1052 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1055 #if CONFIG_SENSOR_Effect
1056 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1057 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1058 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1061 #if CONFIG_SENSOR_Scene
1062 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1065 #if CONFIG_SENSOR_Flash
1066 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1067 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1071 static const struct v4l2_queryctrl sensor_controls[] =
1073 #if CONFIG_SENSOR_WhiteBalance
1075 .id = V4L2_CID_DO_WHITE_BALANCE,
1076 .type = V4L2_CTRL_TYPE_MENU,
1077 .name = "White Balance Control",
1085 #if CONFIG_SENSOR_Brightness
1087 .id = V4L2_CID_BRIGHTNESS,
1088 .type = V4L2_CTRL_TYPE_INTEGER,
1089 .name = "Brightness Control",
1097 #if CONFIG_SENSOR_Effect
1099 .id = V4L2_CID_EFFECT,
1100 .type = V4L2_CTRL_TYPE_MENU,
1101 .name = "Effect Control",
1109 #if CONFIG_SENSOR_Exposure
1111 .id = V4L2_CID_EXPOSURE,
1112 .type = V4L2_CTRL_TYPE_INTEGER,
1113 .name = "Exposure Control",
1121 #if CONFIG_SENSOR_Saturation
1123 .id = V4L2_CID_SATURATION,
1124 .type = V4L2_CTRL_TYPE_INTEGER,
1125 .name = "Saturation Control",
1133 #if CONFIG_SENSOR_Contrast
1135 .id = V4L2_CID_CONTRAST,
1136 .type = V4L2_CTRL_TYPE_INTEGER,
1137 .name = "Contrast Control",
1145 #if CONFIG_SENSOR_Mirror
1147 .id = V4L2_CID_HFLIP,
1148 .type = V4L2_CTRL_TYPE_BOOLEAN,
1149 .name = "Mirror Control",
1157 #if CONFIG_SENSOR_Flip
1159 .id = V4L2_CID_VFLIP,
1160 .type = V4L2_CTRL_TYPE_BOOLEAN,
1161 .name = "Flip Control",
1169 #if CONFIG_SENSOR_Scene
1171 .id = V4L2_CID_SCENE,
1172 .type = V4L2_CTRL_TYPE_MENU,
1173 .name = "Scene Control",
1181 #if CONFIG_SENSOR_DigitalZoom
1183 .id = V4L2_CID_ZOOM_RELATIVE,
1184 .type = V4L2_CTRL_TYPE_INTEGER,
1185 .name = "DigitalZoom Control",
1191 .id = V4L2_CID_ZOOM_ABSOLUTE,
1192 .type = V4L2_CTRL_TYPE_INTEGER,
1193 .name = "DigitalZoom Control",
1201 #if CONFIG_SENSOR_Focus
1203 .id = V4L2_CID_FOCUS_RELATIVE,
1204 .type = V4L2_CTRL_TYPE_INTEGER,
1205 .name = "Focus Control",
1211 .id = V4L2_CID_FOCUS_ABSOLUTE,
1212 .type = V4L2_CTRL_TYPE_INTEGER,
1213 .name = "Focus Control",
1217 .default_value = 125,
1221 #if CONFIG_SENSOR_Flash
1223 .id = V4L2_CID_FLASH,
1224 .type = V4L2_CTRL_TYPE_MENU,
1225 .name = "Flash Control",
1234 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1235 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1236 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1237 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1238 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1239 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1240 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1241 static int sensor_resume(struct soc_camera_device *icd);
1242 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1243 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1244 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1245 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1246 static int sensor_deactivate(struct i2c_client *client);
1247 static int sensor_write(struct i2c_client *client, u8 reg, u8 val);
1248 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val);
1251 static u16 GC2015_read_shutter(struct i2c_client *client); // add 2011-08-11 kim
1252 static void GC2015_set_shutter(struct i2c_client *client, u16 shutter); // add 2011-08-11 kim
1255 ////// add 2011-08-11 kim
1256 static u16 GC2015_read_shutter(struct i2c_client *client)
1258 u8 temp_reg1, temp_reg2;
1261 /* Backup the preview mode last shutter & sensor gain. */
1262 sensor_read(client, 0x03, &temp_reg1);
1263 sensor_read(client, 0x04, &temp_reg2);
1265 shutter = (temp_reg1 << 8) | (temp_reg2 & 0xFF);
1268 } /* GC2015_read_shutter */
1270 static void GC2015_set_shutter(struct i2c_client *client, u16 shutter)
1274 temp_reg = shutter * 10 / 20; ////
1276 /*Set Shutter start*/
1277 if(temp_reg < 1) temp_reg = 1;
1278 sensor_write(client ,0x03 , (temp_reg>>8)&0xff);
1279 sensor_write(client ,0x04 , temp_reg&0xff);
1282 //////// end add kim
1284 static struct soc_camera_ops sensor_ops =
1286 .suspend = sensor_suspend,
1287 .resume = sensor_resume,
1288 .set_bus_param = sensor_set_bus_param,
1289 .query_bus_param = sensor_query_bus_param,
1290 .controls = sensor_controls,
1291 .menus = sensor_menus,
1292 .num_controls = ARRAY_SIZE(sensor_controls),
1293 .num_menus = ARRAY_SIZE(sensor_menus),
1296 /* only one fixed colorspace per pixelcode */
1297 struct sensor_datafmt {
1298 enum v4l2_mbus_pixelcode code;
1299 enum v4l2_colorspace colorspace;
1302 /* Find a data format by a pixel code in an array */
1303 static const struct sensor_datafmt *sensor_find_datafmt(
1304 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1308 for (i = 0; i < n; i++)
1309 if (fmt[i].code == code)
1315 static const struct sensor_datafmt sensor_colour_fmts[] = {
1316 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1317 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1320 typedef struct sensor_info_priv_s
1334 unsigned char mirror; /* HFLIP */
1335 unsigned char flip; /* VFLIP */
1336 unsigned int winseqe_cur_addr;
1337 struct sensor_datafmt fmt;
1338 unsigned int funmodule_state;
1339 } sensor_info_priv_t;
1343 struct v4l2_subdev subdev;
1344 struct i2c_client *client;
1345 sensor_info_priv_t info_priv;
1346 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1347 #if CONFIG_SENSOR_I2C_NOSCHED
1348 atomic_t tasklock_cnt;
1350 struct rk29camera_platform_data *sensor_io_request;
1351 struct rk29camera_gpio_res *sensor_gpio_res;
1354 static struct sensor* to_sensor(const struct i2c_client *client)
1356 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1359 static int sensor_task_lock(struct i2c_client *client, int lock)
1361 #if CONFIG_SENSOR_I2C_NOSCHED
1363 struct sensor *sensor = to_sensor(client);
1366 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1367 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1368 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1372 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1373 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1374 goto sensor_task_lock_err;
1379 atomic_add(1, &sensor->tasklock_cnt);
1381 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1382 atomic_sub(1, &sensor->tasklock_cnt);
1384 if (atomic_read(&sensor->tasklock_cnt) == 0)
1389 sensor_task_lock_err:
1398 /* sensor register */
1399 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1403 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1405 return (ret > 0)? 0 : ret;
1408 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1412 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1414 return (ret > 0)? 0 : ret;
1417 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1421 struct i2c_msg msg[1];
1429 msg->addr = client->addr;
1430 msg->flags = client->flags;
1432 msg->len = sizeof(buf);
1433 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1434 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1439 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1440 err = i2c_transfer(client->adapter, msg, 1);
1445 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1453 /* sensor register read */
1454 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1458 struct i2c_msg msg[2];
1462 msg[0].addr = client->addr;
1463 msg[0].flags = client->flags;
1465 msg[0].len = sizeof(buf);
1466 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1467 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1469 msg[1].addr = client->addr;
1470 msg[1].flags = client->flags|I2C_M_RD;
1473 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1474 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1478 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1479 err = i2c_transfer(client->adapter, msg, 2);
1485 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1495 /* write a array of registers */
1496 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1500 #if CONFIG_SENSOR_I2C_RDWRCHK
1505 if (sensor_task_lock(client, 1) < 0)
1506 goto sensor_write_array_end;
1507 while (regarray[i].reg != 0)
1509 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1513 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1517 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1519 goto sensor_write_array_end;
1522 #if CONFIG_SENSOR_I2C_RDWRCHK
1524 sensor_read(client, regarray[i].reg, &valchk);
1525 if (valchk != regarray[i].val)
1526 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1532 sensor_write_array_end:
1533 sensor_task_lock(client,0);
1536 #if CONFIG_SENSOR_I2C_RDWRCHK
1537 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1545 while (regarray[i].reg != 0)
1547 sensor_read(client, regarray[i].reg, &valchk);
1548 if (valchk != regarray[i].val)
1549 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1556 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1558 struct soc_camera_link *icl = to_soc_camera_link(icd);
1561 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1564 case Sensor_PowerDown:
1566 if (icl->powerdown) {
1567 ret = icl->powerdown(icd->pdev, on);
1568 if (ret == RK29_CAM_IO_SUCCESS) {
1572 icl->reset(icd->pdev);
1574 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1576 goto sensor_power_end;
1583 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1584 struct sensor *sensor = to_sensor(client);
1586 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1587 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1593 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1600 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1602 struct i2c_client *client = v4l2_get_subdevdata(sd);
1603 struct soc_camera_device *icd = client->dev.platform_data;
1604 struct sensor *sensor = to_sensor(client);
1605 const struct v4l2_queryctrl *qctrl;
1606 const struct sensor_datafmt *fmt;
1610 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1612 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1614 goto sensor_INIT_ERR;
1618 if (sensor_task_lock(client,1)<0)
1619 goto sensor_INIT_ERR;
1620 ret = sensor_write(client, 0xfe, 0x80);
1623 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1625 goto sensor_INIT_ERR;
1628 mdelay(5); //delay 5 microseconds
1629 /* check if it is an sensor sensor */
1630 ret = sensor_read(client, 0x00, &value);
1632 SENSOR_TR("read chip id high byte failed\n");
1634 goto sensor_INIT_ERR;
1637 pid |= (value << 8);
1639 ret = sensor_read(client, 0x01, &value);
1641 SENSOR_TR("read chip id low byte failed\n");
1643 goto sensor_INIT_ERR;
1646 pid |= (value & 0xff);
1647 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1648 if (pid == SENSOR_ID) {
1649 sensor->model = SENSOR_V4L2_IDENT;
1651 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1653 goto sensor_INIT_ERR;
1656 ret = sensor_write_array(client, sensor_init_data);
1659 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1660 goto sensor_INIT_ERR;
1662 sensor_task_lock(client,0);
1664 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1665 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1667 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1669 goto sensor_INIT_ERR;
1671 sensor->info_priv.fmt = *fmt;
1673 /* sensor sensor information for initialization */
1674 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1676 sensor->info_priv.whiteBalance = qctrl->default_value;
1677 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1679 sensor->info_priv.brightness = qctrl->default_value;
1680 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1682 sensor->info_priv.effect = qctrl->default_value;
1683 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1685 sensor->info_priv.exposure = qctrl->default_value;
1687 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1689 sensor->info_priv.saturation = qctrl->default_value;
1690 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1692 sensor->info_priv.contrast = qctrl->default_value;
1693 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1695 sensor->info_priv.mirror = qctrl->default_value;
1696 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1698 sensor->info_priv.flip = qctrl->default_value;
1699 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1701 sensor->info_priv.scene = qctrl->default_value;
1702 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1704 sensor->info_priv.digitalzoom = qctrl->default_value;
1706 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1707 #if CONFIG_SENSOR_Focus
1709 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1711 sensor->info_priv.focus = qctrl->default_value;
1714 #if CONFIG_SENSOR_Flash
1715 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1717 sensor->info_priv.flash = qctrl->default_value;
1720 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);
1721 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1724 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1725 sensor_task_lock(client,0);
1726 sensor_deactivate(client);
1730 static int sensor_deactivate(struct i2c_client *client)
1732 struct soc_camera_device *icd = client->dev.platform_data;
1734 struct sensor *sensor = to_sensor(client);
1735 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1737 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1738 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1741 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1742 icd->user_width = SENSOR_INIT_WIDTH;
1743 icd->user_height = SENSOR_INIT_HEIGHT;
1744 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1749 static struct reginfo sensor_power_down_sequence[]=
1753 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1756 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1758 if (pm_msg.event == PM_EVENT_SUSPEND) {
1759 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1760 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1762 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1765 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1767 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1772 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1778 static int sensor_resume(struct soc_camera_device *icd)
1782 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1784 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1788 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1794 static int sensor_set_bus_param(struct soc_camera_device *icd,
1795 unsigned long flags)
1801 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1803 struct soc_camera_link *icl = to_soc_camera_link(icd);
1804 unsigned long flags = SENSOR_BUS_PARAM;
1806 return soc_camera_apply_sensor_flags(icl, flags);
1809 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1811 struct i2c_client *client = v4l2_get_subdevdata(sd);
1812 struct soc_camera_device *icd = client->dev.platform_data;
1813 struct sensor *sensor = to_sensor(client);
1815 mf->width = icd->user_width;
1816 mf->height = icd->user_height;
1817 mf->code = sensor->info_priv.fmt.code;
1818 mf->colorspace = sensor->info_priv.fmt.colorspace;
1819 mf->field = V4L2_FIELD_NONE;
1823 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1827 if ((mf->width == 1024) && (mf->height == 768)) {
1829 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1831 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1833 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1835 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1840 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1844 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1848 if ((mf->width == 1280) && (mf->height == 720)) {
1850 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1855 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1858 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1860 struct i2c_client *client = v4l2_get_subdevdata(sd);
1861 const struct sensor_datafmt *fmt;
1862 struct sensor *sensor = to_sensor(client);
1863 const struct v4l2_queryctrl *qctrl;
1864 struct soc_camera_device *icd = client->dev.platform_data;
1865 struct reginfo *winseqe_set_addr=NULL;
1866 int ret=0, set_w,set_h;
1870 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1871 ARRAY_SIZE(sensor_colour_fmts));
1874 goto sensor_s_fmt_end;
1877 if (sensor->info_priv.fmt.code != mf->code) {
1880 case V4L2_MBUS_FMT_YUYV8_2X8:
1882 winseqe_set_addr = sensor_ClrFmt_YUYV;
1885 case V4L2_MBUS_FMT_UYVY8_2X8:
1887 winseqe_set_addr = sensor_ClrFmt_UYVY;
1893 if (winseqe_set_addr != NULL) {
1894 sensor_write_array(client, winseqe_set_addr);
1895 sensor->info_priv.fmt.code = mf->code;
1896 sensor->info_priv.fmt.colorspace= mf->colorspace;
1897 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1899 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1906 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1908 winseqe_set_addr = sensor_qcif;
1912 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1914 winseqe_set_addr = sensor_qvga;
1918 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1920 winseqe_set_addr = sensor_cif;
1924 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1926 winseqe_set_addr = sensor_vga;
1930 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1932 winseqe_set_addr = sensor_svga;
1936 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1938 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1940 winseqe_set_addr = sensor_xga;
1944 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1946 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1948 winseqe_set_addr = sensor_sxga;
1952 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1955 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1957 winseqe_set_addr = sensor_uxga;
1963 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1964 set_w = SENSOR_INIT_WIDTH;
1965 set_h = SENSOR_INIT_HEIGHT;
1966 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1969 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1970 #if CONFIG_SENSOR_Flash
1971 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1972 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1973 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1974 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1976 } else { /* ddl@rock-chips.com : Video */
1977 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1978 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1979 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1983 ret |= sensor_write_array(client, winseqe_set_addr);
1985 if(set_w >= 1024) GC2015_set_shutter(client, gc2015_shutter); // add 2011-08-11 kim
1988 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1989 #if CONFIG_SENSOR_Flash
1990 if (sensor_fmt_capturechk(sd,mf) == true) {
1991 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1992 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1993 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1997 goto sensor_s_fmt_end;
2000 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2002 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2003 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2004 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2005 if (sensor->info_priv.whiteBalance != 0) {
2006 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2007 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2009 sensor->info_priv.snap2preview = true;
2010 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2011 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2012 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2013 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2014 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2015 sensor->info_priv.video2preview = true;
2016 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2017 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2018 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2019 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2020 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2021 sensor->info_priv.video2preview = false;
2022 sensor->info_priv.snap2preview = false;
2024 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2028 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2038 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2040 struct i2c_client *client = v4l2_get_subdevdata(sd);
2041 struct sensor *sensor = to_sensor(client);
2042 const struct sensor_datafmt *fmt;
2045 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2046 ARRAY_SIZE(sensor_colour_fmts));
2048 fmt = &sensor->info_priv.fmt;
2049 mf->code = fmt->code;
2052 if (mf->height > SENSOR_MAX_HEIGHT)
2053 mf->height = SENSOR_MAX_HEIGHT;
2054 else if (mf->height < SENSOR_MIN_HEIGHT)
2055 mf->height = SENSOR_MIN_HEIGHT;
2057 if (mf->width > SENSOR_MAX_WIDTH)
2058 mf->width = SENSOR_MAX_WIDTH;
2059 else if (mf->width < SENSOR_MIN_WIDTH)
2060 mf->width = SENSOR_MIN_WIDTH;
2062 mf->colorspace = fmt->colorspace;
2067 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2069 struct i2c_client *client = v4l2_get_subdevdata(sd);
2071 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2074 if (id->match.addr != client->addr)
2077 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2082 #if CONFIG_SENSOR_Brightness
2083 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2085 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2087 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2089 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2091 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2093 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2096 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2100 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2104 #if CONFIG_SENSOR_Effect
2105 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2107 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2109 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2111 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2113 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2115 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2118 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2122 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2126 #if CONFIG_SENSOR_Exposure
2127 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2129 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2131 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2133 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2135 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2137 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2140 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2144 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2148 #if CONFIG_SENSOR_Saturation
2149 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2151 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2153 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2155 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2157 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2159 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2162 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2166 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2170 #if CONFIG_SENSOR_Contrast
2171 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2173 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2175 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2177 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2179 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2181 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2184 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2188 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2192 #if CONFIG_SENSOR_Mirror
2193 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2195 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2197 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2199 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2201 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2203 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2206 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2210 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2214 #if CONFIG_SENSOR_Flip
2215 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2217 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2219 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2221 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2223 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2225 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2228 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2232 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2236 #if CONFIG_SENSOR_Scene
2237 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2239 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2241 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2243 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2245 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2247 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2250 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2254 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2258 #if CONFIG_SENSOR_WhiteBalance
2259 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2261 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2263 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2265 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2267 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2269 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2272 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2276 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2280 #if CONFIG_SENSOR_DigitalZoom
2281 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2283 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2284 struct sensor *sensor = to_sensor(client);
2285 const struct v4l2_queryctrl *qctrl_info;
2286 int digitalzoom_cur, digitalzoom_total;
2288 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2292 digitalzoom_cur = sensor->info_priv.digitalzoom;
2293 digitalzoom_total = qctrl_info->maximum;
2295 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2297 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2301 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2303 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2307 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2309 value = digitalzoom_total - digitalzoom_cur;
2312 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2314 value = 0 - digitalzoom_cur;
2317 digitalzoom_cur += value;
2319 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2321 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2323 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2326 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2333 #if CONFIG_SENSOR_Flash
2334 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2336 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2337 if (value == 3) { /* ddl@rock-chips.com: torch */
2338 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2340 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2342 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2346 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2351 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2353 struct i2c_client *client = v4l2_get_subdevdata(sd);
2354 struct sensor *sensor = to_sensor(client);
2355 const struct v4l2_queryctrl *qctrl;
2357 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2361 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2367 case V4L2_CID_BRIGHTNESS:
2369 ctrl->value = sensor->info_priv.brightness;
2372 case V4L2_CID_SATURATION:
2374 ctrl->value = sensor->info_priv.saturation;
2377 case V4L2_CID_CONTRAST:
2379 ctrl->value = sensor->info_priv.contrast;
2382 case V4L2_CID_DO_WHITE_BALANCE:
2384 ctrl->value = sensor->info_priv.whiteBalance;
2387 case V4L2_CID_EXPOSURE:
2389 ctrl->value = sensor->info_priv.exposure;
2392 case V4L2_CID_HFLIP:
2394 ctrl->value = sensor->info_priv.mirror;
2397 case V4L2_CID_VFLIP:
2399 ctrl->value = sensor->info_priv.flip;
2410 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2412 struct i2c_client *client = v4l2_get_subdevdata(sd);
2413 struct sensor *sensor = to_sensor(client);
2414 struct soc_camera_device *icd = client->dev.platform_data;
2415 const struct v4l2_queryctrl *qctrl;
2418 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2422 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2428 #if CONFIG_SENSOR_Brightness
2429 case V4L2_CID_BRIGHTNESS:
2431 if (ctrl->value != sensor->info_priv.brightness)
2433 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2437 sensor->info_priv.brightness = ctrl->value;
2442 #if CONFIG_SENSOR_Exposure
2443 case V4L2_CID_EXPOSURE:
2445 if (ctrl->value != sensor->info_priv.exposure)
2447 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2451 sensor->info_priv.exposure = ctrl->value;
2456 #if CONFIG_SENSOR_Saturation
2457 case V4L2_CID_SATURATION:
2459 if (ctrl->value != sensor->info_priv.saturation)
2461 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2465 sensor->info_priv.saturation = ctrl->value;
2470 #if CONFIG_SENSOR_Contrast
2471 case V4L2_CID_CONTRAST:
2473 if (ctrl->value != sensor->info_priv.contrast)
2475 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2479 sensor->info_priv.contrast = ctrl->value;
2484 #if CONFIG_SENSOR_WhiteBalance
2485 case V4L2_CID_DO_WHITE_BALANCE:
2487 if (ctrl->value != sensor->info_priv.whiteBalance)
2489 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2493 sensor->info_priv.whiteBalance = ctrl->value;
2498 #if CONFIG_SENSOR_Mirror
2499 case V4L2_CID_HFLIP:
2501 if (ctrl->value != sensor->info_priv.mirror)
2503 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2505 sensor->info_priv.mirror = ctrl->value;
2510 #if CONFIG_SENSOR_Flip
2511 case V4L2_CID_VFLIP:
2513 if (ctrl->value != sensor->info_priv.flip)
2515 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2517 sensor->info_priv.flip = ctrl->value;
2528 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2530 const struct v4l2_queryctrl *qctrl;
2531 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2532 struct sensor *sensor = to_sensor(client);
2534 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2538 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2542 switch (ext_ctrl->id)
2544 case V4L2_CID_SCENE:
2546 ext_ctrl->value = sensor->info_priv.scene;
2549 case V4L2_CID_EFFECT:
2551 ext_ctrl->value = sensor->info_priv.effect;
2554 case V4L2_CID_ZOOM_ABSOLUTE:
2556 ext_ctrl->value = sensor->info_priv.digitalzoom;
2559 case V4L2_CID_ZOOM_RELATIVE:
2563 case V4L2_CID_FOCUS_ABSOLUTE:
2565 ext_ctrl->value = sensor->info_priv.focus;
2568 case V4L2_CID_FOCUS_RELATIVE:
2572 case V4L2_CID_FLASH:
2574 ext_ctrl->value = sensor->info_priv.flash;
2582 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2584 const struct v4l2_queryctrl *qctrl;
2585 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2586 struct sensor *sensor = to_sensor(client);
2589 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2593 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2598 switch (ext_ctrl->id)
2600 #if CONFIG_SENSOR_Scene
2601 case V4L2_CID_SCENE:
2603 if (ext_ctrl->value != sensor->info_priv.scene)
2605 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2607 sensor->info_priv.scene = ext_ctrl->value;
2612 #if CONFIG_SENSOR_Effect
2613 case V4L2_CID_EFFECT:
2615 if (ext_ctrl->value != sensor->info_priv.effect)
2617 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2619 sensor->info_priv.effect= ext_ctrl->value;
2624 #if CONFIG_SENSOR_DigitalZoom
2625 case V4L2_CID_ZOOM_ABSOLUTE:
2627 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2630 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2632 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2634 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2636 sensor->info_priv.digitalzoom += val_offset;
2638 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2643 case V4L2_CID_ZOOM_RELATIVE:
2645 if (ext_ctrl->value)
2647 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2649 sensor->info_priv.digitalzoom += ext_ctrl->value;
2651 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2656 #if CONFIG_SENSOR_Focus
2657 case V4L2_CID_FOCUS_ABSOLUTE:
2659 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2662 if (ext_ctrl->value != sensor->info_priv.focus)
2664 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2666 sensor->info_priv.focus += val_offset;
2671 case V4L2_CID_FOCUS_RELATIVE:
2673 if (ext_ctrl->value)
2675 sensor->info_priv.focus += ext_ctrl->value;
2677 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2682 #if CONFIG_SENSOR_Flash
2683 case V4L2_CID_FLASH:
2685 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2687 sensor->info_priv.flash = ext_ctrl->value;
2689 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2700 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2702 struct i2c_client *client = v4l2_get_subdevdata(sd);
2703 struct soc_camera_device *icd = client->dev.platform_data;
2704 int i, error_cnt=0, error_idx=-1;
2707 for (i=0; i<ext_ctrl->count; i++) {
2708 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2715 error_idx = ext_ctrl->count;
2717 if (error_idx != -1) {
2718 ext_ctrl->error_idx = error_idx;
2725 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2727 struct i2c_client *client = v4l2_get_subdevdata(sd);
2728 struct soc_camera_device *icd = client->dev.platform_data;
2729 int i, error_cnt=0, error_idx=-1;
2732 for (i=0; i<ext_ctrl->count; i++) {
2733 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2740 error_idx = ext_ctrl->count;
2742 if (error_idx != -1) {
2743 ext_ctrl->error_idx = error_idx;
2750 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2751 * this wasn't our capture interface, so, we wait for the right one */
2752 static int sensor_video_probe(struct soc_camera_device *icd,
2753 struct i2c_client *client)
2757 struct sensor *sensor = to_sensor(client);
2759 /* We must have a parent by now. And it cannot be a wrong one.
2760 * So this entire test is completely redundant. */
2761 if (!icd->dev.parent ||
2762 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2765 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2767 goto sensor_video_probe_err;
2771 ret = sensor_write(client, 0xfe, 0x80);
2774 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2777 mdelay(5); //delay 5 microseconds
2779 /* check if it is an sensor sensor */
2780 ret = sensor_read(client, 0x00, &value);
2782 SENSOR_TR("read chip id high byte failed\n");
2784 goto sensor_video_probe_err;
2787 pid |= (value << 8);
2789 ret = sensor_read(client, 0x01, &value);
2791 SENSOR_TR("read chip id low byte failed\n");
2793 goto sensor_video_probe_err;
2796 pid |= (value & 0xff);
2797 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2798 if (pid == SENSOR_ID) {
2799 sensor->model = SENSOR_V4L2_IDENT;
2801 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2803 goto sensor_video_probe_err;
2808 sensor_video_probe_err:
2812 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2814 struct i2c_client *client = v4l2_get_subdevdata(sd);
2815 struct soc_camera_device *icd = client->dev.platform_data;
2816 struct sensor *sensor = to_sensor(client);
2818 #if CONFIG_SENSOR_Flash
2822 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2825 case RK29_CAM_SUBDEV_DEACTIVATE:
2827 sensor_deactivate(client);
2831 case RK29_CAM_SUBDEV_IOREQUEST:
2833 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2834 if (sensor->sensor_io_request != NULL) {
2835 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2836 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2837 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2838 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2839 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2840 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2843 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2845 goto sensor_ioctl_end;
2847 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2849 #if CONFIG_SENSOR_Flash
2850 if (sensor->sensor_gpio_res) {
2851 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2852 for (i = 0; i < icd->ops->num_controls; i++) {
2853 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2854 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2857 sensor->info_priv.flash = 0xff;
2858 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2866 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2874 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2875 enum v4l2_mbus_pixelcode *code)
2877 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2880 *code = sensor_colour_fmts[index].code;
2883 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2884 .init = sensor_init,
2885 .g_ctrl = sensor_g_control,
2886 .s_ctrl = sensor_s_control,
2887 .g_ext_ctrls = sensor_g_ext_controls,
2888 .s_ext_ctrls = sensor_s_ext_controls,
2889 .g_chip_ident = sensor_g_chip_ident,
2890 .ioctl = sensor_ioctl,
2893 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2894 .s_mbus_fmt = sensor_s_fmt,
2895 .g_mbus_fmt = sensor_g_fmt,
2896 .try_mbus_fmt = sensor_try_fmt,
2897 .enum_mbus_fmt = sensor_enum_fmt,
2900 static struct v4l2_subdev_ops sensor_subdev_ops = {
2901 .core = &sensor_subdev_core_ops,
2902 .video = &sensor_subdev_video_ops,
2905 static int sensor_probe(struct i2c_client *client,
2906 const struct i2c_device_id *did)
2908 struct sensor *sensor;
2909 struct soc_camera_device *icd = client->dev.platform_data;
2910 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2911 struct soc_camera_link *icl;
2914 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2916 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2920 icl = to_soc_camera_link(icd);
2922 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2926 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2927 dev_warn(&adapter->dev,
2928 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2932 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2936 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2938 /* Second stage probe - when a capture adapter is there */
2939 icd->ops = &sensor_ops;
2941 sensor->info_priv.fmt = sensor_colour_fmts[0];
2943 #if CONFIG_SENSOR_I2C_NOSCHED
2944 atomic_set(&sensor->tasklock_cnt,0);
2947 ret = sensor_video_probe(icd, client);
2950 i2c_set_clientdata(client, NULL);
2954 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2958 static int sensor_remove(struct i2c_client *client)
2960 struct sensor *sensor = to_sensor(client);
2961 struct soc_camera_device *icd = client->dev.platform_data;
2964 i2c_set_clientdata(client, NULL);
2965 client->driver = NULL;
2971 static const struct i2c_device_id sensor_id[] = {
2972 {SENSOR_NAME_STRING(), 0 },
2975 MODULE_DEVICE_TABLE(i2c, sensor_id);
2977 static struct i2c_driver sensor_i2c_driver = {
2979 .name = SENSOR_NAME_STRING(),
2981 .probe = sensor_probe,
2982 .remove = sensor_remove,
2983 .id_table = sensor_id,
2986 static int __init sensor_mod_init(void)
2988 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2989 return i2c_add_driver(&sensor_i2c_driver);
2992 static void __exit sensor_mod_exit(void)
2994 i2c_del_driver(&sensor_i2c_driver);
2997 device_initcall_sync(sensor_mod_init);
2998 module_exit(sensor_mod_exit);
3000 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3001 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3002 MODULE_LICENSE("GPL");