2 #include "generic_sensor.h"
\r
4 * Driver Version Note
\r
5 *v0.0.1: this driver is compatible with generic_sensor
\r
7 * add sensor_focus_af_const_pause_usr_cb;
\r
9 static int version = KERNEL_VERSION(0,1,1);
\r
10 module_param(version, int, S_IRUGO);
\r
15 module_param(debug, int, S_IRUGO|S_IWUSR);
\r
17 #define dprintk(level, fmt, arg...) do { \
\r
18 if (debug > level) \
\r
19 printk(KERN_WARNING fmt , ## arg); } while (0)
\r
21 /* Sensor Driver Configuration Begin */
\r
22 #define SENSOR_NAME RK29_CAM_SENSOR_SP2518
\r
23 #define SENSOR_V4L2_IDENT V4L2_IDENT_SP2518
\r
24 #define SENSOR_ID 0x53
\r
25 #define SENSOR_BUS_PARAM (V4L2_MBUS_MASTER |\
\r
26 V4L2_MBUS_PCLK_SAMPLE_RISING|V4L2_MBUS_HSYNC_ACTIVE_HIGH| V4L2_MBUS_VSYNC_ACTIVE_HIGH|\
\r
27 V4L2_MBUS_DATA_ACTIVE_HIGH |SOCAM_MCLK_24MHZ)
\r
28 #define SENSOR_PREVIEW_W 800
\r
29 #define SENSOR_PREVIEW_H 600
\r
30 #define SENSOR_PREVIEW_FPS 15000 // 15fps
\r
31 #define SENSOR_FULLRES_L_FPS 7500 // 7.5fps
\r
32 #define SENSOR_FULLRES_H_FPS 7500 // 7.5fps
\r
33 #define SENSOR_720P_FPS 0
\r
34 #define SENSOR_1080P_FPS 0
\r
36 #define SENSOR_REGISTER_LEN 1 // sensor register address bytes
\r
37 #define SENSOR_VALUE_LEN 1 // sensor register value bytes
\r
39 static unsigned int SensorConfiguration = (CFG_WhiteBalance|CFG_Effect|CFG_Scene);
\r
40 static unsigned int SensorChipID[] = {SENSOR_ID};
\r
41 /* Sensor Driver Configuration End */
\r
44 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
\r
45 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
\r
47 #define SensorRegVal(a,b) CONS4(SensorReg,SENSOR_REGISTER_LEN,Val,SENSOR_VALUE_LEN)(a,b)
\r
48 #define sensor_write(client,reg,v) CONS4(sensor_write_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
\r
49 #define sensor_read(client,reg,v) CONS4(sensor_read_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
\r
50 #define sensor_write_array generic_sensor_write_array
\r
52 struct sensor_parameter
\r
54 unsigned int PreviewDummyPixels;
\r
55 unsigned int CaptureDummyPixels;
\r
56 unsigned int preview_exposure;
\r
57 unsigned short int preview_line_width;
\r
58 unsigned short int preview_gain;
\r
60 unsigned short int PreviewPclk;
\r
61 unsigned short int CapturePclk;
\r
65 struct specific_sensor{
\r
66 struct generic_sensor common_sensor;
\r
67 //define user data below
\r
68 struct sensor_parameter parameter;
\r
76 #define SP2518_P0_0xf7 0x80//78
\r
77 #define SP2518_P0_0xf8 0x74//6e
\r
78 #define SP2518_P0_0xf9 0x80//74
\r
79 #define SP2518_P0_0xfa 0x74//6a
\r
81 #define SP2518_P0_0xdd 0x80
\r
82 #define SP2518_P0_0xde 0x95
\r
84 #define SP2518_NORMAL_Y0ffset 0x10 //0x0f modify by sp_yjp,20120813
85 #define SP2518_LOWLIGHT_Y0ffset 0x20
\r
88 * The follow setting need been filled.
\r
91 * sensor_init_data : Sensor initial setting;
\r
92 * sensor_fullres_lowfps_data : Sensor full resolution setting with best auality, recommand for video;
\r
93 * sensor_preview_data : Sensor preview resolution setting, recommand it is vga or svga;
\r
94 * sensor_softreset_data : Sensor software reset register;
\r
95 * sensor_check_id_data : Sensir chip id register;
\r
98 * sensor_fullres_highfps_data: Sensor full resolution setting with high framerate, recommand for video;
\r
99 * sensor_720p: Sensor 720p setting, it is for video;
\r
100 * sensor_1080p: Sensor 1080p setting, it is for video;
\r
102 * :::::WARNING:::::
\r
103 * The SensorEnd which is the setting end flag must be filled int the last of each setting;
\r
106 /* Sensor initial setting */
\r
107 static struct rk_sensor_reg sensor_init_data[] = {
\r
109 {0x1b,0x1a},//maximum drv ability //0x02 modify by sp_yjp,20120809
116 {0x14,0x40},// 0x20 zch 20120920
126 {0x2c,0x23},//31 Ronlus remove balck dot0x45},
128 {0x2e,0x38},//sxga 0x18
130 {0x31,0x10},//mirror upside down
178 ///SP2518 UXGA 24MEclk 3±¶Æµ 1·ÖƵ 50Hz fix 10fps
213 /*24*3pll 13-13fps 50hz*/
249 {0xca,0x30},//mean dummy2low
250 {0xcb,0x50},//mean low2dummy
251 {0xcc,0xc0},//f8;rpc low
252 {0xcd,0xc0},//rpc dummy
253 {0xd5,0x80},//mean normal2dummy
254 {0xd6,0x90},//mean dummy2normal
294 {0x57,0x08},//raw_dif_thr
299 {0x5a,0xa0},//raw_rb_fac_outdoor
300 {0xc4,0xa0},//60raw_rb_fac_indoor
301 {0x43,0xa0},//40raw_rb_fac_dummy
302 {0xad,0x40},//raw_rb_fac_low
304 {0x4f,0xa0},//raw_gf_fac_outdoor
305 {0xc3,0xa0},//60raw_gf_fac_indoor
306 {0x3f,0xa0},//40raw_gf_fac_dummy
307 {0x42,0x40},//raw_gf_fac_low
310 {0xb6,0x80},//raw_gflt_fac_outdoor
311 {0xb7,0x80},//60raw_gflt_fac_normal
312 {0xb8,0x40},//40raw_gflt_fac_dummy
313 {0xb9,0x20},//raw_gflt_fac_low
316 {0x50,0x0c},//raw_grgb_thr
360 {0x36,0xf0},//f0;d1;e9
362 {0x38,0x9a},//dc;9a;af
520 {0xdd,SP2518_P0_0xdd},//0x80
521 {0xde,SP2518_P0_0xde},//a0
603 {0x5d,0x0e}, //vsync delay
\r
607 /* Senor full resolution setting: recommand for capture */
\r
608 static struct rk_sensor_reg sensor_fullres_lowfps_data[] ={
\r
626 /* Senor full resolution setting: recommand for video */
\r
627 static struct rk_sensor_reg sensor_fullres_highfps_data[] ={
\r
630 /* Preview resolution setting*/
\r
631 static struct rk_sensor_reg sensor_preview_data[] =
\r
657 static struct rk_sensor_reg sensor_720p[]={
\r
662 static struct rk_sensor_reg sensor_1080p[]={
\r
667 static struct rk_sensor_reg sensor_softreset_data[]={
\r
671 static struct rk_sensor_reg sensor_check_id_data[]={
\r
672 SensorRegVal(0x02,0),
\r
676 * The following setting must been filled, if the function is turn on by CONFIG_SENSOR_xxxx
\r
678 static struct rk_sensor_reg sensor_WhiteB_Auto[]=
\r
688 /* Cloudy Colour Temperature : 6500K - 8000K */
\r
689 static struct rk_sensor_reg sensor_WhiteB_Cloudy[]=
\r
700 /* ClearDay Colour Temperature : 5000K - 6500K */
\r
701 static struct rk_sensor_reg sensor_WhiteB_ClearDay[]=
\r
712 /* Office Colour Temperature : 3500K - 5000K */
\r
713 static struct rk_sensor_reg sensor_WhiteB_TungstenLamp1[]=
\r
725 /* Home Colour Temperature : 2500K - 3500K */
\r
726 static struct rk_sensor_reg sensor_WhiteB_TungstenLamp2[]=
\r
738 static struct rk_sensor_reg *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
\r
739 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
\r
742 static struct rk_sensor_reg sensor_Brightness0[]=
\r
748 static struct rk_sensor_reg sensor_Brightness1[]=
\r
755 static struct rk_sensor_reg sensor_Brightness2[]=
\r
762 static struct rk_sensor_reg sensor_Brightness3[]=
\r
769 static struct rk_sensor_reg sensor_Brightness4[]=
\r
776 static struct rk_sensor_reg sensor_Brightness5[]=
\r
782 static struct rk_sensor_reg *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
\r
783 sensor_Brightness4, sensor_Brightness5,NULL,
\r
786 static struct rk_sensor_reg sensor_Effect_Normal[] =
\r
795 static struct rk_sensor_reg sensor_Effect_WandB[] =
\r
804 static struct rk_sensor_reg sensor_Effect_Sepia[] =
\r
813 static struct rk_sensor_reg sensor_Effect_Negative[] =
\r
821 static struct rk_sensor_reg sensor_Effect_Bluish[] =
\r
830 static struct rk_sensor_reg sensor_Effect_Green[] =
\r
838 static struct rk_sensor_reg *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
\r
839 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
\r
842 static struct rk_sensor_reg sensor_Exposure0[]=
\r
847 static struct rk_sensor_reg sensor_Exposure1[]=
\r
852 static struct rk_sensor_reg sensor_Exposure2[]=
\r
857 static struct rk_sensor_reg sensor_Exposure3[]=
\r
862 static struct rk_sensor_reg sensor_Exposure4[]=
\r
867 static struct rk_sensor_reg sensor_Exposure5[]=
\r
872 static struct rk_sensor_reg sensor_Exposure6[]=
\r
877 static struct rk_sensor_reg *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
\r
878 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
\r
881 static struct rk_sensor_reg sensor_Saturation0[]=
\r
886 static struct rk_sensor_reg sensor_Saturation1[]=
\r
891 static struct rk_sensor_reg sensor_Saturation2[]=
\r
895 static struct rk_sensor_reg *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
\r
897 static struct rk_sensor_reg sensor_Contrast0[]=
\r
902 static struct rk_sensor_reg sensor_Contrast1[]=
\r
907 static struct rk_sensor_reg sensor_Contrast2[]=
\r
912 static struct rk_sensor_reg sensor_Contrast3[]=
\r
917 static struct rk_sensor_reg sensor_Contrast4[]=
\r
923 static struct rk_sensor_reg sensor_Contrast5[]=
\r
928 static struct rk_sensor_reg sensor_Contrast6[]=
\r
932 static struct rk_sensor_reg *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
\r
933 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
\r
935 static struct rk_sensor_reg sensor_SceneAuto[] =
\r
938 {0xb2,SP2518_NORMAL_Y0ffset},
941 //SP2518 UXGA 24MEclk 3PLL 50Hz fix13fps
976 static struct rk_sensor_reg sensor_SceneNight[] =
\r
979 {0xb2,SP2518_LOWLIGHT_Y0ffset},
982 //SP2518 UXGA 24MEclk 3PLL 50Hz fix 6fps
1015 static struct rk_sensor_reg *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
\r
1017 static struct rk_sensor_reg sensor_Zoom0[] =
\r
1022 static struct rk_sensor_reg sensor_Zoom1[] =
\r
1027 static struct rk_sensor_reg sensor_Zoom2[] =
\r
1033 static struct rk_sensor_reg sensor_Zoom3[] =
\r
1037 static struct rk_sensor_reg *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
\r
1040 * User could be add v4l2_querymenu in sensor_controls by new_usr_v4l2menu
\r
1042 static struct v4l2_querymenu sensor_menus[] =
\r
1046 * User could be add v4l2_queryctrl in sensor_controls by new_user_v4l2ctrl
\r
1048 static struct sensor_v4l2ctrl_usr_s sensor_controls[] =
\r
1052 //MUST define the current used format as the first item
\r
1053 static struct rk_sensor_datafmt sensor_colour_fmts[] = {
\r
1054 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
\r
1056 /*static struct soc_camera_ops sensor_ops;*/
\r
1060 **********************************************************
\r
1061 * Following is local code:
\r
1063 * Please codeing your program here
\r
1064 **********************************************************
\r
1068 **********************************************************
\r
1069 * Following is callback
\r
1070 * If necessary, you could coding these callback
\r
1071 **********************************************************
\r
1074 * the function is called in open sensor
\r
1076 static int sensor_activate_cb(struct i2c_client *client)
\r
1079 SENSOR_DG("%s",__FUNCTION__);
\r
1085 * the function is called in close sensor
\r
1087 static int sensor_deactivate_cb(struct i2c_client *client)
\r
1089 //struct generic_sensor *sensor = to_generic_sensor(client);
\r
1091 SENSOR_DG("%s",__FUNCTION__);
\r
1096 * the function is called before sensor register setting in VIDIOC_S_FMT
\r
1098 static int sensor_s_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
\r
1103 * the function is called after sensor register setting finished in VIDIOC_S_FMT
\r
1105 static int sensor_s_fmt_cb_bh (struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
\r
1109 static int sensor_softrest_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
\r
1114 static int sensor_check_id_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
\r
1118 static int sensor_try_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf)
1123 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
\r
1125 //struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1127 if (pm_msg.event == PM_EVENT_SUSPEND) {
\r
1128 SENSOR_DG("Suspend");
\r
1131 SENSOR_TR("pm_msg.event(0x%x) != PM_EVENT_SUSPEND\n",pm_msg.event);
\r
1137 static int sensor_resume(struct soc_camera_device *icd)
\r
1140 SENSOR_DG("Resume");
\r
1145 static int sensor_mirror_cb (struct i2c_client *client, int mirror)
\r
1149 SENSOR_DG("mirror: %d",mirror);
\r
1155 * the function is v4l2 control V4L2_CID_HFLIP callback
\r
1157 static int sensor_v4l2ctrl_mirror_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info,
\r
1158 struct v4l2_ext_control *ext_ctrl)
\r
1160 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1162 if (sensor_mirror_cb(client,ext_ctrl->value) != 0)
\r
1163 SENSOR_TR("sensor_mirror failed, value:0x%x",ext_ctrl->value);
\r
1165 SENSOR_DG("sensor_mirror success, value:0x%x",ext_ctrl->value);
\r
1169 static int sensor_flip_cb(struct i2c_client *client, int flip)
\r
1173 SENSOR_DG("flip: %d",flip);
\r
1178 * the function is v4l2 control V4L2_CID_VFLIP callback
\r
1180 static int sensor_v4l2ctrl_flip_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info,
\r
1181 struct v4l2_ext_control *ext_ctrl)
\r
1183 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1185 if (sensor_flip_cb(client,ext_ctrl->value) != 0)
\r
1186 SENSOR_TR("sensor_flip failed, value:0x%x",ext_ctrl->value);
\r
1188 SENSOR_DG("sensor_flip success, value:0x%x",ext_ctrl->value);
\r
1192 * the functions are focus callbacks
\r
1194 static int sensor_focus_init_usr_cb(struct i2c_client *client){
\r
1198 static int sensor_focus_af_single_usr_cb(struct i2c_client *client){
\r
1202 static int sensor_focus_af_near_usr_cb(struct i2c_client *client){
\r
1206 static int sensor_focus_af_far_usr_cb(struct i2c_client *client){
\r
1210 static int sensor_focus_af_specialpos_usr_cb(struct i2c_client *client,int pos){
\r
1214 static int sensor_focus_af_const_usr_cb(struct i2c_client *client){
\r
1217 static int sensor_focus_af_const_pause_usr_cb(struct i2c_client *client)
1221 static int sensor_focus_af_close_usr_cb(struct i2c_client *client){
\r
1225 static int sensor_focus_af_zoneupdate_usr_cb(struct i2c_client *client, int *zone_tm_pos)
\r
1231 face defect call back
\r
1233 static int sensor_face_detect_usr_cb(struct i2c_client *client,int on){
\r
1238 * The function can been run in sensor_init_parametres which run in sensor_probe, so user can do some
\r
1239 * initialization in the function.
\r
1241 static void sensor_init_parameters_user(struct specific_sensor* spsensor,struct soc_camera_device *icd)
\r
1247 * :::::WARNING:::::
\r
1248 * It is not allowed to modify the following code
\r
1251 sensor_init_parameters_default_code();
\r
1253 sensor_v4l2_struct_initialization();
\r
1255 sensor_probe_default_code();
\r
1257 sensor_remove_default_code();
\r
1259 sensor_driver_default_module_code();
\r