1 //#include <linux/gpio.h>
2 #include "generic_sensor.h"
5 *v0.0.1: this driver is compatible with generic_sensor
7 * add sensor_focus_af_const_pause_usr_cb;
9 static int version = KERNEL_VERSION(0,1,1);
10 module_param(version, int, S_IRUGO);
15 module_param(debug, int, S_IRUGO|S_IWUSR);
17 #define dprintk(level, fmt, arg...) do { \
19 printk(KERN_WARNING fmt , ## arg); } while (0)
21 /* Sensor Driver Configuration Begin */
22 #define SENSOR_NAME RK29_CAM_SENSOR_SP0838
23 #define SENSOR_V4L2_IDENT V4L2_IDENT_SP0838
24 #define SENSOR_ID 0x27
25 #define SENSOR_BUS_PARAM (V4L2_MBUS_MASTER |\
26 V4L2_MBUS_PCLK_SAMPLE_RISING|V4L2_MBUS_HSYNC_ACTIVE_HIGH| V4L2_MBUS_VSYNC_ACTIVE_HIGH|\
27 V4L2_MBUS_DATA_ACTIVE_LOW | SOCAM_MCLK_24MHZ)
28 #define SENSOR_PREVIEW_W 640
29 #define SENSOR_PREVIEW_H 480
30 #define SENSOR_PREVIEW_FPS 15000 // 15fps
31 #define SENSOR_FULLRES_L_FPS 7500 // 7.5fps
32 #define SENSOR_FULLRES_H_FPS 7500 // 7.5fps
33 #define SENSOR_720P_FPS 0
34 #define SENSOR_1080P_FPS 0
36 #define SENSOR_REGISTER_LEN 1 // sensor register address bytes
37 #define SENSOR_VALUE_LEN 1 // sensor register value bytes
39 static unsigned int SensorConfiguration = (CFG_WhiteBalance|CFG_Effect|CFG_Scene);
40 static unsigned int SensorChipID[] = {SENSOR_ID};
41 /* Sensor Driver Configuration End */
44 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
45 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
47 #define SensorRegVal(a,b) CONS4(SensorReg,SENSOR_REGISTER_LEN,Val,SENSOR_VALUE_LEN)(a,b)
48 #define sensor_write(client,reg,v) CONS4(sensor_write_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
49 #define sensor_read(client,reg,v) CONS4(sensor_read_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
50 #define sensor_write_array generic_sensor_write_array
52 struct sensor_parameter
54 unsigned int PreviewDummyPixels;
55 unsigned int CaptureDummyPixels;
56 unsigned int preview_exposure;
57 unsigned short int preview_line_width;
58 unsigned short int preview_gain;
60 unsigned short int PreviewPclk;
61 unsigned short int CapturePclk;
65 struct specific_sensor{
66 struct generic_sensor common_sensor;
67 //define user data below
68 struct sensor_parameter parameter;
73 #define SP0838_MIRROR 0
79 * The follow setting need been filled.
82 * sensor_init_data : Sensor initial setting;
83 * sensor_fullres_lowfps_data : Sensor full resolution setting with best auality, recommand for video;
84 * sensor_preview_data : Sensor preview resolution setting, recommand it is vga or svga;
85 * sensor_softreset_data : Sensor software reset register;
86 * sensor_check_id_data : Sensir chip id register;
89 * sensor_fullres_highfps_data: Sensor full resolution setting with high framerate, recommand for video;
90 * sensor_720p: Sensor 720p setting, it is for video;
91 * sensor_1080p: Sensor 1080p setting, it is for video;
94 * The SensorEnd which is the setting end flag must be filled int the last of each setting;
97 /* Sensor initial setting *//* init 640X480 VGA */
98 static struct rk_sensor_reg sensor_init_data[] =
102 #ifdef SP0838_FRONT_DRVCAP
103 {0x1C , 0x03}, //add by sp_yjp,bit2: driver ability set(8mA)
107 {0x30 , 0x02},// 1/2ispclk
109 {0x28 , 0x0b}, // 0x0B pzt 2012-7-26
113 {0x31 , 0x10|(SP0838_FLIP<<6)|(SP0838_MIRROR<<5)},//0x10}, //Upside/mirr/Pclk inv/sub
115 {0x5f , 0x11}, //Bayer order
123 {0x25 , 0x1a}, //Awb start
157 {0x38 , 0x00}, //awb end
159 {0x33 , 0x6f}, //LSC BPC EN // 0x6f pzt 2012-7-26
160 {0x51 , 0x3f}, //BPC debug start
164 {0x55 , 0x10}, //BPC debug end
165 {0x4f , 0xff}, //blueedge
167 {0x57 , 0x10}, //Raw filter debut start
170 {0x56 , 0x71}, //0x70 modify by sp_yjp,20120613
172 {0x5a , 0x06}, //{0x5a , 0x02}, //0x05 modify by sp_yjp,20130709
173 {0x5b , 0x08},// {0x5b , 0x02}, //0x06 modify by sp_yjp,20130709
174 {0x5c , 0x30}, //Raw filter debut end //0x20 modify by sp_yjp,20120613
176 {0x65 , 0x04}, //Sharpness debug start //0x03 modify by sp_yjp,20130709
177 {0x66 , 0x01}, // {0x66 , 0x01},sp_wyq
178 {0x67 , 0x08},// {0x67 , 0x03}, //0x05 //modify by sp_yjp,20120613
179 {0x68 , 0x46},// {0x68 , 0x46},//0x46 zch 20120725
184 {0x6b , 0x04},//{0x6b , 0x04}, //0x06 modify by sp_yjp,20130709
186 {0x6d , 0x06}, //Edge gain normal {0x6d , 0x03}, //0x05 //modify by sp_yjp,20120613
187 {0x6e , 0x46}, //Edge gain normal {0x6e , 0x46}, //0x46 zch 20120725
192 {0x71 , 0x0a}, //����Ã
\96µ//0x09 modify by sp_yjp,20130709
193 {0x72 , 0x01}, //�ï½ï¿½ï¿½ï¿½ï¿½Ã
\96?
194 {0x73 , 0x02}, //? //0x05 //modify by sp_yjp,20120613
195 {0x74 , 0x43}, //ï¿//0x47? //modify by sp_yjp,20120613
198 {0x75 , 0x7f}, //Ã
\8a¹ÿ¿½ÿ¿½Ã
\8e»
199 {0x76 , 0x01}, //Sharpness debug end
200 {0xcb , 0x07}, //HEQ&Saturation debug start
212 {0xdd , 0x70}, //Contrast //0x70 //modify by sp_yjp,20130709
213 {0xde , 0xa0}, //HEQ&Saturation debug end //0x90 //modify by sp_yjp,20130709
216 {0x7f , 0xe1}, //Color Correction start
227 {0x8a , 0x0f}, //Color Correction end
232 {0x7f , 0xee}, //Color Correction start
243 {0x8a , 0x0c}, //Color Correction end
248 {0x7f , 0xf4},//0xed//0xe1 //Color Correction start
249 {0x80 , 0xbc},//0xbc//0xbc
250 {0x81 , 0xd0},//0xd7//0xe3
251 {0x82 , 0xbe},//0xbe//0xd7
252 {0x83 , 0xd5},//0xd5//0xd5
253 {0x84 , 0xee},//0xee//0xd4
254 {0x85 , 0xec},//0xf3//0xff
255 {0x86 , 0xb6},//0xaf//0x89
256 {0x87 , 0xde},//0xdf//0xf8
257 {0x88 , 0x3c},//0x3c//0x3c
258 {0x89 , 0x33},//0x33//0x33
259 {0x8a , 0x0f},//0x0f//0x0f //Color Correction end
263 {0x8b , 0x00}, //gamma start
282 {0x8e , 0xfa}, //gamma end
287 {0xd8 , 0x58}, //UV outdoor
288 {0xd9 , 0x58}, //UV indoor
289 {0xda , 0x50}, //UV dummy //0x48 //modify by sp_yjp,20120613
290 {0xdb , 0x40}, //UV lowlight //0x48 //modify by sp_yjp,20120613
292 {0xd8 , 0x58}, //UV outdoor
293 {0xd9 , 0x58}, //UV indoor
294 {0xda , 0x50}, //UV dummy //0x48 //modify by sp_yjp,20120613
295 {0xdb , 0x50}, //UV lowlight //0x48 //modify by sp_yjp,20120613
298 {0xb9 , 0x00}, //Ygamma start
317 {0x8a , 0xff}, //Ygamma end
319 {0xe8 , 0x30}, //AEdebug start
321 {0xea , 0x40}, //Alc Window sel
322 {0xf4 , 0x1b}, //outdoor mode sel
325 ///{0xf7 , 0x78}, //AE target
327 ///{0xf9 , 0x68}, //AE target
331 {0xf7 , 0x88}, //AE target //modify by sp_yjp,20130709
333 {0xf9 , 0x78}, //AE target
336 {0xf7 , 0x80}, //AE target //modify by sp_yjp,20120613
338 {0xf9 , 0x70}, //AE target
343 {0x09 , 0x31}, //AE Step 3.0
345 {0x0b , 0x0b}, //AE Step 3.0
350 #if 0//24M 1div 50HZ 16-8fps //modify by sp_yjp,20120613
383 {0xc5 , 0x70}, //0x70
385 {0xca , 0x70}, //0x70
388 #else//caprure preview daylight 24M 50hz 20-8FPS maxgain:0x70
429 //caprure preview daylight 24M 50hz 15-10FPS maxgain:0x68
469 #if 0//2/1/2 ISP9-12fps
553 //sensor AE settings:6-11fps
592 //added by yaowei@2013-06-05
601 {0x32 , 0x15}, //Auto_mode set
602 {0x34 , 0x66}, //Isp_mode set
603 {0x35 , 0x40}, //out format
609 /* Senor full resolution setting: recommand for capture */
610 static struct rk_sensor_reg sensor_fullres_lowfps_data[] ={
622 /* Senor full resolution setting: recommand for video */
623 static struct rk_sensor_reg sensor_fullres_highfps_data[] ={
626 /* Preview resolution setting*/
627 static struct rk_sensor_reg sensor_preview_data[] =
641 static struct rk_sensor_reg sensor_720p[]={
646 static struct rk_sensor_reg sensor_1080p[]={
651 static struct rk_sensor_reg sensor_softreset_data[]={
655 static struct rk_sensor_reg sensor_check_id_data[]={
656 SensorRegVal(0x02,0x27),
660 ///=========sp0838-modify by sp_yjp,20120529=================
662 static struct rk_sensor_reg sensor_WhiteB_Auto[]=
664 //sp0838_reg_WB_auto �Զ�
668 {0xfd, 0x00}, // AUTO 3000K~7000K
673 /* Cloudy Colour Temperature : 6500K - 8000K */
674 static struct rk_sensor_reg sensor_WhiteB_Cloudy[]=
676 // sp0838_reg_WB_auto ����
685 /* ClearDay Colour Temperature : 5000K - 6500K */
686 static struct rk_sensor_reg sensor_WhiteB_ClearDay[]=
689 // sp0838_reg_WB_auto ����
698 /* Office Colour Temperature : 3500K - 5000K */
699 static struct rk_sensor_reg sensor_WhiteB_TungstenLamp1[]=
702 //sp0838_reg_WB_auto ӫ����
711 /* Home Colour Temperature : 2500K - 3500K */
712 static struct rk_sensor_reg sensor_WhiteB_TungstenLamp2[]=
715 //sp0838_reg_WB_auto �׳���
724 static struct rk_sensor_reg *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
725 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
728 ///=========sp0838-modify by sp_yjp,20120529=================
729 static struct rk_sensor_reg sensor_Brightness0[]=
738 static struct rk_sensor_reg sensor_Brightness1[]=
747 static struct rk_sensor_reg sensor_Brightness2[]=
756 static struct rk_sensor_reg sensor_Brightness3[]=
765 static struct rk_sensor_reg sensor_Brightness4[]=
774 static struct rk_sensor_reg sensor_Brightness5[]=
782 static struct rk_sensor_reg *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
783 sensor_Brightness4, sensor_Brightness5,NULL,
786 ///=========sp0838-modify by sp_yjp,20120529=================
787 static struct rk_sensor_reg sensor_Effect_Normal[] =
797 static struct rk_sensor_reg sensor_Effect_WandB[] =
807 static struct rk_sensor_reg sensor_Effect_Sepia[] =
817 static struct rk_sensor_reg sensor_Effect_Negative[] =
827 static struct rk_sensor_reg sensor_Effect_Bluish[] =
838 static struct rk_sensor_reg sensor_Effect_Green[] =
848 static struct rk_sensor_reg *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
849 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
852 ///=========sp0838-modify by sp_yjp,20120529=================
853 static struct rk_sensor_reg sensor_Exposure0[]=
861 static struct rk_sensor_reg sensor_Exposure1[]=
869 static struct rk_sensor_reg sensor_Exposure2[]=
877 static struct rk_sensor_reg sensor_Exposure3[]=
885 static struct rk_sensor_reg sensor_Exposure4[]=
893 static struct rk_sensor_reg sensor_Exposure5[]=
901 static struct rk_sensor_reg sensor_Exposure6[]=
909 static struct rk_sensor_reg *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
910 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
913 ///=========sp0838-modify by sp_yjp,20120529=================
914 static struct rk_sensor_reg sensor_Saturation0[]=
919 static struct rk_sensor_reg sensor_Saturation1[]=
924 static struct rk_sensor_reg sensor_Saturation2[]=
928 static struct rk_sensor_reg *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
930 ///=========sp0838-modify by sp_yjp,20120529=================
931 static struct rk_sensor_reg sensor_Contrast0[]=
936 static struct rk_sensor_reg sensor_Contrast1[]=
941 static struct rk_sensor_reg sensor_Contrast2[]=
946 static struct rk_sensor_reg sensor_Contrast3[]=
951 static struct rk_sensor_reg sensor_Contrast4[]=
957 static struct rk_sensor_reg sensor_Contrast5[]=
962 static struct rk_sensor_reg sensor_Contrast6[]=
970 static struct rk_sensor_reg *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
971 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
976 ///=========sp0838-modify by sp_yjp,20120529=================
977 static struct rk_sensor_reg sensor_MirrorOn[]=
979 {0xfd, 0x00}, //page 0
980 {0x31, 0x30}, //bit6:flip bit5:mirror bit4:pclk
985 static struct rk_sensor_reg sensor_MirrorOff[]=
987 {0xfd, 0x00}, //page 0
992 //static struct rk_sensor_reg *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
994 static struct rk_sensor_reg sensor_FlipOn[]=
996 {0xfd, 0x00}, //page 0
1002 static struct rk_sensor_reg sensor_FlipOff[]=
1004 {0xfd, 0x00}, //page 0
1009 //static struct rk_sensor_reg *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1011 ///=========sp0838-modify by sp_yjp,20120529=================
1013 static struct rk_sensor_reg sensor_SceneAuto[] =
1016 //caprure preview daylight 24M 50hz 20-10FPS maxgain:0x70
1143 //sensor AE settings:6-11fps
1187 static struct rk_sensor_reg sensor_SceneNight[] =
1190 //caprure preview night 24M 50hz 20-6FPS maxgain:0x78
1270 //sensor AE settings:6-11fps
1315 static struct rk_sensor_reg *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1317 ///=========sp0838-modify by sp_yjp,20120529=================
1318 static struct rk_sensor_reg sensor_Zoom0[] =
1323 static struct rk_sensor_reg sensor_Zoom1[] =
1328 static struct rk_sensor_reg sensor_Zoom2[] =
1334 static struct rk_sensor_reg sensor_Zoom3[] =
1338 static struct rk_sensor_reg *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1341 ///=========sp0838-modify by sp_yjp,20120529=================
1342 static struct v4l2_querymenu sensor_menus[] =
1346 * User could be add v4l2_queryctrl in sensor_controls by new_user_v4l2ctrl
1348 static struct sensor_v4l2ctrl_usr_s sensor_controls[] =
1352 //MUST define the current used format as the first item
1353 static struct rk_sensor_datafmt sensor_colour_fmts[] = {
1354 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1356 //static struct soc_camera_ops sensor_ops;
1359 **********************************************************
1360 * Following is local code:
1362 * Please codeing your program here
1363 **********************************************************
1367 **********************************************************
1368 * Following is callback
1369 * If necessary, you could coding these callback
1370 **********************************************************
1373 * the function is called in open sensor
1375 static int sensor_activate_cb(struct i2c_client *client)
1378 SENSOR_DG("%s",__FUNCTION__);
1384 * the function is called in close sensor
1386 static int sensor_deactivate_cb(struct i2c_client *client)
1388 //struct generic_sensor *sensor = to_generic_sensor(client);
1390 SENSOR_DG("%s",__FUNCTION__);
1395 * the function is called before sensor register setting in VIDIOC_S_FMT
1397 static int sensor_s_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
1402 * the function is called after sensor register setting finished in VIDIOC_S_FMT
1404 static int sensor_s_fmt_cb_bh (struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
1408 static int sensor_softrest_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
1413 static int sensor_check_id_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
1417 static int sensor_try_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf)
1422 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1424 //struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1427 if (pm_msg.event == PM_EVENT_SUSPEND) {
1428 SENSOR_DG("Suspend");
1431 SENSOR_TR("pm_msg.event(0x%x) != PM_EVENT_SUSPEND\n",pm_msg.event);
1437 static int sensor_resume(struct soc_camera_device *icd)
1440 SENSOR_DG("Resume");
1445 static int sensor_mirror_cb (struct i2c_client *client, int mirror)
1449 SENSOR_DG("mirror: %d",mirror);
1455 * the function is v4l2 control V4L2_CID_HFLIP callback
1457 static int sensor_v4l2ctrl_mirror_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info,
1458 struct v4l2_ext_control *ext_ctrl)
1460 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1462 if (sensor_mirror_cb(client,ext_ctrl->value) != 0)
1463 SENSOR_TR("sensor_mirror failed, value:0x%x",ext_ctrl->value);
1465 SENSOR_DG("sensor_mirror success, value:0x%x",ext_ctrl->value);
1469 static int sensor_flip_cb(struct i2c_client *client, int flip)
1473 SENSOR_DG("flip: %d",flip);
1478 * the function is v4l2 control V4L2_CID_VFLIP callback
1480 static int sensor_v4l2ctrl_flip_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info,
1481 struct v4l2_ext_control *ext_ctrl)
1483 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1485 if (sensor_flip_cb(client,ext_ctrl->value) != 0)
1486 SENSOR_TR("sensor_flip failed, value:0x%x",ext_ctrl->value);
1488 SENSOR_DG("sensor_flip success, value:0x%x",ext_ctrl->value);
1492 * the functions are focus callbacks
1494 static int sensor_focus_init_usr_cb(struct i2c_client *client){
1498 static int sensor_focus_af_single_usr_cb(struct i2c_client *client){
1502 static int sensor_focus_af_near_usr_cb(struct i2c_client *client){
1506 static int sensor_focus_af_far_usr_cb(struct i2c_client *client){
1510 static int sensor_focus_af_specialpos_usr_cb(struct i2c_client *client,int pos){
1514 static int sensor_focus_af_const_usr_cb(struct i2c_client *client){
1517 static int sensor_focus_af_const_pause_usr_cb(struct i2c_client *client)
1521 static int sensor_focus_af_close_usr_cb(struct i2c_client *client){
1525 static int sensor_focus_af_zoneupdate_usr_cb(struct i2c_client *client, int *zone_tm_pos){
1530 face defect call back
1532 static int sensor_face_detect_usr_cb(struct i2c_client *client,int on){
1537 * The function can been run in sensor_init_parametres which run in sensor_probe, so user can do some
1538 * initialization in the function.
1540 static void sensor_init_parameters_user(struct specific_sensor* spsensor,struct soc_camera_device *icd)
1546 #define CHIP_NAME RK29_CAM_SENSOR_NAME_SP0838
1547 #define DBG_DIR "fcam"
1548 #include "./add-cam-inf.c"
1551 * It is not allowed to modify the following code
1554 sensor_init_parameters_default_code();
1556 sensor_v4l2_struct_initialization();
1558 sensor_probe_default_code();
1560 sensor_remove_default_code();
1562 sensor_driver_default_module_code();