1 #include <linux/videodev2.h>
\r
2 #include <linux/slab.h>
4 #include <linux/log2.h>
5 #include <linux/platform_device.h>
6 #include <linux/delay.h>
7 #include <linux/circ_buf.h>
8 #include <linux/miscdevice.h>
9 #include <media/v4l2-common.h>
10 #include <media/v4l2-chip-ident.h>
11 #include <media/soc_camera.h>
12 #include <plat/rk_camera.h>
\r
15 module_param(debug, int, S_IRUGO|S_IWUSR);
17 #define dprintk(level, fmt, arg...) do { \
19 printk(KERN_WARNING fmt , ## arg); } while (0)
21 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
22 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
25 #define _CONS(a,b) a##b
26 #define CONS(a,b) _CONS(a,b)
29 #define _STR(x) __STR(x)
30 #define STR(x) _STR(x)
32 #define MIN(x,y) ((x<y) ? x: y)
33 #define MAX(x,y) ((x>y) ? x: y)
35 /* Sensor Driver Configuration */
36 #define SENSOR_NAME RK29_CAM_SENSOR_OV2640
37 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2640
38 #define SENSOR_ID 0x2642
39 #define SENSOR_ID1 0x2641
40 #define SENSOR_MIN_WIDTH 640
41 #define SENSOR_MIN_HEIGHT 480
42 #define SENSOR_MAX_WIDTH 1600
43 #define SENSOR_MAX_HEIGHT 1200
44 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
45 #define SENSOR_INIT_HEIGHT 480
46 #define SENSOR_INIT_WINSEQADR sensor_vga
47 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
49 #define CONFIG_SENSOR_WhiteBalance 0
50 #define CONFIG_SENSOR_Brightness 1
51 #define CONFIG_SENSOR_Contrast 0
52 #define CONFIG_SENSOR_Saturation 1
53 #define CONFIG_SENSOR_Effect 1
54 #define CONFIG_SENSOR_Scene 0
55 #define CONFIG_SENSOR_DigitalZoom 0
56 #define CONFIG_SENSOR_Focus 0
57 #define CONFIG_SENSOR_Exposure 0
58 #define CONFIG_SENSOR_Flash 1
\r
59 #define CONFIG_SENSOR_Mirror 0
60 #define CONFIG_SENSOR_Flip 0
62 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
63 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
64 #define CONFIG_SENSOR_I2C_NOSCHED 0
65 #define CONFIG_SENSOR_I2C_RDWRCHK 0
67 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
68 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
69 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
71 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
72 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
73 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
74 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
75 #define COLOR_TEMPERATURE_OFFICE_DN 3500
76 #define COLOR_TEMPERATURE_OFFICE_UP 5000
77 #define COLOR_TEMPERATURE_HOME_DN 2500
78 #define COLOR_TEMPERATURE_HOME_UP 3500
80 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
81 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
89 /* init 800*600 SVGA */
90 static struct reginfo sensor_init_data[] =
107 {0x04,0xF8},//b7,b6 directs
177 {0x7d,0x00},//0x00//0x07
179 {0x7d,0x48},//0x48//0x40
180 {0x7d,0x48},//0x48//0x40
321 {0x0, 0x0} //end flag
326 static struct reginfo sensor_uxga[] =
345 {0x0, 0x0} //end flag
349 static struct reginfo sensor_sxga[] =
368 {0x0, 0x0} //end flag
372 static struct reginfo sensor_xga[] =
391 {0x0, 0x0} //end flag
398 static struct reginfo sensor_svga[] =
400 {0x0, 0x0} //end flag
404 static struct reginfo sensor_vga[] =
406 {0x0, 0x0} //end flag
410 static struct reginfo sensor_cif[] =
412 {0x0, 0x0} //end flag
416 static struct reginfo sensor_qvga[] =
418 {0x0, 0x0} //end flag
422 static struct reginfo sensor_qcif[] =
424 {0x0, 0x0} //end flag
428 static struct reginfo ov2655_qqvga[] =
472 static struct reginfo ov2655_Sharpness_auto[] =
477 static struct reginfo ov2655_Sharpness1[] =
483 static struct reginfo ov2655_Sharpness2[][3] =
490 static struct reginfo ov2655_Sharpness3[] =
496 static struct reginfo ov2655_Sharpness4[]=
503 static struct reginfo ov2655_Sharpness5[] =
511 static struct reginfo sensor_ClrFmt_YUYV[]=
517 static struct reginfo sensor_ClrFmt_UYVY[]=
523 #if CONFIG_SENSOR_WhiteBalance
524 static struct reginfo sensor_WhiteB_Auto[]=
526 {0x3406, 0x00}, //AWB auto, bit[1]:0,auto
529 /* Cloudy Colour Temperature : 6500K - 8000K */
530 static struct reginfo sensor_WhiteB_Cloudy[]=
541 /* ClearDay Colour Temperature : 5000K - 6500K */
542 static struct reginfo sensor_WhiteB_ClearDay[]=
554 /* Office Colour Temperature : 3500K - 5000K */
555 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
568 /* Home Colour Temperature : 2500K - 3500K */
569 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
581 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
582 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
586 #if CONFIG_SENSOR_Brightness
587 static struct reginfo sensor_Brightness0[]=
594 {0x0, 0x0} //end flag
597 static struct reginfo sensor_Brightness1[]=
605 {0x0, 0x0} //end flag
608 static struct reginfo sensor_Brightness2[]=
616 {0x0, 0x0} //end flag
619 static struct reginfo sensor_Brightness3[]=
627 {0x0, 0x0} //end flag
630 static struct reginfo sensor_Brightness4[]=
638 {0x0, 0x0} //end flag
641 static struct reginfo sensor_Brightness5[]=
648 {0x0, 0x0} //end flag
650 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
651 sensor_Brightness4, sensor_Brightness5,NULL,
656 #if CONFIG_SENSOR_Effect
657 static struct reginfo sensor_Effect_Normal[] =
665 {0x0, 0x0} //end flag
668 static struct reginfo sensor_Effect_WandB[] =
676 {0x0, 0x0} //end flag
679 static struct reginfo sensor_Effect_Sepia[] =
687 {0x0, 0x0} //end flag
690 static struct reginfo sensor_Effect_Negative[] =
698 {0x0, 0x0} //end flag
700 static struct reginfo sensor_Effect_Bluish[] =
708 {0x0, 0x0} //end flag
711 static struct reginfo sensor_Effect_Green[] =
719 {0x0, 0x0} //end flag
722 static struct reginfo sensor_Effect_Exp_Windows_Half[] =
729 {0x0, 0x0} //end flag
731 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
732 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
735 #if CONFIG_SENSOR_Exposure
736 static struct reginfo sensor_Exposure0[]=
741 static struct reginfo sensor_Exposure1[]=
746 static struct reginfo sensor_Exposure2[]=
751 static struct reginfo sensor_Exposure3[]=
756 static struct reginfo sensor_Exposure4[]=
761 static struct reginfo sensor_Exposure5[]=
766 static struct reginfo sensor_Exposure6[]=
771 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
772 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
775 #if CONFIG_SENSOR_Saturation
776 static struct reginfo sensor_Saturation0[]=
796 {0x0, 0x0} //end flag
799 static struct reginfo sensor_Saturation1[]=
819 {0x0, 0x0} //end flag
822 static struct reginfo sensor_Saturation2[]=
842 {0x0, 0x0} //end flag
844 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
848 #if CONFIG_SENSOR_Contrast
849 static struct reginfo sensor_Contrast0[]=
859 {0x0, 0x0} //end flag
863 static struct reginfo sensor_Contrast1[]=
873 {0x0, 0x0} //end flag
876 static struct reginfo sensor_Contrast2[]=
886 {0x0, 0x0} //end flag
889 static struct reginfo sensor_Contrast3[]=
899 {0x0, 0x0} //end flag
902 static struct reginfo sensor_Contrast4[]=
912 {0x0, 0x0} //end flag
916 static struct reginfo sensor_Contrast5[]=
926 {0x0, 0x0} //end flag
929 static struct reginfo sensor_Contrast6[]=
939 {0x0, 0x0} //end flag
943 static struct reginfo sensor_Contrast7[]=
953 {0x0, 0x0} //end flag
956 static struct reginfo sensor_Contrast8[]=
966 {0x0, 0x0} //end flag
969 static struct reginfo sensor_Contrast9[]=
979 {0x0, 0x0} //end flag
984 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
985 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
989 #if CONFIG_SENSOR_Mirror
990 static struct reginfo sensor_MirrorOn[]=
995 static struct reginfo sensor_MirrorOff[]=
999 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1001 #if CONFIG_SENSOR_Flip
1002 static struct reginfo sensor_FlipOn[]=
1007 static struct reginfo sensor_FlipOff[]=
1011 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1014 #if CONFIG_SENSOR_Scene
1015 static struct reginfo sensor_SceneAuto[] =
1021 static struct reginfo sensor_SceneNight[] =
1034 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1037 #if CONFIG_SENSOR_DigitalZoom
1038 static struct reginfo sensor_Zoom0[] =
1043 static struct reginfo sensor_Zoom1[] =
1048 static struct reginfo sensor_Zoom2[] =
1054 static struct reginfo sensor_Zoom3[] =
1058 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1060 static const struct v4l2_querymenu sensor_menus[] =
1062 #if CONFIG_SENSOR_WhiteBalance
1063 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1064 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1065 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1068 #if CONFIG_SENSOR_Effect
1069 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1070 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1071 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1074 #if CONFIG_SENSOR_Scene
1075 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1078 #if CONFIG_SENSOR_Flash
1079 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1080 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1084 static const struct v4l2_queryctrl sensor_controls[] =
1086 #if CONFIG_SENSOR_WhiteBalance
1088 .id = V4L2_CID_DO_WHITE_BALANCE,
1089 .type = V4L2_CTRL_TYPE_MENU,
1090 .name = "White Balance Control",
1098 #if CONFIG_SENSOR_Brightness
1100 .id = V4L2_CID_BRIGHTNESS,
1101 .type = V4L2_CTRL_TYPE_INTEGER,
1102 .name = "Brightness Control",
1110 #if CONFIG_SENSOR_Effect
1112 .id = V4L2_CID_EFFECT,
1113 .type = V4L2_CTRL_TYPE_MENU,
1114 .name = "Effect Control",
1122 #if CONFIG_SENSOR_Exposure
1124 .id = V4L2_CID_EXPOSURE,
1125 .type = V4L2_CTRL_TYPE_INTEGER,
1126 .name = "Exposure Control",
1134 #if CONFIG_SENSOR_Saturation
1136 .id = V4L2_CID_SATURATION,
1137 .type = V4L2_CTRL_TYPE_INTEGER,
1138 .name = "Saturation Control",
1146 #if CONFIG_SENSOR_Contrast
1148 .id = V4L2_CID_CONTRAST,
1149 .type = V4L2_CTRL_TYPE_INTEGER,
1150 .name = "Contrast Control",
1158 #if CONFIG_SENSOR_Mirror
1160 .id = V4L2_CID_HFLIP,
1161 .type = V4L2_CTRL_TYPE_BOOLEAN,
1162 .name = "Mirror Control",
1170 #if CONFIG_SENSOR_Flip
1172 .id = V4L2_CID_VFLIP,
1173 .type = V4L2_CTRL_TYPE_BOOLEAN,
1174 .name = "Flip Control",
1182 #if CONFIG_SENSOR_Scene
1184 .id = V4L2_CID_SCENE,
1185 .type = V4L2_CTRL_TYPE_MENU,
1186 .name = "Scene Control",
1194 #if CONFIG_SENSOR_DigitalZoom
1196 .id = V4L2_CID_ZOOM_RELATIVE,
1197 .type = V4L2_CTRL_TYPE_INTEGER,
1198 .name = "DigitalZoom Control",
1204 .id = V4L2_CID_ZOOM_ABSOLUTE,
1205 .type = V4L2_CTRL_TYPE_INTEGER,
1206 .name = "DigitalZoom Control",
1214 #if CONFIG_SENSOR_Focus
1216 .id = V4L2_CID_FOCUS_RELATIVE,
1217 .type = V4L2_CTRL_TYPE_INTEGER,
1218 .name = "Focus Control",
1224 .id = V4L2_CID_FOCUS_ABSOLUTE,
1225 .type = V4L2_CTRL_TYPE_INTEGER,
1226 .name = "Focus Control",
1230 .default_value = 125,
1234 #if CONFIG_SENSOR_Flash
1236 .id = V4L2_CID_FLASH,
1237 .type = V4L2_CTRL_TYPE_MENU,
1238 .name = "Flash Control",
1247 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1248 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1249 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1250 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1251 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1252 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1253 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1254 static int sensor_resume(struct soc_camera_device *icd);
1255 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1256 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1257 #if CONFIG_SENSOR_Effect
1258 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1260 #if CONFIG_SENSOR_WhiteBalance
1261 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1263 static int sensor_deactivate(struct i2c_client *client);
1265 static struct soc_camera_ops sensor_ops =
1267 .suspend = sensor_suspend,
1268 .resume = sensor_resume,
1269 .set_bus_param = sensor_set_bus_param,
1270 .query_bus_param = sensor_query_bus_param,
1271 .controls = sensor_controls,
1272 .menus = sensor_menus,
1273 .num_controls = ARRAY_SIZE(sensor_controls),
1274 .num_menus = ARRAY_SIZE(sensor_menus),
1277 /* only one fixed colorspace per pixelcode */
1278 struct sensor_datafmt {
1279 enum v4l2_mbus_pixelcode code;
1280 enum v4l2_colorspace colorspace;
1283 /* Find a data format by a pixel code in an array */
1284 static const struct sensor_datafmt *sensor_find_datafmt(
1285 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1289 for (i = 0; i < n; i++)
1290 if (fmt[i].code == code)
1296 static const struct sensor_datafmt sensor_colour_fmts[] = {
1297 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1298 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1301 typedef struct sensor_info_priv_s
1315 unsigned char mirror; /* HFLIP */
1316 unsigned char flip; /* VFLIP */
1317 unsigned int winseqe_cur_addr;
1318 struct sensor_datafmt fmt;
1320 } sensor_info_priv_t;
1324 struct v4l2_subdev subdev;
1325 struct i2c_client *client;
1326 sensor_info_priv_t info_priv;
1327 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1328 #if CONFIG_SENSOR_I2C_NOSCHED
1329 atomic_t tasklock_cnt;
1331 struct rk29camera_platform_data *sensor_io_request;
1332 struct rk29camera_gpio_res *sensor_gpio_res;
1335 static struct sensor* to_sensor(const struct i2c_client *client)
1337 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1340 static int sensor_task_lock(struct i2c_client *client, int lock)
1342 #if CONFIG_SENSOR_I2C_NOSCHED
1344 struct sensor *sensor = to_sensor(client);
1347 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1348 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1349 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1353 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1354 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1355 goto sensor_task_lock_err;
1360 atomic_add(1, &sensor->tasklock_cnt);
1362 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1363 atomic_sub(1, &sensor->tasklock_cnt);
1365 if (atomic_read(&sensor->tasklock_cnt) == 0)
1370 sensor_task_lock_err:
1377 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1381 struct i2c_msg msg[1];
1383 buf[0] = reg & 0xFF;
1386 msg->addr = client->addr;
1387 msg->flags = client->flags;
1389 msg->len = sizeof(buf);
1390 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1391 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1396 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1397 err = i2c_transfer(client->adapter, msg, 1);
1402 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1410 /* sensor register read */
1411 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1415 struct i2c_msg msg[2];
1417 buf[0] = reg ;//>> 8;
1420 msg[0].addr = client->addr;
1421 msg[0].flags = client->flags;
1423 msg[0].len = sizeof(buf);
1424 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1425 msg[0].read_type = 2;//0x55; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1427 msg[1].addr = client->addr;
1428 msg[1].flags = client->flags|I2C_M_RD;
1431 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1432 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1436 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1437 err = i2c_transfer(client->adapter, msg, 2);
1443 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1451 /* write a array of registers */
1452 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1456 #if CONFIG_SENSOR_I2C_RDWRCHK
1461 if (sensor_task_lock(client, 1) < 0)
1462 goto sensor_write_array_end;
1463 while (regarray[i].reg != 0)
1465 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1469 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1473 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1475 goto sensor_write_array_end;
1478 #if CONFIG_SENSOR_I2C_RDWRCHK
1479 sensor_read(client, regarray[i].reg, &valchk);
1480 if (valchk != regarray[i].val)
1481 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1487 sensor_write_array_end:
1488 sensor_task_lock(client,0);
1491 #if CONFIG_SENSOR_I2C_RDWRCHK
1492 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1500 while (regarray[i].reg != 0)
1502 sensor_read(client, regarray[i].reg, &valchk);
1503 if (valchk != regarray[i].val)
1504 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1511 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1513 struct soc_camera_link *icl = to_soc_camera_link(icd);
1516 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1520 case Sensor_PowerDown:
1522 if (icl->powerdown) {
1523 ret = icl->powerdown(icd->pdev, on);
1524 if (ret == RK29_CAM_IO_SUCCESS) {
1528 icl->reset(icd->pdev);
1530 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1532 goto sensor_power_end;
1539 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1540 struct sensor *sensor = to_sensor(client);
1542 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1543 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1549 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1556 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1558 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1559 struct soc_camera_device *icd = client->dev.platform_data;
1560 struct sensor *sensor = to_sensor(client);
1561 const struct v4l2_queryctrl *qctrl;
1562 const struct sensor_datafmt *fmt;
1566 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1568 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1570 goto sensor_INIT_ERR;
1574 if (sensor_task_lock(client,1)<0)
1575 goto sensor_INIT_ERR;
1576 ret = sensor_write(client, 0xff, 1);
1577 ret |= sensor_write(client, 0x12, 0x80);
1580 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1582 goto sensor_INIT_ERR;
1585 mdelay(5); //delay 5 microseconds
1586 /* check if it is an sensor sensor */
1587 ret = sensor_write(client, 0xff, 1);
1588 ret |= sensor_read(client, 0x0a, &value);
1590 SENSOR_TR("read chip id high byte failed\n");
1592 goto sensor_INIT_ERR;
1596 ret = sensor_read(client, 0x0b, &value);
1598 SENSOR_TR("read chip id low byte failed\n");
1600 goto sensor_INIT_ERR;
1603 pid |= (value & 0xff);
1605 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1606 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
1607 sensor->model = SENSOR_V4L2_IDENT;
1609 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1611 goto sensor_INIT_ERR;
1614 ret = sensor_write_array(client, sensor_init_data);
1617 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1618 goto sensor_INIT_ERR;
1620 sensor_task_lock(client,0);
1621 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1622 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1624 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1626 goto sensor_INIT_ERR;
1628 sensor->info_priv.fmt = *fmt;
1630 /* sensor sensor information for initialization */
1631 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1633 sensor->info_priv.whiteBalance = qctrl->default_value;
1634 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1636 sensor->info_priv.brightness = qctrl->default_value;
1637 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1639 sensor->info_priv.effect = qctrl->default_value;
1640 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1642 sensor->info_priv.exposure = qctrl->default_value;
1644 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1646 sensor->info_priv.saturation = qctrl->default_value;
1647 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1649 sensor->info_priv.contrast = qctrl->default_value;
1650 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1652 sensor->info_priv.mirror = qctrl->default_value;
1653 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1655 sensor->info_priv.flip = qctrl->default_value;
1656 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1658 sensor->info_priv.scene = qctrl->default_value;
1659 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1661 sensor->info_priv.digitalzoom = qctrl->default_value;
1663 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1664 #if CONFIG_SENSOR_Focus
1666 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1668 sensor->info_priv.focus = qctrl->default_value;
1671 #if CONFIG_SENSOR_Flash
1672 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1674 sensor->info_priv.flash = qctrl->default_value;
1677 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);
1681 sensor_task_lock(client,0);
1682 sensor_deactivate(client);
1686 static int sensor_deactivate(struct i2c_client *client)
1688 struct soc_camera_device *icd = client->dev.platform_data;
1690 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1692 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1694 sensor_task_lock(client, 1);
1695 sensor_write(client, 0x3000, reg_val&0xfc);
1696 sensor_write(client, 0x3001, 0x00);
1697 sensor_task_lock(client, 0);
1699 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1700 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1701 icd->user_width = SENSOR_INIT_WIDTH;
1702 icd->user_height = SENSOR_INIT_HEIGHT;
1707 static struct reginfo sensor_power_down_sequence[]=
1711 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1714 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1716 if (pm_msg.event == PM_EVENT_SUSPEND) {
1717 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1718 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1720 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1723 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1725 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1730 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1736 static int sensor_resume(struct soc_camera_device *icd)
1740 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1742 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1746 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1752 static int sensor_set_bus_param(struct soc_camera_device *icd,
1753 unsigned long flags)
1759 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1761 struct soc_camera_link *icl = to_soc_camera_link(icd);
1762 unsigned long flags = SENSOR_BUS_PARAM;
1764 return soc_camera_apply_sensor_flags(icl, flags);
1767 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1769 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1770 struct soc_camera_device *icd = client->dev.platform_data;
1771 struct sensor *sensor = to_sensor(client);
1773 mf->width = icd->user_width;
1774 mf->height = icd->user_height;
1775 mf->code = sensor->info_priv.fmt.code;
1776 mf->colorspace = sensor->info_priv.fmt.colorspace;
1777 mf->field = V4L2_FIELD_NONE;
1781 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1785 if ((mf->width == 1024) && (mf->height == 768)) {
1787 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1789 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1791 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1793 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1798 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1802 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1806 if ((mf->width == 1280) && (mf->height == 720)) {
1808 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1813 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1816 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1818 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1819 struct sensor *sensor = to_sensor(client);
1820 const struct sensor_datafmt *fmt;
1821 const struct v4l2_queryctrl *qctrl;
1822 struct soc_camera_device *icd = client->dev.platform_data;
1823 struct reginfo *winseqe_set_addr=NULL;
1824 int ret=0, set_w,set_h;
1826 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1827 ARRAY_SIZE(sensor_colour_fmts));
1830 goto sensor_s_fmt_end;
1833 if (sensor->info_priv.fmt.code != mf->code) {
1836 case V4L2_MBUS_FMT_YUYV8_2X8:
1838 winseqe_set_addr = sensor_ClrFmt_YUYV;
1841 case V4L2_MBUS_FMT_UYVY8_2X8:
1843 winseqe_set_addr = sensor_ClrFmt_UYVY;
1849 if (winseqe_set_addr != NULL) {
1850 sensor_write_array(client, winseqe_set_addr);
1851 sensor->info_priv.fmt.code = mf->code;
1852 sensor->info_priv.fmt.colorspace= mf->colorspace;
1853 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1855 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1862 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1864 winseqe_set_addr = sensor_qcif;
1868 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1870 winseqe_set_addr = sensor_qvga;
1874 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1876 winseqe_set_addr = sensor_cif;
1880 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1882 winseqe_set_addr = sensor_vga;
1886 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1888 winseqe_set_addr = sensor_svga;
1892 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1894 winseqe_set_addr = sensor_xga;
1898 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1900 winseqe_set_addr = sensor_sxga;
1904 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1906 winseqe_set_addr = sensor_uxga;
1912 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1913 set_w = SENSOR_INIT_WIDTH;
1914 set_h = SENSOR_INIT_HEIGHT;
1915 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1918 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1919 #if CONFIG_SENSOR_Flash
1920 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1921 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1922 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1923 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1925 } else { /* ddl@rock-chips.com : Video */
1926 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1927 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1928 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1932 ret |= sensor_write_array(client, winseqe_set_addr);
1934 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1935 #if CONFIG_SENSOR_Flash
1936 if (sensor_fmt_capturechk(sd,mf) == true) {
1937 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1938 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1939 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1943 goto sensor_s_fmt_end;
1946 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1948 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1949 #if CONFIG_SENSOR_Effect
1950 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1951 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1953 #if CONFIG_SENSOR_WhiteBalance
1954 if (sensor->info_priv.whiteBalance != 0) {
1955 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1956 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1959 sensor->info_priv.snap2preview = true;
1960 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1961 #if CONFIG_SENSOR_Effect
1962 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1963 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1965 #if CONFIG_SENSOR_WhiteBalance
1966 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1967 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1969 sensor->info_priv.video2preview = true;
1970 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1971 #if CONFIG_SENSOR_Effect
1972 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1973 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1975 #if CONFIG_SENSOR_WhiteBalance
1976 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1977 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1979 sensor->info_priv.video2preview = false;
1980 sensor->info_priv.snap2preview = false;
1982 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1986 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1996 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1998 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1999 struct sensor *sensor = to_sensor(client);
2000 const struct sensor_datafmt *fmt;
2001 int ret = 0,set_w,set_h;
\r
2003 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2004 ARRAY_SIZE(sensor_colour_fmts));
2006 fmt = &sensor->info_priv.fmt;
2007 mf->code = fmt->code;
2010 if (mf->height > SENSOR_MAX_HEIGHT)
2011 mf->height = SENSOR_MAX_HEIGHT;
2012 else if (mf->height < SENSOR_MIN_HEIGHT)
2013 mf->height = SENSOR_MIN_HEIGHT;
2015 if (mf->width > SENSOR_MAX_WIDTH)
2016 mf->width = SENSOR_MAX_WIDTH;
2017 else if (mf->width < SENSOR_MIN_WIDTH)
2018 mf->width = SENSOR_MIN_WIDTH;
2023 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2028 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2033 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2038 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2043 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2048 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
2053 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2058 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2065 set_w = SENSOR_INIT_WIDTH;
\r
2066 set_h = SENSOR_INIT_HEIGHT;
2070 mf->height = set_h;
\r
2072 mf->colorspace = fmt->colorspace;
2076 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2078 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2080 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2083 if (id->match.addr != client->addr)
2086 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2091 #if CONFIG_SENSOR_Brightness
2092 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2094 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2096 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2098 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2100 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2102 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2105 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2109 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2113 #if CONFIG_SENSOR_Effect
2114 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2116 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2118 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2120 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2122 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2124 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2127 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2131 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2135 #if CONFIG_SENSOR_Exposure
2136 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2138 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2140 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2142 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2144 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2146 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2149 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2153 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2157 #if CONFIG_SENSOR_Saturation
2158 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2160 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2162 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2164 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2166 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2168 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2171 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2175 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2179 #if CONFIG_SENSOR_Contrast
2180 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2182 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2184 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2186 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2188 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2190 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2193 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2197 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2201 #if CONFIG_SENSOR_Mirror
2202 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2204 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2206 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2208 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2210 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2212 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2215 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2219 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2223 #if CONFIG_SENSOR_Flip
2224 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2226 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2228 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2230 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2232 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2234 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2237 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2241 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2245 #if CONFIG_SENSOR_Scene
2246 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2248 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2250 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2252 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2254 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2256 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2259 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2263 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2267 #if CONFIG_SENSOR_WhiteBalance
2268 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2270 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2272 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2274 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2276 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2278 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2281 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2285 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2289 #if CONFIG_SENSOR_DigitalZoom
2290 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2292 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2293 struct sensor *sensor = to_sensor(client);
2294 const struct v4l2_queryctrl *qctrl_info;
2295 int digitalzoom_cur, digitalzoom_total;
2297 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2301 digitalzoom_cur = sensor->info_priv.digitalzoom;
2302 digitalzoom_total = qctrl_info->maximum;
2304 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2306 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2310 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2312 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2316 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2318 *value = digitalzoom_total - digitalzoom_cur;
2321 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2323 *value = 0 - digitalzoom_cur;
2326 digitalzoom_cur += *value;
2328 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2330 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2332 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2335 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2342 #if CONFIG_SENSOR_Flash
2343 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2345 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2346 if (value == 3) { /* ddl@rock-chips.com: torch */
2347 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2349 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2351 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2355 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2360 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2362 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2363 struct sensor *sensor = to_sensor(client);
2364 const struct v4l2_queryctrl *qctrl;
2366 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2370 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2376 case V4L2_CID_BRIGHTNESS:
2378 ctrl->value = sensor->info_priv.brightness;
2381 case V4L2_CID_SATURATION:
2383 ctrl->value = sensor->info_priv.saturation;
2386 case V4L2_CID_CONTRAST:
2388 ctrl->value = sensor->info_priv.contrast;
2391 case V4L2_CID_DO_WHITE_BALANCE:
2393 ctrl->value = sensor->info_priv.whiteBalance;
2396 case V4L2_CID_EXPOSURE:
2398 ctrl->value = sensor->info_priv.exposure;
2401 case V4L2_CID_HFLIP:
2403 ctrl->value = sensor->info_priv.mirror;
2406 case V4L2_CID_VFLIP:
2408 ctrl->value = sensor->info_priv.flip;
2419 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2421 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2422 struct sensor *sensor = to_sensor(client);
2423 struct soc_camera_device *icd = client->dev.platform_data;
2424 const struct v4l2_queryctrl *qctrl;
2427 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2431 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2437 #if CONFIG_SENSOR_Brightness
2438 case V4L2_CID_BRIGHTNESS:
2440 if (ctrl->value != sensor->info_priv.brightness)
2442 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2446 sensor->info_priv.brightness = ctrl->value;
2451 #if CONFIG_SENSOR_Exposure
2452 case V4L2_CID_EXPOSURE:
2454 if (ctrl->value != sensor->info_priv.exposure)
2456 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2460 sensor->info_priv.exposure = ctrl->value;
2465 #if CONFIG_SENSOR_Saturation
2466 case V4L2_CID_SATURATION:
2468 if (ctrl->value != sensor->info_priv.saturation)
2470 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2474 sensor->info_priv.saturation = ctrl->value;
2479 #if CONFIG_SENSOR_Contrast
2480 case V4L2_CID_CONTRAST:
2482 if (ctrl->value != sensor->info_priv.contrast)
2484 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2488 sensor->info_priv.contrast = ctrl->value;
2493 #if CONFIG_SENSOR_WhiteBalance
2494 case V4L2_CID_DO_WHITE_BALANCE:
2496 if (ctrl->value != sensor->info_priv.whiteBalance)
2498 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2502 sensor->info_priv.whiteBalance = ctrl->value;
2507 #if CONFIG_SENSOR_Mirror
2508 case V4L2_CID_HFLIP:
2510 if (ctrl->value != sensor->info_priv.mirror)
2512 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2514 sensor->info_priv.mirror = ctrl->value;
2519 #if CONFIG_SENSOR_Flip
2520 case V4L2_CID_VFLIP:
2522 if (ctrl->value != sensor->info_priv.flip)
2524 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2526 sensor->info_priv.flip = ctrl->value;
2537 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2539 const struct v4l2_queryctrl *qctrl;
2540 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2541 struct sensor *sensor = to_sensor(client);
2543 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2547 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2551 switch (ext_ctrl->id)
2553 case V4L2_CID_SCENE:
2555 ext_ctrl->value = sensor->info_priv.scene;
2558 case V4L2_CID_EFFECT:
2560 ext_ctrl->value = sensor->info_priv.effect;
2563 case V4L2_CID_ZOOM_ABSOLUTE:
2565 ext_ctrl->value = sensor->info_priv.digitalzoom;
2568 case V4L2_CID_ZOOM_RELATIVE:
2572 case V4L2_CID_FOCUS_ABSOLUTE:
2574 ext_ctrl->value = sensor->info_priv.focus;
2577 case V4L2_CID_FOCUS_RELATIVE:
2581 case V4L2_CID_FLASH:
2583 ext_ctrl->value = sensor->info_priv.flash;
2591 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2593 const struct v4l2_queryctrl *qctrl;
2594 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2595 struct sensor *sensor = to_sensor(client);
2598 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2602 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2607 switch (ext_ctrl->id)
2609 #if CONFIG_SENSOR_Scene
2610 case V4L2_CID_SCENE:
2612 if (ext_ctrl->value != sensor->info_priv.scene)
2614 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2616 sensor->info_priv.scene = ext_ctrl->value;
2621 #if CONFIG_SENSOR_Effect
2622 case V4L2_CID_EFFECT:
2624 if (ext_ctrl->value != sensor->info_priv.effect)
2626 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2628 sensor->info_priv.effect= ext_ctrl->value;
2633 #if CONFIG_SENSOR_DigitalZoom
2634 case V4L2_CID_ZOOM_ABSOLUTE:
2636 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2639 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2641 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2643 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2645 sensor->info_priv.digitalzoom += val_offset;
2647 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2652 case V4L2_CID_ZOOM_RELATIVE:
2654 if (ext_ctrl->value)
2656 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2658 sensor->info_priv.digitalzoom += ext_ctrl->value;
2660 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2665 #if CONFIG_SENSOR_Focus
2666 case V4L2_CID_FOCUS_ABSOLUTE:
2668 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2671 if (ext_ctrl->value != sensor->info_priv.focus)
2673 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2675 sensor->info_priv.focus += val_offset;
2680 case V4L2_CID_FOCUS_RELATIVE:
2682 if (ext_ctrl->value)
2684 sensor->info_priv.focus += ext_ctrl->value;
2686 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2691 #if CONFIG_SENSOR_Flash
2692 case V4L2_CID_FLASH:
2694 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2696 sensor->info_priv.flash = ext_ctrl->value;
2698 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2709 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2711 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2712 struct soc_camera_device *icd = client->dev.platform_data;
2713 int i, error_cnt=0, error_idx=-1;
2716 for (i=0; i<ext_ctrl->count; i++) {
2717 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2724 error_idx = ext_ctrl->count;
2726 if (error_idx != -1) {
2727 ext_ctrl->error_idx = error_idx;
2734 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2736 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2737 struct soc_camera_device *icd = client->dev.platform_data;
2738 int i, error_cnt=0, error_idx=-1;
2741 for (i=0; i<ext_ctrl->count; i++) {
2742 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2749 error_idx = ext_ctrl->count;
2751 if (error_idx != -1) {
2752 ext_ctrl->error_idx = error_idx;
2759 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2760 * this wasn't our capture interface, so, we wait for the right one */
2761 static int sensor_video_probe(struct soc_camera_device *icd,
2762 struct i2c_client *client)
2766 struct sensor *sensor = to_sensor(client);
2768 /* We must have a parent by now. And it cannot be a wrong one.
2769 * So this entire test is completely redundant. */
2770 if (!icd->dev.parent ||
2771 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2774 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2776 goto sensor_video_probe_err;
2780 ret = sensor_write(client, 0xff, 0x1);
2782 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2784 goto sensor_video_probe_err;
2786 mdelay(5); //delay 5 microseconds
2788 /* check if it is an sensor sensor */
2789 ret = sensor_read(client, 0x0a, &value);
2791 SENSOR_TR("read chip id high byte failed\n");
2793 goto sensor_video_probe_err;
2797 ret = sensor_read(client, 0x0b, &value);
2799 SENSOR_TR("read chip id low byte failed\n");
2801 goto sensor_video_probe_err;
2804 pid |= (value & 0xff);
2805 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2807 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
2808 sensor->model = SENSOR_V4L2_IDENT;
2810 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2812 goto sensor_video_probe_err;
2817 sensor_video_probe_err:
2822 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2824 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2825 struct soc_camera_device *icd = client->dev.platform_data;
2826 struct sensor *sensor = to_sensor(client);
2829 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2832 case RK29_CAM_SUBDEV_DEACTIVATE:
2834 sensor_deactivate(client);
2838 case RK29_CAM_SUBDEV_IOREQUEST:
2840 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
\r
2841 if (sensor->sensor_io_request != NULL) {
2842 sensor->sensor_gpio_res = NULL;
2843 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2844 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2845 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2846 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2849 if (sensor->sensor_gpio_res == NULL) {
2850 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2852 goto sensor_ioctl_end;
2855 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2857 goto sensor_ioctl_end;
2859 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2861 #if CONFIG_SENSOR_Flash
2862 if (sensor->sensor_gpio_res) {
2863 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2864 for (i = 0; i < icd->ops->num_controls; i++) {
2865 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2866 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2869 sensor->info_priv.flash = 0xff;
2870 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2878 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2887 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2888 enum v4l2_mbus_pixelcode *code)
2890 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2893 *code = sensor_colour_fmts[index].code;
2896 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2897 .init = sensor_init,
2898 .g_ctrl = sensor_g_control,
2899 .s_ctrl = sensor_s_control,
2900 .g_ext_ctrls = sensor_g_ext_controls,
2901 .s_ext_ctrls = sensor_s_ext_controls,
2902 .g_chip_ident = sensor_g_chip_ident,
2903 .ioctl = sensor_ioctl,
2906 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2907 .s_mbus_fmt = sensor_s_fmt,
2908 .g_mbus_fmt = sensor_g_fmt,
2909 .try_mbus_fmt = sensor_try_fmt,
2910 .enum_mbus_fmt = sensor_enum_fmt,
2913 static struct v4l2_subdev_ops sensor_subdev_ops = {
2914 .core = &sensor_subdev_core_ops,
2915 .video = &sensor_subdev_video_ops,
2918 static int sensor_probe(struct i2c_client *client,
2919 const struct i2c_device_id *did)
2921 struct sensor *sensor;
2922 struct soc_camera_device *icd = client->dev.platform_data;
2923 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2924 struct soc_camera_link *icl;
2927 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2929 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2933 icl = to_soc_camera_link(icd);
2935 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2939 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2940 dev_warn(&adapter->dev,
2941 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2945 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2949 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2951 /* Second stage probe - when a capture adapter is there */
2952 icd->ops = &sensor_ops;
2953 sensor->info_priv.fmt = sensor_colour_fmts[0];
2954 #if CONFIG_SENSOR_I2C_NOSCHED
2955 atomic_set(&sensor->tasklock_cnt,0);
2958 ret = sensor_video_probe(icd, client);
2961 i2c_set_clientdata(client, NULL);
2965 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2969 static int sensor_remove(struct i2c_client *client)
2971 struct sensor *sensor = to_sensor(client);
2972 struct soc_camera_device *icd = client->dev.platform_data;
2975 i2c_set_clientdata(client, NULL);
2976 client->driver = NULL;
2982 static const struct i2c_device_id sensor_id[] = {
2983 {SENSOR_NAME_STRING(), 0 },
2986 MODULE_DEVICE_TABLE(i2c, sensor_id);
2988 static struct i2c_driver sensor_i2c_driver = {
2990 .name = SENSOR_NAME_STRING(),
2992 .probe = sensor_probe,
2993 .remove = sensor_remove,
2994 .id_table = sensor_id,
2997 static int __init sensor_mod_init(void)
2999 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3000 return i2c_add_driver(&sensor_i2c_driver);
3003 static void __exit sensor_mod_exit(void)
3005 i2c_del_driver(&sensor_i2c_driver);
3008 device_initcall_sync(sensor_mod_init);
3009 module_exit(sensor_mod_exit);
3011 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3012 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3013 MODULE_LICENSE("GPL");
\r