3 o* Driver for MT9M001 CMOS Image Sensor from Micron
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 #include <linux/videodev2.h>
13 #include <linux/slab.h>
14 #include <linux/i2c.h>
15 #include <linux/log2.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/circ_buf.h>
19 #include <linux/miscdevice.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-chip-ident.h>
22 #include <media/soc_camera.h>
23 #include <plat/rk_camera.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_SP2518
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_SP2518
48 #define SENSOR_ID 0x53
49 #define SENSOR_ID_REG 0x02
50 #define SENSOR_MIN_WIDTH 640
51 #define SENSOR_MIN_HEIGHT 480
52 #define SENSOR_MAX_WIDTH 1600
53 #define SENSOR_MAX_HEIGHT 1200
54 #define SENSOR_INIT_WIDTH 800 /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT 600
56 #define SENSOR_INIT_WINSEQADR sensor_vga
57 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 1
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 100000 ///250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
78 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
79 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
81 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
82 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
83 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
84 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
85 #define COLOR_TEMPERATURE_OFFICE_DN 3500
86 #define COLOR_TEMPERATURE_OFFICE_UP 5000
87 #define COLOR_TEMPERATURE_HOME_DN 2500
88 #define COLOR_TEMPERATURE_HOME_UP 3500
90 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
91 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
93 #define SENSOR_AF_IS_ERR (0x00<<0)
94 #define SENSOR_AF_IS_OK (0x01<<0)
95 #define SENSOR_INIT_IS_ERR (0x00<<28)
96 #define SENSOR_INIT_IS_OK (0x01<<28)
99 #define SP2518_P0_0xf7 0x78///0x80//78
100 #define SP2518_P0_0xf8 0x6e///0x74//6e
101 #define SP2518_P0_0xf9 0x74///0x80//74
102 #define SP2518_P0_0xfa 0x6a///0x74//6a
105 #define SP2518_P0_0xdd 0x7c //0x80 modify by sp_yjp,20120814
106 #define SP2518_P0_0xde 0x90 //0x95 modify by sp_yjp,20120814
109 #define SP2518_NORMAL_Y0ffset 0x10 //0x0f modify by sp_yjp,20120813
110 #define SP2518_LOWLIGHT_Y0ffset 0x20
121 ///=========SP2518-modify by sp_yjp,20120529=================
122 /* init 640X480 VGA */
123 static struct reginfo sensor_init_data[] =
127 {0x1b,0x1a},//maximum drv ability //0x02 modify by sp_yjp,20120809
144 {0x2c,0x31},//Ronlus remove balck dot0x45},
146 {0x2e,0x38},//sxga 0x18
148 {0x31,0x10},//mirror upside down
198 ///SP2518 UXGA 24MEclk 3±¶Æµ 1·ÖƵ 50Hz fix 11fps
233 ///SP2518 UXGA 24MEclk 3±¶Æµ 1·ÖƵ 50Hz fix 10fps
269 /// UXGA 24MEclk 3±¶Æµ 1·ÖƵ 50Hz fix 9fps
304 /*24*3pll 8~13fps 50hz*/
314 ///////////////////SP2518_write_cmos_sensor(0x2f , 0x00}, modify by sp_yjp,20120809
315 {0x30 , 0x08}, //0x08 modify by sp_yjp,20120809
340 {0xca,0x30},//mean dummy2low
341 {0xcb,0x50},//mean low2dummy
342 {0xcc,0xc0},//f8;rpc low
343 {0xcd,0xc0},//rpc dummy
344 {0xd5,0x80},//mean normal2dummy
345 {0xd6,0x90},//mean dummy2normal
385 {0x57,0x08},//raw_dif_thr
390 {0x5a,0xa0},//raw_rb_fac_outdoor
391 {0xc4,0xa0},//60raw_rb_fac_indoor
392 {0x43,0xa0},//40raw_rb_fac_dummy
393 {0xad,0x40},//raw_rb_fac_low
395 {0x4f,0xa0},//raw_gf_fac_outdoor
396 {0xc3,0xa0},//60raw_gf_fac_indoor
397 {0x3f,0xa0},//40raw_gf_fac_dummy
398 {0x42,0x40},//raw_gf_fac_low
401 {0xb6,0x80},//raw_gflt_fac_outdoor
402 {0xb7,0x80},//60raw_gflt_fac_normal
403 {0xb8,0x40},//40raw_gflt_fac_dummy
404 {0xb9,0x20},//raw_gflt_fac_low
407 {0x50,0x0c},//raw_grgb_thr
446 {0x36,0xf0},//f0;d1;e9
448 {0x38,0x9a},//dc;9a;af
498 {0xd3,0x68}, //0x77 modify by sp_yjp,20120814
499 {0xd4,0x68}, //0x77 modify by sp_yjp,20120814
500 {0xd6,0x68}, //0x77 modify by sp_yjp,20120814
501 {0xd7,0x68}, //0x77 modify by sp_yjp,20120814
502 {0xd8,0x68}, //0x77 modify by sp_yjp,20120814
503 {0xd9,0x68}, //0x77 modify by sp_yjp,20120814
504 {0xda,0x68}, //0x77 modify by sp_yjp,20120814
505 {0xdb,0x68}, //0x77 modify by sp_yjp,20120814
561 {0xdd,SP2518_P0_0xdd},//0x80
562 {0xde,SP2518_P0_0xde},//a0
621 //SP2518_config_window(WINDOW_SIZE_VGA}
670 {0xff,0xff}//The end flag
675 static struct reginfo sensor_uxga[] =
693 {0xff,0xff}//The end flag
698 static struct reginfo sensor_sxga[] =
718 static struct reginfo sensor_svga[] =
743 {0xff,0xff}//The end flag
747 static struct reginfo sensor_vga[] =
773 {0xff,0xff}//The end flag
777 ///=========SP2518-modify by sp_yjp,20120529=================
780 static struct reginfo sensor_cif[] =
787 static struct reginfo sensor_qvga[] =
815 {0xff,0xff}//The end flag
819 static struct reginfo sensor_qcif[] =
821 {0x00, 0x00}//,{0xff,0xff}
824 static struct reginfo sensor_ClrFmt_YUYV[]=
826 {0xfd, 0x00},{0xff,0xff}
829 static struct reginfo sensor_ClrFmt_UYVY[]=
831 {0xfd, 0x00},{0xff,0xff}
834 ///=========SP2518-modify by sp_yjp,20120529=================
836 #if CONFIG_SENSOR_WhiteBalance
837 static struct reginfo sensor_WhiteB_Auto[]=
847 /* Cloudy Colour Temperature : 6500K - 8000K */
848 static struct reginfo sensor_WhiteB_Cloudy[]=
859 /* ClearDay Colour Temperature : 5000K - 6500K */
860 static struct reginfo sensor_WhiteB_ClearDay[]=
871 /* Office Colour Temperature : 3500K - 5000K */
872 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
884 /* Home Colour Temperature : 2500K - 3500K */
885 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
896 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
897 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
902 ///=========SP2518-modify by sp_yjp,20120529=================
903 #if CONFIG_SENSOR_Brightness
904 static struct reginfo sensor_Brightness0[]=
911 static struct reginfo sensor_Brightness1[]=
918 static struct reginfo sensor_Brightness2[]=
926 static struct reginfo sensor_Brightness3[]=
933 static struct reginfo sensor_Brightness4[]=
940 static struct reginfo sensor_Brightness5[]=
946 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
947 sensor_Brightness4, sensor_Brightness5,NULL,
952 ///=========SP2518-modify by sp_yjp,20120529=================
953 #if CONFIG_SENSOR_Effect
954 static struct reginfo sensor_Effect_Normal[] =
963 static struct reginfo sensor_Effect_WandB[] =
972 static struct reginfo sensor_Effect_Sepia[] =
981 static struct reginfo sensor_Effect_Negative[] =
989 static struct reginfo sensor_Effect_Bluish[] =
998 static struct reginfo sensor_Effect_Green[] =
1006 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1007 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1011 ///=========SP2518-modify by sp_yjp,20120529=================
1012 #if CONFIG_SENSOR_Exposure
1013 static struct reginfo sensor_Exposure0[]=
1017 {0xed,SP2518_P0_0xf7-0x18+0x04},
1018 {0xf7,SP2518_P0_0xf7-0x18},
1019 {0xf8,SP2518_P0_0xf8-0x18},
1020 {0xec,SP2518_P0_0xf8-0x18-0x04},
1021 {0xef,SP2518_P0_0xf9-0x18+0x04},
1022 {0xf9,SP2518_P0_0xf9-0x18},
1023 {0xfa,SP2518_P0_0xfa-0x18},
1024 {0xee,SP2518_P0_0xfa-0x18-0x04},
1030 static struct reginfo sensor_Exposure1[]=
1034 {0xed,SP2518_P0_0xf7-0x10+0x04},
1035 {0xf7,SP2518_P0_0xf7-0x10},
1036 {0xf8,SP2518_P0_0xf8-0x10},
1037 {0xec,SP2518_P0_0xf8-0x10-0x04},
1038 {0xef,SP2518_P0_0xf9-0x10+0x04},
1039 {0xf9,SP2518_P0_0xf9-0x10},
1040 {0xfa,SP2518_P0_0xfa-0x10},
1041 {0xee,SP2518_P0_0xfa-0x10-0x04},
1047 static struct reginfo sensor_Exposure2[]=
1051 {0xed,SP2518_P0_0xf7-0x08+0x04},
1052 {0xf7,SP2518_P0_0xf7-0x08},
1053 {0xf8,SP2518_P0_0xf8-0x08},
1054 {0xec,SP2518_P0_0xf8-0x08-0x04},
1055 {0xef,SP2518_P0_0xf9-0x08+0x04},
1056 {0xf9,SP2518_P0_0xf9-0x08},
1057 {0xfa,SP2518_P0_0xfa-0x08},
1058 {0xee,SP2518_P0_0xfa-0x08-0x04},
1064 static struct reginfo sensor_Exposure3[]=
1068 {0xed,SP2518_P0_0xf7+0x04},
1069 {0xf7,SP2518_P0_0xf7},
1070 {0xf8,SP2518_P0_0xf8},
1071 {0xec,SP2518_P0_0xf8-0x04},
1072 {0xef,SP2518_P0_0xf9+0x04},
1073 {0xf9,SP2518_P0_0xf9},
1074 {0xfa,SP2518_P0_0xfa},
1075 {0xee,SP2518_P0_0xfa-0x04},
1081 static struct reginfo sensor_Exposure4[]=
1085 {0xed,SP2518_P0_0xf7+0x08+0x04},
1086 {0xf7,SP2518_P0_0xf7+0x08},
1087 {0xf8,SP2518_P0_0xf8+0x08},
1088 {0xec,SP2518_P0_0xf8+0x08-0x04},
1089 {0xef,SP2518_P0_0xf9+0x08+0x04},
1090 {0xf9,SP2518_P0_0xf9+0x08},
1091 {0xfa,SP2518_P0_0xfa+0x08},
1092 {0xee,SP2518_P0_0xfa+0x08-0x04},
1098 static struct reginfo sensor_Exposure5[]=
1102 {0xed,SP2518_P0_0xf7+0x10+0x04},
1103 {0xf7,SP2518_P0_0xf7+0x10},
1104 {0xf8,SP2518_P0_0xf8+0x10},
1105 {0xec,SP2518_P0_0xf8+0x10-0x04},
1106 {0xef,SP2518_P0_0xf9+0x10+0x04},
1107 {0xf9,SP2518_P0_0xf9+0x10},
1108 {0xfa,SP2518_P0_0xfa+0x10},
1109 {0xee,SP2518_P0_0xfa+0x10-0x04},
1115 static struct reginfo sensor_Exposure6[]=
1119 {0xed,SP2518_P0_0xf7+0x18+0x04},
1120 {0xf7,SP2518_P0_0xf7+0x18},
1121 {0xf8,SP2518_P0_0xf8+0x18},
1122 {0xec,SP2518_P0_0xf8+0x18-0x04},
1123 {0xef,SP2518_P0_0xf9+0x18+0x04},
1124 {0xf9,SP2518_P0_0xf9+0x18},
1125 {0xfa,SP2518_P0_0xfa+0x18},
1126 {0xee,SP2518_P0_0xfa+0x18-0x04},
1132 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1133 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1137 ///=========SP2518-modify by sp_yjp,20120529=================
1138 #if CONFIG_SENSOR_Saturation
1139 static struct reginfo sensor_Saturation0[]=
1145 static struct reginfo sensor_Saturation1[]=
1151 static struct reginfo sensor_Saturation2[]=
1156 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1160 ///=========SP2518-modify by sp_yjp,20120529=================
1161 #if CONFIG_SENSOR_Contrast
1162 static struct reginfo sensor_Contrast0[]=
1166 {0xdd , SP2518_P0_0xdd-0x30},
1167 {0xde , SP2518_P0_0xde-0x30},
1171 static struct reginfo sensor_Contrast1[]=
1175 {0xdd , SP2518_P0_0xdd-0x20},
1176 {0xde , SP2518_P0_0xde-0x20},
1180 static struct reginfo sensor_Contrast2[]=
1184 {0xdd , SP2518_P0_0xdd-0x10},
1185 {0xde , SP2518_P0_0xde-0x10},
1189 static struct reginfo sensor_Contrast3[]=
1193 {0xdd , SP2518_P0_0xdd},
1194 {0xde , SP2518_P0_0xde},
1198 static struct reginfo sensor_Contrast4[]=
1202 {0xdd , SP2518_P0_0xdd+0x10},
1203 {0xde , SP2518_P0_0xde+0x10},
1208 static struct reginfo sensor_Contrast5[]=
1212 {0xdd , SP2518_P0_0xdd+0x20},
1213 {0xde , SP2518_P0_0xde+0x20},
1217 static struct reginfo sensor_Contrast6[]=
1221 {0xdd , SP2518_P0_0xdd+0x30},
1222 {0xde , SP2518_P0_0xde+0x30},
1229 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1230 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1236 ///=========SP2518-modify by sp_yjp,20120529=================
1237 #if CONFIG_SENSOR_Mirror
1238 static struct reginfo sensor_MirrorOn[]=
1245 static struct reginfo sensor_MirrorOff[]=
1251 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1253 #if CONFIG_SENSOR_Flip
1254 static struct reginfo sensor_FlipOn[]=
1261 static struct reginfo sensor_FlipOff[]=
1267 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1271 ///=========SP2518-modify by sp_yjp,20120529=================
1272 #if CONFIG_SENSOR_Scene//? zch
1273 static struct reginfo sensor_SceneAuto[] =
1277 {0xb2,SP2518_NORMAL_Y0ffset},
1280 ///SP2518 UXGA 24MEclk 3PLL 50Hz fix 10fps
1316 static struct reginfo sensor_SceneNight[] =
1320 {0xb2,SP2518_LOWLIGHT_Y0ffset},
1323 //SP2518 UXGA 24MEclk 3PLL 50Hz fix 6fps
1360 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1364 ///=========SP2518-modify by sp_yjp,20120529=================
1365 #if CONFIG_SENSOR_DigitalZoom
1366 static struct reginfo sensor_Zoom0[] =
1372 static struct reginfo sensor_Zoom1[] =
1378 static struct reginfo sensor_Zoom2[] =
1385 static struct reginfo sensor_Zoom3[] =
1390 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1394 ///=========SP2518-modify by sp_yjp,20120529=================
1395 static const struct v4l2_querymenu sensor_menus[] =
1397 #if CONFIG_SENSOR_WhiteBalance
1398 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1399 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1400 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1403 #if CONFIG_SENSOR_Effect
1404 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1405 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1406 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1409 #if CONFIG_SENSOR_Scene
1410 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1413 #if CONFIG_SENSOR_Flash
1414 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1415 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1419 static const struct v4l2_queryctrl sensor_controls[] =
1421 #if CONFIG_SENSOR_WhiteBalance
1423 .id = V4L2_CID_DO_WHITE_BALANCE,
1424 .type = V4L2_CTRL_TYPE_MENU,
1425 .name = "White Balance Control",
1433 #if CONFIG_SENSOR_Brightness
1435 .id = V4L2_CID_BRIGHTNESS,
1436 .type = V4L2_CTRL_TYPE_INTEGER,
1437 .name = "Brightness Control",
1445 #if CONFIG_SENSOR_Effect
1447 .id = V4L2_CID_EFFECT,
1448 .type = V4L2_CTRL_TYPE_MENU,
1449 .name = "Effect Control",
1457 #if CONFIG_SENSOR_Exposure
1459 .id = V4L2_CID_EXPOSURE,
1460 .type = V4L2_CTRL_TYPE_INTEGER,
1461 .name = "Exposure Control",
1469 #if CONFIG_SENSOR_Saturation
1471 .id = V4L2_CID_SATURATION,
1472 .type = V4L2_CTRL_TYPE_INTEGER,
1473 .name = "Saturation Control",
1481 #if CONFIG_SENSOR_Contrast
1483 .id = V4L2_CID_CONTRAST,
1484 .type = V4L2_CTRL_TYPE_INTEGER,
1485 .name = "Contrast Control",
1493 #if CONFIG_SENSOR_Mirror
1495 .id = V4L2_CID_HFLIP,
1496 .type = V4L2_CTRL_TYPE_BOOLEAN,
1497 .name = "Mirror Control",
1505 #if CONFIG_SENSOR_Flip
1507 .id = V4L2_CID_VFLIP,
1508 .type = V4L2_CTRL_TYPE_BOOLEAN,
1509 .name = "Flip Control",
1517 #if CONFIG_SENSOR_Scene
1519 .id = V4L2_CID_SCENE,
1520 .type = V4L2_CTRL_TYPE_MENU,
1521 .name = "Scene Control",
1529 #if CONFIG_SENSOR_DigitalZoom
1531 .id = V4L2_CID_ZOOM_RELATIVE,
1532 .type = V4L2_CTRL_TYPE_INTEGER,
1533 .name = "DigitalZoom Control",
1539 .id = V4L2_CID_ZOOM_ABSOLUTE,
1540 .type = V4L2_CTRL_TYPE_INTEGER,
1541 .name = "DigitalZoom Control",
1549 #if CONFIG_SENSOR_Focus
1551 .id = V4L2_CID_FOCUS_RELATIVE,
1552 .type = V4L2_CTRL_TYPE_INTEGER,
1553 .name = "Focus Control",
1559 .id = V4L2_CID_FOCUS_ABSOLUTE,
1560 .type = V4L2_CTRL_TYPE_INTEGER,
1561 .name = "Focus Control",
1565 .default_value = 125,
1569 #if CONFIG_SENSOR_Flash
1571 .id = V4L2_CID_FLASH,
1572 .type = V4L2_CTRL_TYPE_MENU,
1573 .name = "Flash Control",
1582 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1583 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1584 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1585 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1586 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1587 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1588 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1589 static int sensor_resume(struct soc_camera_device *icd);
1590 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1591 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1592 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1593 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1594 static int sensor_deactivate(struct i2c_client *client);
1596 static struct soc_camera_ops sensor_ops =
1598 .suspend = sensor_suspend,
1599 .resume = sensor_resume,
1600 .set_bus_param = sensor_set_bus_param,
1601 .query_bus_param = sensor_query_bus_param,
1602 .controls = sensor_controls,
1603 .menus = sensor_menus,
1604 .num_controls = ARRAY_SIZE(sensor_controls),
1605 .num_menus = ARRAY_SIZE(sensor_menus),
1608 /* only one fixed colorspace per pixelcode */
1609 struct sensor_datafmt {
1610 enum v4l2_mbus_pixelcode code;
1611 enum v4l2_colorspace colorspace;
1614 /* Find a data format by a pixel code in an array */
1615 static const struct sensor_datafmt *sensor_find_datafmt(
1616 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1620 for (i = 0; i < n; i++)
1621 if (fmt[i].code == code)
1627 static const struct sensor_datafmt sensor_colour_fmts[] = {
1628 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1631 typedef struct sensor_info_priv_s
1645 unsigned char mirror; /* HFLIP */
1646 unsigned char flip; /* VFLIP */
1647 unsigned int winseqe_cur_addr;
1648 struct sensor_datafmt fmt;
1649 unsigned int funmodule_state;
1650 } sensor_info_priv_t;
1654 struct v4l2_subdev subdev;
1655 struct i2c_client *client;
1656 sensor_info_priv_t info_priv;
1657 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1658 #if CONFIG_SENSOR_I2C_NOSCHED
1659 atomic_t tasklock_cnt;
1661 struct rk29camera_platform_data *sensor_io_request;
1662 struct rk29camera_gpio_res *sensor_gpio_res;
1665 static struct sensor* to_sensor(const struct i2c_client *client)
1667 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1670 static int sensor_task_lock(struct i2c_client *client, int lock)
1672 #if CONFIG_SENSOR_I2C_NOSCHED
1674 struct sensor *sensor = to_sensor(client);
1677 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1678 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1679 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1683 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1684 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1685 goto sensor_task_lock_err;
1690 atomic_add(1, &sensor->tasklock_cnt);
1692 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1693 atomic_sub(1, &sensor->tasklock_cnt);
1695 if (atomic_read(&sensor->tasklock_cnt) == 0)
1700 sensor_task_lock_err:
1708 /* sensor register write */
1709 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1713 struct i2c_msg msg[1];
1715 buf[0] = reg & 0xFF;
1718 msg->addr = client->addr;
1719 msg->flags = client->flags;
1721 msg->len = sizeof(buf);
1722 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1723 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1728 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1729 err = i2c_transfer(client->adapter, msg, 1);
1734 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1742 /* sensor register read */
1743 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1748 struct i2c_msg msg[2];
1750 //buf[0] = reg >> 8;
1752 buf[1] = reg & 0xFF;
1754 msg[0].addr = client->addr;
1755 msg[0].flags = client->flags;
1757 msg[0].len = sizeof(buf);
1758 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1759 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1761 msg[1].addr = client->addr;
1762 msg[1].flags = client->flags|I2C_M_RD;
1765 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1766 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1770 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1771 err = i2c_transfer(client->adapter, msg, 2);
1777 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1785 /* write a array of registers */
1786 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1791 while((regarray[i].reg != 0xff) || (regarray[i].val != 0xff))
1793 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1796 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1804 #if CONFIG_SENSOR_I2C_RDWRCHK
1805 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
1812 while((regarray[i].reg != 0xff) || (regarray[i].val != 0xff))
1814 ret = sensor_read(client,regarray[i].reg,&value);
1817 SENSOR_TR("read value failed\n");
1820 if(regarray[i].val != value)
1822 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
1831 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1833 struct soc_camera_link *icl = to_soc_camera_link(icd);
1836 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1839 case Sensor_PowerDown:
1841 if (icl->powerdown) {
1842 ret = icl->powerdown(icd->pdev, on);
1843 if (ret == RK29_CAM_IO_SUCCESS) {
1847 icl->reset(icd->pdev);
1849 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1851 goto sensor_power_end;
1858 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1859 struct sensor *sensor = to_sensor(client);
1861 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1862 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1868 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1876 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1878 struct i2c_client *client = v4l2_get_subdevdata(sd);
1879 struct soc_camera_device *icd = client->dev.platform_data;
1880 struct sensor *sensor = to_sensor(client);
1881 const struct v4l2_queryctrl *qctrl;
1882 const struct sensor_datafmt *fmt;
1885 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1887 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1889 goto sensor_INIT_ERR;
1892 if (sensor_ioctrl(icd, Sensor_PowerDown, 1) < 0) {
1894 goto sensor_INIT_ERR;
1897 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1899 goto sensor_INIT_ERR;
1904 if (sensor_task_lock(client,1)<0)
1905 goto sensor_INIT_ERR;
1906 /* ret = sensor_write(client, 0x12, 0x80);
1909 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1911 goto sensor_INIT_ERR;
1914 mdelay(5); */ //delay 5 microseconds
1916 ret = sensor_write_array(client, sensor_init_data);
1919 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1920 goto sensor_INIT_ERR;
1923 sensor_task_lock(client,0);
1925 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1926 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1928 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1930 goto sensor_INIT_ERR;
1932 sensor->info_priv.fmt = *fmt;
1934 /* sensor sensor information for initialization */
1935 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1937 sensor->info_priv.whiteBalance = qctrl->default_value;
1938 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1940 sensor->info_priv.brightness = qctrl->default_value;
1941 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1943 sensor->info_priv.effect = qctrl->default_value;
1944 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1946 sensor->info_priv.exposure = qctrl->default_value;
1948 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1950 sensor->info_priv.saturation = qctrl->default_value;
1951 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1953 sensor->info_priv.contrast = qctrl->default_value;
1954 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1956 sensor->info_priv.mirror = qctrl->default_value;
1957 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1959 sensor->info_priv.flip = qctrl->default_value;
1960 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1962 sensor->info_priv.scene = qctrl->default_value;
1963 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1965 sensor->info_priv.digitalzoom = qctrl->default_value;
1967 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1968 #if CONFIG_SENSOR_Focus
1970 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1972 sensor->info_priv.focus = qctrl->default_value;
1975 #if CONFIG_SENSOR_Flash
1976 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1978 sensor->info_priv.flash = qctrl->default_value;
1981 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);
1982 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1985 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1986 sensor_task_lock(client,0);
1987 sensor_deactivate(client);
1991 static int sensor_deactivate(struct i2c_client *client)
1993 struct soc_camera_device *icd = client->dev.platform_data;
1995 struct sensor *sensor = to_sensor(client);
1996 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1998 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1999 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2002 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2003 icd->user_width = SENSOR_INIT_WIDTH;
2004 icd->user_height = SENSOR_INIT_HEIGHT;
2005 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2009 static struct reginfo sensor_power_down_sequence[]=
2014 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2017 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2019 if (pm_msg.event == PM_EVENT_SUSPEND) {
2020 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2021 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2023 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2026 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2028 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2033 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2039 static int sensor_resume(struct soc_camera_device *icd)
2043 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2045 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2049 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2055 static int sensor_set_bus_param(struct soc_camera_device *icd,
2056 unsigned long flags)
2062 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2064 struct soc_camera_link *icl = to_soc_camera_link(icd);
2065 unsigned long flags = SENSOR_BUS_PARAM;
2067 return soc_camera_apply_sensor_flags(icl, flags);
2070 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2072 struct i2c_client *client = v4l2_get_subdevdata(sd);
2073 struct soc_camera_device *icd = client->dev.platform_data;
2074 struct sensor *sensor = to_sensor(client);
2076 mf->width = icd->user_width;
2077 mf->height = icd->user_height;
2078 mf->code = sensor->info_priv.fmt.code;
2079 mf->colorspace = sensor->info_priv.fmt.colorspace;
2080 mf->field = V4L2_FIELD_NONE;
2084 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2088 if ((mf->width == 1024) && (mf->height == 768)) {
2090 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2092 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2094 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2096 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2101 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2105 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2109 if ((mf->width == 1280) && (mf->height == 720)) {
2111 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2116 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2119 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2121 struct i2c_client *client = v4l2_get_subdevdata(sd);
2122 const struct sensor_datafmt *fmt;
2123 struct sensor *sensor = to_sensor(client);
2124 const struct v4l2_queryctrl *qctrl;
2125 struct soc_camera_device *icd = client->dev.platform_data;
2126 struct reginfo *winseqe_set_addr=NULL;
2127 int ret=0, set_w,set_h;
2129 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2130 ARRAY_SIZE(sensor_colour_fmts));
2133 goto sensor_s_fmt_end;
2136 if (sensor->info_priv.fmt.code != mf->code) {
2139 case V4L2_MBUS_FMT_YUYV8_2X8:
2141 winseqe_set_addr = sensor_ClrFmt_YUYV;
2144 case V4L2_MBUS_FMT_UYVY8_2X8:
2146 winseqe_set_addr = sensor_ClrFmt_UYVY;
2152 if (winseqe_set_addr != NULL) {
2153 sensor_write_array(client, winseqe_set_addr);
2154 sensor->info_priv.fmt.code = mf->code;
2155 sensor->info_priv.fmt.colorspace= mf->colorspace;
2156 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2158 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2165 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2167 winseqe_set_addr = sensor_qcif;
2171 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2173 winseqe_set_addr = sensor_qvga;
2177 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2179 winseqe_set_addr = sensor_cif;
2183 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2185 winseqe_set_addr = sensor_vga;
2189 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2191 winseqe_set_addr = sensor_svga;
2195 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2197 winseqe_set_addr = sensor_sxga;
2201 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2203 winseqe_set_addr = sensor_uxga;
2209 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2210 set_w = SENSOR_INIT_WIDTH;
2211 set_h = SENSOR_INIT_HEIGHT;
2212 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2215 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2216 #if CONFIG_SENSOR_Flash
2217 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2218 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2219 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2220 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2222 } else { /* ddl@rock-chips.com : Video */
2223 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2224 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2225 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2229 ret |= sensor_write_array(client, winseqe_set_addr);
2231 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2232 #if CONFIG_SENSOR_Flash
2233 if (sensor_fmt_capturechk(sd,mf) == true) {
2234 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2235 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2236 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2240 goto sensor_s_fmt_end;
2243 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2245 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2246 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2247 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2248 if (sensor->info_priv.whiteBalance != 0) {
2249 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2250 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2252 sensor->info_priv.snap2preview = true;
2253 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2254 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2255 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2256 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2257 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2258 sensor->info_priv.video2preview = true;
2259 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2260 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2261 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2262 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2263 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2265 sensor->info_priv.video2preview = false;
2266 sensor->info_priv.snap2preview = false;
2269 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2273 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2283 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2285 struct i2c_client *client = v4l2_get_subdevdata(sd);
2286 struct sensor *sensor = to_sensor(client);
2287 const struct sensor_datafmt *fmt;
2288 int ret = 0,set_w,set_h;
2290 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2291 ARRAY_SIZE(sensor_colour_fmts));
2293 fmt = &sensor->info_priv.fmt;
2294 mf->code = fmt->code;
2297 if (mf->height > SENSOR_MAX_HEIGHT)
2298 mf->height = SENSOR_MAX_HEIGHT;
2299 else if (mf->height < SENSOR_MIN_HEIGHT)
2300 mf->height = SENSOR_MIN_HEIGHT;
2302 if (mf->width > SENSOR_MAX_WIDTH)
2303 mf->width = SENSOR_MAX_WIDTH;
2304 else if (mf->width < SENSOR_MIN_WIDTH)
2305 mf->width = SENSOR_MIN_WIDTH;
2310 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2315 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2320 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2325 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2330 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2335 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2340 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2347 set_w = SENSOR_INIT_WIDTH;
2348 set_h = SENSOR_INIT_HEIGHT;
2354 mf->colorspace = fmt->colorspace;
2359 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2361 struct i2c_client *client = v4l2_get_subdevdata(sd);
2363 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2366 if (id->match.addr != client->addr)
2369 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
2374 #if CONFIG_SENSOR_Brightness
2375 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2377 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2379 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2381 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2383 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2385 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2388 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2392 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2396 #if CONFIG_SENSOR_Effect
2397 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2399 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2401 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2403 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2405 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2407 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2410 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2414 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2418 #if CONFIG_SENSOR_Exposure
2419 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2421 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2423 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2425 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2427 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2429 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2432 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2436 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2440 #if CONFIG_SENSOR_Saturation
2441 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2443 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2445 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2447 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2449 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2451 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2454 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2458 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2462 #if CONFIG_SENSOR_Contrast
2463 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2465 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2467 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2469 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2471 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2473 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2476 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2480 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2484 #if CONFIG_SENSOR_Mirror
2485 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2487 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2489 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2491 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2493 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2495 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2498 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2502 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2506 #if CONFIG_SENSOR_Flip
2507 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2509 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2511 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2513 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2515 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2517 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2520 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2524 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2528 #if CONFIG_SENSOR_Scene
2529 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2531 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2533 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2535 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2537 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2539 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2542 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2546 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2550 #if CONFIG_SENSOR_WhiteBalance
2551 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2553 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2555 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2557 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2559 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2561 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2564 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2568 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2572 #if CONFIG_SENSOR_DigitalZoom
2573 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2575 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2576 struct sensor *sensor = to_sensor(client);
2577 const struct v4l2_queryctrl *qctrl_info;
2578 int digitalzoom_cur, digitalzoom_total;
2580 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2584 digitalzoom_cur = sensor->info_priv.digitalzoom;
2585 digitalzoom_total = qctrl_info->maximum;
2587 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2589 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2593 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2595 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2599 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2601 *value = digitalzoom_total - digitalzoom_cur;
2604 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2606 *value = 0 - digitalzoom_cur;
2609 digitalzoom_cur += *value;
2611 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2613 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2615 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2618 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2625 #if CONFIG_SENSOR_Flash
2626 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2628 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2629 if (value == 3) { /* ddl@rock-chips.com: torch */
2630 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2632 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2634 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2638 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2643 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2645 struct i2c_client *client = v4l2_get_subdevdata(sd);
2646 struct sensor *sensor = to_sensor(client);
2647 const struct v4l2_queryctrl *qctrl;
2649 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2653 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2659 case V4L2_CID_BRIGHTNESS:
2661 ctrl->value = sensor->info_priv.brightness;
2664 case V4L2_CID_SATURATION:
2666 ctrl->value = sensor->info_priv.saturation;
2669 case V4L2_CID_CONTRAST:
2671 ctrl->value = sensor->info_priv.contrast;
2674 case V4L2_CID_DO_WHITE_BALANCE:
2676 ctrl->value = sensor->info_priv.whiteBalance;
2679 case V4L2_CID_EXPOSURE:
2681 ctrl->value = sensor->info_priv.exposure;
2684 case V4L2_CID_HFLIP:
2686 ctrl->value = sensor->info_priv.mirror;
2689 case V4L2_CID_VFLIP:
2691 ctrl->value = sensor->info_priv.flip;
2702 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2704 struct i2c_client *client = v4l2_get_subdevdata(sd);
2705 struct sensor *sensor = to_sensor(client);
2706 struct soc_camera_device *icd = client->dev.platform_data;
2707 const struct v4l2_queryctrl *qctrl;
2710 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2714 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2720 #if CONFIG_SENSOR_Brightness
2721 case V4L2_CID_BRIGHTNESS:
2723 if (ctrl->value != sensor->info_priv.brightness)
2725 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2729 sensor->info_priv.brightness = ctrl->value;
2734 #if CONFIG_SENSOR_Exposure
2735 case V4L2_CID_EXPOSURE:
2737 if (ctrl->value != sensor->info_priv.exposure)
2739 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2743 sensor->info_priv.exposure = ctrl->value;
2748 #if CONFIG_SENSOR_Saturation
2749 case V4L2_CID_SATURATION:
2751 if (ctrl->value != sensor->info_priv.saturation)
2753 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2757 sensor->info_priv.saturation = ctrl->value;
2762 #if CONFIG_SENSOR_Contrast
2763 case V4L2_CID_CONTRAST:
2765 if (ctrl->value != sensor->info_priv.contrast)
2767 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2771 sensor->info_priv.contrast = ctrl->value;
2776 #if CONFIG_SENSOR_WhiteBalance
2777 case V4L2_CID_DO_WHITE_BALANCE:
2779 if (ctrl->value != sensor->info_priv.whiteBalance)
2781 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2785 sensor->info_priv.whiteBalance = ctrl->value;
2790 #if CONFIG_SENSOR_Mirror
2791 case V4L2_CID_HFLIP:
2793 if (ctrl->value != sensor->info_priv.mirror)
2795 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2797 sensor->info_priv.mirror = ctrl->value;
2802 #if CONFIG_SENSOR_Flip
2803 case V4L2_CID_VFLIP:
2805 if (ctrl->value != sensor->info_priv.flip)
2807 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2809 sensor->info_priv.flip = ctrl->value;
2820 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2822 const struct v4l2_queryctrl *qctrl;
2823 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2824 struct sensor *sensor = to_sensor(client);
2826 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2830 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2834 switch (ext_ctrl->id)
2836 case V4L2_CID_SCENE:
2838 ext_ctrl->value = sensor->info_priv.scene;
2841 case V4L2_CID_EFFECT:
2843 ext_ctrl->value = sensor->info_priv.effect;
2846 case V4L2_CID_ZOOM_ABSOLUTE:
2848 ext_ctrl->value = sensor->info_priv.digitalzoom;
2851 case V4L2_CID_ZOOM_RELATIVE:
2855 case V4L2_CID_FOCUS_ABSOLUTE:
2857 ext_ctrl->value = sensor->info_priv.focus;
2860 case V4L2_CID_FOCUS_RELATIVE:
2864 case V4L2_CID_FLASH:
2866 ext_ctrl->value = sensor->info_priv.flash;
2874 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2876 const struct v4l2_queryctrl *qctrl;
2877 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2878 struct sensor *sensor = to_sensor(client);
2881 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2885 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2890 switch (ext_ctrl->id)
2892 #if CONFIG_SENSOR_Scene
2893 case V4L2_CID_SCENE:
2895 if (ext_ctrl->value != sensor->info_priv.scene)
2897 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2899 sensor->info_priv.scene = ext_ctrl->value;
2904 #if CONFIG_SENSOR_Effect
2905 case V4L2_CID_EFFECT:
2907 if (ext_ctrl->value != sensor->info_priv.effect)
2909 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2911 sensor->info_priv.effect= ext_ctrl->value;
2916 #if CONFIG_SENSOR_DigitalZoom
2917 case V4L2_CID_ZOOM_ABSOLUTE:
2919 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2922 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2924 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2926 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2928 sensor->info_priv.digitalzoom += val_offset;
2930 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2935 case V4L2_CID_ZOOM_RELATIVE:
2937 if (ext_ctrl->value)
2939 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2941 sensor->info_priv.digitalzoom += ext_ctrl->value;
2943 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2948 #if CONFIG_SENSOR_Focus
2949 case V4L2_CID_FOCUS_ABSOLUTE:
2951 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2954 if (ext_ctrl->value != sensor->info_priv.focus)
2956 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2958 sensor->info_priv.focus += val_offset;
2963 case V4L2_CID_FOCUS_RELATIVE:
2965 if (ext_ctrl->value)
2967 sensor->info_priv.focus += ext_ctrl->value;
2969 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2974 #if CONFIG_SENSOR_Flash
2975 case V4L2_CID_FLASH:
2977 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2979 sensor->info_priv.flash = ext_ctrl->value;
2981 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2992 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2994 struct i2c_client *client = v4l2_get_subdevdata(sd);
2995 struct soc_camera_device *icd = client->dev.platform_data;
2996 int i, error_cnt=0, error_idx=-1;
2999 for (i=0; i<ext_ctrl->count; i++) {
3000 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3007 error_idx = ext_ctrl->count;
3009 if (error_idx != -1) {
3010 ext_ctrl->error_idx = error_idx;
3017 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3019 struct i2c_client *client = v4l2_get_subdevdata(sd);
3020 struct soc_camera_device *icd = client->dev.platform_data;
3021 int i, error_cnt=0, error_idx=-1;
3024 for (i=0; i<ext_ctrl->count; i++) {
3025 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3032 error_idx = ext_ctrl->count;
3034 if (error_idx != -1) {
3035 ext_ctrl->error_idx = error_idx;
3042 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3043 * this wasn't our capture interface, so, we wait for the right one */
3044 static int sensor_video_probe(struct soc_camera_device *icd,
3045 struct i2c_client *client)
3049 struct sensor *sensor = to_sensor(client);
3051 /* We must have a parent by now. And it cannot be a wrong one.
3052 * So this entire test is completely redundant. */
3053 if (!icd->dev.parent ||
3054 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3057 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3059 goto sensor_video_probe_err;
3062 if (sensor_ioctrl(icd, Sensor_PowerDown, 1) < 0) {
3064 goto sensor_video_probe_err;
3067 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3069 goto sensor_video_probe_err;
3073 /* check if it is an sensor sensor */
3074 ret = sensor_read(client, SENSOR_ID_REG, &pid);
3076 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
3078 goto sensor_video_probe_err;
3081 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3083 if (pid == SENSOR_ID) {
3084 sensor->model = SENSOR_V4L2_IDENT;
3086 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3088 goto sensor_video_probe_err;
3092 sensor_video_probe_err:
3097 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3099 struct i2c_client *client = v4l2_get_subdevdata(sd);
3100 struct soc_camera_device *icd = client->dev.platform_data;
3101 struct sensor *sensor = to_sensor(client);
3107 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3110 case RK29_CAM_SUBDEV_DEACTIVATE:
3112 sensor_deactivate(client);
3116 case RK29_CAM_SUBDEV_IOREQUEST:
3118 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3119 if (sensor->sensor_io_request != NULL) {
3120 sensor->sensor_gpio_res = NULL;
3121 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
3122 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
3123 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
3124 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
3127 if (sensor->sensor_gpio_res == NULL) {
3128 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
3130 goto sensor_ioctl_end;
3133 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3135 goto sensor_ioctl_end;
3137 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3139 #if CONFIG_SENSOR_Flash
3140 if (sensor->sensor_gpio_res) {
3141 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3142 for (i = 0; i < icd->ops->num_controls; i++) {
3143 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3144 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3147 sensor->info_priv.flash = 0xff;
3148 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3156 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3164 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3165 enum v4l2_mbus_pixelcode *code)
3167 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3170 *code = sensor_colour_fmts[index].code;
3173 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3174 .init = sensor_init,
3175 .g_ctrl = sensor_g_control,
3176 .s_ctrl = sensor_s_control,
3177 .g_ext_ctrls = sensor_g_ext_controls,
3178 .s_ext_ctrls = sensor_s_ext_controls,
3179 .g_chip_ident = sensor_g_chip_ident,
3180 .ioctl = sensor_ioctl,
3183 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3184 .s_mbus_fmt = sensor_s_fmt,
3185 .g_mbus_fmt = sensor_g_fmt,
3186 .try_mbus_fmt = sensor_try_fmt,
3187 .enum_mbus_fmt = sensor_enum_fmt,
3190 static struct v4l2_subdev_ops sensor_subdev_ops = {
3191 .core = &sensor_subdev_core_ops,
3192 .video = &sensor_subdev_video_ops,
3195 static int sensor_probe(struct i2c_client *client,
3196 const struct i2c_device_id *did)
3198 struct sensor *sensor;
3199 struct soc_camera_device *icd = client->dev.platform_data;
3200 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3201 struct soc_camera_link *icl;
3204 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3206 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3210 icl = to_soc_camera_link(icd);
3212 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3216 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3217 dev_warn(&adapter->dev,
3218 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3222 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3226 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3228 /* Second stage probe - when a capture adapter is there */
3229 icd->ops = &sensor_ops;
3231 sensor->info_priv.fmt = sensor_colour_fmts[0];
3233 #if CONFIG_SENSOR_I2C_NOSCHED
3234 atomic_set(&sensor->tasklock_cnt,0);
3237 ret = sensor_video_probe(icd, client);
3240 i2c_set_clientdata(client, NULL);
3244 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3248 static int sensor_remove(struct i2c_client *client)
3250 struct sensor *sensor = to_sensor(client);
3251 struct soc_camera_device *icd = client->dev.platform_data;
3254 i2c_set_clientdata(client, NULL);
3255 client->driver = NULL;
3261 static const struct i2c_device_id sensor_id[] = {
3262 {SENSOR_NAME_STRING(), 0 },
3265 MODULE_DEVICE_TABLE(i2c, sensor_id);
3267 static struct i2c_driver sensor_i2c_driver = {
3269 .name = SENSOR_NAME_STRING(),
3271 .probe = sensor_probe,
3272 .remove = sensor_remove,
3273 .id_table = sensor_id,
3276 static int __init sensor_mod_init(void)
3278 return i2c_add_driver(&sensor_i2c_driver);
3281 static void __exit sensor_mod_exit(void)
3283 i2c_del_driver(&sensor_i2c_driver);
3286 device_initcall_sync(sensor_mod_init);
3287 module_exit(sensor_mod_exit);
3289 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3290 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3291 MODULE_LICENSE("GPL");