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;
1568 struct sensor *sensor = to_sensor(client);
1569 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1571 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1572 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1575 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1576 icd->user_width = SENSOR_INIT_WIDTH;
1577 icd->user_height = SENSOR_INIT_HEIGHT;
1578 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1583 static struct reginfo sensor_power_down_sequence[]=
1587 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1590 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1592 if (pm_msg.event == PM_EVENT_SUSPEND) {
1593 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1594 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1596 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1599 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1601 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1606 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1612 static int sensor_resume(struct soc_camera_device *icd)
1616 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1618 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1622 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1628 static int sensor_set_bus_param(struct soc_camera_device *icd,
1629 unsigned long flags)
1635 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1637 struct soc_camera_link *icl = to_soc_camera_link(icd);
1638 unsigned long flags = SENSOR_BUS_PARAM;
1640 return soc_camera_apply_sensor_flags(icl, flags);
1643 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1645 struct i2c_client *client = v4l2_get_subdevdata(sd);
1646 struct soc_camera_device *icd = client->dev.platform_data;
1647 struct sensor *sensor = to_sensor(client);
1649 mf->width = icd->user_width;
1650 mf->height = icd->user_height;
1651 mf->code = sensor->info_priv.fmt.code;
1652 mf->colorspace = sensor->info_priv.fmt.colorspace;
1653 mf->field = V4L2_FIELD_NONE;
1657 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1661 if ((mf->width == 1024) && (mf->height == 768)) {
1663 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1665 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1667 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1669 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1674 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1678 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1682 if ((mf->width == 1280) && (mf->height == 720)) {
1684 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1689 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1692 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1694 struct i2c_client *client = v4l2_get_subdevdata(sd);
1695 const struct sensor_datafmt *fmt;
1696 struct sensor *sensor = to_sensor(client);
1697 const struct v4l2_queryctrl *qctrl;
1698 struct soc_camera_device *icd = client->dev.platform_data;
1699 struct reginfo *winseqe_set_addr=NULL;
1700 int ret=0, set_w,set_h;
1702 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1703 ARRAY_SIZE(sensor_colour_fmts));
1706 goto sensor_s_fmt_end;
1709 if (sensor->info_priv.fmt.code != mf->code) {
1712 case V4L2_MBUS_FMT_YUYV8_2X8:
1714 winseqe_set_addr = sensor_ClrFmt_YUYV;
1717 case V4L2_MBUS_FMT_UYVY8_2X8:
1719 winseqe_set_addr = sensor_ClrFmt_UYVY;
1725 if (winseqe_set_addr != NULL) {
1726 sensor_write_array(client, winseqe_set_addr);
1727 sensor->info_priv.fmt.code = mf->code;
1728 sensor->info_priv.fmt.colorspace= mf->colorspace;
1729 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1731 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1738 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1740 winseqe_set_addr = sensor_qcif;
1744 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1746 winseqe_set_addr = sensor_qvga;
1750 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1752 winseqe_set_addr = sensor_cif;
1756 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1758 winseqe_set_addr = sensor_vga;
1765 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1766 set_w = SENSOR_INIT_WIDTH;
1767 set_h = SENSOR_INIT_HEIGHT;
1768 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1771 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1772 #if CONFIG_SENSOR_Flash
1773 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1774 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1775 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1776 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1778 } else { /* ddl@rock-chips.com : Video */
1779 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1780 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1781 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1785 ret |= sensor_write_array(client, winseqe_set_addr);
1787 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1788 #if CONFIG_SENSOR_Flash
1789 if (sensor_fmt_capturechk(sd,mf) == true) {
1790 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1791 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1792 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1796 goto sensor_s_fmt_end;
1799 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1801 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1802 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1803 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1804 if (sensor->info_priv.whiteBalance != 0) {
1805 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1806 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1808 sensor->info_priv.snap2preview = true;
1809 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1810 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1811 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1812 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1813 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1814 sensor->info_priv.video2preview = true;
1815 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1816 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1817 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1818 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1819 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1820 sensor->info_priv.video2preview = false;
1821 sensor->info_priv.snap2preview = false;
1823 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1825 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1835 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1837 struct i2c_client *client = v4l2_get_subdevdata(sd);
1838 struct sensor *sensor = to_sensor(client);
1839 const struct sensor_datafmt *fmt;
1842 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1843 ARRAY_SIZE(sensor_colour_fmts));
1845 fmt = &sensor->info_priv.fmt;
1846 mf->code = fmt->code;
1849 if (mf->height > SENSOR_MAX_HEIGHT)
1850 mf->height = SENSOR_MAX_HEIGHT;
1851 else if (mf->height < SENSOR_MIN_HEIGHT)
1852 mf->height = SENSOR_MIN_HEIGHT;
1854 if (mf->width > SENSOR_MAX_WIDTH)
1855 mf->width = SENSOR_MAX_WIDTH;
1856 else if (mf->width < SENSOR_MIN_WIDTH)
1857 mf->width = SENSOR_MIN_WIDTH;
1859 mf->colorspace = fmt->colorspace;
1864 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1866 struct i2c_client *client = v4l2_get_subdevdata(sd);
1868 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1871 if (id->match.addr != client->addr)
1874 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1879 #if CONFIG_SENSOR_Brightness
1880 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1882 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1884 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1886 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1888 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1890 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1893 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1897 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1901 #if CONFIG_SENSOR_Effect
1902 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1904 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1906 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1908 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1910 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1912 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1915 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1919 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1923 #if CONFIG_SENSOR_Exposure
1924 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1926 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1928 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1930 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1932 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1934 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1937 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1941 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1945 #if CONFIG_SENSOR_Saturation
1946 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1948 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1950 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1952 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1954 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1956 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1959 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1963 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1967 #if CONFIG_SENSOR_Contrast
1968 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1970 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1972 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1974 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1976 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1978 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1981 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1985 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1989 #if CONFIG_SENSOR_Mirror
1990 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1992 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1994 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1996 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1998 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2000 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2003 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2007 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2011 #if CONFIG_SENSOR_Flip
2012 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2014 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2016 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2018 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2020 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2022 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2025 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2029 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2033 #if CONFIG_SENSOR_Scene
2034 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2036 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2038 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2040 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2042 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2044 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2047 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2051 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2055 #if CONFIG_SENSOR_WhiteBalance
2056 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2058 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2060 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2062 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2064 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2066 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2069 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2073 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2077 #if CONFIG_SENSOR_DigitalZoom
2078 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2080 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2081 struct sensor *sensor = to_sensor(client);
2082 const struct v4l2_queryctrl *qctrl_info;
2083 int digitalzoom_cur, digitalzoom_total;
2085 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2089 digitalzoom_cur = sensor->info_priv.digitalzoom;
2090 digitalzoom_total = qctrl_info->maximum;
2092 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2094 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2098 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2100 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2104 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2106 value = digitalzoom_total - digitalzoom_cur;
2109 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2111 value = 0 - digitalzoom_cur;
2114 digitalzoom_cur += value;
2116 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2118 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2120 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2123 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2130 #if CONFIG_SENSOR_Flash
2131 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2133 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2134 if (value == 3) { /* ddl@rock-chips.com: torch */
2135 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2137 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2139 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2143 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2148 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2150 struct i2c_client *client = v4l2_get_subdevdata(sd);
2151 struct sensor *sensor = to_sensor(client);
2152 const struct v4l2_queryctrl *qctrl;
2154 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2158 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2164 case V4L2_CID_BRIGHTNESS:
2166 ctrl->value = sensor->info_priv.brightness;
2169 case V4L2_CID_SATURATION:
2171 ctrl->value = sensor->info_priv.saturation;
2174 case V4L2_CID_CONTRAST:
2176 ctrl->value = sensor->info_priv.contrast;
2179 case V4L2_CID_DO_WHITE_BALANCE:
2181 ctrl->value = sensor->info_priv.whiteBalance;
2184 case V4L2_CID_EXPOSURE:
2186 ctrl->value = sensor->info_priv.exposure;
2189 case V4L2_CID_HFLIP:
2191 ctrl->value = sensor->info_priv.mirror;
2194 case V4L2_CID_VFLIP:
2196 ctrl->value = sensor->info_priv.flip;
2207 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2209 struct i2c_client *client = v4l2_get_subdevdata(sd);
2210 struct sensor *sensor = to_sensor(client);
2211 struct soc_camera_device *icd = client->dev.platform_data;
2212 const struct v4l2_queryctrl *qctrl;
2215 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2219 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2225 #if CONFIG_SENSOR_Brightness
2226 case V4L2_CID_BRIGHTNESS:
2228 if (ctrl->value != sensor->info_priv.brightness)
2230 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2234 sensor->info_priv.brightness = ctrl->value;
2239 #if CONFIG_SENSOR_Exposure
2240 case V4L2_CID_EXPOSURE:
2242 if (ctrl->value != sensor->info_priv.exposure)
2244 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2248 sensor->info_priv.exposure = ctrl->value;
2253 #if CONFIG_SENSOR_Saturation
2254 case V4L2_CID_SATURATION:
2256 if (ctrl->value != sensor->info_priv.saturation)
2258 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2262 sensor->info_priv.saturation = ctrl->value;
2267 #if CONFIG_SENSOR_Contrast
2268 case V4L2_CID_CONTRAST:
2270 if (ctrl->value != sensor->info_priv.contrast)
2272 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2276 sensor->info_priv.contrast = ctrl->value;
2281 #if CONFIG_SENSOR_WhiteBalance
2282 case V4L2_CID_DO_WHITE_BALANCE:
2284 if (ctrl->value != sensor->info_priv.whiteBalance)
2286 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2290 sensor->info_priv.whiteBalance = ctrl->value;
2295 #if CONFIG_SENSOR_Mirror
2296 case V4L2_CID_HFLIP:
2298 if (ctrl->value != sensor->info_priv.mirror)
2300 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2302 sensor->info_priv.mirror = ctrl->value;
2307 #if CONFIG_SENSOR_Flip
2308 case V4L2_CID_VFLIP:
2310 if (ctrl->value != sensor->info_priv.flip)
2312 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2314 sensor->info_priv.flip = ctrl->value;
2325 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2327 const struct v4l2_queryctrl *qctrl;
2328 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2329 struct sensor *sensor = to_sensor(client);
2331 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2335 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2339 switch (ext_ctrl->id)
2341 case V4L2_CID_SCENE:
2343 ext_ctrl->value = sensor->info_priv.scene;
2346 case V4L2_CID_EFFECT:
2348 ext_ctrl->value = sensor->info_priv.effect;
2351 case V4L2_CID_ZOOM_ABSOLUTE:
2353 ext_ctrl->value = sensor->info_priv.digitalzoom;
2356 case V4L2_CID_ZOOM_RELATIVE:
2360 case V4L2_CID_FOCUS_ABSOLUTE:
2362 ext_ctrl->value = sensor->info_priv.focus;
2365 case V4L2_CID_FOCUS_RELATIVE:
2369 case V4L2_CID_FLASH:
2371 ext_ctrl->value = sensor->info_priv.flash;
2379 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2381 const struct v4l2_queryctrl *qctrl;
2382 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2383 struct sensor *sensor = to_sensor(client);
2386 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2390 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2395 switch (ext_ctrl->id)
2397 #if CONFIG_SENSOR_Scene
2398 case V4L2_CID_SCENE:
2400 if (ext_ctrl->value != sensor->info_priv.scene)
2402 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2404 sensor->info_priv.scene = ext_ctrl->value;
2409 #if CONFIG_SENSOR_Effect
2410 case V4L2_CID_EFFECT:
2412 if (ext_ctrl->value != sensor->info_priv.effect)
2414 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2416 sensor->info_priv.effect= ext_ctrl->value;
2421 #if CONFIG_SENSOR_DigitalZoom
2422 case V4L2_CID_ZOOM_ABSOLUTE:
2424 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2427 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2429 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2431 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2433 sensor->info_priv.digitalzoom += val_offset;
2435 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2440 case V4L2_CID_ZOOM_RELATIVE:
2442 if (ext_ctrl->value)
2444 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2446 sensor->info_priv.digitalzoom += ext_ctrl->value;
2448 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2453 #if CONFIG_SENSOR_Focus
2454 case V4L2_CID_FOCUS_ABSOLUTE:
2456 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2459 if (ext_ctrl->value != sensor->info_priv.focus)
2461 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2463 sensor->info_priv.focus += val_offset;
2468 case V4L2_CID_FOCUS_RELATIVE:
2470 if (ext_ctrl->value)
2472 sensor->info_priv.focus += ext_ctrl->value;
2474 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2479 #if CONFIG_SENSOR_Flash
2480 case V4L2_CID_FLASH:
2482 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2484 sensor->info_priv.flash = ext_ctrl->value;
2486 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2497 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2499 struct i2c_client *client = v4l2_get_subdevdata(sd);
2500 struct soc_camera_device *icd = client->dev.platform_data;
2501 int i, error_cnt=0, error_idx=-1;
2504 for (i=0; i<ext_ctrl->count; i++) {
2505 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2512 error_idx = ext_ctrl->count;
2514 if (error_idx != -1) {
2515 ext_ctrl->error_idx = error_idx;
2522 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2524 struct i2c_client *client = v4l2_get_subdevdata(sd);
2525 struct soc_camera_device *icd = client->dev.platform_data;
2526 int i, error_cnt=0, error_idx=-1;
2529 for (i=0; i<ext_ctrl->count; i++) {
2530 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2537 error_idx = ext_ctrl->count;
2539 if (error_idx != -1) {
2540 ext_ctrl->error_idx = error_idx;
2547 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2548 * this wasn't our capture interface, so, we wait for the right one */
2549 static int sensor_video_probe(struct soc_camera_device *icd,
2550 struct i2c_client *client)
2554 struct sensor *sensor = to_sensor(client);
2556 /* We must have a parent by now. And it cannot be a wrong one.
2557 * So this entire test is completely redundant. */
2558 if (!icd->dev.parent ||
2559 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2562 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2564 goto sensor_video_probe_err;
2568 ret = sensor_write(client, 0xfe, 0x80);
2571 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2574 mdelay(5); //delay 5 microseconds
2576 /* check if it is an sensor sensor */
2577 ret = sensor_read(client, 0x00, &value);
2579 SENSOR_TR("read chip id high byte failed\n");
2581 goto sensor_video_probe_err;
2584 if (value == SENSOR_ID) {
2585 sensor->model = SENSOR_V4L2_IDENT;
2586 SENSOR_TR("chip id:0x%x\n",value);
2588 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2590 goto sensor_video_probe_err;
2595 sensor_video_probe_err:
2599 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2601 struct i2c_client *client = v4l2_get_subdevdata(sd);
2602 struct soc_camera_device *icd = client->dev.platform_data;
2603 struct sensor *sensor = to_sensor(client);
2605 #if CONFIG_SENSOR_Flash
2609 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2612 case RK29_CAM_SUBDEV_DEACTIVATE:
2614 sensor_deactivate(client);
2618 case RK29_CAM_SUBDEV_IOREQUEST:
2620 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2621 if (sensor->sensor_io_request != NULL) {
2622 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2623 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2624 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2625 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2626 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2627 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2630 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2632 goto sensor_ioctl_end;
2634 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2636 #if CONFIG_SENSOR_Flash
2637 if (sensor->sensor_gpio_res) {
2638 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2639 for (i = 0; i < icd->ops->num_controls; i++) {
2640 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2641 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2644 sensor->info_priv.flash = 0xff;
2645 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2653 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2661 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2662 enum v4l2_mbus_pixelcode *code)
2664 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2667 *code = sensor_colour_fmts[index].code;
2670 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2671 .init = sensor_init,
2672 .g_ctrl = sensor_g_control,
2673 .s_ctrl = sensor_s_control,
2674 .g_ext_ctrls = sensor_g_ext_controls,
2675 .s_ext_ctrls = sensor_s_ext_controls,
2676 .g_chip_ident = sensor_g_chip_ident,
2677 .ioctl = sensor_ioctl,
2680 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2681 .s_mbus_fmt = sensor_s_fmt,
2682 .g_mbus_fmt = sensor_g_fmt,
2683 .try_mbus_fmt = sensor_try_fmt,
2684 .enum_mbus_fmt = sensor_enum_fmt,
2687 static struct v4l2_subdev_ops sensor_subdev_ops = {
2688 .core = &sensor_subdev_core_ops,
2689 .video = &sensor_subdev_video_ops,
2692 static int sensor_probe(struct i2c_client *client,
2693 const struct i2c_device_id *did)
2695 struct sensor *sensor;
2696 struct soc_camera_device *icd = client->dev.platform_data;
2697 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2698 struct soc_camera_link *icl;
2701 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2703 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2707 icl = to_soc_camera_link(icd);
2709 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2713 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2714 dev_warn(&adapter->dev,
2715 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2719 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2723 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2725 /* Second stage probe - when a capture adapter is there */
2726 icd->ops = &sensor_ops;
2728 sensor->info_priv.fmt = sensor_colour_fmts[0];
2730 #if CONFIG_SENSOR_I2C_NOSCHED
2731 atomic_set(&sensor->tasklock_cnt,0);
2734 ret = sensor_video_probe(icd, client);
2737 i2c_set_clientdata(client, NULL);
2741 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2745 static int sensor_remove(struct i2c_client *client)
2747 struct sensor *sensor = to_sensor(client);
2748 struct soc_camera_device *icd = client->dev.platform_data;
2751 i2c_set_clientdata(client, NULL);
2752 client->driver = NULL;
2758 static const struct i2c_device_id sensor_id[] = {
2759 {SENSOR_NAME_STRING(), 0 },
2762 MODULE_DEVICE_TABLE(i2c, sensor_id);
2764 static struct i2c_driver sensor_i2c_driver = {
2766 .name = SENSOR_NAME_STRING(),
2768 .probe = sensor_probe,
2769 .remove = sensor_remove,
2770 .id_table = sensor_id,
2773 static int __init sensor_mod_init(void)
2775 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2776 return i2c_add_driver(&sensor_i2c_driver);
2779 static void __exit sensor_mod_exit(void)
2781 i2c_del_driver(&sensor_i2c_driver);
2784 device_initcall_sync(sensor_mod_init);
2785 module_exit(sensor_mod_exit);
2787 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2788 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2789 MODULE_LICENSE("GPL");