3 o* Driver for MT9M001 CMOS Image Sensor from Micron
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/videodev2.h>
13 #include <linux/slab.h>
14 #include <linux/i2c.h>
15 #include <linux/log2.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/circ_buf.h>
19 #include <linux/miscdevice.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-chip-ident.h>
22 #include <media/soc_camera.h>
23 #include <plat/rk_camera.h>
24 #include <linux/vmalloc.h>
26 module_param(debug, int, S_IRUGO|S_IWUSR);
28 #define dprintk(level, fmt, arg...) do { \
30 printk(KERN_WARNING fmt , ## arg); } while (0)
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
43 #define MIN(x,y) ((x<y) ? x: y)
44 #define MAX(x,y) ((x>y) ? x: y)
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME RK29_CAM_SENSOR_GC0307
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_GC0307
49 #define SENSOR_ID 0x99
50 #define SENSOR_MIN_WIDTH 640//176
51 #define SENSOR_MIN_HEIGHT 480//144
52 #define SENSOR_MAX_WIDTH 800//1600
53 #define SENSOR_MAX_HEIGHT 600//1200
54 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT sensor_init_height
56 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
57 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
58 #define SENSOR_BUS_PARAM sensor_init_busparam
60 #define CONFIG_SENSOR_WhiteBalance 1
61 #define CONFIG_SENSOR_Brightness 0
62 #define CONFIG_SENSOR_Contrast 0
63 #define CONFIG_SENSOR_Saturation 0
64 #define CONFIG_SENSOR_Effect 1
65 #define CONFIG_SENSOR_Scene 0
66 #define CONFIG_SENSOR_DigitalZoom 0
67 #define CONFIG_SENSOR_Focus 0
68 #define CONFIG_SENSOR_Exposure 0
69 #define CONFIG_SENSOR_Flash 0
70 #define CONFIG_SENSOR_Mirror 0
71 #define CONFIG_SENSOR_Flip 0
73 #define CONFIG_SENSOR_I2C_SPEED 100000//250000 /* Hz */
74 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
75 #define CONFIG_SENSOR_I2C_NOSCHED 0
76 #define CONFIG_SENSOR_I2C_RDWRCHK 0
78 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
79 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
80 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
81 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
82 #define COLOR_TEMPERATURE_OFFICE_DN 3500
83 #define COLOR_TEMPERATURE_OFFICE_UP 5000
84 #define COLOR_TEMPERATURE_HOME_DN 2500
85 #define COLOR_TEMPERATURE_HOME_UP 3500
87 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
88 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
90 #define SENSOR_AF_IS_ERR (0x00<<0)
91 #define SENSOR_AF_IS_OK (0x01<<0)
92 #define SENSOR_INIT_IS_ERR (0x00<<28)
93 #define SENSOR_INIT_IS_OK (0x01<<28)
100 /* init 640X480 VGA */
101 static struct reginfo sensor_init_data[] =
103 //========= close output
107 //========= close some functions
108 // open them after configure their parmameters
112 {0x47 ,0x00}, //mode1,
113 {0x48 ,0xc3}, //mode2,
114 {0x49 ,0x00}, //dither_mode
115 {0x4a ,0x00}, //clock_gating_en
116 {0x4b ,0x00}, //mode_reg3
117 {0x4E ,0x22},//0x23}, //sync mode yaowei
118 {0x4F ,0x01}, //AWB, AEC, every N frame
120 //========= frame timing
123 {0x1C ,0x00}, //Vs_st
124 {0x1D ,0x00}, //Vs_et
125 {0x10 ,0x00}, //high 4 bits of VB, HB
126 {0x11 ,0x05}, //row_tail, AD_pipe_number
132 //========= windowing
133 {0x05 ,0x00}, //row_start
135 {0x07 ,0x00}, //col start
137 {0x09 ,0x01}, //win height
139 {0x0B ,0x02}, //win width, pixel array only 640
143 {0x0D ,0x22}, //rsh_width
145 {0x0E ,0x02}, //CISCTL mode2,
148 {0x12 ,0x70}, //7 hrst, 6_4 darsg,
149 {0x13 ,0x00}, //7 CISCTL_restart, 0 apwd
151 {0x15 ,0xba}, //7_4 vref
152 {0x16 ,0x13}, //5to4 _coln_r, __1to0__da18
153 {0x17 ,0x52}, //opa_r, ref_r, sRef_r
154 //{0x18 ,0xc0}, //analog_mode, best case for left band.
156 {0x1E ,0x0d}, //tsp_width
157 {0x1F ,0x32}, //sh_delay
160 {0x47 ,0x00}, //7__test_image, __6__fixed_pga, __5__auto_DN, __4__CbCr_fix,
161 //__3to2__dark_sequence, __1__allow_pclk_vcync, __0__LSC_test_image
162 {0x19 ,0x06}, //pga_o
163 {0x1a ,0x06}, //pga_e
165 {0x31 ,0x00}, //4 //pga_oFFset , high 8bits of 11bits
166 {0x3B ,0x00}, //global_oFFset, low 8bits of 11bits
168 {0x59 ,0x0f}, //offset_mode
169 {0x58 ,0x88}, //DARK_VALUE_RATIO_G, DARK_VALUE_RATIO_RB
170 {0x57 ,0x08}, //DARK_CURRENT_RATE
171 {0x56 ,0x77}, //PGA_OFFSET_EVEN_RATIO, PGA_OFFSET_ODD_RATIO
174 {0x35 ,0xd8}, //blk_mode
190 {0x7e ,0x50},//0x45 ylz++
197 //========= manual_gain
198 {0x61 ,0x80}, //manual_gain_g1
199 {0x63 ,0x80}, //manual_gain_r
200 {0x65 ,0x98}, //manual_gai_b, 0xa0=1.25, 0x98=1.1875
201 {0x67 ,0x80}, //manual_gain_g2
202 {0x68 ,0x18}, //global_manual_gain 2.4bits
224 {0x7d ,0x2f}, //dn_mode
225 {0x80 ,0x0c}, //when auto_dn, check 7e,7f
230 {0x83 ,0x18}, //DD_TH1
231 {0x84 ,0x18}, //DD_TH2
232 {0x85 ,0x04}, //DD_TH3
233 {0x87 ,0x34}, //32 b DNDD_low_range X16, DNDD_low_range_C_weight_center
256 {0x77 ,0x80}, //contrast_center
257 {0x78 ,0x00}, //fixed_Cb
258 {0x79 ,0x00}, //fixed_Cr
259 {0x7a ,0x00}, //luma_offset
260 {0x7b ,0x40}, //hue_cos
261 {0x7c ,0x00}, //hue_sin
264 {0xa0 ,0x40}, //global_saturation
265 {0xa1 ,0x42}, //luma_contrast
266 {0xa2 ,0x40}, //saturation_Cb //ylz 34
267 {0xa3 ,0x34}, //saturation_Cr
302 {0xc4 ,0x1c}, //18//20
310 {0xcd ,0x80}, //R_ratio
311 {0xce ,0x80}, //G_ratio , cold_white white
312 {0xcf ,0x80}, //B_ratio
324 {0x28 ,0x02}, //AEC_exp_level_1bit11to8
325 {0x29 ,0x58}, //AEC_exp_level_1bit7to0
326 {0x2a ,0x03}, //AEC_exp_level_2bit11to8
327 {0x2b ,0x84}, //AEC_exp_level_2bit7to0
328 {0x2c ,0x09}, //AEC_exp_level_3bit11to8 659 - 8FPS, 8ca - 6FPS //
329 {0x2d ,0x60}, //AEC_exp_level_3bit7to0
330 {0x2e ,0x0a}, //AEC_exp_level_4bit11to8 4FPS
331 {0x2f ,0x8c}, //AEC_exp_level_4bit7to0
341 {0xd1 ,0x40}, //AEC_target_Y
344 {0xd5 ,0x01}, // william 0318
345 {0xd6 ,0x96}, //antiflicker_step
346 {0xd7 ,0x03}, //AEC_exp_time_min ,william 20090312
351 //========= measure window
362 //========= close_frame
363 {0xed ,0x00}, //close_frame_num1 ,can be use to reduce FPS
364 {0xee ,0x00}, //close_frame_num2
365 {0xef ,0x00}, //close_frame_num
368 {0xf0 ,0x01}, //select page1
402 //=============================lscP
427 //============================= ccP
429 {0x69 ,0x03}, //cc_mode
448 //============================= AGP
474 //about gamma1 is hex r oct
493 //========= open functions
494 {0xf0 ,0x00}, //set back to page0
498 ///// Çë×¢Ò⣬µ÷ÕûGC0307µÄ¾µÏñºÍ·×ª£¬ÐèҪͬʱÐÞ¸ÄÈý¸ö¼Ä´æÆ÷£¬ÈçÏÂ:
504 { 0x01 ,0xfa}, // 24M
522 ///// ËÄÖÖ²»Í¬µÄ·×ªºÍ¾µÏñÉ趨£¬¿Í»§¿ÉÖ±½Ó¸´ÖÆ!!!!!!
541 // IMAGE_HV_MIRROR: // 180
551 static struct reginfo sensor_720p[]=
557 static struct reginfo sensor_sxga[] =
564 static struct reginfo sensor_svga[] =
572 static struct reginfo sensor_vga[] =
578 { 0x08 , 0x00},//0x10 james 20100715
582 { 0x0c , 0x88},//0x80 james 20100715
583 { 0x45 , 0x24}, // bit[7:2]=001001
584 { 0x48 , 0x84}, // bit[7]=1
609 static struct reginfo sensor_cif[] =
616 static struct reginfo sensor_qvga[] =
623 static struct reginfo sensor_qcif[] =
629 static struct reginfo sensor_ClrFmt_YUYV[]=
635 static struct reginfo sensor_ClrFmt_UYVY[]=
641 #if CONFIG_SENSOR_WhiteBalance
642 static struct reginfo sensor_WhiteB_Auto[]=
644 {0xc7,0x4c}, //for AWB can adjust back
653 /* Cloudy Colour Temperature : 6500K - 8000K */
654 static struct reginfo sensor_WhiteB_Cloudy[]=
656 {0x41,0x2b}, // Enable AWB
657 {0xc7,0x5a}, //WB_manual_gain
664 /* ClearDay Colour Temperature : 5000K - 6500K */
665 static struct reginfo sensor_WhiteB_ClearDay[]=
668 {0x41,0x2b}, // Enable AWB
676 /* Office Colour Temperature : 3500K - 5000K */
677 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
680 {0x41,0x2b}, // Enable AWB
690 /* Home Colour Temperature : 2500K - 3500K */
691 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
694 {0x41,0x2b}, // Enable AWB
702 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
703 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
707 #if CONFIG_SENSOR_Brightness
708 static struct reginfo sensor_Brightness0[]=
716 static struct reginfo sensor_Brightness1[]=
723 static struct reginfo sensor_Brightness2[]=
730 static struct reginfo sensor_Brightness3[]=
737 static struct reginfo sensor_Brightness4[]=
744 static struct reginfo sensor_Brightness5[]=
750 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
751 sensor_Brightness4, sensor_Brightness5,NULL,
756 #if CONFIG_SENSOR_Effect
757 static struct reginfo sensor_Effect_Normal[] =
779 static struct reginfo sensor_Effect_WandB[] =
781 {0x41,0x2f}, // danse
800 static struct reginfo sensor_Effect_Sepia[] =
824 static struct reginfo sensor_Effect_Negative[] =
846 static struct reginfo sensor_Effect_Bluish[] =
869 static struct reginfo sensor_Effect_Green[] =
891 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
892 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
895 #if CONFIG_SENSOR_Exposure
896 static struct reginfo sensor_Exposure0[]=
902 static struct reginfo sensor_Exposure1[]=
908 static struct reginfo sensor_Exposure2[]=
914 static struct reginfo sensor_Exposure3[]=
920 static struct reginfo sensor_Exposure4[]=
926 static struct reginfo sensor_Exposure5[]=
932 static struct reginfo sensor_Exposure6[]=
938 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
939 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
942 #if CONFIG_SENSOR_Saturation
943 static struct reginfo sensor_Saturation0[]=
948 static struct reginfo sensor_Saturation1[]=
953 static struct reginfo sensor_Saturation2[]=
957 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
960 #if CONFIG_SENSOR_Contrast
961 static struct reginfo sensor_Contrast0[]=
966 static struct reginfo sensor_Contrast1[]=
971 static struct reginfo sensor_Contrast2[]=
976 static struct reginfo sensor_Contrast3[]=
981 static struct reginfo sensor_Contrast4[]=
987 static struct reginfo sensor_Contrast5[]=
992 static struct reginfo sensor_Contrast6[]=
996 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
997 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1001 #if CONFIG_SENSOR_Mirror
1002 static struct reginfo sensor_MirrorOn[]=
1007 static struct reginfo sensor_MirrorOff[]=
1011 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1013 #if CONFIG_SENSOR_Flip
1014 static struct reginfo sensor_FlipOn[]=
1019 static struct reginfo sensor_FlipOff[]=
1023 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1026 #if CONFIG_SENSOR_Scene
1027 static struct reginfo sensor_SceneAuto[] =
1029 { 0xdd ,0x22}, //0x12
1036 static struct reginfo sensor_SceneNight[] =
1045 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1048 #if CONFIG_SENSOR_DigitalZoom
1049 static struct reginfo sensor_Zoom0[] =
1055 static struct reginfo sensor_Zoom1[] =
1061 static struct reginfo sensor_Zoom2[] =
1068 static struct reginfo sensor_Zoom3[] =
1073 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1075 static const struct v4l2_querymenu sensor_menus[] =
1077 #if CONFIG_SENSOR_WhiteBalance
1078 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1079 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1080 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1083 #if CONFIG_SENSOR_Effect
1084 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1085 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1086 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1089 #if CONFIG_SENSOR_Scene
1090 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1093 #if CONFIG_SENSOR_Flash
1094 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1095 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1099 static const struct v4l2_queryctrl sensor_controls[] =
1101 #if CONFIG_SENSOR_WhiteBalance
1103 .id = V4L2_CID_DO_WHITE_BALANCE,
1104 .type = V4L2_CTRL_TYPE_MENU,
1105 .name = "White Balance Control",
1113 #if CONFIG_SENSOR_Brightness
1115 .id = V4L2_CID_BRIGHTNESS,
1116 .type = V4L2_CTRL_TYPE_INTEGER,
1117 .name = "Brightness Control",
1125 #if CONFIG_SENSOR_Effect
1127 .id = V4L2_CID_EFFECT,
1128 .type = V4L2_CTRL_TYPE_MENU,
1129 .name = "Effect Control",
1137 #if CONFIG_SENSOR_Exposure
1139 .id = V4L2_CID_EXPOSURE,
1140 .type = V4L2_CTRL_TYPE_INTEGER,
1141 .name = "Exposure Control",
1149 #if CONFIG_SENSOR_Saturation
1151 .id = V4L2_CID_SATURATION,
1152 .type = V4L2_CTRL_TYPE_INTEGER,
1153 .name = "Saturation Control",
1161 #if CONFIG_SENSOR_Contrast
1163 .id = V4L2_CID_CONTRAST,
1164 .type = V4L2_CTRL_TYPE_INTEGER,
1165 .name = "Contrast Control",
1173 #if CONFIG_SENSOR_Mirror
1175 .id = V4L2_CID_HFLIP,
1176 .type = V4L2_CTRL_TYPE_BOOLEAN,
1177 .name = "Mirror Control",
1185 #if CONFIG_SENSOR_Flip
1187 .id = V4L2_CID_VFLIP,
1188 .type = V4L2_CTRL_TYPE_BOOLEAN,
1189 .name = "Flip Control",
1197 #if CONFIG_SENSOR_Scene
1199 .id = V4L2_CID_SCENE,
1200 .type = V4L2_CTRL_TYPE_MENU,
1201 .name = "Scene Control",
1209 #if CONFIG_SENSOR_DigitalZoom
1211 .id = V4L2_CID_ZOOM_RELATIVE,
1212 .type = V4L2_CTRL_TYPE_INTEGER,
1213 .name = "DigitalZoom Control",
1219 .id = V4L2_CID_ZOOM_ABSOLUTE,
1220 .type = V4L2_CTRL_TYPE_INTEGER,
1221 .name = "DigitalZoom Control",
1229 #if CONFIG_SENSOR_Focus
1231 .id = V4L2_CID_FOCUS_RELATIVE,
1232 .type = V4L2_CTRL_TYPE_INTEGER,
1233 .name = "Focus Control",
1239 .id = V4L2_CID_FOCUS_ABSOLUTE,
1240 .type = V4L2_CTRL_TYPE_INTEGER,
1241 .name = "Focus Control",
1245 .default_value = 125,
1249 #if CONFIG_SENSOR_Flash
1251 .id = V4L2_CID_FLASH,
1252 .type = V4L2_CTRL_TYPE_MENU,
1253 .name = "Flash Control",
1262 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1263 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1264 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1265 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1266 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1267 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1268 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1269 static int sensor_resume(struct soc_camera_device *icd);
1270 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1271 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1272 #if CONFIG_SENSOR_Effect
1273 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1275 #if CONFIG_SENSOR_WhiteBalance
1276 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1278 static int sensor_deactivate(struct i2c_client *client);
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 /* only one fixed colorspace per pixelcode */
1293 struct sensor_datafmt {
1294 enum v4l2_mbus_pixelcode code;
1295 enum v4l2_colorspace colorspace;
1298 /* Find a data format by a pixel code in an array */
1299 static const struct sensor_datafmt *sensor_find_datafmt(
1300 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1304 for (i = 0; i < n; i++)
1305 if (fmt[i].code == code)
1311 static const struct sensor_datafmt sensor_colour_fmts[] = {
1312 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG},
1313 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG}
1315 typedef struct sensor_info_priv_s
1329 unsigned char mirror; /* HFLIP */
1330 unsigned char flip; /* VFLIP */
1331 unsigned int winseqe_cur_addr;
1332 struct sensor_datafmt fmt;
1333 unsigned int funmodule_state;
1334 } sensor_info_priv_t;
1338 struct v4l2_subdev subdev;
1339 struct i2c_client *client;
1340 sensor_info_priv_t info_priv;
1341 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1342 #if CONFIG_SENSOR_I2C_NOSCHED
1343 atomic_t tasklock_cnt;
1345 struct rk29camera_platform_data *sensor_io_request;
1346 struct rk29camera_gpio_res *sensor_gpio_res;
1349 static struct sensor* to_sensor(const struct i2c_client *client)
1351 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1354 static int sensor_task_lock(struct i2c_client *client, int lock)
1356 #if CONFIG_SENSOR_I2C_NOSCHED
1358 struct sensor *sensor = to_sensor(client);
1361 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1362 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1363 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1367 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1368 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1369 goto sensor_task_lock_err;
1374 atomic_add(1, &sensor->tasklock_cnt);
1376 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1377 atomic_sub(1, &sensor->tasklock_cnt);
1379 if (atomic_read(&sensor->tasklock_cnt) == 0)
1384 sensor_task_lock_err:
1392 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val);
1394 /* sensor register write */
1395 static int sensor_write_internal(struct i2c_client *client, u8 reg, u8 val)
1399 struct i2c_msg msg[1];
1401 buf[0] = reg & 0xFF;
1404 msg->addr = client->addr;
1405 msg->flags = client->flags;
1407 msg->len = sizeof(buf);
1408 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1409 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1414 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1415 err = i2c_transfer(client->adapter, msg, 1);
1420 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1429 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1433 for(cnt=0; cnt<1; cnt++)
1436 ret=sensor_write_internal(client, reg, val);
1444 printk("sensor_write() : reg %02x 0x%02x\n", reg, val);
1445 sensor_write_internal(client, reg, val);
1447 sensor_read(client, reg, &val_tmp);
1450 printk("sensor_write() error: reg %02x 0x%02x != 0x%02x \n", reg, val, val_tmp);
1454 while(val_tmp != val);
1459 /* sensor register read */
1460 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1465 struct i2c_msg msg[2];
1467 //buf[0] = reg >> 8;
1469 // buf[1] = reg & 0xFF;
1471 msg[0].addr = client->addr;
1472 msg[0].flags = client->flags;
1474 msg[0].len = sizeof(buf);
1475 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1476 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1478 msg[1].addr = client->addr;
1479 msg[1].flags = client->flags|I2C_M_RD;
1482 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1483 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1487 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1488 err = i2c_transfer(client->adapter, msg, 2);
1494 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1502 /* write a array of registers */
1504 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1509 for(i=0; regarray[i].reg!=0xff;i++)
1511 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1514 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1521 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1526 while (regarray[i].reg != 0)
1528 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1531 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1534 err = sensor_read(client, regarray[i].reg, &val_read);
1535 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1543 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
1550 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
1551 for(i=0;i<sizeof(sensor_init_data) / 2;i++)
1553 ret = sensor_read(client,regarray[i].reg,&value);
1556 SENSOR_TR("read value failed\n");
1559 if(regarray[i].val != value)
1561 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
1569 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1571 struct soc_camera_link *icl = to_soc_camera_link(icd);
1574 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1577 case Sensor_PowerDown:
1579 if (icl->powerdown) {
1580 ret = icl->powerdown(icd->pdev, on);
1581 if (ret == RK29_CAM_IO_SUCCESS) {
1585 icl->reset(icd->pdev);
1587 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1589 goto sensor_power_end;
1596 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1597 struct sensor *sensor = to_sensor(client);
1599 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1600 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1606 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1613 static s32 sensor_init_width = 640;
1614 static s32 sensor_init_height = 480;
1615 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
1616 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1617 static struct reginfo* sensor_init_data_p = NULL;
1618 static struct reginfo* sensor_init_winseq_p = NULL;
1619 static struct reginfo* sensor_init_winseq_board = NULL;
1621 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1623 struct i2c_client *client = v4l2_get_subdevdata(sd);;
1624 struct soc_camera_device *icd = client->dev.platform_data;
1625 struct sensor *sensor = to_sensor(client);
1626 const struct v4l2_queryctrl *qctrl;
1627 const struct sensor_datafmt *fmt;
1629 int ret,pid = 0,i = 0,j=0;
1630 struct rk29camera_platform_data* tmp_plat_data =(struct rk29camera_platform_data*)val;
1631 sensor_init_data_p = sensor_init_data;
1632 sensor_init_winseq_p = sensor_vga;
1633 sensor_init_width = 640;
1634 sensor_init_height = 480;
1635 if (tmp_plat_data != NULL && (u32)tmp_plat_data != 1) {
1636 for(i = 0;i < RK_CAM_NUM;i++){
1637 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1638 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1642 if(tmp_plat_data && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1643 //user has defined the init data
1645 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1646 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1647 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1648 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1650 sensor_init_data_p = sensor_init_data;
1652 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1653 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1656 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1657 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1658 if(sensor_init_winseq_board)
1660 vfree(sensor_init_winseq_board);
1661 sensor_init_winseq_board = NULL;
1663 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1664 if(!sensor_init_winseq_board)
1665 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1666 for(j = 0;j< tmp_winseq_size;j++){
1667 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1668 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1670 sensor_init_winseq_p = sensor_init_winseq_board;
1672 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1673 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1675 //init width,height,bus,pixelcode
1676 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1677 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1678 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1679 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1680 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1681 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1682 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1683 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1685 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1687 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1689 goto sensor_INIT_ERR;
1693 if (sensor_task_lock(client,1)<0)
1694 goto sensor_INIT_ERR;
1695 /* ret = sensor_write(client, 0x12, 0x80);
1698 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1700 goto sensor_INIT_ERR;
1703 mdelay(5); */ //delay 5 microseconds
1705 ret = sensor_write_array(client, sensor_init_data_p);
1708 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1709 goto sensor_INIT_ERR;
1715 printk("****************** check init data\n");
1716 for(i=0; sensor_init_data[i].reg!=0xff; i++)
1718 sensor_read(client, sensor_init_data[i].reg, &val);
1719 printk("reg 0x%02x: org=0x%02x, val=0x%02x, %s\n",
1720 sensor_init_data[i].reg,
1721 sensor_init_data[i].val,
1723 sensor_init_data[i].val==val?"O":"X");
1725 printk("**********************************\n");
1729 sensor_task_lock(client,0);
1730 //icd->user_width = SENSOR_INIT_WIDTH;
1731 //icd->user_height = SENSOR_INIT_HEIGHT;
1732 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1733 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1735 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1737 goto sensor_INIT_ERR;
1739 sensor->info_priv.fmt = *fmt;
1741 /* sensor sensor information for initialization */
1742 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1744 sensor->info_priv.whiteBalance = qctrl->default_value;
1745 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1747 sensor->info_priv.brightness = qctrl->default_value;
1748 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1750 sensor->info_priv.effect = qctrl->default_value;
1751 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1753 sensor->info_priv.exposure = qctrl->default_value;
1755 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1757 sensor->info_priv.saturation = qctrl->default_value;
1758 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1760 sensor->info_priv.contrast = qctrl->default_value;
1761 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1763 sensor->info_priv.mirror = qctrl->default_value;
1764 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1766 sensor->info_priv.flip = qctrl->default_value;
1767 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1769 sensor->info_priv.scene = qctrl->default_value;
1770 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1772 sensor->info_priv.digitalzoom = qctrl->default_value;
1774 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1775 #if CONFIG_SENSOR_Focus
1777 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1779 sensor->info_priv.focus = qctrl->default_value;
1782 #if CONFIG_SENSOR_Flash
1783 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1785 sensor->info_priv.flash = qctrl->default_value;
1788 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);
1789 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1792 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1793 sensor_task_lock(client,0);
1794 sensor_deactivate(client);
1798 static int sensor_deactivate(struct i2c_client *client)
1800 struct soc_camera_device *icd = client->dev.platform_data;
1802 struct sensor *sensor = to_sensor(client);
1803 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1805 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1806 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
1807 sensor_task_lock(client, 1);
1808 sensor_task_lock(client, 0);
1810 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1813 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1814 icd->user_width = SENSOR_INIT_WIDTH;
1815 icd->user_height = SENSOR_INIT_HEIGHT;
1816 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1820 static struct reginfo sensor_power_down_sequence[]=
1824 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1827 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1829 if (pm_msg.event == PM_EVENT_SUSPEND) {
1830 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1831 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1833 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1836 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1838 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1843 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1849 static int sensor_resume(struct soc_camera_device *icd)
1853 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1855 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1859 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1865 static int sensor_set_bus_param(struct soc_camera_device *icd,
1866 unsigned long flags)
1872 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1874 struct soc_camera_link *icl = to_soc_camera_link(icd);
1875 unsigned long flags = SENSOR_BUS_PARAM;
1877 return soc_camera_apply_sensor_flags(icl, flags);
1880 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1882 struct i2c_client *client = v4l2_get_subdevdata(sd);
1883 struct soc_camera_device *icd = client->dev.platform_data;
1884 struct sensor *sensor = to_sensor(client);
1886 mf->width = icd->user_width;
1887 mf->height = icd->user_height;
1888 mf->code = sensor->info_priv.fmt.code;
1889 mf->colorspace = sensor->info_priv.fmt.colorspace;
1890 mf->field = V4L2_FIELD_NONE;
1894 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1898 if ((mf->width == 1024) && (mf->height == 768)) {
1900 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1902 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1904 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1906 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1911 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1915 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1919 if ((mf->width == 1280) && (mf->height == 720)) {
1921 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1926 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1929 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1931 struct i2c_client *client = v4l2_get_subdevdata(sd);
1932 const struct sensor_datafmt *fmt;
1933 struct sensor *sensor = to_sensor(client);
1934 const struct v4l2_queryctrl *qctrl;
1935 struct soc_camera_device *icd = client->dev.platform_data;
1936 struct reginfo *winseqe_set_addr=NULL;
1937 int ret=0, set_w,set_h;
1939 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1940 ARRAY_SIZE(sensor_colour_fmts));
1943 goto sensor_s_fmt_end;
1946 if (sensor->info_priv.fmt.code != mf->code) {
1949 case V4L2_MBUS_FMT_YUYV8_2X8:
1951 winseqe_set_addr = sensor_ClrFmt_YUYV;
1954 case V4L2_MBUS_FMT_UYVY8_2X8:
1956 winseqe_set_addr = sensor_ClrFmt_UYVY;
1962 if (winseqe_set_addr != NULL) {
1963 sensor_write_array(client, winseqe_set_addr);
1964 sensor->info_priv.fmt.code = mf->code;
1965 sensor->info_priv.fmt.colorspace= mf->colorspace;
1966 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1968 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1975 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg!=0xff)
1977 winseqe_set_addr = sensor_qcif;
1981 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg!=0xff)
1983 winseqe_set_addr = sensor_qvga;
1987 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg!=0xff)
1989 winseqe_set_addr = sensor_cif;
1993 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg!=0xff)
1995 winseqe_set_addr = sensor_vga;
1999 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg!=0xff)
2001 winseqe_set_addr = sensor_svga;
2005 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg!=0xff)
2007 winseqe_set_addr = sensor_720p;
2011 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg!=0xff)
2013 winseqe_set_addr = sensor_sxga;
2019 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2020 set_w = SENSOR_INIT_WIDTH;
2021 set_h = SENSOR_INIT_HEIGHT;
2022 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2025 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2026 #if CONFIG_SENSOR_Flash
2027 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2028 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2029 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2030 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2032 } else { /* ddl@rock-chips.com : Video */
2033 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2034 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2035 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2039 ret |= sensor_write_array(client, winseqe_set_addr);
2041 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2042 #if CONFIG_SENSOR_Flash
2043 if (sensor_fmt_capturechk(sd,mf) == true) {
2044 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2045 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2046 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2050 goto sensor_s_fmt_end;
2053 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2055 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2056 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2057 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2058 if (sensor->info_priv.whiteBalance != 0) {
2059 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2060 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2062 sensor->info_priv.snap2preview = true;
2063 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2064 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2065 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2066 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2067 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2068 sensor->info_priv.video2preview = true;
2069 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2070 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2071 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2072 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2073 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2074 sensor->info_priv.video2preview = false;
2075 sensor->info_priv.snap2preview = false;
2078 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2082 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2092 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2094 struct i2c_client *client = v4l2_get_subdevdata(sd);
2095 struct sensor *sensor = to_sensor(client);
2096 const struct sensor_datafmt *fmt;
2099 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2100 ARRAY_SIZE(sensor_colour_fmts));
2102 fmt = &sensor->info_priv.fmt;
2103 mf->code = fmt->code;
2106 if (mf->height > SENSOR_MAX_HEIGHT)
2107 mf->height = SENSOR_MAX_HEIGHT;
2108 else if (mf->height < SENSOR_MIN_HEIGHT)
2109 mf->height = SENSOR_MIN_HEIGHT;
2111 if (mf->width > SENSOR_MAX_WIDTH)
2112 mf->width = SENSOR_MAX_WIDTH;
2113 else if (mf->width < SENSOR_MIN_WIDTH)
2114 mf->width = SENSOR_MIN_WIDTH;
2116 mf->colorspace = fmt->colorspace;
2121 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2123 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2125 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2128 if (id->match.addr != client->addr)
2131 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
2136 #if CONFIG_SENSOR_Brightness
2137 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2139 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2141 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2143 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2145 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2147 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2150 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2154 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2158 #if CONFIG_SENSOR_Effect
2159 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2161 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2163 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2165 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2167 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2169 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2172 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2176 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2180 #if CONFIG_SENSOR_Exposure
2181 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2183 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2185 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2187 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2189 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2191 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2194 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2198 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2202 #if CONFIG_SENSOR_Saturation
2203 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2205 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2207 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2209 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2211 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2213 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2216 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2220 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2224 #if CONFIG_SENSOR_Contrast
2225 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2227 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2229 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2231 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2233 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2235 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2238 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2242 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2246 #if CONFIG_SENSOR_Mirror
2247 static int sensor_mirror(struct i2c_client *client, int on)
2252 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2254 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2256 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2258 if (sensor_mirror(client,value) != 0)
2259 SENSOR_TR("%s(%d): sensor_mirror failed, value:0x%x",__FUNCTION__, __LINE__,value);
2261 SENSOR_DG("%s(%d): sensor_mirror success, value:0x%x",__FUNCTION__, __LINE__,value);
2264 SENSOR_TR("\n %s..%s value = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2268 #if CONFIG_SENSOR_Flip
2269 static int sensor_flip(struct i2c_client *client, int on)
2274 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2276 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2278 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2280 if (sensor_flip(client,value) != 0)
2281 SENSOR_TR("%s(%d): sensor_flip failed, value:0x%x",__FUNCTION__, __LINE__,value);
2283 SENSOR_DG("%s(%d): sensor_flip success, value:0x%x",__FUNCTION__, __LINE__,value);
2286 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2290 #if CONFIG_SENSOR_Scene
2291 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2293 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2295 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2297 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2299 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2301 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2304 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2308 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2312 #if CONFIG_SENSOR_WhiteBalance
2313 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2315 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2317 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2319 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2321 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 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);
2330 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2334 #if CONFIG_SENSOR_DigitalZoom
2335 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2337 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2338 struct sensor *sensor = to_sensor(client);
2339 const struct v4l2_queryctrl *qctrl_info;
2340 int digitalzoom_cur, digitalzoom_total;
2342 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2346 digitalzoom_cur = sensor->info_priv.digitalzoom;
2347 digitalzoom_total = qctrl_info->maximum;
2349 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2351 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2355 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2357 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2361 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2363 *value = digitalzoom_total - digitalzoom_cur;
2366 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2368 *value = 0 - digitalzoom_cur;
2371 digitalzoom_cur += *value;
2373 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2375 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2377 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2380 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2387 #if CONFIG_SENSOR_Flash
2388 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2390 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2391 if (value == 3) { /* ddl@rock-chips.com: torch */
2392 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2394 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2396 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2400 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2405 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2407 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2408 struct sensor *sensor = to_sensor(client);
2409 const struct v4l2_queryctrl *qctrl;
2411 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2415 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2421 case V4L2_CID_BRIGHTNESS:
2423 ctrl->value = sensor->info_priv.brightness;
2426 case V4L2_CID_SATURATION:
2428 ctrl->value = sensor->info_priv.saturation;
2431 case V4L2_CID_CONTRAST:
2433 ctrl->value = sensor->info_priv.contrast;
2436 case V4L2_CID_DO_WHITE_BALANCE:
2438 ctrl->value = sensor->info_priv.whiteBalance;
2441 case V4L2_CID_EXPOSURE:
2443 ctrl->value = sensor->info_priv.exposure;
2446 case V4L2_CID_HFLIP:
2448 ctrl->value = sensor->info_priv.mirror;
2451 case V4L2_CID_VFLIP:
2453 ctrl->value = sensor->info_priv.flip;
2464 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2466 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2467 struct sensor *sensor = to_sensor(client);
2468 struct soc_camera_device *icd = client->dev.platform_data;
2469 const struct v4l2_queryctrl *qctrl;
2472 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2476 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2482 #if CONFIG_SENSOR_Brightness
2483 case V4L2_CID_BRIGHTNESS:
2485 if (ctrl->value != sensor->info_priv.brightness)
2487 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2491 sensor->info_priv.brightness = ctrl->value;
2496 #if CONFIG_SENSOR_Exposure
2497 case V4L2_CID_EXPOSURE:
2499 if (ctrl->value != sensor->info_priv.exposure)
2501 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2505 sensor->info_priv.exposure = ctrl->value;
2510 #if CONFIG_SENSOR_Saturation
2511 case V4L2_CID_SATURATION:
2513 if (ctrl->value != sensor->info_priv.saturation)
2515 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2519 sensor->info_priv.saturation = ctrl->value;
2524 #if CONFIG_SENSOR_Contrast
2525 case V4L2_CID_CONTRAST:
2527 if (ctrl->value != sensor->info_priv.contrast)
2529 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2533 sensor->info_priv.contrast = ctrl->value;
2538 #if CONFIG_SENSOR_WhiteBalance
2539 case V4L2_CID_DO_WHITE_BALANCE:
2541 if (ctrl->value != sensor->info_priv.whiteBalance)
2543 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2547 sensor->info_priv.whiteBalance = ctrl->value;
2552 #if CONFIG_SENSOR_Mirror
2553 case V4L2_CID_HFLIP:
2555 if (ctrl->value != sensor->info_priv.mirror)
2557 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2559 sensor->info_priv.mirror = ctrl->value;
2564 #if CONFIG_SENSOR_Flip
2565 case V4L2_CID_VFLIP:
2567 if (ctrl->value != sensor->info_priv.flip)
2569 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2571 sensor->info_priv.flip = ctrl->value;
2582 static int sensor_g_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);
2588 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2592 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2596 switch (ext_ctrl->id)
2598 case V4L2_CID_SCENE:
2600 ext_ctrl->value = sensor->info_priv.scene;
2603 case V4L2_CID_EFFECT:
2605 ext_ctrl->value = sensor->info_priv.effect;
2608 case V4L2_CID_ZOOM_ABSOLUTE:
2610 ext_ctrl->value = sensor->info_priv.digitalzoom;
2613 case V4L2_CID_ZOOM_RELATIVE:
2617 case V4L2_CID_FOCUS_ABSOLUTE:
2619 ext_ctrl->value = sensor->info_priv.focus;
2622 case V4L2_CID_FOCUS_RELATIVE:
2626 case V4L2_CID_FLASH:
2628 ext_ctrl->value = sensor->info_priv.flash;
2636 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2638 const struct v4l2_queryctrl *qctrl;
2639 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2640 struct sensor *sensor = to_sensor(client);
2643 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2647 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2652 switch (ext_ctrl->id)
2654 #if CONFIG_SENSOR_Scene
2655 case V4L2_CID_SCENE:
2657 if (ext_ctrl->value != sensor->info_priv.scene)
2659 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2661 sensor->info_priv.scene = ext_ctrl->value;
2666 #if CONFIG_SENSOR_Effect
2667 case V4L2_CID_EFFECT:
2669 if (ext_ctrl->value != sensor->info_priv.effect)
2671 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2673 sensor->info_priv.effect= ext_ctrl->value;
2678 #if CONFIG_SENSOR_DigitalZoom
2679 case V4L2_CID_ZOOM_ABSOLUTE:
2681 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2684 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2686 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2688 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2690 sensor->info_priv.digitalzoom += val_offset;
2692 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2697 case V4L2_CID_ZOOM_RELATIVE:
2699 if (ext_ctrl->value)
2701 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2703 sensor->info_priv.digitalzoom += ext_ctrl->value;
2705 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2710 #if CONFIG_SENSOR_Focus
2711 case V4L2_CID_FOCUS_ABSOLUTE:
2713 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2716 if (ext_ctrl->value != sensor->info_priv.focus)
2718 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2720 sensor->info_priv.focus += val_offset;
2725 case V4L2_CID_FOCUS_RELATIVE:
2727 if (ext_ctrl->value)
2729 sensor->info_priv.focus += ext_ctrl->value;
2731 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2736 #if CONFIG_SENSOR_Flash
2737 case V4L2_CID_FLASH:
2739 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2741 sensor->info_priv.flash = ext_ctrl->value;
2743 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2754 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2756 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2757 struct soc_camera_device *icd = client->dev.platform_data;
2758 int i, error_cnt=0, error_idx=-1;
2761 for (i=0; i<ext_ctrl->count; i++) {
2762 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2769 error_idx = ext_ctrl->count;
2771 if (error_idx != -1) {
2772 ext_ctrl->error_idx = error_idx;
2779 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2781 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2782 struct soc_camera_device *icd = client->dev.platform_data;
2783 int i, error_cnt=0, error_idx=-1;
2786 for (i=0; i<ext_ctrl->count; i++) {
2787 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2794 error_idx = ext_ctrl->count;
2796 if (error_idx != -1) {
2797 ext_ctrl->error_idx = error_idx;
2804 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2805 * this wasn't our capture interface, so, we wait for the right one */
2806 static int sensor_video_probe(struct soc_camera_device *icd,
2807 struct i2c_client *client)
2811 struct sensor *sensor = to_sensor(client);
2813 /* We must have a parent by now. And it cannot be a wrong one.
2814 * So this entire test is completely redundant. */
2815 if (!icd->dev.parent ||
2816 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2819 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2821 printk("%s(): set powerdn failed\n", __FUNCTION__);
2822 goto sensor_video_probe_err;
2826 /* ret = sensor_write(client, 0x12, 0x80);
2829 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2832 mdelay(50); *///delay 5 microseconds
2834 /* check if it is an sensor sensor */
2835 ret = sensor_read(client, 0x00, &pid);
2837 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2841 goto sensor_video_probe_err;
2844 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2845 if (pid == SENSOR_ID) {
2846 sensor->model = SENSOR_V4L2_IDENT;
2848 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2851 goto sensor_video_probe_err;
2857 sensor_video_probe_err:
2862 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2864 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2865 struct soc_camera_device *icd = client->dev.platform_data;
2866 struct sensor *sensor = to_sensor(client);
2868 #if CONFIG_SENSOR_Flash
2872 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2875 case RK29_CAM_SUBDEV_DEACTIVATE:
2877 sensor_deactivate(client);
2881 case RK29_CAM_SUBDEV_IOREQUEST:
2883 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2884 if (sensor->sensor_io_request != NULL) {
2886 for(j = 0;j < RK_CAM_NUM;j++){
2887 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
2888 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
2889 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
2893 if(j == RK_CAM_NUM){
2894 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2896 goto sensor_ioctl_end;
2899 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2901 #if CONFIG_SENSOR_Flash
2902 if (sensor->sensor_gpio_res) {
2903 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2904 for (i = 0; i < icd->ops->num_controls; i++) {
2905 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2906 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2909 sensor->info_priv.flash = 0xff;
2910 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2918 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2926 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2927 enum v4l2_mbus_pixelcode *code)
2929 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2932 *code = sensor_colour_fmts[index].code;
2935 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2936 .init = sensor_init,
2937 .g_ctrl = sensor_g_control,
2938 .s_ctrl = sensor_s_control,
2939 .g_ext_ctrls = sensor_g_ext_controls,
2940 .s_ext_ctrls = sensor_s_ext_controls,
2941 .g_chip_ident = sensor_g_chip_ident,
2942 .ioctl = sensor_ioctl,
2945 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2946 .s_mbus_fmt = sensor_s_fmt,
2947 .g_mbus_fmt = sensor_g_fmt,
2948 .try_mbus_fmt = sensor_try_fmt,
2949 .enum_mbus_fmt = sensor_enum_fmt,
2952 static struct v4l2_subdev_ops sensor_subdev_ops = {
2953 .core = &sensor_subdev_core_ops,
2954 .video = &sensor_subdev_video_ops,
2957 static int sensor_probe(struct i2c_client *client,
2958 const struct i2c_device_id *did)
2960 struct sensor *sensor;
2961 struct soc_camera_device *icd = client->dev.platform_data;
2962 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2963 struct soc_camera_link *icl;
2966 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2968 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2972 icl = to_soc_camera_link(icd);
2974 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2978 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2979 dev_warn(&adapter->dev,
2980 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2984 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2988 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2990 /* Second stage probe - when a capture adapter is there */
2991 icd->ops = &sensor_ops;
2992 sensor->info_priv.fmt = sensor_colour_fmts[0];
2993 #if CONFIG_SENSOR_I2C_NOSCHED
2994 atomic_set(&sensor->tasklock_cnt,0);
2997 ret = sensor_video_probe(icd, client);
3000 i2c_set_clientdata(client, NULL);
3004 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3008 static int sensor_remove(struct i2c_client *client)
3010 struct sensor *sensor = to_sensor(client);
3011 struct soc_camera_device *icd = client->dev.platform_data;
3014 i2c_set_clientdata(client, NULL);
3015 client->driver = NULL;
3021 static const struct i2c_device_id sensor_id[] = {
3022 {SENSOR_NAME_STRING(), 0 },
3025 MODULE_DEVICE_TABLE(i2c, sensor_id);
3027 static struct i2c_driver sensor_i2c_driver = {
3029 .name = SENSOR_NAME_STRING(),
3031 .probe = sensor_probe,
3032 .remove = sensor_remove,
3033 .id_table = sensor_id,
3036 static int __init sensor_mod_init(void)
3038 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3039 return i2c_add_driver(&sensor_i2c_driver);
3042 static void __exit sensor_mod_exit(void)
3044 i2c_del_driver(&sensor_i2c_driver);
3047 device_initcall_sync(sensor_mod_init);
3048 module_exit(sensor_mod_exit);
3050 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3051 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3052 MODULE_LICENSE("GPL");