2 * Driver for OV5642 CMOS Image Sensor from OmniVision
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
23 #include <linux/vmalloc.h>
27 module_param(debug, int, S_IRUGO|S_IWUSR);
29 #define dprintk(level, fmt, arg...) do { \
31 printk(KERN_WARNING fmt , ## arg); } while (0)
33 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
34 #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_OV5642
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV5642
49 #define SENSOR_ID 0x5642
50 #define SENSOR_MIN_WIDTH 176
51 #define SENSOR_MIN_HEIGHT 144
52 #define SENSOR_MAX_WIDTH_REAL 2592
53 #define SENSOR_MAX_HEIGHT_REAL 1944
54 #if defined(CONFIG_SOC_CAMERA_OV5642_INTERPOLATION_8M)
55 #define SENSOR_MAX_WIDTH 3264
56 #define SENSOR_MAX_HEIGHT 2448
58 #define SENSOR_MAX_WIDTH SENSOR_MAX_WIDTH_REAL
59 #define SENSOR_MAX_HEIGHT SENSOR_MAX_HEIGHT_REAL
61 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
62 #define SENSOR_INIT_HEIGHT sensor_init_height
63 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
64 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
65 #define SENSOR_BUS_PARAM sensor_init_busparam
67 #define CONFIG_SENSOR_WhiteBalance 1
68 #define CONFIG_SENSOR_Brightness 0
69 #define CONFIG_SENSOR_Contrast 0
70 #define CONFIG_SENSOR_Saturation 0
71 #define CONFIG_SENSOR_Effect 1
72 #define CONFIG_SENSOR_Scene 1
73 #define CONFIG_SENSOR_DigitalZoom 0
74 #define CONFIG_SENSOR_Exposure 0
75 #define CONFIG_SENSOR_Flash 1
76 #define CONFIG_SENSOR_Mirror 0
77 #define CONFIG_SENSOR_Flip 0
78 #ifdef CONFIG_OV5642_AUTOFOCUS
79 #define CONFIG_SENSOR_Focus 1
80 #define CONFIG_SENSOR_FocusContinues 0
81 #include "ov5642_af_firmware.c"
83 #define CONFIG_SENSOR_Focus 0
86 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
87 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
88 #define CONFIG_SENSOR_I2C_NOSCHED 0
89 #define CONFIG_SENSOR_I2C_RDWRCHK 0
91 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
92 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
93 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
94 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
95 #define COLOR_TEMPERATURE_OFFICE_DN 3500
96 #define COLOR_TEMPERATURE_OFFICE_UP 5000
97 #define COLOR_TEMPERATURE_HOME_DN 2500
98 #define COLOR_TEMPERATURE_HOME_UP 3500
100 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
101 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
103 #define SENSOR_AF_IS_ERR (0x00<<0)
104 #define SENSOR_AF_IS_OK (0x01<<0)
105 #define SENSOR_INIT_IS_ERR (0x00<<28)
106 #define SENSOR_INIT_IS_OK (0x01<<28)
108 #if CONFIG_SENSOR_Focus
109 #define SENSOR_AF_MODE_INFINITY 0
110 #define SENSOR_AF_MODE_MACRO 1
111 #define SENSOR_AF_MODE_FIXED 2
112 #define SENSOR_AF_MODE_AUTO 3
113 #define SENSOR_AF_MODE_CONTINUOUS 4
114 #define SENSOR_AF_MODE_CLOSE 5
117 #if CONFIG_SENSOR_Focus
118 /* ov5642 VCM Command and Status Registers */
119 #define CMD_MAIN_Reg 0x3024
120 #define CMD_TAG_Reg 0x3025
121 #define CMD_PARA0_Reg 0x5085
122 #define CMD_PARA1_Reg 0x5084
123 #define CMD_PARA2_Reg 0x5083
124 #define CMD_PARA3_Reg 0x5082
125 #define STA_ZONE_Reg 0x3026
126 #define STA_FOCUS_Reg 0x3027
128 /* ov5642 VCM Command */
129 #define OverlayEn_Cmd 0x01
130 #define OverlayDis_Cmd 0x02
131 #define SingleFocus_Cmd 0x03
132 #define ConstFocus_Cmd 0x04
133 #define StepMode_Cmd 0x05
134 #define PauseFocus_Cmd 0x06
135 #define ReturnIdle_Cmd 0x08
136 #define SetZone_Cmd 0x10
137 #define UpdateZone_Cmd 0x12
138 #define SetMotor_Cmd 0x20
140 /* ov5642 Focus State */
141 #define S_FIRWRE 0xFF
142 #define S_STARTUP 0xfa
144 #define S_DRVICERR 0xee
146 #define S_FOCUSING 0x01
147 #define S_FOCUSED 0x02
148 #define S_CAPTURE 0x12
151 /* ov5642 Zone State */
152 #define Zone_Is_Focused(a, zone_val) (zone_val&(1<<(a-3)))
153 #define Zone_Get_ID(zone_val) (zone_val&0x03)
155 #define Zone_CenterMode 0x01
156 #define Zone_5xMode 0x02
157 #define Zone_5PlusMode 0x03
158 #define Zone_4fMode 0x04
160 #define ZoneSel_Auto 0x0b
161 #define ZoneSel_SemiAuto 0x0c
162 #define ZoneSel_Manual 0x0d
163 #define ZoneSel_Rotate 0x0e
165 /* ov5642 Step Focus Commands */
166 #define StepFocus_Near_Tag 0x01
167 #define StepFocus_Far_Tag 0x02
168 #define StepFocus_Furthest_Tag 0x03
169 #define StepFocus_Nearest_Tag 0x04
170 #define StepFocus_Spec_Tag 0x10
174 //flash off in fixed time to prevent from too hot , zyc
176 struct soc_camera_device *icd;
177 struct hrtimer timer;
179 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
181 static struct flash_timer flash_off_timer;
182 //for user defined if user want to customize the series , zyc
183 #ifdef CONFIG_OV5642_USER_DEFINED_SERIES
184 #include "ov5642_user_series.c"
186 /* init 800X600 SVGA */
187 static struct reginfo sensor_init_data[] =
257 {0x4300 , 0x32}, //UYVY
860 /* 720p 15fps @ 1280x720 */
862 static struct reginfo sensor_720p[]=
865 {SEQUENCE_PROPERTY, SEQUENCE_INIT},
1326 {0x3011, 0x10 },//15fps 0x08 // 10fps: 0x05
1379 {0x4300, 0x32 }, // 0x30---> 0x32, set yuv
1384 //{0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
1465 //{0x3008,0x02}, //software wake
1471 /* 1080p, 0x15fps, 0xyuv @1920x1080 */
1473 static struct reginfo sensor_1080p[]=
1476 {SEQUENCE_PROPERTY, SEQUENCE_INIT},
1489 { 0x3011, 0x05 }, //10 fps 0x05 //15fps 0x08
1937 { 0x3011, 0x07 }, //10 fps 0x05 //15fps 0x07
1945 { 0x3807, 0x39 },//0x3a
1983 { 0x4300, 0x32 }, // set yuv, 0x30--> 0x32
1988 //{0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2003 {0x3622,0x00},//60},
2005 {0x3604,0x40},//48},
2034 { 0x3011, 0x07 }, //10 fps 0x05 //15fps 0x08
2037 {0x3a08,0x14}, //0x05
2038 {0x3a09,0xe0}, //0xf5
2039 {0x3a0a,0x11}, //0x04
2040 {0x3a0b,0x60}, //0xf6
2041 {0x3a0d,0x04}, //0x0b
2042 {0x3a0e,0x03}, //0x0d
2068 //{0x3008,0x02}, //software wake
2073 /* 2592X1944 QSXGA */
2074 static struct reginfo sensor_qsxga[] =
2076 {0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2144 {0x3008,0x02}, //software wake
2147 /* 2048*1536 QXGA */
2148 static struct reginfo sensor_qxga[] =
2150 {0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2244 {0x3008,0x02}, //software wake
2248 /* 1600X1200 UXGA */
2249 static struct reginfo sensor_uxga[] =
2251 {0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2345 {0x3008,0x02}, //software wake
2348 /* 1280X1024 SXGA */
2349 static struct reginfo sensor_sxga[] =
2354 static struct reginfo sensor_xga[] =
2356 {0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2450 {0x3008,0x02}, //software wake
2455 static struct reginfo sensor_svga[] =
2545 static struct reginfo sensor_vga[] =
2551 static struct reginfo sensor_cif[] =
2582 static struct reginfo sensor_qvga[] =
2588 static struct reginfo sensor_qcif[] =
2620 static struct reginfo ov2655_qqvga[] =
2664 static struct reginfo ov2655_Sharpness_auto[] =
2669 static struct reginfo ov2655_Sharpness1[] =
2675 static struct reginfo ov2655_Sharpness2[][3] =
2682 static struct reginfo ov2655_Sharpness3[] =
2688 static struct reginfo ov2655_Sharpness4[]=
2695 static struct reginfo ov2655_Sharpness5[] =
2703 static struct reginfo sensor_ClrFmt_YUYV[]=
2709 static struct reginfo sensor_ClrFmt_UYVY[]=
2716 #if CONFIG_SENSOR_WhiteBalance
2717 static struct reginfo sensor_WhiteB_Auto[]=
2739 /* Cloudy Colour Temperature : 6500K - 8000K */
2740 static struct reginfo sensor_WhiteB_Cloudy[]=
2751 /* ClearDay Colour Temperature : 5000K - 6500K */
2752 static struct reginfo sensor_WhiteB_ClearDay[]=
2764 /* Office Colour Temperature : 3500K - 5000K */
2765 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
2778 /* Home Colour Temperature : 2500K - 3500K */
2779 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
2791 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
2792 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
2796 #if CONFIG_SENSOR_Brightness
2797 static struct reginfo sensor_Brightness0[]=
2802 static struct reginfo sensor_Brightness1[]=
2807 static struct reginfo sensor_Brightness2[]=
2812 static struct reginfo sensor_Brightness3[]=
2817 static struct reginfo sensor_Brightness4[]=
2822 static struct reginfo sensor_Brightness5[]=
2826 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
2827 sensor_Brightness4, sensor_Brightness5,NULL,
2832 #if CONFIG_SENSOR_Effect
2833 static struct reginfo sensor_Effect_Normal[] =
2840 static struct reginfo sensor_Effect_WandB[] =
2849 static struct reginfo sensor_Effect_Sepia[] =
2858 static struct reginfo sensor_Effect_Negative[] =
2865 static struct reginfo sensor_Effect_Bluish[] =
2875 static struct reginfo sensor_Effect_Green[] =
2884 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
2885 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
2888 #if CONFIG_SENSOR_Exposure
2889 static struct reginfo sensor_Exposure0[]=
2894 static struct reginfo sensor_Exposure1[]=
2899 static struct reginfo sensor_Exposure2[]=
2904 static struct reginfo sensor_Exposure3[]=
2909 static struct reginfo sensor_Exposure4[]=
2914 static struct reginfo sensor_Exposure5[]=
2919 static struct reginfo sensor_Exposure6[]=
2924 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
2925 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
2928 #if CONFIG_SENSOR_Saturation
2929 static struct reginfo sensor_Saturation0[]=
2934 static struct reginfo sensor_Saturation1[]=
2939 static struct reginfo sensor_Saturation2[]=
2943 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
2946 #if CONFIG_SENSOR_Contrast
2947 static struct reginfo sensor_Contrast0[]=
2952 static struct reginfo sensor_Contrast1[]=
2957 static struct reginfo sensor_Contrast2[]=
2962 static struct reginfo sensor_Contrast3[]=
2967 static struct reginfo sensor_Contrast4[]=
2973 static struct reginfo sensor_Contrast5[]=
2978 static struct reginfo sensor_Contrast6[]=
2982 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
2983 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
2987 #if CONFIG_SENSOR_Mirror
2988 static struct reginfo sensor_MirrorOn[]=
2993 static struct reginfo sensor_MirrorOff[]=
2997 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
2999 #if CONFIG_SENSOR_Flip
3000 static struct reginfo sensor_FlipOn[]=
3005 static struct reginfo sensor_FlipOff[]=
3009 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
3012 #if CONFIG_SENSOR_Scene
3013 static struct reginfo sensor_SceneAuto[] =
3019 static struct reginfo sensor_SceneNight[] =
3022 //15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mzh pclk
3040 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
3043 #if CONFIG_SENSOR_DigitalZoom
3044 static struct reginfo sensor_Zoom0[] =
3049 static struct reginfo sensor_Zoom1[] =
3054 static struct reginfo sensor_Zoom2[] =
3060 static struct reginfo sensor_Zoom3[] =
3064 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
3066 static const struct v4l2_querymenu sensor_menus[] =
3068 #if CONFIG_SENSOR_WhiteBalance
3069 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
3070 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
3071 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
3074 #if CONFIG_SENSOR_Effect
3075 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
3076 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
3077 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
3080 #if CONFIG_SENSOR_Scene
3081 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
3084 #if CONFIG_SENSOR_Flash
3085 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
3086 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
3090 static struct v4l2_queryctrl sensor_controls[] =
3092 #if CONFIG_SENSOR_WhiteBalance
3094 .id = V4L2_CID_DO_WHITE_BALANCE,
3095 .type = V4L2_CTRL_TYPE_MENU,
3096 .name = "White Balance Control",
3104 #if CONFIG_SENSOR_Brightness
3106 .id = V4L2_CID_BRIGHTNESS,
3107 .type = V4L2_CTRL_TYPE_INTEGER,
3108 .name = "Brightness Control",
3116 #if CONFIG_SENSOR_Effect
3118 .id = V4L2_CID_EFFECT,
3119 .type = V4L2_CTRL_TYPE_MENU,
3120 .name = "Effect Control",
3128 #if CONFIG_SENSOR_Exposure
3130 .id = V4L2_CID_EXPOSURE,
3131 .type = V4L2_CTRL_TYPE_INTEGER,
3132 .name = "Exposure Control",
3140 #if CONFIG_SENSOR_Saturation
3142 .id = V4L2_CID_SATURATION,
3143 .type = V4L2_CTRL_TYPE_INTEGER,
3144 .name = "Saturation Control",
3152 #if CONFIG_SENSOR_Contrast
3154 .id = V4L2_CID_CONTRAST,
3155 .type = V4L2_CTRL_TYPE_INTEGER,
3156 .name = "Contrast Control",
3164 #if CONFIG_SENSOR_Mirror
3166 .id = V4L2_CID_HFLIP,
3167 .type = V4L2_CTRL_TYPE_BOOLEAN,
3168 .name = "Mirror Control",
3176 #if CONFIG_SENSOR_Flip
3178 .id = V4L2_CID_VFLIP,
3179 .type = V4L2_CTRL_TYPE_BOOLEAN,
3180 .name = "Flip Control",
3188 #if CONFIG_SENSOR_Scene
3190 .id = V4L2_CID_SCENE,
3191 .type = V4L2_CTRL_TYPE_MENU,
3192 .name = "Scene Control",
3200 #if CONFIG_SENSOR_DigitalZoom
3202 .id = V4L2_CID_ZOOM_RELATIVE,
3203 .type = V4L2_CTRL_TYPE_INTEGER,
3204 .name = "DigitalZoom Control",
3210 .id = V4L2_CID_ZOOM_ABSOLUTE,
3211 .type = V4L2_CTRL_TYPE_INTEGER,
3212 .name = "DigitalZoom Control",
3220 #if CONFIG_SENSOR_Focus
3222 .id = V4L2_CID_FOCUS_RELATIVE,
3223 .type = V4L2_CTRL_TYPE_INTEGER,
3224 .name = "Focus Control",
3230 .id = V4L2_CID_FOCUS_ABSOLUTE,
3231 .type = V4L2_CTRL_TYPE_INTEGER,
3232 .name = "Focus Control",
3236 .default_value = 125,
3239 .id = V4L2_CID_FOCUS_AUTO,
3240 .type = V4L2_CTRL_TYPE_BOOLEAN,
3241 .name = "Focus Control",
3247 #if CONFIG_SENSOR_FocusContinues
3249 .id = V4L2_CID_FOCUS_CONTINUOUS,
3250 .type = V4L2_CTRL_TYPE_BOOLEAN,
3251 .name = "Focus Control",
3260 #if CONFIG_SENSOR_Flash
3262 .id = V4L2_CID_FLASH,
3263 .type = V4L2_CTRL_TYPE_MENU,
3264 .name = "Flash Control",
3273 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
3274 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
3275 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
3276 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
3277 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
3278 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
3279 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
3280 static int sensor_resume(struct soc_camera_device *icd);
3281 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
3282 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
3283 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
3284 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
3285 static int sensor_deactivate(struct i2c_client *client);
3286 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
3287 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
3289 static struct soc_camera_ops sensor_ops =
3291 .suspend = sensor_suspend,
3292 .resume = sensor_resume,
3293 .set_bus_param = sensor_set_bus_param,
3294 .query_bus_param = sensor_query_bus_param,
3295 .controls = sensor_controls,
3296 .menus = sensor_menus,
3297 .num_controls = ARRAY_SIZE(sensor_controls),
3298 .num_menus = ARRAY_SIZE(sensor_menus),
3301 /* only one fixed colorspace per pixelcode */
3302 struct sensor_datafmt {
3303 enum v4l2_mbus_pixelcode code;
3304 enum v4l2_colorspace colorspace;
3307 /* Find a data format by a pixel code in an array */
3308 static const struct sensor_datafmt *sensor_find_datafmt(
3309 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
3313 for (i = 0; i < n; i++)
3314 if (fmt[i].code == code)
3320 static const struct sensor_datafmt sensor_colour_fmts[] = {
3321 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
3322 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
3328 WqCmd_af_special_pos,
3332 WqCmd_af_update_zone
3334 enum sensor_wq_result
3342 struct i2c_client *client;
3343 struct delayed_work dwork;
3344 enum sensor_wq_cmd cmd;
3345 wait_queue_head_t done;
3346 enum sensor_wq_result result;
3350 typedef struct sensor_info_priv_s
3364 unsigned char mirror; /* HFLIP */
3365 unsigned char flip; /* VFLIP */
3368 struct reginfo *winseqe_cur_addr;
3369 struct sensor_datafmt fmt;
3370 unsigned int enable;
3371 unsigned int funmodule_state;
3372 } sensor_info_priv_t;
3376 struct sensor_parameter
3378 unsigned short int preview_maxlines;
3379 unsigned short int preview_exposure;
3380 unsigned short int preview_line_width;
3381 unsigned short int preview_gain;
3383 unsigned short int capture_framerate;
3384 unsigned short int preview_framerate;
3389 struct v4l2_subdev subdev;
3390 struct i2c_client *client;
3391 sensor_info_priv_t info_priv;
3392 struct sensor_parameter parameter;
3393 struct workqueue_struct *sensor_wq;
3394 struct mutex wq_lock;
3395 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
3396 #if CONFIG_SENSOR_I2C_NOSCHED
3397 atomic_t tasklock_cnt;
3399 struct rk29camera_platform_data *sensor_io_request;
3400 struct rk29camera_gpio_res *sensor_gpio_res;
3403 static struct sensor* to_sensor(const struct i2c_client *client)
3405 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
3408 static int sensor_task_lock(struct i2c_client *client, int lock)
3410 #if CONFIG_SENSOR_I2C_NOSCHED
3412 struct sensor *sensor = to_sensor(client);
3415 if (atomic_read(&sensor->tasklock_cnt) == 0) {
3416 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
3417 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
3421 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
3422 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
3423 goto sensor_task_lock_err;
3428 atomic_add(1, &sensor->tasklock_cnt);
3430 if (atomic_read(&sensor->tasklock_cnt) > 0) {
3431 atomic_sub(1, &sensor->tasklock_cnt);
3433 if (atomic_read(&sensor->tasklock_cnt) == 0)
3438 sensor_task_lock_err:
3446 /* sensor register write */
3447 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
3451 struct i2c_msg msg[1];
3454 buf[1] = reg & 0xFF;
3457 msg->addr = client->addr;
3458 msg->flags = client->flags;
3460 msg->len = sizeof(buf);
3461 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
3462 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
3467 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
3468 err = i2c_transfer(client->adapter, msg, 1);
3473 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
3481 /* sensor register read */
3482 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
3486 struct i2c_msg msg[2];
3489 buf[1] = reg & 0xFF;
3491 msg[0].addr = client->addr;
3492 msg[0].flags = client->flags;
3494 msg[0].len = sizeof(buf);
3495 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
3496 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
3498 msg[1].addr = client->addr;
3499 msg[1].flags = client->flags|I2C_M_RD;
3502 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
3503 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
3507 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
3508 err = i2c_transfer(client->adapter, msg, 2);
3514 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
3522 /* write a array of registers */
3523 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
3527 #if CONFIG_SENSOR_Focus
3528 struct sensor *sensor = to_sensor(client);
3530 #if CONFIG_SENSOR_I2C_RDWRCHK
3535 if (sensor_task_lock(client, 1) < 0)
3536 goto sensor_write_array_end;
3537 while (regarray[i].reg != 0)
3539 #if CONFIG_SENSOR_Focus
3540 if ((regarray == sensor_af_firmware) && (sensor->info_priv.enable == 0)) {
3541 SENSOR_DG("%s disable, Download af firmware terminated!\n",SENSOR_NAME_STRING());
3543 goto sensor_write_array_end;
3547 err = sensor_write(client, regarray[i].reg, regarray[i].val);
3551 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
3555 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
3557 goto sensor_write_array_end;
3560 #if CONFIG_SENSOR_I2C_RDWRCHK
3561 sensor_read(client, regarray[i].reg, &valchk);
3562 if (valchk != regarray[i].val)
3563 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
3570 #if CONFIG_SENSOR_Focus
3571 if (((regarray->reg == SEQUENCE_PROPERTY) && (regarray->val == SEQUENCE_INIT))
3572 || (regarray == sensor_init_data)) {
3573 sensor->info_priv.affm_reinit = 1;
3577 sensor_write_array_end:
3578 sensor_task_lock(client,0);
3581 #if CONFIG_SENSOR_I2C_RDWRCHK
3582 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
3590 while (regarray[i].reg != 0)
3592 sensor_read(client, regarray[i].reg, &valchk);
3593 if (valchk != regarray[i].val)
3594 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
3601 #if CONFIG_SENSOR_Focus
3608 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
3611 char read_tag=0xff,cnt;
3612 struct sensor *sensor = to_sensor(client);
3614 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3615 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3616 goto sensor_af_cmdset_err;
3620 if (cmdinfo->validate_bit & 0x80) {
3621 if (sensor_write(client, CMD_TAG_Reg, cmdinfo->cmd_tag)) {
3622 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
3623 goto sensor_af_cmdset_err;
3625 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
3627 for (i=0; i<4; i++) {
3628 if (cmdinfo->validate_bit & (1<<i)) {
3629 if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
3630 SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
3631 goto sensor_af_cmdset_err;
3633 SENSOR_DG("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
3637 if (sensor_write(client, CMD_TAG_Reg, 0xff)) {
3638 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
3639 goto sensor_af_cmdset_err;
3641 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
3644 if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
3645 SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
3646 goto sensor_af_cmdset_err;
3653 if (sensor_read(client,CMD_TAG_Reg,&read_tag)){
3654 SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
3657 } while((read_tag != 0x00)&& (cnt++<100));
3659 SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
3661 sensor_af_cmdset_err:
3665 static int sensor_af_idlechk(struct i2c_client *client)
3669 struct sensor *sensor = to_sensor(client);
3671 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3672 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3674 goto sensor_af_idlechk_end;
3680 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3682 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3684 goto sensor_af_idlechk_end;
3687 if (state != S_IDLE) {
3688 sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
3692 } while((state != S_IDLE)&& (cnt<20));
3694 ret = (state == S_IDLE) ? 0 : -1;
3696 sensor_af_idlechk_end:
3700 static int sensor_af_single(struct i2c_client *client)
3704 struct sensor *sensor = to_sensor(client);
3706 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3707 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3709 goto sensor_af_single_end;
3712 if (sensor_af_idlechk(client))
3713 goto sensor_af_single_end;
3715 if (sensor_af_cmdset(client, SingleFocus_Cmd, NULL)) {
3716 SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
3718 goto sensor_af_single_end;
3728 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3730 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3732 goto sensor_af_single_end;
3734 }while((state == S_FOCUSING) && (cnt<100));
3736 if (state != S_FOCUSED) {
3737 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
3739 goto sensor_af_single_end;
3741 sensor_af_single_end:
3745 static int sensor_af_const(struct i2c_client *client)
3748 struct sensor *sensor = to_sensor(client);
3750 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3751 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3753 goto sensor_af_const_end;
3756 if (sensor_af_idlechk(client))
3757 goto sensor_af_const_end;
3759 if (sensor_af_cmdset(client, ConstFocus_Cmd, NULL)) {
3760 SENSOR_TR("%s const focus mode set error!\n",SENSOR_NAME_STRING());
3762 goto sensor_af_const_end;
3764 sensor_af_const_end:
3767 static int sensor_af_pause2capture(struct i2c_client *client)
3771 struct sensor *sensor = to_sensor(client);
3773 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3774 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3776 goto sensor_af_pause_end;
3779 if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
3780 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
3782 goto sensor_af_pause_end;
3792 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3794 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3796 goto sensor_af_pause_end;
3798 }while((state != S_CAPTURE) && (cnt<100));
3800 if (state != S_CAPTURE) {
3801 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
3803 goto sensor_af_pause_end;
3805 sensor_af_pause_end:
3808 static int sensor_af_zoneupdate(struct i2c_client *client)
3811 struct sensor *sensor = to_sensor(client);
3813 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3814 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3816 goto sensor_af_zoneupdate_end;
3819 if (sensor_af_idlechk(client))
3820 goto sensor_af_zoneupdate_end;
3822 if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
3823 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
3825 goto sensor_af_zoneupdate_end;
3828 sensor_af_zoneupdate_end:
3831 static int sensor_af_init(struct i2c_client *client)
3836 ret = sensor_write_array(client, sensor_af_firmware);
3838 SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
3840 goto sensor_af_init_end;
3850 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3852 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3854 goto sensor_af_init_end;
3856 }while((state == S_STARTUP) && (cnt<100));
3858 if (state != S_IDLE) {
3859 SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
3861 goto sensor_af_init_end;
3865 SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
3869 static int sensor_af_downfirmware(struct i2c_client *client)
3871 struct sensor *sensor = to_sensor(client);
3872 struct af_cmdinfo cmdinfo;
3873 int ret=0, focus_pos = 0xfe;
3874 struct soc_camera_device *icd = client->dev.platform_data;
3875 struct v4l2_mbus_framefmt mf;
3877 SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
3879 if (sensor_af_init(client)) {
3880 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
3883 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
3885 mf.width = icd->user_width;
3886 mf.height = icd->user_height;
3887 mf.code = sensor->info_priv.fmt.code;
3888 mf.colorspace = sensor->info_priv.fmt.colorspace;
3889 mf.field = V4L2_FIELD_NONE;
3890 if (sensor_fmt_videochk(NULL, &mf) == true) { /* ddl@rock-chips.com: focus mode fix const auto focus in video */
3891 ret = sensor_af_const(client);
3893 switch (sensor->info_priv.auto_focus)
3895 case SENSOR_AF_MODE_INFINITY:
3899 case SENSOR_AF_MODE_MACRO:
3901 if (focus_pos != 0x00)
3904 sensor_af_idlechk(client);
3905 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3906 cmdinfo.cmd_para[0] = focus_pos;
3907 cmdinfo.validate_bit = 0x81;
3908 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3911 case SENSOR_AF_MODE_AUTO:
3913 ret = sensor_af_single(client);
3916 case SENSOR_AF_MODE_CONTINUOUS:
3918 ret = sensor_af_const(client);
3921 case SENSOR_AF_MODE_CLOSE:
3928 SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
3929 goto sensor_af_downfirmware_end;
3933 SENSOR_DG("%s sensor_af_downfirmware set focus mode(0x%x) ret:0x%x\n",SENSOR_NAME_STRING(), sensor->info_priv.auto_focus,ret);
3936 sensor_af_downfirmware_end:
3940 static void sensor_af_workqueue(struct work_struct *work)
3942 struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
3943 struct i2c_client *client = sensor_work->client;
3944 struct sensor *sensor = to_sensor(client);
3945 struct af_cmdinfo cmdinfo;
3947 SENSOR_DG("%s %s Enter, cmd:0x%x \n",SENSOR_NAME_STRING(), __FUNCTION__,sensor_work->cmd);
3949 mutex_lock(&sensor->wq_lock);
3951 switch (sensor_work->cmd)
3955 if (sensor_af_downfirmware(client) < 0) {
3956 SENSOR_TR("%s Sensor_af_init is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3960 case WqCmd_af_single:
3962 if (sensor_af_single(client) < 0) {
3963 SENSOR_TR("%s Sensor_af_single is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3964 sensor_work->result = WqRet_fail;
3966 sensor_work->result = WqRet_success;
3970 case WqCmd_af_special_pos:
3972 sensor_af_idlechk(client);
3974 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3975 cmdinfo.cmd_para[0] = sensor_work->var;
3976 cmdinfo.validate_bit = 0x81;
3977 if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3978 sensor_work->result = WqRet_fail;
3980 sensor_work->result = WqRet_success;
3983 case WqCmd_af_near_pos:
3985 sensor_af_idlechk(client);
3986 cmdinfo.cmd_tag = StepFocus_Near_Tag;
3987 cmdinfo.validate_bit = 0x80;
3988 if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3989 sensor_work->result = WqRet_fail;
3991 sensor_work->result = WqRet_success;
3994 case WqCmd_af_far_pos:
3996 sensor_af_idlechk(client);
3997 cmdinfo.cmd_tag = StepFocus_Far_Tag;
3998 cmdinfo.validate_bit = 0x80;
3999 if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
4000 sensor_work->result = WqRet_fail;
4002 sensor_work->result = WqRet_success;
4005 case WqCmd_af_continues:
4007 if (sensor_af_const(client) < 0)
4008 sensor_work->result = WqRet_fail;
4010 sensor_work->result = WqRet_success;
4013 case WqCmd_af_update_zone:
4015 if (sensor_af_zoneupdate(client) < 0)
4016 sensor_work->result = WqRet_fail;
4018 sensor_work->result = WqRet_success;
4022 SENSOR_TR("Unknow command(%d) in %s af workqueue!",sensor_work->cmd,SENSOR_NAME_STRING());
4026 if (sensor_work->wait == false) {
4027 kfree((void*)sensor_work);
4029 wake_up(&sensor_work->done);
4031 mutex_unlock(&sensor->wq_lock);
4035 static int sensor_af_workqueue_set(struct soc_camera_device *icd, enum sensor_wq_cmd cmd, int var, bool wait)
4037 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4038 struct sensor *sensor = to_sensor(client);
4039 struct sensor_work *wk;
4042 if (sensor->sensor_wq == NULL) {
4044 goto sensor_af_workqueue_set_end;
4047 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) != SENSOR_AF_IS_OK) {
4048 if (cmd != WqCmd_af_init) {
4049 SENSOR_TR("%s %s cmd(%d) ingore,because af module isn't ready!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4051 goto sensor_af_workqueue_set_end;
4055 wk = kzalloc(sizeof(struct sensor_work), GFP_KERNEL);
4057 wk->client = client;
4058 INIT_DELAYED_WORK(&wk->dwork, sensor_af_workqueue);
4060 wk->result = WqRet_inval;
4063 init_waitqueue_head(&wk->done);
4065 /* ddl@rock-chips.com:
4066 * video_lock is been locked in v4l2_ioctl function, but auto focus may slow,
4067 * As a result any other ioctl calls will proceed very, very slowly since each call
4068 * will have to wait for the AF to finish. Camera preview is pause,because VIDIOC_QBUF
4069 * and VIDIOC_DQBUF is sched. so unlock video_lock here.
4072 queue_delayed_work(sensor->sensor_wq,&(wk->dwork),0);
4073 mutex_unlock(&icd->video_lock);
4074 if (wait_event_timeout(wk->done, (wk->result != WqRet_inval), msecs_to_jiffies(5000)) == 0) {
4075 SENSOR_TR("%s %s cmd(%d) is timeout!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4077 flush_workqueue(sensor->sensor_wq);
4080 mutex_lock(&icd->video_lock);
4082 queue_delayed_work(sensor->sensor_wq,&(wk->dwork),msecs_to_jiffies(10));
4086 SENSOR_TR("%s %s cmd(%d) ingore,because struct sensor_work malloc failed!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4089 sensor_af_workqueue_set_end:
4093 static int sensor_parameter_record(struct i2c_client *client)
4095 u8 ret_l,ret_m,ret_h;
4097 struct sensor *sensor = to_sensor(client);
4099 sensor_write(client,0x3503,0x07); //stop AE/AG
4100 sensor_write(client,0x3406,0x01); //stop AWB
4102 sensor_read(client,0x3500,&ret_h);
4103 sensor_read(client,0x3501, &ret_m);
4104 sensor_read(client,0x3502, &ret_l);
4108 SENSOR_DG(" %s Read 0x3500 = 0x%02x 0x3501 = 0x%02x 0x3502=0x%02x \n",SENSOR_NAME_STRING(), ret_h, ret_m, ret_l);
4109 sensor->parameter.preview_exposure = (tp_h<<12)+(tp_m<<4)+(tp_l>>4);
4110 sensor_read(client,0x350c, &ret_h);
4111 sensor_read(client,0x350d, &ret_l);
4112 sensor->parameter.preview_line_width = ret_h & 0xff;
4113 sensor->parameter.preview_line_width = (sensor->parameter.preview_line_width << 8) +ret_l;
4114 //Read back AGC Gain for preview
4115 sensor_read(client,0x350b, &tp_l);
4116 sensor->parameter.preview_gain = tp_l;
4118 sensor->parameter.capture_framerate = 900;
4119 sensor->parameter.preview_framerate = 1500;
4121 SENSOR_DG(" %s Read 0x350c = 0x%02x 0x350d = 0x%02x 0x350b=0x%02x \n",SENSOR_NAME_STRING(), ret_h, ret_l, sensor->parameter.preview_gain);
4124 static int sensor_ae_transfer(struct i2c_client *client)
4129 u16 ulCapture_Exposure;
4130 u32 ulCapture_Exposure_Gain;
4134 u8 reg_l = 0,reg_h =0;
4135 u16 Preview_Maxlines;
4137 u32 Capture_MaxLines;
4138 struct sensor *sensor = to_sensor(client);
4140 Preview_Maxlines = sensor->parameter.preview_line_width;
4141 Gain = sensor->parameter.preview_gain;
4142 sensor_read(client,0x350c, ®_h);
4143 sensor_read(client,0x350d, ®_l);
4144 Capture_MaxLines = reg_h & 0xff;
4145 Capture_MaxLines = (Capture_MaxLines << 8) + reg_l;
4148 Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/12000;
4150 Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/10000;
4153 if(Preview_Maxlines == 0)
4154 Preview_Maxlines = 1;
4156 ulCapture_Exposure =
4157 (sensor->parameter.preview_exposure*(sensor->parameter.capture_framerate)*(Capture_MaxLines))/(((Preview_Maxlines)*(sensor->parameter.preview_framerate)));
4158 iCapture_Gain = (Gain & 0x0f) + 16;
4160 iCapture_Gain = iCapture_Gain << 1;
4163 iCapture_Gain = iCapture_Gain << 1;
4166 iCapture_Gain = iCapture_Gain << 1;
4169 iCapture_Gain = iCapture_Gain << 1;
4171 ulCapture_Exposure_Gain =(u32) (11 * ulCapture_Exposure * iCapture_Gain/5); //0ld value 2.5, ½â¾ö¹ýÁÁ
4172 if(ulCapture_Exposure_Gain < Capture_MaxLines*16) {
4173 ulCapture_Exposure = ulCapture_Exposure_Gain/16;
4174 if (ulCapture_Exposure > Lines_10ms)
4176 //ulCapture_Exposure *= 1.7;
4177 ulCapture_Exposure /= Lines_10ms;
4178 ulCapture_Exposure *= Lines_10ms;
4181 ulCapture_Exposure = Capture_MaxLines;
4182 //ulCapture_Exposure_Gain *= 1.5;
4184 if(ulCapture_Exposure == 0)
4185 ulCapture_Exposure = 1;
4186 iCapture_Gain = (ulCapture_Exposure_Gain*2/ulCapture_Exposure + 1)/2;
4187 ExposureLow = ((unsigned char)ulCapture_Exposure)<<4;
4188 ExposureMid = (unsigned char)(ulCapture_Exposure >> 4) & 0xff;
4189 ExposureHigh = (unsigned char)(ulCapture_Exposure >> 12);
4192 if (iCapture_Gain > 31) {
4194 iCapture_Gain = iCapture_Gain >> 1;
4196 if (iCapture_Gain > 31) {
4198 iCapture_Gain = iCapture_Gain >> 1;
4200 if (iCapture_Gain > 31) {
4202 iCapture_Gain = iCapture_Gain >> 1;
4204 if (iCapture_Gain > 31) {
4206 iCapture_Gain = iCapture_Gain >> 1;
4208 if (iCapture_Gain > 16)
4209 Gain |= ((iCapture_Gain -16) & 0x0f);
4212 // write the gain and exposure to 0x350* registers
4213 //m_iWrite0x350b=Gain;
4214 sensor_write(client,0x350b, Gain);
4215 //m_iWrite0x3502=ExposureLow;
4216 sensor_write(client,0x3502, ExposureLow);
4217 //m_iWrite0x3501=ExposureMid;
4218 sensor_write(client,0x3501, ExposureMid);
4219 //m_iWrite0x3500=ExposureHigh;
4220 sensor_write(client,0x3500, ExposureHigh);
4221 // SendToFile("Gain = 0x%x\r\n", Gain);
4222 // SendToFile("ExposureLow = 0x%x\r\n", ExposureLow);
4223 // SendToFile("ExposureMid = 0x%x\r\n", ExposureMid);
4224 // SendToFile("ExposureHigh = 0x%x\r\n", ExposureHigh);
4225 //¼Ó³¤ÑÓʱ£¬±ÜÃâ°µ´¦ÅÄÕÕʱµÄÃ÷°µ·Ö½çÎÊÌâ
4226 //camera_timed_wait(200);
4227 //linzhk camera_timed_wait(500);
4229 SENSOR_DG(" %s Write 0x350b = 0x%02x 0x3502 = 0x%02x 0x3501=0x%02x 0x3500 = 0x%02x\n",SENSOR_NAME_STRING(), Gain, ExposureLow, ExposureMid, ExposureHigh);
4233 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
4235 struct soc_camera_link *icl = to_soc_camera_link(icd);
4238 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
4242 case Sensor_PowerDown:
4244 if (icl->powerdown) {
4245 ret = icl->powerdown(icd->pdev, on);
4246 if (ret == RK29_CAM_IO_SUCCESS) {
4250 icl->reset(icd->pdev);
4252 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
4254 goto sensor_power_end;
4261 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4262 struct sensor *sensor = to_sensor(client);
4264 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
4265 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
4267 //flash off after 2 secs
4268 hrtimer_cancel(&(flash_off_timer.timer));
4269 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
4276 SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
4285 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
4286 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
4287 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
4288 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
4293 static s32 sensor_init_width = 800;
4294 static s32 sensor_init_height = 600;
4295 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);
4296 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
4297 static struct reginfo* sensor_init_data_p = NULL;
4298 static struct reginfo* sensor_init_winseq_p = NULL;
4299 static struct reginfo* sensor_init_winseq_board = NULL;
4300 static struct reginfo* sensor_init_data_board = NULL;
4301 static int sensor_init(struct v4l2_subdev *sd, u32 val)
4303 struct i2c_client *client = v4l2_get_subdevdata(sd);
4304 struct soc_camera_device *icd = client->dev.platform_data;
4305 struct sensor *sensor = to_sensor(client);
4306 const struct v4l2_queryctrl *qctrl;
4307 const struct sensor_datafmt *fmt;
4309 int ret,pid = 0,i = 0,j=0;
4310 struct rk29camera_platform_data* tmp_plat_data =sensor->sensor_io_request;
4312 sensor_init_data_p = sensor_init_data;
4313 sensor_init_winseq_p = sensor_svga;
4314 sensor_init_width = 800;
4315 sensor_init_height = 600;
4316 if (tmp_plat_data != NULL) {
4317 for(i = 0;i < RK_CAM_NUM;i++){
4318 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
4319 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0)) {
4324 if(tmp_plat_data &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
4325 //user has defined the init data
4327 int tmp_init_data_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data_size;
4328 if(tmp_init_data_size > 2){//init data is valid
4329 if((sizeof(struct reginfo) != sizeof(struct reginfo_t))){
4330 if(sensor_init_data_board) {
4331 vfree(sensor_init_data_board);
4332 sensor_init_data_board = NULL;
4334 sensor_init_data_board = (struct reginfo*)vmalloc(tmp_init_data_size);
4335 if(!sensor_init_data_board)
4336 SENSOR_TR("%s :vmalloc init data erro !",__FUNCTION__);
4337 for(j = 0;j< tmp_init_data_size;j++) {
4338 sensor_init_data_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
4339 sensor_init_data_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
4341 sensor_init_data_p = sensor_init_data_board;
4343 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
4347 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
4348 if(tmp_winseq_size > 2){
4349 if(sizeof(struct reginfo) != sizeof(struct reginfo_t)){
4350 if(sensor_init_winseq_board) {
4351 vfree(sensor_init_winseq_board);
4352 sensor_init_winseq_board = NULL;
4354 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
4355 if(!sensor_init_winseq_board)
4356 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
4357 for(j = 0;j< tmp_winseq_size;j++){
4358 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
4359 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
4361 sensor_init_winseq_p = sensor_init_winseq_board;
4363 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
4366 //init width,height,bus,pixelcode
4367 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
4368 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
4369 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
4370 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
4371 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
4372 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
4373 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
4374 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
4376 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
4378 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
4380 goto sensor_INIT_ERR;
4384 if (sensor_task_lock(client,1)<0)
4385 goto sensor_INIT_ERR;
4386 ret = sensor_write(client, 0x3008, 0x80);
4388 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
4390 goto sensor_INIT_ERR;
4393 mdelay(5); //delay 5 microseconds
4394 /* check if it is an sensor sensor */
4395 ret = sensor_read(client, 0x300a, &value);
4397 SENSOR_TR("read chip id high byte failed\n");
4399 goto sensor_INIT_ERR;
4402 pid |= (value << 8);
4404 ret = sensor_read(client, 0x300b, &value);
4406 SENSOR_TR("read chip id low byte failed\n");
4408 goto sensor_INIT_ERR;
4411 pid |= (value & 0xff);
4412 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
4414 if (pid == SENSOR_ID) {
4415 sensor->model = SENSOR_V4L2_IDENT;
4417 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4419 goto sensor_INIT_ERR;
4422 ret = sensor_write_array(client, sensor_init_data_p);
4424 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
4425 goto sensor_INIT_ERR;
4427 sensor_task_lock(client,0);
4428 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
4429 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
4431 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
4433 goto sensor_INIT_ERR;
4435 sensor->info_priv.fmt = *fmt;
4437 /* sensor sensor information for initialization */
4438 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4440 sensor->info_priv.whiteBalance = qctrl->default_value;
4441 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
4443 sensor->info_priv.brightness = qctrl->default_value;
4444 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4446 sensor->info_priv.effect = qctrl->default_value;
4447 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
4449 sensor->info_priv.exposure = qctrl->default_value;
4451 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
4453 sensor->info_priv.saturation = qctrl->default_value;
4454 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
4456 sensor->info_priv.contrast = qctrl->default_value;
4457 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
4459 sensor->info_priv.mirror = qctrl->default_value;
4460 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
4462 sensor->info_priv.flip = qctrl->default_value;
4463 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
4465 sensor->info_priv.scene = qctrl->default_value;
4466 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
4468 sensor->info_priv.digitalzoom = qctrl->default_value;
4470 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
4471 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
4473 sensor->info_priv.focus = qctrl->default_value;
4475 #if CONFIG_SENSOR_Flash
4476 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
4478 sensor->info_priv.flash = qctrl->default_value;
4479 flash_off_timer.icd = icd;
4480 flash_off_timer.timer.function = flash_off_func;
4482 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);
4484 sensor->info_priv.funmodule_state = SENSOR_INIT_IS_OK;
4488 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4489 sensor_task_lock(client,0);
4490 sensor_deactivate(client);
4493 static int sensor_deactivate(struct i2c_client *client)
4495 struct soc_camera_device *icd = client->dev.platform_data;
4496 struct sensor *sensor = to_sensor(client);
4498 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
4500 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
4501 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
4502 sensor_task_lock(client, 1);
4503 sensor_write(client, 0x3017, 0x00); // FREX,VSYNC,HREF,PCLK,D9-D6
4504 sensor_write(client, 0x3018, 0x03); // D5-D0
4505 sensor_write(client,0x3019,0x00); // STROBE,SDA
4506 sensor_task_lock(client, 0);
4508 sensor_ioctrl(icd, Sensor_PowerDown, 1);
4510 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
4511 icd->user_width = SENSOR_INIT_WIDTH;
4512 icd->user_height = SENSOR_INIT_HEIGHT;
4513 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4516 static struct reginfo sensor_power_down_sequence[]=
4520 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
4523 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4525 if (pm_msg.event == PM_EVENT_SUSPEND) {
4526 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
4527 ret = sensor_write_array(client, sensor_power_down_sequence) ;
4529 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
4532 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
4534 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
4539 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
4546 static int sensor_resume(struct soc_camera_device *icd)
4550 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
4552 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
4556 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
4560 static int sensor_set_bus_param(struct soc_camera_device *icd,
4561 unsigned long flags)
4567 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
4569 struct soc_camera_link *icl = to_soc_camera_link(icd);
4570 unsigned long flags = SENSOR_BUS_PARAM;
4572 return soc_camera_apply_sensor_flags(icl, flags);
4574 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4576 struct i2c_client *client = v4l2_get_subdevdata(sd);
4577 struct soc_camera_device *icd = client->dev.platform_data;
4578 struct sensor *sensor = to_sensor(client);
4580 mf->width = icd->user_width;
4581 mf->height = icd->user_height;
4582 mf->code = sensor->info_priv.fmt.code;
4583 mf->colorspace = sensor->info_priv.fmt.colorspace;
4584 mf->field = V4L2_FIELD_NONE;
4588 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4592 if ((mf->width == 1024) && (mf->height == 768)) {
4594 } else if ((mf->width == 1280) && (mf->height == 1024)) {
4596 } else if ((mf->width == 1600) && (mf->height == 1200)) {
4598 } else if ((mf->width == 2048) && (mf->height == 1536)) {
4600 } else if ((mf->width == 2592) && (mf->height == 1944)) {
4602 } else if ((mf->width == 3264) && (mf->height == 2448)) {
4607 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
4611 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4615 if ((mf->width == 1280) && (mf->height == 720)) {
4617 } else if ((mf->width == 1920) && (mf->height == 1080)) {
4622 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
4625 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4627 struct i2c_client *client = v4l2_get_subdevdata(sd);
4628 const struct sensor_datafmt *fmt;
4629 struct sensor *sensor = to_sensor(client);
4630 const struct v4l2_queryctrl *qctrl;
4631 struct soc_camera_device *icd = client->dev.platform_data;
4632 struct reginfo *winseqe_set_addr=NULL;
4633 int ret = 0, set_w,set_h;
4635 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4636 ARRAY_SIZE(sensor_colour_fmts));
4639 goto sensor_s_fmt_end;
4642 if (sensor->info_priv.fmt.code != mf->code) {
4645 case V4L2_MBUS_FMT_YUYV8_2X8:
4647 winseqe_set_addr = sensor_ClrFmt_YUYV;
4650 case V4L2_MBUS_FMT_UYVY8_2X8:
4652 winseqe_set_addr = sensor_ClrFmt_UYVY;
4658 if (winseqe_set_addr != NULL) {
4659 sensor_write_array(client, winseqe_set_addr);
4660 sensor->info_priv.fmt.code = mf->code;
4661 sensor->info_priv.fmt.colorspace= mf->colorspace;
4662 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
4664 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
4671 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
4673 winseqe_set_addr = sensor_qcif;
4677 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
4679 winseqe_set_addr = sensor_qvga;
4683 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
4685 winseqe_set_addr = sensor_cif;
4689 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
4691 winseqe_set_addr = sensor_vga;
4695 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
4697 winseqe_set_addr = sensor_svga;
4701 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
4703 winseqe_set_addr = sensor_xga;
4707 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
4709 winseqe_set_addr = sensor_720p;
4713 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
4715 winseqe_set_addr = sensor_sxga;
4719 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
4721 winseqe_set_addr = sensor_uxga;
4725 else if (((set_w <= 1920) && (set_h <= 1080)) && sensor_1080p[0].reg)
4727 winseqe_set_addr = sensor_1080p;
4731 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_qxga[0].reg)
4733 winseqe_set_addr = sensor_qxga;
4737 else if (((set_w <= 2592) && (set_h <= 1944)) && sensor_qsxga[0].reg)
4739 winseqe_set_addr = sensor_qsxga;
4743 #if defined(CONFIG_SOC_CAMERA_OV5642_INTERPOLATION)
4744 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
4746 winseqe_set_addr = sensor_qsxga;
4747 set_w = SENSOR_MAX_WIDTH_REAL;
4748 set_h = SENSOR_MAX_HEIGHT_REAL;
4753 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
4754 set_w = SENSOR_INIT_WIDTH;
4755 set_h = SENSOR_INIT_HEIGHT;
4756 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
4759 if (winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
4761 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
4762 sensor_parameter_record(client);
4763 #if CONFIG_SENSOR_Flash
4764 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4765 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
4766 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
4769 }else { /* ddl@rock-chips.com : Video */
4770 #if CONFIG_SENSOR_Flash
4771 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4772 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4773 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
4778 if ((sensor->info_priv.winseqe_cur_addr->reg == SEQUENCE_PROPERTY) && (sensor->info_priv.winseqe_cur_addr->val == SEQUENCE_INIT)) {
4779 if (((winseqe_set_addr->reg == SEQUENCE_PROPERTY) && (winseqe_set_addr->val == SEQUENCE_NORMAL))
4780 || (winseqe_set_addr->reg != SEQUENCE_PROPERTY)) {
4781 ret |= sensor_write_array(client,sensor_init_data);
4782 SENSOR_DG("\n%s reinit ret:0x%x \n",SENSOR_NAME_STRING(), ret);
4786 ret |= sensor_write_array(client, winseqe_set_addr);
4788 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
4789 #if CONFIG_SENSOR_Flash
4790 if (sensor_fmt_capturechk(sd,mf) == true) {
4791 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4792 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4793 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
4797 goto sensor_s_fmt_end;
4800 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
4802 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
4803 sensor_ae_transfer(client);
4804 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4805 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4806 if (sensor->info_priv.whiteBalance != 0) {
4807 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4808 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4810 #if CONFIG_SENSOR_Focus
4811 if (sensor->info_priv.auto_focus != SENSOR_AF_MODE_INFINITY) {
4812 if (sensor_af_workqueue_set(icd, WqCmd_af_update_zone,0,true) == 0) {
4813 if ((sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) ||
4814 (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS)) {
4816 sensor_af_workqueue_set(icd, WqCmd_af_single,0,true);
4821 sensor->info_priv.snap2preview = true;
4822 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
4823 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4824 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4825 #if CONFIG_SENSOR_Focus
4826 sensor->info_priv.affm_reinit = 1;
4828 sensor->info_priv.video2preview = true;
4829 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
4830 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4831 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4832 if (sensor->info_priv.snap2preview == true) {
4833 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4834 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4836 #if CONFIG_SENSOR_Focus
4837 if (sensor->info_priv.auto_focus != SENSOR_AF_MODE_INFINITY) {
4838 /* ddl@rock-chips.com: The af operation is not necessary, if user don't care whether in focus after preview*/
4839 if (sensor_af_workqueue_set(icd, WqCmd_af_update_zone,0,false) == 0) {
4840 if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS) {
4841 sensor_af_workqueue_set(icd, WqCmd_af_continues,0,false);
4842 } else if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) {
4844 sensor_af_workqueue_set(icd, WqCmd_af_single,0,false);
4849 msleep(600); /* ddl@rock-chips.com : whitebalance auto must delay */
4852 sensor->info_priv.video2preview = false;
4853 sensor->info_priv.snap2preview = false;
4858 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
4862 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
4871 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4873 struct i2c_client *client = v4l2_get_subdevdata(sd);
4874 struct sensor *sensor = to_sensor(client);
4875 const struct sensor_datafmt *fmt;
4876 int ret = 0,set_w,set_h;
4878 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4879 ARRAY_SIZE(sensor_colour_fmts));
4881 fmt = &sensor->info_priv.fmt;
4882 mf->code = fmt->code;
4884 /* ddl@rock-chips.com : It is query max resolution only. */
4885 if (mf->reserved[6] == 0xfefe5a5a) {
4886 mf->height = SENSOR_MAX_HEIGHT;
4887 mf->width = SENSOR_MAX_WIDTH;
4889 printk("%s(%d): query resolution\n",__FUNCTION__,__LINE__);
4890 goto sensor_try_fmt_end;
4893 if (mf->height > SENSOR_MAX_HEIGHT)
4894 mf->height = SENSOR_MAX_HEIGHT;
4895 else if (mf->height < SENSOR_MIN_HEIGHT)
4896 mf->height = SENSOR_MIN_HEIGHT;
4898 if (mf->width > SENSOR_MAX_WIDTH)
4899 mf->width = SENSOR_MAX_WIDTH;
4900 else if (mf->width < SENSOR_MIN_WIDTH)
4901 mf->width = SENSOR_MIN_WIDTH;
4906 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
4911 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
4916 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
4921 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
4926 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
4931 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
4936 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
4941 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
4946 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
4951 else if (((set_w <= 1920) && (set_h <= 1080)) && sensor_1080p[0].reg)
4956 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_qxga[0].reg)
4961 else if (((set_w <= 2592) && (set_h <= 1944)) && sensor_qsxga[0].reg)
4966 #if defined(CONFIG_SOC_CAMERA_OV5642_INTERPOLATION)
4967 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
4969 set_w = SENSOR_MAX_WIDTH_REAL;
4970 set_h = SENSOR_MAX_HEIGHT_REAL;
4975 set_w = SENSOR_INIT_WIDTH;
4976 set_h = SENSOR_INIT_HEIGHT;
4982 mf->colorspace = fmt->colorspace;
4987 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
4989 struct i2c_client *client = v4l2_get_subdevdata(sd);
4991 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
4994 if (id->match.addr != client->addr)
4997 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
5002 #if CONFIG_SENSOR_Brightness
5003 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5005 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5007 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5009 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
5011 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
5013 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5016 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5020 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5024 #if CONFIG_SENSOR_Effect
5025 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5027 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5029 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5031 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
5033 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
5035 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5038 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5042 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5046 #if CONFIG_SENSOR_Exposure
5047 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5049 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5051 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5053 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
5055 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
5057 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5060 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5064 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5068 #if CONFIG_SENSOR_Saturation
5069 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5071 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5073 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5075 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
5077 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
5079 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5082 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5086 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5090 #if CONFIG_SENSOR_Contrast
5091 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5093 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5095 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5097 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
5099 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
5101 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5104 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5108 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5112 #if CONFIG_SENSOR_Mirror
5113 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5115 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5117 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5119 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
5121 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
5123 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5126 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5130 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5134 #if CONFIG_SENSOR_Flip
5135 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5137 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5139 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5141 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
5143 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
5145 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5148 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5152 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5156 #if CONFIG_SENSOR_Scene
5157 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5159 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5161 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5163 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
5165 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
5167 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5170 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5174 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5178 #if CONFIG_SENSOR_WhiteBalance
5179 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5181 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5183 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5185 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
5187 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
5189 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5192 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5196 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5200 #if CONFIG_SENSOR_DigitalZoom
5201 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
5203 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5204 struct sensor *sensor = to_sensor(client);
5205 const struct v4l2_queryctrl *qctrl_info;
5206 int digitalzoom_cur, digitalzoom_total;
5208 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
5212 digitalzoom_cur = sensor->info_priv.digitalzoom;
5213 digitalzoom_total = qctrl_info->maximum;
5215 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
5217 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
5221 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
5223 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
5227 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
5229 *value = digitalzoom_total - digitalzoom_cur;
5232 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
5234 *value = 0 - digitalzoom_cur;
5237 digitalzoom_cur += *value;
5239 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
5241 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
5243 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5246 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
5253 #if CONFIG_SENSOR_Focus
5254 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5256 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5257 struct sensor *sensor = to_sensor(client);
5258 const struct v4l2_queryctrl *qctrl_info;
5261 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
5265 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5266 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
5267 ret = sensor_af_workqueue_set(icd, WqCmd_af_special_pos, value, true);
5268 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5271 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5275 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5276 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5281 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5283 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5284 struct sensor *sensor = to_sensor(client);
5285 const struct v4l2_queryctrl *qctrl_info;
5288 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
5292 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5293 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
5295 ret = sensor_af_workqueue_set(icd, WqCmd_af_near_pos, 0, true);
5297 ret = sensor_af_workqueue_set(icd, WqCmd_af_far_pos, 0, true);
5299 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5302 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5306 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5307 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5312 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5314 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5315 struct sensor *sensor = to_sensor(client);
5318 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5321 case SENSOR_AF_MODE_AUTO:
5323 ret = sensor_af_workqueue_set(icd, WqCmd_af_single, 0, true);
5327 case SENSOR_AF_MODE_MACRO:
5329 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
5333 case SENSOR_AF_MODE_INFINITY:
5335 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
5339 case SENSOR_AF_MODE_CONTINUOUS:
5341 ret = sensor_af_workqueue_set(icd, WqCmd_af_continues, 0, true);
5345 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5350 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5353 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5354 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5361 #if CONFIG_SENSOR_Flash
5362 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5364 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
5365 if (value == 3) { /* ddl@rock-chips.com: torch */
5366 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
5368 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
5370 SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5374 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5379 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5381 struct i2c_client *client = v4l2_get_subdevdata(sd);
5382 struct sensor *sensor = to_sensor(client);
5383 const struct v4l2_queryctrl *qctrl;
5385 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5389 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5395 case V4L2_CID_BRIGHTNESS:
5397 ctrl->value = sensor->info_priv.brightness;
5400 case V4L2_CID_SATURATION:
5402 ctrl->value = sensor->info_priv.saturation;
5405 case V4L2_CID_CONTRAST:
5407 ctrl->value = sensor->info_priv.contrast;
5410 case V4L2_CID_DO_WHITE_BALANCE:
5412 ctrl->value = sensor->info_priv.whiteBalance;
5415 case V4L2_CID_EXPOSURE:
5417 ctrl->value = sensor->info_priv.exposure;
5420 case V4L2_CID_HFLIP:
5422 ctrl->value = sensor->info_priv.mirror;
5425 case V4L2_CID_VFLIP:
5427 ctrl->value = sensor->info_priv.flip;
5438 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5440 struct i2c_client *client = v4l2_get_subdevdata(sd);
5441 struct sensor *sensor = to_sensor(client);
5442 struct soc_camera_device *icd = client->dev.platform_data;
5443 const struct v4l2_queryctrl *qctrl;
5446 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5450 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5456 #if CONFIG_SENSOR_Brightness
5457 case V4L2_CID_BRIGHTNESS:
5459 if (ctrl->value != sensor->info_priv.brightness)
5461 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
5465 sensor->info_priv.brightness = ctrl->value;
5470 #if CONFIG_SENSOR_Exposure
5471 case V4L2_CID_EXPOSURE:
5473 if (ctrl->value != sensor->info_priv.exposure)
5475 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
5479 sensor->info_priv.exposure = ctrl->value;
5484 #if CONFIG_SENSOR_Saturation
5485 case V4L2_CID_SATURATION:
5487 if (ctrl->value != sensor->info_priv.saturation)
5489 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
5493 sensor->info_priv.saturation = ctrl->value;
5498 #if CONFIG_SENSOR_Contrast
5499 case V4L2_CID_CONTRAST:
5501 if (ctrl->value != sensor->info_priv.contrast)
5503 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
5507 sensor->info_priv.contrast = ctrl->value;
5512 #if CONFIG_SENSOR_WhiteBalance
5513 case V4L2_CID_DO_WHITE_BALANCE:
5515 if (ctrl->value != sensor->info_priv.whiteBalance)
5517 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
5521 sensor->info_priv.whiteBalance = ctrl->value;
5526 #if CONFIG_SENSOR_Mirror
5527 case V4L2_CID_HFLIP:
5529 if (ctrl->value != sensor->info_priv.mirror)
5531 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
5533 sensor->info_priv.mirror = ctrl->value;
5538 #if CONFIG_SENSOR_Flip
5539 case V4L2_CID_VFLIP:
5541 if (ctrl->value != sensor->info_priv.flip)
5543 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
5545 sensor->info_priv.flip = ctrl->value;
5556 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
5558 const struct v4l2_queryctrl *qctrl;
5559 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5560 struct sensor *sensor = to_sensor(client);
5562 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5566 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5570 switch (ext_ctrl->id)
5572 case V4L2_CID_SCENE:
5574 ext_ctrl->value = sensor->info_priv.scene;
5577 case V4L2_CID_EFFECT:
5579 ext_ctrl->value = sensor->info_priv.effect;
5582 case V4L2_CID_ZOOM_ABSOLUTE:
5584 ext_ctrl->value = sensor->info_priv.digitalzoom;
5587 case V4L2_CID_ZOOM_RELATIVE:
5591 case V4L2_CID_FOCUS_ABSOLUTE:
5595 case V4L2_CID_FOCUS_RELATIVE:
5599 case V4L2_CID_FLASH:
5601 ext_ctrl->value = sensor->info_priv.flash;
5609 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
5611 const struct v4l2_queryctrl *qctrl;
5612 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5613 struct sensor *sensor = to_sensor(client);
5616 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5620 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5625 switch (ext_ctrl->id)
5627 #if CONFIG_SENSOR_Scene
5628 case V4L2_CID_SCENE:
5630 if (ext_ctrl->value != sensor->info_priv.scene)
5632 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
5634 sensor->info_priv.scene = ext_ctrl->value;
5639 #if CONFIG_SENSOR_Effect
5640 case V4L2_CID_EFFECT:
5642 if (ext_ctrl->value != sensor->info_priv.effect)
5644 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
5646 sensor->info_priv.effect= ext_ctrl->value;
5651 #if CONFIG_SENSOR_DigitalZoom
5652 case V4L2_CID_ZOOM_ABSOLUTE:
5654 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5657 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
5659 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
5661 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
5663 sensor->info_priv.digitalzoom += val_offset;
5665 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
5670 case V4L2_CID_ZOOM_RELATIVE:
5672 if (ext_ctrl->value)
5674 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
5676 sensor->info_priv.digitalzoom += ext_ctrl->value;
5678 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
5683 #if CONFIG_SENSOR_Focus
5684 case V4L2_CID_FOCUS_ABSOLUTE:
5686 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5689 ret = sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value);
5690 if ((ret == 0) || (0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK))) {
5691 if (ext_ctrl->value == qctrl->minimum) {
5692 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
5693 } else if (ext_ctrl->value == qctrl->maximum) {
5694 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
5696 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
5702 case V4L2_CID_FOCUS_RELATIVE:
5704 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5707 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
5710 case V4L2_CID_FOCUS_AUTO:
5712 if (ext_ctrl->value) {
5713 if ((ext_ctrl->value==1) || (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus)) {
5714 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0) {
5715 if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5716 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5721 if (ext_ctrl->value == 1)
5722 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5723 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
5724 if (ext_ctrl->value == 0)
5725 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5729 case V4L2_CID_FOCUS_CONTINUOUS:
5731 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
5732 if (ext_ctrl->value == 1) {
5733 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0) {
5734 if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5735 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5739 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5742 if (ext_ctrl->value == 0)
5743 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5748 #if CONFIG_SENSOR_Flash
5749 case V4L2_CID_FLASH:
5751 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
5753 sensor->info_priv.flash = ext_ctrl->value;
5755 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
5766 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5768 struct i2c_client *client = v4l2_get_subdevdata(sd);
5769 struct soc_camera_device *icd = client->dev.platform_data;
5770 int i, error_cnt=0, error_idx=-1;
5773 for (i=0; i<ext_ctrl->count; i++) {
5774 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5781 error_idx = ext_ctrl->count;
5783 if (error_idx != -1) {
5784 ext_ctrl->error_idx = error_idx;
5791 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5793 struct i2c_client *client = v4l2_get_subdevdata(sd);
5794 struct soc_camera_device *icd = client->dev.platform_data;
5795 int i, error_cnt=0, error_idx=-1;
5797 for (i=0; i<ext_ctrl->count; i++) {
5798 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5805 error_idx = ext_ctrl->count;
5807 if (error_idx != -1) {
5808 ext_ctrl->error_idx = error_idx;
5815 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
5817 struct i2c_client *client = v4l2_get_subdevdata(sd);
5818 struct sensor *sensor = to_sensor(client);
5819 #if CONFIG_SENSOR_Focus
5820 struct soc_camera_device *icd = client->dev.platform_data;
5821 struct v4l2_mbus_framefmt mf;
5825 sensor->info_priv.enable = 1;
5826 #if CONFIG_SENSOR_Focus
5827 mf.width = icd->user_width;
5828 mf.height = icd->user_height;
5829 mf.code = sensor->info_priv.fmt.code;
5830 mf.colorspace = sensor->info_priv.fmt.colorspace;
5831 mf.field = V4L2_FIELD_NONE;
5832 /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
5833 if (sensor_fmt_capturechk(sd, &mf) == false) {
5834 if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {
5835 sensor_af_workqueue_set(icd, WqCmd_af_init, 0, false);
5836 sensor->info_priv.affm_reinit = 0;
5840 } else if (enable == 0) {
5841 sensor->info_priv.enable = 0;
5842 #if CONFIG_SENSOR_Focus
5843 flush_workqueue(sensor->sensor_wq);
5849 /* Interface active, can use i2c. If it fails, it can indeed mean, that
5850 * this wasn't our capture interface, so, we wait for the right one */
5851 static int sensor_video_probe(struct soc_camera_device *icd,
5852 struct i2c_client *client)
5856 struct sensor *sensor = to_sensor(client);
5858 /* We must have a parent by now. And it cannot be a wrong one.
5859 * So this entire test is completely redundant. */
5860 if (!icd->dev.parent ||
5861 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
5864 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
5866 goto sensor_video_probe_err;
5869 ret = sensor_write(client, 0x3012, 0x80);
5871 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
5873 goto sensor_video_probe_err;
5875 mdelay(5); //delay 5 microseconds
5877 /* check if it is an sensor sensor */
5878 ret = sensor_read(client, 0x300a, &value);
5880 SENSOR_TR("read chip id high byte failed\n");
5882 goto sensor_video_probe_err;
5885 pid |= (value << 8);
5887 ret = sensor_read(client, 0x300b, &value);
5889 SENSOR_TR("read chip id low byte failed\n");
5891 goto sensor_video_probe_err;
5894 pid |= (value & 0xff);
5895 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5896 if (pid == SENSOR_ID) {
5897 sensor->model = SENSOR_V4L2_IDENT;
5899 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5901 goto sensor_video_probe_err;
5906 sensor_video_probe_err:
5910 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
5912 struct i2c_client *client = v4l2_get_subdevdata(sd);
5913 struct soc_camera_device *icd = client->dev.platform_data;
5914 struct sensor *sensor = to_sensor(client);
5917 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5920 case RK29_CAM_SUBDEV_DEACTIVATE:
5922 sensor_deactivate(client);
5925 case RK29_CAM_SUBDEV_IOREQUEST:
5927 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
5929 if (sensor->sensor_io_request != NULL) {
5931 for(j = 0;j < RK_CAM_NUM;j++){
5932 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
5933 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
5934 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
5938 if(j == RK_CAM_NUM){
5939 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
5941 goto sensor_ioctl_end;
5945 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
5947 #if CONFIG_SENSOR_Flash
5948 if (sensor->sensor_gpio_res) {
5949 printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
5950 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
5951 for (i = 0; i < icd->ops->num_controls; i++) {
5952 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
5953 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
5954 sensor_controls[i].id=0xffff;
5957 sensor->info_priv.flash = 0xff;
5958 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
5959 }else{ //two cameras are the same,need to deal diffrently ,zycc
5960 for (i = 0; i < icd->ops->num_controls; i++) {
5961 if(0xffff == icd->ops->controls[i].id){
5962 sensor_controls[i].id=V4L2_CID_FLASH;
5972 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5981 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
5982 enum v4l2_mbus_pixelcode *code)
5984 if (index >= ARRAY_SIZE(sensor_colour_fmts))
5987 *code = sensor_colour_fmts[index].code;
5990 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
5991 .init = sensor_init,
5992 .g_ctrl = sensor_g_control,
5993 .s_ctrl = sensor_s_control,
5994 .g_ext_ctrls = sensor_g_ext_controls,
5995 .s_ext_ctrls = sensor_s_ext_controls,
5996 .g_chip_ident = sensor_g_chip_ident,
5997 .ioctl = sensor_ioctl,
6000 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
6001 .s_mbus_fmt = sensor_s_fmt,
6002 .g_mbus_fmt = sensor_g_fmt,
6003 .try_mbus_fmt = sensor_try_fmt,
6004 .enum_mbus_fmt = sensor_enum_fmt,
6005 .s_stream = sensor_s_stream,
6007 static struct v4l2_subdev_ops sensor_subdev_ops = {
6008 .core = &sensor_subdev_core_ops,
6009 .video = &sensor_subdev_video_ops,
6012 static int sensor_probe(struct i2c_client *client,
6013 const struct i2c_device_id *did)
6015 struct sensor *sensor;
6016 struct soc_camera_device *icd = client->dev.platform_data;
6017 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
6018 struct soc_camera_link *icl;
6021 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
6023 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
6027 icl = to_soc_camera_link(icd);
6029 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
6033 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
6034 dev_warn(&adapter->dev,
6035 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
6039 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
6043 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
6045 /* Second stage probe - when a capture adapter is there */
6046 icd->ops = &sensor_ops;
6047 sensor->info_priv.fmt = sensor_colour_fmts[0];
6048 #if CONFIG_SENSOR_I2C_NOSCHED
6049 atomic_set(&sensor->tasklock_cnt,0);
6052 ret = sensor_video_probe(icd, client);
6055 i2c_set_clientdata(client, NULL);
6059 #if CONFIG_SENSOR_Focus
6060 sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING(_af_workqueue));
6061 if (sensor->sensor_wq == NULL)
6062 SENSOR_TR("%s create fail!", SENSOR_NAME_STRING(_af_workqueue));
6063 mutex_init(&sensor->wq_lock);
6066 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
6067 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
6071 static int sensor_remove(struct i2c_client *client)
6073 struct sensor *sensor = to_sensor(client);
6074 struct soc_camera_device *icd = client->dev.platform_data;
6076 #if CONFIG_SENSOR_Focus
6077 if (sensor->sensor_wq) {
6078 destroy_workqueue(sensor->sensor_wq);
6079 sensor->sensor_wq = NULL;
6084 i2c_set_clientdata(client, NULL);
6085 client->driver = NULL;
6091 static const struct i2c_device_id sensor_id[] = {
6092 {SENSOR_NAME_STRING(), 0 },
6095 MODULE_DEVICE_TABLE(i2c, sensor_id);
6097 static struct i2c_driver sensor_i2c_driver = {
6099 .name = SENSOR_NAME_STRING(),
6101 .probe = sensor_probe,
6102 .remove = sensor_remove,
6103 .id_table = sensor_id,
6106 static int __init sensor_mod_init(void)
6108 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
6109 return i2c_add_driver(&sensor_i2c_driver);
6112 static void __exit sensor_mod_exit(void)
6114 i2c_del_driver(&sensor_i2c_driver);
6117 device_initcall_sync(sensor_mod_init);
6118 module_exit(sensor_mod_exit);
6120 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
6121 MODULE_AUTHOR("ddl <kernel@rock-chips>");
6122 MODULE_LICENSE("GPL");