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_PIX_FMT_UYVY
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)
99 /* init SVGA preview */
100 static struct reginfo sensor_init_data[] =
103 {0xfe, 0x80}, //soft reset
104 {0xfe, 0x80}, //soft reset
105 {0xfe, 0x80}, //soft reset
107 {0xfe, 0x00}, //page0
108 {0x45, 0x00}, //output_disable
110 //////////////////////////////////////////////////////////////////////////////////////
111 //////////////////////////preview capture switch /////////////////////////////////////
112 //////////////////////////////////////////////////////////////////////////////////////
114 {0x02, 0x01}, //preview mode
115 {0x2a, 0xca}, //[7]col_binning, 0x[6]even skip
116 {0x48, 0x40}, //manual_gain
118 ////////////////////////////////////////////////////////////////////////
119 ////////////////////////// preview LSC /////////////////////////////////
120 ////////////////////////////////////////////////////////////////////////
121 {0xfe, 0x01}, //page1
122 {0xb0, 0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
123 {0xb1, 0x46}, //P_LSC_red_b2
124 {0xb2, 0x40}, //P_LSC_green_b2
125 {0xb3, 0x40}, //P_LSC_blue_b2
126 {0xb4, 0x24}, //P_LSC_red_b4
127 {0xb5, 0x20}, //P_LSC_green_b4
128 {0xb6, 0x22}, //P_LSC_blue_b4
129 {0xb7, 0x00}, //P_LSC_compensate_b2
130 {0xb8, 0x80}, //P_LSC_row_center, 0x344, 0x (1200/2-344)/2=128, 0x, 0x
131 {0xb9, 0x80}, //P_LSC_col_center, 0x544, 0x (1600/2-544)/2=128
134 ////////////////////////////////////////////////////////////////////////
135 ////////////////////////// capture LSC /////////////////////////////////
136 ////////////////////////////////////////////////////////////////////////
137 {0xba, 0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
138 {0xbb, 0x46}, //C_LSC_red_b2
139 {0xbc, 0x40}, //C_LSC_green_b2
140 {0xbd, 0x40}, //C_LSC_blue_b2
141 {0xbe, 0x24}, //C_LSC_red_b4
142 {0xbf, 0x20}, //C_LSC_green_b4
143 {0xc0, 0x22}, //C_LSC_blue_b4
144 {0xc1, 0x00}, //C_Lsc_compensate_b2
145 {0xc2, 0x80}, //C_LSC_row_center, 0x344, 0x (1200/2-344)/2=128
146 {0xc3, 0x80}, //C_LSC_col_center, 0x544, 0x (1600/2-544)/2=128
147 {0xfe, 0x00}, //page0
149 ////////////////////////////////////////////////////////////////////////
150 ////////////////////////// analog configure ///////////////////////////
151 ////////////////////////////////////////////////////////////////////////
152 {0xfe, 0x00}, //page0
153 {0x29, 0x00}, //cisctl mode 1
154 {0x2b, 0x06}, //cisctl mode 3
155 {0x32, 0x1c}, //analog mode 1
156 {0x33, 0x0f}, //analog mode 2
157 {0x34, 0x30}, //[6:4]da_rsg
159 {0x35, 0x88}, //Vref_A25
160 {0x37, 0x16}, //Drive Current
162 /////////////////////////////////////////////////////////////////////
163 /////////////////////////// ISP Related /////////////////////////////
164 /////////////////////////////////////////////////////////////////////
166 {0x41, 0x20}, //[5]skin_detectionenable[2]auto_gray, 0x[1]y_gamma
167 {0x42, 0xf6}, //[7]auto_sa[6]auto_ee[5]auto_dndd[4]auto_lsc[3]na[2]abs, 0x[1]awb
168 {0x4b, 0xe8}, //[1]AWB_gain_mode, 0x1:atpregain0:atpostgain
169 {0x4d, 0x03}, //[1]inbf_en
170 {0x4f, 0x01}, //AEC enable
172 ////////////////////////////////////////////////////////////////////
173 /////////////////////////// BLK //////////////////////////////////
174 ////////////////////////////////////////////////////////////////////
175 {0x63, 0x77}, //BLK mode 1
176 {0x66, 0x00}, //BLK global offset
178 {0x6e, 0x1a}, //BLK offset submode,offset R
187 ////////////////////////////////////////////////////////////////////
188 /////////////////////////// DNDD ///////////////////////////////////
189 ////////////////////////////////////////////////////////////////////
190 {0x80, 0x07}, //[7]dn_inc_or_dec [4]zero_weight_mode[3]share [2]c_weight_adap [1]dn_lsc_mode [0]dn_b
191 {0x82, 0x0c}, //DN lilat b base
194 ////////////////////////////////////////////////////////////////////
195 /////////////////////////// EEINTP ////////////////////////////////
196 ////////////////////////////////////////////////////////////////////
203 /////////////////////////////////////////////////////////////////////
204 /////////////////////////// CC_t ////////////////////////////////////
205 /////////////////////////////////////////////////////////////////////
206 {0xb0, 0x40}, // 0x48
217 /////////////////////////////////////////////////////////////////////
218 /////////////////////////// GAMMA ///////////////////////////////////
219 /////////////////////////////////////////////////////////////////////
257 /////////////////////////////////////////////////////////////////////
258 /////////////////////////// YCP_t ///////////////////////////////////
259 /////////////////////////////////////////////////////////////////////
260 {0xd1, 0x40}, //saturation 38
261 {0xd2, 0x40}, //saturation 38
263 {0xd3, 0x46}, // 2011-08-11 kim add
265 {0xde, 0x21}, //auto_gray
267 ////////////////////////////////////////////////////////////////////
268 /////////////////////////// ASDE ///////////////////////////////////
269 ////////////////////////////////////////////////////////////////////
277 {0xfe, 0x01}, //page1
283 ////////////////////////////////////////////////////////////////////
284 /////////////////////////// AEC ////////////////////////////////////
285 ////////////////////////////////////////////////////////////////////
286 {0x10, 0x09}, //AEC mode 1
287 {0x11, 0x92}, //[7]fix target // 0xb2 2011-08-11 kim
289 {0x13, 0x78}, // 0x78 2011-08-11 kim
292 {0x1d, 0x04}, // sunlight step
294 {0x21, 0xc0}, //max_post_gain
295 {0x22, 0x40}, //max_pre_gain // 0x60 2011-08-11 kim
296 {0x2d, 0x06}, //P_N_AEC_exp_level_1[12:8]
297 {0x2e, 0x00}, //P_N_AEC_exp_level_1[7:0]
299 {0x33, 0x00}, //[6:5]max_exp_level [4:0]min_exp_level
300 {0x34, 0x04}, // min exp
302 ////////////////////////////////////////////////////////////////////
303 /////////////////////////// Measure Window /////////////////////////
304 ////////////////////////////////////////////////////////////////////
310 ////////////////////////////////////////////////////////////////////
311 /////////////////////////// AWB ////////////////////////////////////
312 ////////////////////////////////////////////////////////////////////
313 {0x57, 0x40}, //number limit
315 {0x5c, 0x35}, //show mode,close dark_mode
316 {0x5e, 0x29}, //close color temp
320 ////////////////////////////////////////////////////////////////////
321 /////////////////////////// ABS ////////////////////////////////////
322 ////////////////////////////////////////////////////////////////////
328 {0x83, 0x10}, //ABS Y stretch limit
330 ////////////////////////////////////////////////////////////////////
331 /////////////////////////// OUT ////////////////////////////////////
332 ////////////////////////////////////////////////////////////////////
345 {0x44, 0xa0}, //YUV sequence
346 {0x45, 0x0f}, //output enable
347 {0x46, 0x02}, //sync mode
373 {0x29, 0x00},//Anti Step 128
376 {0x2b, 0x05},//Level_0 10.00fps
378 {0x2d, 0x06},//Level_1 8.33fps
380 {0x2f, 0x08},//Level_2 6.25fps
382 {0x31, 0x09},//Level_3 5.55fps
387 //--------------------Updated By Mormo 2011/08/08 Start --------------------//
391 //--------------------Updated By Mormo 2011/08/08 End ---------------------//
400 /* 1600X1200 UXGA capture */
401 static struct reginfo sensor_uxga[] =
407 {0x4f, 0x00}, // aec off
438 static struct reginfo sensor_sxga[] =
444 {0x4f, 0x00}, // aec off
474 static struct reginfo sensor_xga[] =
480 {0x4f, 0x00}, // aec off
484 //subsample 1600x1200 to 1066x800
485 {0x59 , 0x33},//out window
496 {0x50 , 0x01},//out window
507 /* 800X600 SVGA,30fps*/
508 static struct reginfo sensor_svga[] =
513 {0x4f, 0x01}, // aec on
530 {0x50 , 0x01},//out window
543 static struct reginfo sensor_vga[] =
550 {0x4f, 0x01}, // aec on
556 {0x59 , 0x55},//out window
567 {0x50 , 0x01},//out window
576 {0x45 , 0x0f}, //output enable
581 static struct reginfo sensor_cif[] =
585 static struct reginfo sensor_qvga[] =
589 static struct reginfo sensor_qcif[] =
593 static struct reginfo ov2655_qqvga[] =
600 static struct reginfo ov2655_Sharpness_auto[] =
606 static struct reginfo ov2655_Sharpness1[] =
612 static struct reginfo ov2655_Sharpness2[][3] =
619 static struct reginfo ov2655_Sharpness3[] =
625 static struct reginfo ov2655_Sharpness4[]=
632 static struct reginfo ov2655_Sharpness5[] =
640 static struct reginfo sensor_ClrFmt_YUYV[]=
646 static struct reginfo sensor_ClrFmt_UYVY[]=
652 #if CONFIG_SENSOR_WhiteBalance
653 static struct reginfo sensor_WhiteB_Auto[]=
658 /* Cloudy Colour Temperature : 6500K - 8000K */
659 static struct reginfo sensor_WhiteB_Cloudy[]=
662 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
663 {0x7a , 0x8c}, //AWB_R_gain
664 {0x7b , 0x50}, //AWB_G_gain
665 {0x7c , 0x40}, //AWB_B_gain
668 /* ClearDay Colour Temperature : 5000K - 6500K */
669 static struct reginfo sensor_WhiteB_ClearDay[]=
672 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
673 {0x7a , 0x74}, //AWB_R_gain
674 {0x7b , 0x52}, //AWB_G_gain
675 {0x7c , 0x40}, //AWB_B_gain
678 /* Office Colour Temperature : 3500K - 5000K */
679 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
682 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
683 {0x7a , 0x48}, //AWB_R_gain
684 {0x7b , 0x40}, //AWB_G_gain
685 {0x7c , 0x5c}, //AWB_B_gain
689 /* Home Colour Temperature : 2500K - 3500K */
690 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
693 {0x42 , 0x74},// [1] AWB enable ¹¦ÄÜ¿ª¹ØAWB OFF
694 {0x7a , 0x40}, //AWB_R_gain
695 {0x7b , 0x54}, //AWB_G_gain
696 {0x7c , 0x70}, //AWB_B_gain
699 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
700 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
704 #if CONFIG_SENSOR_Brightness
705 static struct reginfo sensor_Brightness0[]=
710 {0x13, 0x68}, //AEC_target_Y
712 {0xd5, 0xe0},// Luma_offset
716 static struct reginfo sensor_Brightness1[]=
720 {0x13, 0x70}, //AEC_target_Y
722 {0xd5, 0xf0},// Luma_offset
727 static struct reginfo sensor_Brightness2[]=
732 {0x13, 0x78}, //AEC_target_Y 48
734 {0xd5, 0x00},// Luma_offset c0
739 static struct reginfo sensor_Brightness3[]=
743 {0x13, 0x80}, //AEC_target_Y
745 {0xd5, 0x10},// Luma_offset
750 static struct reginfo sensor_Brightness4[]=
754 {0x13, 0x88}, //AEC_target_Y
756 {0xd5, 0x20},// Luma_offset
761 static struct reginfo sensor_Brightness5[]=
765 {0x13, 0x90}, //AEC_target_Y
767 {0xd5, 0x30},// Luma_offset
770 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
771 sensor_Brightness4, sensor_Brightness5,NULL,
776 #if CONFIG_SENSOR_Effect
777 static struct reginfo sensor_Effect_Normal[] =
784 static struct reginfo sensor_Effect_WandB[] =
792 static struct reginfo sensor_Effect_Sepia[] =
800 static struct reginfo sensor_Effect_Negative[] =
808 static struct reginfo sensor_Effect_Bluish[] =
818 static struct reginfo sensor_Effect_Green[] =
826 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
827 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
830 #if CONFIG_SENSOR_Exposure
831 static struct reginfo sensor_Exposure0[]=
837 static struct reginfo sensor_Exposure1[]=
844 static struct reginfo sensor_Exposure2[]=
851 static struct reginfo sensor_Exposure3[]=
858 static struct reginfo sensor_Exposure4[]=
865 static struct reginfo sensor_Exposure5[]=
872 static struct reginfo sensor_Exposure6[]=
879 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
880 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
883 #if CONFIG_SENSOR_Saturation
884 static struct reginfo sensor_Saturation0[]=
890 static struct reginfo sensor_Saturation1[]=
896 static struct reginfo sensor_Saturation2[]=
901 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
904 #if CONFIG_SENSOR_Contrast
905 static struct reginfo sensor_Contrast0[]=
913 static struct reginfo sensor_Contrast1[]=
921 static struct reginfo sensor_Contrast2[]=
929 static struct reginfo sensor_Contrast3[]=
937 static struct reginfo sensor_Contrast4[]=
946 static struct reginfo sensor_Contrast5[]=
954 static struct reginfo sensor_Contrast6[]=
961 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
962 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
966 #if CONFIG_SENSOR_Mirror
967 static struct reginfo sensor_MirrorOn[]=
973 static struct reginfo sensor_MirrorOff[]=
978 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
980 #if CONFIG_SENSOR_Flip
981 static struct reginfo sensor_FlipOn[]=
987 static struct reginfo sensor_FlipOff[]=
992 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
995 #if CONFIG_SENSOR_Scene
996 static struct reginfo sensor_SceneAuto[] =
998 /* ddl@rock-chips.com : */
1007 static struct reginfo sensor_SceneNight[] =
1010 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1017 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1020 #if CONFIG_SENSOR_DigitalZoom
1021 static struct reginfo sensor_Zoom0[] =
1026 static struct reginfo sensor_Zoom1[] =
1031 static struct reginfo sensor_Zoom2[] =
1037 static struct reginfo sensor_Zoom3[] =
1041 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1043 static const struct v4l2_querymenu sensor_menus[] =
1045 #if CONFIG_SENSOR_WhiteBalance
1046 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1047 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1048 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1051 #if CONFIG_SENSOR_Effect
1052 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1053 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1054 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1057 #if CONFIG_SENSOR_Scene
1058 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1061 #if CONFIG_SENSOR_Flash
1062 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1063 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1067 static const struct v4l2_queryctrl sensor_controls[] =
1069 #if CONFIG_SENSOR_WhiteBalance
1071 .id = V4L2_CID_DO_WHITE_BALANCE,
1072 .type = V4L2_CTRL_TYPE_MENU,
1073 .name = "White Balance Control",
1081 #if CONFIG_SENSOR_Brightness
1083 .id = V4L2_CID_BRIGHTNESS,
1084 .type = V4L2_CTRL_TYPE_INTEGER,
1085 .name = "Brightness Control",
1093 #if CONFIG_SENSOR_Effect
1095 .id = V4L2_CID_EFFECT,
1096 .type = V4L2_CTRL_TYPE_MENU,
1097 .name = "Effect Control",
1105 #if CONFIG_SENSOR_Exposure
1107 .id = V4L2_CID_EXPOSURE,
1108 .type = V4L2_CTRL_TYPE_INTEGER,
1109 .name = "Exposure Control",
1117 #if CONFIG_SENSOR_Saturation
1119 .id = V4L2_CID_SATURATION,
1120 .type = V4L2_CTRL_TYPE_INTEGER,
1121 .name = "Saturation Control",
1129 #if CONFIG_SENSOR_Contrast
1131 .id = V4L2_CID_CONTRAST,
1132 .type = V4L2_CTRL_TYPE_INTEGER,
1133 .name = "Contrast Control",
1141 #if CONFIG_SENSOR_Mirror
1143 .id = V4L2_CID_HFLIP,
1144 .type = V4L2_CTRL_TYPE_BOOLEAN,
1145 .name = "Mirror Control",
1153 #if CONFIG_SENSOR_Flip
1155 .id = V4L2_CID_VFLIP,
1156 .type = V4L2_CTRL_TYPE_BOOLEAN,
1157 .name = "Flip Control",
1165 #if CONFIG_SENSOR_Scene
1167 .id = V4L2_CID_SCENE,
1168 .type = V4L2_CTRL_TYPE_MENU,
1169 .name = "Scene Control",
1177 #if CONFIG_SENSOR_DigitalZoom
1179 .id = V4L2_CID_ZOOM_RELATIVE,
1180 .type = V4L2_CTRL_TYPE_INTEGER,
1181 .name = "DigitalZoom Control",
1187 .id = V4L2_CID_ZOOM_ABSOLUTE,
1188 .type = V4L2_CTRL_TYPE_INTEGER,
1189 .name = "DigitalZoom Control",
1197 #if CONFIG_SENSOR_Focus
1199 .id = V4L2_CID_FOCUS_RELATIVE,
1200 .type = V4L2_CTRL_TYPE_INTEGER,
1201 .name = "Focus Control",
1207 .id = V4L2_CID_FOCUS_ABSOLUTE,
1208 .type = V4L2_CTRL_TYPE_INTEGER,
1209 .name = "Focus Control",
1213 .default_value = 125,
1217 #if CONFIG_SENSOR_Flash
1219 .id = V4L2_CID_FLASH,
1220 .type = V4L2_CTRL_TYPE_MENU,
1221 .name = "Flash Control",
1230 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1231 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1232 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1233 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1234 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1235 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1236 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1237 static int sensor_resume(struct soc_camera_device *icd);
1238 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1239 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1240 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1241 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1242 static int sensor_deactivate(struct i2c_client *client);
1243 static int sensor_write(struct i2c_client *client, u8 reg, u8 val);
1244 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val);
1247 static u16 GC2015_read_shutter(struct i2c_client *client); // add 2011-08-11 kim
1248 static void GC2015_set_shutter(struct i2c_client *client, u16 shutter); // add 2011-08-11 kim
1251 ////// add 2011-08-11 kim
1252 static u16 GC2015_read_shutter(struct i2c_client *client)
1254 u8 temp_reg1, temp_reg2;
1257 /* Backup the preview mode last shutter & sensor gain. */
1258 sensor_read(client, 0x03, &temp_reg1);
1259 sensor_read(client, 0x04, &temp_reg2);
1261 shutter = (temp_reg1 << 8) | (temp_reg2 & 0xFF);
1264 } /* GC2015_read_shutter */
1266 static void GC2015_set_shutter(struct i2c_client *client, u16 shutter)
1270 temp_reg = shutter * 10 / 20; ////
1272 /*Set Shutter start*/
1273 if(temp_reg < 1) temp_reg = 1;
1274 sensor_write(client ,0x03 , (temp_reg>>8)&0xff);
1275 sensor_write(client ,0x04 , temp_reg&0xff);
1278 //////// end add kim
1280 static struct soc_camera_ops sensor_ops =
1282 .suspend = sensor_suspend,
1283 .resume = sensor_resume,
1284 .set_bus_param = sensor_set_bus_param,
1285 .query_bus_param = sensor_query_bus_param,
1286 .controls = sensor_controls,
1287 .menus = sensor_menus,
1288 .num_controls = ARRAY_SIZE(sensor_controls),
1289 .num_menus = ARRAY_SIZE(sensor_menus),
1292 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1293 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1294 .colorspace = _colorspace }
1296 #define JPG_FMT(_name, _depth, _fourcc) \
1297 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1299 static const struct soc_camera_data_format sensor_colour_formats[] = {
1300 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1301 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1304 typedef struct sensor_info_priv_s
1318 unsigned char mirror; /* HFLIP */
1319 unsigned char flip; /* VFLIP */
1320 unsigned int winseqe_cur_addr;
1321 unsigned int pixfmt;
1323 } sensor_info_priv_t;
1327 struct v4l2_subdev subdev;
1328 struct i2c_client *client;
1329 sensor_info_priv_t info_priv;
1330 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1331 #if CONFIG_SENSOR_I2C_NOSCHED
1332 atomic_t tasklock_cnt;
1334 struct rk29camera_platform_data *sensor_io_request;
1335 struct rk29camera_gpio_res *sensor_gpio_res;
1338 static struct sensor* to_sensor(const struct i2c_client *client)
1340 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1343 static int sensor_task_lock(struct i2c_client *client, int lock)
1345 #if CONFIG_SENSOR_I2C_NOSCHED
1347 struct sensor *sensor = to_sensor(client);
1350 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1351 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1352 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1356 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1357 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1358 goto sensor_task_lock_err;
1363 atomic_add(1, &sensor->tasklock_cnt);
1365 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1366 atomic_sub(1, &sensor->tasklock_cnt);
1368 if (atomic_read(&sensor->tasklock_cnt) == 0)
1373 sensor_task_lock_err:
1382 /* sensor register */
1383 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1387 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1389 return (ret > 0)? 0 : ret;
1392 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1396 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1398 return (ret > 0)? 0 : ret;
1401 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1405 struct i2c_msg msg[1];
1413 msg->addr = client->addr;
1414 msg->flags = client->flags;
1416 msg->len = sizeof(buf);
1417 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1418 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1423 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1424 err = i2c_transfer(client->adapter, msg, 1);
1429 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1437 /* sensor register read */
1438 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1442 struct i2c_msg msg[2];
1446 msg[0].addr = client->addr;
1447 msg[0].flags = client->flags;
1449 msg[0].len = sizeof(buf);
1450 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1451 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1453 msg[1].addr = client->addr;
1454 msg[1].flags = client->flags|I2C_M_RD;
1457 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1458 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1462 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1463 err = i2c_transfer(client->adapter, msg, 2);
1469 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1479 /* write a array of registers */
1480 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1484 #if CONFIG_SENSOR_I2C_RDWRCHK
1489 if (sensor_task_lock(client, 1) < 0)
1490 goto sensor_write_array_end;
1491 while (regarray[i].reg != 0)
1493 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1497 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1501 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1503 goto sensor_write_array_end;
1506 #if CONFIG_SENSOR_I2C_RDWRCHK
1508 sensor_read(client, regarray[i].reg, &valchk);
1509 if (valchk != regarray[i].val)
1510 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1516 sensor_write_array_end:
1517 sensor_task_lock(client,0);
1520 #if CONFIG_SENSOR_I2C_RDWRCHK
1521 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1529 while (regarray[i].reg != 0)
1531 sensor_read(client, regarray[i].reg, &valchk);
1532 if (valchk != regarray[i].val)
1533 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1540 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1542 struct soc_camera_link *icl = to_soc_camera_link(icd);
1545 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1548 case Sensor_PowerDown:
1550 if (icl->powerdown) {
1551 ret = icl->powerdown(icd->pdev, on);
1552 if (ret == RK29_CAM_IO_SUCCESS) {
1556 icl->reset(icd->pdev);
1558 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1560 goto sensor_power_end;
1567 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1568 struct sensor *sensor = to_sensor(client);
1570 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1571 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1577 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1584 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1586 struct i2c_client *client = sd->priv;
1587 struct soc_camera_device *icd = client->dev.platform_data;
1588 struct sensor *sensor = to_sensor(client);
1589 const struct v4l2_queryctrl *qctrl;
1593 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1595 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1597 goto sensor_INIT_ERR;
1601 if (sensor_task_lock(client,1)<0)
1602 goto sensor_INIT_ERR;
1603 ret = sensor_write(client, 0xfe, 0x80);
1606 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1608 goto sensor_INIT_ERR;
1611 mdelay(5); //delay 5 microseconds
1612 /* check if it is an sensor sensor */
1613 ret = sensor_read(client, 0x00, &value);
1615 SENSOR_TR("read chip id high byte failed\n");
1617 goto sensor_INIT_ERR;
1620 pid |= (value << 8);
1622 ret = sensor_read(client, 0x01, &value);
1624 SENSOR_TR("read chip id low byte failed\n");
1626 goto sensor_INIT_ERR;
1629 pid |= (value & 0xff);
1630 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1631 if (pid == SENSOR_ID) {
1632 sensor->model = SENSOR_V4L2_IDENT;
1634 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1636 goto sensor_INIT_ERR;
1639 ret = sensor_write_array(client, sensor_init_data);
1642 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1643 goto sensor_INIT_ERR;
1645 sensor_task_lock(client,0);
1646 //icd->user_width = SENSOR_INIT_WIDTH;
1647 //icd->user_height = SENSOR_INIT_HEIGHT;
1648 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1649 sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
1651 /* sensor sensor information for initialization */
1652 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1654 sensor->info_priv.whiteBalance = qctrl->default_value;
1655 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1657 sensor->info_priv.brightness = qctrl->default_value;
1658 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1660 sensor->info_priv.effect = qctrl->default_value;
1661 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1663 sensor->info_priv.exposure = qctrl->default_value;
1665 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1667 sensor->info_priv.saturation = qctrl->default_value;
1668 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1670 sensor->info_priv.contrast = qctrl->default_value;
1671 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1673 sensor->info_priv.mirror = qctrl->default_value;
1674 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1676 sensor->info_priv.flip = qctrl->default_value;
1677 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1679 sensor->info_priv.scene = qctrl->default_value;
1680 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1682 sensor->info_priv.digitalzoom = qctrl->default_value;
1684 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1685 #if CONFIG_SENSOR_Focus
1687 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1689 sensor->info_priv.focus = qctrl->default_value;
1692 #if CONFIG_SENSOR_Flash
1693 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1695 sensor->info_priv.flash = qctrl->default_value;
1698 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);
1702 sensor_task_lock(client,0);
1703 sensor_deactivate(client);
1707 static int sensor_deactivate(struct i2c_client *client)
1709 struct soc_camera_device *icd = client->dev.platform_data;
1711 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1713 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1714 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1716 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1717 icd->user_width = SENSOR_INIT_WIDTH;
1718 icd->user_height = SENSOR_INIT_HEIGHT;
1723 static struct reginfo sensor_power_down_sequence[]=
1727 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1730 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1732 if (pm_msg.event == PM_EVENT_SUSPEND) {
1733 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1734 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1736 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1739 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1741 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1746 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1752 static int sensor_resume(struct soc_camera_device *icd)
1756 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1758 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1762 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1768 static int sensor_set_bus_param(struct soc_camera_device *icd,
1769 unsigned long flags)
1775 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1777 struct soc_camera_link *icl = to_soc_camera_link(icd);
1778 unsigned long flags = SENSOR_BUS_PARAM;
1780 return soc_camera_apply_sensor_flags(icl, flags);
1783 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1785 struct i2c_client *client = sd->priv;
1786 struct soc_camera_device *icd = client->dev.platform_data;
1787 struct sensor *sensor = to_sensor(client);
1788 struct v4l2_pix_format *pix = &f->fmt.pix;
1790 pix->width = icd->user_width;
1791 pix->height = icd->user_height;
1792 pix->pixelformat = sensor->info_priv.pixfmt;
1793 pix->field = V4L2_FIELD_NONE;
1794 pix->colorspace = V4L2_COLORSPACE_JPEG;
1798 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_format *f)
1802 if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
1804 } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
1806 } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
1808 } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
1810 } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
1815 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1819 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_format *f)
1823 if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 720)) {
1825 } else if ((f->fmt.pix.width == 1920) && (f->fmt.pix.height == 1080)) {
1830 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1833 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1835 struct i2c_client *client = sd->priv;
1836 struct sensor *sensor = to_sensor(client);
1837 struct v4l2_pix_format *pix = &f->fmt.pix;
1838 const struct v4l2_queryctrl *qctrl;
1839 struct soc_camera_device *icd = client->dev.platform_data;
1840 struct reginfo *winseqe_set_addr=NULL;
1841 int ret=0, set_w,set_h;
1845 SENSOR_TR("sensor_s_fmt\n");
1846 if (sensor->info_priv.pixfmt != pix->pixelformat) {
1847 switch (pix->pixelformat)
1849 case V4L2_PIX_FMT_YUYV:
1851 winseqe_set_addr = sensor_ClrFmt_YUYV;
1854 case V4L2_PIX_FMT_UYVY:
1856 winseqe_set_addr = sensor_ClrFmt_UYVY;
1862 if (winseqe_set_addr != NULL) {
1863 sensor_write_array(client, winseqe_set_addr);
1864 sensor->info_priv.pixfmt = pix->pixelformat;
1866 SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1868 SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1873 set_h = pix->height;
1875 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1877 winseqe_set_addr = sensor_qcif;
1881 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1883 winseqe_set_addr = sensor_qvga;
1887 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1889 winseqe_set_addr = sensor_cif;
1893 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1895 winseqe_set_addr = sensor_vga;
1899 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1901 winseqe_set_addr = sensor_svga;
1905 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1907 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1909 winseqe_set_addr = sensor_xga;
1913 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1915 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1917 winseqe_set_addr = sensor_sxga;
1921 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1924 gc2015_shutter = GC2015_read_shutter(client); // add 2011-08-11 kim
1926 winseqe_set_addr = sensor_uxga;
1932 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1933 set_w = SENSOR_INIT_WIDTH;
1934 set_h = SENSOR_INIT_HEIGHT;
1935 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1938 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1939 #if CONFIG_SENSOR_Flash
1940 if (sensor_fmt_capturechk(sd,f) == true) { /* ddl@rock-chips.com : Capture */
1941 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1942 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1943 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1945 } else { /* ddl@rock-chips.com : Video */
1946 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1947 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1948 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1952 ret |= sensor_write_array(client, winseqe_set_addr);
1954 if(set_w >= 1024) GC2015_set_shutter(client, gc2015_shutter); // add 2011-08-11 kim
1957 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1958 #if CONFIG_SENSOR_Flash
1959 if (sensor_fmt_capturechk(sd,f) == true) {
1960 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1961 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1962 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1966 goto sensor_s_fmt_end;
1969 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1971 if (sensor_fmt_capturechk(sd,f) == true) { /* ddl@rock-chips.com : Capture */
1972 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1973 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1974 if (sensor->info_priv.whiteBalance != 0) {
1975 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1976 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1978 sensor->info_priv.snap2preview = true;
1979 } else if (sensor_fmt_videochk(sd,f) == true) { /* ddl@rock-chips.com : Video */
1980 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1981 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1982 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1983 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1984 sensor->info_priv.video2preview = true;
1985 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1986 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1987 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1988 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1989 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1990 sensor->info_priv.video2preview = false;
1991 sensor->info_priv.snap2preview = false;
1993 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1997 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2001 pix->height = set_h;
2007 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2009 struct v4l2_pix_format *pix = &f->fmt.pix;
2010 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
2011 pix->pixelformat == V4L2_PIX_FMT_YUYV;
2014 * With Bayer format enforce even side lengths, but let the user play
2015 * with the starting pixel
2018 if (pix->height > SENSOR_MAX_HEIGHT)
2019 pix->height = SENSOR_MAX_HEIGHT;
2020 else if (pix->height < SENSOR_MIN_HEIGHT)
2021 pix->height = SENSOR_MIN_HEIGHT;
2023 pix->height = ALIGN(pix->height, 2);
2025 if (pix->width > SENSOR_MAX_WIDTH)
2026 pix->width = SENSOR_MAX_WIDTH;
2027 else if (pix->width < SENSOR_MIN_WIDTH)
2028 pix->width = SENSOR_MIN_WIDTH;
2030 pix->width = ALIGN(pix->width, 2);
2035 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2037 struct i2c_client *client = sd->priv;
2039 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2042 if (id->match.addr != client->addr)
2045 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2050 #if CONFIG_SENSOR_Brightness
2051 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2053 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2055 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2057 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2059 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2061 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2064 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2068 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2072 #if CONFIG_SENSOR_Effect
2073 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2075 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2077 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2079 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2081 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2083 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2086 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2090 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2094 #if CONFIG_SENSOR_Exposure
2095 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2097 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2099 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2101 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2103 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2105 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2108 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2112 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2116 #if CONFIG_SENSOR_Saturation
2117 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2119 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2121 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2123 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2125 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2127 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2130 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2134 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2138 #if CONFIG_SENSOR_Contrast
2139 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2141 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2143 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2145 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2147 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2149 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2152 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2156 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2160 #if CONFIG_SENSOR_Mirror
2161 static int sensor_set_mirror(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_MirrorSeqe[value - qctrl->minimum] != NULL)
2169 if (sensor_write_array(client, sensor_MirrorSeqe[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_Flip
2183 static int sensor_set_flip(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_FlipSeqe[value - qctrl->minimum] != NULL)
2191 if (sensor_write_array(client, sensor_FlipSeqe[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_Scene
2205 static int sensor_set_scene(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_SceneSeqe[value - qctrl->minimum] != NULL)
2213 if (sensor_write_array(client, sensor_SceneSeqe[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_WhiteBalance
2227 static int sensor_set_whiteBalance(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_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2235 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[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_DigitalZoom
2249 static int sensor_set_digitalzoom(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));
2252 struct sensor *sensor = to_sensor(client);
2253 const struct v4l2_queryctrl *qctrl_info;
2254 int digitalzoom_cur, digitalzoom_total;
2256 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2260 digitalzoom_cur = sensor->info_priv.digitalzoom;
2261 digitalzoom_total = qctrl_info->maximum;
2263 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2265 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2269 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2271 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2275 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2277 *value = digitalzoom_total - digitalzoom_cur;
2280 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2282 *value = 0 - digitalzoom_cur;
2285 digitalzoom_cur += *value;
2287 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2289 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2291 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2294 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2301 #if CONFIG_SENSOR_Flash
2302 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2304 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2305 if (value == 3) { /* ddl@rock-chips.com: torch */
2306 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2308 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2310 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2314 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2319 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2321 struct i2c_client *client = sd->priv;
2322 struct sensor *sensor = to_sensor(client);
2323 const struct v4l2_queryctrl *qctrl;
2325 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2329 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2335 case V4L2_CID_BRIGHTNESS:
2337 ctrl->value = sensor->info_priv.brightness;
2340 case V4L2_CID_SATURATION:
2342 ctrl->value = sensor->info_priv.saturation;
2345 case V4L2_CID_CONTRAST:
2347 ctrl->value = sensor->info_priv.contrast;
2350 case V4L2_CID_DO_WHITE_BALANCE:
2352 ctrl->value = sensor->info_priv.whiteBalance;
2355 case V4L2_CID_EXPOSURE:
2357 ctrl->value = sensor->info_priv.exposure;
2360 case V4L2_CID_HFLIP:
2362 ctrl->value = sensor->info_priv.mirror;
2365 case V4L2_CID_VFLIP:
2367 ctrl->value = sensor->info_priv.flip;
2378 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2380 struct i2c_client *client = sd->priv;
2381 struct sensor *sensor = to_sensor(client);
2382 struct soc_camera_device *icd = client->dev.platform_data;
2383 const struct v4l2_queryctrl *qctrl;
2386 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2390 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2396 #if CONFIG_SENSOR_Brightness
2397 case V4L2_CID_BRIGHTNESS:
2399 if (ctrl->value != sensor->info_priv.brightness)
2401 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2405 sensor->info_priv.brightness = ctrl->value;
2410 #if CONFIG_SENSOR_Exposure
2411 case V4L2_CID_EXPOSURE:
2413 if (ctrl->value != sensor->info_priv.exposure)
2415 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2419 sensor->info_priv.exposure = ctrl->value;
2424 #if CONFIG_SENSOR_Saturation
2425 case V4L2_CID_SATURATION:
2427 if (ctrl->value != sensor->info_priv.saturation)
2429 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2433 sensor->info_priv.saturation = ctrl->value;
2438 #if CONFIG_SENSOR_Contrast
2439 case V4L2_CID_CONTRAST:
2441 if (ctrl->value != sensor->info_priv.contrast)
2443 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2447 sensor->info_priv.contrast = ctrl->value;
2452 #if CONFIG_SENSOR_WhiteBalance
2453 case V4L2_CID_DO_WHITE_BALANCE:
2455 if (ctrl->value != sensor->info_priv.whiteBalance)
2457 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2461 sensor->info_priv.whiteBalance = ctrl->value;
2466 #if CONFIG_SENSOR_Mirror
2467 case V4L2_CID_HFLIP:
2469 if (ctrl->value != sensor->info_priv.mirror)
2471 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2473 sensor->info_priv.mirror = ctrl->value;
2478 #if CONFIG_SENSOR_Flip
2479 case V4L2_CID_VFLIP:
2481 if (ctrl->value != sensor->info_priv.flip)
2483 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2485 sensor->info_priv.flip = ctrl->value;
2496 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2498 const struct v4l2_queryctrl *qctrl;
2499 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2500 struct sensor *sensor = to_sensor(client);
2502 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2506 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2510 switch (ext_ctrl->id)
2512 case V4L2_CID_SCENE:
2514 ext_ctrl->value = sensor->info_priv.scene;
2517 case V4L2_CID_EFFECT:
2519 ext_ctrl->value = sensor->info_priv.effect;
2522 case V4L2_CID_ZOOM_ABSOLUTE:
2524 ext_ctrl->value = sensor->info_priv.digitalzoom;
2527 case V4L2_CID_ZOOM_RELATIVE:
2531 case V4L2_CID_FOCUS_ABSOLUTE:
2533 ext_ctrl->value = sensor->info_priv.focus;
2536 case V4L2_CID_FOCUS_RELATIVE:
2540 case V4L2_CID_FLASH:
2542 ext_ctrl->value = sensor->info_priv.flash;
2550 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2552 const struct v4l2_queryctrl *qctrl;
2553 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2554 struct sensor *sensor = to_sensor(client);
2557 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2561 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2566 switch (ext_ctrl->id)
2568 #if CONFIG_SENSOR_Scene
2569 case V4L2_CID_SCENE:
2571 if (ext_ctrl->value != sensor->info_priv.scene)
2573 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2575 sensor->info_priv.scene = ext_ctrl->value;
2580 #if CONFIG_SENSOR_Effect
2581 case V4L2_CID_EFFECT:
2583 if (ext_ctrl->value != sensor->info_priv.effect)
2585 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2587 sensor->info_priv.effect= ext_ctrl->value;
2592 #if CONFIG_SENSOR_DigitalZoom
2593 case V4L2_CID_ZOOM_ABSOLUTE:
2595 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2598 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2600 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2602 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2604 sensor->info_priv.digitalzoom += val_offset;
2606 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2611 case V4L2_CID_ZOOM_RELATIVE:
2613 if (ext_ctrl->value)
2615 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2617 sensor->info_priv.digitalzoom += ext_ctrl->value;
2619 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2624 #if CONFIG_SENSOR_Focus
2625 case V4L2_CID_FOCUS_ABSOLUTE:
2627 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2630 if (ext_ctrl->value != sensor->info_priv.focus)
2632 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2634 sensor->info_priv.focus += val_offset;
2639 case V4L2_CID_FOCUS_RELATIVE:
2641 if (ext_ctrl->value)
2643 sensor->info_priv.focus += ext_ctrl->value;
2645 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2650 #if CONFIG_SENSOR_Flash
2651 case V4L2_CID_FLASH:
2653 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2655 sensor->info_priv.flash = ext_ctrl->value;
2657 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2668 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2670 struct i2c_client *client = sd->priv;
2671 struct soc_camera_device *icd = client->dev.platform_data;
2672 int i, error_cnt=0, error_idx=-1;
2675 for (i=0; i<ext_ctrl->count; i++) {
2676 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2683 error_idx = ext_ctrl->count;
2685 if (error_idx != -1) {
2686 ext_ctrl->error_idx = error_idx;
2693 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2695 struct i2c_client *client = sd->priv;
2696 struct soc_camera_device *icd = client->dev.platform_data;
2697 int i, error_cnt=0, error_idx=-1;
2700 for (i=0; i<ext_ctrl->count; i++) {
2701 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2708 error_idx = ext_ctrl->count;
2710 if (error_idx != -1) {
2711 ext_ctrl->error_idx = error_idx;
2718 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2719 * this wasn't our capture interface, so, we wait for the right one */
2720 static int sensor_video_probe(struct soc_camera_device *icd,
2721 struct i2c_client *client)
2725 struct sensor *sensor = to_sensor(client);
2727 /* We must have a parent by now. And it cannot be a wrong one.
2728 * So this entire test is completely redundant. */
2729 if (!icd->dev.parent ||
2730 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2733 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2735 goto sensor_video_probe_err;
2739 ret = sensor_write(client, 0xfe, 0x80);
2742 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2745 mdelay(5); //delay 5 microseconds
2747 /* check if it is an sensor sensor */
2748 ret = sensor_read(client, 0x00, &value);
2750 SENSOR_TR("read chip id high byte failed\n");
2752 goto sensor_video_probe_err;
2755 pid |= (value << 8);
2757 ret = sensor_read(client, 0x01, &value);
2759 SENSOR_TR("read chip id low byte failed\n");
2761 goto sensor_video_probe_err;
2764 pid |= (value & 0xff);
2765 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2766 if (pid == SENSOR_ID) {
2767 sensor->model = SENSOR_V4L2_IDENT;
2769 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2771 goto sensor_video_probe_err;
2774 icd->formats = sensor_colour_formats;
2775 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2779 sensor_video_probe_err:
2783 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2785 struct i2c_client *client = sd->priv;
2786 struct soc_camera_device *icd = client->dev.platform_data;
2787 struct sensor *sensor = to_sensor(client);
2789 #if CONFIG_SENSOR_Flash
2793 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2796 case RK29_CAM_SUBDEV_DEACTIVATE:
2798 sensor_deactivate(client);
2802 case RK29_CAM_SUBDEV_IOREQUEST:
2804 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2805 if (sensor->sensor_io_request != NULL) {
2806 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2807 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2808 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2809 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2810 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2811 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2814 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2816 goto sensor_ioctl_end;
2818 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2820 #if CONFIG_SENSOR_Flash
2821 if (sensor->sensor_gpio_res) {
2822 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2823 for (i = 0; i < icd->ops->num_controls; i++) {
2824 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2825 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2828 sensor->info_priv.flash = 0xff;
2829 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2837 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2845 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2846 .init = sensor_init,
2847 .g_ctrl = sensor_g_control,
2848 .s_ctrl = sensor_s_control,
2849 .g_ext_ctrls = sensor_g_ext_controls,
2850 .s_ext_ctrls = sensor_s_ext_controls,
2851 .g_chip_ident = sensor_g_chip_ident,
2852 .ioctl = sensor_ioctl,
2855 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2856 .s_fmt = sensor_s_fmt,
2857 .g_fmt = sensor_g_fmt,
2858 .try_fmt = sensor_try_fmt,
2861 static struct v4l2_subdev_ops sensor_subdev_ops = {
2862 .core = &sensor_subdev_core_ops,
2863 .video = &sensor_subdev_video_ops,
2866 static int sensor_probe(struct i2c_client *client,
2867 const struct i2c_device_id *did)
2869 struct sensor *sensor;
2870 struct soc_camera_device *icd = client->dev.platform_data;
2871 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2872 struct soc_camera_link *icl;
2875 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2877 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2881 icl = to_soc_camera_link(icd);
2883 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2887 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2888 dev_warn(&adapter->dev,
2889 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2893 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2897 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2899 /* Second stage probe - when a capture adapter is there */
2900 icd->ops = &sensor_ops;
2901 icd->y_skip_top = 0;
2902 #if CONFIG_SENSOR_I2C_NOSCHED
2903 atomic_set(&sensor->tasklock_cnt,0);
2906 ret = sensor_video_probe(icd, client);
2909 i2c_set_clientdata(client, NULL);
2913 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2917 static int sensor_remove(struct i2c_client *client)
2919 struct sensor *sensor = to_sensor(client);
2920 struct soc_camera_device *icd = client->dev.platform_data;
2923 i2c_set_clientdata(client, NULL);
2924 client->driver = NULL;
2930 static const struct i2c_device_id sensor_id[] = {
2931 {SENSOR_NAME_STRING(), 0 },
2934 MODULE_DEVICE_TABLE(i2c, sensor_id);
2936 static struct i2c_driver sensor_i2c_driver = {
2938 .name = SENSOR_NAME_STRING(),
2940 .probe = sensor_probe,
2941 .remove = sensor_remove,
2942 .id_table = sensor_id,
2945 static int __init sensor_mod_init(void)
2947 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2948 return i2c_add_driver(&sensor_i2c_driver);
2951 static void __exit sensor_mod_exit(void)
2953 i2c_del_driver(&sensor_i2c_driver);
2956 device_initcall_sync(sensor_mod_init);
2957 module_exit(sensor_mod_exit);
2959 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2960 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2961 MODULE_LICENSE("GPL");