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 <plat/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 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 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 /* init 800*600 SVGA */
87 static struct reginfo sensor_init_data[] =
104 {0x04,0xF8},//b7,b6 directs
174 {0x7d,0x00},//0x00//0x07
176 {0x7d,0x48},//0x48//0x40
177 {0x7d,0x48},//0x48//0x40
318 {0x0, 0x0} //end flag
323 static struct reginfo sensor_uxga[] =
342 {0x0, 0x0} //end flag
346 static struct reginfo sensor_sxga[] =
365 {0x0, 0x0} //end flag
369 static struct reginfo sensor_xga[] =
388 {0x0, 0x0} //end flag
395 static struct reginfo sensor_svga[] =
397 {0x0, 0x0} //end flag
401 static struct reginfo sensor_vga[] =
403 {0x0, 0x0} //end flag
407 static struct reginfo sensor_cif[] =
409 {0x0, 0x0} //end flag
413 static struct reginfo sensor_qvga[] =
415 {0x0, 0x0} //end flag
419 static struct reginfo sensor_qcif[] =
421 {0x0, 0x0} //end flag
425 static struct reginfo ov2655_qqvga[] =
469 static struct reginfo ov2655_Sharpness_auto[] =
474 static struct reginfo ov2655_Sharpness1[] =
480 static struct reginfo ov2655_Sharpness2[][3] =
487 static struct reginfo ov2655_Sharpness3[] =
493 static struct reginfo ov2655_Sharpness4[]=
500 static struct reginfo ov2655_Sharpness5[] =
508 static struct reginfo sensor_ClrFmt_YUYV[]=
514 static struct reginfo sensor_ClrFmt_UYVY[]=
520 #if CONFIG_SENSOR_WhiteBalance
521 static struct reginfo sensor_WhiteB_Auto[]=
523 {0x3406, 0x00}, //AWB auto, bit[1]:0,auto
526 /* Cloudy Colour Temperature : 6500K - 8000K */
527 static struct reginfo sensor_WhiteB_Cloudy[]=
538 /* ClearDay Colour Temperature : 5000K - 6500K */
539 static struct reginfo sensor_WhiteB_ClearDay[]=
551 /* Office Colour Temperature : 3500K - 5000K */
552 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
565 /* Home Colour Temperature : 2500K - 3500K */
566 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
578 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
579 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
583 #if CONFIG_SENSOR_Brightness
584 static struct reginfo sensor_Brightness0[]=
591 {0x0, 0x0} //end flag
594 static struct reginfo sensor_Brightness1[]=
602 {0x0, 0x0} //end flag
605 static struct reginfo sensor_Brightness2[]=
613 {0x0, 0x0} //end flag
616 static struct reginfo sensor_Brightness3[]=
624 {0x0, 0x0} //end flag
627 static struct reginfo sensor_Brightness4[]=
635 {0x0, 0x0} //end flag
638 static struct reginfo sensor_Brightness5[]=
645 {0x0, 0x0} //end flag
647 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
648 sensor_Brightness4, sensor_Brightness5,NULL,
653 #if CONFIG_SENSOR_Effect
654 static struct reginfo sensor_Effect_Normal[] =
662 {0x0, 0x0} //end flag
665 static struct reginfo sensor_Effect_WandB[] =
673 {0x0, 0x0} //end flag
676 static struct reginfo sensor_Effect_Sepia[] =
684 {0x0, 0x0} //end flag
687 static struct reginfo sensor_Effect_Negative[] =
695 {0x0, 0x0} //end flag
697 static struct reginfo sensor_Effect_Bluish[] =
705 {0x0, 0x0} //end flag
708 static struct reginfo sensor_Effect_Green[] =
716 {0x0, 0x0} //end flag
719 static struct reginfo sensor_Effect_Exp_Windows_Half[] =
726 {0x0, 0x0} //end flag
728 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
729 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
732 #if CONFIG_SENSOR_Exposure
733 static struct reginfo sensor_Exposure0[]=
738 static struct reginfo sensor_Exposure1[]=
743 static struct reginfo sensor_Exposure2[]=
748 static struct reginfo sensor_Exposure3[]=
753 static struct reginfo sensor_Exposure4[]=
758 static struct reginfo sensor_Exposure5[]=
763 static struct reginfo sensor_Exposure6[]=
768 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
769 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
772 #if CONFIG_SENSOR_Saturation
773 static struct reginfo sensor_Saturation0[]=
793 {0x0, 0x0} //end flag
796 static struct reginfo sensor_Saturation1[]=
816 {0x0, 0x0} //end flag
819 static struct reginfo sensor_Saturation2[]=
839 {0x0, 0x0} //end flag
841 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
845 #if CONFIG_SENSOR_Contrast
846 static struct reginfo sensor_Contrast0[]=
856 {0x0, 0x0} //end flag
860 static struct reginfo sensor_Contrast1[]=
870 {0x0, 0x0} //end flag
873 static struct reginfo sensor_Contrast2[]=
883 {0x0, 0x0} //end flag
886 static struct reginfo sensor_Contrast3[]=
896 {0x0, 0x0} //end flag
899 static struct reginfo sensor_Contrast4[]=
909 {0x0, 0x0} //end flag
913 static struct reginfo sensor_Contrast5[]=
923 {0x0, 0x0} //end flag
926 static struct reginfo sensor_Contrast6[]=
936 {0x0, 0x0} //end flag
940 static struct reginfo sensor_Contrast7[]=
950 {0x0, 0x0} //end flag
953 static struct reginfo sensor_Contrast8[]=
963 {0x0, 0x0} //end flag
966 static struct reginfo sensor_Contrast9[]=
976 {0x0, 0x0} //end flag
981 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
982 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
986 #if CONFIG_SENSOR_Mirror
987 static struct reginfo sensor_MirrorOn[]=
992 static struct reginfo sensor_MirrorOff[]=
996 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
998 #if CONFIG_SENSOR_Flip
999 static struct reginfo sensor_FlipOn[]=
1004 static struct reginfo sensor_FlipOff[]=
1008 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1011 #if CONFIG_SENSOR_Scene
1012 static struct reginfo sensor_SceneAuto[] =
1018 static struct reginfo sensor_SceneNight[] =
1031 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1034 #if CONFIG_SENSOR_DigitalZoom
1035 static struct reginfo sensor_Zoom0[] =
1040 static struct reginfo sensor_Zoom1[] =
1045 static struct reginfo sensor_Zoom2[] =
1051 static struct reginfo sensor_Zoom3[] =
1055 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1057 static const struct v4l2_querymenu sensor_menus[] =
1059 #if CONFIG_SENSOR_WhiteBalance
1060 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1061 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1062 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1065 #if CONFIG_SENSOR_Effect
1066 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1067 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1068 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1071 #if CONFIG_SENSOR_Scene
1072 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1075 #if CONFIG_SENSOR_Flash
1076 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1077 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1081 static const struct v4l2_queryctrl sensor_controls[] =
1083 #if CONFIG_SENSOR_WhiteBalance
1085 .id = V4L2_CID_DO_WHITE_BALANCE,
1086 .type = V4L2_CTRL_TYPE_MENU,
1087 .name = "White Balance Control",
1095 #if CONFIG_SENSOR_Brightness
1097 .id = V4L2_CID_BRIGHTNESS,
1098 .type = V4L2_CTRL_TYPE_INTEGER,
1099 .name = "Brightness Control",
1107 #if CONFIG_SENSOR_Effect
1109 .id = V4L2_CID_EFFECT,
1110 .type = V4L2_CTRL_TYPE_MENU,
1111 .name = "Effect Control",
1119 #if CONFIG_SENSOR_Exposure
1121 .id = V4L2_CID_EXPOSURE,
1122 .type = V4L2_CTRL_TYPE_INTEGER,
1123 .name = "Exposure Control",
1131 #if CONFIG_SENSOR_Saturation
1133 .id = V4L2_CID_SATURATION,
1134 .type = V4L2_CTRL_TYPE_INTEGER,
1135 .name = "Saturation Control",
1143 #if CONFIG_SENSOR_Contrast
1145 .id = V4L2_CID_CONTRAST,
1146 .type = V4L2_CTRL_TYPE_INTEGER,
1147 .name = "Contrast Control",
1155 #if CONFIG_SENSOR_Mirror
1157 .id = V4L2_CID_HFLIP,
1158 .type = V4L2_CTRL_TYPE_BOOLEAN,
1159 .name = "Mirror Control",
1167 #if CONFIG_SENSOR_Flip
1169 .id = V4L2_CID_VFLIP,
1170 .type = V4L2_CTRL_TYPE_BOOLEAN,
1171 .name = "Flip Control",
1179 #if CONFIG_SENSOR_Scene
1181 .id = V4L2_CID_SCENE,
1182 .type = V4L2_CTRL_TYPE_MENU,
1183 .name = "Scene Control",
1191 #if CONFIG_SENSOR_DigitalZoom
1193 .id = V4L2_CID_ZOOM_RELATIVE,
1194 .type = V4L2_CTRL_TYPE_INTEGER,
1195 .name = "DigitalZoom Control",
1201 .id = V4L2_CID_ZOOM_ABSOLUTE,
1202 .type = V4L2_CTRL_TYPE_INTEGER,
1203 .name = "DigitalZoom Control",
1211 #if CONFIG_SENSOR_Focus
1213 .id = V4L2_CID_FOCUS_RELATIVE,
1214 .type = V4L2_CTRL_TYPE_INTEGER,
1215 .name = "Focus Control",
1221 .id = V4L2_CID_FOCUS_ABSOLUTE,
1222 .type = V4L2_CTRL_TYPE_INTEGER,
1223 .name = "Focus Control",
1227 .default_value = 125,
1231 #if CONFIG_SENSOR_Flash
1233 .id = V4L2_CID_FLASH,
1234 .type = V4L2_CTRL_TYPE_MENU,
1235 .name = "Flash Control",
1244 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1245 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1246 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1247 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1248 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1249 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1250 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1251 static int sensor_resume(struct soc_camera_device *icd);
1252 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1253 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1254 #if CONFIG_SENSOR_Effect
1255 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1257 #if CONFIG_SENSOR_WhiteBalance
1258 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1260 static int sensor_deactivate(struct i2c_client *client);
1262 static struct soc_camera_ops sensor_ops =
1264 .suspend = sensor_suspend,
1265 .resume = sensor_resume,
1266 .set_bus_param = sensor_set_bus_param,
1267 .query_bus_param = sensor_query_bus_param,
1268 .controls = sensor_controls,
1269 .menus = sensor_menus,
1270 .num_controls = ARRAY_SIZE(sensor_controls),
1271 .num_menus = ARRAY_SIZE(sensor_menus),
1274 /* only one fixed colorspace per pixelcode */
1275 struct sensor_datafmt {
1276 enum v4l2_mbus_pixelcode code;
1277 enum v4l2_colorspace colorspace;
1280 /* Find a data format by a pixel code in an array */
1281 static const struct sensor_datafmt *sensor_find_datafmt(
1282 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1286 for (i = 0; i < n; i++)
1287 if (fmt[i].code == code)
1293 static const struct sensor_datafmt sensor_colour_fmts[] = {
1294 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1295 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1298 typedef struct sensor_info_priv_s
1312 unsigned char mirror; /* HFLIP */
1313 unsigned char flip; /* VFLIP */
1314 unsigned int winseqe_cur_addr;
1315 struct sensor_datafmt fmt;
1317 } sensor_info_priv_t;
1321 struct v4l2_subdev subdev;
1322 struct i2c_client *client;
1323 sensor_info_priv_t info_priv;
1324 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1325 #if CONFIG_SENSOR_I2C_NOSCHED
1326 atomic_t tasklock_cnt;
1328 struct rk29camera_platform_data *sensor_io_request;
1329 struct rk29camera_gpio_res *sensor_gpio_res;
1332 static struct sensor* to_sensor(const struct i2c_client *client)
1334 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1337 static int sensor_task_lock(struct i2c_client *client, int lock)
1339 #if CONFIG_SENSOR_I2C_NOSCHED
1341 struct sensor *sensor = to_sensor(client);
1344 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1345 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1346 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1350 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1351 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1352 goto sensor_task_lock_err;
1357 atomic_add(1, &sensor->tasklock_cnt);
1359 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1360 atomic_sub(1, &sensor->tasklock_cnt);
1362 if (atomic_read(&sensor->tasklock_cnt) == 0)
1367 sensor_task_lock_err:
1374 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1378 struct i2c_msg msg[1];
1380 buf[0] = reg & 0xFF;
1383 msg->addr = client->addr;
1384 msg->flags = client->flags;
1386 msg->len = sizeof(buf);
1387 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1388 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1393 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1394 err = i2c_transfer(client->adapter, msg, 1);
1399 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1407 /* sensor register read */
1408 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1412 struct i2c_msg msg[2];
1414 buf[0] = reg ;//>> 8;
1417 msg[0].addr = client->addr;
1418 msg[0].flags = client->flags;
1420 msg[0].len = sizeof(buf);
1421 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1422 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 */
1424 msg[1].addr = client->addr;
1425 msg[1].flags = client->flags|I2C_M_RD;
1428 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1429 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1433 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1434 err = i2c_transfer(client->adapter, msg, 2);
1440 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1448 /* write a array of registers */
1449 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1453 #if CONFIG_SENSOR_I2C_RDWRCHK
1458 if (sensor_task_lock(client, 1) < 0)
1459 goto sensor_write_array_end;
1460 while (regarray[i].reg != 0)
1462 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1466 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1470 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1472 goto sensor_write_array_end;
1475 #if CONFIG_SENSOR_I2C_RDWRCHK
1476 sensor_read(client, regarray[i].reg, &valchk);
1477 if (valchk != regarray[i].val)
1478 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1484 sensor_write_array_end:
1485 sensor_task_lock(client,0);
1488 #if CONFIG_SENSOR_I2C_RDWRCHK
1489 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1497 while (regarray[i].reg != 0)
1499 sensor_read(client, regarray[i].reg, &valchk);
1500 if (valchk != regarray[i].val)
1501 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1508 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1510 struct soc_camera_link *icl = to_soc_camera_link(icd);
1513 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1517 case Sensor_PowerDown:
1519 if (icl->powerdown) {
1520 ret = icl->powerdown(icd->pdev, on);
1521 if (ret == RK29_CAM_IO_SUCCESS) {
1525 icl->reset(icd->pdev);
1527 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1529 goto sensor_power_end;
1536 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1537 struct sensor *sensor = to_sensor(client);
1539 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1540 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1546 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1553 static s32 sensor_init_width = 640;
1554 static s32 sensor_init_height = 480;
1555 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);
1556 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1557 static struct reginfo* sensor_init_data_p = NULL;
1558 static struct reginfo* sensor_init_winseq_p = NULL;
1559 static struct reginfo* sensor_init_winseq_board = NULL;
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 rk29camera_platform_data* tmp_plat_data =(struct rk29camera_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 && (u32)tmp_plat_data != 1) {
1575 for(i = 0;i < RK_CAM_NUM;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 && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && 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 RK29_CAM_SUBDEV_DEACTIVATE:
2840 sensor_deactivate(client);
2844 case RK29_CAM_SUBDEV_IOREQUEST:
2846 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2847 if (sensor->sensor_io_request != NULL) {
2849 for(j = 0;j < RK_CAM_NUM;j++){
2850 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
2851 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
2852 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
2856 if(j == RK_CAM_NUM){
2857 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2859 goto sensor_ioctl_end;
2862 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2864 #if CONFIG_SENSOR_Flash
2865 if (sensor->sensor_gpio_res) {
2866 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2867 for (i = 0; i < icd->ops->num_controls; i++) {
2868 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2869 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2872 sensor->info_priv.flash = 0xff;
2873 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2881 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2890 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2891 enum v4l2_mbus_pixelcode *code)
2893 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2896 *code = sensor_colour_fmts[index].code;
2899 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2900 .init = sensor_init,
2901 .g_ctrl = sensor_g_control,
2902 .s_ctrl = sensor_s_control,
2903 .g_ext_ctrls = sensor_g_ext_controls,
2904 .s_ext_ctrls = sensor_s_ext_controls,
2905 .g_chip_ident = sensor_g_chip_ident,
2906 .ioctl = sensor_ioctl,
2909 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2910 .s_mbus_fmt = sensor_s_fmt,
2911 .g_mbus_fmt = sensor_g_fmt,
2912 .try_mbus_fmt = sensor_try_fmt,
2913 .enum_mbus_fmt = sensor_enum_fmt,
2916 static struct v4l2_subdev_ops sensor_subdev_ops = {
2917 .core = &sensor_subdev_core_ops,
2918 .video = &sensor_subdev_video_ops,
2921 static int sensor_probe(struct i2c_client *client,
2922 const struct i2c_device_id *did)
2924 struct sensor *sensor;
2925 struct soc_camera_device *icd = client->dev.platform_data;
2926 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2927 struct soc_camera_link *icl;
2930 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2932 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2936 icl = to_soc_camera_link(icd);
2938 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2942 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2943 dev_warn(&adapter->dev,
2944 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2948 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2952 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2954 /* Second stage probe - when a capture adapter is there */
2955 icd->ops = &sensor_ops;
2956 sensor->info_priv.fmt = sensor_colour_fmts[0];
2957 #if CONFIG_SENSOR_I2C_NOSCHED
2958 atomic_set(&sensor->tasklock_cnt,0);
2961 ret = sensor_video_probe(icd, client);
2964 i2c_set_clientdata(client, NULL);
2968 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2972 static int sensor_remove(struct i2c_client *client)
2974 struct sensor *sensor = to_sensor(client);
2975 struct soc_camera_device *icd = client->dev.platform_data;
2978 i2c_set_clientdata(client, NULL);
2979 client->driver = NULL;
2985 static const struct i2c_device_id sensor_id[] = {
2986 {SENSOR_NAME_STRING(), 0 },
2989 MODULE_DEVICE_TABLE(i2c, sensor_id);
2991 static struct i2c_driver sensor_i2c_driver = {
2993 .name = SENSOR_NAME_STRING(),
2995 .probe = sensor_probe,
2996 .remove = sensor_remove,
2997 .id_table = sensor_id,
3000 static int __init sensor_mod_init(void)
3002 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3003 return i2c_add_driver(&sensor_i2c_driver);
3006 static void __exit sensor_mod_exit(void)
3008 i2c_del_driver(&sensor_i2c_driver);
3011 device_initcall_sync(sensor_mod_init);
3012 module_exit(sensor_mod_exit);
3014 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3015 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3016 MODULE_LICENSE("GPL");
3019 >>>>>>> parent of 15f7fab... temp revert rk change