2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #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_GC0309
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_GC0309
48 #define SENSOR_ID 0xa0
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
51 #define SENSOR_MAX_WIDTH 640
52 #define SENSOR_MAX_HEIGHT 480
53 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT 480
55 #define SENSOR_INIT_WINSEQADR sensor_vga
56 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
58 #define CONFIG_SENSOR_WhiteBalance 1
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 1
63 #define CONFIG_SENSOR_Scene 1
64 #define CONFIG_SENSOR_DigitalZoom 0
65 #define CONFIG_SENSOR_Focus 0
66 #define CONFIG_SENSOR_Exposure 0
67 #define CONFIG_SENSOR_Flash 1
68 #define CONFIG_SENSOR_Mirror 0
69 #define CONFIG_SENSOR_Flip 0
71 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
72 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
73 #define CONFIG_SENSOR_I2C_NOSCHED 0
74 #define CONFIG_SENSOR_I2C_RDWRCHK 0
76 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|\
77 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
78 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
80 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
81 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
82 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
83 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
84 #define COLOR_TEMPERATURE_OFFICE_DN 3500
85 #define COLOR_TEMPERATURE_OFFICE_UP 5000
86 #define COLOR_TEMPERATURE_HOME_DN 2500
87 #define COLOR_TEMPERATURE_HOME_UP 3500
89 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
90 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
92 #define SENSOR_AF_IS_ERR (0x00<<0)
93 #define SENSOR_AF_IS_OK (0x01<<0)
94 #define SENSOR_INIT_IS_ERR (0x00<<28)
95 #define SENSOR_INIT_IS_OK (0x01<<28)
102 //flash off in fixed time to prevent from too hot , zyc
104 struct soc_camera_device *icd;
105 struct hrtimer timer;
107 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
109 static struct flash_timer flash_off_timer;
110 //for user defined if user want to customize the series , zyc
111 #ifdef CONFIG_GC0309_USER_DEFINED_SERIES
112 #include "gc0309_user_series.c"
114 /* init SVGA preview */
115 static struct reginfo sensor_init_data[] =
117 /*init registers code.*/
119 {0xfe,0x80}, // soft reset
122 {0xd2,0x10}, // close AEC
123 {0x22,0x55}, // close AWB
173 /////////////////////////////////////////////////////////////////////
174 /////////////////////////// grab_t ////////////////////////////////
175 /////////////////////////////////////////////////////////////////////
195 /////////////////////////////////////////////////////////////////////
196 /////////////////////////// LSC_t ////////////////////////////////
197 /////////////////////////////////////////////////////////////////////
209 /////////////////////////////////////////////////////////////////////
210 /////////////////////////// DNDD_t ///////////////////////////////
211 /////////////////////////////////////////////////////////////////////
220 /////////////////////////////////////////////////////////////////////
221 /////////////////////////// asde_t ///////////////////////////////
222 /////////////////////////////////////////////////////////////////////
232 /////////////////////////////////////////////////////////////////////
233 /////////////////////////// eeintp_t///////////////////////////////
234 /////////////////////////////////////////////////////////////////////
237 //for high resolution in light scene
249 /////////////////////////////////////////////////////////////////////
250 ///////////////////////////CC_t///////////////////////////////
251 /////////////////////////////////////////////////////////////////////
264 /////////////////////////////////////////////////////////////////////
265 ///////////////////////////YCP_t///////////////////////////////
266 /////////////////////////////////////////////////////////////////////
272 /////////////////////////////////////////////////////////////////////
273 ///////////////////////////AEC_t///////////////////////////////
274 /////////////////////////////////////////////////////////////////////
308 /////////////////////////////////////////////////////////////////
309 /////////////////////////// ABS_t ///////////////////////////////
310 /////////////////////////////////////////////////////////////////
316 /////////////////////////////////////////////////////////////////
317 /////////////////////////// Measure Window ///////////////////////
318 /////////////////////////////////////////////////////////////////
325 {0xfe,0x80}, // soft reset
328 {0xd2,0x10}, // close AEC
329 {0x22,0x55}, // close AWB
380 /////////////////////////////////////////////////////////////////////
381 /////////////////////////// grab_t ////////////////////////////////
382 /////////////////////////////////////////////////////////////////////
402 /////////////////////////////////////////////////////////////////////
403 /////////////////////////// LSC_t ////////////////////////////////
404 /////////////////////////////////////////////////////////////////////
416 /////////////////////////////////////////////////////////////////////
417 /////////////////////////// DNDD_t ///////////////////////////////
418 /////////////////////////////////////////////////////////////////////
427 /////////////////////////////////////////////////////////////////////
428 /////////////////////////// asde_t ///////////////////////////////
429 /////////////////////////////////////////////////////////////////////
439 /////////////////////////////////////////////////////////////////////
440 /////////////////////////// eeintp_t///////////////////////////////
458 static struct reginfo sensor_vga[] =
460 //{0x45 , 0x0f}, //output enable
461 {0x15 , 0x0a}, //output enable
466 static struct reginfo sensor_cif[] =
470 static struct reginfo sensor_qvga[] =
474 static struct reginfo sensor_qcif[] =
478 static struct reginfo sensor_ClrFmt_YUYV[]=
484 static struct reginfo sensor_ClrFmt_UYVY[]=
490 #if CONFIG_SENSOR_WhiteBalance
491 static struct reginfo sensor_WhiteB_Auto[]=
493 {0x5a,0x56}, //for AWB can adjust back
496 {0x22,0x57}, // Enable AWB
499 /* Cloudy Colour Temperature : 6500K - 8000K */
500 static struct reginfo sensor_WhiteB_Cloudy[]=
502 {0x22,0x55}, // Disable AWB
503 {0x5a,0x8c}, //WB_manual_gain
508 /* ClearDay Colour Temperature : 5000K - 6500K */
509 static struct reginfo sensor_WhiteB_ClearDay[]=
518 /* Office Colour Temperature : 3500K - 5000K */
519 static struct reginfo sensor_WhiteB_Incandescent[]=
529 /* Home Colour Temperature : 2500K - 3500K */
530 static struct reginfo sensor_WhiteB_Fluorescent[]=
539 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_Incandescent,sensor_WhiteB_Fluorescent,
540 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
544 #if CONFIG_SENSOR_Brightness
545 static struct reginfo sensor_Brightness0[]=
552 static struct reginfo sensor_Brightness1[]=
559 static struct reginfo sensor_Brightness2[]=
566 static struct reginfo sensor_Brightness3[]=
573 static struct reginfo sensor_Brightness4[]=
580 static struct reginfo sensor_Brightness5[]=
586 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
587 sensor_Brightness4, sensor_Brightness5,NULL,
592 #if CONFIG_SENSOR_Effect
593 static struct reginfo sensor_Effect_Normal[] =
609 static struct reginfo sensor_Effect_WandB[] =
626 static struct reginfo sensor_Effect_Sepia[] =
641 static struct reginfo sensor_Effect_Negative[] =
656 static struct reginfo sensor_Effect_Bluish[] =
672 static struct reginfo sensor_Effect_Green[] =
689 static struct reginfo sensor_Effect_Grayscale[]=
704 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
705 sensor_Effect_Bluish, sensor_Effect_Green,sensor_Effect_Grayscale,NULL,
708 #if CONFIG_SENSOR_Exposure
709 static struct reginfo sensor_Exposure0[]=
715 static struct reginfo sensor_Exposure1[]=
722 static struct reginfo sensor_Exposure2[]=
729 static struct reginfo sensor_Exposure3[]=
736 static struct reginfo sensor_Exposure4[]=
743 static struct reginfo sensor_Exposure5[]=
750 static struct reginfo sensor_Exposure6[]=
757 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
758 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
761 #if CONFIG_SENSOR_Saturation
762 static struct reginfo sensor_Saturation0[]=
768 static struct reginfo sensor_Saturation1[]=
774 static struct reginfo sensor_Saturation2[]=
779 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
782 #if CONFIG_SENSOR_Contrast
783 static struct reginfo sensor_Contrast0[]=
790 static struct reginfo sensor_Contrast1[]=
797 static struct reginfo sensor_Contrast2[]=
804 static struct reginfo sensor_Contrast3[]=
811 static struct reginfo sensor_Contrast4[]=
819 static struct reginfo sensor_Contrast5[]=
826 static struct reginfo sensor_Contrast6[]=
832 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
833 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
837 #if CONFIG_SENSOR_Mirror
838 static struct reginfo sensor_MirrorOn[]=
844 static struct reginfo sensor_MirrorOff[]=
849 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
851 #if CONFIG_SENSOR_Flip
852 static struct reginfo sensor_FlipOn[]=
858 static struct reginfo sensor_FlipOff[]=
863 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
866 #if CONFIG_SENSOR_Scene
867 static struct reginfo sensor_SceneAuto[] =
869 #if 0 /* ddl@rock-chips.com : */
877 {0x20 ,0x7f}, // close cc
886 static struct reginfo sensor_SceneNight[] =
889 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
891 {0x20 ,0x5f}, // close cc
898 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
914 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
917 #if CONFIG_SENSOR_DigitalZoom
918 static struct reginfo sensor_Zoom0[] =
923 static struct reginfo sensor_Zoom1[] =
928 static struct reginfo sensor_Zoom2[] =
934 static struct reginfo sensor_Zoom3[] =
938 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
940 static const struct v4l2_querymenu sensor_menus[] =
942 #if CONFIG_SENSOR_WhiteBalance
943 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
944 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
945 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
948 #if CONFIG_SENSOR_Effect
949 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
950 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
951 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
952 { .id = V4L2_CID_EFFECT, .index = 6, .name = "grayscale", .reserved = 0,},
955 #if CONFIG_SENSOR_Scene
956 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
959 #if CONFIG_SENSOR_Flash
960 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
961 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
965 static struct v4l2_queryctrl sensor_controls[] =
967 #if CONFIG_SENSOR_WhiteBalance
969 .id = V4L2_CID_DO_WHITE_BALANCE,
970 .type = V4L2_CTRL_TYPE_MENU,
971 .name = "White Balance Control",
979 #if CONFIG_SENSOR_Brightness
981 .id = V4L2_CID_BRIGHTNESS,
982 .type = V4L2_CTRL_TYPE_INTEGER,
983 .name = "Brightness Control",
991 #if CONFIG_SENSOR_Effect
993 .id = V4L2_CID_EFFECT,
994 .type = V4L2_CTRL_TYPE_MENU,
995 .name = "Effect Control",
1003 #if CONFIG_SENSOR_Exposure
1005 .id = V4L2_CID_EXPOSURE,
1006 .type = V4L2_CTRL_TYPE_INTEGER,
1007 .name = "Exposure Control",
1015 #if CONFIG_SENSOR_Saturation
1017 .id = V4L2_CID_SATURATION,
1018 .type = V4L2_CTRL_TYPE_INTEGER,
1019 .name = "Saturation Control",
1027 #if CONFIG_SENSOR_Contrast
1029 .id = V4L2_CID_CONTRAST,
1030 .type = V4L2_CTRL_TYPE_INTEGER,
1031 .name = "Contrast Control",
1039 #if CONFIG_SENSOR_Mirror
1041 .id = V4L2_CID_HFLIP,
1042 .type = V4L2_CTRL_TYPE_BOOLEAN,
1043 .name = "Mirror Control",
1051 #if CONFIG_SENSOR_Flip
1053 .id = V4L2_CID_VFLIP,
1054 .type = V4L2_CTRL_TYPE_BOOLEAN,
1055 .name = "Flip Control",
1063 #if CONFIG_SENSOR_Scene
1065 .id = V4L2_CID_SCENE,
1066 .type = V4L2_CTRL_TYPE_MENU,
1067 .name = "Scene Control",
1075 #if CONFIG_SENSOR_DigitalZoom
1077 .id = V4L2_CID_ZOOM_RELATIVE,
1078 .type = V4L2_CTRL_TYPE_INTEGER,
1079 .name = "DigitalZoom Control",
1085 .id = V4L2_CID_ZOOM_ABSOLUTE,
1086 .type = V4L2_CTRL_TYPE_INTEGER,
1087 .name = "DigitalZoom Control",
1095 #if CONFIG_SENSOR_Focus
1097 .id = V4L2_CID_FOCUS_RELATIVE,
1098 .type = V4L2_CTRL_TYPE_INTEGER,
1099 .name = "Focus Control",
1105 .id = V4L2_CID_FOCUS_ABSOLUTE,
1106 .type = V4L2_CTRL_TYPE_INTEGER,
1107 .name = "Focus Control",
1111 .default_value = 125,
1115 #if CONFIG_SENSOR_Flash
1117 .id = V4L2_CID_FLASH,
1118 .type = V4L2_CTRL_TYPE_MENU,
1119 .name = "Flash Control",
1128 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1129 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1130 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1131 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1132 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1133 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1134 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1135 static int sensor_resume(struct soc_camera_device *icd);
1136 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1137 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1138 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1139 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1140 static int sensor_deactivate(struct i2c_client *client);
1142 static struct soc_camera_ops sensor_ops =
1144 .suspend = sensor_suspend,
1145 .resume = sensor_resume,
1146 .set_bus_param = sensor_set_bus_param,
1147 .query_bus_param = sensor_query_bus_param,
1148 .controls = sensor_controls,
1149 .menus = sensor_menus,
1150 .num_controls = ARRAY_SIZE(sensor_controls),
1151 .num_menus = ARRAY_SIZE(sensor_menus),
1154 /* only one fixed colorspace per pixelcode */
1155 struct sensor_datafmt {
1156 enum v4l2_mbus_pixelcode code;
1157 enum v4l2_colorspace colorspace;
1160 /* Find a data format by a pixel code in an array */
1161 static const struct sensor_datafmt *sensor_find_datafmt(
1162 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1166 for (i = 0; i < n; i++)
1167 if (fmt[i].code == code)
1173 static const struct sensor_datafmt sensor_colour_fmts[] = {
1174 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1175 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1178 typedef struct sensor_info_priv_s
1192 unsigned char mirror; /* HFLIP */
1193 unsigned char flip; /* VFLIP */
1194 unsigned int winseqe_cur_addr;
1195 struct sensor_datafmt fmt;
1196 unsigned int funmodule_state;
1197 } sensor_info_priv_t;
1201 struct v4l2_subdev subdev;
1202 struct i2c_client *client;
1203 sensor_info_priv_t info_priv;
1204 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1205 #if CONFIG_SENSOR_I2C_NOSCHED
1206 atomic_t tasklock_cnt;
1208 struct rk29camera_platform_data *sensor_io_request;
1209 struct rk29camera_gpio_res *sensor_gpio_res;
1212 static struct sensor* to_sensor(const struct i2c_client *client)
1214 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1217 static int sensor_task_lock(struct i2c_client *client, int lock)
1219 #if CONFIG_SENSOR_I2C_NOSCHED
1221 struct sensor *sensor = to_sensor(client);
1224 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1225 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1226 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1230 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1231 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1232 goto sensor_task_lock_err;
1237 atomic_add(1, &sensor->tasklock_cnt);
1239 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1240 atomic_sub(1, &sensor->tasklock_cnt);
1242 if (atomic_read(&sensor->tasklock_cnt) == 0)
1247 sensor_task_lock_err:
1256 /* sensor register */
1257 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1261 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1263 return (ret > 0)? 0 : ret;
1266 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1270 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1272 return (ret > 0)? 0 : ret;
1275 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1279 struct i2c_msg msg[1];
1287 msg->addr = client->addr;
1288 msg->flags = client->flags;
1290 msg->len = sizeof(buf);
1291 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1292 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1297 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1298 err = i2c_transfer(client->adapter, msg, 1);
1303 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1311 /* sensor register read */
1312 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1316 struct i2c_msg msg[2];
1320 msg[0].addr = client->addr;
1321 msg[0].flags = client->flags;
1323 msg[0].len = sizeof(buf);
1324 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1325 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1327 msg[1].addr = client->addr;
1328 msg[1].flags = client->flags|I2C_M_RD;
1331 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1332 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1336 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1337 err = i2c_transfer(client->adapter, msg, 2);
1343 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1353 /* write a array of registers */
1354 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1358 #if CONFIG_SENSOR_I2C_RDWRCHK
1364 if (sensor_task_lock(client, 1) < 0)
1365 goto sensor_write_array_end;
1366 while (regarray[i].reg != 0)
1368 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1372 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1376 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1378 goto sensor_write_array_end;
1381 #if CONFIG_SENSOR_I2C_RDWRCHK
1383 sensor_read(client, regarray[i].reg, &valchk);
1384 if (valchk != regarray[i].val)
1385 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1391 sensor_write_array_end:
1392 sensor_task_lock(client,0);
1395 #if CONFIG_SENSOR_I2C_RDWRCHK
1396 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1404 while (regarray[i].reg != 0)
1406 sensor_read(client, regarray[i].reg, &valchk);
1407 if (valchk != regarray[i].val)
1408 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1415 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1417 struct soc_camera_link *icl = to_soc_camera_link(icd);
1420 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1423 case Sensor_PowerDown:
1425 if (icl->powerdown) {
1426 ret = icl->powerdown(icd->pdev, on);
1427 if (ret == RK29_CAM_IO_SUCCESS) {
1431 icl->reset(icd->pdev);
1433 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1435 goto sensor_power_end;
1442 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1443 struct sensor *sensor = to_sensor(client);
1445 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1446 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1448 //flash off after 2 secs
1449 hrtimer_cancel(&(flash_off_timer.timer));
1450 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1457 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1465 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1466 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1467 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1468 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1472 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1474 struct i2c_client *client = v4l2_get_subdevdata(sd);
1475 struct soc_camera_device *icd = client->dev.platform_data;
1476 struct sensor *sensor = to_sensor(client);
1477 const struct v4l2_queryctrl *qctrl;
1478 const struct sensor_datafmt *fmt;
1482 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1484 goto sensor_INIT_ERR;
1488 if (sensor_task_lock(client,1)<0)
1489 goto sensor_INIT_ERR;
1490 ret = sensor_write(client, 0xfe, 0x80);
1493 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1495 goto sensor_INIT_ERR;
1498 mdelay(5); //delay 5 microseconds
1499 /* check if it is an sensor sensor */
1500 ret = sensor_read(client, 0x00, &value);
1502 SENSOR_TR("read chip id high byte failed\n");
1504 goto sensor_INIT_ERR;
1507 if (value == SENSOR_ID) {
1508 sensor->model = SENSOR_V4L2_IDENT;
1510 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
1512 goto sensor_INIT_ERR;
1515 ret = sensor_write_array(client, sensor_init_data);
1518 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1519 goto sensor_INIT_ERR;
1521 sensor_task_lock(client,0);
1523 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1524 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1526 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1528 goto sensor_INIT_ERR;
1530 sensor->info_priv.fmt = *fmt;
1532 /* sensor sensor information for initialization */
1533 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1535 sensor->info_priv.whiteBalance = qctrl->default_value;
1536 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1538 sensor->info_priv.brightness = qctrl->default_value;
1539 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1541 sensor->info_priv.effect = qctrl->default_value;
1542 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1544 sensor->info_priv.exposure = qctrl->default_value;
1546 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1548 sensor->info_priv.saturation = qctrl->default_value;
1549 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1551 sensor->info_priv.contrast = qctrl->default_value;
1552 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1554 sensor->info_priv.mirror = qctrl->default_value;
1555 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1557 sensor->info_priv.flip = qctrl->default_value;
1558 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1560 sensor->info_priv.scene = qctrl->default_value;
1561 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1563 sensor->info_priv.digitalzoom = qctrl->default_value;
1565 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1566 #if CONFIG_SENSOR_Focus
1567 //sensor_set_focus();
1568 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1570 sensor->info_priv.focus = qctrl->default_value;
1573 #if CONFIG_SENSOR_Flash
1574 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1576 sensor->info_priv.flash = qctrl->default_value;
1577 flash_off_timer.icd = icd;
1578 flash_off_timer.timer.function = flash_off_func;
1581 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);
1582 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1585 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1586 sensor_task_lock(client,0);
1587 sensor_deactivate(client);
1591 static int sensor_deactivate(struct i2c_client *client)
1593 struct soc_camera_device *icd = client->dev.platform_data;
1594 struct sensor *sensor = to_sensor(client);
1595 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1597 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1598 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1601 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1602 icd->user_width = SENSOR_INIT_WIDTH;
1603 icd->user_height = SENSOR_INIT_HEIGHT;
1604 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1609 static struct reginfo sensor_power_down_sequence[]=
1613 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1616 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1618 if (pm_msg.event == PM_EVENT_SUSPEND) {
1619 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1620 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1622 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1625 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1627 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1632 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1638 static int sensor_resume(struct soc_camera_device *icd)
1642 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1644 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1648 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1654 static int sensor_set_bus_param(struct soc_camera_device *icd,
1655 unsigned long flags)
1661 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1663 struct soc_camera_link *icl = to_soc_camera_link(icd);
1664 unsigned long flags = SENSOR_BUS_PARAM;
1666 return soc_camera_apply_sensor_flags(icl, flags);
1669 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1671 struct i2c_client *client = v4l2_get_subdevdata(sd);
1672 struct soc_camera_device *icd = client->dev.platform_data;
1673 struct sensor *sensor = to_sensor(client);
1675 mf->width = icd->user_width;
1676 mf->height = icd->user_height;
1677 mf->code = sensor->info_priv.fmt.code;
1678 mf->colorspace = sensor->info_priv.fmt.colorspace;
1679 mf->field = V4L2_FIELD_NONE;
1683 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1687 if ((mf->width == 1024) && (mf->height == 768)) {
1689 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1691 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1693 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1695 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1700 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1704 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1708 if ((mf->width == 1280) && (mf->height == 720)) {
1710 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1715 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1718 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1720 struct i2c_client *client = v4l2_get_subdevdata(sd);
1721 const struct sensor_datafmt *fmt;
1722 struct sensor *sensor = to_sensor(client);
1723 const struct v4l2_queryctrl *qctrl;
1724 struct soc_camera_device *icd = client->dev.platform_data;
1725 struct reginfo *winseqe_set_addr=NULL;
1726 int ret=0, set_w,set_h;
1728 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1729 ARRAY_SIZE(sensor_colour_fmts));
1732 goto sensor_s_fmt_end;
1735 if (sensor->info_priv.fmt.code != mf->code) {
1738 case V4L2_MBUS_FMT_YUYV8_2X8:
1740 winseqe_set_addr = sensor_ClrFmt_YUYV;
1743 case V4L2_MBUS_FMT_UYVY8_2X8:
1745 winseqe_set_addr = sensor_ClrFmt_UYVY;
1751 if (winseqe_set_addr != NULL) {
1752 sensor_write_array(client, winseqe_set_addr);
1753 sensor->info_priv.fmt.code = mf->code;
1754 sensor->info_priv.fmt.colorspace= mf->colorspace;
1755 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1757 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1764 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1766 winseqe_set_addr = sensor_qcif;
1770 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1772 winseqe_set_addr = sensor_qvga;
1776 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1778 winseqe_set_addr = sensor_cif;
1782 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1784 winseqe_set_addr = sensor_vga;
1791 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1792 set_w = SENSOR_INIT_WIDTH;
1793 set_h = SENSOR_INIT_HEIGHT;
1794 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1797 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1798 #if CONFIG_SENSOR_Flash
1799 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1800 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1801 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1802 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1804 } else { /* ddl@rock-chips.com : Video */
1805 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1806 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1807 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1811 ret |= sensor_write_array(client, winseqe_set_addr);
1813 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1814 #if CONFIG_SENSOR_Flash
1815 if (sensor_fmt_capturechk(sd,mf) == true) {
1816 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1817 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1818 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1822 goto sensor_s_fmt_end;
1825 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1827 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1828 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1829 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1830 if (sensor->info_priv.whiteBalance != 0) {
1831 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1832 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1834 sensor->info_priv.snap2preview = true;
1835 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1836 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1837 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1838 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1839 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1840 sensor->info_priv.video2preview = true;
1841 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1842 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1843 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1844 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1845 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1846 sensor->info_priv.video2preview = false;
1847 sensor->info_priv.snap2preview = false;
1849 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1851 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1861 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1863 struct i2c_client *client = v4l2_get_subdevdata(sd);
1864 struct sensor *sensor = to_sensor(client);
1865 const struct sensor_datafmt *fmt;
1866 int ret = 0,set_w,set_h;
1868 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1869 ARRAY_SIZE(sensor_colour_fmts));
1871 fmt = &sensor->info_priv.fmt;
1872 mf->code = fmt->code;
1875 if (mf->height > SENSOR_MAX_HEIGHT)
1876 mf->height = SENSOR_MAX_HEIGHT;
1877 else if (mf->height < SENSOR_MIN_HEIGHT)
1878 mf->height = SENSOR_MIN_HEIGHT;
1880 if (mf->width > SENSOR_MAX_WIDTH)
1881 mf->width = SENSOR_MAX_WIDTH;
1882 else if (mf->width < SENSOR_MIN_WIDTH)
1883 mf->width = SENSOR_MIN_WIDTH;
1888 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1893 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1898 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1903 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1911 set_w = SENSOR_INIT_WIDTH;
1912 set_h = SENSOR_INIT_HEIGHT;
1916 mf->colorspace = fmt->colorspace;
1921 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1923 struct i2c_client *client = v4l2_get_subdevdata(sd);
1925 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1928 if (id->match.addr != client->addr)
1931 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1936 #if CONFIG_SENSOR_Brightness
1937 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1939 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1941 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1943 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1945 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1947 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1950 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1954 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1958 #if CONFIG_SENSOR_Effect
1959 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1961 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1963 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1965 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1967 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1969 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1972 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1976 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1980 #if CONFIG_SENSOR_Exposure
1981 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1983 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1985 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1987 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1989 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1991 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1994 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1998 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2002 #if CONFIG_SENSOR_Saturation
2003 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2005 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2007 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2009 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2011 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2013 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2016 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2020 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2024 #if CONFIG_SENSOR_Contrast
2025 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2027 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2029 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2031 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2033 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2035 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2038 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2042 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2046 #if CONFIG_SENSOR_Mirror
2047 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2049 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2051 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2053 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2055 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2057 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2060 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2064 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2068 #if CONFIG_SENSOR_Flip
2069 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2071 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2073 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2075 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2077 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2079 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2082 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2086 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2090 #if CONFIG_SENSOR_Scene
2091 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2093 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2095 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2097 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2099 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2101 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2104 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2108 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2112 #if CONFIG_SENSOR_WhiteBalance
2113 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2115 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2117 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2119 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2121 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2123 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2126 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2130 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2134 #if CONFIG_SENSOR_DigitalZoom
2135 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2137 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2138 struct sensor *sensor = to_sensor(client);
2139 const struct v4l2_queryctrl *qctrl_info;
2140 int digitalzoom_cur, digitalzoom_total;
2142 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2146 digitalzoom_cur = sensor->info_priv.digitalzoom;
2147 digitalzoom_total = qctrl_info->maximum;
2149 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2151 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2155 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2157 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2161 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2163 value = digitalzoom_total - digitalzoom_cur;
2166 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2168 value = 0 - digitalzoom_cur;
2171 digitalzoom_cur += value;
2173 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2175 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2177 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2180 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2187 #if CONFIG_SENSOR_Flash
2188 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2190 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2191 if (value == 3) { /* ddl@rock-chips.com: torch */
2192 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2194 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2196 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2200 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2205 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2207 struct i2c_client *client = v4l2_get_subdevdata(sd);
2208 struct sensor *sensor = to_sensor(client);
2209 const struct v4l2_queryctrl *qctrl;
2211 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2215 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2221 case V4L2_CID_BRIGHTNESS:
2223 ctrl->value = sensor->info_priv.brightness;
2226 case V4L2_CID_SATURATION:
2228 ctrl->value = sensor->info_priv.saturation;
2231 case V4L2_CID_CONTRAST:
2233 ctrl->value = sensor->info_priv.contrast;
2236 case V4L2_CID_DO_WHITE_BALANCE:
2238 ctrl->value = sensor->info_priv.whiteBalance;
2241 case V4L2_CID_EXPOSURE:
2243 ctrl->value = sensor->info_priv.exposure;
2246 case V4L2_CID_HFLIP:
2248 ctrl->value = sensor->info_priv.mirror;
2251 case V4L2_CID_VFLIP:
2253 ctrl->value = sensor->info_priv.flip;
2264 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2266 struct i2c_client *client = v4l2_get_subdevdata(sd);
2267 struct sensor *sensor = to_sensor(client);
2268 struct soc_camera_device *icd = client->dev.platform_data;
2269 const struct v4l2_queryctrl *qctrl;
2272 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2276 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2282 #if CONFIG_SENSOR_Brightness
2283 case V4L2_CID_BRIGHTNESS:
2285 if (ctrl->value != sensor->info_priv.brightness)
2287 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2291 sensor->info_priv.brightness = ctrl->value;
2296 #if CONFIG_SENSOR_Exposure
2297 case V4L2_CID_EXPOSURE:
2299 if (ctrl->value != sensor->info_priv.exposure)
2301 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2305 sensor->info_priv.exposure = ctrl->value;
2310 #if CONFIG_SENSOR_Saturation
2311 case V4L2_CID_SATURATION:
2313 if (ctrl->value != sensor->info_priv.saturation)
2315 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2319 sensor->info_priv.saturation = ctrl->value;
2324 #if CONFIG_SENSOR_Contrast
2325 case V4L2_CID_CONTRAST:
2327 if (ctrl->value != sensor->info_priv.contrast)
2329 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2333 sensor->info_priv.contrast = ctrl->value;
2338 #if CONFIG_SENSOR_WhiteBalance
2339 case V4L2_CID_DO_WHITE_BALANCE:
2341 if (ctrl->value != sensor->info_priv.whiteBalance)
2343 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2347 sensor->info_priv.whiteBalance = ctrl->value;
2352 #if CONFIG_SENSOR_Mirror
2353 case V4L2_CID_HFLIP:
2355 if (ctrl->value != sensor->info_priv.mirror)
2357 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2359 sensor->info_priv.mirror = ctrl->value;
2364 #if CONFIG_SENSOR_Flip
2365 case V4L2_CID_VFLIP:
2367 if (ctrl->value != sensor->info_priv.flip)
2369 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2371 sensor->info_priv.flip = ctrl->value;
2382 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2384 const struct v4l2_queryctrl *qctrl;
2385 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2386 struct sensor *sensor = to_sensor(client);
2388 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2392 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2396 switch (ext_ctrl->id)
2398 case V4L2_CID_SCENE:
2400 ext_ctrl->value = sensor->info_priv.scene;
2403 case V4L2_CID_EFFECT:
2405 ext_ctrl->value = sensor->info_priv.effect;
2408 case V4L2_CID_ZOOM_ABSOLUTE:
2410 ext_ctrl->value = sensor->info_priv.digitalzoom;
2413 case V4L2_CID_ZOOM_RELATIVE:
2417 case V4L2_CID_FOCUS_ABSOLUTE:
2419 ext_ctrl->value = sensor->info_priv.focus;
2422 case V4L2_CID_FOCUS_RELATIVE:
2426 case V4L2_CID_FLASH:
2428 ext_ctrl->value = sensor->info_priv.flash;
2436 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2438 const struct v4l2_queryctrl *qctrl;
2439 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2440 struct sensor *sensor = to_sensor(client);
2443 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2447 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2452 switch (ext_ctrl->id)
2454 #if CONFIG_SENSOR_Scene
2455 case V4L2_CID_SCENE:
2457 if (ext_ctrl->value != sensor->info_priv.scene)
2459 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2461 sensor->info_priv.scene = ext_ctrl->value;
2466 #if CONFIG_SENSOR_Effect
2467 case V4L2_CID_EFFECT:
2469 if (ext_ctrl->value != sensor->info_priv.effect)
2471 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2473 sensor->info_priv.effect= ext_ctrl->value;
2478 #if CONFIG_SENSOR_DigitalZoom
2479 case V4L2_CID_ZOOM_ABSOLUTE:
2481 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2484 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2486 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2488 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2490 sensor->info_priv.digitalzoom += val_offset;
2492 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2497 case V4L2_CID_ZOOM_RELATIVE:
2499 if (ext_ctrl->value)
2501 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2503 sensor->info_priv.digitalzoom += ext_ctrl->value;
2505 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2510 #if CONFIG_SENSOR_Focus
2511 case V4L2_CID_FOCUS_ABSOLUTE:
2513 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2516 if (ext_ctrl->value != sensor->info_priv.focus)
2518 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2520 sensor->info_priv.focus += val_offset;
2525 case V4L2_CID_FOCUS_RELATIVE:
2527 if (ext_ctrl->value)
2529 sensor->info_priv.focus += ext_ctrl->value;
2531 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2536 #if CONFIG_SENSOR_Flash
2537 case V4L2_CID_FLASH:
2539 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2541 sensor->info_priv.flash = ext_ctrl->value;
2543 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2554 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2556 struct i2c_client *client = v4l2_get_subdevdata(sd);
2557 struct soc_camera_device *icd = client->dev.platform_data;
2558 int i, error_cnt=0, error_idx=-1;
2561 for (i=0; i<ext_ctrl->count; i++) {
2562 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2569 error_idx = ext_ctrl->count;
2571 if (error_idx != -1) {
2572 ext_ctrl->error_idx = error_idx;
2579 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2581 struct i2c_client *client = v4l2_get_subdevdata(sd);
2582 struct soc_camera_device *icd = client->dev.platform_data;
2583 int i, error_cnt=0, error_idx=-1;
2586 for (i=0; i<ext_ctrl->count; i++) {
2587 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2594 error_idx = ext_ctrl->count;
2596 if (error_idx != -1) {
2597 ext_ctrl->error_idx = error_idx;
2604 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2605 * this wasn't our capture interface, so, we wait for the right one */
2606 static int sensor_video_probe(struct soc_camera_device *icd,
2607 struct i2c_client *client)
2611 struct sensor *sensor = to_sensor(client);
2613 /* We must have a parent by now. And it cannot be a wrong one.
2614 * So this entire test is completely redundant. */
2615 if (!icd->dev.parent ||
2616 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2619 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2621 goto sensor_video_probe_err;
2625 ret = sensor_write(client, 0xfe, 0x80);
2628 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2631 mdelay(5); //delay 5 microseconds
2633 /* check if it is an sensor sensor */
2634 ret = sensor_read(client, 0x00, &value);
2636 SENSOR_TR("read chip id high byte failed\n");
2638 goto sensor_video_probe_err;
2641 if (value == SENSOR_ID) {
2642 sensor->model = SENSOR_V4L2_IDENT;
2643 SENSOR_TR("chip id:0x%x\n",value);
2645 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2647 goto sensor_video_probe_err;
2652 sensor_video_probe_err:
2656 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2658 struct i2c_client *client = v4l2_get_subdevdata(sd);
2659 struct soc_camera_device *icd = client->dev.platform_data;
2660 struct sensor *sensor = to_sensor(client);
2662 #if CONFIG_SENSOR_Flash
2666 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2669 case RK29_CAM_SUBDEV_DEACTIVATE:
2671 sensor_deactivate(client);
2675 case RK29_CAM_SUBDEV_IOREQUEST:
2677 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2678 if (sensor->sensor_io_request != NULL) {
2679 sensor->sensor_gpio_res = NULL;
2680 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2681 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2682 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2683 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2686 if (sensor->sensor_gpio_res == NULL) {
2687 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2689 goto sensor_ioctl_end;
2692 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2694 goto sensor_ioctl_end;
2696 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2698 #if CONFIG_SENSOR_Flash
2699 if (sensor->sensor_gpio_res) {
2700 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2701 for (i = 0; i < icd->ops->num_controls; i++) {
2702 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2703 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2704 sensor_controls[i].id=0xffff;
2707 sensor->info_priv.flash = 0xff;
2708 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2709 }else{ //two cameras are the same,need to deal diffrently ,zyc
2710 for (i = 0; i < icd->ops->num_controls; i++) {
2711 if(0xffff == icd->ops->controls[i].id){
2712 sensor_controls[i].id=V4L2_CID_FLASH;
2722 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2730 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2731 enum v4l2_mbus_pixelcode *code)
2733 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2736 *code = sensor_colour_fmts[index].code;
2739 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2740 .init = sensor_init,
2741 .g_ctrl = sensor_g_control,
2742 .s_ctrl = sensor_s_control,
2743 .g_ext_ctrls = sensor_g_ext_controls,
2744 .s_ext_ctrls = sensor_s_ext_controls,
2745 .g_chip_ident = sensor_g_chip_ident,
2746 .ioctl = sensor_ioctl,
2749 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2750 .s_mbus_fmt = sensor_s_fmt,
2751 .g_mbus_fmt = sensor_g_fmt,
2752 .try_mbus_fmt = sensor_try_fmt,
2753 .enum_mbus_fmt = sensor_enum_fmt,
2756 static struct v4l2_subdev_ops sensor_subdev_ops = {
2757 .core = &sensor_subdev_core_ops,
2758 .video = &sensor_subdev_video_ops,
2761 static int sensor_probe(struct i2c_client *client,
2762 const struct i2c_device_id *did)
2764 struct sensor *sensor;
2765 struct soc_camera_device *icd = client->dev.platform_data;
2766 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2767 struct soc_camera_link *icl;
2770 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2772 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2776 icl = to_soc_camera_link(icd);
2778 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2782 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2783 dev_warn(&adapter->dev,
2784 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2788 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2792 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2794 /* Second stage probe - when a capture adapter is there */
2795 icd->ops = &sensor_ops;
2797 sensor->info_priv.fmt = sensor_colour_fmts[0];
2799 #if CONFIG_SENSOR_I2C_NOSCHED
2800 atomic_set(&sensor->tasklock_cnt,0);
2803 ret = sensor_video_probe(icd, client);
2806 i2c_set_clientdata(client, NULL);
2810 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2811 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2815 static int sensor_remove(struct i2c_client *client)
2817 struct sensor *sensor = to_sensor(client);
2818 struct soc_camera_device *icd = client->dev.platform_data;
2821 i2c_set_clientdata(client, NULL);
2822 client->driver = NULL;
2828 static const struct i2c_device_id sensor_id[] = {
2829 {SENSOR_NAME_STRING(), 0 },
2832 MODULE_DEVICE_TABLE(i2c, sensor_id);
2834 static struct i2c_driver sensor_i2c_driver = {
2836 .name = SENSOR_NAME_STRING(),
2838 .probe = sensor_probe,
2839 .remove = sensor_remove,
2840 .id_table = sensor_id,
2843 static int __init sensor_mod_init(void)
2845 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2846 return i2c_add_driver(&sensor_i2c_driver);
2849 static void __exit sensor_mod_exit(void)
2851 i2c_del_driver(&sensor_i2c_driver);
2854 device_initcall_sync(sensor_mod_init);
2855 module_exit(sensor_mod_exit);
2857 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2858 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2859 MODULE_LICENSE("GPL");