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 <mach/rk29_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 0
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)
103 /* init SVGA preview */
104 static struct reginfo sensor_init_data[] =
106 /*init registers code.*/
108 {0xfe,0x80}, // soft reset
111 {0xd2,0x10}, // close AEC
112 {0x22,0x55}, // close AWB
162 /////////////////////////////////////////////////////////////////////
163 /////////////////////////// grab_t ////////////////////////////////
164 /////////////////////////////////////////////////////////////////////
184 /////////////////////////////////////////////////////////////////////
185 /////////////////////////// LSC_t ////////////////////////////////
186 /////////////////////////////////////////////////////////////////////
198 /////////////////////////////////////////////////////////////////////
199 /////////////////////////// DNDD_t ///////////////////////////////
200 /////////////////////////////////////////////////////////////////////
209 /////////////////////////////////////////////////////////////////////
210 /////////////////////////// asde_t ///////////////////////////////
211 /////////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////
222 /////////////////////////// eeintp_t///////////////////////////////
223 /////////////////////////////////////////////////////////////////////
226 //for high resolution in light scene
238 /////////////////////////////////////////////////////////////////////
239 ///////////////////////////CC_t///////////////////////////////
240 /////////////////////////////////////////////////////////////////////
253 /////////////////////////////////////////////////////////////////////
254 ///////////////////////////YCP_t///////////////////////////////
255 /////////////////////////////////////////////////////////////////////
261 /////////////////////////////////////////////////////////////////////
262 ///////////////////////////AEC_t///////////////////////////////
263 /////////////////////////////////////////////////////////////////////
297 /////////////////////////////////////////////////////////////////
298 /////////////////////////// ABS_t ///////////////////////////////
299 /////////////////////////////////////////////////////////////////
305 /////////////////////////////////////////////////////////////////
306 /////////////////////////// Measure Window ///////////////////////
307 /////////////////////////////////////////////////////////////////
314 {0xfe,0x80}, // soft reset
317 {0xd2,0x10}, // close AEC
318 {0x22,0x55}, // close AWB
369 /////////////////////////////////////////////////////////////////////
370 /////////////////////////// grab_t ////////////////////////////////
371 /////////////////////////////////////////////////////////////////////
391 /////////////////////////////////////////////////////////////////////
392 /////////////////////////// LSC_t ////////////////////////////////
393 /////////////////////////////////////////////////////////////////////
405 /////////////////////////////////////////////////////////////////////
406 /////////////////////////// DNDD_t ///////////////////////////////
407 /////////////////////////////////////////////////////////////////////
416 /////////////////////////////////////////////////////////////////////
417 /////////////////////////// asde_t ///////////////////////////////
418 /////////////////////////////////////////////////////////////////////
428 /////////////////////////////////////////////////////////////////////
429 /////////////////////////// eeintp_t///////////////////////////////
447 static struct reginfo sensor_vga[] =
449 //{0x45 , 0x0f}, //output enable
450 {0x15 , 0x0a}, //output enable
455 static struct reginfo sensor_cif[] =
459 static struct reginfo sensor_qvga[] =
463 static struct reginfo sensor_qcif[] =
467 static struct reginfo sensor_ClrFmt_YUYV[]=
473 static struct reginfo sensor_ClrFmt_UYVY[]=
479 #if CONFIG_SENSOR_WhiteBalance
480 static struct reginfo sensor_WhiteB_Auto[]=
482 {0x5a,0x56}, //for AWB can adjust back
485 {0x22,0x57}, // Enable AWB
488 /* Cloudy Colour Temperature : 6500K - 8000K */
489 static struct reginfo sensor_WhiteB_Cloudy[]=
491 {0x22,0x55}, // Disable AWB
492 {0x5a,0x8c}, //WB_manual_gain
497 /* ClearDay Colour Temperature : 5000K - 6500K */
498 static struct reginfo sensor_WhiteB_ClearDay[]=
507 /* Office Colour Temperature : 3500K - 5000K */
508 static struct reginfo sensor_WhiteB_Incandescent[]=
518 /* Home Colour Temperature : 2500K - 3500K */
519 static struct reginfo sensor_WhiteB_Fluorescent[]=
528 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_Incandescent,sensor_WhiteB_Fluorescent,
529 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
533 #if CONFIG_SENSOR_Brightness
534 static struct reginfo sensor_Brightness0[]=
541 static struct reginfo sensor_Brightness1[]=
548 static struct reginfo sensor_Brightness2[]=
555 static struct reginfo sensor_Brightness3[]=
562 static struct reginfo sensor_Brightness4[]=
569 static struct reginfo sensor_Brightness5[]=
575 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
576 sensor_Brightness4, sensor_Brightness5,NULL,
581 #if CONFIG_SENSOR_Effect
582 static struct reginfo sensor_Effect_Normal[] =
598 static struct reginfo sensor_Effect_WandB[] =
615 static struct reginfo sensor_Effect_Sepia[] =
630 static struct reginfo sensor_Effect_Negative[] =
645 static struct reginfo sensor_Effect_Bluish[] =
661 static struct reginfo sensor_Effect_Green[] =
678 static struct reginfo sensor_Effect_Grayscale[]=
693 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
694 sensor_Effect_Bluish, sensor_Effect_Green,sensor_Effect_Grayscale,NULL,
697 #if CONFIG_SENSOR_Exposure
698 static struct reginfo sensor_Exposure0[]=
704 static struct reginfo sensor_Exposure1[]=
711 static struct reginfo sensor_Exposure2[]=
718 static struct reginfo sensor_Exposure3[]=
725 static struct reginfo sensor_Exposure4[]=
732 static struct reginfo sensor_Exposure5[]=
739 static struct reginfo sensor_Exposure6[]=
746 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
747 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
750 #if CONFIG_SENSOR_Saturation
751 static struct reginfo sensor_Saturation0[]=
757 static struct reginfo sensor_Saturation1[]=
763 static struct reginfo sensor_Saturation2[]=
768 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
771 #if CONFIG_SENSOR_Contrast
772 static struct reginfo sensor_Contrast0[]=
779 static struct reginfo sensor_Contrast1[]=
786 static struct reginfo sensor_Contrast2[]=
793 static struct reginfo sensor_Contrast3[]=
800 static struct reginfo sensor_Contrast4[]=
808 static struct reginfo sensor_Contrast5[]=
815 static struct reginfo sensor_Contrast6[]=
821 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
822 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
826 #if CONFIG_SENSOR_Mirror
827 static struct reginfo sensor_MirrorOn[]=
833 static struct reginfo sensor_MirrorOff[]=
838 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
840 #if CONFIG_SENSOR_Flip
841 static struct reginfo sensor_FlipOn[]=
847 static struct reginfo sensor_FlipOff[]=
852 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
855 #if CONFIG_SENSOR_Scene
856 static struct reginfo sensor_SceneAuto[] =
858 #if 0 /* ddl@rock-chips.com : */
866 {0x20 ,0x7f}, // close cc
875 static struct reginfo sensor_SceneNight[] =
878 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
880 {0x20 ,0x5f}, // close cc
887 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
903 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
906 #if CONFIG_SENSOR_DigitalZoom
907 static struct reginfo sensor_Zoom0[] =
912 static struct reginfo sensor_Zoom1[] =
917 static struct reginfo sensor_Zoom2[] =
923 static struct reginfo sensor_Zoom3[] =
927 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
929 static const struct v4l2_querymenu sensor_menus[] =
931 #if CONFIG_SENSOR_WhiteBalance
932 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
933 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
934 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
937 #if CONFIG_SENSOR_Effect
938 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
939 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
940 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
941 { .id = V4L2_CID_EFFECT, .index = 6, .name = "grayscale", .reserved = 0,},
944 #if CONFIG_SENSOR_Scene
945 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
948 #if CONFIG_SENSOR_Flash
949 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
950 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
954 static const struct v4l2_queryctrl sensor_controls[] =
956 #if CONFIG_SENSOR_WhiteBalance
958 .id = V4L2_CID_DO_WHITE_BALANCE,
959 .type = V4L2_CTRL_TYPE_MENU,
960 .name = "White Balance Control",
968 #if CONFIG_SENSOR_Brightness
970 .id = V4L2_CID_BRIGHTNESS,
971 .type = V4L2_CTRL_TYPE_INTEGER,
972 .name = "Brightness Control",
980 #if CONFIG_SENSOR_Effect
982 .id = V4L2_CID_EFFECT,
983 .type = V4L2_CTRL_TYPE_MENU,
984 .name = "Effect Control",
992 #if CONFIG_SENSOR_Exposure
994 .id = V4L2_CID_EXPOSURE,
995 .type = V4L2_CTRL_TYPE_INTEGER,
996 .name = "Exposure Control",
1004 #if CONFIG_SENSOR_Saturation
1006 .id = V4L2_CID_SATURATION,
1007 .type = V4L2_CTRL_TYPE_INTEGER,
1008 .name = "Saturation Control",
1016 #if CONFIG_SENSOR_Contrast
1018 .id = V4L2_CID_CONTRAST,
1019 .type = V4L2_CTRL_TYPE_INTEGER,
1020 .name = "Contrast Control",
1028 #if CONFIG_SENSOR_Mirror
1030 .id = V4L2_CID_HFLIP,
1031 .type = V4L2_CTRL_TYPE_BOOLEAN,
1032 .name = "Mirror Control",
1040 #if CONFIG_SENSOR_Flip
1042 .id = V4L2_CID_VFLIP,
1043 .type = V4L2_CTRL_TYPE_BOOLEAN,
1044 .name = "Flip Control",
1052 #if CONFIG_SENSOR_Scene
1054 .id = V4L2_CID_SCENE,
1055 .type = V4L2_CTRL_TYPE_MENU,
1056 .name = "Scene Control",
1064 #if CONFIG_SENSOR_DigitalZoom
1066 .id = V4L2_CID_ZOOM_RELATIVE,
1067 .type = V4L2_CTRL_TYPE_INTEGER,
1068 .name = "DigitalZoom Control",
1074 .id = V4L2_CID_ZOOM_ABSOLUTE,
1075 .type = V4L2_CTRL_TYPE_INTEGER,
1076 .name = "DigitalZoom Control",
1084 #if CONFIG_SENSOR_Focus
1086 .id = V4L2_CID_FOCUS_RELATIVE,
1087 .type = V4L2_CTRL_TYPE_INTEGER,
1088 .name = "Focus Control",
1094 .id = V4L2_CID_FOCUS_ABSOLUTE,
1095 .type = V4L2_CTRL_TYPE_INTEGER,
1096 .name = "Focus Control",
1100 .default_value = 125,
1104 #if CONFIG_SENSOR_Flash
1106 .id = V4L2_CID_FLASH,
1107 .type = V4L2_CTRL_TYPE_MENU,
1108 .name = "Flash Control",
1117 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1118 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1119 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1120 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1121 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1122 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1123 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1124 static int sensor_resume(struct soc_camera_device *icd);
1125 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1126 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1127 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1128 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1129 static int sensor_deactivate(struct i2c_client *client);
1131 static struct soc_camera_ops sensor_ops =
1133 .suspend = sensor_suspend,
1134 .resume = sensor_resume,
1135 .set_bus_param = sensor_set_bus_param,
1136 .query_bus_param = sensor_query_bus_param,
1137 .controls = sensor_controls,
1138 .menus = sensor_menus,
1139 .num_controls = ARRAY_SIZE(sensor_controls),
1140 .num_menus = ARRAY_SIZE(sensor_menus),
1143 /* only one fixed colorspace per pixelcode */
1144 struct sensor_datafmt {
1145 enum v4l2_mbus_pixelcode code;
1146 enum v4l2_colorspace colorspace;
1149 /* Find a data format by a pixel code in an array */
1150 static const struct sensor_datafmt *sensor_find_datafmt(
1151 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1155 for (i = 0; i < n; i++)
1156 if (fmt[i].code == code)
1162 static const struct sensor_datafmt sensor_colour_fmts[] = {
1163 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1164 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1167 typedef struct sensor_info_priv_s
1181 unsigned char mirror; /* HFLIP */
1182 unsigned char flip; /* VFLIP */
1183 unsigned int winseqe_cur_addr;
1184 struct sensor_datafmt fmt;
1185 unsigned int funmodule_state;
1186 } sensor_info_priv_t;
1190 struct v4l2_subdev subdev;
1191 struct i2c_client *client;
1192 sensor_info_priv_t info_priv;
1193 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1194 #if CONFIG_SENSOR_I2C_NOSCHED
1195 atomic_t tasklock_cnt;
1197 struct rk29camera_platform_data *sensor_io_request;
1198 struct rk29camera_gpio_res *sensor_gpio_res;
1201 static struct sensor* to_sensor(const struct i2c_client *client)
1203 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1206 static int sensor_task_lock(struct i2c_client *client, int lock)
1208 #if CONFIG_SENSOR_I2C_NOSCHED
1210 struct sensor *sensor = to_sensor(client);
1213 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1214 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1215 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1219 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1220 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1221 goto sensor_task_lock_err;
1226 atomic_add(1, &sensor->tasklock_cnt);
1228 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1229 atomic_sub(1, &sensor->tasklock_cnt);
1231 if (atomic_read(&sensor->tasklock_cnt) == 0)
1236 sensor_task_lock_err:
1245 /* sensor register */
1246 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1250 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1252 return (ret > 0)? 0 : ret;
1255 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1259 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1261 return (ret > 0)? 0 : ret;
1264 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1268 struct i2c_msg msg[1];
1276 msg->addr = client->addr;
1277 msg->flags = client->flags;
1279 msg->len = sizeof(buf);
1280 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1281 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1286 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1287 err = i2c_transfer(client->adapter, msg, 1);
1292 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1300 /* sensor register read */
1301 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1305 struct i2c_msg msg[2];
1309 msg[0].addr = client->addr;
1310 msg[0].flags = client->flags;
1312 msg[0].len = sizeof(buf);
1313 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1314 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1316 msg[1].addr = client->addr;
1317 msg[1].flags = client->flags|I2C_M_RD;
1320 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1321 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1325 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1326 err = i2c_transfer(client->adapter, msg, 2);
1332 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1342 /* write a array of registers */
1343 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1347 #if CONFIG_SENSOR_I2C_RDWRCHK
1353 if (sensor_task_lock(client, 1) < 0)
1354 goto sensor_write_array_end;
1355 while (regarray[i].reg != 0)
1357 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1361 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1365 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1367 goto sensor_write_array_end;
1370 #if CONFIG_SENSOR_I2C_RDWRCHK
1372 sensor_read(client, regarray[i].reg, &valchk);
1373 if (valchk != regarray[i].val)
1374 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1380 sensor_write_array_end:
1381 sensor_task_lock(client,0);
1384 #if CONFIG_SENSOR_I2C_RDWRCHK
1385 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1393 while (regarray[i].reg != 0)
1395 sensor_read(client, regarray[i].reg, &valchk);
1396 if (valchk != regarray[i].val)
1397 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1404 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1406 struct soc_camera_link *icl = to_soc_camera_link(icd);
1409 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1412 case Sensor_PowerDown:
1414 if (icl->powerdown) {
1415 ret = icl->powerdown(icd->pdev, on);
1416 if (ret == RK29_CAM_IO_SUCCESS) {
1420 icl->reset(icd->pdev);
1422 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1424 goto sensor_power_end;
1431 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1432 struct sensor *sensor = to_sensor(client);
1434 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1435 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1441 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1448 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1450 struct i2c_client *client = v4l2_get_subdevdata(sd);
1451 struct soc_camera_device *icd = client->dev.platform_data;
1452 struct sensor *sensor = to_sensor(client);
1453 const struct v4l2_queryctrl *qctrl;
1454 const struct sensor_datafmt *fmt;
1458 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1460 goto sensor_INIT_ERR;
1464 if (sensor_task_lock(client,1)<0)
1465 goto sensor_INIT_ERR;
1466 ret = sensor_write(client, 0xfe, 0x80);
1469 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1471 goto sensor_INIT_ERR;
1474 mdelay(5); //delay 5 microseconds
1475 /* check if it is an sensor sensor */
1476 ret = sensor_read(client, 0x00, &value);
1478 SENSOR_TR("read chip id high byte failed\n");
1480 goto sensor_INIT_ERR;
1483 if (value == SENSOR_ID) {
1484 sensor->model = SENSOR_V4L2_IDENT;
1486 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
1488 goto sensor_INIT_ERR;
1491 ret = sensor_write_array(client, sensor_init_data);
1494 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1495 goto sensor_INIT_ERR;
1497 sensor_task_lock(client,0);
1499 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1500 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1502 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1504 goto sensor_INIT_ERR;
1506 sensor->info_priv.fmt = *fmt;
1508 /* sensor sensor information for initialization */
1509 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1511 sensor->info_priv.whiteBalance = qctrl->default_value;
1512 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1514 sensor->info_priv.brightness = qctrl->default_value;
1515 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1517 sensor->info_priv.effect = qctrl->default_value;
1518 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1520 sensor->info_priv.exposure = qctrl->default_value;
1522 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1524 sensor->info_priv.saturation = qctrl->default_value;
1525 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1527 sensor->info_priv.contrast = qctrl->default_value;
1528 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1530 sensor->info_priv.mirror = qctrl->default_value;
1531 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1533 sensor->info_priv.flip = qctrl->default_value;
1534 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1536 sensor->info_priv.scene = qctrl->default_value;
1537 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1539 sensor->info_priv.digitalzoom = qctrl->default_value;
1541 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1542 #if CONFIG_SENSOR_Focus
1543 //sensor_set_focus();
1544 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1546 sensor->info_priv.focus = qctrl->default_value;
1549 #if CONFIG_SENSOR_Flash
1550 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1552 sensor->info_priv.flash = qctrl->default_value;
1555 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);
1556 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1559 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1560 sensor_task_lock(client,0);
1561 sensor_deactivate(client);
1565 static int sensor_deactivate(struct i2c_client *client)
1567 struct soc_camera_device *icd = client->dev.platform_data;
1569 struct sensor *sensor = to_sensor(client);
1570 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1572 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1573 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1576 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1577 icd->user_width = SENSOR_INIT_WIDTH;
1578 icd->user_height = SENSOR_INIT_HEIGHT;
1579 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1584 static struct reginfo sensor_power_down_sequence[]=
1588 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1591 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1593 if (pm_msg.event == PM_EVENT_SUSPEND) {
1594 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1595 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1597 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1600 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1602 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1607 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1613 static int sensor_resume(struct soc_camera_device *icd)
1617 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1619 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1623 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1629 static int sensor_set_bus_param(struct soc_camera_device *icd,
1630 unsigned long flags)
1636 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1638 struct soc_camera_link *icl = to_soc_camera_link(icd);
1639 unsigned long flags = SENSOR_BUS_PARAM;
1641 return soc_camera_apply_sensor_flags(icl, flags);
1644 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1646 struct i2c_client *client = v4l2_get_subdevdata(sd);
1647 struct soc_camera_device *icd = client->dev.platform_data;
1648 struct sensor *sensor = to_sensor(client);
1650 mf->width = icd->user_width;
1651 mf->height = icd->user_height;
1652 mf->code = sensor->info_priv.fmt.code;
1653 mf->colorspace = sensor->info_priv.fmt.colorspace;
1654 mf->field = V4L2_FIELD_NONE;
1658 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1662 if ((mf->width == 1024) && (mf->height == 768)) {
1664 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1666 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1668 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1670 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1675 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1679 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1683 if ((mf->width == 1280) && (mf->height == 720)) {
1685 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1690 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1693 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1695 struct i2c_client *client = v4l2_get_subdevdata(sd);
1696 const struct sensor_datafmt *fmt;
1697 struct sensor *sensor = to_sensor(client);
1698 const struct v4l2_queryctrl *qctrl;
1699 struct soc_camera_device *icd = client->dev.platform_data;
1700 struct reginfo *winseqe_set_addr=NULL;
1701 int ret=0, set_w,set_h;
1703 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1704 ARRAY_SIZE(sensor_colour_fmts));
1707 goto sensor_s_fmt_end;
1710 if (sensor->info_priv.fmt.code != mf->code) {
1713 case V4L2_MBUS_FMT_YUYV8_2X8:
1715 winseqe_set_addr = sensor_ClrFmt_YUYV;
1718 case V4L2_MBUS_FMT_UYVY8_2X8:
1720 winseqe_set_addr = sensor_ClrFmt_UYVY;
1726 if (winseqe_set_addr != NULL) {
1727 sensor_write_array(client, winseqe_set_addr);
1728 sensor->info_priv.fmt.code = mf->code;
1729 sensor->info_priv.fmt.colorspace= mf->colorspace;
1730 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1732 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1739 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1741 winseqe_set_addr = sensor_qcif;
1745 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1747 winseqe_set_addr = sensor_qvga;
1751 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1753 winseqe_set_addr = sensor_cif;
1757 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1759 winseqe_set_addr = sensor_vga;
1766 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1767 set_w = SENSOR_INIT_WIDTH;
1768 set_h = SENSOR_INIT_HEIGHT;
1769 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1772 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1773 #if CONFIG_SENSOR_Flash
1774 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1775 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1776 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1777 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1779 } else { /* ddl@rock-chips.com : Video */
1780 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1781 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1782 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1786 ret |= sensor_write_array(client, winseqe_set_addr);
1788 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1789 #if CONFIG_SENSOR_Flash
1790 if (sensor_fmt_capturechk(sd,mf) == true) {
1791 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1792 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1793 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1797 goto sensor_s_fmt_end;
1800 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1802 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1803 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1804 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1805 if (sensor->info_priv.whiteBalance != 0) {
1806 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1807 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1809 sensor->info_priv.snap2preview = true;
1810 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1811 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1812 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1813 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1814 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1815 sensor->info_priv.video2preview = true;
1816 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1817 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1818 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1819 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1820 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1821 sensor->info_priv.video2preview = false;
1822 sensor->info_priv.snap2preview = false;
1824 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1826 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1836 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1838 struct i2c_client *client = v4l2_get_subdevdata(sd);
1839 struct sensor *sensor = to_sensor(client);
1840 const struct sensor_datafmt *fmt;
1843 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1844 ARRAY_SIZE(sensor_colour_fmts));
1846 fmt = &sensor->info_priv.fmt;
1847 mf->code = fmt->code;
1850 if (mf->height > SENSOR_MAX_HEIGHT)
1851 mf->height = SENSOR_MAX_HEIGHT;
1852 else if (mf->height < SENSOR_MIN_HEIGHT)
1853 mf->height = SENSOR_MIN_HEIGHT;
1855 if (mf->width > SENSOR_MAX_WIDTH)
1856 mf->width = SENSOR_MAX_WIDTH;
1857 else if (mf->width < SENSOR_MIN_WIDTH)
1858 mf->width = SENSOR_MIN_WIDTH;
1860 mf->colorspace = fmt->colorspace;
1865 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1867 struct i2c_client *client = v4l2_get_subdevdata(sd);
1869 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1872 if (id->match.addr != client->addr)
1875 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1880 #if CONFIG_SENSOR_Brightness
1881 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1883 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1885 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1887 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1889 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1891 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1894 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1898 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1902 #if CONFIG_SENSOR_Effect
1903 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1905 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1907 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1909 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1911 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1913 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1916 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1920 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1924 #if CONFIG_SENSOR_Exposure
1925 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1927 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1929 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1931 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1933 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1935 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1938 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1942 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1946 #if CONFIG_SENSOR_Saturation
1947 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1949 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1951 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1953 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1955 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1957 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1960 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1964 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1968 #if CONFIG_SENSOR_Contrast
1969 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1971 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1973 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1975 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1977 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1979 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1982 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1986 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1990 #if CONFIG_SENSOR_Mirror
1991 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1993 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1995 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1997 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1999 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2001 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2004 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2008 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2012 #if CONFIG_SENSOR_Flip
2013 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2015 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2017 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2019 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2021 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2023 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2026 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2030 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2034 #if CONFIG_SENSOR_Scene
2035 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2037 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2039 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2041 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2043 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2045 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2048 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2052 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2056 #if CONFIG_SENSOR_WhiteBalance
2057 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2059 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2061 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2063 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2065 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2067 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2070 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2074 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2078 #if CONFIG_SENSOR_DigitalZoom
2079 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2081 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2082 struct sensor *sensor = to_sensor(client);
2083 const struct v4l2_queryctrl *qctrl_info;
2084 int digitalzoom_cur, digitalzoom_total;
2086 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2090 digitalzoom_cur = sensor->info_priv.digitalzoom;
2091 digitalzoom_total = qctrl_info->maximum;
2093 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2095 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2099 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2101 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2105 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2107 value = digitalzoom_total - digitalzoom_cur;
2110 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2112 value = 0 - digitalzoom_cur;
2115 digitalzoom_cur += value;
2117 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2119 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2121 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2124 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2131 #if CONFIG_SENSOR_Flash
2132 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2134 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2135 if (value == 3) { /* ddl@rock-chips.com: torch */
2136 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2138 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2140 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2144 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2149 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2151 struct i2c_client *client = v4l2_get_subdevdata(sd);
2152 struct sensor *sensor = to_sensor(client);
2153 const struct v4l2_queryctrl *qctrl;
2155 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2159 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2165 case V4L2_CID_BRIGHTNESS:
2167 ctrl->value = sensor->info_priv.brightness;
2170 case V4L2_CID_SATURATION:
2172 ctrl->value = sensor->info_priv.saturation;
2175 case V4L2_CID_CONTRAST:
2177 ctrl->value = sensor->info_priv.contrast;
2180 case V4L2_CID_DO_WHITE_BALANCE:
2182 ctrl->value = sensor->info_priv.whiteBalance;
2185 case V4L2_CID_EXPOSURE:
2187 ctrl->value = sensor->info_priv.exposure;
2190 case V4L2_CID_HFLIP:
2192 ctrl->value = sensor->info_priv.mirror;
2195 case V4L2_CID_VFLIP:
2197 ctrl->value = sensor->info_priv.flip;
2208 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2210 struct i2c_client *client = v4l2_get_subdevdata(sd);
2211 struct sensor *sensor = to_sensor(client);
2212 struct soc_camera_device *icd = client->dev.platform_data;
2213 const struct v4l2_queryctrl *qctrl;
2216 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2220 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2226 #if CONFIG_SENSOR_Brightness
2227 case V4L2_CID_BRIGHTNESS:
2229 if (ctrl->value != sensor->info_priv.brightness)
2231 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2235 sensor->info_priv.brightness = ctrl->value;
2240 #if CONFIG_SENSOR_Exposure
2241 case V4L2_CID_EXPOSURE:
2243 if (ctrl->value != sensor->info_priv.exposure)
2245 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2249 sensor->info_priv.exposure = ctrl->value;
2254 #if CONFIG_SENSOR_Saturation
2255 case V4L2_CID_SATURATION:
2257 if (ctrl->value != sensor->info_priv.saturation)
2259 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2263 sensor->info_priv.saturation = ctrl->value;
2268 #if CONFIG_SENSOR_Contrast
2269 case V4L2_CID_CONTRAST:
2271 if (ctrl->value != sensor->info_priv.contrast)
2273 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2277 sensor->info_priv.contrast = ctrl->value;
2282 #if CONFIG_SENSOR_WhiteBalance
2283 case V4L2_CID_DO_WHITE_BALANCE:
2285 if (ctrl->value != sensor->info_priv.whiteBalance)
2287 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2291 sensor->info_priv.whiteBalance = ctrl->value;
2296 #if CONFIG_SENSOR_Mirror
2297 case V4L2_CID_HFLIP:
2299 if (ctrl->value != sensor->info_priv.mirror)
2301 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2303 sensor->info_priv.mirror = ctrl->value;
2308 #if CONFIG_SENSOR_Flip
2309 case V4L2_CID_VFLIP:
2311 if (ctrl->value != sensor->info_priv.flip)
2313 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2315 sensor->info_priv.flip = ctrl->value;
2326 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2328 const struct v4l2_queryctrl *qctrl;
2329 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2330 struct sensor *sensor = to_sensor(client);
2332 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2336 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2340 switch (ext_ctrl->id)
2342 case V4L2_CID_SCENE:
2344 ext_ctrl->value = sensor->info_priv.scene;
2347 case V4L2_CID_EFFECT:
2349 ext_ctrl->value = sensor->info_priv.effect;
2352 case V4L2_CID_ZOOM_ABSOLUTE:
2354 ext_ctrl->value = sensor->info_priv.digitalzoom;
2357 case V4L2_CID_ZOOM_RELATIVE:
2361 case V4L2_CID_FOCUS_ABSOLUTE:
2363 ext_ctrl->value = sensor->info_priv.focus;
2366 case V4L2_CID_FOCUS_RELATIVE:
2370 case V4L2_CID_FLASH:
2372 ext_ctrl->value = sensor->info_priv.flash;
2380 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2382 const struct v4l2_queryctrl *qctrl;
2383 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2384 struct sensor *sensor = to_sensor(client);
2387 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2391 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2396 switch (ext_ctrl->id)
2398 #if CONFIG_SENSOR_Scene
2399 case V4L2_CID_SCENE:
2401 if (ext_ctrl->value != sensor->info_priv.scene)
2403 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2405 sensor->info_priv.scene = ext_ctrl->value;
2410 #if CONFIG_SENSOR_Effect
2411 case V4L2_CID_EFFECT:
2413 if (ext_ctrl->value != sensor->info_priv.effect)
2415 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2417 sensor->info_priv.effect= ext_ctrl->value;
2422 #if CONFIG_SENSOR_DigitalZoom
2423 case V4L2_CID_ZOOM_ABSOLUTE:
2425 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2428 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2430 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2432 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2434 sensor->info_priv.digitalzoom += val_offset;
2436 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2441 case V4L2_CID_ZOOM_RELATIVE:
2443 if (ext_ctrl->value)
2445 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2447 sensor->info_priv.digitalzoom += ext_ctrl->value;
2449 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2454 #if CONFIG_SENSOR_Focus
2455 case V4L2_CID_FOCUS_ABSOLUTE:
2457 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2460 if (ext_ctrl->value != sensor->info_priv.focus)
2462 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2464 sensor->info_priv.focus += val_offset;
2469 case V4L2_CID_FOCUS_RELATIVE:
2471 if (ext_ctrl->value)
2473 sensor->info_priv.focus += ext_ctrl->value;
2475 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2480 #if CONFIG_SENSOR_Flash
2481 case V4L2_CID_FLASH:
2483 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2485 sensor->info_priv.flash = ext_ctrl->value;
2487 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2498 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2500 struct i2c_client *client = v4l2_get_subdevdata(sd);
2501 struct soc_camera_device *icd = client->dev.platform_data;
2502 int i, error_cnt=0, error_idx=-1;
2505 for (i=0; i<ext_ctrl->count; i++) {
2506 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2513 error_idx = ext_ctrl->count;
2515 if (error_idx != -1) {
2516 ext_ctrl->error_idx = error_idx;
2523 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2525 struct i2c_client *client = v4l2_get_subdevdata(sd);
2526 struct soc_camera_device *icd = client->dev.platform_data;
2527 int i, error_cnt=0, error_idx=-1;
2530 for (i=0; i<ext_ctrl->count; i++) {
2531 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2538 error_idx = ext_ctrl->count;
2540 if (error_idx != -1) {
2541 ext_ctrl->error_idx = error_idx;
2548 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2549 * this wasn't our capture interface, so, we wait for the right one */
2550 static int sensor_video_probe(struct soc_camera_device *icd,
2551 struct i2c_client *client)
2555 struct sensor *sensor = to_sensor(client);
2557 /* We must have a parent by now. And it cannot be a wrong one.
2558 * So this entire test is completely redundant. */
2559 if (!icd->dev.parent ||
2560 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2563 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2565 goto sensor_video_probe_err;
2569 ret = sensor_write(client, 0xfe, 0x80);
2572 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2575 mdelay(5); //delay 5 microseconds
2577 /* check if it is an sensor sensor */
2578 ret = sensor_read(client, 0x00, &value);
2580 SENSOR_TR("read chip id high byte failed\n");
2582 goto sensor_video_probe_err;
2585 if (value == SENSOR_ID) {
2586 sensor->model = SENSOR_V4L2_IDENT;
2587 SENSOR_TR("chip id:0x%x\n",value);
2589 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2591 goto sensor_video_probe_err;
2596 sensor_video_probe_err:
2600 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2602 struct i2c_client *client = v4l2_get_subdevdata(sd);
2603 struct soc_camera_device *icd = client->dev.platform_data;
2604 struct sensor *sensor = to_sensor(client);
2606 #if CONFIG_SENSOR_Flash
2610 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2613 case RK29_CAM_SUBDEV_DEACTIVATE:
2615 sensor_deactivate(client);
2619 case RK29_CAM_SUBDEV_IOREQUEST:
2621 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2622 if (sensor->sensor_io_request != NULL) {
2623 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2624 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2625 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2626 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2627 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2628 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2631 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2633 goto sensor_ioctl_end;
2635 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2637 #if CONFIG_SENSOR_Flash
2638 if (sensor->sensor_gpio_res) {
2639 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2640 for (i = 0; i < icd->ops->num_controls; i++) {
2641 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2642 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2645 sensor->info_priv.flash = 0xff;
2646 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2654 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2662 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2663 enum v4l2_mbus_pixelcode *code)
2665 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2668 *code = sensor_colour_fmts[index].code;
2671 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2672 .init = sensor_init,
2673 .g_ctrl = sensor_g_control,
2674 .s_ctrl = sensor_s_control,
2675 .g_ext_ctrls = sensor_g_ext_controls,
2676 .s_ext_ctrls = sensor_s_ext_controls,
2677 .g_chip_ident = sensor_g_chip_ident,
2678 .ioctl = sensor_ioctl,
2681 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2682 .s_mbus_fmt = sensor_s_fmt,
2683 .g_mbus_fmt = sensor_g_fmt,
2684 .try_mbus_fmt = sensor_try_fmt,
2685 .enum_mbus_fmt = sensor_enum_fmt,
2688 static struct v4l2_subdev_ops sensor_subdev_ops = {
2689 .core = &sensor_subdev_core_ops,
2690 .video = &sensor_subdev_video_ops,
2693 static int sensor_probe(struct i2c_client *client,
2694 const struct i2c_device_id *did)
2696 struct sensor *sensor;
2697 struct soc_camera_device *icd = client->dev.platform_data;
2698 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2699 struct soc_camera_link *icl;
2702 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2704 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2708 icl = to_soc_camera_link(icd);
2710 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2714 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2715 dev_warn(&adapter->dev,
2716 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2720 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2724 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2726 /* Second stage probe - when a capture adapter is there */
2727 icd->ops = &sensor_ops;
2729 sensor->info_priv.fmt = sensor_colour_fmts[0];
2731 #if CONFIG_SENSOR_I2C_NOSCHED
2732 atomic_set(&sensor->tasklock_cnt,0);
2735 ret = sensor_video_probe(icd, client);
2738 i2c_set_clientdata(client, NULL);
2742 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2746 static int sensor_remove(struct i2c_client *client)
2748 struct sensor *sensor = to_sensor(client);
2749 struct soc_camera_device *icd = client->dev.platform_data;
2752 i2c_set_clientdata(client, NULL);
2753 client->driver = NULL;
2759 static const struct i2c_device_id sensor_id[] = {
2760 {SENSOR_NAME_STRING(), 0 },
2763 MODULE_DEVICE_TABLE(i2c, sensor_id);
2765 static struct i2c_driver sensor_i2c_driver = {
2767 .name = SENSOR_NAME_STRING(),
2769 .probe = sensor_probe,
2770 .remove = sensor_remove,
2771 .id_table = sensor_id,
2774 static int __init sensor_mod_init(void)
2776 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2777 return i2c_add_driver(&sensor_i2c_driver);
2780 static void __exit sensor_mod_exit(void)
2782 i2c_del_driver(&sensor_i2c_driver);
2785 device_initcall_sync(sensor_mod_init);
2786 module_exit(sensor_mod_exit);
2788 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2789 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2790 MODULE_LICENSE("GPL");