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 <mach/rk29_camera.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 640 /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT 480
56 #define SENSOR_INIT_WINSEQADR sensor_vga
57 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 0
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 100000//250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
78 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
79 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
81 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
82 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
83 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
84 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
85 #define COLOR_TEMPERATURE_OFFICE_DN 3500
86 #define COLOR_TEMPERATURE_OFFICE_UP 5000
87 #define COLOR_TEMPERATURE_HOME_DN 2500
88 #define COLOR_TEMPERATURE_HOME_UP 3500
90 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
91 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
93 #define SENSOR_AF_IS_ERR (0x00<<0)
94 #define SENSOR_AF_IS_OK (0x01<<0)
95 #define SENSOR_INIT_IS_ERR (0x00<<28)
96 #define SENSOR_INIT_IS_OK (0x01<<28)
103 /* init 640X480 VGA */
104 static struct reginfo sensor_init_data[] =
106 //========= close output
110 //========= close some functions
111 // open them after configure their parmameters
115 {0x47 ,0x00}, //mode1,
116 {0x48 ,0xc3}, //mode2,
117 {0x49 ,0x00}, //dither_mode
118 {0x4a ,0x00}, //clock_gating_en
119 {0x4b ,0x00}, //mode_reg3
120 {0x4E ,0x22},//0x23}, //sync mode yaowei
121 {0x4F ,0x01}, //AWB, AEC, every N frame
123 //========= frame timing
126 {0x1C ,0x00}, //Vs_st
127 {0x1D ,0x00}, //Vs_et
128 {0x10 ,0x00}, //high 4 bits of VB, HB
129 {0x11 ,0x05}, //row_tail, AD_pipe_number
135 //========= windowing
136 {0x05 ,0x00}, //row_start
138 {0x07 ,0x00}, //col start
140 {0x09 ,0x01}, //win height
142 {0x0B ,0x02}, //win width, pixel array only 640
146 {0x0D ,0x22}, //rsh_width
148 {0x0E ,0x02}, //CISCTL mode2,
151 {0x12 ,0x70}, //7 hrst, 6_4 darsg,
152 {0x13 ,0x00}, //7 CISCTL_restart, 0 apwd
154 {0x15 ,0xba}, //7_4 vref
155 {0x16 ,0x13}, //5to4 _coln_r, __1to0__da18
156 {0x17 ,0x52}, //opa_r, ref_r, sRef_r
157 //{0x18 ,0xc0}, //analog_mode, best case for left band.
159 {0x1E ,0x0d}, //tsp_width
160 {0x1F ,0x32}, //sh_delay
163 {0x47 ,0x00}, //7__test_image, __6__fixed_pga, __5__auto_DN, __4__CbCr_fix,
164 //__3to2__dark_sequence, __1__allow_pclk_vcync, __0__LSC_test_image
165 {0x19 ,0x06}, //pga_o
166 {0x1a ,0x06}, //pga_e
168 {0x31 ,0x00}, //4 //pga_oFFset , high 8bits of 11bits
169 {0x3B ,0x00}, //global_oFFset, low 8bits of 11bits
171 {0x59 ,0x0f}, //offset_mode
172 {0x58 ,0x88}, //DARK_VALUE_RATIO_G, DARK_VALUE_RATIO_RB
173 {0x57 ,0x08}, //DARK_CURRENT_RATE
174 {0x56 ,0x77}, //PGA_OFFSET_EVEN_RATIO, PGA_OFFSET_ODD_RATIO
177 {0x35 ,0xd8}, //blk_mode
193 {0x7e ,0x50},//0x45 ylz++
200 //========= manual_gain
201 {0x61 ,0x80}, //manual_gain_g1
202 {0x63 ,0x80}, //manual_gain_r
203 {0x65 ,0x98}, //manual_gai_b, 0xa0=1.25, 0x98=1.1875
204 {0x67 ,0x80}, //manual_gain_g2
205 {0x68 ,0x18}, //global_manual_gain 2.4bits
227 {0x7d ,0x2f}, //dn_mode
228 {0x80 ,0x0c}, //when auto_dn, check 7e,7f
233 {0x83 ,0x18}, //DD_TH1
234 {0x84 ,0x18}, //DD_TH2
235 {0x85 ,0x04}, //DD_TH3
236 {0x87 ,0x34}, //32 b DNDD_low_range X16, DNDD_low_range_C_weight_center
259 {0x77 ,0x80}, //contrast_center
260 {0x78 ,0x00}, //fixed_Cb
261 {0x79 ,0x00}, //fixed_Cr
262 {0x7a ,0x00}, //luma_offset
263 {0x7b ,0x40}, //hue_cos
264 {0x7c ,0x00}, //hue_sin
267 {0xa0 ,0x40}, //global_saturation
268 {0xa1 ,0x42}, //luma_contrast
269 {0xa2 ,0x40}, //saturation_Cb //ylz 34
270 {0xa3 ,0x34}, //saturation_Cr
305 {0xc4 ,0x1c}, //18//20
313 {0xcd ,0x80}, //R_ratio
314 {0xce ,0x80}, //G_ratio , cold_white white
315 {0xcf ,0x80}, //B_ratio
327 {0x28 ,0x02}, //AEC_exp_level_1bit11to8
328 {0x29 ,0x58}, //AEC_exp_level_1bit7to0
329 {0x2a ,0x03}, //AEC_exp_level_2bit11to8
330 {0x2b ,0x84}, //AEC_exp_level_2bit7to0
331 {0x2c ,0x09}, //AEC_exp_level_3bit11to8 659 - 8FPS, 8ca - 6FPS //
332 {0x2d ,0x60}, //AEC_exp_level_3bit7to0
333 {0x2e ,0x0a}, //AEC_exp_level_4bit11to8 4FPS
334 {0x2f ,0x8c}, //AEC_exp_level_4bit7to0
344 {0xd1 ,0x40}, //AEC_target_Y
347 {0xd5 ,0x01}, // william 0318
348 {0xd6 ,0x96}, //antiflicker_step
349 {0xd7 ,0x03}, //AEC_exp_time_min ,william 20090312
354 //========= measure window
365 //========= close_frame
366 {0xed ,0x00}, //close_frame_num1 ,can be use to reduce FPS
367 {0xee ,0x00}, //close_frame_num2
368 {0xef ,0x00}, //close_frame_num
371 {0xf0 ,0x01}, //select page1
405 //=============================lscP
430 //============================= ccP
432 {0x69 ,0x03}, //cc_mode
451 //============================= AGP
477 //about gamma1 is hex r oct
496 //========= open functions
497 {0xf0 ,0x00}, //set back to page0
501 ///// Çë×¢Ò⣬µ÷ÕûGC0307µÄ¾µÏñºÍ·×ª£¬ÐèҪͬʱÐÞ¸ÄÈý¸ö¼Ä´æÆ÷£¬ÈçÏÂ:
507 { 0x01 ,0xfa}, // 24M
525 ///// ËÄÖÖ²»Í¬µÄ·×ªºÍ¾µÏñÉ趨£¬¿Í»§¿ÉÖ±½Ó¸´ÖÆ!!!!!!
544 // IMAGE_HV_MIRROR: // 180
554 static struct reginfo sensor_720p[]=
560 static struct reginfo sensor_sxga[] =
567 static struct reginfo sensor_svga[] =
575 static struct reginfo sensor_vga[] =
581 { 0x08 , 0x00},//0x10 james 20100715
585 { 0x0c , 0x88},//0x80 james 20100715
586 { 0x45 , 0x24}, // bit[7:2]=001001
587 { 0x48 , 0x84}, // bit[7]=1
612 static struct reginfo sensor_cif[] =
619 static struct reginfo sensor_qvga[] =
626 static struct reginfo sensor_qcif[] =
632 static struct reginfo sensor_ClrFmt_YUYV[]=
638 static struct reginfo sensor_ClrFmt_UYVY[]=
644 #if CONFIG_SENSOR_WhiteBalance
645 static struct reginfo sensor_WhiteB_Auto[]=
647 {0xc7,0x4c}, //for AWB can adjust back
656 /* Cloudy Colour Temperature : 6500K - 8000K */
657 static struct reginfo sensor_WhiteB_Cloudy[]=
659 {0x41,0x2b}, // Enable AWB
660 {0xc7,0x5a}, //WB_manual_gain
667 /* ClearDay Colour Temperature : 5000K - 6500K */
668 static struct reginfo sensor_WhiteB_ClearDay[]=
671 {0x41,0x2b}, // Enable AWB
679 /* Office Colour Temperature : 3500K - 5000K */
680 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
683 {0x41,0x2b}, // Enable AWB
693 /* Home Colour Temperature : 2500K - 3500K */
694 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
697 {0x41,0x2b}, // Enable AWB
705 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
706 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
710 #if CONFIG_SENSOR_Brightness
711 static struct reginfo sensor_Brightness0[]=
719 static struct reginfo sensor_Brightness1[]=
726 static struct reginfo sensor_Brightness2[]=
733 static struct reginfo sensor_Brightness3[]=
740 static struct reginfo sensor_Brightness4[]=
747 static struct reginfo sensor_Brightness5[]=
753 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
754 sensor_Brightness4, sensor_Brightness5,NULL,
759 #if CONFIG_SENSOR_Effect
760 static struct reginfo sensor_Effect_Normal[] =
782 static struct reginfo sensor_Effect_WandB[] =
784 {0x41,0x2f}, // danse
803 static struct reginfo sensor_Effect_Sepia[] =
827 static struct reginfo sensor_Effect_Negative[] =
849 static struct reginfo sensor_Effect_Bluish[] =
872 static struct reginfo sensor_Effect_Green[] =
894 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
895 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
898 #if CONFIG_SENSOR_Exposure
899 static struct reginfo sensor_Exposure0[]=
905 static struct reginfo sensor_Exposure1[]=
911 static struct reginfo sensor_Exposure2[]=
917 static struct reginfo sensor_Exposure3[]=
923 static struct reginfo sensor_Exposure4[]=
929 static struct reginfo sensor_Exposure5[]=
935 static struct reginfo sensor_Exposure6[]=
941 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
942 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
945 #if CONFIG_SENSOR_Saturation
946 static struct reginfo sensor_Saturation0[]=
951 static struct reginfo sensor_Saturation1[]=
956 static struct reginfo sensor_Saturation2[]=
960 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
963 #if CONFIG_SENSOR_Contrast
964 static struct reginfo sensor_Contrast0[]=
969 static struct reginfo sensor_Contrast1[]=
974 static struct reginfo sensor_Contrast2[]=
979 static struct reginfo sensor_Contrast3[]=
984 static struct reginfo sensor_Contrast4[]=
990 static struct reginfo sensor_Contrast5[]=
995 static struct reginfo sensor_Contrast6[]=
999 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1000 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1004 #if CONFIG_SENSOR_Mirror
1005 static struct reginfo sensor_MirrorOn[]=
1010 static struct reginfo sensor_MirrorOff[]=
1014 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1016 #if CONFIG_SENSOR_Flip
1017 static struct reginfo sensor_FlipOn[]=
1022 static struct reginfo sensor_FlipOff[]=
1026 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1029 #if CONFIG_SENSOR_Scene
1030 static struct reginfo sensor_SceneAuto[] =
1032 { 0xdd ,0x22}, //0x12
1039 static struct reginfo sensor_SceneNight[] =
1048 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1051 #if CONFIG_SENSOR_DigitalZoom
1052 static struct reginfo sensor_Zoom0[] =
1058 static struct reginfo sensor_Zoom1[] =
1064 static struct reginfo sensor_Zoom2[] =
1071 static struct reginfo sensor_Zoom3[] =
1076 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1078 static const struct v4l2_querymenu sensor_menus[] =
1080 #if CONFIG_SENSOR_WhiteBalance
1081 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1082 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1083 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1086 #if CONFIG_SENSOR_Effect
1087 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1088 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1089 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1092 #if CONFIG_SENSOR_Scene
1093 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1096 #if CONFIG_SENSOR_Flash
1097 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1098 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1102 static const struct v4l2_queryctrl sensor_controls[] =
1104 #if CONFIG_SENSOR_WhiteBalance
1106 .id = V4L2_CID_DO_WHITE_BALANCE,
1107 .type = V4L2_CTRL_TYPE_MENU,
1108 .name = "White Balance Control",
1116 #if CONFIG_SENSOR_Brightness
1118 .id = V4L2_CID_BRIGHTNESS,
1119 .type = V4L2_CTRL_TYPE_INTEGER,
1120 .name = "Brightness Control",
1128 #if CONFIG_SENSOR_Effect
1130 .id = V4L2_CID_EFFECT,
1131 .type = V4L2_CTRL_TYPE_MENU,
1132 .name = "Effect Control",
1140 #if CONFIG_SENSOR_Exposure
1142 .id = V4L2_CID_EXPOSURE,
1143 .type = V4L2_CTRL_TYPE_INTEGER,
1144 .name = "Exposure Control",
1152 #if CONFIG_SENSOR_Saturation
1154 .id = V4L2_CID_SATURATION,
1155 .type = V4L2_CTRL_TYPE_INTEGER,
1156 .name = "Saturation Control",
1164 #if CONFIG_SENSOR_Contrast
1166 .id = V4L2_CID_CONTRAST,
1167 .type = V4L2_CTRL_TYPE_INTEGER,
1168 .name = "Contrast Control",
1176 #if CONFIG_SENSOR_Mirror
1178 .id = V4L2_CID_HFLIP,
1179 .type = V4L2_CTRL_TYPE_BOOLEAN,
1180 .name = "Mirror Control",
1188 #if CONFIG_SENSOR_Flip
1190 .id = V4L2_CID_VFLIP,
1191 .type = V4L2_CTRL_TYPE_BOOLEAN,
1192 .name = "Flip Control",
1200 #if CONFIG_SENSOR_Scene
1202 .id = V4L2_CID_SCENE,
1203 .type = V4L2_CTRL_TYPE_MENU,
1204 .name = "Scene Control",
1212 #if CONFIG_SENSOR_DigitalZoom
1214 .id = V4L2_CID_ZOOM_RELATIVE,
1215 .type = V4L2_CTRL_TYPE_INTEGER,
1216 .name = "DigitalZoom Control",
1222 .id = V4L2_CID_ZOOM_ABSOLUTE,
1223 .type = V4L2_CTRL_TYPE_INTEGER,
1224 .name = "DigitalZoom Control",
1232 #if CONFIG_SENSOR_Focus
1234 .id = V4L2_CID_FOCUS_RELATIVE,
1235 .type = V4L2_CTRL_TYPE_INTEGER,
1236 .name = "Focus Control",
1242 .id = V4L2_CID_FOCUS_ABSOLUTE,
1243 .type = V4L2_CTRL_TYPE_INTEGER,
1244 .name = "Focus Control",
1248 .default_value = 125,
1252 #if CONFIG_SENSOR_Flash
1254 .id = V4L2_CID_FLASH,
1255 .type = V4L2_CTRL_TYPE_MENU,
1256 .name = "Flash Control",
1265 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1266 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1267 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1268 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1269 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1270 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1271 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1272 static int sensor_resume(struct soc_camera_device *icd);
1273 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1274 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1275 #if CONFIG_SENSOR_Effect
1276 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1278 #if CONFIG_SENSOR_WhiteBalance
1279 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1281 static int sensor_deactivate(struct i2c_client *client);
1283 static struct soc_camera_ops sensor_ops =
1285 .suspend = sensor_suspend,
1286 .resume = sensor_resume,
1287 .set_bus_param = sensor_set_bus_param,
1288 .query_bus_param = sensor_query_bus_param,
1289 .controls = sensor_controls,
1290 .menus = sensor_menus,
1291 .num_controls = ARRAY_SIZE(sensor_controls),
1292 .num_menus = ARRAY_SIZE(sensor_menus),
1295 /* only one fixed colorspace per pixelcode */
1296 struct sensor_datafmt {
1297 enum v4l2_mbus_pixelcode code;
1298 enum v4l2_colorspace colorspace;
1301 /* Find a data format by a pixel code in an array */
1302 static const struct sensor_datafmt *sensor_find_datafmt(
1303 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1307 for (i = 0; i < n; i++)
1308 if (fmt[i].code == code)
1314 static const struct sensor_datafmt sensor_colour_fmts[] = {
1315 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG},
1316 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG}
1318 typedef struct sensor_info_priv_s
1332 unsigned char mirror; /* HFLIP */
1333 unsigned char flip; /* VFLIP */
1334 unsigned int winseqe_cur_addr;
1335 struct sensor_datafmt fmt;
1336 unsigned int funmodule_state;
1337 } sensor_info_priv_t;
1341 struct v4l2_subdev subdev;
1342 struct i2c_client *client;
1343 sensor_info_priv_t info_priv;
1344 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1345 #if CONFIG_SENSOR_I2C_NOSCHED
1346 atomic_t tasklock_cnt;
1348 struct rk29camera_platform_data *sensor_io_request;
1349 struct rk29camera_gpio_res *sensor_gpio_res;
1352 static struct sensor* to_sensor(const struct i2c_client *client)
1354 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1357 static int sensor_task_lock(struct i2c_client *client, int lock)
1359 #if CONFIG_SENSOR_I2C_NOSCHED
1361 struct sensor *sensor = to_sensor(client);
1364 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1365 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1366 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1370 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1371 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1372 goto sensor_task_lock_err;
1377 atomic_add(1, &sensor->tasklock_cnt);
1379 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1380 atomic_sub(1, &sensor->tasklock_cnt);
1382 if (atomic_read(&sensor->tasklock_cnt) == 0)
1387 sensor_task_lock_err:
1395 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val);
1397 /* sensor register write */
1398 static int sensor_write_internal(struct i2c_client *client, u8 reg, u8 val)
1402 struct i2c_msg msg[1];
1404 buf[0] = reg & 0xFF;
1407 msg->addr = client->addr;
1408 msg->flags = client->flags;
1410 msg->len = sizeof(buf);
1411 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1412 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1417 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1418 err = i2c_transfer(client->adapter, msg, 1);
1423 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1432 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1436 for(cnt=0; cnt<1; cnt++)
1439 ret=sensor_write_internal(client, reg, val);
1447 printk("sensor_write() : reg %02x 0x%02x\n", reg, val);
1448 sensor_write_internal(client, reg, val);
1450 sensor_read(client, reg, &val_tmp);
1453 printk("sensor_write() error: reg %02x 0x%02x != 0x%02x \n", reg, val, val_tmp);
1457 while(val_tmp != val);
1462 /* sensor register read */
1463 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1468 struct i2c_msg msg[2];
1470 //buf[0] = reg >> 8;
1472 // buf[1] = reg & 0xFF;
1474 msg[0].addr = client->addr;
1475 msg[0].flags = client->flags;
1477 msg[0].len = sizeof(buf);
1478 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1479 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1481 msg[1].addr = client->addr;
1482 msg[1].flags = client->flags|I2C_M_RD;
1485 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1486 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1490 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1491 err = i2c_transfer(client->adapter, msg, 2);
1497 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1505 /* write a array of registers */
1507 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1512 for(i=0; regarray[i].reg!=0xff;i++)
1514 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1517 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1524 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1529 while (regarray[i].reg != 0)
1531 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1534 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1537 err = sensor_read(client, regarray[i].reg, &val_read);
1538 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1546 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
1553 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
1554 for(i=0;i<sizeof(sensor_init_data) / 2;i++)
1556 ret = sensor_read(client,regarray[i].reg,&value);
1559 SENSOR_TR("read value failed\n");
1562 if(regarray[i].val != value)
1564 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
1572 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1574 struct soc_camera_link *icl = to_soc_camera_link(icd);
1577 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1580 case Sensor_PowerDown:
1582 if (icl->powerdown) {
1583 ret = icl->powerdown(icd->pdev, on);
1584 if (ret == RK29_CAM_IO_SUCCESS) {
1588 icl->reset(icd->pdev);
1590 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1592 goto sensor_power_end;
1599 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1600 struct sensor *sensor = to_sensor(client);
1602 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1603 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1609 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1617 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1619 struct i2c_client *client = v4l2_get_subdevdata(sd);;
1620 struct soc_camera_device *icd = client->dev.platform_data;
1621 struct sensor *sensor = to_sensor(client);
1622 const struct v4l2_queryctrl *qctrl;
1623 const struct sensor_datafmt *fmt;
1627 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1629 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1631 goto sensor_INIT_ERR;
1635 if (sensor_task_lock(client,1)<0)
1636 goto sensor_INIT_ERR;
1637 /* ret = sensor_write(client, 0x12, 0x80);
1640 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1642 goto sensor_INIT_ERR;
1645 mdelay(5); */ //delay 5 microseconds
1647 ret = sensor_write_array(client, sensor_init_data);
1650 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1651 goto sensor_INIT_ERR;
1657 printk("****************** check init data\n");
1658 for(i=0; sensor_init_data[i].reg!=0xff; i++)
1660 sensor_read(client, sensor_init_data[i].reg, &val);
1661 printk("reg 0x%02x: org=0x%02x, val=0x%02x, %s\n",
1662 sensor_init_data[i].reg,
1663 sensor_init_data[i].val,
1665 sensor_init_data[i].val==val?"O":"X");
1667 printk("**********************************\n");
1671 sensor_task_lock(client,0);
1672 //icd->user_width = SENSOR_INIT_WIDTH;
1673 //icd->user_height = SENSOR_INIT_HEIGHT;
1674 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1675 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1677 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1679 goto sensor_INIT_ERR;
1681 sensor->info_priv.fmt = *fmt;
1683 /* sensor sensor information for initialization */
1684 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1686 sensor->info_priv.whiteBalance = qctrl->default_value;
1687 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1689 sensor->info_priv.brightness = qctrl->default_value;
1690 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1692 sensor->info_priv.effect = qctrl->default_value;
1693 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1695 sensor->info_priv.exposure = qctrl->default_value;
1697 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1699 sensor->info_priv.saturation = qctrl->default_value;
1700 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1702 sensor->info_priv.contrast = qctrl->default_value;
1703 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1705 sensor->info_priv.mirror = qctrl->default_value;
1706 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1708 sensor->info_priv.flip = qctrl->default_value;
1709 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1711 sensor->info_priv.scene = qctrl->default_value;
1712 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1714 sensor->info_priv.digitalzoom = qctrl->default_value;
1716 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1717 #if CONFIG_SENSOR_Focus
1719 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1721 sensor->info_priv.focus = qctrl->default_value;
1724 #if CONFIG_SENSOR_Flash
1725 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1727 sensor->info_priv.flash = qctrl->default_value;
1730 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);
1731 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1734 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1735 sensor_task_lock(client,0);
1736 sensor_deactivate(client);
1740 static int sensor_deactivate(struct i2c_client *client)
1742 struct soc_camera_device *icd = client->dev.platform_data;
1744 struct sensor *sensor = to_sensor(client);
1745 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1747 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1748 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
1749 sensor_task_lock(client, 1);
1750 sensor_task_lock(client, 0);
1752 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1755 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1756 icd->user_width = SENSOR_INIT_WIDTH;
1757 icd->user_height = SENSOR_INIT_HEIGHT;
1758 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1762 static struct reginfo sensor_power_down_sequence[]=
1766 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1769 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1771 if (pm_msg.event == PM_EVENT_SUSPEND) {
1772 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1773 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1775 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1778 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1780 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1785 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1791 static int sensor_resume(struct soc_camera_device *icd)
1795 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1797 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1801 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1807 static int sensor_set_bus_param(struct soc_camera_device *icd,
1808 unsigned long flags)
1814 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1816 struct soc_camera_link *icl = to_soc_camera_link(icd);
1817 unsigned long flags = SENSOR_BUS_PARAM;
1819 return soc_camera_apply_sensor_flags(icl, flags);
1822 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1824 struct i2c_client *client = v4l2_get_subdevdata(sd);
1825 struct soc_camera_device *icd = client->dev.platform_data;
1826 struct sensor *sensor = to_sensor(client);
1828 mf->width = icd->user_width;
1829 mf->height = icd->user_height;
1830 mf->code = sensor->info_priv.fmt.code;
1831 mf->colorspace = sensor->info_priv.fmt.colorspace;
1832 mf->field = V4L2_FIELD_NONE;
1836 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1840 if ((mf->width == 1024) && (mf->height == 768)) {
1842 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1844 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1846 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1848 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1853 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1857 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1861 if ((mf->width == 1280) && (mf->height == 720)) {
1863 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1868 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1871 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1873 struct i2c_client *client = v4l2_get_subdevdata(sd);
1874 const struct sensor_datafmt *fmt;
1875 struct sensor *sensor = to_sensor(client);
1876 const struct v4l2_queryctrl *qctrl;
1877 struct soc_camera_device *icd = client->dev.platform_data;
1878 struct reginfo *winseqe_set_addr=NULL;
1879 int ret=0, set_w,set_h;
1881 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1882 ARRAY_SIZE(sensor_colour_fmts));
1885 goto sensor_s_fmt_end;
1888 if (sensor->info_priv.fmt.code != mf->code) {
1891 case V4L2_MBUS_FMT_YUYV8_2X8:
1893 winseqe_set_addr = sensor_ClrFmt_YUYV;
1896 case V4L2_MBUS_FMT_UYVY8_2X8:
1898 winseqe_set_addr = sensor_ClrFmt_UYVY;
1904 if (winseqe_set_addr != NULL) {
1905 sensor_write_array(client, winseqe_set_addr);
1906 sensor->info_priv.fmt.code = mf->code;
1907 sensor->info_priv.fmt.colorspace= mf->colorspace;
1908 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1910 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1917 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg!=0xff)
1919 winseqe_set_addr = sensor_qcif;
1923 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg!=0xff)
1925 winseqe_set_addr = sensor_qvga;
1929 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg!=0xff)
1931 winseqe_set_addr = sensor_cif;
1935 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg!=0xff)
1937 winseqe_set_addr = sensor_vga;
1941 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg!=0xff)
1943 winseqe_set_addr = sensor_svga;
1947 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg!=0xff)
1949 winseqe_set_addr = sensor_720p;
1953 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg!=0xff)
1955 winseqe_set_addr = sensor_sxga;
1961 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1962 set_w = SENSOR_INIT_WIDTH;
1963 set_h = SENSOR_INIT_HEIGHT;
1964 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1967 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1968 #if CONFIG_SENSOR_Flash
1969 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1970 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1971 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1972 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1974 } else { /* ddl@rock-chips.com : Video */
1975 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1976 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1977 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1981 ret |= sensor_write_array(client, winseqe_set_addr);
1983 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1984 #if CONFIG_SENSOR_Flash
1985 if (sensor_fmt_capturechk(sd,mf) == true) {
1986 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1987 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1988 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1992 goto sensor_s_fmt_end;
1995 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1997 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1998 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1999 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2000 if (sensor->info_priv.whiteBalance != 0) {
2001 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2002 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2004 sensor->info_priv.snap2preview = true;
2005 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2006 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2007 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2008 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2009 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2010 sensor->info_priv.video2preview = true;
2011 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2012 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2013 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2014 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2015 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2016 sensor->info_priv.video2preview = false;
2017 sensor->info_priv.snap2preview = false;
2020 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2024 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2034 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2036 struct i2c_client *client = v4l2_get_subdevdata(sd);
2037 struct sensor *sensor = to_sensor(client);
2038 const struct sensor_datafmt *fmt;
2039 int ret = 0,set_w,set_h;
2041 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2042 ARRAY_SIZE(sensor_colour_fmts));
2044 fmt = &sensor->info_priv.fmt;
2045 mf->code = fmt->code;
2048 if (mf->height > SENSOR_MAX_HEIGHT)
2049 mf->height = SENSOR_MAX_HEIGHT;
2050 else if (mf->height < SENSOR_MIN_HEIGHT)
2051 mf->height = SENSOR_MIN_HEIGHT;
2053 if (mf->width > SENSOR_MAX_WIDTH)
2054 mf->width = SENSOR_MAX_WIDTH;
2055 else if (mf->width < SENSOR_MIN_WIDTH)
2056 mf->width = SENSOR_MIN_WIDTH;
2061 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg!=0xff)
2066 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg!=0xff)
2071 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg!=0xff)
2076 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg!=0xff)
2081 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg!=0xff)
2086 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg!=0xff)
2091 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg!=0xff)
2098 set_w = SENSOR_INIT_WIDTH;
2099 set_h = SENSOR_INIT_HEIGHT;
2104 mf->colorspace = fmt->colorspace;
2109 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2111 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2113 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2116 if (id->match.addr != client->addr)
2119 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
2124 #if CONFIG_SENSOR_Brightness
2125 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2127 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2129 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2131 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2133 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2135 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2138 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2142 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2146 #if CONFIG_SENSOR_Effect
2147 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2149 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2151 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2153 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2155 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2157 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2160 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2164 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2168 #if CONFIG_SENSOR_Exposure
2169 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2171 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2173 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2175 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2177 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2179 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2182 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2186 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2190 #if CONFIG_SENSOR_Saturation
2191 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2193 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2195 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2197 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2199 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2201 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2204 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2208 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2212 #if CONFIG_SENSOR_Contrast
2213 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2215 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2217 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2219 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2221 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2223 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2226 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2230 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2234 #if CONFIG_SENSOR_Mirror
2235 static int sensor_mirror(struct i2c_client *client, int on)
2240 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2242 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2244 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2246 if (sensor_mirror(client,value) != 0)
2247 SENSOR_TR("%s(%d): sensor_mirror failed, value:0x%x",__FUNCTION__, __LINE__,value);
2249 SENSOR_DG("%s(%d): sensor_mirror success, value:0x%x",__FUNCTION__, __LINE__,value);
2252 SENSOR_TR("\n %s..%s value = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2256 #if CONFIG_SENSOR_Flip
2257 static int sensor_flip(struct i2c_client *client, int on)
2262 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2264 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2266 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2268 if (sensor_flip(client,value) != 0)
2269 SENSOR_TR("%s(%d): sensor_flip failed, value:0x%x",__FUNCTION__, __LINE__,value);
2271 SENSOR_DG("%s(%d): sensor_flip success, value:0x%x",__FUNCTION__, __LINE__,value);
2274 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2278 #if CONFIG_SENSOR_Scene
2279 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2281 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2283 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2285 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2287 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2289 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2292 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2296 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2300 #if CONFIG_SENSOR_WhiteBalance
2301 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2303 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2305 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2307 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2309 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2311 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2314 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2318 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2322 #if CONFIG_SENSOR_DigitalZoom
2323 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2325 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2326 struct sensor *sensor = to_sensor(client);
2327 const struct v4l2_queryctrl *qctrl_info;
2328 int digitalzoom_cur, digitalzoom_total;
2330 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2334 digitalzoom_cur = sensor->info_priv.digitalzoom;
2335 digitalzoom_total = qctrl_info->maximum;
2337 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2339 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2343 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2345 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2349 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2351 *value = digitalzoom_total - digitalzoom_cur;
2354 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2356 *value = 0 - digitalzoom_cur;
2359 digitalzoom_cur += *value;
2361 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2363 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2365 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2368 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2375 #if CONFIG_SENSOR_Flash
2376 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2378 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2379 if (value == 3) { /* ddl@rock-chips.com: torch */
2380 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2382 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2384 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2388 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2393 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2395 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2396 struct sensor *sensor = to_sensor(client);
2397 const struct v4l2_queryctrl *qctrl;
2399 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2403 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2409 case V4L2_CID_BRIGHTNESS:
2411 ctrl->value = sensor->info_priv.brightness;
2414 case V4L2_CID_SATURATION:
2416 ctrl->value = sensor->info_priv.saturation;
2419 case V4L2_CID_CONTRAST:
2421 ctrl->value = sensor->info_priv.contrast;
2424 case V4L2_CID_DO_WHITE_BALANCE:
2426 ctrl->value = sensor->info_priv.whiteBalance;
2429 case V4L2_CID_EXPOSURE:
2431 ctrl->value = sensor->info_priv.exposure;
2434 case V4L2_CID_HFLIP:
2436 ctrl->value = sensor->info_priv.mirror;
2439 case V4L2_CID_VFLIP:
2441 ctrl->value = sensor->info_priv.flip;
2452 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2454 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2455 struct sensor *sensor = to_sensor(client);
2456 struct soc_camera_device *icd = client->dev.platform_data;
2457 const struct v4l2_queryctrl *qctrl;
2460 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2464 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2470 #if CONFIG_SENSOR_Brightness
2471 case V4L2_CID_BRIGHTNESS:
2473 if (ctrl->value != sensor->info_priv.brightness)
2475 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2479 sensor->info_priv.brightness = ctrl->value;
2484 #if CONFIG_SENSOR_Exposure
2485 case V4L2_CID_EXPOSURE:
2487 if (ctrl->value != sensor->info_priv.exposure)
2489 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2493 sensor->info_priv.exposure = ctrl->value;
2498 #if CONFIG_SENSOR_Saturation
2499 case V4L2_CID_SATURATION:
2501 if (ctrl->value != sensor->info_priv.saturation)
2503 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2507 sensor->info_priv.saturation = ctrl->value;
2512 #if CONFIG_SENSOR_Contrast
2513 case V4L2_CID_CONTRAST:
2515 if (ctrl->value != sensor->info_priv.contrast)
2517 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2521 sensor->info_priv.contrast = ctrl->value;
2526 #if CONFIG_SENSOR_WhiteBalance
2527 case V4L2_CID_DO_WHITE_BALANCE:
2529 if (ctrl->value != sensor->info_priv.whiteBalance)
2531 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2535 sensor->info_priv.whiteBalance = ctrl->value;
2540 #if CONFIG_SENSOR_Mirror
2541 case V4L2_CID_HFLIP:
2543 if (ctrl->value != sensor->info_priv.mirror)
2545 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2547 sensor->info_priv.mirror = ctrl->value;
2552 #if CONFIG_SENSOR_Flip
2553 case V4L2_CID_VFLIP:
2555 if (ctrl->value != sensor->info_priv.flip)
2557 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2559 sensor->info_priv.flip = ctrl->value;
2570 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2572 const struct v4l2_queryctrl *qctrl;
2573 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2574 struct sensor *sensor = to_sensor(client);
2576 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2580 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2584 switch (ext_ctrl->id)
2586 case V4L2_CID_SCENE:
2588 ext_ctrl->value = sensor->info_priv.scene;
2591 case V4L2_CID_EFFECT:
2593 ext_ctrl->value = sensor->info_priv.effect;
2596 case V4L2_CID_ZOOM_ABSOLUTE:
2598 ext_ctrl->value = sensor->info_priv.digitalzoom;
2601 case V4L2_CID_ZOOM_RELATIVE:
2605 case V4L2_CID_FOCUS_ABSOLUTE:
2607 ext_ctrl->value = sensor->info_priv.focus;
2610 case V4L2_CID_FOCUS_RELATIVE:
2614 case V4L2_CID_FLASH:
2616 ext_ctrl->value = sensor->info_priv.flash;
2624 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2626 const struct v4l2_queryctrl *qctrl;
2627 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2628 struct sensor *sensor = to_sensor(client);
2631 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2635 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2640 switch (ext_ctrl->id)
2642 #if CONFIG_SENSOR_Scene
2643 case V4L2_CID_SCENE:
2645 if (ext_ctrl->value != sensor->info_priv.scene)
2647 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2649 sensor->info_priv.scene = ext_ctrl->value;
2654 #if CONFIG_SENSOR_Effect
2655 case V4L2_CID_EFFECT:
2657 if (ext_ctrl->value != sensor->info_priv.effect)
2659 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2661 sensor->info_priv.effect= ext_ctrl->value;
2666 #if CONFIG_SENSOR_DigitalZoom
2667 case V4L2_CID_ZOOM_ABSOLUTE:
2669 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2672 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2674 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2676 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2678 sensor->info_priv.digitalzoom += val_offset;
2680 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2685 case V4L2_CID_ZOOM_RELATIVE:
2687 if (ext_ctrl->value)
2689 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2691 sensor->info_priv.digitalzoom += ext_ctrl->value;
2693 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2698 #if CONFIG_SENSOR_Focus
2699 case V4L2_CID_FOCUS_ABSOLUTE:
2701 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2704 if (ext_ctrl->value != sensor->info_priv.focus)
2706 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2708 sensor->info_priv.focus += val_offset;
2713 case V4L2_CID_FOCUS_RELATIVE:
2715 if (ext_ctrl->value)
2717 sensor->info_priv.focus += ext_ctrl->value;
2719 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2724 #if CONFIG_SENSOR_Flash
2725 case V4L2_CID_FLASH:
2727 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2729 sensor->info_priv.flash = ext_ctrl->value;
2731 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2742 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2744 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2745 struct soc_camera_device *icd = client->dev.platform_data;
2746 int i, error_cnt=0, error_idx=-1;
2749 for (i=0; i<ext_ctrl->count; i++) {
2750 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2757 error_idx = ext_ctrl->count;
2759 if (error_idx != -1) {
2760 ext_ctrl->error_idx = error_idx;
2767 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2769 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2770 struct soc_camera_device *icd = client->dev.platform_data;
2771 int i, error_cnt=0, error_idx=-1;
2774 for (i=0; i<ext_ctrl->count; i++) {
2775 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2782 error_idx = ext_ctrl->count;
2784 if (error_idx != -1) {
2785 ext_ctrl->error_idx = error_idx;
2792 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2793 * this wasn't our capture interface, so, we wait for the right one */
2794 static int sensor_video_probe(struct soc_camera_device *icd,
2795 struct i2c_client *client)
2799 struct sensor *sensor = to_sensor(client);
2801 /* We must have a parent by now. And it cannot be a wrong one.
2802 * So this entire test is completely redundant. */
2803 if (!icd->dev.parent ||
2804 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2807 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2809 printk("%s(): set powerdn failed\n", __FUNCTION__);
2810 goto sensor_video_probe_err;
2814 /* ret = sensor_write(client, 0x12, 0x80);
2817 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2820 mdelay(50); *///delay 5 microseconds
2822 /* check if it is an sensor sensor */
2823 ret = sensor_read(client, 0x00, &pid);
2825 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2829 goto sensor_video_probe_err;
2832 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2833 if (pid == SENSOR_ID) {
2834 sensor->model = SENSOR_V4L2_IDENT;
2836 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2839 goto sensor_video_probe_err;
2845 sensor_video_probe_err:
2850 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2852 struct i2c_client *client = v4l2_get_subdevdata(sd);;
2853 struct soc_camera_device *icd = client->dev.platform_data;
2854 struct sensor *sensor = to_sensor(client);
2856 #if CONFIG_SENSOR_Flash
2860 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2863 case RK29_CAM_SUBDEV_DEACTIVATE:
2865 sensor_deactivate(client);
2869 case RK29_CAM_SUBDEV_IOREQUEST:
2871 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2872 if (sensor->sensor_io_request != NULL) {
2873 sensor->sensor_gpio_res = NULL;
2874 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2875 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2876 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2877 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2880 if (sensor->sensor_gpio_res == NULL) {
2881 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2883 goto sensor_ioctl_end;
2886 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2888 goto sensor_ioctl_end;
2890 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2892 #if CONFIG_SENSOR_Flash
2893 if (sensor->sensor_gpio_res) {
2894 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2895 for (i = 0; i < icd->ops->num_controls; i++) {
2896 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2897 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2900 sensor->info_priv.flash = 0xff;
2901 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2909 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2917 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2918 enum v4l2_mbus_pixelcode *code)
2920 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2923 *code = sensor_colour_fmts[index].code;
2926 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2927 .init = sensor_init,
2928 .g_ctrl = sensor_g_control,
2929 .s_ctrl = sensor_s_control,
2930 .g_ext_ctrls = sensor_g_ext_controls,
2931 .s_ext_ctrls = sensor_s_ext_controls,
2932 .g_chip_ident = sensor_g_chip_ident,
2933 .ioctl = sensor_ioctl,
2936 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2937 .s_mbus_fmt = sensor_s_fmt,
2938 .g_mbus_fmt = sensor_g_fmt,
2939 .try_mbus_fmt = sensor_try_fmt,
2940 .enum_mbus_fmt = sensor_enum_fmt,
2943 static struct v4l2_subdev_ops sensor_subdev_ops = {
2944 .core = &sensor_subdev_core_ops,
2945 .video = &sensor_subdev_video_ops,
2948 static int sensor_probe(struct i2c_client *client,
2949 const struct i2c_device_id *did)
2951 struct sensor *sensor;
2952 struct soc_camera_device *icd = client->dev.platform_data;
2953 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2954 struct soc_camera_link *icl;
2957 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2959 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2963 icl = to_soc_camera_link(icd);
2965 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2969 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2970 dev_warn(&adapter->dev,
2971 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2975 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2979 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2981 /* Second stage probe - when a capture adapter is there */
2982 icd->ops = &sensor_ops;
2983 sensor->info_priv.fmt = sensor_colour_fmts[0];
2984 #if CONFIG_SENSOR_I2C_NOSCHED
2985 atomic_set(&sensor->tasklock_cnt,0);
2988 ret = sensor_video_probe(icd, client);
2991 i2c_set_clientdata(client, NULL);
2995 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2999 static int sensor_remove(struct i2c_client *client)
3001 struct sensor *sensor = to_sensor(client);
3002 struct soc_camera_device *icd = client->dev.platform_data;
3005 i2c_set_clientdata(client, NULL);
3006 client->driver = NULL;
3012 static const struct i2c_device_id sensor_id[] = {
3013 {SENSOR_NAME_STRING(), 0 },
3016 MODULE_DEVICE_TABLE(i2c, sensor_id);
3018 static struct i2c_driver sensor_i2c_driver = {
3020 .name = SENSOR_NAME_STRING(),
3022 .probe = sensor_probe,
3023 .remove = sensor_remove,
3024 .id_table = sensor_id,
3027 static int __init sensor_mod_init(void)
3029 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3030 return i2c_add_driver(&sensor_i2c_driver);
3033 static void __exit sensor_mod_exit(void)
3035 i2c_del_driver(&sensor_i2c_driver);
3038 device_initcall_sync(sensor_mod_init);
3039 module_exit(sensor_mod_exit);
3041 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3042 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3043 MODULE_LICENSE("GPL");