1 #include <linux/videodev2.h>
\r
2 #include <linux/slab.h>
\r
3 #include <linux/i2c.h>
\r
4 #include <linux/log2.h>
\r
5 #include <linux/platform_device.h>
\r
6 #include <linux/delay.h>
\r
7 #include <linux/circ_buf.h>
\r
8 #include <linux/miscdevice.h>
\r
9 #include <media/v4l2-common.h>
\r
10 #include <media/v4l2-chip-ident.h>
\r
11 #include <media/soc_camera.h>
\r
12 #include <plat/rk_camera.h>
\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 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
\r
22 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
\r
25 #define _CONS(a,b) a##b
\r
26 #define CONS(a,b) _CONS(a,b)
\r
29 #define _STR(x) __STR(x)
\r
30 #define STR(x) _STR(x)
\r
32 #define MIN(x,y) ((x<y) ? x: y)
\r
33 #define MAX(x,y) ((x>y) ? x: y)
\r
35 /* Sensor Driver Configuration */
\r
36 #define SENSOR_NAME RK29_CAM_SENSOR_OV2640
\r
37 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2640
\r
38 #define SENSOR_ID 0x2642
\r
39 #define SENSOR_ID1 0x2641
\r
40 #define SENSOR_MIN_WIDTH 640
\r
41 #define SENSOR_MIN_HEIGHT 480
\r
42 #define SENSOR_MAX_WIDTH 1600
\r
43 #define SENSOR_MAX_HEIGHT 1200
\r
44 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
\r
45 #define SENSOR_INIT_HEIGHT 480
\r
46 #define SENSOR_INIT_WINSEQADR sensor_vga
\r
47 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
\r
49 #define CONFIG_SENSOR_WhiteBalance 1
\r
50 #define CONFIG_SENSOR_Brightness 0
\r
51 #define CONFIG_SENSOR_Contrast 0
\r
52 #define CONFIG_SENSOR_Saturation 0
\r
53 #define CONFIG_SENSOR_Effect 0
\r
54 #define CONFIG_SENSOR_Scene 0
\r
55 #define CONFIG_SENSOR_DigitalZoom 0
\r
56 #define CONFIG_SENSOR_Focus 0
\r
57 #define CONFIG_SENSOR_Exposure 0
\r
58 #define CONFIG_SENSOR_Flash 1
\r
59 #define CONFIG_SENSOR_Mirror 0
\r
60 #define CONFIG_SENSOR_Flip 0
\r
62 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
\r
63 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
\r
64 #define CONFIG_SENSOR_I2C_NOSCHED 0
\r
65 #define CONFIG_SENSOR_I2C_RDWRCHK 0
\r
67 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
\r
68 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
\r
69 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
\r
71 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
\r
72 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
\r
73 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
\r
74 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
\r
75 #define COLOR_TEMPERATURE_OFFICE_DN 3500
\r
76 #define COLOR_TEMPERATURE_OFFICE_UP 5000
\r
77 #define COLOR_TEMPERATURE_HOME_DN 2500
\r
78 #define COLOR_TEMPERATURE_HOME_UP 3500
\r
80 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
\r
81 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
\r
83 #define SENSOR_AF_IS_ERR (0x00<<0)
\r
84 #define SENSOR_AF_IS_OK (0x01<<0)
\r
85 #define SENSOR_INIT_IS_ERR (0x00<<28)
\r
86 #define SENSOR_INIT_IS_OK (0x01<<28)
\r
93 //flash off in fixed time to prevent from too hot , zyc
\r
95 struct soc_camera_device *icd;
\r
96 struct hrtimer timer;
\r
98 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
\r
100 static struct flash_timer flash_off_timer;
\r
101 //for user defined if user want to customize the series , zyc
\r
102 #ifdef CONFIG_OV2640_USER_DEFINED_SERIES
\r
103 #include "ov2640_user_series.c"
\r
105 /* init 800*600 SVGA */
\r
106 static struct reginfo sensor_init_data[] =
\r
116 {0x03,0x4f},// 0x8f peak
\r
123 {0x04,0x28},//b7,b6 directs
\r
125 {0x14,0x28}, //0x48 peak
\r
196 //{0xff,0x00}, //added by peak on 20120409
\r
198 {0x7d,0x02},//0x00 peak//0x07,È·±£ÔÚ±ðµÄÎļþÀïû±»¸²¸Ç
\r
200 {0x7d,0x28},//0x48//0x40 Õâ¸öÖµÒѾºÜСÁË,³ý·ÇÄãÔÚ±ðµÄÎļþÀïÓÖдÁË
\r
201 {0x7d,0x28},//0x48 peak//0x40 Õâ¸öÖµÒѾºÜСÁË,³ý·ÇÄãÔÚ±ðµÄÎļþÀïÓÖдÁË
\r
203 // removed by peak on 20120409
\r
210 //contrast added by peak on 20120409
\r
212 //{0x7d,0x04},//0x48//0x40
\r
213 //{0x7c,0x07},//0x48 peak//0x40
\r
216 //{0x7d,0x0c},//0x10
\r
217 //{0x7d,0x06},//0x0e
\r
219 //{0xff, 0x01},// added by peak on 20120409
\r
319 {0x5d, 0x55},//0x00
\r
320 //{0x5e, 0x7d},//0x3c
\r
321 //{0x5f, 0x7d},//0x28
\r
322 //{0x60, 0x55},//0x55
\r
323 {0x5e, 0x55},//0x3c
\r
324 {0x5f, 0x55},//0x28
\r
325 {0x60, 0x55},//0x55
\r
355 {0x93,0x06}, //0x06 peak
\r
402 {0x0, 0x0} //end flag
\r
406 /* 1600X1200 UXGA */
\r
407 static struct reginfo sensor_uxga[] =
\r
426 {0x0, 0x0} //end flag
\r
429 /* 1280X1024 SXGA */
\r
430 static struct reginfo sensor_sxga[] =
\r
449 {0x0, 0x0} //end flag
\r
453 static struct reginfo sensor_xga[] =
\r
472 {0x0, 0x0} //end flag
\r
479 static struct reginfo sensor_svga[] =
\r
481 {0x0, 0x0} //end flag
\r
485 static struct reginfo sensor_vga[] =
\r
487 {0x0, 0x0} //end flag
\r
491 static struct reginfo sensor_cif[] =
\r
493 {0x0, 0x0} //end flag
\r
497 static struct reginfo sensor_qvga[] =
\r
499 {0x0, 0x0} //end flag
\r
503 static struct reginfo sensor_qcif[] =
\r
505 {0x0, 0x0} //end flag
\r
511 static struct reginfo ov2655_qqvga[] =
\r
555 static struct reginfo ov2655_Sharpness_auto[] =
\r
560 static struct reginfo ov2655_Sharpness1[] =
\r
566 static struct reginfo ov2655_Sharpness2[][3] =
\r
573 static struct reginfo ov2655_Sharpness3[] =
\r
579 static struct reginfo ov2655_Sharpness4[]=
\r
586 static struct reginfo ov2655_Sharpness5[] =
\r
594 static struct reginfo sensor_ClrFmt_YUYV[]=
\r
600 static struct reginfo sensor_ClrFmt_UYVY[]=
\r
606 #if CONFIG_SENSOR_WhiteBalance
\r
607 static struct reginfo sensor_WhiteB_Auto[]=
\r
610 {0xff, 0x00}, //AWB auto, bit[1]:0,auto
\r
614 /* Cloudy Colour Temperature : 6500K - 8000K */
\r
615 static struct reginfo sensor_WhiteB_Cloudy[]=
\r
624 /* ClearDay Colour Temperature : 5000K - 6500K */
\r
625 static struct reginfo sensor_WhiteB_ClearDay[]=
\r
636 /* Office Colour Temperature : 3500K - 5000K */
\r
637 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
\r
647 /* Home Colour Temperature : 2500K - 3500K */
\r
648 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
\r
658 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_ClearDay,sensor_WhiteB_Cloudy,sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
\r
663 #if CONFIG_SENSOR_Brightness
\r
664 static struct reginfo sensor_Brightness0[]=
\r
671 {0x0, 0x0} //end flag
\r
674 static struct reginfo sensor_Brightness1[]=
\r
682 {0x0, 0x0} //end flag
\r
685 static struct reginfo sensor_Brightness2[]=
\r
693 {0x0, 0x0} //end flag
\r
696 static struct reginfo sensor_Brightness3[]=
\r
704 {0x0, 0x0} //end flag
\r
707 static struct reginfo sensor_Brightness4[]=
\r
715 {0x0, 0x0} //end flag
\r
718 static struct reginfo sensor_Brightness5[]=
\r
725 {0x0, 0x0} //end flag
\r
727 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
\r
728 sensor_Brightness4, sensor_Brightness5,NULL,
\r
733 #if CONFIG_SENSOR_Effect
\r
734 static struct reginfo sensor_Effect_Normal[] =
\r
742 {0x0, 0x0} //end flag
\r
745 static struct reginfo sensor_Effect_WandB[] =
\r
753 {0x0, 0x0} //end flag
\r
756 static struct reginfo sensor_Effect_Sepia[] =
\r
764 {0x0, 0x0} //end flag
\r
767 static struct reginfo sensor_Effect_Negative[] =
\r
775 {0x0, 0x0} //end flag
\r
777 static struct reginfo sensor_Effect_Bluish[] =
\r
785 {0x0, 0x0} //end flag
\r
788 static struct reginfo sensor_Effect_Green[] =
\r
796 {0x0, 0x0} //end flag
\r
799 static struct reginfo sensor_Effect_Exp_Windows_Half[] =
\r
806 {0x0, 0x0} //end flag
\r
808 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
\r
809 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
\r
812 #if CONFIG_SENSOR_Exposure
\r
813 static struct reginfo sensor_Exposure0[]=
\r
818 static struct reginfo sensor_Exposure1[]=
\r
823 static struct reginfo sensor_Exposure2[]=
\r
828 static struct reginfo sensor_Exposure3[]=
\r
833 static struct reginfo sensor_Exposure4[]=
\r
838 static struct reginfo sensor_Exposure5[]=
\r
843 static struct reginfo sensor_Exposure6[]=
\r
848 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
\r
849 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
\r
852 #if CONFIG_SENSOR_Saturation
\r
853 static struct reginfo sensor_Saturation0[]=
\r
873 {0x0, 0x0} //end flag
\r
876 static struct reginfo sensor_Saturation1[]=
\r
896 {0x0, 0x0} //end flag
\r
899 static struct reginfo sensor_Saturation2[]=
\r
919 {0x0, 0x0} //end flag
\r
921 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
\r
925 #if CONFIG_SENSOR_Contrast
\r
926 static struct reginfo sensor_Contrast0[]=
\r
936 {0x0, 0x0} //end flag
\r
940 static struct reginfo sensor_Contrast1[]=
\r
950 {0x0, 0x0} //end flag
\r
953 static struct reginfo sensor_Contrast2[]=
\r
963 {0x0, 0x0} //end flag
\r
966 static struct reginfo sensor_Contrast3[]=
\r
976 {0x0, 0x0} //end flag
\r
979 static struct reginfo sensor_Contrast4[]=
\r
989 {0x0, 0x0} //end flag
\r
993 static struct reginfo sensor_Contrast5[]=
\r
1003 {0x0, 0x0} //end flag
\r
1006 static struct reginfo sensor_Contrast6[]=
\r
1016 {0x0, 0x0} //end flag
\r
1020 static struct reginfo sensor_Contrast7[]=
\r
1030 {0x0, 0x0} //end flag
\r
1033 static struct reginfo sensor_Contrast8[]=
\r
1043 {0x0, 0x0} //end flag
\r
1046 static struct reginfo sensor_Contrast9[]=
\r
1056 {0x0, 0x0} //end flag
\r
1061 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
\r
1062 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
\r
1066 #if CONFIG_SENSOR_Mirror
\r
1067 static struct reginfo sensor_MirrorOn[]=
\r
1072 static struct reginfo sensor_MirrorOff[]=
\r
1076 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
\r
1078 #if CONFIG_SENSOR_Flip
\r
1079 static struct reginfo sensor_FlipOn[]=
\r
1084 static struct reginfo sensor_FlipOff[]=
\r
1088 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
\r
1091 #if CONFIG_SENSOR_Scene
\r
1092 static struct reginfo sensor_SceneAuto[] =
\r
1100 static struct reginfo sensor_SceneNight[] =
\r
1122 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
\r
1125 #if CONFIG_SENSOR_DigitalZoom
\r
1126 static struct reginfo sensor_Zoom0[] =
\r
1131 static struct reginfo sensor_Zoom1[] =
\r
1136 static struct reginfo sensor_Zoom2[] =
\r
1142 static struct reginfo sensor_Zoom3[] =
\r
1146 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
\r
1148 static const struct v4l2_querymenu sensor_menus[] =
\r
1150 #if CONFIG_SENSOR_WhiteBalance
\r
1151 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
\r
1152 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
\r
1153 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
\r
1156 #if CONFIG_SENSOR_Effect
\r
1157 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
\r
1158 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
\r
1159 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
\r
1162 #if CONFIG_SENSOR_Scene
\r
1163 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
\r
1166 #if CONFIG_SENSOR_Flash
\r
1167 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
\r
1168 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
\r
1172 static struct v4l2_queryctrl sensor_controls[] =
\r
1174 #if CONFIG_SENSOR_WhiteBalance
\r
1176 .id = V4L2_CID_DO_WHITE_BALANCE,
\r
1177 .type = V4L2_CTRL_TYPE_MENU,
\r
1178 .name = "White Balance Control",
\r
1182 .default_value = 0,
\r
1186 #if CONFIG_SENSOR_Brightness
\r
1188 .id = V4L2_CID_BRIGHTNESS,
\r
1189 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1190 .name = "Brightness Control",
\r
1194 .default_value = 0,
\r
1198 #if CONFIG_SENSOR_Effect
\r
1200 .id = V4L2_CID_EFFECT,
\r
1201 .type = V4L2_CTRL_TYPE_MENU,
\r
1202 .name = "Effect Control",
\r
1206 .default_value = 0,
\r
1210 #if CONFIG_SENSOR_Exposure
\r
1212 .id = V4L2_CID_EXPOSURE,
\r
1213 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1214 .name = "Exposure Control",
\r
1218 .default_value = 0,
\r
1222 #if CONFIG_SENSOR_Saturation
\r
1224 .id = V4L2_CID_SATURATION,
\r
1225 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1226 .name = "Saturation Control",
\r
1230 .default_value = 0,
\r
1234 #if CONFIG_SENSOR_Contrast
\r
1236 .id = V4L2_CID_CONTRAST,
\r
1237 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1238 .name = "Contrast Control",
\r
1242 .default_value = 0,
\r
1246 #if CONFIG_SENSOR_Mirror
\r
1248 .id = V4L2_CID_HFLIP,
\r
1249 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
1250 .name = "Mirror Control",
\r
1254 .default_value = 1,
\r
1258 #if CONFIG_SENSOR_Flip
\r
1260 .id = V4L2_CID_VFLIP,
\r
1261 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
1262 .name = "Flip Control",
\r
1266 .default_value = 1,
\r
1270 #if CONFIG_SENSOR_Scene
\r
1272 .id = V4L2_CID_SCENE,
\r
1273 .type = V4L2_CTRL_TYPE_MENU,
\r
1274 .name = "Scene Control",
\r
1278 .default_value = 0,
\r
1282 #if CONFIG_SENSOR_DigitalZoom
\r
1284 .id = V4L2_CID_ZOOM_RELATIVE,
\r
1285 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1286 .name = "DigitalZoom Control",
\r
1290 .default_value = 0,
\r
1292 .id = V4L2_CID_ZOOM_ABSOLUTE,
\r
1293 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1294 .name = "DigitalZoom Control",
\r
1298 .default_value = 0,
\r
1302 #if CONFIG_SENSOR_Focus
\r
1304 .id = V4L2_CID_FOCUS_RELATIVE,
\r
1305 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1306 .name = "Focus Control",
\r
1310 .default_value = 0,
\r
1312 .id = V4L2_CID_FOCUS_ABSOLUTE,
\r
1313 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1314 .name = "Focus Control",
\r
1318 .default_value = 125,
\r
1322 #if CONFIG_SENSOR_Flash
\r
1324 .id = V4L2_CID_FLASH,
\r
1325 .type = V4L2_CTRL_TYPE_MENU,
\r
1326 .name = "Flash Control",
\r
1330 .default_value = 0,
\r
1335 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
\r
1336 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
\r
1337 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
1338 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
1339 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
1340 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
1341 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
\r
1342 static int sensor_resume(struct soc_camera_device *icd);
\r
1343 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
\r
1344 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
\r
1345 #if CONFIG_SENSOR_Effect
\r
1346 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1348 #if CONFIG_SENSOR_WhiteBalance
\r
1349 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1351 static int sensor_deactivate(struct i2c_client *client);
\r
1353 static struct soc_camera_ops sensor_ops =
\r
1355 .suspend = sensor_suspend,
\r
1356 .resume = sensor_resume,
\r
1357 .set_bus_param = sensor_set_bus_param,
\r
1358 .query_bus_param = sensor_query_bus_param,
\r
1359 .controls = sensor_controls,
\r
1360 .menus = sensor_menus,
\r
1361 .num_controls = ARRAY_SIZE(sensor_controls),
\r
1362 .num_menus = ARRAY_SIZE(sensor_menus),
\r
1365 /* only one fixed colorspace per pixelcode */
\r
1366 struct sensor_datafmt {
\r
1367 enum v4l2_mbus_pixelcode code;
\r
1368 enum v4l2_colorspace colorspace;
\r
1371 /* Find a data format by a pixel code in an array */
\r
1372 static const struct sensor_datafmt *sensor_find_datafmt(
\r
1373 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
\r
1377 for (i = 0; i < n; i++)
\r
1378 if (fmt[i].code == code)
\r
1384 static const struct sensor_datafmt sensor_colour_fmts[] = {
\r
1385 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
\r
1386 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
\r
1389 typedef struct sensor_info_priv_s
\r
1401 bool snap2preview;
\r
1402 bool video2preview;
\r
1403 unsigned char mirror; /* HFLIP */
\r
1404 unsigned char flip; /* VFLIP */
\r
1405 unsigned int winseqe_cur_addr;
\r
1406 struct sensor_datafmt fmt;
\r
1407 unsigned int funmodule_state;
\r
1408 } sensor_info_priv_t;
\r
1412 struct v4l2_subdev subdev;
\r
1413 struct i2c_client *client;
\r
1414 sensor_info_priv_t info_priv;
\r
1415 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
\r
1416 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1417 atomic_t tasklock_cnt;
\r
1419 struct rk29camera_platform_data *sensor_io_request;
\r
1420 struct rk29camera_gpio_res *sensor_gpio_res;
\r
1423 static struct sensor* to_sensor(const struct i2c_client *client)
\r
1425 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
\r
1428 static int sensor_task_lock(struct i2c_client *client, int lock)
\r
1430 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1432 struct sensor *sensor = to_sensor(client);
\r
1435 if (atomic_read(&sensor->tasklock_cnt) == 0) {
\r
1436 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
\r
1437 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
\r
1441 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
\r
1442 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
\r
1443 goto sensor_task_lock_err;
\r
1445 preempt_disable();
\r
1448 atomic_add(1, &sensor->tasklock_cnt);
\r
1450 if (atomic_read(&sensor->tasklock_cnt) > 0) {
\r
1451 atomic_sub(1, &sensor->tasklock_cnt);
\r
1453 if (atomic_read(&sensor->tasklock_cnt) == 0)
\r
1458 sensor_task_lock_err:
\r
1465 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
\r
1469 struct i2c_msg msg[1];
\r
1471 buf[0] = reg & 0xFF;
\r
1474 msg->addr = client->addr;
\r
1475 msg->flags = client->flags;
\r
1477 msg->len = sizeof(buf);
\r
1478 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1479 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
\r
1484 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1485 err = i2c_transfer(client->adapter, msg, 1);
\r
1490 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
\r
1498 /* sensor register read */
\r
1499 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
\r
1503 struct i2c_msg msg[2];
\r
1505 buf[0] = reg ;//>> 8;
\r
1508 msg[0].addr = client->addr;
\r
1509 msg[0].flags = client->flags;
\r
1511 msg[0].len = sizeof(buf);
\r
1512 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1513 msg[0].read_type = 2;//0x55; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
\r
1515 msg[1].addr = client->addr;
\r
1516 msg[1].flags = client->flags|I2C_M_RD;
\r
1519 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1520 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
\r
1524 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1525 err = i2c_transfer(client->adapter, msg, 2);
\r
1531 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
\r
1539 /* write a array of registers */
\r
1540 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
\r
1544 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1549 if (sensor_task_lock(client, 1) < 0)
\r
1550 goto sensor_write_array_end;
\r
1551 while (regarray[i].reg != 0)
\r
1553 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1557 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
\r
1561 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
\r
1563 goto sensor_write_array_end;
\r
1566 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1567 sensor_read(client, regarray[i].reg, &valchk);
\r
1568 if (valchk != regarray[i].val)
\r
1569 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
\r
1575 sensor_write_array_end:
\r
1576 sensor_task_lock(client,0);
\r
1579 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1580 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
\r
1588 while (regarray[i].reg != 0)
\r
1590 sensor_read(client, regarray[i].reg, &valchk);
\r
1591 if (valchk != regarray[i].val)
\r
1592 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
\r
1599 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
\r
1601 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1604 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
\r
1608 case Sensor_PowerDown:
\r
1610 if (icl->powerdown) {
\r
1611 ret = icl->powerdown(icd->pdev, on);
\r
1612 if (ret == RK29_CAM_IO_SUCCESS) {
\r
1616 icl->reset(icd->pdev);
\r
1618 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
\r
1620 goto sensor_power_end;
\r
1625 case Sensor_Flash:
\r
1627 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1628 struct sensor *sensor = to_sensor(client);
\r
1630 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
\r
1631 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
\r
1633 //flash off after 2 secs
\r
1634 hrtimer_cancel(&(flash_off_timer.timer));
\r
1635 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
\r
1642 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
1650 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
\r
1651 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
\r
1652 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
\r
1653 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1658 static int sensor_init(struct v4l2_subdev *sd, u32 val)
\r
1660 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1661 struct soc_camera_device *icd = client->dev.platform_data;
\r
1662 struct sensor *sensor = to_sensor(client);
\r
1663 const struct v4l2_queryctrl *qctrl;
\r
1664 const struct sensor_datafmt *fmt;
\r
1668 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1670 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
1672 goto sensor_INIT_ERR;
\r
1676 if (sensor_task_lock(client,1)<0)
\r
1677 goto sensor_INIT_ERR;
\r
1678 ret = sensor_write(client, 0xff, 1);
\r
1679 ret |= sensor_write(client, 0x12, 0x80);
\r
1682 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
\r
1684 goto sensor_INIT_ERR;
\r
1687 mdelay(5); //delay 5 microseconds
\r
1688 /* check if it is an sensor sensor */
\r
1689 ret = sensor_write(client, 0xff, 1);
\r
1690 ret |= sensor_read(client, 0x0a, &value);
\r
1692 SENSOR_TR("read chip id high byte failed\n");
\r
1694 goto sensor_INIT_ERR;
\r
1698 ret = sensor_read(client, 0x0b, &value);
\r
1700 SENSOR_TR("read chip id low byte failed\n");
\r
1702 goto sensor_INIT_ERR;
\r
1705 pid |= (value & 0xff);
\r
1707 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1708 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
\r
1709 sensor->model = SENSOR_V4L2_IDENT;
\r
1711 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1713 goto sensor_INIT_ERR;
\r
1716 ret = sensor_write_array(client, sensor_init_data);
\r
1719 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
\r
1720 goto sensor_INIT_ERR;
\r
1722 sensor_task_lock(client,0);
\r
1723 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
\r
1724 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
\r
1726 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
\r
1728 goto sensor_INIT_ERR;
\r
1730 sensor->info_priv.fmt = *fmt;
\r
1732 /* sensor sensor information for initialization */
\r
1733 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1735 sensor->info_priv.whiteBalance = qctrl->default_value;
\r
1736 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
\r
1738 sensor->info_priv.brightness = qctrl->default_value;
\r
1739 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1741 sensor->info_priv.effect = qctrl->default_value;
\r
1742 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
\r
1744 sensor->info_priv.exposure = qctrl->default_value;
\r
1746 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
\r
1748 sensor->info_priv.saturation = qctrl->default_value;
\r
1749 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
\r
1751 sensor->info_priv.contrast = qctrl->default_value;
\r
1752 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
\r
1754 sensor->info_priv.mirror = qctrl->default_value;
\r
1755 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
\r
1757 sensor->info_priv.flip = qctrl->default_value;
\r
1758 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
\r
1760 sensor->info_priv.scene = qctrl->default_value;
\r
1761 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
1763 sensor->info_priv.digitalzoom = qctrl->default_value;
\r
1765 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
\r
1766 #if CONFIG_SENSOR_Focus
\r
1767 sensor_set_focus();
\r
1768 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
\r
1770 sensor->info_priv.focus = qctrl->default_value;
\r
1773 #if CONFIG_SENSOR_Flash
\r
1774 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
\r
1776 sensor->info_priv.flash = qctrl->default_value;
\r
1778 flash_off_timer.icd = icd;
\r
1779 flash_off_timer.timer.function = flash_off_func;
\r
1782 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);
\r
1783 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
\r
1786 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1787 sensor_task_lock(client,0);
\r
1788 sensor_deactivate(client);
\r
1792 static int sensor_deactivate(struct i2c_client *client)
\r
1794 struct soc_camera_device *icd = client->dev.platform_data;
\r
1796 struct sensor *sensor = to_sensor(client);
\r
1797 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1799 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
\r
1801 sensor_task_lock(client, 1);
\r
1802 sensor_write(client, 0x3000, reg_val&0xfc);
\r
1803 sensor_write(client, 0x3001, 0x00);
\r
1804 sensor_task_lock(client, 0);
\r
1806 sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1808 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
\r
1809 icd->user_width = SENSOR_INIT_WIDTH;
\r
1810 icd->user_height = SENSOR_INIT_HEIGHT;
\r
1811 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1816 static struct reginfo sensor_power_down_sequence[]=
\r
1820 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
\r
1823 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1825 if (pm_msg.event == PM_EVENT_SUSPEND) {
\r
1826 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
\r
1827 ret = sensor_write_array(client, sensor_power_down_sequence) ;
\r
1829 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
\r
1832 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1834 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1839 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
\r
1845 static int sensor_resume(struct soc_camera_device *icd)
\r
1849 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
\r
1851 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1855 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
\r
1861 static int sensor_set_bus_param(struct soc_camera_device *icd,
\r
1862 unsigned long flags)
\r
1868 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
\r
1870 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1871 unsigned long flags = SENSOR_BUS_PARAM;
\r
1873 return soc_camera_apply_sensor_flags(icl, flags);
\r
1876 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1878 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1879 struct soc_camera_device *icd = client->dev.platform_data;
\r
1880 struct sensor *sensor = to_sensor(client);
\r
1882 mf->width = icd->user_width;
\r
1883 mf->height = icd->user_height;
\r
1884 mf->code = sensor->info_priv.fmt.code;
\r
1885 mf->colorspace = sensor->info_priv.fmt.colorspace;
\r
1886 mf->field = V4L2_FIELD_NONE;
\r
1890 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1894 if ((mf->width == 1024) && (mf->height == 768)) {
\r
1896 } else if ((mf->width == 1280) && (mf->height == 1024)) {
\r
1898 } else if ((mf->width == 1600) && (mf->height == 1200)) {
\r
1900 } else if ((mf->width == 2048) && (mf->height == 1536)) {
\r
1902 } else if ((mf->width == 2592) && (mf->height == 1944)) {
\r
1907 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
\r
1911 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1915 if ((mf->width == 1280) && (mf->height == 720)) {
\r
1917 } else if ((mf->width == 1920) && (mf->height == 1080)) {
\r
1922 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
\r
1925 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1927 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1928 struct sensor *sensor = to_sensor(client);
\r
1929 const struct sensor_datafmt *fmt;
\r
1930 const struct v4l2_queryctrl *qctrl;
\r
1931 struct soc_camera_device *icd = client->dev.platform_data;
\r
1932 struct reginfo *winseqe_set_addr=NULL;
\r
1933 int ret=0, set_w,set_h;
\r
1935 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
1936 ARRAY_SIZE(sensor_colour_fmts));
\r
1939 goto sensor_s_fmt_end;
\r
1942 if (sensor->info_priv.fmt.code != mf->code) {
\r
1945 case V4L2_MBUS_FMT_YUYV8_2X8:
\r
1947 winseqe_set_addr = sensor_ClrFmt_YUYV;
\r
1950 case V4L2_MBUS_FMT_UYVY8_2X8:
\r
1952 winseqe_set_addr = sensor_ClrFmt_UYVY;
\r
1958 if (winseqe_set_addr != NULL) {
\r
1959 sensor_write_array(client, winseqe_set_addr);
\r
1960 sensor->info_priv.fmt.code = mf->code;
\r
1961 sensor->info_priv.fmt.colorspace= mf->colorspace;
\r
1962 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
\r
1964 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
\r
1968 set_w = mf->width;
\r
1969 set_h = mf->height;
\r
1971 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
\r
1973 winseqe_set_addr = sensor_qcif;
\r
1977 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
\r
1979 winseqe_set_addr = sensor_qvga;
\r
1983 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
\r
1985 winseqe_set_addr = sensor_cif;
\r
1989 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
\r
1991 winseqe_set_addr = sensor_vga;
\r
1995 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
\r
1997 winseqe_set_addr = sensor_svga;
\r
2001 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
\r
2003 winseqe_set_addr = sensor_xga;
\r
2007 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
\r
2009 winseqe_set_addr = sensor_sxga;
\r
2013 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
\r
2015 winseqe_set_addr = sensor_uxga;
\r
2021 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
\r
2022 set_w = SENSOR_INIT_WIDTH;
\r
2023 set_h = SENSOR_INIT_HEIGHT;
\r
2024 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
\r
2027 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
\r
2028 #if CONFIG_SENSOR_Flash
\r
2029 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
2030 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2031 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
\r
2032 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
\r
2034 } else { /* ddl@rock-chips.com : Video */
\r
2035 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2036 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2037 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
\r
2041 ret |= sensor_write_array(client, winseqe_set_addr);
\r
2043 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
\r
2044 #if CONFIG_SENSOR_Flash
\r
2045 if (sensor_fmt_capturechk(sd,mf) == true) {
\r
2046 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2047 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2048 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
\r
2052 goto sensor_s_fmt_end;
\r
2055 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
\r
2057 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
2058 #if CONFIG_SENSOR_Effect
\r
2059 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2060 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2062 #if CONFIG_SENSOR_WhiteBalance
\r
2063 if (sensor->info_priv.whiteBalance != 0) {
\r
2064 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2065 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2068 sensor->info_priv.snap2preview = true;
\r
2069 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
\r
2070 #if CONFIG_SENSOR_Effect
\r
2071 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2072 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2074 #if CONFIG_SENSOR_WhiteBalance
\r
2075 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2076 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2078 sensor->info_priv.video2preview = true;
\r
2079 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
\r
2080 #if CONFIG_SENSOR_Effect
\r
2081 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2082 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2084 #if CONFIG_SENSOR_WhiteBalance
\r
2085 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2086 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2088 sensor->info_priv.video2preview = false;
\r
2089 sensor->info_priv.snap2preview = false;
\r
2091 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
\r
2095 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
\r
2098 mf->width = set_w;
\r
2099 mf->height = set_h;
\r
2105 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
2107 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2108 struct sensor *sensor = to_sensor(client);
\r
2109 const struct sensor_datafmt *fmt;
\r
2110 int ret = 0,set_w,set_h;
\r
2112 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
2113 ARRAY_SIZE(sensor_colour_fmts));
\r
2114 if (fmt == NULL) {
\r
2115 fmt = &sensor->info_priv.fmt;
\r
2116 mf->code = fmt->code;
\r
2119 if (mf->height > SENSOR_MAX_HEIGHT)
\r
2120 mf->height = SENSOR_MAX_HEIGHT;
\r
2121 else if (mf->height < SENSOR_MIN_HEIGHT)
\r
2122 mf->height = SENSOR_MIN_HEIGHT;
\r
2124 if (mf->width > SENSOR_MAX_WIDTH)
\r
2125 mf->width = SENSOR_MAX_WIDTH;
\r
2126 else if (mf->width < SENSOR_MIN_WIDTH)
\r
2127 mf->width = SENSOR_MIN_WIDTH;
\r
2129 set_w = mf->width;
\r
2130 set_h = mf->height;
\r
2132 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
\r
2137 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
\r
2142 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
\r
2147 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
\r
2152 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
\r
2157 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
\r
2162 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
\r
2167 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
\r
2174 set_w = SENSOR_INIT_WIDTH;
\r
2175 set_h = SENSOR_INIT_HEIGHT;
\r
2178 mf->width = set_w;
\r
2179 mf->height = set_h;
\r
2181 mf->colorspace = fmt->colorspace;
\r
2185 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
\r
2187 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2189 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
\r
2192 if (id->match.addr != client->addr)
\r
2195 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
\r
2200 #if CONFIG_SENSOR_Brightness
\r
2201 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2203 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2205 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2207 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
\r
2209 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
\r
2211 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2214 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2218 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2222 #if CONFIG_SENSOR_Effect
\r
2223 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2225 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2227 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2229 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
\r
2231 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
\r
2233 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2236 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2240 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2244 #if CONFIG_SENSOR_Exposure
\r
2245 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2247 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2249 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2251 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
\r
2253 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
\r
2255 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2258 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2262 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2266 #if CONFIG_SENSOR_Saturation
\r
2267 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2269 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2271 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2273 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
\r
2275 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
\r
2277 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2280 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2284 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2288 #if CONFIG_SENSOR_Contrast
\r
2289 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2291 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2293 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2295 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
\r
2297 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
\r
2299 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2302 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2306 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2310 #if CONFIG_SENSOR_Mirror
\r
2311 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2313 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2315 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2317 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
\r
2319 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
\r
2321 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2324 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2328 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2332 #if CONFIG_SENSOR_Flip
\r
2333 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2335 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2337 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2339 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
\r
2341 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
\r
2343 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2346 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2350 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2354 #if CONFIG_SENSOR_Scene
\r
2355 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2357 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2359 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2361 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
\r
2363 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
\r
2365 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2368 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2372 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2376 #if CONFIG_SENSOR_WhiteBalance
\r
2377 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2379 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2381 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2383 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
\r
2385 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
\r
2387 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2390 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2394 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2398 #if CONFIG_SENSOR_DigitalZoom
\r
2399 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
\r
2401 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2402 struct sensor *sensor = to_sensor(client);
\r
2403 const struct v4l2_queryctrl *qctrl_info;
\r
2404 int digitalzoom_cur, digitalzoom_total;
\r
2406 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
2410 digitalzoom_cur = sensor->info_priv.digitalzoom;
\r
2411 digitalzoom_total = qctrl_info->maximum;
\r
2413 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
\r
2415 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2419 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
\r
2421 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2425 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
\r
2427 value = digitalzoom_total - digitalzoom_cur;
\r
2430 if ((value < 0) && ((digitalzoom_cur + value) < 0))
\r
2432 value = 0 - digitalzoom_cur;
\r
2435 digitalzoom_cur += value;
\r
2437 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
\r
2439 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
\r
2441 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2444 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2451 #if CONFIG_SENSOR_Flash
\r
2452 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2454 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
\r
2455 if (value == 3) { /* ddl@rock-chips.com: torch */
\r
2456 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
\r
2458 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2460 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2464 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2469 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2471 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2472 struct sensor *sensor = to_sensor(client);
\r
2473 const struct v4l2_queryctrl *qctrl;
\r
2475 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2479 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2485 case V4L2_CID_BRIGHTNESS:
\r
2487 ctrl->value = sensor->info_priv.brightness;
\r
2490 case V4L2_CID_SATURATION:
\r
2492 ctrl->value = sensor->info_priv.saturation;
\r
2495 case V4L2_CID_CONTRAST:
\r
2497 ctrl->value = sensor->info_priv.contrast;
\r
2500 case V4L2_CID_DO_WHITE_BALANCE:
\r
2502 ctrl->value = sensor->info_priv.whiteBalance;
\r
2505 case V4L2_CID_EXPOSURE:
\r
2507 ctrl->value = sensor->info_priv.exposure;
\r
2510 case V4L2_CID_HFLIP:
\r
2512 ctrl->value = sensor->info_priv.mirror;
\r
2515 case V4L2_CID_VFLIP:
\r
2517 ctrl->value = sensor->info_priv.flip;
\r
2528 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2530 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2531 struct sensor *sensor = to_sensor(client);
\r
2532 struct soc_camera_device *icd = client->dev.platform_data;
\r
2533 const struct v4l2_queryctrl *qctrl;
\r
2536 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2540 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2546 #if CONFIG_SENSOR_Brightness
\r
2547 case V4L2_CID_BRIGHTNESS:
\r
2549 if (ctrl->value != sensor->info_priv.brightness)
\r
2551 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
\r
2555 sensor->info_priv.brightness = ctrl->value;
\r
2560 #if CONFIG_SENSOR_Exposure
\r
2561 case V4L2_CID_EXPOSURE:
\r
2563 if (ctrl->value != sensor->info_priv.exposure)
\r
2565 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
\r
2569 sensor->info_priv.exposure = ctrl->value;
\r
2574 #if CONFIG_SENSOR_Saturation
\r
2575 case V4L2_CID_SATURATION:
\r
2577 if (ctrl->value != sensor->info_priv.saturation)
\r
2579 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
\r
2583 sensor->info_priv.saturation = ctrl->value;
\r
2588 #if CONFIG_SENSOR_Contrast
\r
2589 case V4L2_CID_CONTRAST:
\r
2591 if (ctrl->value != sensor->info_priv.contrast)
\r
2593 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
\r
2597 sensor->info_priv.contrast = ctrl->value;
\r
2602 #if CONFIG_SENSOR_WhiteBalance
\r
2603 case V4L2_CID_DO_WHITE_BALANCE:
\r
2605 if (ctrl->value != sensor->info_priv.whiteBalance)
\r
2607 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
\r
2611 sensor->info_priv.whiteBalance = ctrl->value;
\r
2616 #if CONFIG_SENSOR_Mirror
\r
2617 case V4L2_CID_HFLIP:
\r
2619 if (ctrl->value != sensor->info_priv.mirror)
\r
2621 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
\r
2623 sensor->info_priv.mirror = ctrl->value;
\r
2628 #if CONFIG_SENSOR_Flip
\r
2629 case V4L2_CID_VFLIP:
\r
2631 if (ctrl->value != sensor->info_priv.flip)
\r
2633 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
\r
2635 sensor->info_priv.flip = ctrl->value;
\r
2646 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
\r
2648 const struct v4l2_queryctrl *qctrl;
\r
2649 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2650 struct sensor *sensor = to_sensor(client);
\r
2652 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2656 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2660 switch (ext_ctrl->id)
\r
2662 case V4L2_CID_SCENE:
\r
2664 ext_ctrl->value = sensor->info_priv.scene;
\r
2667 case V4L2_CID_EFFECT:
\r
2669 ext_ctrl->value = sensor->info_priv.effect;
\r
2672 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2674 ext_ctrl->value = sensor->info_priv.digitalzoom;
\r
2677 case V4L2_CID_ZOOM_RELATIVE:
\r
2681 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2683 ext_ctrl->value = sensor->info_priv.focus;
\r
2686 case V4L2_CID_FOCUS_RELATIVE:
\r
2690 case V4L2_CID_FLASH:
\r
2692 ext_ctrl->value = sensor->info_priv.flash;
\r
2700 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
\r
2702 const struct v4l2_queryctrl *qctrl;
\r
2703 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2704 struct sensor *sensor = to_sensor(client);
\r
2707 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2711 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2716 switch (ext_ctrl->id)
\r
2718 #if CONFIG_SENSOR_Scene
\r
2719 case V4L2_CID_SCENE:
\r
2721 if (ext_ctrl->value != sensor->info_priv.scene)
\r
2723 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
\r
2725 sensor->info_priv.scene = ext_ctrl->value;
\r
2730 #if CONFIG_SENSOR_Effect
\r
2731 case V4L2_CID_EFFECT:
\r
2733 if (ext_ctrl->value != sensor->info_priv.effect)
\r
2735 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
\r
2737 sensor->info_priv.effect= ext_ctrl->value;
\r
2742 #if CONFIG_SENSOR_DigitalZoom
\r
2743 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2745 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2748 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
\r
2750 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
\r
2752 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
\r
2754 sensor->info_priv.digitalzoom += val_offset;
\r
2756 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2761 case V4L2_CID_ZOOM_RELATIVE:
\r
2763 if (ext_ctrl->value)
\r
2765 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
\r
2767 sensor->info_priv.digitalzoom += ext_ctrl->value;
\r
2769 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2774 #if CONFIG_SENSOR_Focus
\r
2775 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2777 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2780 if (ext_ctrl->value != sensor->info_priv.focus)
\r
2782 val_offset = ext_ctrl->value -sensor->info_priv.focus;
\r
2784 sensor->info_priv.focus += val_offset;
\r
2789 case V4L2_CID_FOCUS_RELATIVE:
\r
2791 if (ext_ctrl->value)
\r
2793 sensor->info_priv.focus += ext_ctrl->value;
\r
2795 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
\r
2800 #if CONFIG_SENSOR_Flash
\r
2801 case V4L2_CID_FLASH:
\r
2803 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
\r
2805 sensor->info_priv.flash = ext_ctrl->value;
\r
2807 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
\r
2818 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2820 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2821 struct soc_camera_device *icd = client->dev.platform_data;
\r
2822 int i, error_cnt=0, error_idx=-1;
\r
2825 for (i=0; i<ext_ctrl->count; i++) {
\r
2826 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2832 if (error_cnt > 1)
\r
2833 error_idx = ext_ctrl->count;
\r
2835 if (error_idx != -1) {
\r
2836 ext_ctrl->error_idx = error_idx;
\r
2843 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2845 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2846 struct soc_camera_device *icd = client->dev.platform_data;
\r
2847 int i, error_cnt=0, error_idx=-1;
\r
2850 for (i=0; i<ext_ctrl->count; i++) {
\r
2851 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2857 if (error_cnt > 1)
\r
2858 error_idx = ext_ctrl->count;
\r
2860 if (error_idx != -1) {
\r
2861 ext_ctrl->error_idx = error_idx;
\r
2868 /* Interface active, can use i2c. If it fails, it can indeed mean, that
\r
2869 * this wasn't our capture interface, so, we wait for the right one */
\r
2870 static int sensor_video_probe(struct soc_camera_device *icd,
\r
2871 struct i2c_client *client)
\r
2875 struct sensor *sensor = to_sensor(client);
\r
2877 /* We must have a parent by now. And it cannot be a wrong one.
\r
2878 * So this entire test is completely redundant. */
\r
2879 if (!icd->dev.parent ||
\r
2880 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
\r
2883 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
2885 goto sensor_video_probe_err;
\r
2889 ret = sensor_write(client, 0xff, 0x1);
\r
2891 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
\r
2893 goto sensor_video_probe_err;
\r
2895 mdelay(5); //delay 5 microseconds
\r
2897 /* check if it is an sensor sensor */
\r
2898 ret = sensor_read(client, 0x0a, &value);
\r
2900 SENSOR_TR("read chip id high byte failed\n");
\r
2902 goto sensor_video_probe_err;
\r
2906 ret = sensor_read(client, 0x0b, &value);
\r
2908 SENSOR_TR("read chip id low byte failed\n");
\r
2910 goto sensor_video_probe_err;
\r
2913 pid |= (value & 0xff);
\r
2914 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2916 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
\r
2917 sensor->model = SENSOR_V4L2_IDENT;
\r
2919 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2921 goto sensor_video_probe_err;
\r
2926 sensor_video_probe_err:
\r
2931 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
\r
2933 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2934 struct soc_camera_device *icd = client->dev.platform_data;
\r
2935 struct sensor *sensor = to_sensor(client);
\r
2938 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2941 case RK29_CAM_SUBDEV_DEACTIVATE:
\r
2943 sensor_deactivate(client);
\r
2947 case RK29_CAM_SUBDEV_IOREQUEST:
\r
2949 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
\r
2950 if (sensor->sensor_io_request != NULL) {
\r
2951 sensor->sensor_gpio_res = NULL;
\r
2952 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
\r
2953 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
\r
2954 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
\r
2955 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
\r
2958 if (sensor->sensor_gpio_res == NULL) {
\r
2959 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
2961 goto sensor_ioctl_end;
\r
2964 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
2966 goto sensor_ioctl_end;
\r
2968 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
\r
2969 for this project */
\r
2970 #if CONFIG_SENSOR_Flash
\r
2971 if (sensor->sensor_gpio_res) {
\r
2972 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
\r
2973 for (i = 0; i < icd->ops->num_controls; i++) {
\r
2974 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
\r
2975 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
\r
2976 sensor_controls[i].id=0xffff;
\r
2979 sensor->info_priv.flash = 0xff;
\r
2980 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
\r
2981 }else{ //two cameras are the same,need to deal diffrently ,zyc
\r
2982 for (i = 0; i < icd->ops->num_controls; i++) {
\r
2983 if(0xffff == icd->ops->controls[i].id){
\r
2984 sensor_controls[i].id=V4L2_CID_FLASH;
\r
2994 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
3003 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
\r
3004 enum v4l2_mbus_pixelcode *code)
\r
3006 if (index >= ARRAY_SIZE(sensor_colour_fmts))
\r
3009 *code = sensor_colour_fmts[index].code;
\r
3012 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
\r
3013 .init = sensor_init,
\r
3014 .g_ctrl = sensor_g_control,
\r
3015 .s_ctrl = sensor_s_control,
\r
3016 .g_ext_ctrls = sensor_g_ext_controls,
\r
3017 .s_ext_ctrls = sensor_s_ext_controls,
\r
3018 .g_chip_ident = sensor_g_chip_ident,
\r
3019 .ioctl = sensor_ioctl,
\r
3022 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
\r
3023 .s_mbus_fmt = sensor_s_fmt,
\r
3024 .g_mbus_fmt = sensor_g_fmt,
\r
3025 .try_mbus_fmt = sensor_try_fmt,
\r
3026 .enum_mbus_fmt = sensor_enum_fmt,
\r
3029 static struct v4l2_subdev_ops sensor_subdev_ops = {
\r
3030 .core = &sensor_subdev_core_ops,
\r
3031 .video = &sensor_subdev_video_ops,
\r
3034 static int sensor_probe(struct i2c_client *client,
\r
3035 const struct i2c_device_id *did)
\r
3037 struct sensor *sensor;
\r
3038 struct soc_camera_device *icd = client->dev.platform_data;
\r
3039 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
\r
3040 struct soc_camera_link *icl;
\r
3043 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
\r
3045 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
\r
3049 icl = to_soc_camera_link(icd);
\r
3051 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
\r
3055 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
\r
3056 dev_warn(&adapter->dev,
\r
3057 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
\r
3061 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
\r
3065 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
\r
3067 /* Second stage probe - when a capture adapter is there */
\r
3068 icd->ops = &sensor_ops;
\r
3069 sensor->info_priv.fmt = sensor_colour_fmts[0];
\r
3070 #if CONFIG_SENSOR_I2C_NOSCHED
\r
3071 atomic_set(&sensor->tasklock_cnt,0);
\r
3074 ret = sensor_video_probe(icd, client);
\r
3077 i2c_set_clientdata(client, NULL);
\r
3081 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
\r
3082 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
\r
3086 static int sensor_remove(struct i2c_client *client)
\r
3088 struct sensor *sensor = to_sensor(client);
\r
3089 struct soc_camera_device *icd = client->dev.platform_data;
\r
3092 i2c_set_clientdata(client, NULL);
\r
3093 client->driver = NULL;
\r
3099 static const struct i2c_device_id sensor_id[] = {
\r
3100 {SENSOR_NAME_STRING(), 0 },
\r
3103 MODULE_DEVICE_TABLE(i2c, sensor_id);
\r
3105 static struct i2c_driver sensor_i2c_driver = {
\r
3107 .name = SENSOR_NAME_STRING(),
\r
3109 .probe = sensor_probe,
\r
3110 .remove = sensor_remove,
\r
3111 .id_table = sensor_id,
\r
3114 static int __init sensor_mod_init(void)
\r
3116 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
\r
3117 return i2c_add_driver(&sensor_i2c_driver);
\r
3120 static void __exit sensor_mod_exit(void)
\r
3122 i2c_del_driver(&sensor_i2c_driver);
\r
3125 device_initcall_sync(sensor_mod_init);
\r
3126 module_exit(sensor_mod_exit);
\r
3128 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
\r
3129 MODULE_AUTHOR("ddl <kernel@rock-chips>");
\r
3130 MODULE_LICENSE("GPL");
\r