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>
26 module_param(debug, int, S_IRUGO|S_IWUSR);
28 #define dprintk(level, fmt, arg...) do { \
30 printk(KERN_WARNING fmt , ## arg); } while (0)
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
43 #define MIN(x,y) ((x<y) ? x: y)
44 #define MAX(x,y) ((x>y) ? x: y)
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME RK29_CAM_SENSOR_GC0308
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_GC0308
49 #define SENSOR_ID 0x9b
50 #define SENSOR_MIN_WIDTH 640//176
51 #define SENSOR_MIN_HEIGHT 480//144
52 #define SENSOR_MAX_WIDTH_REAL 640
53 #define SENSOR_MAX_HEIGHT_REAL 480
54 #if defined(CONFIG_SOC_CAMERA_GC0308_INTERPOLATION_5M)
55 #define SENSOR_MAX_WIDTH 2592
56 #define SENSOR_MAX_HEIGHT 1944
57 #elif defined(CONFIG_SOC_CAMERA_GC0308_INTERPOLATION_3M)
58 #define SENSOR_MAX_WIDTH 2048
59 #define SENSOR_MAX_HEIGHT 1536
60 #elif defined(CONFIG_SOC_CAMERA_GC0308_INTERPOLATION_2M)
61 #define SENSOR_MAX_WIDTH 1600
62 #define SENSOR_MAX_HEIGHT 1200
64 #define SENSOR_MAX_WIDTH SENSOR_MAX_WIDTH_REAL
65 #define SENSOR_MAX_HEIGHT SENSOR_MAX_HEIGHT_REAL
67 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
68 #define SENSOR_INIT_HEIGHT 480
69 #define SENSOR_INIT_WINSEQADR sensor_vga
70 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
72 #define CONFIG_SENSOR_WhiteBalance 1
73 #define CONFIG_SENSOR_Brightness 0
74 #define CONFIG_SENSOR_Contrast 0
75 #define CONFIG_SENSOR_Saturation 0
76 #define CONFIG_SENSOR_Effect 1
77 #define CONFIG_SENSOR_Scene 1
78 #define CONFIG_SENSOR_DigitalZoom 0
79 #define CONFIG_SENSOR_Focus 0
80 #define CONFIG_SENSOR_Exposure 0
81 #define CONFIG_SENSOR_Flash 1
82 #define CONFIG_SENSOR_Mirror 0
83 #define CONFIG_SENSOR_Flip 0
85 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
86 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
87 #define CONFIG_SENSOR_I2C_NOSCHED 0
88 #define CONFIG_SENSOR_I2C_RDWRCHK 0
90 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
91 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
92 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
94 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
95 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
96 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
97 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
98 #define COLOR_TEMPERATURE_OFFICE_DN 3500
99 #define COLOR_TEMPERATURE_OFFICE_UP 5000
100 #define COLOR_TEMPERATURE_HOME_DN 2500
101 #define COLOR_TEMPERATURE_HOME_UP 3500
103 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
104 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
106 #define SENSOR_AF_IS_ERR (0x00<<0)
107 #define SENSOR_AF_IS_OK (0x01<<0)
108 #define SENSOR_INIT_IS_ERR (0x00<<28)
109 #define SENSOR_INIT_IS_OK (0x01<<28)
117 //flash off in fixed time to prevent from too hot , zyc
119 struct soc_camera_device *icd;
120 struct hrtimer timer;
122 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
124 static struct flash_timer flash_off_timer;
125 //for user defined if user want to customize the series , zyc
126 #ifdef CONFIG_GC0308_USER_DEFINED_SERIES
127 #include "gc0308_user_series.c"
129 /* init 640X480 VGA */
130 static struct reginfo sensor_init_data[] =
135 {0xfe , 0x00}, // set page0
137 {0xd2 , 0x10}, // close AEC
138 {0x22 , 0x55}, // close AWB
146 {0x22 , 0x57}, // Open AWB
153 {0xe2 , 0x00}, //anti-flicker step [11:8]
154 {0xe3 , 0x64}, //anti-flicker step [7:0]
156 {0xe4 , 0x02}, //exp level 1 16.67fps
158 {0xe6 , 0x03}, //exp level 2 12.5fps
160 {0xe8 , 0x04}, //exp level 3 8.33fps
162 {0xea , 0x09}, //exp level 4 4.00fps
202 {0x26 , 0x02}, //0x03 20101016 zhj
322 //---------------------------------------------------------------
323 {0xfe , 0x01},// set page1
375 {0xfe , 0x00}, // set page0
377 //-----------Update the registers 2010/07/06-------------//
379 {0xfe , 0x00}, // set page0
381 {0x11 , 0x0d}, // fd,modified by mormo 2010/07/06
382 {0x1a , 0x2a}, // 1e,modified by mormo 2010/07/06
384 {0x1c , 0x49}, // c1,modified by mormo 2010/07/06
385 {0x1d , 0x9a}, // 08,modified by mormo 2010/07/06
386 {0x1e , 0x61}, // 60,modified by mormo 2010/07/06
390 {0x50 , 0x14}, // 10,modified by mormo 2010/07/06
405 {0xb1 , 0x40}, // YCPT
410 {0xd0 , 0xcb}, // AECT c9,modifed by mormo 2010/07/06
411 {0xd3 , 0x48}, // 80,modified by mormor 2010/07/06
418 {0xfe , 0x01},// set page1
442 //-----------Update the registers end---------//
445 {0xfe , 0x00}, // set page0
449 //-----------GAMMA Select(3)---------------//
468 /*GC0308_GAMMA_Select,
469 1: //smallest gamma curve
545 5: //largest gamma curve
563 //-----------GAMMA Select End--------------//
568 //-------------H_V_Switch(4)---------------//
569 {0x14 , 0x10}, //0x10
582 4: // IMAGE_HV_MIRROR
585 //-------------H_V_Select End--------------//
590 static struct reginfo sensor_sxga[] =
596 static struct reginfo sensor_svga[] =
602 static struct reginfo sensor_vga[] =
614 static struct reginfo sensor_cif[] =
620 static struct reginfo sensor_qvga[] =
626 static struct reginfo sensor_qcif[] =
631 static struct reginfo sensor_ClrFmt_YUYV[]=
636 static struct reginfo sensor_ClrFmt_UYVY[]=
642 #if CONFIG_SENSOR_WhiteBalance
643 static struct reginfo sensor_WhiteB_Auto[]=
651 /* Cloudy Colour Temperature : 6500K - 8000K */
652 static struct reginfo sensor_WhiteB_Cloudy[]=
654 {0x22, 0x55}, // Disable AWB
660 /* ClearDay Colour Temperature : 5000K - 6500K */
661 static struct reginfo sensor_WhiteB_ClearDay[]=
664 {0x22, 0x55}, // Disable AWB
670 /* Office Colour Temperature : 3500K - 5000K */
671 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
674 {0x22, 0x55}, // Disable AWB
681 /* Home Colour Temperature : 2500K - 3500K */
682 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
685 {0x22, 0x55}, // Disable AWB
691 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
692 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
696 #if CONFIG_SENSOR_Brightness
697 static struct reginfo sensor_Brightness0[]=
704 static struct reginfo sensor_Brightness1[]=
711 static struct reginfo sensor_Brightness2[]=
718 static struct reginfo sensor_Brightness3[]=
725 static struct reginfo sensor_Brightness4[]=
732 static struct reginfo sensor_Brightness5[]=
738 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
739 sensor_Brightness4, sensor_Brightness5,NULL,
744 #if CONFIG_SENSOR_Effect
745 static struct reginfo sensor_Effect_Normal[] =
760 static struct reginfo sensor_Effect_WandB[] =
774 static struct reginfo sensor_Effect_Sepia[] =
788 static struct reginfo sensor_Effect_Negative[] =
802 static struct reginfo sensor_Effect_Bluish[] =
817 static struct reginfo sensor_Effect_Green[] =
831 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
832 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
835 #if CONFIG_SENSOR_Exposure
836 static struct reginfo sensor_Exposure0[]=
842 static struct reginfo sensor_Exposure1[]=
848 static struct reginfo sensor_Exposure2[]=
854 static struct reginfo sensor_Exposure3[]=
860 static struct reginfo sensor_Exposure4[]=
866 static struct reginfo sensor_Exposure5[]=
872 static struct reginfo sensor_Exposure6[]=
878 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
879 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
882 #if CONFIG_SENSOR_Saturation
883 static struct reginfo sensor_Saturation0[]=
888 static struct reginfo sensor_Saturation1[]=
893 static struct reginfo sensor_Saturation2[]=
897 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
900 #if CONFIG_SENSOR_Contrast
901 static struct reginfo sensor_Contrast0[]=
907 static struct reginfo sensor_Contrast1[]=
913 static struct reginfo sensor_Contrast2[]=
919 static struct reginfo sensor_Contrast3[]=
925 static struct reginfo sensor_Contrast4[]=
932 static struct reginfo sensor_Contrast5[]=
938 static struct reginfo sensor_Contrast6[]=
943 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
944 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
948 #if CONFIG_SENSOR_Mirror
949 static struct reginfo sensor_MirrorOn[]=
954 static struct reginfo sensor_MirrorOff[]=
958 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
960 #if CONFIG_SENSOR_Flip
961 static struct reginfo sensor_FlipOn[]=
966 static struct reginfo sensor_FlipOff[]=
970 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
973 #if CONFIG_SENSOR_Scene
974 static struct reginfo sensor_SceneAuto[] =
980 static struct reginfo sensor_SceneNight[] =
985 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
988 #if CONFIG_SENSOR_DigitalZoom
989 static struct reginfo sensor_Zoom0[] =
994 static struct reginfo sensor_Zoom1[] =
999 static struct reginfo sensor_Zoom2[] =
1005 static struct reginfo sensor_Zoom3[] =
1009 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1011 static const struct v4l2_querymenu sensor_menus[] =
1013 #if CONFIG_SENSOR_WhiteBalance
1014 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1015 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1016 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1019 #if CONFIG_SENSOR_Effect
1020 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1021 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1022 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1025 #if CONFIG_SENSOR_Scene
1026 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1029 #if CONFIG_SENSOR_Flash
1030 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1031 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1035 static struct v4l2_queryctrl sensor_controls[] =
1037 #if CONFIG_SENSOR_WhiteBalance
1039 .id = V4L2_CID_DO_WHITE_BALANCE,
1040 .type = V4L2_CTRL_TYPE_MENU,
1041 .name = "White Balance Control",
1049 #if CONFIG_SENSOR_Brightness
1051 .id = V4L2_CID_BRIGHTNESS,
1052 .type = V4L2_CTRL_TYPE_INTEGER,
1053 .name = "Brightness Control",
1061 #if CONFIG_SENSOR_Effect
1063 .id = V4L2_CID_EFFECT,
1064 .type = V4L2_CTRL_TYPE_MENU,
1065 .name = "Effect Control",
1073 #if CONFIG_SENSOR_Exposure
1075 .id = V4L2_CID_EXPOSURE,
1076 .type = V4L2_CTRL_TYPE_INTEGER,
1077 .name = "Exposure Control",
1085 #if CONFIG_SENSOR_Saturation
1087 .id = V4L2_CID_SATURATION,
1088 .type = V4L2_CTRL_TYPE_INTEGER,
1089 .name = "Saturation Control",
1097 #if CONFIG_SENSOR_Contrast
1099 .id = V4L2_CID_CONTRAST,
1100 .type = V4L2_CTRL_TYPE_INTEGER,
1101 .name = "Contrast Control",
1109 #if CONFIG_SENSOR_Mirror
1111 .id = V4L2_CID_HFLIP,
1112 .type = V4L2_CTRL_TYPE_BOOLEAN,
1113 .name = "Mirror Control",
1121 #if CONFIG_SENSOR_Flip
1123 .id = V4L2_CID_VFLIP,
1124 .type = V4L2_CTRL_TYPE_BOOLEAN,
1125 .name = "Flip Control",
1133 #if CONFIG_SENSOR_Scene
1135 .id = V4L2_CID_SCENE,
1136 .type = V4L2_CTRL_TYPE_MENU,
1137 .name = "Scene Control",
1145 #if CONFIG_SENSOR_DigitalZoom
1147 .id = V4L2_CID_ZOOM_RELATIVE,
1148 .type = V4L2_CTRL_TYPE_INTEGER,
1149 .name = "DigitalZoom Control",
1155 .id = V4L2_CID_ZOOM_ABSOLUTE,
1156 .type = V4L2_CTRL_TYPE_INTEGER,
1157 .name = "DigitalZoom Control",
1165 #if CONFIG_SENSOR_Focus
1167 .id = V4L2_CID_FOCUS_RELATIVE,
1168 .type = V4L2_CTRL_TYPE_INTEGER,
1169 .name = "Focus Control",
1175 .id = V4L2_CID_FOCUS_ABSOLUTE,
1176 .type = V4L2_CTRL_TYPE_INTEGER,
1177 .name = "Focus Control",
1181 .default_value = 125,
1185 #if CONFIG_SENSOR_Flash
1187 .id = V4L2_CID_FLASH,
1188 .type = V4L2_CTRL_TYPE_MENU,
1189 .name = "Flash Control",
1198 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1199 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1200 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1201 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1202 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1203 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1204 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1205 static int sensor_resume(struct soc_camera_device *icd);
1206 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1207 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1208 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1209 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1210 static int sensor_deactivate(struct i2c_client *client);
1212 static struct soc_camera_ops sensor_ops =
1214 .suspend = sensor_suspend,
1215 .resume = sensor_resume,
1216 .set_bus_param = sensor_set_bus_param,
1217 .query_bus_param = sensor_query_bus_param,
1218 .controls = sensor_controls,
1219 .menus = sensor_menus,
1220 .num_controls = ARRAY_SIZE(sensor_controls),
1221 .num_menus = ARRAY_SIZE(sensor_menus),
1224 /* only one fixed colorspace per pixelcode */
1225 struct sensor_datafmt {
1226 enum v4l2_mbus_pixelcode code;
1227 enum v4l2_colorspace colorspace;
1230 /* Find a data format by a pixel code in an array */
1231 static const struct sensor_datafmt *sensor_find_datafmt(
1232 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1236 for (i = 0; i < n; i++)
1237 if (fmt[i].code == code)
1243 static const struct sensor_datafmt sensor_colour_fmts[] = {
1244 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1247 typedef struct sensor_info_priv_s
1261 unsigned char mirror; /* HFLIP */
1262 unsigned char flip; /* VFLIP */
1263 unsigned int winseqe_cur_addr;
1264 struct sensor_datafmt fmt;
1265 unsigned int funmodule_state;
1266 } sensor_info_priv_t;
1270 struct v4l2_subdev subdev;
1271 struct i2c_client *client;
1272 sensor_info_priv_t info_priv;
1273 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1274 #if CONFIG_SENSOR_I2C_NOSCHED
1275 atomic_t tasklock_cnt;
1277 struct rk29camera_platform_data *sensor_io_request;
1278 struct rk29camera_gpio_res *sensor_gpio_res;
1281 static struct sensor* to_sensor(const struct i2c_client *client)
1283 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1286 static int sensor_task_lock(struct i2c_client *client, int lock)
1288 #if CONFIG_SENSOR_I2C_NOSCHED
1290 struct sensor *sensor = to_sensor(client);
1293 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1294 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1295 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1299 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1300 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1301 goto sensor_task_lock_err;
1306 atomic_add(1, &sensor->tasklock_cnt);
1308 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1309 atomic_sub(1, &sensor->tasklock_cnt);
1311 if (atomic_read(&sensor->tasklock_cnt) == 0)
1316 sensor_task_lock_err:
1324 /* sensor register write */
1325 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1329 struct i2c_msg msg[1];
1331 buf[0] = reg & 0xFF;
1334 msg->addr = client->addr;
1335 msg->flags = client->flags;
1337 msg->len = sizeof(buf);
1338 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1339 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1344 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1345 err = i2c_transfer(client->adapter, msg, 1);
1350 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1358 /* sensor register read */
1359 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1364 struct i2c_msg msg[2];
1366 //buf[0] = reg >> 8;
1368 buf[1] = reg & 0xFF;
1370 msg[0].addr = client->addr;
1371 msg[0].flags = client->flags;
1373 msg[0].len = sizeof(buf);
1374 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1375 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1377 msg[1].addr = client->addr;
1378 msg[1].flags = client->flags|I2C_M_RD;
1381 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1382 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1386 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1387 err = i2c_transfer(client->adapter, msg, 2);
1393 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1401 /* write a array of registers */
1403 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1408 //for(i=0; i < sizeof(sensor_init_data) / 2;i++)
1409 while((regarray[i].reg != 0) || (regarray[i].val != 0))
1411 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1414 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1423 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1428 while (regarray[i].reg != 0)
1430 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1433 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1436 err = sensor_read(client, regarray[i].reg, &val_read);
1437 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1444 #if CONFIG_SENSOR_I2C_RDWRCHK
1445 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
1452 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
1453 for(i=0;i<sizeof(sensor_init_data) / 2;i++)
1455 ret = sensor_read(client,regarray[i].reg,&value);
1458 SENSOR_TR("read value failed\n");
1461 if(regarray[i].val != value)
1463 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
1472 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1474 struct soc_camera_link *icl = to_soc_camera_link(icd);
1477 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1480 case Sensor_PowerDown:
1482 if (icl->powerdown) {
1483 ret = icl->powerdown(icd->pdev, on);
1484 if (ret == RK29_CAM_IO_SUCCESS) {
1488 icl->reset(icd->pdev);
1490 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1492 goto sensor_power_end;
1499 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1500 struct sensor *sensor = to_sensor(client);
1502 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1503 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1505 //flash off after 2 secs
1506 hrtimer_cancel(&(flash_off_timer.timer));
1507 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1514 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1522 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1523 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1524 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1525 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1529 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1531 struct i2c_client *client = v4l2_get_subdevdata(sd);
1532 struct soc_camera_device *icd = client->dev.platform_data;
1533 struct sensor *sensor = to_sensor(client);
1534 const struct v4l2_queryctrl *qctrl;
1535 const struct sensor_datafmt *fmt;
1538 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1540 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1542 goto sensor_INIT_ERR;
1546 if (sensor_task_lock(client,1)<0)
1547 goto sensor_INIT_ERR;
1548 /* ret = sensor_write(client, 0x12, 0x80);
1551 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1553 goto sensor_INIT_ERR;
1556 mdelay(5); */ //delay 5 microseconds
1558 ret = sensor_write_array(client, sensor_init_data);
1561 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1562 goto sensor_INIT_ERR;
1565 sensor_task_lock(client,0);
1567 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1568 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1570 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1572 goto sensor_INIT_ERR;
1574 sensor->info_priv.fmt = *fmt;
1576 /* sensor sensor information for initialization */
1577 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1579 sensor->info_priv.whiteBalance = qctrl->default_value;
1580 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1582 sensor->info_priv.brightness = qctrl->default_value;
1583 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1585 sensor->info_priv.effect = qctrl->default_value;
1586 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1588 sensor->info_priv.exposure = qctrl->default_value;
1590 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1592 sensor->info_priv.saturation = qctrl->default_value;
1593 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1595 sensor->info_priv.contrast = qctrl->default_value;
1596 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1598 sensor->info_priv.mirror = qctrl->default_value;
1599 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1601 sensor->info_priv.flip = qctrl->default_value;
1602 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1604 sensor->info_priv.scene = qctrl->default_value;
1605 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1607 sensor->info_priv.digitalzoom = qctrl->default_value;
1609 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1610 #if CONFIG_SENSOR_Focus
1612 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1614 sensor->info_priv.focus = qctrl->default_value;
1617 #if CONFIG_SENSOR_Flash
1618 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1620 sensor->info_priv.flash = qctrl->default_value;
1621 flash_off_timer.icd = icd;
1622 flash_off_timer.timer.function = flash_off_func;
1625 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);
1626 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1629 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1630 sensor_task_lock(client,0);
1631 sensor_deactivate(client);
1635 static int sensor_deactivate(struct i2c_client *client)
1637 struct soc_camera_device *icd = client->dev.platform_data;
1639 struct sensor *sensor = to_sensor(client);
1640 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1642 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1643 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1646 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1647 icd->user_width = SENSOR_INIT_WIDTH;
1648 icd->user_height = SENSOR_INIT_HEIGHT;
1649 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1653 static struct reginfo sensor_power_down_sequence[]=
1657 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1660 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1662 if (pm_msg.event == PM_EVENT_SUSPEND) {
1663 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1664 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1666 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1669 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1671 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1676 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1682 static int sensor_resume(struct soc_camera_device *icd)
1686 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1688 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1692 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1698 static int sensor_set_bus_param(struct soc_camera_device *icd,
1699 unsigned long flags)
1705 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1707 struct soc_camera_link *icl = to_soc_camera_link(icd);
1708 unsigned long flags = SENSOR_BUS_PARAM;
1710 return soc_camera_apply_sensor_flags(icl, flags);
1713 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1715 struct i2c_client *client = v4l2_get_subdevdata(sd);
1716 struct soc_camera_device *icd = client->dev.platform_data;
1717 struct sensor *sensor = to_sensor(client);
1719 mf->width = icd->user_width;
1720 mf->height = icd->user_height;
1721 mf->code = sensor->info_priv.fmt.code;
1722 mf->colorspace = sensor->info_priv.fmt.colorspace;
1723 mf->field = V4L2_FIELD_NONE;
1727 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1731 if ((mf->width == 1024) && (mf->height == 768)) {
1733 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1735 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1737 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1739 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1744 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1748 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1752 if ((mf->width == 1280) && (mf->height == 720)) {
1754 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1759 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1762 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1764 struct i2c_client *client = v4l2_get_subdevdata(sd);
1765 const struct sensor_datafmt *fmt;
1766 struct sensor *sensor = to_sensor(client);
1767 const struct v4l2_queryctrl *qctrl;
1768 struct soc_camera_device *icd = client->dev.platform_data;
1769 struct reginfo *winseqe_set_addr=NULL;
1770 int ret=0, set_w,set_h;
1772 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1773 ARRAY_SIZE(sensor_colour_fmts));
1776 goto sensor_s_fmt_end;
1779 if (sensor->info_priv.fmt.code != mf->code) {
1782 case V4L2_MBUS_FMT_YUYV8_2X8:
1784 winseqe_set_addr = sensor_ClrFmt_YUYV;
1787 case V4L2_MBUS_FMT_UYVY8_2X8:
1789 winseqe_set_addr = sensor_ClrFmt_UYVY;
1795 if (winseqe_set_addr != NULL) {
1796 sensor_write_array(client, winseqe_set_addr);
1797 sensor->info_priv.fmt.code = mf->code;
1798 sensor->info_priv.fmt.colorspace= mf->colorspace;
1799 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1801 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1808 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1810 winseqe_set_addr = sensor_qcif;
1814 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1816 winseqe_set_addr = sensor_qvga;
1820 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1822 winseqe_set_addr = sensor_cif;
1826 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1828 winseqe_set_addr = sensor_vga;
1832 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1834 winseqe_set_addr = sensor_svga;
1838 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1840 winseqe_set_addr = sensor_sxga;
1844 #if defined(CONFIG_SOC_CAMERA_GC0308_INTERPOLATION)
1845 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
1847 winseqe_set_addr = sensor_vga;
1848 set_w = SENSOR_MAX_WIDTH_REAL;
1849 set_h = SENSOR_MAX_HEIGHT_REAL;
1855 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1856 set_w = SENSOR_INIT_WIDTH;
1857 set_h = SENSOR_INIT_HEIGHT;
1858 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1861 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1862 #if CONFIG_SENSOR_Flash
1863 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1864 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1865 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1866 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1868 } else { /* ddl@rock-chips.com : Video */
1869 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1870 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1871 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1875 ret |= sensor_write_array(client, winseqe_set_addr);
1877 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1878 #if CONFIG_SENSOR_Flash
1879 if (sensor_fmt_capturechk(sd,mf) == true) {
1880 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1881 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1882 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1886 goto sensor_s_fmt_end;
1889 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1891 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1892 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1893 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1894 if (sensor->info_priv.whiteBalance != 0) {
1895 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1896 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1898 sensor->info_priv.snap2preview = true;
1899 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1900 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1901 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1902 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1903 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1904 sensor->info_priv.video2preview = true;
1905 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1906 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1907 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1908 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1909 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1911 sensor->info_priv.video2preview = false;
1912 sensor->info_priv.snap2preview = false;
1915 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1919 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1929 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1931 struct i2c_client *client = v4l2_get_subdevdata(sd);
1932 struct sensor *sensor = to_sensor(client);
1933 const struct sensor_datafmt *fmt;
1934 int ret = 0,set_w,set_h;
1936 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1937 ARRAY_SIZE(sensor_colour_fmts));
1939 fmt = &sensor->info_priv.fmt;
1940 mf->code = fmt->code;
1943 /* ddl@rock-chips.com : It is query max resolution only. */
1944 if (mf->reserved[6] == 0xfefe5a5a) {
1945 mf->height = SENSOR_MAX_HEIGHT;
1946 mf->width = SENSOR_MAX_WIDTH;
1948 goto sensor_try_fmt_end;
1951 if (mf->height > SENSOR_MAX_HEIGHT)
1952 mf->height = SENSOR_MAX_HEIGHT;
1953 else if (mf->height < SENSOR_MIN_HEIGHT)
1954 mf->height = SENSOR_MIN_HEIGHT;
1956 if (mf->width > SENSOR_MAX_WIDTH)
1957 mf->width = SENSOR_MAX_WIDTH;
1958 else if (mf->width < SENSOR_MIN_WIDTH)
1959 mf->width = SENSOR_MIN_WIDTH;
1964 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1969 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1974 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1979 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1984 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1989 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1994 #if defined(CONFIG_SOC_CAMERA_GC0308_INTERPOLATION)
1995 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
1997 set_w = SENSOR_MAX_WIDTH_REAL;
1998 set_h = SENSOR_MAX_HEIGHT_REAL;
2004 set_w = SENSOR_INIT_WIDTH;
2005 set_h = SENSOR_INIT_HEIGHT;
2011 mf->colorspace = fmt->colorspace;
2016 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2018 struct i2c_client *client = v4l2_get_subdevdata(sd);
2020 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2023 if (id->match.addr != client->addr)
2026 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
2031 #if CONFIG_SENSOR_Brightness
2032 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2034 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2036 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2038 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2040 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2042 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2045 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2049 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2053 #if CONFIG_SENSOR_Effect
2054 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2056 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2058 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2060 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2062 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2064 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2067 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2071 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2075 #if CONFIG_SENSOR_Exposure
2076 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2078 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2080 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2082 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2084 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2086 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2089 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2093 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2097 #if CONFIG_SENSOR_Saturation
2098 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2100 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2102 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2104 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2106 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2108 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2111 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2115 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2119 #if CONFIG_SENSOR_Contrast
2120 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2122 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2124 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2126 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2128 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2130 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2133 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2137 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2141 #if CONFIG_SENSOR_Mirror
2142 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2144 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2146 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2148 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2150 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2152 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2155 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2159 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2163 #if CONFIG_SENSOR_Flip
2164 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2166 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2168 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2170 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2172 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2174 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2177 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2181 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2185 #if CONFIG_SENSOR_Scene
2186 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2188 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2190 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2192 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2194 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2196 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2199 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2203 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2207 #if CONFIG_SENSOR_WhiteBalance
2208 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2210 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2212 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2214 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2216 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2218 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2221 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2225 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2229 #if CONFIG_SENSOR_DigitalZoom
2230 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2232 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2233 struct sensor *sensor = to_sensor(client);
2234 const struct v4l2_queryctrl *qctrl_info;
2235 int digitalzoom_cur, digitalzoom_total;
2237 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2241 digitalzoom_cur = sensor->info_priv.digitalzoom;
2242 digitalzoom_total = qctrl_info->maximum;
2244 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2246 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2250 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2252 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2256 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2258 *value = digitalzoom_total - digitalzoom_cur;
2261 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2263 *value = 0 - digitalzoom_cur;
2266 digitalzoom_cur += *value;
2268 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2270 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2272 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2275 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2282 #if CONFIG_SENSOR_Flash
2283 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2285 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2286 if (value == 3) { /* ddl@rock-chips.com: torch */
2287 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2289 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2291 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2295 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2300 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2302 struct i2c_client *client = v4l2_get_subdevdata(sd);
2303 struct sensor *sensor = to_sensor(client);
2304 const struct v4l2_queryctrl *qctrl;
2306 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2310 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2316 case V4L2_CID_BRIGHTNESS:
2318 ctrl->value = sensor->info_priv.brightness;
2321 case V4L2_CID_SATURATION:
2323 ctrl->value = sensor->info_priv.saturation;
2326 case V4L2_CID_CONTRAST:
2328 ctrl->value = sensor->info_priv.contrast;
2331 case V4L2_CID_DO_WHITE_BALANCE:
2333 ctrl->value = sensor->info_priv.whiteBalance;
2336 case V4L2_CID_EXPOSURE:
2338 ctrl->value = sensor->info_priv.exposure;
2341 case V4L2_CID_HFLIP:
2343 ctrl->value = sensor->info_priv.mirror;
2346 case V4L2_CID_VFLIP:
2348 ctrl->value = sensor->info_priv.flip;
2359 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2361 struct i2c_client *client = v4l2_get_subdevdata(sd);
2362 struct sensor *sensor = to_sensor(client);
2363 struct soc_camera_device *icd = client->dev.platform_data;
2364 const struct v4l2_queryctrl *qctrl;
2367 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2371 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2377 #if CONFIG_SENSOR_Brightness
2378 case V4L2_CID_BRIGHTNESS:
2380 if (ctrl->value != sensor->info_priv.brightness)
2382 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2386 sensor->info_priv.brightness = ctrl->value;
2391 #if CONFIG_SENSOR_Exposure
2392 case V4L2_CID_EXPOSURE:
2394 if (ctrl->value != sensor->info_priv.exposure)
2396 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2400 sensor->info_priv.exposure = ctrl->value;
2405 #if CONFIG_SENSOR_Saturation
2406 case V4L2_CID_SATURATION:
2408 if (ctrl->value != sensor->info_priv.saturation)
2410 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2414 sensor->info_priv.saturation = ctrl->value;
2419 #if CONFIG_SENSOR_Contrast
2420 case V4L2_CID_CONTRAST:
2422 if (ctrl->value != sensor->info_priv.contrast)
2424 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2428 sensor->info_priv.contrast = ctrl->value;
2433 #if CONFIG_SENSOR_WhiteBalance
2434 case V4L2_CID_DO_WHITE_BALANCE:
2436 if (ctrl->value != sensor->info_priv.whiteBalance)
2438 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2442 sensor->info_priv.whiteBalance = ctrl->value;
2447 #if CONFIG_SENSOR_Mirror
2448 case V4L2_CID_HFLIP:
2450 if (ctrl->value != sensor->info_priv.mirror)
2452 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2454 sensor->info_priv.mirror = ctrl->value;
2459 #if CONFIG_SENSOR_Flip
2460 case V4L2_CID_VFLIP:
2462 if (ctrl->value != sensor->info_priv.flip)
2464 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2466 sensor->info_priv.flip = ctrl->value;
2477 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2479 const struct v4l2_queryctrl *qctrl;
2480 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2481 struct sensor *sensor = to_sensor(client);
2483 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2487 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2491 switch (ext_ctrl->id)
2493 case V4L2_CID_SCENE:
2495 ext_ctrl->value = sensor->info_priv.scene;
2498 case V4L2_CID_EFFECT:
2500 ext_ctrl->value = sensor->info_priv.effect;
2503 case V4L2_CID_ZOOM_ABSOLUTE:
2505 ext_ctrl->value = sensor->info_priv.digitalzoom;
2508 case V4L2_CID_ZOOM_RELATIVE:
2512 case V4L2_CID_FOCUS_ABSOLUTE:
2514 ext_ctrl->value = sensor->info_priv.focus;
2517 case V4L2_CID_FOCUS_RELATIVE:
2521 case V4L2_CID_FLASH:
2523 ext_ctrl->value = sensor->info_priv.flash;
2531 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2533 const struct v4l2_queryctrl *qctrl;
2534 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2535 struct sensor *sensor = to_sensor(client);
2538 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2542 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2547 switch (ext_ctrl->id)
2549 #if CONFIG_SENSOR_Scene
2550 case V4L2_CID_SCENE:
2552 if (ext_ctrl->value != sensor->info_priv.scene)
2554 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2556 sensor->info_priv.scene = ext_ctrl->value;
2561 #if CONFIG_SENSOR_Effect
2562 case V4L2_CID_EFFECT:
2564 if (ext_ctrl->value != sensor->info_priv.effect)
2566 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2568 sensor->info_priv.effect= ext_ctrl->value;
2573 #if CONFIG_SENSOR_DigitalZoom
2574 case V4L2_CID_ZOOM_ABSOLUTE:
2576 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2579 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2581 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2583 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2585 sensor->info_priv.digitalzoom += val_offset;
2587 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2592 case V4L2_CID_ZOOM_RELATIVE:
2594 if (ext_ctrl->value)
2596 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2598 sensor->info_priv.digitalzoom += ext_ctrl->value;
2600 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2605 #if CONFIG_SENSOR_Focus
2606 case V4L2_CID_FOCUS_ABSOLUTE:
2608 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2611 if (ext_ctrl->value != sensor->info_priv.focus)
2613 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2615 sensor->info_priv.focus += val_offset;
2620 case V4L2_CID_FOCUS_RELATIVE:
2622 if (ext_ctrl->value)
2624 sensor->info_priv.focus += ext_ctrl->value;
2626 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2631 #if CONFIG_SENSOR_Flash
2632 case V4L2_CID_FLASH:
2634 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2636 sensor->info_priv.flash = ext_ctrl->value;
2638 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2649 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2651 struct i2c_client *client = v4l2_get_subdevdata(sd);
2652 struct soc_camera_device *icd = client->dev.platform_data;
2653 int i, error_cnt=0, error_idx=-1;
2656 for (i=0; i<ext_ctrl->count; i++) {
2657 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2664 error_idx = ext_ctrl->count;
2666 if (error_idx != -1) {
2667 ext_ctrl->error_idx = error_idx;
2674 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2676 struct i2c_client *client = v4l2_get_subdevdata(sd);
2677 struct soc_camera_device *icd = client->dev.platform_data;
2678 int i, error_cnt=0, error_idx=-1;
2681 for (i=0; i<ext_ctrl->count; i++) {
2682 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2689 error_idx = ext_ctrl->count;
2691 if (error_idx != -1) {
2692 ext_ctrl->error_idx = error_idx;
2699 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2700 * this wasn't our capture interface, so, we wait for the right one */
2701 static int sensor_video_probe(struct soc_camera_device *icd,
2702 struct i2c_client *client)
2706 struct sensor *sensor = to_sensor(client);
2708 /* We must have a parent by now. And it cannot be a wrong one.
2709 * So this entire test is completely redundant. */
2710 if (!icd->dev.parent ||
2711 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2714 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2716 goto sensor_video_probe_err;
2720 /* ret = sensor_write(client, 0x12, 0x80);
2723 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2726 mdelay(50); *///delay 5 microseconds
2728 /* check if it is an sensor sensor */
2729 ret = sensor_read(client, 0x00, &pid);
2731 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2733 goto sensor_video_probe_err;
2736 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2737 if (pid == SENSOR_ID) {
2738 sensor->model = SENSOR_V4L2_IDENT;
2740 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2742 goto sensor_video_probe_err;
2747 sensor_video_probe_err:
2752 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2754 struct i2c_client *client = v4l2_get_subdevdata(sd);
2755 struct soc_camera_device *icd = client->dev.platform_data;
2756 struct sensor *sensor = to_sensor(client);
2758 #if CONFIG_SENSOR_Flash
2762 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2765 case RK29_CAM_SUBDEV_DEACTIVATE:
2767 sensor_deactivate(client);
2771 case RK29_CAM_SUBDEV_IOREQUEST:
2773 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2774 if (sensor->sensor_io_request != NULL) {
2775 sensor->sensor_gpio_res = NULL;
2776 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2777 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2778 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2779 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2782 if (sensor->sensor_gpio_res == NULL) {
2783 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2785 goto sensor_ioctl_end;
2788 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2790 goto sensor_ioctl_end;
2792 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2794 #if CONFIG_SENSOR_Flash
2795 if (sensor->sensor_gpio_res) {
2796 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2797 for (i = 0; i < icd->ops->num_controls; i++) {
2798 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2799 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2800 sensor_controls[i].id=0xffff;
2803 sensor->info_priv.flash = 0xff;
2804 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2805 }else{ //two cameras are the same,need to deal diffrently ,zyc
2806 for (i = 0; i < icd->ops->num_controls; i++) {
2807 if(0xffff == icd->ops->controls[i].id){
2808 sensor_controls[i].id=V4L2_CID_FLASH;
2818 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2826 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2827 enum v4l2_mbus_pixelcode *code)
2829 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2832 *code = sensor_colour_fmts[index].code;
2835 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2836 .init = sensor_init,
2837 .g_ctrl = sensor_g_control,
2838 .s_ctrl = sensor_s_control,
2839 .g_ext_ctrls = sensor_g_ext_controls,
2840 .s_ext_ctrls = sensor_s_ext_controls,
2841 .g_chip_ident = sensor_g_chip_ident,
2842 .ioctl = sensor_ioctl,
2845 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2846 .s_mbus_fmt = sensor_s_fmt,
2847 .g_mbus_fmt = sensor_g_fmt,
2848 .try_mbus_fmt = sensor_try_fmt,
2849 .enum_mbus_fmt = sensor_enum_fmt,
2852 static struct v4l2_subdev_ops sensor_subdev_ops = {
2853 .core = &sensor_subdev_core_ops,
2854 .video = &sensor_subdev_video_ops,
2857 static int sensor_probe(struct i2c_client *client,
2858 const struct i2c_device_id *did)
2860 struct sensor *sensor;
2861 struct soc_camera_device *icd = client->dev.platform_data;
2862 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2863 struct soc_camera_link *icl;
2866 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2868 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2872 icl = to_soc_camera_link(icd);
2874 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2878 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2879 dev_warn(&adapter->dev,
2880 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2884 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2888 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2890 /* Second stage probe - when a capture adapter is there */
2891 icd->ops = &sensor_ops;
2893 sensor->info_priv.fmt = sensor_colour_fmts[0];
2895 #if CONFIG_SENSOR_I2C_NOSCHED
2896 atomic_set(&sensor->tasklock_cnt,0);
2899 ret = sensor_video_probe(icd, client);
2902 i2c_set_clientdata(client, NULL);
2906 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2907 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2911 static int sensor_remove(struct i2c_client *client)
2913 struct sensor *sensor = to_sensor(client);
2914 struct soc_camera_device *icd = client->dev.platform_data;
2917 i2c_set_clientdata(client, NULL);
2918 client->driver = NULL;
2924 static const struct i2c_device_id sensor_id[] = {
2925 {SENSOR_NAME_STRING(), 0 },
2928 MODULE_DEVICE_TABLE(i2c, sensor_id);
2930 static struct i2c_driver sensor_i2c_driver = {
2932 .name = SENSOR_NAME_STRING(),
2934 .probe = sensor_probe,
2935 .remove = sensor_remove,
2936 .id_table = sensor_id,
2939 static int __init sensor_mod_init(void)
2941 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2942 return i2c_add_driver(&sensor_i2c_driver);
2945 static void __exit sensor_mod_exit(void)
2947 i2c_del_driver(&sensor_i2c_driver);
2950 device_initcall_sync(sensor_mod_init);
2951 module_exit(sensor_mod_exit);
2953 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2954 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2955 MODULE_LICENSE("GPL");