3 * Driver for SP2518 CMOS Image Sensor from Superpix
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 * First Version yuanjianping 2012-09-20
13 * Set P0:0x14 = 0x40 zengchaohui 2012-09-20
16 #include <linux/videodev2.h>
17 #include <linux/slab.h>
18 #include <linux/i2c.h>
19 #include <linux/log2.h>
20 #include <linux/platform_device.h>
21 #include <linux/delay.h>
22 #include <linux/circ_buf.h>
23 #include <linux/miscdevice.h>
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-chip-ident.h>
26 #include <media/soc_camera.h>
27 #include <plat/rk_camera.h>
29 module_param(debug, int, S_IRUGO|S_IWUSR);
31 #define dprintk(level, fmt, arg...) do { \
33 printk(KERN_WARNING fmt , ## arg); } while (0)
35 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
36 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
39 #define _CONS(a,b) a##b
40 #define CONS(a,b) _CONS(a,b)
43 #define _STR(x) __STR(x)
44 #define STR(x) _STR(x)
46 #define MIN(x,y) ((x<y) ? x: y)
47 #define MAX(x,y) ((x>y) ? x: y)
49 /* Sensor Driver Configuration */
50 #define SENSOR_NAME RK29_CAM_SENSOR_SP2518
51 #define SENSOR_V4L2_IDENT V4L2_IDENT_SP2518
52 #define SENSOR_ID 0x53
53 #define SENSOR_ID_REG 0x02
54 #define SENSOR_MIN_WIDTH 176//640
55 #define SENSOR_MIN_HEIGHT 144//480
56 #define SENSOR_MAX_WIDTH 1600
57 #define SENSOR_MAX_HEIGHT 1200
58 #define SENSOR_INIT_WIDTH 800 /* Sensor pixel size for sensor_init_data array */
59 #define SENSOR_INIT_HEIGHT 600
60 #define SENSOR_INIT_WINSEQADR sensor_svga
61 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
63 #define CONFIG_SENSOR_WhiteBalance 1
64 #define CONFIG_SENSOR_Brightness 0
65 #define CONFIG_SENSOR_Contrast 0
66 #define CONFIG_SENSOR_Saturation 0
67 #define CONFIG_SENSOR_Effect 1
68 #define CONFIG_SENSOR_Scene 1
69 #define CONFIG_SENSOR_DigitalZoom 0
70 #define CONFIG_SENSOR_Focus 0
71 #define CONFIG_SENSOR_Exposure 0
72 #define CONFIG_SENSOR_Flash 0
73 #define CONFIG_SENSOR_Mirror 0
74 #define CONFIG_SENSOR_Flip 0
76 #define CONFIG_SENSOR_I2C_SPEED 100000 ///250000 /* Hz */
77 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
78 #define CONFIG_SENSOR_I2C_NOSCHED 0
79 #define CONFIG_SENSOR_I2C_RDWRCHK 0
81 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
82 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
83 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
85 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
86 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
87 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
88 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
89 #define COLOR_TEMPERATURE_OFFICE_DN 3500
90 #define COLOR_TEMPERATURE_OFFICE_UP 5000
91 #define COLOR_TEMPERATURE_HOME_DN 2500
92 #define COLOR_TEMPERATURE_HOME_UP 3500
94 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
95 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
97 #define SENSOR_AF_IS_ERR (0x00<<0)
98 #define SENSOR_AF_IS_OK (0x01<<0)
99 #define SENSOR_INIT_IS_ERR (0x00<<28)
100 #define SENSOR_INIT_IS_OK (0x01<<28)
103 #define SP2518_P0_0xf7 0x80//78
105 #define SP2518_P0_0xf8 0x74//6e
107 #define SP2518_P0_0xf9 0x80//74
109 #define SP2518_P0_0xfa 0x74//6a
113 #define SP2518_P0_0xdd 0x80
115 #define SP2518_P0_0xde 0x95
118 #define SP2518_NORMAL_Y0ffset 0x10 //0x0f modify by sp_yjp,20120813
119 #define SP2518_LOWLIGHT_Y0ffset 0x20
130 ///=========SP2518-modify by sp_yjp,20120529=================
131 /* init 640X480 VGA */
132 static struct reginfo sensor_init_data[] =
135 {0x1b,0x1a},//maximum drv ability //0x02 modify by sp_yjp,20120809
142 {0x14,0x40},// 0x20 zch 20120920
152 {0x2c,0x23},//31 Ronlus remove balck dot0x45},
154 {0x2e,0x38},//sxga 0x18
156 {0x31,0x10},//mirror upside down
204 ///SP2518 UXGA 24MEclk 3±¶Æµ 1·ÖƵ 50Hz fix 10fps
239 /*24*3pll 13-13fps 50hz*/
275 {0xca,0x30},//mean dummy2low
276 {0xcb,0x50},//mean low2dummy
277 {0xcc,0xc0},//f8;rpc low
278 {0xcd,0xc0},//rpc dummy
279 {0xd5,0x80},//mean normal2dummy
280 {0xd6,0x90},//mean dummy2normal
320 {0x57,0x08},//raw_dif_thr
325 {0x5a,0xa0},//raw_rb_fac_outdoor
326 {0xc4,0xa0},//60raw_rb_fac_indoor
327 {0x43,0xa0},//40raw_rb_fac_dummy
328 {0xad,0x40},//raw_rb_fac_low
330 {0x4f,0xa0},//raw_gf_fac_outdoor
331 {0xc3,0xa0},//60raw_gf_fac_indoor
332 {0x3f,0xa0},//40raw_gf_fac_dummy
333 {0x42,0x40},//raw_gf_fac_low
336 {0xb6,0x80},//raw_gflt_fac_outdoor
337 {0xb7,0x80},//60raw_gflt_fac_normal
338 {0xb8,0x40},//40raw_gflt_fac_dummy
339 {0xb9,0x20},//raw_gflt_fac_low
342 {0x50,0x0c},//raw_grgb_thr
386 {0x36,0xf0},//f0;d1;e9
388 {0x38,0x9a},//dc;9a;af
494 /*//¹â°ß¹ý¶ÈºÃ
546 {0xdd,SP2518_P0_0xdd},//0x80
547 {0xde,SP2518_P0_0xde},//a0
606 //SP2518_config_window(WINDOW_SIZE_VGA}
672 {0x5d,0x0e}, //vsync delay
673 {0xff,0xff}//The end flag
678 static struct reginfo sensor_uxga[] =
694 {0xff,0xff}//The end flag
699 static struct reginfo sensor_sxga[] =
721 static struct reginfo sensor_svga[] =
745 {0xff,0xff}//The end flag
749 static struct reginfo sensor_vga[] =
776 {0xff,0xff}//The end flag
780 ///=========SP2518-modify by sp_yjp,20120529=================
783 static struct reginfo sensor_cif[] =
785 {0xfd, 0x00},{0xff,0xff}
789 static struct reginfo sensor_qvga[] =
818 {0xff,0xff}//The end flag
822 static struct reginfo sensor_qcif[] =
828 static struct reginfo sensor_ClrFmt_YUYV[]=
834 static struct reginfo sensor_ClrFmt_UYVY[]=
840 ///=========SP2518-modify by sp_yjp,20120529=================
842 #if CONFIG_SENSOR_WhiteBalance
843 static struct reginfo sensor_WhiteB_Auto[]=
853 /* Cloudy Colour Temperature : 6500K - 8000K */
854 static struct reginfo sensor_WhiteB_Cloudy[]=
865 /* ClearDay Colour Temperature : 5000K - 6500K */
866 static struct reginfo sensor_WhiteB_ClearDay[]=
877 /* Office Colour Temperature : 3500K - 5000K */
878 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
890 /* Home Colour Temperature : 2500K - 3500K */
891 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
902 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
903 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
908 ///=========SP2518-modify by sp_yjp,20120529=================
909 #if CONFIG_SENSOR_Brightness
910 static struct reginfo sensor_Brightness0[]=
917 static struct reginfo sensor_Brightness1[]=
924 static struct reginfo sensor_Brightness2[]=
931 static struct reginfo sensor_Brightness3[]=
938 static struct reginfo sensor_Brightness4[]=
945 static struct reginfo sensor_Brightness5[]=
951 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
952 sensor_Brightness4, sensor_Brightness5,NULL,
957 ///=========SP2518-modify by sp_yjp,20120529=================
958 #if CONFIG_SENSOR_Effect
959 static struct reginfo sensor_Effect_Normal[] =
968 static struct reginfo sensor_Effect_WandB[] =
977 static struct reginfo sensor_Effect_Sepia[] =
986 static struct reginfo sensor_Effect_Negative[] =
994 static struct reginfo sensor_Effect_Bluish[] =
1003 static struct reginfo sensor_Effect_Green[] =
1011 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1012 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1016 ///=========SP2518-modify by sp_yjp,20120529=================
1017 #if CONFIG_SENSOR_Exposure
1018 static struct reginfo sensor_Exposure0[]=
1022 {0xed,SP2518_P0_0xf7-0x18+0x04},
1023 {0xf7,SP2518_P0_0xf7-0x18},
1024 {0xf8,SP2518_P0_0xf8-0x18},
1025 {0xec,SP2518_P0_0xf8-0x18-0x04},
1026 {0xef,SP2518_P0_0xf9-0x18+0x04},
1027 {0xf9,SP2518_P0_0xf9-0x18},
1028 {0xfa,SP2518_P0_0xfa-0x18},
1029 {0xee,SP2518_P0_0xfa-0x18-0x04},
1035 static struct reginfo sensor_Exposure1[]=
1039 {0xed,SP2518_P0_0xf7-0x10+0x04},
1040 {0xf7,SP2518_P0_0xf7-0x10},
1041 {0xf8,SP2518_P0_0xf8-0x10},
1042 {0xec,SP2518_P0_0xf8-0x10-0x04},
1043 {0xef,SP2518_P0_0xf9-0x10+0x04},
1044 {0xf9,SP2518_P0_0xf9-0x10},
1045 {0xfa,SP2518_P0_0xfa-0x10},
1046 {0xee,SP2518_P0_0xfa-0x10-0x04},
1052 static struct reginfo sensor_Exposure2[]=
1056 {0xed,SP2518_P0_0xf7-0x08+0x04},
1057 {0xf7,SP2518_P0_0xf7-0x08},
1058 {0xf8,SP2518_P0_0xf8-0x08},
1059 {0xec,SP2518_P0_0xf8-0x08-0x04},
1060 {0xef,SP2518_P0_0xf9-0x08+0x04},
1061 {0xf9,SP2518_P0_0xf9-0x08},
1062 {0xfa,SP2518_P0_0xfa-0x08},
1063 {0xee,SP2518_P0_0xfa-0x08-0x04},
1069 static struct reginfo sensor_Exposure3[]=
1073 {0xed,SP2518_P0_0xf7+0x04},
1074 {0xf7,SP2518_P0_0xf7},
1075 {0xf8,SP2518_P0_0xf8},
1076 {0xec,SP2518_P0_0xf8-0x04},
1077 {0xef,SP2518_P0_0xf9+0x04},
1078 {0xf9,SP2518_P0_0xf9},
1079 {0xfa,SP2518_P0_0xfa},
1080 {0xee,SP2518_P0_0xfa-0x04},
1086 static struct reginfo sensor_Exposure4[]=
1090 {0xed,SP2518_P0_0xf7+0x08+0x04},
1091 {0xf7,SP2518_P0_0xf7+0x08},
1092 {0xf8,SP2518_P0_0xf8+0x08},
1093 {0xec,SP2518_P0_0xf8+0x08-0x04},
1094 {0xef,SP2518_P0_0xf9+0x08+0x04},
1095 {0xf9,SP2518_P0_0xf9+0x08},
1096 {0xfa,SP2518_P0_0xfa+0x08},
1097 {0xee,SP2518_P0_0xfa+0x08-0x04},
1103 static struct reginfo sensor_Exposure5[]=
1107 {0xed,SP2518_P0_0xf7+0x10+0x04},
1108 {0xf7,SP2518_P0_0xf7+0x10},
1109 {0xf8,SP2518_P0_0xf8+0x10},
1110 {0xec,SP2518_P0_0xf8+0x10-0x04},
1111 {0xef,SP2518_P0_0xf9+0x10+0x04},
1112 {0xf9,SP2518_P0_0xf9+0x10},
1113 {0xfa,SP2518_P0_0xfa+0x10},
1114 {0xee,SP2518_P0_0xfa+0x10-0x04},
1120 static struct reginfo sensor_Exposure6[]=
1124 {0xed,SP2518_P0_0xf7+0x18+0x04},
1125 {0xf7,SP2518_P0_0xf7+0x18},
1126 {0xf8,SP2518_P0_0xf8+0x18},
1127 {0xec,SP2518_P0_0xf8+0x18-0x04},
1128 {0xef,SP2518_P0_0xf9+0x18+0x04},
1129 {0xf9,SP2518_P0_0xf9+0x18},
1130 {0xfa,SP2518_P0_0xfa+0x18},
1131 {0xee,SP2518_P0_0xfa+0x18-0x04},
1137 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1138 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1142 ///=========SP2518-modify by sp_yjp,20120529=================
1143 #if CONFIG_SENSOR_Saturation
1144 static struct reginfo sensor_Saturation0[]=
1150 static struct reginfo sensor_Saturation1[]=
1156 static struct reginfo sensor_Saturation2[]=
1161 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1165 ///=========SP2518-modify by sp_yjp,20120529=================
1166 #if CONFIG_SENSOR_Contrast
1167 static struct reginfo sensor_Contrast0[]=
1171 {0xdd , SP2518_P0_0xdd-0x30},
1172 {0xde , SP2518_P0_0xde-0x30},
1176 static struct reginfo sensor_Contrast1[]=
1180 {0xdd , SP2518_P0_0xdd-0x20},
1181 {0xde , SP2518_P0_0xde-0x20},
1185 static struct reginfo sensor_Contrast2[]=
1189 {0xdd , SP2518_P0_0xdd-0x10},
1190 {0xde , SP2518_P0_0xde-0x10},
1194 static struct reginfo sensor_Contrast3[]=
1198 {0xdd , SP2518_P0_0xdd},
1199 {0xde , SP2518_P0_0xde},
1203 static struct reginfo sensor_Contrast4[]=
1207 {0xdd , SP2518_P0_0xdd+0x10},
1208 {0xde , SP2518_P0_0xde+0x10},
1213 static struct reginfo sensor_Contrast5[]=
1217 {0xdd , SP2518_P0_0xdd+0x20},
1218 {0xde , SP2518_P0_0xde+0x20},
1222 static struct reginfo sensor_Contrast6[]=
1226 {0xdd , SP2518_P0_0xdd+0x30},
1227 {0xde , SP2518_P0_0xde+0x30},
1234 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1235 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1241 ///=========SP2518-modify by sp_yjp,20120529=================
1242 #if CONFIG_SENSOR_Mirror
1243 static struct reginfo sensor_MirrorOn[]=
1250 static struct reginfo sensor_MirrorOff[]=
1256 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1258 #if CONFIG_SENSOR_Flip
1259 static struct reginfo sensor_FlipOn[]=
1266 static struct reginfo sensor_FlipOff[]=
1272 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1276 ///=========SP2518-modify by sp_yjp,20120529=================
1277 #if CONFIG_SENSOR_Scene//? zch
1278 static struct reginfo sensor_SceneAuto[] =
1282 {0xb2,SP2518_NORMAL_Y0ffset},
1285 //SP2518 UXGA 24MEclk 3PLL 50Hz fix13fps
1324 static struct reginfo sensor_SceneNight[] =
1328 {0xb2,SP2518_LOWLIGHT_Y0ffset},
1331 //SP2518 UXGA 24MEclk 3PLL 50Hz fix 6fps
1368 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1372 ///=========SP2518-modify by sp_yjp,20120529=================
1373 #if CONFIG_SENSOR_DigitalZoom
1374 static struct reginfo sensor_Zoom0[] =
1380 static struct reginfo sensor_Zoom1[] =
1386 static struct reginfo sensor_Zoom2[] =
1393 static struct reginfo sensor_Zoom3[] =
1398 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1402 ///=========SP2518-modify by sp_yjp,20120529=================
1403 static const struct v4l2_querymenu sensor_menus[] =
1405 #if CONFIG_SENSOR_WhiteBalance
1406 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1407 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1408 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1411 #if CONFIG_SENSOR_Effect
1412 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1413 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1414 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1417 #if CONFIG_SENSOR_Scene
1418 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1421 #if CONFIG_SENSOR_Flash
1422 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1423 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1427 static const struct v4l2_queryctrl sensor_controls[] =
1429 #if CONFIG_SENSOR_WhiteBalance
1431 .id = V4L2_CID_DO_WHITE_BALANCE,
1432 .type = V4L2_CTRL_TYPE_MENU,
1433 .name = "White Balance Control",
1441 #if CONFIG_SENSOR_Brightness
1443 .id = V4L2_CID_BRIGHTNESS,
1444 .type = V4L2_CTRL_TYPE_INTEGER,
1445 .name = "Brightness Control",
1453 #if CONFIG_SENSOR_Effect
1455 .id = V4L2_CID_EFFECT,
1456 .type = V4L2_CTRL_TYPE_MENU,
1457 .name = "Effect Control",
1465 #if CONFIG_SENSOR_Exposure
1467 .id = V4L2_CID_EXPOSURE,
1468 .type = V4L2_CTRL_TYPE_INTEGER,
1469 .name = "Exposure Control",
1477 #if CONFIG_SENSOR_Saturation
1479 .id = V4L2_CID_SATURATION,
1480 .type = V4L2_CTRL_TYPE_INTEGER,
1481 .name = "Saturation Control",
1489 #if CONFIG_SENSOR_Contrast
1491 .id = V4L2_CID_CONTRAST,
1492 .type = V4L2_CTRL_TYPE_INTEGER,
1493 .name = "Contrast Control",
1501 #if CONFIG_SENSOR_Mirror
1503 .id = V4L2_CID_HFLIP,
1504 .type = V4L2_CTRL_TYPE_BOOLEAN,
1505 .name = "Mirror Control",
1513 #if CONFIG_SENSOR_Flip
1515 .id = V4L2_CID_VFLIP,
1516 .type = V4L2_CTRL_TYPE_BOOLEAN,
1517 .name = "Flip Control",
1525 #if CONFIG_SENSOR_Scene
1527 .id = V4L2_CID_SCENE,
1528 .type = V4L2_CTRL_TYPE_MENU,
1529 .name = "Scene Control",
1537 #if CONFIG_SENSOR_DigitalZoom
1539 .id = V4L2_CID_ZOOM_RELATIVE,
1540 .type = V4L2_CTRL_TYPE_INTEGER,
1541 .name = "DigitalZoom Control",
1547 .id = V4L2_CID_ZOOM_ABSOLUTE,
1548 .type = V4L2_CTRL_TYPE_INTEGER,
1549 .name = "DigitalZoom Control",
1557 #if CONFIG_SENSOR_Focus
1559 .id = V4L2_CID_FOCUS_RELATIVE,
1560 .type = V4L2_CTRL_TYPE_INTEGER,
1561 .name = "Focus Control",
1567 .id = V4L2_CID_FOCUS_ABSOLUTE,
1568 .type = V4L2_CTRL_TYPE_INTEGER,
1569 .name = "Focus Control",
1573 .default_value = 125,
1577 #if CONFIG_SENSOR_Flash
1579 .id = V4L2_CID_FLASH,
1580 .type = V4L2_CTRL_TYPE_MENU,
1581 .name = "Flash Control",
1590 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1591 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1592 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1593 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1594 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1595 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1596 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1597 static int sensor_resume(struct soc_camera_device *icd);
1598 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1599 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1600 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1601 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1602 static int sensor_deactivate(struct i2c_client *client);
1604 static struct soc_camera_ops sensor_ops =
1606 .suspend = sensor_suspend,
1607 .resume = sensor_resume,
1608 .set_bus_param = sensor_set_bus_param,
1609 .query_bus_param = sensor_query_bus_param,
1610 .controls = sensor_controls,
1611 .menus = sensor_menus,
1612 .num_controls = ARRAY_SIZE(sensor_controls),
1613 .num_menus = ARRAY_SIZE(sensor_menus),
1616 /* only one fixed colorspace per pixelcode */
1617 struct sensor_datafmt {
1618 enum v4l2_mbus_pixelcode code;
1619 enum v4l2_colorspace colorspace;
1622 /* Find a data format by a pixel code in an array */
1623 static const struct sensor_datafmt *sensor_find_datafmt(
1624 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1628 for (i = 0; i < n; i++)
1629 if (fmt[i].code == code)
1635 static const struct sensor_datafmt sensor_colour_fmts[] = {
1636 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1639 typedef struct sensor_info_priv_s
1653 unsigned char mirror; /* HFLIP */
1654 unsigned char flip; /* VFLIP */
1655 unsigned int winseqe_cur_addr;
1656 struct sensor_datafmt fmt;
1657 unsigned int funmodule_state;
1658 } sensor_info_priv_t;
1662 struct v4l2_subdev subdev;
1663 struct i2c_client *client;
1664 sensor_info_priv_t info_priv;
1665 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1666 #if CONFIG_SENSOR_I2C_NOSCHED
1667 atomic_t tasklock_cnt;
1669 struct rk29camera_platform_data *sensor_io_request;
1670 struct rk29camera_gpio_res *sensor_gpio_res;
1673 static struct sensor* to_sensor(const struct i2c_client *client)
1675 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1678 static int sensor_task_lock(struct i2c_client *client, int lock)
1680 #if CONFIG_SENSOR_I2C_NOSCHED
1682 struct sensor *sensor = to_sensor(client);
1685 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1686 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1687 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1691 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1692 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1693 goto sensor_task_lock_err;
1698 atomic_add(1, &sensor->tasklock_cnt);
1700 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1701 atomic_sub(1, &sensor->tasklock_cnt);
1703 if (atomic_read(&sensor->tasklock_cnt) == 0)
1708 sensor_task_lock_err:
1716 /* sensor register write */
1717 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1721 struct i2c_msg msg[1];
1723 buf[0] = reg & 0xFF;
1726 msg->addr = client->addr;
1727 msg->flags = client->flags;
1729 msg->len = sizeof(buf);
1730 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1731 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1736 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1737 err = i2c_transfer(client->adapter, msg, 1);
1742 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1750 /* sensor register read */
1751 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1756 struct i2c_msg msg[2];
1758 //buf[0] = reg >> 8;
1760 buf[1] = reg & 0xFF;
1762 msg[0].addr = client->addr;
1763 msg[0].flags = client->flags;
1765 msg[0].len = sizeof(buf);
1766 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1767 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1769 msg[1].addr = client->addr;
1770 msg[1].flags = client->flags|I2C_M_RD;
1773 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1774 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1778 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1779 err = i2c_transfer(client->adapter, msg, 2);
1785 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1793 /* write a array of registers */
1795 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1800 //for(i=0; i < sizeof(sensor_init_data) / 2;i++)
1801 while((regarray[i].reg != 0xff) || (regarray[i].val != 0xff))
1803 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1806 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1815 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1820 while (regarray[i].reg != 0)
1822 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1825 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1828 err = sensor_read(client, regarray[i].reg, &val_read);
1829 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1836 #if CONFIG_SENSOR_I2C_RDWRCHK
1837 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
1844 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
1845 for(i=0;i<sizeof(sensor_init_data) / 2;i++)
1847 ret = sensor_read(client,regarray[i].reg,&value);
1850 SENSOR_TR("read value failed\n");
1853 if(regarray[i].val != value)
1855 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
1864 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1866 struct soc_camera_link *icl = to_soc_camera_link(icd);
1869 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1872 case Sensor_PowerDown:
1874 if (icl->powerdown) {
1875 ret = icl->powerdown(icd->pdev, on);
1876 if (ret == RK29_CAM_IO_SUCCESS) {
1878 mdelay(20); // 2 modify by sp_yjp,20120831
1880 icl->reset(icd->pdev);
1881 mdelay(50); // add by sp_yjp,20120831
1883 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1885 goto sensor_power_end;
1892 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1893 struct sensor *sensor = to_sensor(client);
1895 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1896 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1902 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1910 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1912 struct i2c_client *client = v4l2_get_subdevdata(sd);
1913 struct soc_camera_device *icd = client->dev.platform_data;
1914 struct sensor *sensor = to_sensor(client);
1915 const struct v4l2_queryctrl *qctrl;
1916 const struct sensor_datafmt *fmt;
1919 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1921 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1923 goto sensor_INIT_ERR;
1926 if (sensor_ioctrl(icd, Sensor_PowerDown, 1) < 0) {
1928 goto sensor_INIT_ERR;
1931 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1933 goto sensor_INIT_ERR;
1938 if (sensor_task_lock(client,1)<0)
1939 goto sensor_INIT_ERR;
1940 /* ret = sensor_write(client, 0x12, 0x80);
1943 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1945 goto sensor_INIT_ERR;
1948 mdelay(5); */ //delay 5 microseconds
1950 ret = sensor_write_array(client, sensor_init_data);
1953 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1954 goto sensor_INIT_ERR;
1957 sensor_task_lock(client,0);
1959 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1960 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1962 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1964 goto sensor_INIT_ERR;
1966 sensor->info_priv.fmt = *fmt;
1968 /* sensor sensor information for initialization */
1969 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1971 sensor->info_priv.whiteBalance = qctrl->default_value;
1972 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1974 sensor->info_priv.brightness = qctrl->default_value;
1975 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1977 sensor->info_priv.effect = qctrl->default_value;
1978 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1980 sensor->info_priv.exposure = qctrl->default_value;
1982 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1984 sensor->info_priv.saturation = qctrl->default_value;
1985 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1987 sensor->info_priv.contrast = qctrl->default_value;
1988 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1990 sensor->info_priv.mirror = qctrl->default_value;
1991 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1993 sensor->info_priv.flip = qctrl->default_value;
1994 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1996 sensor->info_priv.scene = qctrl->default_value;
1997 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1999 sensor->info_priv.digitalzoom = qctrl->default_value;
2001 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2002 #if CONFIG_SENSOR_Focus
2004 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2006 sensor->info_priv.focus = qctrl->default_value;
2009 #if CONFIG_SENSOR_Flash
2010 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2012 sensor->info_priv.flash = qctrl->default_value;
2015 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);
2016 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2019 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2020 sensor_task_lock(client,0);
2021 sensor_deactivate(client);
2025 static int sensor_deactivate(struct i2c_client *client)
2027 struct soc_camera_device *icd = client->dev.platform_data;
2029 struct sensor *sensor = to_sensor(client);
2030 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2032 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2033 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2036 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2037 icd->user_width = SENSOR_INIT_WIDTH;
2038 icd->user_height = SENSOR_INIT_HEIGHT;
2039 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2043 static struct reginfo sensor_power_down_sequence[]=
2045 {0xfd,0x00},{0xff,0xff}
2047 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2050 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2052 if (pm_msg.event == PM_EVENT_SUSPEND) {
2053 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2054 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2056 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2059 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2061 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2066 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2072 static int sensor_resume(struct soc_camera_device *icd)
2076 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2078 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2082 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2088 static int sensor_set_bus_param(struct soc_camera_device *icd,
2089 unsigned long flags)
2095 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2097 struct soc_camera_link *icl = to_soc_camera_link(icd);
2098 unsigned long flags = SENSOR_BUS_PARAM;
2100 return soc_camera_apply_sensor_flags(icl, flags);
2103 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2105 struct i2c_client *client = v4l2_get_subdevdata(sd);
2106 struct soc_camera_device *icd = client->dev.platform_data;
2107 struct sensor *sensor = to_sensor(client);
2109 mf->width = icd->user_width;
2110 mf->height = icd->user_height;
2111 mf->code = sensor->info_priv.fmt.code;
2112 mf->colorspace = sensor->info_priv.fmt.colorspace;
2113 mf->field = V4L2_FIELD_NONE;
2117 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2121 if ((mf->width == 1024) && (mf->height == 768)) {
2123 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2125 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2127 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2129 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2134 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2138 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2142 if ((mf->width == 1280) && (mf->height == 720)) {
2144 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2149 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2152 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2154 struct i2c_client *client = v4l2_get_subdevdata(sd);
2155 const struct sensor_datafmt *fmt;
2156 struct sensor *sensor = to_sensor(client);
2157 const struct v4l2_queryctrl *qctrl;
2158 struct soc_camera_device *icd = client->dev.platform_data;
2159 struct reginfo *winseqe_set_addr=NULL;
2160 int ret=0, set_w,set_h;
2162 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2163 ARRAY_SIZE(sensor_colour_fmts));
2166 goto sensor_s_fmt_end;
2169 if (sensor->info_priv.fmt.code != mf->code) {
2172 case V4L2_MBUS_FMT_YUYV8_2X8:
2174 winseqe_set_addr = sensor_ClrFmt_YUYV;
2177 case V4L2_MBUS_FMT_UYVY8_2X8:
2179 winseqe_set_addr = sensor_ClrFmt_UYVY;
2185 if (winseqe_set_addr != NULL) {
2186 sensor_write_array(client, winseqe_set_addr);
2187 sensor->info_priv.fmt.code = mf->code;
2188 sensor->info_priv.fmt.colorspace= mf->colorspace;
2189 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2191 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2198 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=0xff))
2200 winseqe_set_addr = sensor_qcif;
2204 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=0xff))
2206 winseqe_set_addr = sensor_qvga;
2210 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=0xff))
2212 winseqe_set_addr = sensor_cif;
2216 else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=0xff))
2218 winseqe_set_addr = sensor_vga;
2222 else if (((set_w <= 800) && (set_h <= 600)))
2224 if (sensor_svga[0].reg!=0xff) {
2225 winseqe_set_addr = sensor_svga;
2228 } else if (sensor_vga[0].reg!=0xff) {
2229 winseqe_set_addr = sensor_vga;
2232 } else if (sensor_uxga[0].reg!=0xff) {
2233 winseqe_set_addr = sensor_uxga;
2238 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=0xff))
2240 winseqe_set_addr = sensor_sxga;
2244 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=0xff))
2246 winseqe_set_addr = sensor_uxga;
2252 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2253 set_w = SENSOR_INIT_WIDTH;
2254 set_h = SENSOR_INIT_HEIGHT;
2255 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2257 printk("%s(%d): %dx%d -> %dx%d\n",__FUNCTION__,__LINE__, mf->width,mf->height,set_w,set_h);
2259 printk("win: %p %p %p %p %p %p\n",winseqe_set_addr,sensor->info_priv.winseqe_cur_addr,
2260 sensor_uxga,sensor_svga,sensor_vga,sensor_sxga);
2263 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2264 #if CONFIG_SENSOR_Flash
2265 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2266 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2267 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2268 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2270 } else { /* ddl@rock-chips.com : Video */
2271 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2272 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2273 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2277 ret |= sensor_write_array(client, winseqe_set_addr);
2279 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2280 #if CONFIG_SENSOR_Flash
2281 if (sensor_fmt_capturechk(sd,mf) == true) {
2282 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2283 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2284 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2288 goto sensor_s_fmt_end;
2291 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2293 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2294 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2295 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2296 if (sensor->info_priv.whiteBalance != 0) {
2297 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2298 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2300 sensor->info_priv.snap2preview = true;
2301 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2302 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2303 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2304 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2305 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2306 sensor->info_priv.video2preview = true;
2307 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2308 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2309 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2310 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2311 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2313 sensor->info_priv.video2preview = false;
2314 sensor->info_priv.snap2preview = false;
2317 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2321 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2331 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2333 struct i2c_client *client = v4l2_get_subdevdata(sd);
2334 struct sensor *sensor = to_sensor(client);
2335 const struct sensor_datafmt *fmt;
2336 int ret = 0,set_w,set_h;
2338 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2339 ARRAY_SIZE(sensor_colour_fmts));
2341 fmt = &sensor->info_priv.fmt;
2342 mf->code = fmt->code;
2345 if (mf->height > SENSOR_MAX_HEIGHT)
2346 mf->height = SENSOR_MAX_HEIGHT;
2347 else if (mf->height < SENSOR_MIN_HEIGHT)
2348 mf->height = SENSOR_MIN_HEIGHT;
2350 if (mf->width > SENSOR_MAX_WIDTH)
2351 mf->width = SENSOR_MAX_WIDTH;
2352 else if (mf->width < SENSOR_MIN_WIDTH)
2353 mf->width = SENSOR_MIN_WIDTH;
2356 if ((mf->width == 320) && (mf->height == 240)) {
2357 printk("%s(%d): qvga ERROR\n",__FUNCTION__,__LINE__);
2363 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=0xff))
2368 else if (((set_w == 320) && (set_h == 240)))// && (sensor_qvga[0].reg!=0xff))
2374 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=0xff))
2379 else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=0xff))
2384 else if (((set_w <= 800) && (set_h <= 600)))
2386 if (sensor_svga[0].reg!=0xff) {
2389 } else if (sensor_vga[0].reg!=0xff) {
2392 } else if (sensor_uxga[0].reg!=0xff) {
2397 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=0xff))
2402 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=0xff))
2409 set_w = SENSOR_INIT_WIDTH;
2410 set_h = SENSOR_INIT_HEIGHT;
2416 mf->colorspace = fmt->colorspace;
2421 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2423 struct i2c_client *client = v4l2_get_subdevdata(sd);
2425 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2428 if (id->match.addr != client->addr)
2431 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
2436 #if CONFIG_SENSOR_Brightness
2437 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2439 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2441 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2443 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2445 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2447 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2450 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2454 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2458 #if CONFIG_SENSOR_Effect
2459 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2461 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2463 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2465 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2467 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2469 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2472 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2476 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2480 #if CONFIG_SENSOR_Exposure
2481 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2483 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2485 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2487 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2489 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2491 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2494 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2498 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2502 #if CONFIG_SENSOR_Saturation
2503 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2505 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2507 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2509 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2511 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2513 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2516 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2520 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2524 #if CONFIG_SENSOR_Contrast
2525 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2527 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2529 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2531 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2533 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2535 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2538 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2542 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2546 #if CONFIG_SENSOR_Mirror
2547 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2549 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2551 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2553 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2555 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2557 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2560 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2564 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2568 #if CONFIG_SENSOR_Flip
2569 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2571 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2573 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2575 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2577 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2579 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2582 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2586 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2590 #if CONFIG_SENSOR_Scene
2591 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2593 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2595 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2597 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2599 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2601 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2604 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2608 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2612 #if CONFIG_SENSOR_WhiteBalance
2613 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2615 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2617 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2619 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2621 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2623 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2626 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2630 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2634 #if CONFIG_SENSOR_DigitalZoom
2635 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2637 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2638 struct sensor *sensor = to_sensor(client);
2639 const struct v4l2_queryctrl *qctrl_info;
2640 int digitalzoom_cur, digitalzoom_total;
2642 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2646 digitalzoom_cur = sensor->info_priv.digitalzoom;
2647 digitalzoom_total = qctrl_info->maximum;
2649 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2651 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2655 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2657 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2661 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2663 *value = digitalzoom_total - digitalzoom_cur;
2666 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2668 *value = 0 - digitalzoom_cur;
2671 digitalzoom_cur += *value;
2673 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2675 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2677 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2680 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2687 #if CONFIG_SENSOR_Flash
2688 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2690 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2691 if (value == 3) { /* ddl@rock-chips.com: torch */
2692 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2694 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2696 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2700 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2705 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2707 struct i2c_client *client = v4l2_get_subdevdata(sd);
2708 struct sensor *sensor = to_sensor(client);
2709 const struct v4l2_queryctrl *qctrl;
2711 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2715 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2721 case V4L2_CID_BRIGHTNESS:
2723 ctrl->value = sensor->info_priv.brightness;
2726 case V4L2_CID_SATURATION:
2728 ctrl->value = sensor->info_priv.saturation;
2731 case V4L2_CID_CONTRAST:
2733 ctrl->value = sensor->info_priv.contrast;
2736 case V4L2_CID_DO_WHITE_BALANCE:
2738 ctrl->value = sensor->info_priv.whiteBalance;
2741 case V4L2_CID_EXPOSURE:
2743 ctrl->value = sensor->info_priv.exposure;
2746 case V4L2_CID_HFLIP:
2748 ctrl->value = sensor->info_priv.mirror;
2751 case V4L2_CID_VFLIP:
2753 ctrl->value = sensor->info_priv.flip;
2764 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2766 struct i2c_client *client = v4l2_get_subdevdata(sd);
2767 struct sensor *sensor = to_sensor(client);
2768 struct soc_camera_device *icd = client->dev.platform_data;
2769 const struct v4l2_queryctrl *qctrl;
2772 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2776 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2782 #if CONFIG_SENSOR_Brightness
2783 case V4L2_CID_BRIGHTNESS:
2785 if (ctrl->value != sensor->info_priv.brightness)
2787 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2791 sensor->info_priv.brightness = ctrl->value;
2796 #if CONFIG_SENSOR_Exposure
2797 case V4L2_CID_EXPOSURE:
2799 if (ctrl->value != sensor->info_priv.exposure)
2801 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2805 sensor->info_priv.exposure = ctrl->value;
2810 #if CONFIG_SENSOR_Saturation
2811 case V4L2_CID_SATURATION:
2813 if (ctrl->value != sensor->info_priv.saturation)
2815 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2819 sensor->info_priv.saturation = ctrl->value;
2824 #if CONFIG_SENSOR_Contrast
2825 case V4L2_CID_CONTRAST:
2827 if (ctrl->value != sensor->info_priv.contrast)
2829 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2833 sensor->info_priv.contrast = ctrl->value;
2838 #if CONFIG_SENSOR_WhiteBalance
2839 case V4L2_CID_DO_WHITE_BALANCE:
2841 if (ctrl->value != sensor->info_priv.whiteBalance)
2843 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2847 sensor->info_priv.whiteBalance = ctrl->value;
2852 #if CONFIG_SENSOR_Mirror
2853 case V4L2_CID_HFLIP:
2855 if (ctrl->value != sensor->info_priv.mirror)
2857 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2859 sensor->info_priv.mirror = ctrl->value;
2864 #if CONFIG_SENSOR_Flip
2865 case V4L2_CID_VFLIP:
2867 if (ctrl->value != sensor->info_priv.flip)
2869 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2871 sensor->info_priv.flip = ctrl->value;
2882 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2884 const struct v4l2_queryctrl *qctrl;
2885 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2886 struct sensor *sensor = to_sensor(client);
2888 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2892 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2896 switch (ext_ctrl->id)
2898 case V4L2_CID_SCENE:
2900 ext_ctrl->value = sensor->info_priv.scene;
2903 case V4L2_CID_EFFECT:
2905 ext_ctrl->value = sensor->info_priv.effect;
2908 case V4L2_CID_ZOOM_ABSOLUTE:
2910 ext_ctrl->value = sensor->info_priv.digitalzoom;
2913 case V4L2_CID_ZOOM_RELATIVE:
2917 case V4L2_CID_FOCUS_ABSOLUTE:
2919 ext_ctrl->value = sensor->info_priv.focus;
2922 case V4L2_CID_FOCUS_RELATIVE:
2926 case V4L2_CID_FLASH:
2928 ext_ctrl->value = sensor->info_priv.flash;
2936 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2938 const struct v4l2_queryctrl *qctrl;
2939 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2940 struct sensor *sensor = to_sensor(client);
2943 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2947 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2952 switch (ext_ctrl->id)
2954 #if CONFIG_SENSOR_Scene
2955 case V4L2_CID_SCENE:
2957 if (ext_ctrl->value != sensor->info_priv.scene)
2959 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2961 sensor->info_priv.scene = ext_ctrl->value;
2966 #if CONFIG_SENSOR_Effect
2967 case V4L2_CID_EFFECT:
2969 if (ext_ctrl->value != sensor->info_priv.effect)
2971 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2973 sensor->info_priv.effect= ext_ctrl->value;
2978 #if CONFIG_SENSOR_DigitalZoom
2979 case V4L2_CID_ZOOM_ABSOLUTE:
2981 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2984 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2986 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2988 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2990 sensor->info_priv.digitalzoom += val_offset;
2992 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2997 case V4L2_CID_ZOOM_RELATIVE:
2999 if (ext_ctrl->value)
3001 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3003 sensor->info_priv.digitalzoom += ext_ctrl->value;
3005 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3010 #if CONFIG_SENSOR_Focus
3011 case V4L2_CID_FOCUS_ABSOLUTE:
3013 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3016 if (ext_ctrl->value != sensor->info_priv.focus)
3018 val_offset = ext_ctrl->value -sensor->info_priv.focus;
3020 sensor->info_priv.focus += val_offset;
3025 case V4L2_CID_FOCUS_RELATIVE:
3027 if (ext_ctrl->value)
3029 sensor->info_priv.focus += ext_ctrl->value;
3031 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
3036 #if CONFIG_SENSOR_Flash
3037 case V4L2_CID_FLASH:
3039 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3041 sensor->info_priv.flash = ext_ctrl->value;
3043 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3054 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3056 struct i2c_client *client = v4l2_get_subdevdata(sd);
3057 struct soc_camera_device *icd = client->dev.platform_data;
3058 int i, error_cnt=0, error_idx=-1;
3061 for (i=0; i<ext_ctrl->count; i++) {
3062 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3069 error_idx = ext_ctrl->count;
3071 if (error_idx != -1) {
3072 ext_ctrl->error_idx = error_idx;
3079 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3081 struct i2c_client *client = v4l2_get_subdevdata(sd);
3082 struct soc_camera_device *icd = client->dev.platform_data;
3083 int i, error_cnt=0, error_idx=-1;
3086 for (i=0; i<ext_ctrl->count; i++) {
3087 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3094 error_idx = ext_ctrl->count;
3096 if (error_idx != -1) {
3097 ext_ctrl->error_idx = error_idx;
3104 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3105 * this wasn't our capture interface, so, we wait for the right one */
3106 static int sensor_video_probe(struct soc_camera_device *icd,
3107 struct i2c_client *client)
3111 struct sensor *sensor = to_sensor(client);
3113 /* We must have a parent by now. And it cannot be a wrong one.
3114 * So this entire test is completely redundant. */
3115 if (!icd->dev.parent ||
3116 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3119 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3121 goto sensor_video_probe_err;
3124 if (sensor_ioctrl(icd, Sensor_PowerDown, 1) < 0) {
3126 goto sensor_video_probe_err;
3129 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3131 goto sensor_video_probe_err;
3135 /* check if it is an sensor sensor */
3136 ////////ret = sensor_read(client, 0x00, &pid);
3137 ret = sensor_read(client, SENSOR_ID_REG, &pid);
3139 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
3141 goto sensor_video_probe_err;
3144 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3146 if (pid == SENSOR_ID) {
3147 sensor->model = SENSOR_V4L2_IDENT;
3149 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3151 goto sensor_video_probe_err;
3154 sensor->model = SENSOR_V4L2_IDENT;
3159 sensor_video_probe_err:
3164 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3166 struct i2c_client *client = v4l2_get_subdevdata(sd);
3167 struct soc_camera_device *icd = client->dev.platform_data;
3168 struct sensor *sensor = to_sensor(client);
3174 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3177 case RK29_CAM_SUBDEV_DEACTIVATE:
3179 sensor_deactivate(client);
3183 case RK29_CAM_SUBDEV_IOREQUEST:
3185 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3186 if (sensor->sensor_io_request != NULL) {
3187 sensor->sensor_gpio_res = NULL;
3188 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
3189 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
3190 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
3191 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
3194 if (sensor->sensor_gpio_res == NULL) {
3195 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
3197 goto sensor_ioctl_end;
3200 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3202 goto sensor_ioctl_end;
3204 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3206 #if CONFIG_SENSOR_Flash
3207 if (sensor->sensor_gpio_res) {
3208 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3209 for (i = 0; i < icd->ops->num_controls; i++) {
3210 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3211 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3214 sensor->info_priv.flash = 0xff;
3215 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3223 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3231 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3232 enum v4l2_mbus_pixelcode *code)
3234 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3237 *code = sensor_colour_fmts[index].code;
3240 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3241 .init = sensor_init,
3242 .g_ctrl = sensor_g_control,
3243 .s_ctrl = sensor_s_control,
3244 .g_ext_ctrls = sensor_g_ext_controls,
3245 .s_ext_ctrls = sensor_s_ext_controls,
3246 .g_chip_ident = sensor_g_chip_ident,
3247 .ioctl = sensor_ioctl,
3250 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3251 .s_mbus_fmt = sensor_s_fmt,
3252 .g_mbus_fmt = sensor_g_fmt,
3253 .try_mbus_fmt = sensor_try_fmt,
3254 .enum_mbus_fmt = sensor_enum_fmt,
3257 static struct v4l2_subdev_ops sensor_subdev_ops = {
3258 .core = &sensor_subdev_core_ops,
3259 .video = &sensor_subdev_video_ops,
3262 static int sensor_probe(struct i2c_client *client,
3263 const struct i2c_device_id *did)
3265 struct sensor *sensor;
3266 struct soc_camera_device *icd = client->dev.platform_data;
3267 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3268 struct soc_camera_link *icl;
3271 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3273 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3277 icl = to_soc_camera_link(icd);
3279 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3283 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3284 dev_warn(&adapter->dev,
3285 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3289 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3293 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3295 /* Second stage probe - when a capture adapter is there */
3296 icd->ops = &sensor_ops;
3298 sensor->info_priv.fmt = sensor_colour_fmts[0];
3300 #if CONFIG_SENSOR_I2C_NOSCHED
3301 atomic_set(&sensor->tasklock_cnt,0);
3304 ret = sensor_video_probe(icd, client);
3307 i2c_set_clientdata(client, NULL);
3311 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3315 static int sensor_remove(struct i2c_client *client)
3317 struct sensor *sensor = to_sensor(client);
3318 struct soc_camera_device *icd = client->dev.platform_data;
3321 i2c_set_clientdata(client, NULL);
3322 client->driver = NULL;
3328 static const struct i2c_device_id sensor_id[] = {
3329 {SENSOR_NAME_STRING(), 0 },
3332 MODULE_DEVICE_TABLE(i2c, sensor_id);
3334 static struct i2c_driver sensor_i2c_driver = {
3336 .name = SENSOR_NAME_STRING(),
3338 .probe = sensor_probe,
3339 .remove = sensor_remove,
3340 .id_table = sensor_id,
3343 static int __init sensor_mod_init(void)
3345 printk("\n*****************%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3346 #ifdef CONFIG_SOC_CAMERA_FCAM
3349 return i2c_add_driver(&sensor_i2c_driver);
3353 static void __exit sensor_mod_exit(void)
3355 i2c_del_driver(&sensor_i2c_driver);
3358 device_initcall_sync(sensor_mod_init);
3359 module_exit(sensor_mod_exit);
3361 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3362 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3363 MODULE_LICENSE("GPL");
3365 struct cam_sensor_info cam_sensor_info_SP2518={
3385 EXPORT_SYMBOL_GPL(cam_sensor_info_SP2518);