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(0, 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_PIX_FMT_UYVY
57 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_YVYU
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 1
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|\
78 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
79 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
81 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
82 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
83 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
84 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
85 #define COLOR_TEMPERATURE_OFFICE_DN 3500
86 #define COLOR_TEMPERATURE_OFFICE_UP 5000
87 #define COLOR_TEMPERATURE_HOME_DN 2500
88 #define COLOR_TEMPERATURE_HOME_UP 3500
90 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
91 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
100 /* init SVGA preview */
101 static struct reginfo sensor_init_data[] =
103 /*init registers code.*/
105 {0xfe,0x80}, // soft reset
108 {0xd2,0x10}, // close AEC
109 {0x22,0x55}, // close AWB
159 /////////////////////////////////////////////////////////////////////
160 /////////////////////////// grab_t ////////////////////////////////
161 /////////////////////////////////////////////////////////////////////
181 /////////////////////////////////////////////////////////////////////
182 /////////////////////////// LSC_t ////////////////////////////////
183 /////////////////////////////////////////////////////////////////////
195 /////////////////////////////////////////////////////////////////////
196 /////////////////////////// DNDD_t ///////////////////////////////
197 /////////////////////////////////////////////////////////////////////
206 /////////////////////////////////////////////////////////////////////
207 /////////////////////////// asde_t ///////////////////////////////
208 /////////////////////////////////////////////////////////////////////
218 /////////////////////////////////////////////////////////////////////
219 /////////////////////////// eeintp_t///////////////////////////////
220 /////////////////////////////////////////////////////////////////////
223 //for high resolution in light scene
235 /////////////////////////////////////////////////////////////////////
236 ///////////////////////////CC_t///////////////////////////////
237 /////////////////////////////////////////////////////////////////////
250 /////////////////////////////////////////////////////////////////////
251 ///////////////////////////YCP_t///////////////////////////////
252 /////////////////////////////////////////////////////////////////////
258 /////////////////////////////////////////////////////////////////////
259 ///////////////////////////AEC_t///////////////////////////////
260 /////////////////////////////////////////////////////////////////////
294 /////////////////////////////////////////////////////////////////
295 /////////////////////////// ABS_t ///////////////////////////////
296 /////////////////////////////////////////////////////////////////
302 /////////////////////////////////////////////////////////////////
303 /////////////////////////// Measure Window ///////////////////////
304 /////////////////////////////////////////////////////////////////
311 {0xfe,0x80}, // soft reset
314 {0xd2,0x10}, // close AEC
315 {0x22,0x55}, // close AWB
366 /////////////////////////////////////////////////////////////////////
367 /////////////////////////// grab_t ////////////////////////////////
368 /////////////////////////////////////////////////////////////////////
388 /////////////////////////////////////////////////////////////////////
389 /////////////////////////// LSC_t ////////////////////////////////
390 /////////////////////////////////////////////////////////////////////
402 /////////////////////////////////////////////////////////////////////
403 /////////////////////////// DNDD_t ///////////////////////////////
404 /////////////////////////////////////////////////////////////////////
413 /////////////////////////////////////////////////////////////////////
414 /////////////////////////// asde_t ///////////////////////////////
415 /////////////////////////////////////////////////////////////////////
425 /////////////////////////////////////////////////////////////////////
426 /////////////////////////// eeintp_t///////////////////////////////
433 static struct reginfo sensor_vga[] =
435 //{0x45 , 0x0f}, //output enable
436 {0x15 , 0x0a}, //output enable
441 static struct reginfo sensor_cif[] =
445 static struct reginfo sensor_qvga[] =
449 static struct reginfo sensor_qcif[] =
453 static struct reginfo sensor_ClrFmt_YUYV[]=
459 static struct reginfo sensor_ClrFmt_UYVY[]=
465 #if CONFIG_SENSOR_WhiteBalance
466 static struct reginfo sensor_WhiteB_Auto[]=
468 {0x5a,0x56}, //for AWB can adjust back
471 {0x22,0x57}, // Enable AWB
474 /* Cloudy Colour Temperature : 6500K - 8000K */
475 static struct reginfo sensor_WhiteB_Cloudy[]=
477 {0x22,0x55}, // Disable AWB
478 {0x5a,0x8c}, //WB_manual_gain
483 /* ClearDay Colour Temperature : 5000K - 6500K */
484 static struct reginfo sensor_WhiteB_ClearDay[]=
493 /* Office Colour Temperature : 3500K - 5000K */
494 static struct reginfo sensor_WhiteB_Incandescent[]=
504 /* Home Colour Temperature : 2500K - 3500K */
505 static struct reginfo sensor_WhiteB_Fluorescent[]=
514 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_Incandescent,sensor_WhiteB_Fluorescent,
515 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
519 #if CONFIG_SENSOR_Brightness
520 static struct reginfo sensor_Brightness0[]=
527 static struct reginfo sensor_Brightness1[]=
534 static struct reginfo sensor_Brightness2[]=
541 static struct reginfo sensor_Brightness3[]=
548 static struct reginfo sensor_Brightness4[]=
555 static struct reginfo sensor_Brightness5[]=
561 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
562 sensor_Brightness4, sensor_Brightness5,NULL,
567 #if CONFIG_SENSOR_Effect
568 static struct reginfo sensor_Effect_Normal[] =
584 static struct reginfo sensor_Effect_WandB[] =
601 static struct reginfo sensor_Effect_Sepia[] =
616 static struct reginfo sensor_Effect_Negative[] =
631 static struct reginfo sensor_Effect_Bluish[] =
647 static struct reginfo sensor_Effect_Green[] =
664 static struct reginfo sensor_Effect_Grayscale[]=
679 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
680 sensor_Effect_Bluish, sensor_Effect_Green,sensor_Effect_Grayscale,NULL,
683 #if CONFIG_SENSOR_Exposure
684 static struct reginfo sensor_Exposure0[]=
690 static struct reginfo sensor_Exposure1[]=
697 static struct reginfo sensor_Exposure2[]=
704 static struct reginfo sensor_Exposure3[]=
711 static struct reginfo sensor_Exposure4[]=
718 static struct reginfo sensor_Exposure5[]=
725 static struct reginfo sensor_Exposure6[]=
732 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
733 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
736 #if CONFIG_SENSOR_Saturation
737 static struct reginfo sensor_Saturation0[]=
743 static struct reginfo sensor_Saturation1[]=
749 static struct reginfo sensor_Saturation2[]=
754 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
757 #if CONFIG_SENSOR_Contrast
758 static struct reginfo sensor_Contrast0[]=
765 static struct reginfo sensor_Contrast1[]=
772 static struct reginfo sensor_Contrast2[]=
779 static struct reginfo sensor_Contrast3[]=
786 static struct reginfo sensor_Contrast4[]=
794 static struct reginfo sensor_Contrast5[]=
801 static struct reginfo sensor_Contrast6[]=
807 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
808 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
812 #if CONFIG_SENSOR_Mirror
813 static struct reginfo sensor_MirrorOn[]=
819 static struct reginfo sensor_MirrorOff[]=
824 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
826 #if CONFIG_SENSOR_Flip
827 static struct reginfo sensor_FlipOn[]=
833 static struct reginfo sensor_FlipOff[]=
838 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
841 #if CONFIG_SENSOR_Scene
842 static struct reginfo sensor_SceneAuto[] =
844 #if 0 /* ddl@rock-chips.com : */
852 {0x20 ,0x7f}, // close cc
861 static struct reginfo sensor_SceneNight[] =
864 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
866 {0x20 ,0x5f}, // close cc
873 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
889 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
892 #if CONFIG_SENSOR_DigitalZoom
893 static struct reginfo sensor_Zoom0[] =
898 static struct reginfo sensor_Zoom1[] =
903 static struct reginfo sensor_Zoom2[] =
909 static struct reginfo sensor_Zoom3[] =
913 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
915 static const struct v4l2_querymenu sensor_menus[] =
917 #if CONFIG_SENSOR_WhiteBalance
918 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
919 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
920 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
923 #if CONFIG_SENSOR_Effect
924 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
925 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
926 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
927 { .id = V4L2_CID_EFFECT, .index = 6, .name = "grayscale", .reserved = 0,},
930 #if CONFIG_SENSOR_Scene
931 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
934 #if CONFIG_SENSOR_Flash
935 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
936 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
940 static const struct v4l2_queryctrl sensor_controls[] =
942 #if CONFIG_SENSOR_WhiteBalance
944 .id = V4L2_CID_DO_WHITE_BALANCE,
945 .type = V4L2_CTRL_TYPE_MENU,
946 .name = "White Balance Control",
954 #if CONFIG_SENSOR_Brightness
956 .id = V4L2_CID_BRIGHTNESS,
957 .type = V4L2_CTRL_TYPE_INTEGER,
958 .name = "Brightness Control",
966 #if CONFIG_SENSOR_Effect
968 .id = V4L2_CID_EFFECT,
969 .type = V4L2_CTRL_TYPE_MENU,
970 .name = "Effect Control",
978 #if CONFIG_SENSOR_Exposure
980 .id = V4L2_CID_EXPOSURE,
981 .type = V4L2_CTRL_TYPE_INTEGER,
982 .name = "Exposure Control",
990 #if CONFIG_SENSOR_Saturation
992 .id = V4L2_CID_SATURATION,
993 .type = V4L2_CTRL_TYPE_INTEGER,
994 .name = "Saturation Control",
1002 #if CONFIG_SENSOR_Contrast
1004 .id = V4L2_CID_CONTRAST,
1005 .type = V4L2_CTRL_TYPE_INTEGER,
1006 .name = "Contrast Control",
1014 #if CONFIG_SENSOR_Mirror
1016 .id = V4L2_CID_HFLIP,
1017 .type = V4L2_CTRL_TYPE_BOOLEAN,
1018 .name = "Mirror Control",
1026 #if CONFIG_SENSOR_Flip
1028 .id = V4L2_CID_VFLIP,
1029 .type = V4L2_CTRL_TYPE_BOOLEAN,
1030 .name = "Flip Control",
1038 #if CONFIG_SENSOR_Scene
1040 .id = V4L2_CID_SCENE,
1041 .type = V4L2_CTRL_TYPE_MENU,
1042 .name = "Scene Control",
1050 #if CONFIG_SENSOR_DigitalZoom
1052 .id = V4L2_CID_ZOOM_RELATIVE,
1053 .type = V4L2_CTRL_TYPE_INTEGER,
1054 .name = "DigitalZoom Control",
1060 .id = V4L2_CID_ZOOM_ABSOLUTE,
1061 .type = V4L2_CTRL_TYPE_INTEGER,
1062 .name = "DigitalZoom Control",
1070 #if CONFIG_SENSOR_Focus
1072 .id = V4L2_CID_FOCUS_RELATIVE,
1073 .type = V4L2_CTRL_TYPE_INTEGER,
1074 .name = "Focus Control",
1080 .id = V4L2_CID_FOCUS_ABSOLUTE,
1081 .type = V4L2_CTRL_TYPE_INTEGER,
1082 .name = "Focus Control",
1086 .default_value = 125,
1090 #if CONFIG_SENSOR_Flash
1092 .id = V4L2_CID_FLASH,
1093 .type = V4L2_CTRL_TYPE_MENU,
1094 .name = "Flash Control",
1103 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1104 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1105 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1106 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1107 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1108 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1109 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1110 static int sensor_resume(struct soc_camera_device *icd);
1111 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1112 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1113 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1114 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1115 static int sensor_deactivate(struct i2c_client *client);
1117 static struct soc_camera_ops sensor_ops =
1119 .suspend = sensor_suspend,
1120 .resume = sensor_resume,
1121 .set_bus_param = sensor_set_bus_param,
1122 .query_bus_param = sensor_query_bus_param,
1123 .controls = sensor_controls,
1124 .menus = sensor_menus,
1125 .num_controls = ARRAY_SIZE(sensor_controls),
1126 .num_menus = ARRAY_SIZE(sensor_menus),
1129 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1130 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1131 .colorspace = _colorspace }
1133 #define JPG_FMT(_name, _depth, _fourcc) \
1134 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1136 static const struct soc_camera_data_format sensor_colour_formats[] = {
1137 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1138 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1141 typedef struct sensor_info_priv_s
1155 unsigned char mirror; /* HFLIP */
1156 unsigned char flip; /* VFLIP */
1157 unsigned int winseqe_cur_addr;
1158 unsigned int pixfmt;
1160 } sensor_info_priv_t;
1164 struct v4l2_subdev subdev;
1165 struct i2c_client *client;
1166 sensor_info_priv_t info_priv;
1167 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1168 #if CONFIG_SENSOR_I2C_NOSCHED
1169 atomic_t tasklock_cnt;
1171 struct rk29camera_platform_data *sensor_io_request;
1172 struct rk29camera_gpio_res *sensor_gpio_res;
1175 static struct sensor* to_sensor(const struct i2c_client *client)
1177 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1180 static int sensor_task_lock(struct i2c_client *client, int lock)
1182 #if CONFIG_SENSOR_I2C_NOSCHED
1184 struct sensor *sensor = to_sensor(client);
1187 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1188 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1189 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1193 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1194 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1195 goto sensor_task_lock_err;
1200 atomic_add(1, &sensor->tasklock_cnt);
1202 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1203 atomic_sub(1, &sensor->tasklock_cnt);
1205 if (atomic_read(&sensor->tasklock_cnt) == 0)
1211 sensor_task_lock_err:
1216 /* sensor register */
1217 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1221 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1223 return (ret > 0)? 0 : ret;
1226 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1230 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1232 return (ret > 0)? 0 : ret;
1235 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1239 struct i2c_msg msg[1];
1247 msg->addr = client->addr;
1248 msg->flags = client->flags;
1250 msg->len = sizeof(buf);
1251 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1252 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1257 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1258 err = i2c_transfer(client->adapter, msg, 1);
1263 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1271 /* sensor register read */
1272 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1276 struct i2c_msg msg[2];
1280 msg[0].addr = client->addr;
1281 msg[0].flags = client->flags;
1283 msg[0].len = sizeof(buf);
1284 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1285 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1287 msg[1].addr = client->addr;
1288 msg[1].flags = client->flags|I2C_M_RD;
1291 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1292 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1296 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1297 err = i2c_transfer(client->adapter, msg, 2);
1303 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1313 /* write a array of registers */
1314 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1322 if (sensor_task_lock(client, 1) < 0)
1323 goto sensor_write_array_end;
1324 while (regarray[i].reg != 0)
1326 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1330 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1334 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1336 goto sensor_write_array_end;
1339 #if CONFIG_SENSOR_I2C_RDWRCHK
1341 sensor_read(client, regarray[i].reg, &valchk);
1342 if (valchk != regarray[i].val)
1343 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1349 sensor_write_array_end:
1350 sensor_task_lock(client,0);
1353 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1361 while (regarray[i].reg != 0)
1363 sensor_read(client, regarray[i].reg, &valchk);
1364 if (valchk != regarray[i].val)
1365 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1371 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1373 struct soc_camera_link *icl = to_soc_camera_link(icd);
1376 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1379 case Sensor_PowerDown:
1381 if (icl->powerdown) {
1382 ret = icl->powerdown(icd->pdev, on);
1383 if (ret == RK29_CAM_IO_SUCCESS) {
1387 icl->reset(icd->pdev);
1389 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1391 goto sensor_power_end;
1398 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1399 struct sensor *sensor = to_sensor(client);
1401 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1402 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1408 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1415 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1417 struct i2c_client *client = sd->priv;
1418 struct soc_camera_device *icd = client->dev.platform_data;
1419 struct sensor *sensor = to_sensor(client);
1420 const struct v4l2_queryctrl *qctrl;
1424 SENSOR_DG("\n-------------%s..%s.. %d,val = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__,val);
1426 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1427 SENSOR_DG("\n-------------%s..%s.. %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1429 goto sensor_INIT_ERR;
1433 if (sensor_task_lock(client,1)<0)
1434 goto sensor_INIT_ERR;
1435 ret = sensor_write(client, 0xfe, 0x80);
1438 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1440 goto sensor_INIT_ERR;
1442 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1443 mdelay(5); //delay 5 microseconds
1444 /* check if it is an sensor sensor */
1445 ret = sensor_read(client, 0x00, &value);
1447 SENSOR_TR("read chip id high byte failed\n");
1449 goto sensor_INIT_ERR;
1451 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1452 if (value == SENSOR_ID) {
1453 sensor->model = SENSOR_V4L2_IDENT;
1455 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
1457 goto sensor_INIT_ERR;
1459 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1460 ret = sensor_write_array(client, sensor_init_data);
1463 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1464 goto sensor_INIT_ERR;
1466 sensor_task_lock(client,0);
1467 //icd->user_width = SENSOR_INIT_WIDTH;
1468 //icd->user_height = SENSOR_INIT_HEIGHT;
1469 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1470 sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
1471 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1472 /* sensor sensor information for initialization */
1473 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1475 sensor->info_priv.whiteBalance = qctrl->default_value;
1476 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1478 sensor->info_priv.brightness = qctrl->default_value;
1479 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1481 sensor->info_priv.effect = qctrl->default_value;
1482 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1484 sensor->info_priv.exposure = qctrl->default_value;
1486 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1488 sensor->info_priv.saturation = qctrl->default_value;
1489 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1491 sensor->info_priv.contrast = qctrl->default_value;
1492 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1494 sensor->info_priv.mirror = qctrl->default_value;
1495 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1497 sensor->info_priv.flip = qctrl->default_value;
1498 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1500 sensor->info_priv.scene = qctrl->default_value;
1501 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1503 sensor->info_priv.digitalzoom = qctrl->default_value;
1505 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1506 #if CONFIG_SENSOR_Focus
1507 //sensor_set_focus();
1508 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1510 sensor->info_priv.focus = qctrl->default_value;
1512 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1513 #if CONFIG_SENSOR_Flash
1514 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1516 sensor->info_priv.flash = qctrl->default_value;
1519 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);
1523 sensor_task_lock(client,0);
1524 sensor_deactivate(client);
1528 static int sensor_deactivate(struct i2c_client *client)
1530 struct soc_camera_device *icd = client->dev.platform_data;
1531 SENSOR_DG("\n----------------------------%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1533 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1534 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1536 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1537 icd->user_width = SENSOR_INIT_WIDTH;
1538 icd->user_height = SENSOR_INIT_HEIGHT;
1543 static struct reginfo sensor_power_down_sequence[]=
1547 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1550 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1552 if (pm_msg.event == PM_EVENT_SUSPEND) {
1553 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1554 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1556 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1559 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1561 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1566 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1572 static int sensor_resume(struct soc_camera_device *icd)
1576 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1578 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1582 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1588 static int sensor_set_bus_param(struct soc_camera_device *icd,
1589 unsigned long flags)
1595 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1597 struct soc_camera_link *icl = to_soc_camera_link(icd);
1598 unsigned long flags = SENSOR_BUS_PARAM;
1600 return soc_camera_apply_sensor_flags(icl, flags);
1603 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1605 struct i2c_client *client = sd->priv;
1606 struct soc_camera_device *icd = client->dev.platform_data;
1607 struct sensor *sensor = to_sensor(client);
1608 struct v4l2_pix_format *pix = &f->fmt.pix;
1610 pix->width = icd->user_width;
1611 pix->height = icd->user_height;
1612 pix->pixelformat = sensor->info_priv.pixfmt;
1613 pix->field = V4L2_FIELD_NONE;
1614 pix->colorspace = V4L2_COLORSPACE_JPEG;
1618 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_format *f)
1622 if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
1624 } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
1626 } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
1628 } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
1630 } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
1635 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1639 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_format *f)
1643 if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 720)) {
1645 } else if ((f->fmt.pix.width == 1920) && (f->fmt.pix.height == 1080)) {
1650 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1653 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1655 struct i2c_client *client = sd->priv;
1656 struct sensor *sensor = to_sensor(client);
1657 struct v4l2_pix_format *pix = &f->fmt.pix;
1658 const struct v4l2_queryctrl *qctrl;
1659 struct soc_camera_device *icd = client->dev.platform_data;
1660 struct reginfo *winseqe_set_addr=NULL;
1661 int ret=0, set_w,set_h;
1663 SENSOR_TR("------------------------------%s, %s ,%d,\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1664 if (sensor->info_priv.pixfmt != pix->pixelformat) {
1665 SENSOR_TR("------------------------------%s, %s ,%d,\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1666 switch (pix->pixelformat)
1668 SENSOR_TR("------------------------------%s, %s ,%d,\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1669 case V4L2_PIX_FMT_YUYV:
1671 SENSOR_TR("------------------------------%s, %s ,%d,\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1672 winseqe_set_addr = sensor_ClrFmt_YUYV;
1675 case V4L2_PIX_FMT_UYVY:
1677 SENSOR_TR("------------------------------%s, %s ,%d,\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1678 winseqe_set_addr = sensor_ClrFmt_UYVY;
1684 if (winseqe_set_addr != NULL) {
1685 sensor_write_array(client, winseqe_set_addr);
1686 sensor->info_priv.pixfmt = pix->pixelformat;
1688 SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1690 SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1695 set_h = pix->height;
1696 SENSOR_TR("------------------------------%s, %s ,%d,\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1697 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1699 winseqe_set_addr = sensor_qcif;
1703 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1705 winseqe_set_addr = sensor_qvga;
1709 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1711 winseqe_set_addr = sensor_cif;
1715 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1717 winseqe_set_addr = sensor_vga;
1724 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1725 set_w = SENSOR_INIT_WIDTH;
1726 set_h = SENSOR_INIT_HEIGHT;
1727 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1729 SENSOR_TR("------------------------------%s, %s ,%d,\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
1730 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1731 ret |= sensor_write_array(client, winseqe_set_addr);
1733 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1734 goto sensor_s_fmt_end;
1737 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1739 if (sensor_fmt_capturechk(sd,f) == true) { /* ddl@rock-chips.com : Capture */
1740 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1741 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1742 if (sensor->info_priv.whiteBalance != 0) {
1743 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1744 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1746 sensor->info_priv.snap2preview = true;
1747 } else if (sensor_fmt_videochk(sd,f) == true) { /* ddl@rock-chips.com : Video */
1748 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1749 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1750 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1751 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1752 sensor->info_priv.video2preview = true;
1753 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1754 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1755 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1756 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1757 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1758 sensor->info_priv.video2preview = false;
1759 sensor->info_priv.snap2preview = false;
1761 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1765 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1769 pix->height = set_h;
1775 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1777 struct v4l2_pix_format *pix = &f->fmt.pix;
1778 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1779 pix->pixelformat == V4L2_PIX_FMT_YUYV;
1782 * With Bayer format enforce even side lengths, but let the user play
1783 * with the starting pixel
1786 if (pix->height > SENSOR_MAX_HEIGHT)
1787 pix->height = SENSOR_MAX_HEIGHT;
1788 else if (pix->height < SENSOR_MIN_HEIGHT)
1789 pix->height = SENSOR_MIN_HEIGHT;
1791 pix->height = ALIGN(pix->height, 2);
1793 if (pix->width > SENSOR_MAX_WIDTH)
1794 pix->width = SENSOR_MAX_WIDTH;
1795 else if (pix->width < SENSOR_MIN_WIDTH)
1796 pix->width = SENSOR_MIN_WIDTH;
1798 pix->width = ALIGN(pix->width, 2);
1803 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1805 struct i2c_client *client = sd->priv;
1807 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1810 if (id->match.addr != client->addr)
1813 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1818 #if CONFIG_SENSOR_Brightness
1819 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1821 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1823 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1825 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1827 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1829 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1832 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1836 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1840 #if CONFIG_SENSOR_Effect
1841 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1843 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1845 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1847 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1849 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1851 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1854 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1858 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1862 #if CONFIG_SENSOR_Exposure
1863 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1865 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1867 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1869 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1871 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1873 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1876 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1880 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1884 #if CONFIG_SENSOR_Saturation
1885 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1887 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1889 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1891 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1893 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1895 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1898 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1902 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1906 #if CONFIG_SENSOR_Contrast
1907 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1909 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1911 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1913 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1915 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1917 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1920 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1924 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1928 #if CONFIG_SENSOR_Mirror
1929 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1931 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1933 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1935 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1937 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
1939 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1942 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1946 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1950 #if CONFIG_SENSOR_Flip
1951 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1953 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1955 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1957 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
1959 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
1961 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1964 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1968 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1972 #if CONFIG_SENSOR_Scene
1973 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1975 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1977 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1979 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
1981 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
1983 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1986 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1990 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1994 #if CONFIG_SENSOR_WhiteBalance
1995 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1997 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1999 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2001 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2003 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2005 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2008 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2012 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2016 #if CONFIG_SENSOR_DigitalZoom
2017 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2019 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2020 struct sensor *sensor = to_sensor(client);
2021 const struct v4l2_queryctrl *qctrl_info;
2022 int digitalzoom_cur, digitalzoom_total;
2024 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2028 digitalzoom_cur = sensor->info_priv.digitalzoom;
2029 digitalzoom_total = qctrl_info->maximum;
2031 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2033 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2037 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2039 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2043 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2045 *value = digitalzoom_total - digitalzoom_cur;
2048 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2050 *value = 0 - digitalzoom_cur;
2053 digitalzoom_cur += *value;
2055 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2057 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2059 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2062 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2069 #if CONFIG_SENSOR_Flash
2070 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2072 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2073 if (value == 3) { /* ddl@rock-chips.com: torch */
2074 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2076 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
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);
2087 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2089 struct i2c_client *client = sd->priv;
2090 struct sensor *sensor = to_sensor(client);
2091 const struct v4l2_queryctrl *qctrl;
2093 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2097 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2103 case V4L2_CID_BRIGHTNESS:
2105 ctrl->value = sensor->info_priv.brightness;
2108 case V4L2_CID_SATURATION:
2110 ctrl->value = sensor->info_priv.saturation;
2113 case V4L2_CID_CONTRAST:
2115 ctrl->value = sensor->info_priv.contrast;
2118 case V4L2_CID_DO_WHITE_BALANCE:
2120 ctrl->value = sensor->info_priv.whiteBalance;
2123 case V4L2_CID_EXPOSURE:
2125 ctrl->value = sensor->info_priv.exposure;
2128 case V4L2_CID_HFLIP:
2130 ctrl->value = sensor->info_priv.mirror;
2133 case V4L2_CID_VFLIP:
2135 ctrl->value = sensor->info_priv.flip;
2146 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2148 struct i2c_client *client = sd->priv;
2149 struct sensor *sensor = to_sensor(client);
2150 struct soc_camera_device *icd = client->dev.platform_data;
2151 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 #if CONFIG_SENSOR_Brightness
2165 case V4L2_CID_BRIGHTNESS:
2167 if (ctrl->value != sensor->info_priv.brightness)
2169 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2173 sensor->info_priv.brightness = ctrl->value;
2178 #if CONFIG_SENSOR_Exposure
2179 case V4L2_CID_EXPOSURE:
2181 if (ctrl->value != sensor->info_priv.exposure)
2183 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2187 sensor->info_priv.exposure = ctrl->value;
2192 #if CONFIG_SENSOR_Saturation
2193 case V4L2_CID_SATURATION:
2195 if (ctrl->value != sensor->info_priv.saturation)
2197 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2201 sensor->info_priv.saturation = ctrl->value;
2206 #if CONFIG_SENSOR_Contrast
2207 case V4L2_CID_CONTRAST:
2209 if (ctrl->value != sensor->info_priv.contrast)
2211 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2215 sensor->info_priv.contrast = ctrl->value;
2220 #if CONFIG_SENSOR_WhiteBalance
2221 case V4L2_CID_DO_WHITE_BALANCE:
2223 if (ctrl->value != sensor->info_priv.whiteBalance)
2225 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2229 sensor->info_priv.whiteBalance = ctrl->value;
2234 #if CONFIG_SENSOR_Mirror
2235 case V4L2_CID_HFLIP:
2237 if (ctrl->value != sensor->info_priv.mirror)
2239 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2241 sensor->info_priv.mirror = ctrl->value;
2246 #if CONFIG_SENSOR_Flip
2247 case V4L2_CID_VFLIP:
2249 if (ctrl->value != sensor->info_priv.flip)
2251 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2253 sensor->info_priv.flip = ctrl->value;
2264 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2266 const struct v4l2_queryctrl *qctrl;
2267 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2268 struct sensor *sensor = to_sensor(client);
2270 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2274 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2278 switch (ext_ctrl->id)
2280 case V4L2_CID_SCENE:
2282 ext_ctrl->value = sensor->info_priv.scene;
2285 case V4L2_CID_EFFECT:
2287 ext_ctrl->value = sensor->info_priv.effect;
2290 case V4L2_CID_ZOOM_ABSOLUTE:
2292 ext_ctrl->value = sensor->info_priv.digitalzoom;
2295 case V4L2_CID_ZOOM_RELATIVE:
2299 case V4L2_CID_FOCUS_ABSOLUTE:
2301 ext_ctrl->value = sensor->info_priv.focus;
2304 case V4L2_CID_FOCUS_RELATIVE:
2308 case V4L2_CID_FLASH:
2310 ext_ctrl->value = sensor->info_priv.flash;
2318 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2320 const struct v4l2_queryctrl *qctrl;
2321 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2322 struct sensor *sensor = to_sensor(client);
2325 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2329 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2334 switch (ext_ctrl->id)
2336 #if CONFIG_SENSOR_Scene
2337 case V4L2_CID_SCENE:
2339 if (ext_ctrl->value != sensor->info_priv.scene)
2341 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2343 sensor->info_priv.scene = ext_ctrl->value;
2348 #if CONFIG_SENSOR_Effect
2349 case V4L2_CID_EFFECT:
2351 if (ext_ctrl->value != sensor->info_priv.effect)
2353 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2355 sensor->info_priv.effect= ext_ctrl->value;
2360 #if CONFIG_SENSOR_DigitalZoom
2361 case V4L2_CID_ZOOM_ABSOLUTE:
2363 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2366 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2368 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2370 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2372 sensor->info_priv.digitalzoom += val_offset;
2374 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2379 case V4L2_CID_ZOOM_RELATIVE:
2381 if (ext_ctrl->value)
2383 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2385 sensor->info_priv.digitalzoom += ext_ctrl->value;
2387 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2392 #if CONFIG_SENSOR_Focus
2393 case V4L2_CID_FOCUS_ABSOLUTE:
2395 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2398 if (ext_ctrl->value != sensor->info_priv.focus)
2400 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2402 sensor->info_priv.focus += val_offset;
2407 case V4L2_CID_FOCUS_RELATIVE:
2409 if (ext_ctrl->value)
2411 sensor->info_priv.focus += ext_ctrl->value;
2413 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2418 #if CONFIG_SENSOR_Flash
2419 case V4L2_CID_FLASH:
2421 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2423 sensor->info_priv.flash = ext_ctrl->value;
2425 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2436 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2438 struct i2c_client *client = sd->priv;
2439 struct soc_camera_device *icd = client->dev.platform_data;
2440 int i, error_cnt=0, error_idx=-1;
2443 for (i=0; i<ext_ctrl->count; i++) {
2444 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2451 error_idx = ext_ctrl->count;
2453 if (error_idx != -1) {
2454 ext_ctrl->error_idx = error_idx;
2461 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2463 struct i2c_client *client = sd->priv;
2464 struct soc_camera_device *icd = client->dev.platform_data;
2465 int i, error_cnt=0, error_idx=-1;
2468 for (i=0; i<ext_ctrl->count; i++) {
2469 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2476 error_idx = ext_ctrl->count;
2478 if (error_idx != -1) {
2479 ext_ctrl->error_idx = error_idx;
2486 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2487 * this wasn't our capture interface, so, we wait for the right one */
2488 static int sensor_video_probe(struct soc_camera_device *icd,
2489 struct i2c_client *client)
2493 struct sensor *sensor = to_sensor(client);
2495 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
2497 /* We must have a parent by now. And it cannot be a wrong one.
2498 * So this entire test is completely redundant. */
2499 if (!icd->dev.parent ||
2500 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2503 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2505 goto sensor_video_probe_err;
2507 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
2509 ret = sensor_write(client, 0xfe, 0x80);
2512 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2515 mdelay(5); //delay 5 microseconds
2516 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
2517 /* check if it is an sensor sensor */
2518 ret = sensor_read(client, 0x00, &value);
2520 SENSOR_TR("read chip id high byte failed\n");
2522 goto sensor_video_probe_err;
2524 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
2525 if (value == SENSOR_ID) {
2526 sensor->model = SENSOR_V4L2_IDENT;
2527 SENSOR_TR("chip id:0x%x\n",value);
2529 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2531 goto sensor_video_probe_err;
2534 icd->formats = sensor_colour_formats;
2535 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2536 SENSOR_DG("--------------------%s , %s, %d\n",SENSOR_NAME_STRING(),__FUNCTION__,__LINE__);
2539 sensor_video_probe_err:
2543 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2545 struct i2c_client *client = sd->priv;
2546 struct soc_camera_device *icd = client->dev.platform_data;
2547 struct sensor *sensor = to_sensor(client);
2549 #if CONFIG_SENSOR_Flash
2553 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2556 case RK29_CAM_SUBDEV_DEACTIVATE:
2558 sensor_deactivate(client);
2562 case RK29_CAM_SUBDEV_IOREQUEST:
2564 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2565 if (sensor->sensor_io_request != NULL) {
2566 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2567 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2568 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2569 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2570 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2571 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2574 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2576 goto sensor_ioctl_end;
2578 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2580 #if CONFIG_SENSOR_Flash
2581 if (sensor->sensor_gpio_res) {
2582 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2583 for (i = 0; i < icd->ops->num_controls; i++) {
2584 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2585 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2588 sensor->info_priv.flash = 0xff;
2589 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2597 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2605 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2606 .init = sensor_init,
2607 .g_ctrl = sensor_g_control,
2608 .s_ctrl = sensor_s_control,
2609 .g_ext_ctrls = sensor_g_ext_controls,
2610 .s_ext_ctrls = sensor_s_ext_controls,
2611 .g_chip_ident = sensor_g_chip_ident,
2612 .ioctl = sensor_ioctl,
2615 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2616 .s_fmt = sensor_s_fmt,
2617 .g_fmt = sensor_g_fmt,
2618 .try_fmt = sensor_try_fmt,
2621 static struct v4l2_subdev_ops sensor_subdev_ops = {
2622 .core = &sensor_subdev_core_ops,
2623 .video = &sensor_subdev_video_ops,
2626 static int sensor_probe(struct i2c_client *client,
2627 const struct i2c_device_id *did)
2629 struct sensor *sensor;
2630 struct soc_camera_device *icd = client->dev.platform_data;
2631 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2632 struct soc_camera_link *icl;
2635 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2637 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2641 icl = to_soc_camera_link(icd);
2643 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2647 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2648 dev_warn(&adapter->dev,
2649 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2653 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2657 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2659 /* Second stage probe - when a capture adapter is there */
2660 icd->ops = &sensor_ops;
2661 icd->y_skip_top = 0;
2662 #if CONFIG_SENSOR_I2C_NOSCHED
2663 atomic_set(&sensor->tasklock_cnt,0);
2666 ret = sensor_video_probe(icd, client);
2669 i2c_set_clientdata(client, NULL);
2673 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2677 static int sensor_remove(struct i2c_client *client)
2679 struct sensor *sensor = to_sensor(client);
2680 struct soc_camera_device *icd = client->dev.platform_data;
2683 i2c_set_clientdata(client, NULL);
2684 client->driver = NULL;
2690 static const struct i2c_device_id sensor_id[] = {
2691 {SENSOR_NAME_STRING(), 0 },
2694 MODULE_DEVICE_TABLE(i2c, sensor_id);
2696 static struct i2c_driver sensor_i2c_driver = {
2698 .name = SENSOR_NAME_STRING(),
2700 .probe = sensor_probe,
2701 .remove = sensor_remove,
2702 .id_table = sensor_id,
2705 static int __init sensor_mod_init(void)
2707 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2708 return i2c_add_driver(&sensor_i2c_driver);
2711 static void __exit sensor_mod_exit(void)
2713 i2c_del_driver(&sensor_i2c_driver);
2716 device_initcall_sync(sensor_mod_init);
2717 module_exit(sensor_mod_exit);
2719 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2720 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2721 MODULE_LICENSE("GPL");