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 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:
3768 static int sensor_af_pause2capture(struct i2c_client *client)
3772 struct sensor *sensor = to_sensor(client);
3774 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3775 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3777 goto sensor_af_pause_end;
3780 if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
3781 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
3783 goto sensor_af_pause_end;
3793 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3795 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3797 goto sensor_af_pause_end;
3799 }while((state != S_CAPTURE) && (cnt<100));
3801 if (state != S_CAPTURE) {
3802 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
3804 goto sensor_af_pause_end;
3806 sensor_af_pause_end:
3811 static int sensor_af_zoneupdate(struct i2c_client *client)
3814 struct sensor *sensor = to_sensor(client);
3816 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3817 SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3819 goto sensor_af_zoneupdate_end;
3822 if (sensor_af_idlechk(client))
3823 goto sensor_af_zoneupdate_end;
3825 if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
3826 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
3828 goto sensor_af_zoneupdate_end;
3831 sensor_af_zoneupdate_end:
3834 static int sensor_af_init(struct i2c_client *client)
3839 ret = sensor_write_array(client, sensor_af_firmware);
3841 SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
3843 goto sensor_af_init_end;
3853 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3855 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3857 goto sensor_af_init_end;
3859 }while((state == S_STARTUP) && (cnt<100));
3861 if (state != S_IDLE) {
3862 SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
3864 goto sensor_af_init_end;
3868 SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
3872 static int sensor_af_downfirmware(struct i2c_client *client)
3874 struct sensor *sensor = to_sensor(client);
3875 struct af_cmdinfo cmdinfo;
3876 int ret=0, focus_pos = 0xfe;
3877 struct soc_camera_device *icd = client->dev.platform_data;
3878 struct v4l2_mbus_framefmt mf;
3880 SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
3882 if (sensor_af_init(client)) {
3883 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
3886 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
3888 mf.width = icd->user_width;
3889 mf.height = icd->user_height;
3890 mf.code = sensor->info_priv.fmt.code;
3891 mf.colorspace = sensor->info_priv.fmt.colorspace;
3892 mf.field = V4L2_FIELD_NONE;
3893 if (sensor_fmt_videochk(NULL, &mf) == true) { /* ddl@rock-chips.com: focus mode fix const auto focus in video */
3894 ret = sensor_af_const(client);
3896 switch (sensor->info_priv.auto_focus)
3898 case SENSOR_AF_MODE_INFINITY:
3902 case SENSOR_AF_MODE_MACRO:
3904 if (focus_pos != 0x00)
3907 sensor_af_idlechk(client);
3908 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3909 cmdinfo.cmd_para[0] = focus_pos;
3910 cmdinfo.validate_bit = 0x81;
3911 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3914 case SENSOR_AF_MODE_AUTO:
3916 ret = sensor_af_single(client);
3919 case SENSOR_AF_MODE_CONTINUOUS:
3921 ret = sensor_af_const(client);
3924 case SENSOR_AF_MODE_CLOSE:
3931 SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
3932 goto sensor_af_downfirmware_end;
3936 SENSOR_DG("%s sensor_af_downfirmware set focus mode(0x%x) ret:0x%x\n",SENSOR_NAME_STRING(), sensor->info_priv.auto_focus,ret);
3939 sensor_af_downfirmware_end:
3943 static void sensor_af_workqueue(struct work_struct *work)
3945 struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
3946 struct i2c_client *client = sensor_work->client;
3947 struct sensor *sensor = to_sensor(client);
3948 struct af_cmdinfo cmdinfo;
3950 SENSOR_DG("%s %s Enter, cmd:0x%x \n",SENSOR_NAME_STRING(), __FUNCTION__,sensor_work->cmd);
3952 mutex_lock(&sensor->wq_lock);
3954 switch (sensor_work->cmd)
3958 if (sensor_af_downfirmware(client) < 0) {
3959 SENSOR_TR("%s Sensor_af_init is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3963 case WqCmd_af_single:
3965 if (sensor_af_single(client) < 0) {
3966 SENSOR_TR("%s Sensor_af_single is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3967 sensor_work->result = WqRet_fail;
3969 sensor_work->result = WqRet_success;
3973 case WqCmd_af_special_pos:
3975 sensor_af_idlechk(client);
3977 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3978 cmdinfo.cmd_para[0] = sensor_work->var;
3979 cmdinfo.validate_bit = 0x81;
3980 if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3981 sensor_work->result = WqRet_fail;
3983 sensor_work->result = WqRet_success;
3986 case WqCmd_af_near_pos:
3988 sensor_af_idlechk(client);
3989 cmdinfo.cmd_tag = StepFocus_Near_Tag;
3990 cmdinfo.validate_bit = 0x80;
3991 if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3992 sensor_work->result = WqRet_fail;
3994 sensor_work->result = WqRet_success;
3997 case WqCmd_af_far_pos:
3999 sensor_af_idlechk(client);
4000 cmdinfo.cmd_tag = StepFocus_Far_Tag;
4001 cmdinfo.validate_bit = 0x80;
4002 if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
4003 sensor_work->result = WqRet_fail;
4005 sensor_work->result = WqRet_success;
4008 case WqCmd_af_continues:
4010 if (sensor_af_const(client) < 0)
4011 sensor_work->result = WqRet_fail;
4013 sensor_work->result = WqRet_success;
4016 case WqCmd_af_update_zone:
4018 if (sensor_af_zoneupdate(client) < 0)
4019 sensor_work->result = WqRet_fail;
4021 sensor_work->result = WqRet_success;
4025 SENSOR_TR("Unknow command(%d) in %s af workqueue!",sensor_work->cmd,SENSOR_NAME_STRING());
4029 if (sensor_work->wait == false) {
4030 kfree((void*)sensor_work);
4032 wake_up(&sensor_work->done);
4034 mutex_unlock(&sensor->wq_lock);
4038 static int sensor_af_workqueue_set(struct soc_camera_device *icd, enum sensor_wq_cmd cmd, int var, bool wait)
4040 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4041 struct sensor *sensor = to_sensor(client);
4042 struct sensor_work *wk;
4045 if (sensor->sensor_wq == NULL) {
4047 goto sensor_af_workqueue_set_end;
4050 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) != SENSOR_AF_IS_OK) {
4051 if (cmd != WqCmd_af_init) {
4052 SENSOR_TR("%s %s cmd(%d) ingore,because af module isn't ready!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4054 goto sensor_af_workqueue_set_end;
4058 wk = kzalloc(sizeof(struct sensor_work), GFP_KERNEL);
4060 wk->client = client;
4061 INIT_DELAYED_WORK(&wk->dwork, sensor_af_workqueue);
4063 wk->result = WqRet_inval;
4066 init_waitqueue_head(&wk->done);
4068 /* ddl@rock-chips.com:
4069 * video_lock is been locked in v4l2_ioctl function, but auto focus may slow,
4070 * As a result any other ioctl calls will proceed very, very slowly since each call
4071 * will have to wait for the AF to finish. Camera preview is pause,because VIDIOC_QBUF
4072 * and VIDIOC_DQBUF is sched. so unlock video_lock here.
4075 queue_delayed_work(sensor->sensor_wq,&(wk->dwork),0);
4076 mutex_unlock(&icd->video_lock);
4077 if (wait_event_timeout(wk->done, (wk->result != WqRet_inval), msecs_to_jiffies(5000)) == 0) {
4078 SENSOR_TR("%s %s cmd(%d) is timeout!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4080 flush_workqueue(sensor->sensor_wq);
4083 mutex_lock(&icd->video_lock);
4085 queue_delayed_work(sensor->sensor_wq,&(wk->dwork),msecs_to_jiffies(10));
4089 SENSOR_TR("%s %s cmd(%d) ingore,because struct sensor_work malloc failed!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4092 sensor_af_workqueue_set_end:
4096 static int sensor_parameter_record(struct i2c_client *client)
4098 u8 ret_l,ret_m,ret_h;
4100 struct sensor *sensor = to_sensor(client);
4102 sensor_write(client,0x3503,0x07); //stop AE/AG
4103 sensor_write(client,0x3406,0x01); //stop AWB
4105 sensor_read(client,0x3500,&ret_h);
4106 sensor_read(client,0x3501, &ret_m);
4107 sensor_read(client,0x3502, &ret_l);
4111 SENSOR_DG(" %s Read 0x3500 = 0x%02x 0x3501 = 0x%02x 0x3502=0x%02x \n",SENSOR_NAME_STRING(), ret_h, ret_m, ret_l);
4112 sensor->parameter.preview_exposure = (tp_h<<12)+(tp_m<<4)+(tp_l>>4);
4113 sensor_read(client,0x350c, &ret_h);
4114 sensor_read(client,0x350d, &ret_l);
4115 sensor->parameter.preview_line_width = ret_h & 0xff;
4116 sensor->parameter.preview_line_width = (sensor->parameter.preview_line_width << 8) +ret_l;
4117 //Read back AGC Gain for preview
4118 sensor_read(client,0x350b, &tp_l);
4119 sensor->parameter.preview_gain = tp_l;
4121 sensor->parameter.capture_framerate = 900;
4122 sensor->parameter.preview_framerate = 1500;
4124 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);
4127 static int sensor_ae_transfer(struct i2c_client *client)
4132 u16 ulCapture_Exposure;
4133 u32 ulCapture_Exposure_Gain;
4137 u8 reg_l = 0,reg_h =0;
4138 u16 Preview_Maxlines;
4140 u32 Capture_MaxLines;
4141 struct sensor *sensor = to_sensor(client);
4143 Preview_Maxlines = sensor->parameter.preview_line_width;
4144 Gain = sensor->parameter.preview_gain;
4145 sensor_read(client,0x350c, ®_h);
4146 sensor_read(client,0x350d, ®_l);
4147 Capture_MaxLines = reg_h & 0xff;
4148 Capture_MaxLines = (Capture_MaxLines << 8) + reg_l;
4151 Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/12000;
4153 Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/10000;
4156 if(Preview_Maxlines == 0)
4157 Preview_Maxlines = 1;
4159 ulCapture_Exposure =
4160 (sensor->parameter.preview_exposure*(sensor->parameter.capture_framerate)*(Capture_MaxLines))/(((Preview_Maxlines)*(sensor->parameter.preview_framerate)));
4161 iCapture_Gain = (Gain & 0x0f) + 16;
4163 iCapture_Gain = iCapture_Gain << 1;
4166 iCapture_Gain = iCapture_Gain << 1;
4169 iCapture_Gain = iCapture_Gain << 1;
4172 iCapture_Gain = iCapture_Gain << 1;
4174 ulCapture_Exposure_Gain =(u32) (11 * ulCapture_Exposure * iCapture_Gain/5); //0ld value 2.5, ½â¾ö¹ýÁÁ
4175 if(ulCapture_Exposure_Gain < Capture_MaxLines*16) {
4176 ulCapture_Exposure = ulCapture_Exposure_Gain/16;
4177 if (ulCapture_Exposure > Lines_10ms)
4179 //ulCapture_Exposure *= 1.7;
4180 ulCapture_Exposure /= Lines_10ms;
4181 ulCapture_Exposure *= Lines_10ms;
4184 ulCapture_Exposure = Capture_MaxLines;
4185 //ulCapture_Exposure_Gain *= 1.5;
4187 if(ulCapture_Exposure == 0)
4188 ulCapture_Exposure = 1;
4189 iCapture_Gain = (ulCapture_Exposure_Gain*2/ulCapture_Exposure + 1)/2;
4190 ExposureLow = ((unsigned char)ulCapture_Exposure)<<4;
4191 ExposureMid = (unsigned char)(ulCapture_Exposure >> 4) & 0xff;
4192 ExposureHigh = (unsigned char)(ulCapture_Exposure >> 12);
4195 if (iCapture_Gain > 31) {
4197 iCapture_Gain = iCapture_Gain >> 1;
4199 if (iCapture_Gain > 31) {
4201 iCapture_Gain = iCapture_Gain >> 1;
4203 if (iCapture_Gain > 31) {
4205 iCapture_Gain = iCapture_Gain >> 1;
4207 if (iCapture_Gain > 31) {
4209 iCapture_Gain = iCapture_Gain >> 1;
4211 if (iCapture_Gain > 16)
4212 Gain |= ((iCapture_Gain -16) & 0x0f);
4215 // write the gain and exposure to 0x350* registers
4216 //m_iWrite0x350b=Gain;
4217 sensor_write(client,0x350b, Gain);
4218 //m_iWrite0x3502=ExposureLow;
4219 sensor_write(client,0x3502, ExposureLow);
4220 //m_iWrite0x3501=ExposureMid;
4221 sensor_write(client,0x3501, ExposureMid);
4222 //m_iWrite0x3500=ExposureHigh;
4223 sensor_write(client,0x3500, ExposureHigh);
4224 // SendToFile("Gain = 0x%x\r\n", Gain);
4225 // SendToFile("ExposureLow = 0x%x\r\n", ExposureLow);
4226 // SendToFile("ExposureMid = 0x%x\r\n", ExposureMid);
4227 // SendToFile("ExposureHigh = 0x%x\r\n", ExposureHigh);
4228 //¼Ó³¤ÑÓʱ£¬±ÜÃâ°µ´¦ÅÄÕÕʱµÄÃ÷°µ·Ö½çÎÊÌâ
4229 //camera_timed_wait(200);
4230 //linzhk camera_timed_wait(500);
4232 SENSOR_DG(" %s Write 0x350b = 0x%02x 0x3502 = 0x%02x 0x3501=0x%02x 0x3500 = 0x%02x\n",SENSOR_NAME_STRING(), Gain, ExposureLow, ExposureMid, ExposureHigh);
4236 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
4238 struct soc_camera_link *icl = to_soc_camera_link(icd);
4241 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
4245 case Sensor_PowerDown:
4247 if (icl->powerdown) {
4248 ret = icl->powerdown(icd->pdev, on);
4249 if (ret == RK29_CAM_IO_SUCCESS) {
4253 icl->reset(icd->pdev);
4255 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
4257 goto sensor_power_end;
4264 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4265 struct sensor *sensor = to_sensor(client);
4267 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
4268 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
4270 //flash off after 2 secs
4271 hrtimer_cancel(&(flash_off_timer.timer));
4272 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
4279 SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
4288 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
4289 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
4290 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
4291 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
4296 static s32 sensor_init_width = 800;
4297 static s32 sensor_init_height = 600;
4298 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);
4299 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
4300 static struct reginfo* sensor_init_data_p = NULL;
4301 static struct reginfo* sensor_init_winseq_p = NULL;
4302 static struct reginfo* sensor_init_winseq_board = NULL;
4303 static struct reginfo* sensor_init_data_board = NULL;
4304 static int sensor_init(struct v4l2_subdev *sd, u32 val)
4306 struct i2c_client *client = v4l2_get_subdevdata(sd);
4307 struct soc_camera_device *icd = client->dev.platform_data;
4308 struct sensor *sensor = to_sensor(client);
4309 const struct v4l2_queryctrl *qctrl;
4310 const struct sensor_datafmt *fmt;
4312 int ret,pid = 0,i = 0,j=0;
4313 struct rk29camera_platform_data* tmp_plat_data =sensor->sensor_io_request;
4314 int tmp_winseq_size;
4316 sensor_init_data_p = sensor_init_data;
4317 sensor_init_winseq_p = sensor_svga;
4318 sensor_init_width = 800;
4319 sensor_init_height = 600;
4320 if (tmp_plat_data != NULL) {
4321 for(i = 0;i < RK_CAM_NUM;i++){
4322 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
4323 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0)) {
4328 if(tmp_plat_data &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
4329 //user has defined the init data
4331 int tmp_init_data_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data_size;
4332 if(tmp_init_data_size > 2){//init data is valid
4333 if((sizeof(struct reginfo) != sizeof(struct reginfo_t))){
4334 if(sensor_init_data_board) {
4335 vfree(sensor_init_data_board);
4336 sensor_init_data_board = NULL;
4338 sensor_init_data_board = (struct reginfo*)vmalloc(tmp_init_data_size);
4339 if(!sensor_init_data_board)
4340 SENSOR_TR("%s :vmalloc init data erro !",__FUNCTION__);
4341 for(j = 0;j< tmp_init_data_size;j++) {
4342 sensor_init_data_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
4343 sensor_init_data_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
4345 sensor_init_data_p = sensor_init_data_board;
4347 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
4351 tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
4352 if(tmp_winseq_size > 2){
4353 if(sizeof(struct reginfo) != sizeof(struct reginfo_t)){
4354 if(sensor_init_winseq_board) {
4355 vfree(sensor_init_winseq_board);
4356 sensor_init_winseq_board = NULL;
4358 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
4359 if(!sensor_init_winseq_board)
4360 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
4361 for(j = 0;j< tmp_winseq_size;j++){
4362 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
4363 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
4365 sensor_init_winseq_p = sensor_init_winseq_board;
4367 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
4370 //init width,height,bus,pixelcode
4371 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
4372 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
4373 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
4374 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
4375 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
4376 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
4377 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
4378 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
4380 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
4382 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
4384 goto sensor_INIT_ERR;
4388 if (sensor_task_lock(client,1)<0)
4389 goto sensor_INIT_ERR;
4390 ret = sensor_write(client, 0x3008, 0x80);
4392 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
4394 goto sensor_INIT_ERR;
4397 mdelay(5); //delay 5 microseconds
4398 /* check if it is an sensor sensor */
4399 ret = sensor_read(client, 0x300a, &value);
4401 SENSOR_TR("read chip id high byte failed\n");
4403 goto sensor_INIT_ERR;
4406 pid |= (value << 8);
4408 ret = sensor_read(client, 0x300b, &value);
4410 SENSOR_TR("read chip id low byte failed\n");
4412 goto sensor_INIT_ERR;
4415 pid |= (value & 0xff);
4416 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
4418 if (pid == SENSOR_ID) {
4419 sensor->model = SENSOR_V4L2_IDENT;
4421 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4423 goto sensor_INIT_ERR;
4426 ret = sensor_write_array(client, sensor_init_data_p);
4428 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
4429 goto sensor_INIT_ERR;
4431 sensor_task_lock(client,0);
4432 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
4433 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
4435 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
4437 goto sensor_INIT_ERR;
4439 sensor->info_priv.fmt = *fmt;
4441 /* sensor sensor information for initialization */
4442 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4444 sensor->info_priv.whiteBalance = qctrl->default_value;
4445 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
4447 sensor->info_priv.brightness = qctrl->default_value;
4448 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4450 sensor->info_priv.effect = qctrl->default_value;
4451 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
4453 sensor->info_priv.exposure = qctrl->default_value;
4455 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
4457 sensor->info_priv.saturation = qctrl->default_value;
4458 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
4460 sensor->info_priv.contrast = qctrl->default_value;
4461 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
4463 sensor->info_priv.mirror = qctrl->default_value;
4464 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
4466 sensor->info_priv.flip = qctrl->default_value;
4467 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
4469 sensor->info_priv.scene = qctrl->default_value;
4470 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
4472 sensor->info_priv.digitalzoom = qctrl->default_value;
4474 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
4475 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
4477 sensor->info_priv.focus = qctrl->default_value;
4479 #if CONFIG_SENSOR_Flash
4480 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
4482 sensor->info_priv.flash = qctrl->default_value;
4483 flash_off_timer.icd = icd;
4484 flash_off_timer.timer.function = flash_off_func;
4486 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);
4488 sensor->info_priv.funmodule_state = SENSOR_INIT_IS_OK;
4492 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4493 sensor_task_lock(client,0);
4494 sensor_deactivate(client);
4497 static int sensor_deactivate(struct i2c_client *client)
4499 struct soc_camera_device *icd = client->dev.platform_data;
4500 struct sensor *sensor = to_sensor(client);
4502 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
4504 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
4505 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
4506 sensor_task_lock(client, 1);
4507 sensor_write(client, 0x3017, 0x00); // FREX,VSYNC,HREF,PCLK,D9-D6
4508 sensor_write(client, 0x3018, 0x03); // D5-D0
4509 sensor_write(client,0x3019,0x00); // STROBE,SDA
4510 sensor_task_lock(client, 0);
4512 sensor_ioctrl(icd, Sensor_PowerDown, 1);
4514 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
4515 icd->user_width = SENSOR_INIT_WIDTH;
4516 icd->user_height = SENSOR_INIT_HEIGHT;
4517 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4520 static struct reginfo sensor_power_down_sequence[]=
4524 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
4527 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4529 if (pm_msg.event == PM_EVENT_SUSPEND) {
4530 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
4531 ret = sensor_write_array(client, sensor_power_down_sequence) ;
4533 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
4536 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
4538 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
4543 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
4550 static int sensor_resume(struct soc_camera_device *icd)
4554 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
4556 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
4560 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
4564 static int sensor_set_bus_param(struct soc_camera_device *icd,
4565 unsigned long flags)
4571 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
4573 struct soc_camera_link *icl = to_soc_camera_link(icd);
4574 unsigned long flags = SENSOR_BUS_PARAM;
4576 return soc_camera_apply_sensor_flags(icl, flags);
4578 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4580 struct i2c_client *client = v4l2_get_subdevdata(sd);
4581 struct soc_camera_device *icd = client->dev.platform_data;
4582 struct sensor *sensor = to_sensor(client);
4584 mf->width = icd->user_width;
4585 mf->height = icd->user_height;
4586 mf->code = sensor->info_priv.fmt.code;
4587 mf->colorspace = sensor->info_priv.fmt.colorspace;
4588 mf->field = V4L2_FIELD_NONE;
4592 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4596 if ((mf->width == 1024) && (mf->height == 768)) {
4598 } else if ((mf->width == 1280) && (mf->height == 1024)) {
4600 } else if ((mf->width == 1600) && (mf->height == 1200)) {
4602 } else if ((mf->width == 2048) && (mf->height == 1536)) {
4604 } else if ((mf->width == 2592) && (mf->height == 1944)) {
4606 } else if ((mf->width == 3264) && (mf->height == 2448)) {
4611 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
4615 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4619 if ((mf->width == 1280) && (mf->height == 720)) {
4621 } else if ((mf->width == 1920) && (mf->height == 1080)) {
4626 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
4629 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4631 struct i2c_client *client = v4l2_get_subdevdata(sd);
4632 const struct sensor_datafmt *fmt;
4633 struct sensor *sensor = to_sensor(client);
4634 const struct v4l2_queryctrl *qctrl;
4635 struct soc_camera_device *icd = client->dev.platform_data;
4636 struct reginfo *winseqe_set_addr=NULL;
4637 int ret = 0, set_w,set_h;
4639 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4640 ARRAY_SIZE(sensor_colour_fmts));
4643 goto sensor_s_fmt_end;
4646 if (sensor->info_priv.fmt.code != mf->code) {
4649 case V4L2_MBUS_FMT_YUYV8_2X8:
4651 winseqe_set_addr = sensor_ClrFmt_YUYV;
4654 case V4L2_MBUS_FMT_UYVY8_2X8:
4656 winseqe_set_addr = sensor_ClrFmt_UYVY;
4662 if (winseqe_set_addr != NULL) {
4663 sensor_write_array(client, winseqe_set_addr);
4664 sensor->info_priv.fmt.code = mf->code;
4665 sensor->info_priv.fmt.colorspace= mf->colorspace;
4666 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
4668 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
4675 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
4677 winseqe_set_addr = sensor_qcif;
4681 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
4683 winseqe_set_addr = sensor_qvga;
4687 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
4689 winseqe_set_addr = sensor_cif;
4693 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
4695 winseqe_set_addr = sensor_vga;
4699 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
4701 winseqe_set_addr = sensor_svga;
4705 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
4707 winseqe_set_addr = sensor_xga;
4711 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
4713 winseqe_set_addr = sensor_720p;
4717 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
4719 winseqe_set_addr = sensor_sxga;
4723 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
4725 winseqe_set_addr = sensor_uxga;
4729 else if (((set_w <= 1920) && (set_h <= 1080)) && sensor_1080p[0].reg)
4731 winseqe_set_addr = sensor_1080p;
4735 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_qxga[0].reg)
4737 winseqe_set_addr = sensor_qxga;
4741 else if (((set_w <= 2592) && (set_h <= 1944)) && sensor_qsxga[0].reg)
4743 winseqe_set_addr = sensor_qsxga;
4747 #if defined(CONFIG_SOC_CAMERA_OV5642_INTERPOLATION)
4748 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
4750 winseqe_set_addr = sensor_qsxga;
4751 set_w = SENSOR_MAX_WIDTH_REAL;
4752 set_h = SENSOR_MAX_HEIGHT_REAL;
4757 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
4758 set_w = SENSOR_INIT_WIDTH;
4759 set_h = SENSOR_INIT_HEIGHT;
4760 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
4763 if (winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
4765 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
4766 sensor_parameter_record(client);
4767 #if CONFIG_SENSOR_Flash
4768 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4769 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
4770 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
4773 }else { /* ddl@rock-chips.com : Video */
4774 #if CONFIG_SENSOR_Flash
4775 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4776 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4777 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
4782 if ((sensor->info_priv.winseqe_cur_addr->reg == SEQUENCE_PROPERTY) && (sensor->info_priv.winseqe_cur_addr->val == SEQUENCE_INIT)) {
4783 if (((winseqe_set_addr->reg == SEQUENCE_PROPERTY) && (winseqe_set_addr->val == SEQUENCE_NORMAL))
4784 || (winseqe_set_addr->reg != SEQUENCE_PROPERTY)) {
4785 ret |= sensor_write_array(client,sensor_init_data);
4786 SENSOR_DG("\n%s reinit ret:0x%x \n",SENSOR_NAME_STRING(), ret);
4790 ret |= sensor_write_array(client, winseqe_set_addr);
4792 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
4793 #if CONFIG_SENSOR_Flash
4794 if (sensor_fmt_capturechk(sd,mf) == true) {
4795 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4796 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4797 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
4801 goto sensor_s_fmt_end;
4804 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
4806 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
4807 sensor_ae_transfer(client);
4808 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4809 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4810 if (sensor->info_priv.whiteBalance != 0) {
4811 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4812 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4814 #if CONFIG_SENSOR_Focus
4815 if (sensor->info_priv.auto_focus != SENSOR_AF_MODE_INFINITY) {
4816 if (sensor_af_workqueue_set(icd, WqCmd_af_update_zone,0,true) == 0) {
4817 if ((sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) ||
4818 (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS)) {
4820 sensor_af_workqueue_set(icd, WqCmd_af_single,0,true);
4825 sensor->info_priv.snap2preview = true;
4826 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
4827 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4828 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4829 #if CONFIG_SENSOR_Focus
4830 sensor->info_priv.affm_reinit = 1;
4832 sensor->info_priv.video2preview = true;
4833 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
4834 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4835 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4836 if (sensor->info_priv.snap2preview == true) {
4837 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4838 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4840 #if CONFIG_SENSOR_Focus
4841 if (sensor->info_priv.auto_focus != SENSOR_AF_MODE_INFINITY) {
4842 /* ddl@rock-chips.com: The af operation is not necessary, if user don't care whether in focus after preview*/
4843 if (sensor_af_workqueue_set(icd, WqCmd_af_update_zone,0,false) == 0) {
4844 if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS) {
4845 sensor_af_workqueue_set(icd, WqCmd_af_continues,0,false);
4846 } else if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) {
4848 sensor_af_workqueue_set(icd, WqCmd_af_single,0,false);
4853 msleep(600); /* ddl@rock-chips.com : whitebalance auto must delay */
4856 sensor->info_priv.video2preview = false;
4857 sensor->info_priv.snap2preview = false;
4862 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
4866 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
4875 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4877 struct i2c_client *client = v4l2_get_subdevdata(sd);
4878 struct sensor *sensor = to_sensor(client);
4879 const struct sensor_datafmt *fmt;
4880 int ret = 0,set_w,set_h;
4882 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4883 ARRAY_SIZE(sensor_colour_fmts));
4885 fmt = &sensor->info_priv.fmt;
4886 mf->code = fmt->code;
4888 /* ddl@rock-chips.com : It is query max resolution only. */
4889 if (mf->reserved[6] == 0xfefe5a5a) {
4890 mf->height = SENSOR_MAX_HEIGHT;
4891 mf->width = SENSOR_MAX_WIDTH;
4893 printk("%s(%d): query resolution\n",__FUNCTION__,__LINE__);
4894 goto sensor_try_fmt_end;
4897 if (mf->height > SENSOR_MAX_HEIGHT)
4898 mf->height = SENSOR_MAX_HEIGHT;
4899 else if (mf->height < SENSOR_MIN_HEIGHT)
4900 mf->height = SENSOR_MIN_HEIGHT;
4902 if (mf->width > SENSOR_MAX_WIDTH)
4903 mf->width = SENSOR_MAX_WIDTH;
4904 else if (mf->width < SENSOR_MIN_WIDTH)
4905 mf->width = SENSOR_MIN_WIDTH;
4910 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
4915 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
4920 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
4925 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
4930 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
4935 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
4940 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
4945 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
4950 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
4955 else if (((set_w <= 1920) && (set_h <= 1080)) && sensor_1080p[0].reg)
4960 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_qxga[0].reg)
4965 else if (((set_w <= 2592) && (set_h <= 1944)) && sensor_qsxga[0].reg)
4970 #if defined(CONFIG_SOC_CAMERA_OV5642_INTERPOLATION)
4971 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
4973 set_w = SENSOR_MAX_WIDTH_REAL;
4974 set_h = SENSOR_MAX_HEIGHT_REAL;
4979 set_w = SENSOR_INIT_WIDTH;
4980 set_h = SENSOR_INIT_HEIGHT;
4986 mf->colorspace = fmt->colorspace;
4991 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
4993 struct i2c_client *client = v4l2_get_subdevdata(sd);
4995 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
4998 if (id->match.addr != client->addr)
5001 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
5006 #if CONFIG_SENSOR_Brightness
5007 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5009 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5011 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5013 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
5015 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
5017 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5020 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5024 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5028 #if CONFIG_SENSOR_Effect
5029 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5031 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5033 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5035 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
5037 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
5039 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5042 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5046 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5050 #if CONFIG_SENSOR_Exposure
5051 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5053 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5055 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5057 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
5059 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
5061 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5064 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5068 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5072 #if CONFIG_SENSOR_Saturation
5073 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5075 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5077 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5079 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
5081 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
5083 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5086 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5090 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5094 #if CONFIG_SENSOR_Contrast
5095 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5097 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5099 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5101 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
5103 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
5105 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5108 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5112 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5116 #if CONFIG_SENSOR_Mirror
5117 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5119 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5121 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5123 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
5125 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
5127 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5130 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5134 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5138 #if CONFIG_SENSOR_Flip
5139 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5141 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5143 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5145 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
5147 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
5149 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5152 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5156 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5160 #if CONFIG_SENSOR_Scene
5161 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5163 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5165 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5167 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
5169 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
5171 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5174 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5178 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5182 #if CONFIG_SENSOR_WhiteBalance
5183 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5185 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5187 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5189 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
5191 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
5193 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5196 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5200 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5204 #if CONFIG_SENSOR_DigitalZoom
5205 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
5207 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5208 struct sensor *sensor = to_sensor(client);
5209 const struct v4l2_queryctrl *qctrl_info;
5210 int digitalzoom_cur, digitalzoom_total;
5212 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
5216 digitalzoom_cur = sensor->info_priv.digitalzoom;
5217 digitalzoom_total = qctrl_info->maximum;
5219 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
5221 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
5225 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
5227 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
5231 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
5233 *value = digitalzoom_total - digitalzoom_cur;
5236 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
5238 *value = 0 - digitalzoom_cur;
5241 digitalzoom_cur += *value;
5243 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
5245 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
5247 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5250 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
5257 #if CONFIG_SENSOR_Focus
5258 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5260 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5261 struct sensor *sensor = to_sensor(client);
5262 const struct v4l2_queryctrl *qctrl_info;
5265 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
5269 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5270 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
5271 ret = sensor_af_workqueue_set(icd, WqCmd_af_special_pos, value, true);
5272 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5275 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5279 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5280 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5285 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5287 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5288 struct sensor *sensor = to_sensor(client);
5289 const struct v4l2_queryctrl *qctrl_info;
5292 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
5296 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5297 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
5299 ret = sensor_af_workqueue_set(icd, WqCmd_af_near_pos, 0, true);
5301 ret = sensor_af_workqueue_set(icd, WqCmd_af_far_pos, 0, true);
5303 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5306 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5310 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5311 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5316 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5318 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5319 struct sensor *sensor = to_sensor(client);
5322 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5325 case SENSOR_AF_MODE_AUTO:
5327 ret = sensor_af_workqueue_set(icd, WqCmd_af_single, 0, true);
5331 case SENSOR_AF_MODE_MACRO:
5333 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
5337 case SENSOR_AF_MODE_INFINITY:
5339 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
5343 case SENSOR_AF_MODE_CONTINUOUS:
5345 ret = sensor_af_workqueue_set(icd, WqCmd_af_continues, 0, true);
5349 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5354 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5357 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5358 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5365 #if CONFIG_SENSOR_Flash
5366 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5368 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
5369 if (value == 3) { /* ddl@rock-chips.com: torch */
5370 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
5372 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
5374 SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5378 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5383 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5385 struct i2c_client *client = v4l2_get_subdevdata(sd);
5386 struct sensor *sensor = to_sensor(client);
5387 const struct v4l2_queryctrl *qctrl;
5389 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5393 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5399 case V4L2_CID_BRIGHTNESS:
5401 ctrl->value = sensor->info_priv.brightness;
5404 case V4L2_CID_SATURATION:
5406 ctrl->value = sensor->info_priv.saturation;
5409 case V4L2_CID_CONTRAST:
5411 ctrl->value = sensor->info_priv.contrast;
5414 case V4L2_CID_DO_WHITE_BALANCE:
5416 ctrl->value = sensor->info_priv.whiteBalance;
5419 case V4L2_CID_EXPOSURE:
5421 ctrl->value = sensor->info_priv.exposure;
5424 case V4L2_CID_HFLIP:
5426 ctrl->value = sensor->info_priv.mirror;
5429 case V4L2_CID_VFLIP:
5431 ctrl->value = sensor->info_priv.flip;
5442 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5444 struct i2c_client *client = v4l2_get_subdevdata(sd);
5445 struct sensor *sensor = to_sensor(client);
5446 struct soc_camera_device *icd = client->dev.platform_data;
5447 const struct v4l2_queryctrl *qctrl;
5450 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5454 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5460 #if CONFIG_SENSOR_Brightness
5461 case V4L2_CID_BRIGHTNESS:
5463 if (ctrl->value != sensor->info_priv.brightness)
5465 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
5469 sensor->info_priv.brightness = ctrl->value;
5474 #if CONFIG_SENSOR_Exposure
5475 case V4L2_CID_EXPOSURE:
5477 if (ctrl->value != sensor->info_priv.exposure)
5479 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
5483 sensor->info_priv.exposure = ctrl->value;
5488 #if CONFIG_SENSOR_Saturation
5489 case V4L2_CID_SATURATION:
5491 if (ctrl->value != sensor->info_priv.saturation)
5493 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
5497 sensor->info_priv.saturation = ctrl->value;
5502 #if CONFIG_SENSOR_Contrast
5503 case V4L2_CID_CONTRAST:
5505 if (ctrl->value != sensor->info_priv.contrast)
5507 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
5511 sensor->info_priv.contrast = ctrl->value;
5516 #if CONFIG_SENSOR_WhiteBalance
5517 case V4L2_CID_DO_WHITE_BALANCE:
5519 if (ctrl->value != sensor->info_priv.whiteBalance)
5521 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
5525 sensor->info_priv.whiteBalance = ctrl->value;
5530 #if CONFIG_SENSOR_Mirror
5531 case V4L2_CID_HFLIP:
5533 if (ctrl->value != sensor->info_priv.mirror)
5535 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
5537 sensor->info_priv.mirror = ctrl->value;
5542 #if CONFIG_SENSOR_Flip
5543 case V4L2_CID_VFLIP:
5545 if (ctrl->value != sensor->info_priv.flip)
5547 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
5549 sensor->info_priv.flip = ctrl->value;
5560 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
5562 const struct v4l2_queryctrl *qctrl;
5563 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5564 struct sensor *sensor = to_sensor(client);
5566 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5570 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5574 switch (ext_ctrl->id)
5576 case V4L2_CID_SCENE:
5578 ext_ctrl->value = sensor->info_priv.scene;
5581 case V4L2_CID_EFFECT:
5583 ext_ctrl->value = sensor->info_priv.effect;
5586 case V4L2_CID_ZOOM_ABSOLUTE:
5588 ext_ctrl->value = sensor->info_priv.digitalzoom;
5591 case V4L2_CID_ZOOM_RELATIVE:
5595 case V4L2_CID_FOCUS_ABSOLUTE:
5599 case V4L2_CID_FOCUS_RELATIVE:
5603 case V4L2_CID_FLASH:
5605 ext_ctrl->value = sensor->info_priv.flash;
5613 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
5615 const struct v4l2_queryctrl *qctrl;
5616 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5617 struct sensor *sensor = to_sensor(client);
5620 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5624 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5629 switch (ext_ctrl->id)
5631 #if CONFIG_SENSOR_Scene
5632 case V4L2_CID_SCENE:
5634 if (ext_ctrl->value != sensor->info_priv.scene)
5636 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
5638 sensor->info_priv.scene = ext_ctrl->value;
5643 #if CONFIG_SENSOR_Effect
5644 case V4L2_CID_EFFECT:
5646 if (ext_ctrl->value != sensor->info_priv.effect)
5648 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
5650 sensor->info_priv.effect= ext_ctrl->value;
5655 #if CONFIG_SENSOR_DigitalZoom
5656 case V4L2_CID_ZOOM_ABSOLUTE:
5658 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5661 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
5663 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
5665 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
5667 sensor->info_priv.digitalzoom += val_offset;
5669 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
5674 case V4L2_CID_ZOOM_RELATIVE:
5676 if (ext_ctrl->value)
5678 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
5680 sensor->info_priv.digitalzoom += ext_ctrl->value;
5682 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
5687 #if CONFIG_SENSOR_Focus
5688 case V4L2_CID_FOCUS_ABSOLUTE:
5690 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5693 ret = sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value);
5694 if ((ret == 0) || (0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK))) {
5695 if (ext_ctrl->value == qctrl->minimum) {
5696 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
5697 } else if (ext_ctrl->value == qctrl->maximum) {
5698 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
5700 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
5706 case V4L2_CID_FOCUS_RELATIVE:
5708 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5711 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
5714 case V4L2_CID_FOCUS_AUTO:
5716 if (ext_ctrl->value) {
5717 if ((ext_ctrl->value==1) || (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus)) {
5718 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0) {
5719 if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5720 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5725 if (ext_ctrl->value == 1)
5726 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5727 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
5728 if (ext_ctrl->value == 0)
5729 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5733 case V4L2_CID_FOCUS_CONTINUOUS:
5735 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
5736 if (ext_ctrl->value == 1) {
5737 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0) {
5738 if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5739 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5743 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5746 if (ext_ctrl->value == 0)
5747 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5752 #if CONFIG_SENSOR_Flash
5753 case V4L2_CID_FLASH:
5755 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
5757 sensor->info_priv.flash = ext_ctrl->value;
5759 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
5770 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5772 struct i2c_client *client = v4l2_get_subdevdata(sd);
5773 struct soc_camera_device *icd = client->dev.platform_data;
5774 int i, error_cnt=0, error_idx=-1;
5777 for (i=0; i<ext_ctrl->count; i++) {
5778 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5785 error_idx = ext_ctrl->count;
5787 if (error_idx != -1) {
5788 ext_ctrl->error_idx = error_idx;
5795 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5797 struct i2c_client *client = v4l2_get_subdevdata(sd);
5798 struct soc_camera_device *icd = client->dev.platform_data;
5799 int i, error_cnt=0, error_idx=-1;
5801 for (i=0; i<ext_ctrl->count; i++) {
5802 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5809 error_idx = ext_ctrl->count;
5811 if (error_idx != -1) {
5812 ext_ctrl->error_idx = error_idx;
5819 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
5821 struct i2c_client *client = v4l2_get_subdevdata(sd);
5822 struct sensor *sensor = to_sensor(client);
5823 #if CONFIG_SENSOR_Focus
5824 struct soc_camera_device *icd = client->dev.platform_data;
5825 struct v4l2_mbus_framefmt mf;
5829 sensor->info_priv.enable = 1;
5830 #if CONFIG_SENSOR_Focus
5831 mf.width = icd->user_width;
5832 mf.height = icd->user_height;
5833 mf.code = sensor->info_priv.fmt.code;
5834 mf.colorspace = sensor->info_priv.fmt.colorspace;
5835 mf.field = V4L2_FIELD_NONE;
5836 /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
5837 if (sensor_fmt_capturechk(sd, &mf) == false) {
5838 if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {
5839 sensor_af_workqueue_set(icd, WqCmd_af_init, 0, false);
5840 sensor->info_priv.affm_reinit = 0;
5844 } else if (enable == 0) {
5845 sensor->info_priv.enable = 0;
5846 #if CONFIG_SENSOR_Focus
5847 flush_workqueue(sensor->sensor_wq);
5853 /* Interface active, can use i2c. If it fails, it can indeed mean, that
5854 * this wasn't our capture interface, so, we wait for the right one */
5855 static int sensor_video_probe(struct soc_camera_device *icd,
5856 struct i2c_client *client)
5860 struct sensor *sensor = to_sensor(client);
5862 /* We must have a parent by now. And it cannot be a wrong one.
5863 * So this entire test is completely redundant. */
5864 if (!icd->dev.parent ||
5865 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
5868 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
5870 goto sensor_video_probe_err;
5873 ret = sensor_write(client, 0x3012, 0x80);
5875 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
5877 goto sensor_video_probe_err;
5879 mdelay(5); //delay 5 microseconds
5881 /* check if it is an sensor sensor */
5882 ret = sensor_read(client, 0x300a, &value);
5884 SENSOR_TR("read chip id high byte failed\n");
5886 goto sensor_video_probe_err;
5889 pid |= (value << 8);
5891 ret = sensor_read(client, 0x300b, &value);
5893 SENSOR_TR("read chip id low byte failed\n");
5895 goto sensor_video_probe_err;
5898 pid |= (value & 0xff);
5899 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5900 if (pid == SENSOR_ID) {
5901 sensor->model = SENSOR_V4L2_IDENT;
5903 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5905 goto sensor_video_probe_err;
5910 sensor_video_probe_err:
5914 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
5916 struct i2c_client *client = v4l2_get_subdevdata(sd);
5917 struct soc_camera_device *icd = client->dev.platform_data;
5918 struct sensor *sensor = to_sensor(client);
5921 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5924 case RK29_CAM_SUBDEV_DEACTIVATE:
5926 sensor_deactivate(client);
5929 case RK29_CAM_SUBDEV_IOREQUEST:
5931 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
5933 if (sensor->sensor_io_request != NULL) {
5935 for(j = 0;j < RK_CAM_NUM;j++){
5936 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
5937 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
5938 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
5942 if(j == RK_CAM_NUM){
5943 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
5945 goto sensor_ioctl_end;
5949 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
5951 #if CONFIG_SENSOR_Flash
5952 if (sensor->sensor_gpio_res) {
5953 printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
5954 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
5955 for (i = 0; i < icd->ops->num_controls; i++) {
5956 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
5957 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
5958 sensor_controls[i].id=0xffff;
5961 sensor->info_priv.flash = 0xff;
5962 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
5963 }else{ //two cameras are the same,need to deal diffrently ,zycc
5964 for (i = 0; i < icd->ops->num_controls; i++) {
5965 if(0xffff == icd->ops->controls[i].id){
5966 sensor_controls[i].id=V4L2_CID_FLASH;
5976 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5985 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
5986 enum v4l2_mbus_pixelcode *code)
5988 if (index >= ARRAY_SIZE(sensor_colour_fmts))
5991 *code = sensor_colour_fmts[index].code;
5994 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
5995 .init = sensor_init,
5996 .g_ctrl = sensor_g_control,
5997 .s_ctrl = sensor_s_control,
5998 .g_ext_ctrls = sensor_g_ext_controls,
5999 .s_ext_ctrls = sensor_s_ext_controls,
6000 .g_chip_ident = sensor_g_chip_ident,
6001 .ioctl = sensor_ioctl,
6004 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
6005 .s_mbus_fmt = sensor_s_fmt,
6006 .g_mbus_fmt = sensor_g_fmt,
6007 .try_mbus_fmt = sensor_try_fmt,
6008 .enum_mbus_fmt = sensor_enum_fmt,
6009 .s_stream = sensor_s_stream,
6011 static struct v4l2_subdev_ops sensor_subdev_ops = {
6012 .core = &sensor_subdev_core_ops,
6013 .video = &sensor_subdev_video_ops,
6016 static int sensor_probe(struct i2c_client *client,
6017 const struct i2c_device_id *did)
6019 struct sensor *sensor;
6020 struct soc_camera_device *icd = client->dev.platform_data;
6021 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
6022 struct soc_camera_link *icl;
6025 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
6027 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
6031 icl = to_soc_camera_link(icd);
6033 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
6037 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
6038 dev_warn(&adapter->dev,
6039 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
6043 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
6047 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
6049 /* Second stage probe - when a capture adapter is there */
6050 icd->ops = &sensor_ops;
6051 sensor->info_priv.fmt = sensor_colour_fmts[0];
6052 #if CONFIG_SENSOR_I2C_NOSCHED
6053 atomic_set(&sensor->tasklock_cnt,0);
6056 ret = sensor_video_probe(icd, client);
6059 i2c_set_clientdata(client, NULL);
6063 #if CONFIG_SENSOR_Focus
6064 sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING(_af_workqueue));
6065 if (sensor->sensor_wq == NULL)
6066 SENSOR_TR("%s create fail!", SENSOR_NAME_STRING(_af_workqueue));
6067 mutex_init(&sensor->wq_lock);
6070 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
6071 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
6075 static int sensor_remove(struct i2c_client *client)
6077 struct sensor *sensor = to_sensor(client);
6078 struct soc_camera_device *icd = client->dev.platform_data;
6080 #if CONFIG_SENSOR_Focus
6081 if (sensor->sensor_wq) {
6082 destroy_workqueue(sensor->sensor_wq);
6083 sensor->sensor_wq = NULL;
6088 i2c_set_clientdata(client, NULL);
6089 client->driver = NULL;
6095 static const struct i2c_device_id sensor_id[] = {
6096 {SENSOR_NAME_STRING(), 0 },
6099 MODULE_DEVICE_TABLE(i2c, sensor_id);
6101 static struct i2c_driver sensor_i2c_driver = {
6103 .name = SENSOR_NAME_STRING(),
6105 .probe = sensor_probe,
6106 .remove = sensor_remove,
6107 .id_table = sensor_id,
6110 static int __init sensor_mod_init(void)
6112 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
6113 return i2c_add_driver(&sensor_i2c_driver);
6116 static void __exit sensor_mod_exit(void)
6118 i2c_del_driver(&sensor_i2c_driver);
6121 device_initcall_sync(sensor_mod_init);
6122 module_exit(sensor_mod_exit);
6124 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
6125 MODULE_AUTHOR("ddl <kernel@rock-chips>");
6126 MODULE_LICENSE("GPL");