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;
1840 int ret = 0,set_w,set_h;
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;
1862 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1867 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1872 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1877 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1885 set_w = SENSOR_INIT_WIDTH;
1886 set_h = SENSOR_INIT_HEIGHT;
1890 mf->colorspace = fmt->colorspace;
1895 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1897 struct i2c_client *client = v4l2_get_subdevdata(sd);
1899 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1902 if (id->match.addr != client->addr)
1905 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1910 #if CONFIG_SENSOR_Brightness
1911 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1913 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1915 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1917 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1919 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1921 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1924 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1928 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1932 #if CONFIG_SENSOR_Effect
1933 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1935 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1937 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1939 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1941 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1943 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1946 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1950 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1954 #if CONFIG_SENSOR_Exposure
1955 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1957 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1959 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1961 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1963 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1965 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1968 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1972 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1976 #if CONFIG_SENSOR_Saturation
1977 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1979 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1981 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1983 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1985 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1987 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1990 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1994 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1998 #if CONFIG_SENSOR_Contrast
1999 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2001 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2003 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2005 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2007 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2009 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2012 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2016 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2020 #if CONFIG_SENSOR_Mirror
2021 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2023 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2025 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2027 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2029 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2031 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2034 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2038 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2042 #if CONFIG_SENSOR_Flip
2043 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2045 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2047 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2049 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2051 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2053 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2056 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2060 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2064 #if CONFIG_SENSOR_Scene
2065 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2067 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2069 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2071 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2073 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2075 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2078 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2082 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2086 #if CONFIG_SENSOR_WhiteBalance
2087 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2089 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2091 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2093 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2095 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2097 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2100 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2104 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2108 #if CONFIG_SENSOR_DigitalZoom
2109 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2111 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2112 struct sensor *sensor = to_sensor(client);
2113 const struct v4l2_queryctrl *qctrl_info;
2114 int digitalzoom_cur, digitalzoom_total;
2116 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2120 digitalzoom_cur = sensor->info_priv.digitalzoom;
2121 digitalzoom_total = qctrl_info->maximum;
2123 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2125 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2129 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2131 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2135 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2137 value = digitalzoom_total - digitalzoom_cur;
2140 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2142 value = 0 - digitalzoom_cur;
2145 digitalzoom_cur += value;
2147 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2149 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2151 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2154 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2161 #if CONFIG_SENSOR_Flash
2162 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2164 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2165 if (value == 3) { /* ddl@rock-chips.com: torch */
2166 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2168 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2170 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2174 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2179 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2181 struct i2c_client *client = v4l2_get_subdevdata(sd);
2182 struct sensor *sensor = to_sensor(client);
2183 const struct v4l2_queryctrl *qctrl;
2185 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2189 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2195 case V4L2_CID_BRIGHTNESS:
2197 ctrl->value = sensor->info_priv.brightness;
2200 case V4L2_CID_SATURATION:
2202 ctrl->value = sensor->info_priv.saturation;
2205 case V4L2_CID_CONTRAST:
2207 ctrl->value = sensor->info_priv.contrast;
2210 case V4L2_CID_DO_WHITE_BALANCE:
2212 ctrl->value = sensor->info_priv.whiteBalance;
2215 case V4L2_CID_EXPOSURE:
2217 ctrl->value = sensor->info_priv.exposure;
2220 case V4L2_CID_HFLIP:
2222 ctrl->value = sensor->info_priv.mirror;
2225 case V4L2_CID_VFLIP:
2227 ctrl->value = sensor->info_priv.flip;
2238 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2240 struct i2c_client *client = v4l2_get_subdevdata(sd);
2241 struct sensor *sensor = to_sensor(client);
2242 struct soc_camera_device *icd = client->dev.platform_data;
2243 const struct v4l2_queryctrl *qctrl;
2246 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2250 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2256 #if CONFIG_SENSOR_Brightness
2257 case V4L2_CID_BRIGHTNESS:
2259 if (ctrl->value != sensor->info_priv.brightness)
2261 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2265 sensor->info_priv.brightness = ctrl->value;
2270 #if CONFIG_SENSOR_Exposure
2271 case V4L2_CID_EXPOSURE:
2273 if (ctrl->value != sensor->info_priv.exposure)
2275 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2279 sensor->info_priv.exposure = ctrl->value;
2284 #if CONFIG_SENSOR_Saturation
2285 case V4L2_CID_SATURATION:
2287 if (ctrl->value != sensor->info_priv.saturation)
2289 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2293 sensor->info_priv.saturation = ctrl->value;
2298 #if CONFIG_SENSOR_Contrast
2299 case V4L2_CID_CONTRAST:
2301 if (ctrl->value != sensor->info_priv.contrast)
2303 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2307 sensor->info_priv.contrast = ctrl->value;
2312 #if CONFIG_SENSOR_WhiteBalance
2313 case V4L2_CID_DO_WHITE_BALANCE:
2315 if (ctrl->value != sensor->info_priv.whiteBalance)
2317 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2321 sensor->info_priv.whiteBalance = ctrl->value;
2326 #if CONFIG_SENSOR_Mirror
2327 case V4L2_CID_HFLIP:
2329 if (ctrl->value != sensor->info_priv.mirror)
2331 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2333 sensor->info_priv.mirror = ctrl->value;
2338 #if CONFIG_SENSOR_Flip
2339 case V4L2_CID_VFLIP:
2341 if (ctrl->value != sensor->info_priv.flip)
2343 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2345 sensor->info_priv.flip = ctrl->value;
2356 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2358 const struct v4l2_queryctrl *qctrl;
2359 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2360 struct sensor *sensor = to_sensor(client);
2362 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2366 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2370 switch (ext_ctrl->id)
2372 case V4L2_CID_SCENE:
2374 ext_ctrl->value = sensor->info_priv.scene;
2377 case V4L2_CID_EFFECT:
2379 ext_ctrl->value = sensor->info_priv.effect;
2382 case V4L2_CID_ZOOM_ABSOLUTE:
2384 ext_ctrl->value = sensor->info_priv.digitalzoom;
2387 case V4L2_CID_ZOOM_RELATIVE:
2391 case V4L2_CID_FOCUS_ABSOLUTE:
2393 ext_ctrl->value = sensor->info_priv.focus;
2396 case V4L2_CID_FOCUS_RELATIVE:
2400 case V4L2_CID_FLASH:
2402 ext_ctrl->value = sensor->info_priv.flash;
2410 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2412 const struct v4l2_queryctrl *qctrl;
2413 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2414 struct sensor *sensor = to_sensor(client);
2417 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2421 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2426 switch (ext_ctrl->id)
2428 #if CONFIG_SENSOR_Scene
2429 case V4L2_CID_SCENE:
2431 if (ext_ctrl->value != sensor->info_priv.scene)
2433 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2435 sensor->info_priv.scene = ext_ctrl->value;
2440 #if CONFIG_SENSOR_Effect
2441 case V4L2_CID_EFFECT:
2443 if (ext_ctrl->value != sensor->info_priv.effect)
2445 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2447 sensor->info_priv.effect= ext_ctrl->value;
2452 #if CONFIG_SENSOR_DigitalZoom
2453 case V4L2_CID_ZOOM_ABSOLUTE:
2455 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2458 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2460 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2462 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2464 sensor->info_priv.digitalzoom += val_offset;
2466 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2471 case V4L2_CID_ZOOM_RELATIVE:
2473 if (ext_ctrl->value)
2475 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2477 sensor->info_priv.digitalzoom += ext_ctrl->value;
2479 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2484 #if CONFIG_SENSOR_Focus
2485 case V4L2_CID_FOCUS_ABSOLUTE:
2487 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2490 if (ext_ctrl->value != sensor->info_priv.focus)
2492 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2494 sensor->info_priv.focus += val_offset;
2499 case V4L2_CID_FOCUS_RELATIVE:
2501 if (ext_ctrl->value)
2503 sensor->info_priv.focus += ext_ctrl->value;
2505 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2510 #if CONFIG_SENSOR_Flash
2511 case V4L2_CID_FLASH:
2513 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2515 sensor->info_priv.flash = ext_ctrl->value;
2517 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2528 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2530 struct i2c_client *client = v4l2_get_subdevdata(sd);
2531 struct soc_camera_device *icd = client->dev.platform_data;
2532 int i, error_cnt=0, error_idx=-1;
2535 for (i=0; i<ext_ctrl->count; i++) {
2536 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2543 error_idx = ext_ctrl->count;
2545 if (error_idx != -1) {
2546 ext_ctrl->error_idx = error_idx;
2553 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2555 struct i2c_client *client = v4l2_get_subdevdata(sd);
2556 struct soc_camera_device *icd = client->dev.platform_data;
2557 int i, error_cnt=0, error_idx=-1;
2560 for (i=0; i<ext_ctrl->count; i++) {
2561 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2568 error_idx = ext_ctrl->count;
2570 if (error_idx != -1) {
2571 ext_ctrl->error_idx = error_idx;
2578 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2579 * this wasn't our capture interface, so, we wait for the right one */
2580 static int sensor_video_probe(struct soc_camera_device *icd,
2581 struct i2c_client *client)
2585 struct sensor *sensor = to_sensor(client);
2587 /* We must have a parent by now. And it cannot be a wrong one.
2588 * So this entire test is completely redundant. */
2589 if (!icd->dev.parent ||
2590 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2593 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2595 goto sensor_video_probe_err;
2599 ret = sensor_write(client, 0xfe, 0x80);
2602 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2605 mdelay(5); //delay 5 microseconds
2607 /* check if it is an sensor sensor */
2608 ret = sensor_read(client, 0x00, &value);
2610 SENSOR_TR("read chip id high byte failed\n");
2612 goto sensor_video_probe_err;
2615 if (value == SENSOR_ID) {
2616 sensor->model = SENSOR_V4L2_IDENT;
2617 SENSOR_TR("chip id:0x%x\n",value);
2619 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2621 goto sensor_video_probe_err;
2626 sensor_video_probe_err:
2630 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2632 struct i2c_client *client = v4l2_get_subdevdata(sd);
2633 struct soc_camera_device *icd = client->dev.platform_data;
2634 struct sensor *sensor = to_sensor(client);
2636 #if CONFIG_SENSOR_Flash
2640 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2643 case RK29_CAM_SUBDEV_DEACTIVATE:
2645 sensor_deactivate(client);
2649 case RK29_CAM_SUBDEV_IOREQUEST:
2651 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2652 if (sensor->sensor_io_request != NULL) {
2653 sensor->sensor_gpio_res = NULL;
2654 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2655 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2656 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2657 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2660 if (sensor->sensor_gpio_res == NULL) {
2661 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2663 goto sensor_ioctl_end;
2666 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2668 goto sensor_ioctl_end;
2670 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2672 #if CONFIG_SENSOR_Flash
2673 if (sensor->sensor_gpio_res) {
2674 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2675 for (i = 0; i < icd->ops->num_controls; i++) {
2676 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2677 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2680 sensor->info_priv.flash = 0xff;
2681 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2689 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2697 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2698 enum v4l2_mbus_pixelcode *code)
2700 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2703 *code = sensor_colour_fmts[index].code;
2706 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2707 .init = sensor_init,
2708 .g_ctrl = sensor_g_control,
2709 .s_ctrl = sensor_s_control,
2710 .g_ext_ctrls = sensor_g_ext_controls,
2711 .s_ext_ctrls = sensor_s_ext_controls,
2712 .g_chip_ident = sensor_g_chip_ident,
2713 .ioctl = sensor_ioctl,
2716 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2717 .s_mbus_fmt = sensor_s_fmt,
2718 .g_mbus_fmt = sensor_g_fmt,
2719 .try_mbus_fmt = sensor_try_fmt,
2720 .enum_mbus_fmt = sensor_enum_fmt,
2723 static struct v4l2_subdev_ops sensor_subdev_ops = {
2724 .core = &sensor_subdev_core_ops,
2725 .video = &sensor_subdev_video_ops,
2728 static int sensor_probe(struct i2c_client *client,
2729 const struct i2c_device_id *did)
2731 struct sensor *sensor;
2732 struct soc_camera_device *icd = client->dev.platform_data;
2733 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2734 struct soc_camera_link *icl;
2737 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2739 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2743 icl = to_soc_camera_link(icd);
2745 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2749 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2750 dev_warn(&adapter->dev,
2751 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2755 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2759 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2761 /* Second stage probe - when a capture adapter is there */
2762 icd->ops = &sensor_ops;
2764 sensor->info_priv.fmt = sensor_colour_fmts[0];
2766 #if CONFIG_SENSOR_I2C_NOSCHED
2767 atomic_set(&sensor->tasklock_cnt,0);
2770 ret = sensor_video_probe(icd, client);
2773 i2c_set_clientdata(client, NULL);
2777 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2781 static int sensor_remove(struct i2c_client *client)
2783 struct sensor *sensor = to_sensor(client);
2784 struct soc_camera_device *icd = client->dev.platform_data;
2787 i2c_set_clientdata(client, NULL);
2788 client->driver = NULL;
2794 static const struct i2c_device_id sensor_id[] = {
2795 {SENSOR_NAME_STRING(), 0 },
2798 MODULE_DEVICE_TABLE(i2c, sensor_id);
2800 static struct i2c_driver sensor_i2c_driver = {
2802 .name = SENSOR_NAME_STRING(),
2804 .probe = sensor_probe,
2805 .remove = sensor_remove,
2806 .id_table = sensor_id,
2809 static int __init sensor_mod_init(void)
2811 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2812 return i2c_add_driver(&sensor_i2c_driver);
2815 static void __exit sensor_mod_exit(void)
2817 i2c_del_driver(&sensor_i2c_driver);
2820 device_initcall_sync(sensor_mod_init);
2821 module_exit(sensor_mod_exit);
2823 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2824 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2825 MODULE_LICENSE("GPL");