1 #include <linux/videodev2.h>
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 <mach/rk_camera.h>
13 #include <linux/vmalloc.h>
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 RK_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 sensor_init_width /* Sensor pixel size for sensor_init_data array */
45 #define SENSOR_INIT_HEIGHT sensor_init_height
46 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
47 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
48 #define SENSOR_BUS_PARAM sensor_init_busparam
50 #define CONFIG_SENSOR_WhiteBalance 0
51 #define CONFIG_SENSOR_Brightness 1
52 #define CONFIG_SENSOR_Contrast 0
53 #define CONFIG_SENSOR_Saturation 1
54 #define CONFIG_SENSOR_Effect 1
55 #define CONFIG_SENSOR_Scene 0
56 #define CONFIG_SENSOR_DigitalZoom 0
57 #define CONFIG_SENSOR_Focus 0
58 #define CONFIG_SENSOR_Exposure 0
59 #define CONFIG_SENSOR_Flash 0
60 #define CONFIG_SENSOR_Mirror 0
61 #define CONFIG_SENSOR_Flip 0
63 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
64 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
65 #define CONFIG_SENSOR_I2C_NOSCHED 0
66 #define CONFIG_SENSOR_I2C_RDWRCHK 0
68 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
69 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
70 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
71 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
72 #define COLOR_TEMPERATURE_OFFICE_DN 3500
73 #define COLOR_TEMPERATURE_OFFICE_UP 5000
74 #define COLOR_TEMPERATURE_HOME_DN 2500
75 #define COLOR_TEMPERATURE_HOME_UP 3500
77 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
78 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
86 static s32 sensor_init_width = 0;
87 static s32 sensor_init_height = 0;
88 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
89 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
90 static struct reginfo* sensor_init_data_p = NULL;
91 static struct reginfo* sensor_init_winseq_p = NULL;
92 static struct reginfo* sensor_init_winseq_board = NULL;
93 /* init 800*600 SVGA */
94 static struct reginfo sensor_init_data[] =
111 {0x04,0xF8},//b7,b6 directs
181 {0x7d,0x00},//0x00//0x07
183 {0x7d,0x48},//0x48//0x40
184 {0x7d,0x48},//0x48//0x40
325 {0x0, 0x0} //end flag
330 static struct reginfo sensor_uxga[] =
349 {0x0, 0x0} //end flag
353 static struct reginfo sensor_sxga[] =
372 {0x0, 0x0} //end flag
376 static struct reginfo sensor_xga[] =
395 {0x0, 0x0} //end flag
402 static struct reginfo sensor_svga[] =
404 {0x0, 0x0} //end flag
408 static struct reginfo sensor_vga[] =
410 {0x0, 0x0} //end flag
414 static struct reginfo sensor_cif[] =
416 {0x0, 0x0} //end flag
420 static struct reginfo sensor_qvga[] =
422 {0x0, 0x0} //end flag
426 static struct reginfo sensor_qcif[] =
428 {0x0, 0x0} //end flag
432 static struct reginfo ov2655_qqvga[] =
476 static struct reginfo ov2655_Sharpness_auto[] =
481 static struct reginfo ov2655_Sharpness1[] =
487 static struct reginfo ov2655_Sharpness2[][3] =
494 static struct reginfo ov2655_Sharpness3[] =
500 static struct reginfo ov2655_Sharpness4[]=
507 static struct reginfo ov2655_Sharpness5[] =
515 static struct reginfo sensor_ClrFmt_YUYV[]=
521 static struct reginfo sensor_ClrFmt_UYVY[]=
527 #if CONFIG_SENSOR_WhiteBalance
528 static struct reginfo sensor_WhiteB_Auto[]=
530 {0x3406, 0x00}, //AWB auto, bit[1]:0,auto
533 /* Cloudy Colour Temperature : 6500K - 8000K */
534 static struct reginfo sensor_WhiteB_Cloudy[]=
545 /* ClearDay Colour Temperature : 5000K - 6500K */
546 static struct reginfo sensor_WhiteB_ClearDay[]=
558 /* Office Colour Temperature : 3500K - 5000K */
559 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
572 /* Home Colour Temperature : 2500K - 3500K */
573 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
585 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
586 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
590 #if CONFIG_SENSOR_Brightness
591 static struct reginfo sensor_Brightness0[]=
598 {0x0, 0x0} //end flag
601 static struct reginfo sensor_Brightness1[]=
609 {0x0, 0x0} //end flag
612 static struct reginfo sensor_Brightness2[]=
620 {0x0, 0x0} //end flag
623 static struct reginfo sensor_Brightness3[]=
631 {0x0, 0x0} //end flag
634 static struct reginfo sensor_Brightness4[]=
642 {0x0, 0x0} //end flag
645 static struct reginfo sensor_Brightness5[]=
652 {0x0, 0x0} //end flag
654 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
655 sensor_Brightness4, sensor_Brightness5,NULL,
660 #if CONFIG_SENSOR_Effect
661 static struct reginfo sensor_Effect_Normal[] =
669 {0x0, 0x0} //end flag
672 static struct reginfo sensor_Effect_WandB[] =
680 {0x0, 0x0} //end flag
683 static struct reginfo sensor_Effect_Sepia[] =
691 {0x0, 0x0} //end flag
694 static struct reginfo sensor_Effect_Negative[] =
702 {0x0, 0x0} //end flag
704 static struct reginfo sensor_Effect_Bluish[] =
712 {0x0, 0x0} //end flag
715 static struct reginfo sensor_Effect_Green[] =
723 {0x0, 0x0} //end flag
726 static struct reginfo sensor_Effect_Exp_Windows_Half[] =
733 {0x0, 0x0} //end flag
735 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
736 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
739 #if CONFIG_SENSOR_Exposure
740 static struct reginfo sensor_Exposure0[]=
745 static struct reginfo sensor_Exposure1[]=
750 static struct reginfo sensor_Exposure2[]=
755 static struct reginfo sensor_Exposure3[]=
760 static struct reginfo sensor_Exposure4[]=
765 static struct reginfo sensor_Exposure5[]=
770 static struct reginfo sensor_Exposure6[]=
775 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
776 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
779 #if CONFIG_SENSOR_Saturation
780 static struct reginfo sensor_Saturation0[]=
800 {0x0, 0x0} //end flag
803 static struct reginfo sensor_Saturation1[]=
823 {0x0, 0x0} //end flag
826 static struct reginfo sensor_Saturation2[]=
846 {0x0, 0x0} //end flag
848 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
852 #if CONFIG_SENSOR_Contrast
853 static struct reginfo sensor_Contrast0[]=
863 {0x0, 0x0} //end flag
867 static struct reginfo sensor_Contrast1[]=
877 {0x0, 0x0} //end flag
880 static struct reginfo sensor_Contrast2[]=
890 {0x0, 0x0} //end flag
893 static struct reginfo sensor_Contrast3[]=
903 {0x0, 0x0} //end flag
906 static struct reginfo sensor_Contrast4[]=
916 {0x0, 0x0} //end flag
920 static struct reginfo sensor_Contrast5[]=
930 {0x0, 0x0} //end flag
933 static struct reginfo sensor_Contrast6[]=
943 {0x0, 0x0} //end flag
947 static struct reginfo sensor_Contrast7[]=
957 {0x0, 0x0} //end flag
960 static struct reginfo sensor_Contrast8[]=
970 {0x0, 0x0} //end flag
973 static struct reginfo sensor_Contrast9[]=
983 {0x0, 0x0} //end flag
988 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
989 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
993 #if CONFIG_SENSOR_Mirror
994 static struct reginfo sensor_MirrorOn[]=
999 static struct reginfo sensor_MirrorOff[]=
1003 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1005 #if CONFIG_SENSOR_Flip
1006 static struct reginfo sensor_FlipOn[]=
1011 static struct reginfo sensor_FlipOff[]=
1015 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1018 #if CONFIG_SENSOR_Scene
1019 static struct reginfo sensor_SceneAuto[] =
1025 static struct reginfo sensor_SceneNight[] =
1038 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1041 #if CONFIG_SENSOR_DigitalZoom
1042 static struct reginfo sensor_Zoom0[] =
1047 static struct reginfo sensor_Zoom1[] =
1052 static struct reginfo sensor_Zoom2[] =
1058 static struct reginfo sensor_Zoom3[] =
1062 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1064 static const struct v4l2_querymenu sensor_menus[] =
1066 #if CONFIG_SENSOR_WhiteBalance
1067 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1068 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1069 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1072 #if CONFIG_SENSOR_Effect
1073 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1074 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1075 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1078 #if CONFIG_SENSOR_Scene
1079 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1082 #if CONFIG_SENSOR_Flash
1083 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1084 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1088 static const struct v4l2_queryctrl sensor_controls[] =
1090 #if CONFIG_SENSOR_WhiteBalance
1092 .id = V4L2_CID_DO_WHITE_BALANCE,
1093 .type = V4L2_CTRL_TYPE_MENU,
1094 .name = "White Balance Control",
1102 #if CONFIG_SENSOR_Brightness
1104 .id = V4L2_CID_BRIGHTNESS,
1105 .type = V4L2_CTRL_TYPE_INTEGER,
1106 .name = "Brightness Control",
1114 #if CONFIG_SENSOR_Effect
1116 .id = V4L2_CID_EFFECT,
1117 .type = V4L2_CTRL_TYPE_MENU,
1118 .name = "Effect Control",
1126 #if CONFIG_SENSOR_Exposure
1128 .id = V4L2_CID_EXPOSURE,
1129 .type = V4L2_CTRL_TYPE_INTEGER,
1130 .name = "Exposure Control",
1138 #if CONFIG_SENSOR_Saturation
1140 .id = V4L2_CID_SATURATION,
1141 .type = V4L2_CTRL_TYPE_INTEGER,
1142 .name = "Saturation Control",
1150 #if CONFIG_SENSOR_Contrast
1152 .id = V4L2_CID_CONTRAST,
1153 .type = V4L2_CTRL_TYPE_INTEGER,
1154 .name = "Contrast Control",
1162 #if CONFIG_SENSOR_Mirror
1164 .id = V4L2_CID_HFLIP,
1165 .type = V4L2_CTRL_TYPE_BOOLEAN,
1166 .name = "Mirror Control",
1174 #if CONFIG_SENSOR_Flip
1176 .id = V4L2_CID_VFLIP,
1177 .type = V4L2_CTRL_TYPE_BOOLEAN,
1178 .name = "Flip Control",
1186 #if CONFIG_SENSOR_Scene
1188 .id = V4L2_CID_SCENE,
1189 .type = V4L2_CTRL_TYPE_MENU,
1190 .name = "Scene Control",
1198 #if CONFIG_SENSOR_DigitalZoom
1200 .id = V4L2_CID_ZOOM_RELATIVE,
1201 .type = V4L2_CTRL_TYPE_INTEGER,
1202 .name = "DigitalZoom Control",
1208 .id = V4L2_CID_ZOOM_ABSOLUTE,
1209 .type = V4L2_CTRL_TYPE_INTEGER,
1210 .name = "DigitalZoom Control",
1218 #if CONFIG_SENSOR_Focus
1220 .id = V4L2_CID_FOCUS_RELATIVE,
1221 .type = V4L2_CTRL_TYPE_INTEGER,
1222 .name = "Focus Control",
1228 .id = V4L2_CID_FOCUS_ABSOLUTE,
1229 .type = V4L2_CTRL_TYPE_INTEGER,
1230 .name = "Focus Control",
1234 .default_value = 125,
1238 #if CONFIG_SENSOR_Flash
1240 .id = V4L2_CID_FLASH,
1241 .type = V4L2_CTRL_TYPE_MENU,
1242 .name = "Flash Control",
1251 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1252 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1253 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1254 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1255 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1256 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1257 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1258 static int sensor_resume(struct soc_camera_device *icd);
1259 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1260 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1261 #if CONFIG_SENSOR_Effect
1262 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1264 #if CONFIG_SENSOR_WhiteBalance
1265 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1267 static int sensor_deactivate(struct i2c_client *client);
1269 static struct soc_camera_ops sensor_ops =
1271 .suspend = sensor_suspend,
1272 .resume = sensor_resume,
1273 .set_bus_param = sensor_set_bus_param,
1274 .query_bus_param = sensor_query_bus_param,
1275 .controls = sensor_controls,
1276 .menus = sensor_menus,
1277 .num_controls = ARRAY_SIZE(sensor_controls),
1278 .num_menus = ARRAY_SIZE(sensor_menus),
1281 /* only one fixed colorspace per pixelcode */
1282 struct sensor_datafmt {
1283 enum v4l2_mbus_pixelcode code;
1284 enum v4l2_colorspace colorspace;
1287 /* Find a data format by a pixel code in an array */
1288 static const struct sensor_datafmt *sensor_find_datafmt(
1289 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1293 for (i = 0; i < n; i++)
1294 if (fmt[i].code == code)
1300 static const struct sensor_datafmt sensor_colour_fmts[] = {
1301 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1302 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1305 typedef struct sensor_info_priv_s
1319 unsigned char mirror; /* HFLIP */
1320 unsigned char flip; /* VFLIP */
1321 unsigned int winseqe_cur_addr;
1322 struct sensor_datafmt fmt;
1324 } sensor_info_priv_t;
1328 struct v4l2_subdev subdev;
1329 struct i2c_client *client;
1330 sensor_info_priv_t info_priv;
1331 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1332 #if CONFIG_SENSOR_I2C_NOSCHED
1333 atomic_t tasklock_cnt;
1335 struct rkcamera_platform_data *sensor_io_request;
1336 struct rkcamera_gpio_res *sensor_gpio_res;
1339 static struct sensor* to_sensor(const struct i2c_client *client)
1341 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1344 static int sensor_task_lock(struct i2c_client *client, int lock)
1346 #if CONFIG_SENSOR_I2C_NOSCHED
1348 struct sensor *sensor = to_sensor(client);
1351 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1352 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1353 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1357 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1358 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1359 goto sensor_task_lock_err;
1364 atomic_add(1, &sensor->tasklock_cnt);
1366 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1367 atomic_sub(1, &sensor->tasklock_cnt);
1369 if (atomic_read(&sensor->tasklock_cnt) == 0)
1374 sensor_task_lock_err:
1381 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1385 struct i2c_msg msg[1];
1387 buf[0] = reg & 0xFF;
1390 msg->addr = client->addr;
1391 msg->flags = client->flags;
1393 msg->len = sizeof(buf);
1394 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1395 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1400 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1401 err = i2c_transfer(client->adapter, msg, 1);
1406 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1414 /* sensor register read */
1415 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1419 struct i2c_msg msg[2];
1421 buf[0] = reg ;//>> 8;
1424 msg[0].addr = client->addr;
1425 msg[0].flags = client->flags;
1427 msg[0].len = sizeof(buf);
1428 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1429 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 */
1431 msg[1].addr = client->addr;
1432 msg[1].flags = client->flags|I2C_M_RD;
1435 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1436 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1440 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1441 err = i2c_transfer(client->adapter, msg, 2);
1447 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1455 /* write a array of registers */
1456 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1460 #if CONFIG_SENSOR_I2C_RDWRCHK
1465 if (sensor_task_lock(client, 1) < 0)
1466 goto sensor_write_array_end;
1467 while (regarray[i].reg != 0)
1469 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1473 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1477 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1479 goto sensor_write_array_end;
1482 #if CONFIG_SENSOR_I2C_RDWRCHK
1483 sensor_read(client, regarray[i].reg, &valchk);
1484 if (valchk != regarray[i].val)
1485 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1491 sensor_write_array_end:
1492 sensor_task_lock(client,0);
1495 #if CONFIG_SENSOR_I2C_RDWRCHK
1496 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1504 while (regarray[i].reg != 0)
1506 sensor_read(client, regarray[i].reg, &valchk);
1507 if (valchk != regarray[i].val)
1508 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1515 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
1517 struct soc_camera_link *icl = to_soc_camera_link(icd);
1520 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1524 case Sensor_PowerDown:
1526 if (icl->powerdown) {
1527 ret = icl->powerdown(icd->pdev, on);
1528 if (ret == RK_CAM_IO_SUCCESS) {
1532 icl->reset(icd->pdev);
1534 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
1536 goto sensor_power_end;
1543 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1544 struct sensor *sensor = to_sensor(client);
1546 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1547 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1553 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1560 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1562 struct i2c_client *client = sd->priv;
1563 struct soc_camera_device *icd = client->dev.platform_data;
1564 struct sensor *sensor = to_sensor(client);
1565 const struct v4l2_queryctrl *qctrl;
1566 const struct sensor_datafmt *fmt;
1568 int ret,pid = 0,i = 0,j=0;
1569 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
1570 sensor_init_data_p = sensor_init_data;
1571 sensor_init_winseq_p = sensor_vga;
1572 sensor_init_width = 640;
1573 sensor_init_height = 480;
1574 if (tmp_plat_data != NULL) {
1575 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
1576 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1577 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1581 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
1582 //user has defined the init data
1584 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1585 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1586 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1587 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1589 sensor_init_data_p = sensor_init_data;
1591 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1592 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1595 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1596 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1597 if(sensor_init_winseq_board)
1599 vfree(sensor_init_winseq_board);
1600 sensor_init_winseq_board = NULL;
1602 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1603 if(!sensor_init_winseq_board)
1604 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1605 for(j = 0;j< tmp_winseq_size;j++){
1606 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1607 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1609 sensor_init_winseq_p = sensor_init_winseq_board;
1611 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1612 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1614 //init width,height,bus,pixelcode
1615 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1616 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1617 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1618 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1619 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1620 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1621 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1622 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1624 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1626 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1628 goto sensor_INIT_ERR;
1632 if (sensor_task_lock(client,1)<0)
1633 goto sensor_INIT_ERR;
1634 ret = sensor_write(client, 0xff, 1);
1635 ret |= sensor_write(client, 0x12, 0x80);
1638 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1640 goto sensor_INIT_ERR;
1643 mdelay(5); //delay 5 microseconds
1644 /* check if it is an sensor sensor */
1645 ret = sensor_write(client, 0xff, 1);
1646 ret |= sensor_read(client, 0x0a, &value);
1648 SENSOR_TR("read chip id high byte failed\n");
1650 goto sensor_INIT_ERR;
1654 ret = sensor_read(client, 0x0b, &value);
1656 SENSOR_TR("read chip id low byte failed\n");
1658 goto sensor_INIT_ERR;
1661 pid |= (value & 0xff);
1663 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1664 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
1665 sensor->model = SENSOR_V4L2_IDENT;
1667 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1669 goto sensor_INIT_ERR;
1672 ret = sensor_write_array(client, sensor_init_data_p);
1675 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1676 goto sensor_INIT_ERR;
1678 sensor_task_lock(client,0);
1679 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1680 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1682 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1684 goto sensor_INIT_ERR;
1686 sensor->info_priv.fmt = *fmt;
1688 /* sensor sensor information for initialization */
1689 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1691 sensor->info_priv.whiteBalance = qctrl->default_value;
1692 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1694 sensor->info_priv.brightness = qctrl->default_value;
1695 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1697 sensor->info_priv.effect = qctrl->default_value;
1698 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1700 sensor->info_priv.exposure = qctrl->default_value;
1702 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1704 sensor->info_priv.saturation = qctrl->default_value;
1705 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1707 sensor->info_priv.contrast = qctrl->default_value;
1708 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1710 sensor->info_priv.mirror = qctrl->default_value;
1711 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1713 sensor->info_priv.flip = qctrl->default_value;
1714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1716 sensor->info_priv.scene = qctrl->default_value;
1717 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1719 sensor->info_priv.digitalzoom = qctrl->default_value;
1721 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1722 #if CONFIG_SENSOR_Focus
1724 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1726 sensor->info_priv.focus = qctrl->default_value;
1729 #if CONFIG_SENSOR_Flash
1730 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1732 sensor->info_priv.flash = qctrl->default_value;
1735 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);
1739 sensor_task_lock(client,0);
1740 sensor_deactivate(client);
1744 static int sensor_deactivate(struct i2c_client *client)
1746 struct soc_camera_device *icd = client->dev.platform_data;
1748 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1750 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1752 sensor_task_lock(client, 1);
1753 sensor_write(client, 0x3000, reg_val&0xfc);
1754 sensor_write(client, 0x3001, 0x00);
1755 sensor_task_lock(client, 0);
1757 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1758 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1759 icd->user_width = SENSOR_INIT_WIDTH;
1760 icd->user_height = SENSOR_INIT_HEIGHT;
1765 static struct reginfo sensor_power_down_sequence[]=
1769 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1772 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1774 if (pm_msg.event == PM_EVENT_SUSPEND) {
1775 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1776 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1778 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1781 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1783 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1788 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1794 static int sensor_resume(struct soc_camera_device *icd)
1798 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1800 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1804 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1810 static int sensor_set_bus_param(struct soc_camera_device *icd,
1811 unsigned long flags)
1817 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1819 struct soc_camera_link *icl = to_soc_camera_link(icd);
1820 unsigned long flags = SENSOR_BUS_PARAM;
1822 return soc_camera_apply_sensor_flags(icl, flags);
1825 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1827 struct i2c_client *client = sd->priv;
1828 struct soc_camera_device *icd = client->dev.platform_data;
1829 struct sensor *sensor = to_sensor(client);
1831 mf->width = icd->user_width;
1832 mf->height = icd->user_height;
1833 mf->code = sensor->info_priv.fmt.code;
1834 mf->colorspace = sensor->info_priv.fmt.colorspace;
1835 mf->field = V4L2_FIELD_NONE;
1839 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1843 if ((mf->width == 1024) && (mf->height == 768)) {
1845 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1847 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1849 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1851 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1856 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1860 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1864 if ((mf->width == 1280) && (mf->height == 720)) {
1866 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1871 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1874 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1876 struct i2c_client *client = sd->priv;
1877 struct sensor *sensor = to_sensor(client);
1878 const struct sensor_datafmt *fmt;
1879 const struct v4l2_queryctrl *qctrl;
1880 struct soc_camera_device *icd = client->dev.platform_data;
1881 struct reginfo *winseqe_set_addr=NULL;
1882 int ret=0, set_w,set_h;
1884 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1885 ARRAY_SIZE(sensor_colour_fmts));
1888 goto sensor_s_fmt_end;
1891 if (sensor->info_priv.fmt.code != mf->code) {
1894 case V4L2_MBUS_FMT_YUYV8_2X8:
1896 winseqe_set_addr = sensor_ClrFmt_YUYV;
1899 case V4L2_MBUS_FMT_UYVY8_2X8:
1901 winseqe_set_addr = sensor_ClrFmt_UYVY;
1907 if (winseqe_set_addr != NULL) {
1908 sensor_write_array(client, winseqe_set_addr);
1909 sensor->info_priv.fmt.code = mf->code;
1910 sensor->info_priv.fmt.colorspace= mf->colorspace;
1911 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1913 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1920 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1922 winseqe_set_addr = sensor_qcif;
1926 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1928 winseqe_set_addr = sensor_qvga;
1932 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1934 winseqe_set_addr = sensor_cif;
1938 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1940 winseqe_set_addr = sensor_vga;
1944 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1946 winseqe_set_addr = sensor_svga;
1950 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1952 winseqe_set_addr = sensor_xga;
1956 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1958 winseqe_set_addr = sensor_sxga;
1962 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1964 winseqe_set_addr = sensor_uxga;
1970 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1971 set_w = SENSOR_INIT_WIDTH;
1972 set_h = SENSOR_INIT_HEIGHT;
1973 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1976 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1977 #if CONFIG_SENSOR_Flash
1978 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1979 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1980 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1981 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1983 } else { /* ddl@rock-chips.com : Video */
1984 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1985 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1986 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1990 ret |= sensor_write_array(client, winseqe_set_addr);
1992 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1993 #if CONFIG_SENSOR_Flash
1994 if (sensor_fmt_capturechk(sd,mf) == true) {
1995 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1996 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1997 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2001 goto sensor_s_fmt_end;
2004 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2006 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2007 #if CONFIG_SENSOR_Effect
2008 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2009 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2011 #if CONFIG_SENSOR_WhiteBalance
2012 if (sensor->info_priv.whiteBalance != 0) {
2013 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2014 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2017 sensor->info_priv.snap2preview = true;
2018 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2019 #if CONFIG_SENSOR_Effect
2020 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2021 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2023 #if CONFIG_SENSOR_WhiteBalance
2024 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2025 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2027 sensor->info_priv.video2preview = true;
2028 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2029 #if CONFIG_SENSOR_Effect
2030 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2031 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2033 #if CONFIG_SENSOR_WhiteBalance
2034 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2035 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2037 sensor->info_priv.video2preview = false;
2038 sensor->info_priv.snap2preview = false;
2040 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2044 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2054 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2056 struct i2c_client *client = sd->priv;
2057 struct sensor *sensor = to_sensor(client);
2058 const struct sensor_datafmt *fmt;
2061 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2062 ARRAY_SIZE(sensor_colour_fmts));
2064 fmt = &sensor->info_priv.fmt;
2065 mf->code = fmt->code;
2068 if (mf->height > SENSOR_MAX_HEIGHT)
2069 mf->height = SENSOR_MAX_HEIGHT;
2070 else if (mf->height < SENSOR_MIN_HEIGHT)
2071 mf->height = SENSOR_MIN_HEIGHT;
2073 if (mf->width > SENSOR_MAX_WIDTH)
2074 mf->width = SENSOR_MAX_WIDTH;
2075 else if (mf->width < SENSOR_MIN_WIDTH)
2076 mf->width = SENSOR_MIN_WIDTH;
2078 mf->colorspace = fmt->colorspace;
2082 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2084 struct i2c_client *client = sd->priv;
2086 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2089 if (id->match.addr != client->addr)
2092 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2097 #if CONFIG_SENSOR_Brightness
2098 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2100 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2102 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2104 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2106 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2108 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2111 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2115 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2119 #if CONFIG_SENSOR_Effect
2120 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2122 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2124 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2126 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2128 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2130 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2133 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2137 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2141 #if CONFIG_SENSOR_Exposure
2142 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2144 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2146 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2148 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2150 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2152 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2155 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2159 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2163 #if CONFIG_SENSOR_Saturation
2164 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2166 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2168 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2170 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2172 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2174 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2177 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2181 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2185 #if CONFIG_SENSOR_Contrast
2186 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2188 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2190 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2192 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2194 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2196 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2199 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2203 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2207 #if CONFIG_SENSOR_Mirror
2208 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2210 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2212 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2214 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2216 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2218 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2221 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2225 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2229 #if CONFIG_SENSOR_Flip
2230 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2232 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2234 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2236 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2238 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2240 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2243 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2247 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2251 #if CONFIG_SENSOR_Scene
2252 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2254 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2256 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2258 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2260 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2262 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2265 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2269 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2273 #if CONFIG_SENSOR_WhiteBalance
2274 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2276 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2278 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2280 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2282 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2284 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2287 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2291 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2295 #if CONFIG_SENSOR_DigitalZoom
2296 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2298 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2299 struct sensor *sensor = to_sensor(client);
2300 const struct v4l2_queryctrl *qctrl_info;
2301 int digitalzoom_cur, digitalzoom_total;
2303 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2307 digitalzoom_cur = sensor->info_priv.digitalzoom;
2308 digitalzoom_total = qctrl_info->maximum;
2310 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2312 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2316 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2318 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2322 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2324 *value = digitalzoom_total - digitalzoom_cur;
2327 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2329 *value = 0 - digitalzoom_cur;
2332 digitalzoom_cur += *value;
2334 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2336 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2338 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2341 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2348 #if CONFIG_SENSOR_Flash
2349 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2351 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2352 if (value == 3) { /* ddl@rock-chips.com: torch */
2353 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2355 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2357 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2361 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2366 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2368 struct i2c_client *client = sd->priv;
2369 struct sensor *sensor = to_sensor(client);
2370 const struct v4l2_queryctrl *qctrl;
2372 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2376 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2382 case V4L2_CID_BRIGHTNESS:
2384 ctrl->value = sensor->info_priv.brightness;
2387 case V4L2_CID_SATURATION:
2389 ctrl->value = sensor->info_priv.saturation;
2392 case V4L2_CID_CONTRAST:
2394 ctrl->value = sensor->info_priv.contrast;
2397 case V4L2_CID_DO_WHITE_BALANCE:
2399 ctrl->value = sensor->info_priv.whiteBalance;
2402 case V4L2_CID_EXPOSURE:
2404 ctrl->value = sensor->info_priv.exposure;
2407 case V4L2_CID_HFLIP:
2409 ctrl->value = sensor->info_priv.mirror;
2412 case V4L2_CID_VFLIP:
2414 ctrl->value = sensor->info_priv.flip;
2425 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2427 struct i2c_client *client = sd->priv;
2428 struct sensor *sensor = to_sensor(client);
2429 struct soc_camera_device *icd = client->dev.platform_data;
2430 const struct v4l2_queryctrl *qctrl;
2433 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2437 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2443 #if CONFIG_SENSOR_Brightness
2444 case V4L2_CID_BRIGHTNESS:
2446 if (ctrl->value != sensor->info_priv.brightness)
2448 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2452 sensor->info_priv.brightness = ctrl->value;
2457 #if CONFIG_SENSOR_Exposure
2458 case V4L2_CID_EXPOSURE:
2460 if (ctrl->value != sensor->info_priv.exposure)
2462 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2466 sensor->info_priv.exposure = ctrl->value;
2471 #if CONFIG_SENSOR_Saturation
2472 case V4L2_CID_SATURATION:
2474 if (ctrl->value != sensor->info_priv.saturation)
2476 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2480 sensor->info_priv.saturation = ctrl->value;
2485 #if CONFIG_SENSOR_Contrast
2486 case V4L2_CID_CONTRAST:
2488 if (ctrl->value != sensor->info_priv.contrast)
2490 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2494 sensor->info_priv.contrast = ctrl->value;
2499 #if CONFIG_SENSOR_WhiteBalance
2500 case V4L2_CID_DO_WHITE_BALANCE:
2502 if (ctrl->value != sensor->info_priv.whiteBalance)
2504 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2508 sensor->info_priv.whiteBalance = ctrl->value;
2513 #if CONFIG_SENSOR_Mirror
2514 case V4L2_CID_HFLIP:
2516 if (ctrl->value != sensor->info_priv.mirror)
2518 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2520 sensor->info_priv.mirror = ctrl->value;
2525 #if CONFIG_SENSOR_Flip
2526 case V4L2_CID_VFLIP:
2528 if (ctrl->value != sensor->info_priv.flip)
2530 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2532 sensor->info_priv.flip = ctrl->value;
2543 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2545 const struct v4l2_queryctrl *qctrl;
2546 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2547 struct sensor *sensor = to_sensor(client);
2549 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2553 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2557 switch (ext_ctrl->id)
2559 case V4L2_CID_SCENE:
2561 ext_ctrl->value = sensor->info_priv.scene;
2564 case V4L2_CID_EFFECT:
2566 ext_ctrl->value = sensor->info_priv.effect;
2569 case V4L2_CID_ZOOM_ABSOLUTE:
2571 ext_ctrl->value = sensor->info_priv.digitalzoom;
2574 case V4L2_CID_ZOOM_RELATIVE:
2578 case V4L2_CID_FOCUS_ABSOLUTE:
2580 ext_ctrl->value = sensor->info_priv.focus;
2583 case V4L2_CID_FOCUS_RELATIVE:
2587 case V4L2_CID_FLASH:
2589 ext_ctrl->value = sensor->info_priv.flash;
2597 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2599 const struct v4l2_queryctrl *qctrl;
2600 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2601 struct sensor *sensor = to_sensor(client);
2604 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2608 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2613 switch (ext_ctrl->id)
2615 #if CONFIG_SENSOR_Scene
2616 case V4L2_CID_SCENE:
2618 if (ext_ctrl->value != sensor->info_priv.scene)
2620 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2622 sensor->info_priv.scene = ext_ctrl->value;
2627 #if CONFIG_SENSOR_Effect
2628 case V4L2_CID_EFFECT:
2630 if (ext_ctrl->value != sensor->info_priv.effect)
2632 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2634 sensor->info_priv.effect= ext_ctrl->value;
2639 #if CONFIG_SENSOR_DigitalZoom
2640 case V4L2_CID_ZOOM_ABSOLUTE:
2642 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2645 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2647 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2649 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2651 sensor->info_priv.digitalzoom += val_offset;
2653 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2658 case V4L2_CID_ZOOM_RELATIVE:
2660 if (ext_ctrl->value)
2662 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2664 sensor->info_priv.digitalzoom += ext_ctrl->value;
2666 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2671 #if CONFIG_SENSOR_Focus
2672 case V4L2_CID_FOCUS_ABSOLUTE:
2674 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2677 if (ext_ctrl->value != sensor->info_priv.focus)
2679 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2681 sensor->info_priv.focus += val_offset;
2686 case V4L2_CID_FOCUS_RELATIVE:
2688 if (ext_ctrl->value)
2690 sensor->info_priv.focus += ext_ctrl->value;
2692 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2697 #if CONFIG_SENSOR_Flash
2698 case V4L2_CID_FLASH:
2700 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2702 sensor->info_priv.flash = ext_ctrl->value;
2704 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2715 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2717 struct i2c_client *client = sd->priv;
2718 struct soc_camera_device *icd = client->dev.platform_data;
2719 int i, error_cnt=0, error_idx=-1;
2722 for (i=0; i<ext_ctrl->count; i++) {
2723 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2730 error_idx = ext_ctrl->count;
2732 if (error_idx != -1) {
2733 ext_ctrl->error_idx = error_idx;
2740 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2742 struct i2c_client *client = sd->priv;
2743 struct soc_camera_device *icd = client->dev.platform_data;
2744 int i, error_cnt=0, error_idx=-1;
2747 for (i=0; i<ext_ctrl->count; i++) {
2748 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2755 error_idx = ext_ctrl->count;
2757 if (error_idx != -1) {
2758 ext_ctrl->error_idx = error_idx;
2765 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2766 * this wasn't our capture interface, so, we wait for the right one */
2767 static int sensor_video_probe(struct soc_camera_device *icd,
2768 struct i2c_client *client)
2772 struct sensor *sensor = to_sensor(client);
2774 /* We must have a parent by now. And it cannot be a wrong one.
2775 * So this entire test is completely redundant. */
2776 if (!icd->dev.parent ||
2777 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2780 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2782 goto sensor_video_probe_err;
2786 ret = sensor_write(client, 0xff, 0x1);
2788 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2790 goto sensor_video_probe_err;
2792 mdelay(5); //delay 5 microseconds
2794 /* check if it is an sensor sensor */
2795 ret = sensor_read(client, 0x0a, &value);
2797 SENSOR_TR("read chip id high byte failed\n");
2799 goto sensor_video_probe_err;
2803 ret = sensor_read(client, 0x0b, &value);
2805 SENSOR_TR("read chip id low byte failed\n");
2807 goto sensor_video_probe_err;
2810 pid |= (value & 0xff);
2811 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2813 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
2814 sensor->model = SENSOR_V4L2_IDENT;
2816 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2818 goto sensor_video_probe_err;
2823 sensor_video_probe_err:
2828 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2830 struct i2c_client *client = sd->priv;
2831 struct soc_camera_device *icd = client->dev.platform_data;
2832 struct sensor *sensor = to_sensor(client);
2835 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2838 case RK_CAM_SUBDEV_DEACTIVATE:
2840 sensor_deactivate(client);
2844 case RK_CAM_SUBDEV_IOREQUEST:
2846 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
2847 if (sensor->sensor_io_request != NULL) {
2848 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2849 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2850 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2851 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2852 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2853 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2856 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2858 goto sensor_ioctl_end;
2860 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2862 #if CONFIG_SENSOR_Flash
2863 if (sensor->sensor_gpio_res) {
2864 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2865 for (i = 0; i < icd->ops->num_controls; i++) {
2866 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2867 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2870 sensor->info_priv.flash = 0xff;
2871 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2879 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2888 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2889 enum v4l2_mbus_pixelcode *code)
2891 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2894 *code = sensor_colour_fmts[index].code;
2897 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2898 .init = sensor_init,
2899 .g_ctrl = sensor_g_control,
2900 .s_ctrl = sensor_s_control,
2901 .g_ext_ctrls = sensor_g_ext_controls,
2902 .s_ext_ctrls = sensor_s_ext_controls,
2903 .g_chip_ident = sensor_g_chip_ident,
2904 .ioctl = sensor_ioctl,
2907 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2908 .s_mbus_fmt = sensor_s_fmt,
2909 .g_mbus_fmt = sensor_g_fmt,
2910 .try_mbus_fmt = sensor_try_fmt,
2911 .enum_mbus_fmt = sensor_enum_fmt,
2914 static struct v4l2_subdev_ops sensor_subdev_ops = {
2915 .core = &sensor_subdev_core_ops,
2916 .video = &sensor_subdev_video_ops,
2919 static int sensor_probe(struct i2c_client *client,
2920 const struct i2c_device_id *did)
2922 struct sensor *sensor;
2923 struct soc_camera_device *icd = client->dev.platform_data;
2924 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2925 struct soc_camera_link *icl;
2928 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2930 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2934 icl = to_soc_camera_link(icd);
2936 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2940 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2941 dev_warn(&adapter->dev,
2942 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2946 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2950 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2952 /* Second stage probe - when a capture adapter is there */
2953 icd->ops = &sensor_ops;
2954 sensor->info_priv.fmt = sensor_colour_fmts[0];
2955 #if CONFIG_SENSOR_I2C_NOSCHED
2956 atomic_set(&sensor->tasklock_cnt,0);
2959 ret = sensor_video_probe(icd, client);
2962 i2c_set_clientdata(client, NULL);
2966 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2970 static int sensor_remove(struct i2c_client *client)
2972 struct sensor *sensor = to_sensor(client);
2973 struct soc_camera_device *icd = client->dev.platform_data;
2976 i2c_set_clientdata(client, NULL);
2977 client->driver = NULL;
2983 static const struct i2c_device_id sensor_id[] = {
2984 {SENSOR_NAME_STRING(), 0 },
2987 MODULE_DEVICE_TABLE(i2c, sensor_id);
2989 static struct i2c_driver sensor_i2c_driver = {
2991 .name = SENSOR_NAME_STRING(),
2993 .probe = sensor_probe,
2994 .remove = sensor_remove,
2995 .id_table = sensor_id,
2998 static int __init sensor_mod_init(void)
3000 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3001 return i2c_add_driver(&sensor_i2c_driver);
3004 static void __exit sensor_mod_exit(void)
3006 i2c_del_driver(&sensor_i2c_driver);
3009 device_initcall_sync(sensor_mod_init);
3010 module_exit(sensor_mod_exit);
3012 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3013 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3014 MODULE_LICENSE("GPL");