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)
30 #define _STR(x) __STR(x)
31 #define STR(x) _STR(x)
33 #define MIN(x,y) ((x<y) ? x: y)
34 #define MAX(x,y) ((x>y) ? x: y)
36 /* Sensor Driver Configuration */
37 #define SENSOR_NAME RK29_CAM_SENSOR_OV2640
38 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2640
39 #define SENSOR_ID 0x2642
40 #define SENSOR_ID1 0x2641
41 #define SENSOR_MIN_WIDTH 640
42 #define SENSOR_MIN_HEIGHT 480
43 #define SENSOR_MAX_WIDTH 1600
44 #define SENSOR_MAX_HEIGHT 1200
45 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
46 #define SENSOR_INIT_HEIGHT sensor_init_height
47 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
48 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
49 #define SENSOR_BUS_PARAM sensor_init_busparam
51 #define CONFIG_SENSOR_WhiteBalance 0
52 #define CONFIG_SENSOR_Brightness 1
53 #define CONFIG_SENSOR_Contrast 0
54 #define CONFIG_SENSOR_Saturation 1
55 #define CONFIG_SENSOR_Effect 1
56 #define CONFIG_SENSOR_Scene 0
57 #define CONFIG_SENSOR_DigitalZoom 0
58 #define CONFIG_SENSOR_Focus 0
59 #define CONFIG_SENSOR_Exposure 0
60 #define CONFIG_SENSOR_Flash 0
61 #define CONFIG_SENSOR_Mirror 0
62 #define CONFIG_SENSOR_Flip 0
64 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
65 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
66 #define CONFIG_SENSOR_I2C_NOSCHED 0
67 #define CONFIG_SENSOR_I2C_RDWRCHK 0
70 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
71 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
72 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
73 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
74 #define COLOR_TEMPERATURE_OFFICE_DN 3500
75 #define COLOR_TEMPERATURE_OFFICE_UP 5000
76 #define COLOR_TEMPERATURE_HOME_DN 2500
77 #define COLOR_TEMPERATURE_HOME_UP 3500
79 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
80 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
88 /* init 800*600 SVGA */
89 static struct reginfo sensor_init_data[] =
106 {0x04,0xF8},//b7,b6 directs
176 {0x7d,0x00},//0x00//0x07
178 {0x7d,0x48},//0x48//0x40
179 {0x7d,0x48},//0x48//0x40
320 {0x0, 0x0} //end flag
325 static struct reginfo sensor_uxga[] =
344 {0x0, 0x0} //end flag
348 static struct reginfo sensor_sxga[] =
367 {0x0, 0x0} //end flag
371 static struct reginfo sensor_xga[] =
390 {0x0, 0x0} //end flag
397 static struct reginfo sensor_svga[] =
399 {0x0, 0x0} //end flag
403 static struct reginfo sensor_vga[] =
405 {0x0, 0x0} //end flag
409 static struct reginfo sensor_cif[] =
411 {0x0, 0x0} //end flag
415 static struct reginfo sensor_qvga[] =
417 {0x0, 0x0} //end flag
421 static struct reginfo sensor_qcif[] =
423 {0x0, 0x0} //end flag
427 static struct reginfo ov2655_qqvga[] =
471 static struct reginfo ov2655_Sharpness_auto[] =
476 static struct reginfo ov2655_Sharpness1[] =
482 static struct reginfo ov2655_Sharpness2[][3] =
489 static struct reginfo ov2655_Sharpness3[] =
495 static struct reginfo ov2655_Sharpness4[]=
502 static struct reginfo ov2655_Sharpness5[] =
510 static struct reginfo sensor_ClrFmt_YUYV[]=
516 static struct reginfo sensor_ClrFmt_UYVY[]=
522 #if CONFIG_SENSOR_WhiteBalance
523 static struct reginfo sensor_WhiteB_Auto[]=
525 {0x3406, 0x00}, //AWB auto, bit[1]:0,auto
528 /* Cloudy Colour Temperature : 6500K - 8000K */
529 static struct reginfo sensor_WhiteB_Cloudy[]=
540 /* ClearDay Colour Temperature : 5000K - 6500K */
541 static struct reginfo sensor_WhiteB_ClearDay[]=
553 /* Office Colour Temperature : 3500K - 5000K */
554 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
567 /* Home Colour Temperature : 2500K - 3500K */
568 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
580 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
581 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
585 #if CONFIG_SENSOR_Brightness
586 static struct reginfo sensor_Brightness0[]=
593 {0x0, 0x0} //end flag
596 static struct reginfo sensor_Brightness1[]=
604 {0x0, 0x0} //end flag
607 static struct reginfo sensor_Brightness2[]=
615 {0x0, 0x0} //end flag
618 static struct reginfo sensor_Brightness3[]=
626 {0x0, 0x0} //end flag
629 static struct reginfo sensor_Brightness4[]=
637 {0x0, 0x0} //end flag
640 static struct reginfo sensor_Brightness5[]=
647 {0x0, 0x0} //end flag
649 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
650 sensor_Brightness4, sensor_Brightness5,NULL,
655 #if CONFIG_SENSOR_Effect
656 static struct reginfo sensor_Effect_Normal[] =
664 {0x0, 0x0} //end flag
667 static struct reginfo sensor_Effect_WandB[] =
675 {0x0, 0x0} //end flag
678 static struct reginfo sensor_Effect_Sepia[] =
686 {0x0, 0x0} //end flag
689 static struct reginfo sensor_Effect_Negative[] =
697 {0x0, 0x0} //end flag
699 static struct reginfo sensor_Effect_Bluish[] =
707 {0x0, 0x0} //end flag
710 static struct reginfo sensor_Effect_Green[] =
718 {0x0, 0x0} //end flag
721 static struct reginfo sensor_Effect_Exp_Windows_Half[] =
728 {0x0, 0x0} //end flag
730 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
731 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
734 #if CONFIG_SENSOR_Exposure
735 static struct reginfo sensor_Exposure0[]=
740 static struct reginfo sensor_Exposure1[]=
745 static struct reginfo sensor_Exposure2[]=
750 static struct reginfo sensor_Exposure3[]=
755 static struct reginfo sensor_Exposure4[]=
760 static struct reginfo sensor_Exposure5[]=
765 static struct reginfo sensor_Exposure6[]=
770 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
771 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
774 #if CONFIG_SENSOR_Saturation
775 static struct reginfo sensor_Saturation0[]=
795 {0x0, 0x0} //end flag
798 static struct reginfo sensor_Saturation1[]=
818 {0x0, 0x0} //end flag
821 static struct reginfo sensor_Saturation2[]=
841 {0x0, 0x0} //end flag
843 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
847 #if CONFIG_SENSOR_Contrast
848 static struct reginfo sensor_Contrast0[]=
858 {0x0, 0x0} //end flag
862 static struct reginfo sensor_Contrast1[]=
872 {0x0, 0x0} //end flag
875 static struct reginfo sensor_Contrast2[]=
885 {0x0, 0x0} //end flag
888 static struct reginfo sensor_Contrast3[]=
898 {0x0, 0x0} //end flag
901 static struct reginfo sensor_Contrast4[]=
911 {0x0, 0x0} //end flag
915 static struct reginfo sensor_Contrast5[]=
925 {0x0, 0x0} //end flag
928 static struct reginfo sensor_Contrast6[]=
938 {0x0, 0x0} //end flag
942 static struct reginfo sensor_Contrast7[]=
952 {0x0, 0x0} //end flag
955 static struct reginfo sensor_Contrast8[]=
965 {0x0, 0x0} //end flag
968 static struct reginfo sensor_Contrast9[]=
978 {0x0, 0x0} //end flag
983 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
984 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
988 #if CONFIG_SENSOR_Mirror
989 static struct reginfo sensor_MirrorOn[]=
994 static struct reginfo sensor_MirrorOff[]=
998 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1000 #if CONFIG_SENSOR_Flip
1001 static struct reginfo sensor_FlipOn[]=
1006 static struct reginfo sensor_FlipOff[]=
1010 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1013 #if CONFIG_SENSOR_Scene
1014 static struct reginfo sensor_SceneAuto[] =
1020 static struct reginfo sensor_SceneNight[] =
1033 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1036 #if CONFIG_SENSOR_DigitalZoom
1037 static struct reginfo sensor_Zoom0[] =
1042 static struct reginfo sensor_Zoom1[] =
1047 static struct reginfo sensor_Zoom2[] =
1053 static struct reginfo sensor_Zoom3[] =
1057 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1059 static const struct v4l2_querymenu sensor_menus[] =
1061 #if CONFIG_SENSOR_WhiteBalance
1062 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1063 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1064 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1067 #if CONFIG_SENSOR_Effect
1068 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1069 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1070 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1073 #if CONFIG_SENSOR_Scene
1074 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1077 #if CONFIG_SENSOR_Flash
1078 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1079 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1083 static const struct v4l2_queryctrl sensor_controls[] =
1085 #if CONFIG_SENSOR_WhiteBalance
1087 .id = V4L2_CID_DO_WHITE_BALANCE,
1088 .type = V4L2_CTRL_TYPE_MENU,
1089 .name = "White Balance Control",
1097 #if CONFIG_SENSOR_Brightness
1099 .id = V4L2_CID_BRIGHTNESS,
1100 .type = V4L2_CTRL_TYPE_INTEGER,
1101 .name = "Brightness Control",
1109 #if CONFIG_SENSOR_Effect
1111 .id = V4L2_CID_EFFECT,
1112 .type = V4L2_CTRL_TYPE_MENU,
1113 .name = "Effect Control",
1121 #if CONFIG_SENSOR_Exposure
1123 .id = V4L2_CID_EXPOSURE,
1124 .type = V4L2_CTRL_TYPE_INTEGER,
1125 .name = "Exposure Control",
1133 #if CONFIG_SENSOR_Saturation
1135 .id = V4L2_CID_SATURATION,
1136 .type = V4L2_CTRL_TYPE_INTEGER,
1137 .name = "Saturation Control",
1145 #if CONFIG_SENSOR_Contrast
1147 .id = V4L2_CID_CONTRAST,
1148 .type = V4L2_CTRL_TYPE_INTEGER,
1149 .name = "Contrast Control",
1157 #if CONFIG_SENSOR_Mirror
1159 .id = V4L2_CID_HFLIP,
1160 .type = V4L2_CTRL_TYPE_BOOLEAN,
1161 .name = "Mirror Control",
1169 #if CONFIG_SENSOR_Flip
1171 .id = V4L2_CID_VFLIP,
1172 .type = V4L2_CTRL_TYPE_BOOLEAN,
1173 .name = "Flip Control",
1181 #if CONFIG_SENSOR_Scene
1183 .id = V4L2_CID_SCENE,
1184 .type = V4L2_CTRL_TYPE_MENU,
1185 .name = "Scene Control",
1193 #if CONFIG_SENSOR_DigitalZoom
1195 .id = V4L2_CID_ZOOM_RELATIVE,
1196 .type = V4L2_CTRL_TYPE_INTEGER,
1197 .name = "DigitalZoom Control",
1203 .id = V4L2_CID_ZOOM_ABSOLUTE,
1204 .type = V4L2_CTRL_TYPE_INTEGER,
1205 .name = "DigitalZoom Control",
1213 #if CONFIG_SENSOR_Focus
1215 .id = V4L2_CID_FOCUS_RELATIVE,
1216 .type = V4L2_CTRL_TYPE_INTEGER,
1217 .name = "Focus Control",
1223 .id = V4L2_CID_FOCUS_ABSOLUTE,
1224 .type = V4L2_CTRL_TYPE_INTEGER,
1225 .name = "Focus Control",
1229 .default_value = 125,
1233 #if CONFIG_SENSOR_Flash
1235 .id = V4L2_CID_FLASH,
1236 .type = V4L2_CTRL_TYPE_MENU,
1237 .name = "Flash Control",
1246 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1247 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1248 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1249 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1250 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1251 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1252 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1253 static int sensor_resume(struct soc_camera_device *icd);
1254 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1255 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1256 #if CONFIG_SENSOR_Effect
1257 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1259 #if CONFIG_SENSOR_WhiteBalance
1260 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1262 static int sensor_deactivate(struct i2c_client *client);
1264 static struct soc_camera_ops sensor_ops =
1266 .suspend = sensor_suspend,
1267 .resume = sensor_resume,
1268 .set_bus_param = sensor_set_bus_param,
1269 .query_bus_param = sensor_query_bus_param,
1270 .controls = sensor_controls,
1271 .menus = sensor_menus,
1272 .num_controls = ARRAY_SIZE(sensor_controls),
1273 .num_menus = ARRAY_SIZE(sensor_menus),
1276 /* only one fixed colorspace per pixelcode */
1277 struct sensor_datafmt {
1278 enum v4l2_mbus_pixelcode code;
1279 enum v4l2_colorspace colorspace;
1282 /* Find a data format by a pixel code in an array */
1283 static const struct sensor_datafmt *sensor_find_datafmt(
1284 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1288 for (i = 0; i < n; i++)
1289 if (fmt[i].code == code)
1295 static const struct sensor_datafmt sensor_colour_fmts[] = {
1296 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1297 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1300 typedef struct sensor_info_priv_s
1314 unsigned char mirror; /* HFLIP */
1315 unsigned char flip; /* VFLIP */
1316 unsigned int winseqe_cur_addr;
1317 struct sensor_datafmt fmt;
1319 } sensor_info_priv_t;
1323 struct v4l2_subdev subdev;
1324 struct i2c_client *client;
1325 sensor_info_priv_t info_priv;
1326 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1327 #if CONFIG_SENSOR_I2C_NOSCHED
1328 atomic_t tasklock_cnt;
1330 struct rk29camera_platform_data *sensor_io_request;
1331 struct rk29camera_gpio_res *sensor_gpio_res;
1334 static struct sensor* to_sensor(const struct i2c_client *client)
1336 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1339 static int sensor_task_lock(struct i2c_client *client, int lock)
1341 #if CONFIG_SENSOR_I2C_NOSCHED
1343 struct sensor *sensor = to_sensor(client);
1346 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1347 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1348 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1352 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1353 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1354 goto sensor_task_lock_err;
1359 atomic_add(1, &sensor->tasklock_cnt);
1361 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1362 atomic_sub(1, &sensor->tasklock_cnt);
1364 if (atomic_read(&sensor->tasklock_cnt) == 0)
1369 sensor_task_lock_err:
1376 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1380 struct i2c_msg msg[1];
1382 buf[0] = reg & 0xFF;
1385 msg->addr = client->addr;
1386 msg->flags = client->flags;
1388 msg->len = sizeof(buf);
1389 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1390 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1395 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1396 err = i2c_transfer(client->adapter, msg, 1);
1401 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1409 /* sensor register read */
1410 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1414 struct i2c_msg msg[2];
1416 buf[0] = reg ;//>> 8;
1419 msg[0].addr = client->addr;
1420 msg[0].flags = client->flags;
1422 msg[0].len = sizeof(buf);
1423 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1424 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 */
1426 msg[1].addr = client->addr;
1427 msg[1].flags = client->flags|I2C_M_RD;
1430 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1431 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1435 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1436 err = i2c_transfer(client->adapter, msg, 2);
1442 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1450 /* write a array of registers */
1451 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1455 #if CONFIG_SENSOR_I2C_RDWRCHK
1460 if (sensor_task_lock(client, 1) < 0)
1461 goto sensor_write_array_end;
1462 while (regarray[i].reg != 0)
1464 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1468 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1472 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1474 goto sensor_write_array_end;
1477 #if CONFIG_SENSOR_I2C_RDWRCHK
1478 sensor_read(client, regarray[i].reg, &valchk);
1479 if (valchk != regarray[i].val)
1480 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1486 sensor_write_array_end:
1487 sensor_task_lock(client,0);
1490 #if CONFIG_SENSOR_I2C_RDWRCHK
1491 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1499 while (regarray[i].reg != 0)
1501 sensor_read(client, regarray[i].reg, &valchk);
1502 if (valchk != regarray[i].val)
1503 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1510 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1512 struct soc_camera_link *icl = to_soc_camera_link(icd);
1515 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1519 case Sensor_PowerDown:
1521 if (icl->powerdown) {
1522 ret = icl->powerdown(icd->pdev, on);
1523 if (ret == RK29_CAM_IO_SUCCESS) {
1527 icl->reset(icd->pdev);
1529 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1531 goto sensor_power_end;
1538 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1539 struct sensor *sensor = to_sensor(client);
1541 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1542 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1548 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1555 static s32 sensor_init_width = 640;
1556 static s32 sensor_init_height = 480;
1557 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);
1558 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1559 static struct reginfo* sensor_init_data_p = sensor_init_data;
1560 static struct reginfo* sensor_init_winseq_p = sensor_svga;
1561 static struct reginfo* sensor_init_winseq_board = NULL;
1562 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1564 struct i2c_client *client = v4l2_get_subdevdata(sd);
1565 struct soc_camera_device *icd = client->dev.platform_data;
1566 struct sensor *sensor = to_sensor(client);
1567 const struct v4l2_queryctrl *qctrl;
1568 const struct sensor_datafmt *fmt;
1570 int ret,pid = 0,i = 0,j=0;
1571 //if val ==1,mean that sensor need to be reinit
1572 struct rk29camera_platform_data* tmp_plat_data =(struct rk29camera_platform_data*)val;
1573 sensor_init_data_p = sensor_init_data;
1574 sensor_init_winseq_p = sensor_vga;
1575 sensor_init_width = 640;
1576 sensor_init_height = 480;
1577 if (tmp_plat_data != NULL && (u32)tmp_plat_data != 1) {
1578 for(i = 0;i < RK_CAM_NUM;i++){
1579 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1580 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1584 if(tmp_plat_data && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1585 //user has defined the init data
1587 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1588 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1589 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1590 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1592 sensor_init_data_p = sensor_init_data;
1594 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1595 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1598 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1599 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1600 if(sensor_init_winseq_board)
1602 vfree(sensor_init_winseq_board);
1603 sensor_init_winseq_board = NULL;
1605 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1606 if(!sensor_init_winseq_board)
1607 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1608 for(j = 0;j< tmp_winseq_size;j++){
1609 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1610 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1612 sensor_init_winseq_p = sensor_init_winseq_board;
1614 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1615 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1617 //init width,height,bus,pixelcode
1618 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1619 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1620 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1621 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1622 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1623 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1624 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1625 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1628 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1630 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1632 goto sensor_INIT_ERR;
1636 if (sensor_task_lock(client,1)<0)
1637 goto sensor_INIT_ERR;
1638 ret = sensor_write(client, 0xff, 1);
1639 ret |= sensor_write(client, 0x12, 0x80);
1642 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1644 goto sensor_INIT_ERR;
1647 mdelay(5); //delay 5 microseconds
1648 /* check if it is an sensor sensor */
1649 ret = sensor_write(client, 0xff, 1);
1650 ret |= sensor_read(client, 0x0a, &value);
1652 SENSOR_TR("read chip id high byte failed\n");
1654 goto sensor_INIT_ERR;
1658 ret = sensor_read(client, 0x0b, &value);
1660 SENSOR_TR("read chip id low byte failed\n");
1662 goto sensor_INIT_ERR;
1665 pid |= (value & 0xff);
1667 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1668 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
1669 sensor->model = SENSOR_V4L2_IDENT;
1671 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1673 goto sensor_INIT_ERR;
1676 ret = sensor_write_array(client, sensor_init_data_p);
1679 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1680 goto sensor_INIT_ERR;
1682 sensor_task_lock(client,0);
1683 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1684 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1686 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1688 goto sensor_INIT_ERR;
1690 sensor->info_priv.fmt = *fmt;
1692 /* sensor sensor information for initialization */
1693 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1695 sensor->info_priv.whiteBalance = qctrl->default_value;
1696 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1698 sensor->info_priv.brightness = qctrl->default_value;
1699 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1701 sensor->info_priv.effect = qctrl->default_value;
1702 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1704 sensor->info_priv.exposure = qctrl->default_value;
1706 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1708 sensor->info_priv.saturation = qctrl->default_value;
1709 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1711 sensor->info_priv.contrast = qctrl->default_value;
1712 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1714 sensor->info_priv.mirror = qctrl->default_value;
1715 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1717 sensor->info_priv.flip = qctrl->default_value;
1718 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1720 sensor->info_priv.scene = qctrl->default_value;
1721 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1723 sensor->info_priv.digitalzoom = qctrl->default_value;
1725 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1726 #if CONFIG_SENSOR_Focus
1728 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1730 sensor->info_priv.focus = qctrl->default_value;
1733 #if CONFIG_SENSOR_Flash
1734 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1736 sensor->info_priv.flash = qctrl->default_value;
1739 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);
1743 sensor_task_lock(client,0);
1744 sensor_deactivate(client);
1748 static int sensor_deactivate(struct i2c_client *client)
1750 struct soc_camera_device *icd = client->dev.platform_data;
1752 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1754 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1756 sensor_task_lock(client, 1);
1757 sensor_write(client, 0x3000, reg_val&0xfc);
1758 sensor_write(client, 0x3001, 0x00);
1759 sensor_task_lock(client, 0);
1761 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1762 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1763 icd->user_width = SENSOR_INIT_WIDTH;
1764 icd->user_height = SENSOR_INIT_HEIGHT;
1769 static struct reginfo sensor_power_down_sequence[]=
1773 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1776 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1778 if (pm_msg.event == PM_EVENT_SUSPEND) {
1779 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1780 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1782 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1785 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1787 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1792 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1798 static int sensor_resume(struct soc_camera_device *icd)
1802 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1804 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1808 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1814 static int sensor_set_bus_param(struct soc_camera_device *icd,
1815 unsigned long flags)
1821 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1823 struct soc_camera_link *icl = to_soc_camera_link(icd);
1824 unsigned long flags = SENSOR_BUS_PARAM;
1826 return soc_camera_apply_sensor_flags(icl, flags);
1829 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1831 struct i2c_client *client = v4l2_get_subdevdata(sd);
1832 struct soc_camera_device *icd = client->dev.platform_data;
1833 struct sensor *sensor = to_sensor(client);
1835 mf->width = icd->user_width;
1836 mf->height = icd->user_height;
1837 mf->code = sensor->info_priv.fmt.code;
1838 mf->colorspace = sensor->info_priv.fmt.colorspace;
1839 mf->field = V4L2_FIELD_NONE;
1843 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1847 if ((mf->width == 1024) && (mf->height == 768)) {
1849 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1851 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1853 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1855 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1860 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1864 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1868 if ((mf->width == 1280) && (mf->height == 720)) {
1870 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1875 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1878 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1880 struct i2c_client *client = v4l2_get_subdevdata(sd);
1881 struct sensor *sensor = to_sensor(client);
1882 const struct sensor_datafmt *fmt;
1883 const struct v4l2_queryctrl *qctrl;
1884 struct soc_camera_device *icd = client->dev.platform_data;
1885 struct reginfo *winseqe_set_addr=NULL;
1886 int ret=0, set_w,set_h;
1888 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1889 ARRAY_SIZE(sensor_colour_fmts));
1892 goto sensor_s_fmt_end;
1895 if (sensor->info_priv.fmt.code != mf->code) {
1898 case V4L2_MBUS_FMT_YUYV8_2X8:
1900 winseqe_set_addr = sensor_ClrFmt_YUYV;
1903 case V4L2_MBUS_FMT_UYVY8_2X8:
1905 winseqe_set_addr = sensor_ClrFmt_UYVY;
1911 if (winseqe_set_addr != NULL) {
1912 sensor_write_array(client, winseqe_set_addr);
1913 sensor->info_priv.fmt.code = mf->code;
1914 sensor->info_priv.fmt.colorspace= mf->colorspace;
1915 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1917 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1924 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1926 winseqe_set_addr = sensor_qcif;
1930 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1932 winseqe_set_addr = sensor_qvga;
1936 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1938 winseqe_set_addr = sensor_cif;
1942 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1944 winseqe_set_addr = sensor_vga;
1948 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1950 winseqe_set_addr = sensor_svga;
1954 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1956 winseqe_set_addr = sensor_xga;
1960 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1962 winseqe_set_addr = sensor_sxga;
1966 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1968 winseqe_set_addr = sensor_uxga;
1974 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1975 set_w = SENSOR_INIT_WIDTH;
1976 set_h = SENSOR_INIT_HEIGHT;
1977 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1980 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1981 #if CONFIG_SENSOR_Flash
1982 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1983 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1984 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1985 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1987 } else { /* ddl@rock-chips.com : Video */
1988 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1989 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1990 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1994 ret |= sensor_write_array(client, winseqe_set_addr);
1996 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1997 #if CONFIG_SENSOR_Flash
1998 if (sensor_fmt_capturechk(sd,mf) == true) {
1999 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2000 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2001 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2005 goto sensor_s_fmt_end;
2008 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2010 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2011 #if CONFIG_SENSOR_Effect
2012 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2013 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2015 #if CONFIG_SENSOR_WhiteBalance
2016 if (sensor->info_priv.whiteBalance != 0) {
2017 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2018 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2021 sensor->info_priv.snap2preview = true;
2022 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2023 #if CONFIG_SENSOR_Effect
2024 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2025 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2027 #if CONFIG_SENSOR_WhiteBalance
2028 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2029 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2031 sensor->info_priv.video2preview = true;
2032 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2033 #if CONFIG_SENSOR_Effect
2034 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2035 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2037 #if CONFIG_SENSOR_WhiteBalance
2038 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2039 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2041 sensor->info_priv.video2preview = false;
2042 sensor->info_priv.snap2preview = false;
2044 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2048 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2058 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2060 struct i2c_client *client = v4l2_get_subdevdata(sd);
2061 struct sensor *sensor = to_sensor(client);
2062 const struct sensor_datafmt *fmt;
2065 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2066 ARRAY_SIZE(sensor_colour_fmts));
2068 fmt = &sensor->info_priv.fmt;
2069 mf->code = fmt->code;
2072 if (mf->height > SENSOR_MAX_HEIGHT)
2073 mf->height = SENSOR_MAX_HEIGHT;
2074 else if (mf->height < SENSOR_MIN_HEIGHT)
2075 mf->height = SENSOR_MIN_HEIGHT;
2077 if (mf->width > SENSOR_MAX_WIDTH)
2078 mf->width = SENSOR_MAX_WIDTH;
2079 else if (mf->width < SENSOR_MIN_WIDTH)
2080 mf->width = SENSOR_MIN_WIDTH;
2082 mf->colorspace = fmt->colorspace;
2086 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2088 struct i2c_client *client = v4l2_get_subdevdata(sd);
2090 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2093 if (id->match.addr != client->addr)
2096 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2101 #if CONFIG_SENSOR_Brightness
2102 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2104 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2106 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2108 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2110 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2112 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2115 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2119 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2123 #if CONFIG_SENSOR_Effect
2124 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2126 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2128 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2130 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2132 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2134 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2137 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2141 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2145 #if CONFIG_SENSOR_Exposure
2146 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2148 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2150 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2152 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2154 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2156 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2159 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2163 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2167 #if CONFIG_SENSOR_Saturation
2168 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2170 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2172 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2174 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2176 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2178 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2181 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2185 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2189 #if CONFIG_SENSOR_Contrast
2190 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2192 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2194 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2196 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2198 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2200 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2203 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2207 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2211 #if CONFIG_SENSOR_Mirror
2212 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2214 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2216 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2218 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2220 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2222 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2225 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2229 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2233 #if CONFIG_SENSOR_Flip
2234 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2236 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2238 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2240 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2242 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2244 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2247 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2251 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2255 #if CONFIG_SENSOR_Scene
2256 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2258 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2260 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2262 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2264 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2266 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2269 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2273 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2277 #if CONFIG_SENSOR_WhiteBalance
2278 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2280 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2282 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2284 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2286 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2288 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2291 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2295 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2299 #if CONFIG_SENSOR_DigitalZoom
2300 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2302 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2303 struct sensor *sensor = to_sensor(client);
2304 const struct v4l2_queryctrl *qctrl_info;
2305 int digitalzoom_cur, digitalzoom_total;
2307 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2311 digitalzoom_cur = sensor->info_priv.digitalzoom;
2312 digitalzoom_total = qctrl_info->maximum;
2314 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2316 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2320 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2322 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2326 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2328 *value = digitalzoom_total - digitalzoom_cur;
2331 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2333 *value = 0 - digitalzoom_cur;
2336 digitalzoom_cur += *value;
2338 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2340 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2342 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2345 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2352 #if CONFIG_SENSOR_Flash
2353 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2355 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2356 if (value == 3) { /* ddl@rock-chips.com: torch */
2357 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2359 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2361 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2365 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2370 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2372 struct i2c_client *client = v4l2_get_subdevdata(sd);
2373 struct sensor *sensor = to_sensor(client);
2374 const struct v4l2_queryctrl *qctrl;
2376 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2380 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2386 case V4L2_CID_BRIGHTNESS:
2388 ctrl->value = sensor->info_priv.brightness;
2391 case V4L2_CID_SATURATION:
2393 ctrl->value = sensor->info_priv.saturation;
2396 case V4L2_CID_CONTRAST:
2398 ctrl->value = sensor->info_priv.contrast;
2401 case V4L2_CID_DO_WHITE_BALANCE:
2403 ctrl->value = sensor->info_priv.whiteBalance;
2406 case V4L2_CID_EXPOSURE:
2408 ctrl->value = sensor->info_priv.exposure;
2411 case V4L2_CID_HFLIP:
2413 ctrl->value = sensor->info_priv.mirror;
2416 case V4L2_CID_VFLIP:
2418 ctrl->value = sensor->info_priv.flip;
2429 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2431 struct i2c_client *client = v4l2_get_subdevdata(sd);
2432 struct sensor *sensor = to_sensor(client);
2433 struct soc_camera_device *icd = client->dev.platform_data;
2434 const struct v4l2_queryctrl *qctrl;
2437 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2441 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2447 #if CONFIG_SENSOR_Brightness
2448 case V4L2_CID_BRIGHTNESS:
2450 if (ctrl->value != sensor->info_priv.brightness)
2452 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2456 sensor->info_priv.brightness = ctrl->value;
2461 #if CONFIG_SENSOR_Exposure
2462 case V4L2_CID_EXPOSURE:
2464 if (ctrl->value != sensor->info_priv.exposure)
2466 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2470 sensor->info_priv.exposure = ctrl->value;
2475 #if CONFIG_SENSOR_Saturation
2476 case V4L2_CID_SATURATION:
2478 if (ctrl->value != sensor->info_priv.saturation)
2480 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2484 sensor->info_priv.saturation = ctrl->value;
2489 #if CONFIG_SENSOR_Contrast
2490 case V4L2_CID_CONTRAST:
2492 if (ctrl->value != sensor->info_priv.contrast)
2494 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2498 sensor->info_priv.contrast = ctrl->value;
2503 #if CONFIG_SENSOR_WhiteBalance
2504 case V4L2_CID_DO_WHITE_BALANCE:
2506 if (ctrl->value != sensor->info_priv.whiteBalance)
2508 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2512 sensor->info_priv.whiteBalance = ctrl->value;
2517 #if CONFIG_SENSOR_Mirror
2518 case V4L2_CID_HFLIP:
2520 if (ctrl->value != sensor->info_priv.mirror)
2522 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2524 sensor->info_priv.mirror = ctrl->value;
2529 #if CONFIG_SENSOR_Flip
2530 case V4L2_CID_VFLIP:
2532 if (ctrl->value != sensor->info_priv.flip)
2534 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2536 sensor->info_priv.flip = ctrl->value;
2547 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2549 const struct v4l2_queryctrl *qctrl;
2550 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2551 struct sensor *sensor = to_sensor(client);
2553 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2557 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2561 switch (ext_ctrl->id)
2563 case V4L2_CID_SCENE:
2565 ext_ctrl->value = sensor->info_priv.scene;
2568 case V4L2_CID_EFFECT:
2570 ext_ctrl->value = sensor->info_priv.effect;
2573 case V4L2_CID_ZOOM_ABSOLUTE:
2575 ext_ctrl->value = sensor->info_priv.digitalzoom;
2578 case V4L2_CID_ZOOM_RELATIVE:
2582 case V4L2_CID_FOCUS_ABSOLUTE:
2584 ext_ctrl->value = sensor->info_priv.focus;
2587 case V4L2_CID_FOCUS_RELATIVE:
2591 case V4L2_CID_FLASH:
2593 ext_ctrl->value = sensor->info_priv.flash;
2601 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2603 const struct v4l2_queryctrl *qctrl;
2604 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2605 struct sensor *sensor = to_sensor(client);
2608 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2612 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2617 switch (ext_ctrl->id)
2619 #if CONFIG_SENSOR_Scene
2620 case V4L2_CID_SCENE:
2622 if (ext_ctrl->value != sensor->info_priv.scene)
2624 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2626 sensor->info_priv.scene = ext_ctrl->value;
2631 #if CONFIG_SENSOR_Effect
2632 case V4L2_CID_EFFECT:
2634 if (ext_ctrl->value != sensor->info_priv.effect)
2636 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2638 sensor->info_priv.effect= ext_ctrl->value;
2643 #if CONFIG_SENSOR_DigitalZoom
2644 case V4L2_CID_ZOOM_ABSOLUTE:
2646 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2649 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2651 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2653 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2655 sensor->info_priv.digitalzoom += val_offset;
2657 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2662 case V4L2_CID_ZOOM_RELATIVE:
2664 if (ext_ctrl->value)
2666 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2668 sensor->info_priv.digitalzoom += ext_ctrl->value;
2670 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2675 #if CONFIG_SENSOR_Focus
2676 case V4L2_CID_FOCUS_ABSOLUTE:
2678 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2681 if (ext_ctrl->value != sensor->info_priv.focus)
2683 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2685 sensor->info_priv.focus += val_offset;
2690 case V4L2_CID_FOCUS_RELATIVE:
2692 if (ext_ctrl->value)
2694 sensor->info_priv.focus += ext_ctrl->value;
2696 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2701 #if CONFIG_SENSOR_Flash
2702 case V4L2_CID_FLASH:
2704 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2706 sensor->info_priv.flash = ext_ctrl->value;
2708 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2719 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2721 struct i2c_client *client = v4l2_get_subdevdata(sd);
2722 struct soc_camera_device *icd = client->dev.platform_data;
2723 int i, error_cnt=0, error_idx=-1;
2726 for (i=0; i<ext_ctrl->count; i++) {
2727 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2734 error_idx = ext_ctrl->count;
2736 if (error_idx != -1) {
2737 ext_ctrl->error_idx = error_idx;
2744 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2746 struct i2c_client *client = v4l2_get_subdevdata(sd);
2747 struct soc_camera_device *icd = client->dev.platform_data;
2748 int i, error_cnt=0, error_idx=-1;
2751 for (i=0; i<ext_ctrl->count; i++) {
2752 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2759 error_idx = ext_ctrl->count;
2761 if (error_idx != -1) {
2762 ext_ctrl->error_idx = error_idx;
2769 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2770 * this wasn't our capture interface, so, we wait for the right one */
2771 static int sensor_video_probe(struct soc_camera_device *icd,
2772 struct i2c_client *client)
2776 struct sensor *sensor = to_sensor(client);
2778 /* We must have a parent by now. And it cannot be a wrong one.
2779 * So this entire test is completely redundant. */
2780 if (!icd->dev.parent ||
2781 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2784 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2786 goto sensor_video_probe_err;
2790 ret = sensor_write(client, 0xff, 0x1);
2792 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2794 goto sensor_video_probe_err;
2796 mdelay(5); //delay 5 microseconds
2798 /* check if it is an sensor sensor */
2799 ret = sensor_read(client, 0x0a, &value);
2801 SENSOR_TR("read chip id high byte failed\n");
2803 goto sensor_video_probe_err;
2807 ret = sensor_read(client, 0x0b, &value);
2809 SENSOR_TR("read chip id low byte failed\n");
2811 goto sensor_video_probe_err;
2814 pid |= (value & 0xff);
2815 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2817 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
2818 sensor->model = SENSOR_V4L2_IDENT;
2820 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2822 goto sensor_video_probe_err;
2827 sensor_video_probe_err:
2832 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2834 struct i2c_client *client = v4l2_get_subdevdata(sd);
2835 struct soc_camera_device *icd = client->dev.platform_data;
2836 struct sensor *sensor = to_sensor(client);
2839 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2842 case RK29_CAM_SUBDEV_DEACTIVATE:
2844 sensor_deactivate(client);
2848 case RK29_CAM_SUBDEV_IOREQUEST:
2850 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2851 if (sensor->sensor_io_request != NULL) {
2853 for(j = 0;j < RK_CAM_NUM;j++){
2854 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
2855 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
2856 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
2860 if(j == RK_CAM_NUM){
2861 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2863 goto sensor_ioctl_end;
2866 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2868 #if CONFIG_SENSOR_Flash
2869 if (sensor->sensor_gpio_res) {
2870 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2871 for (i = 0; i < icd->ops->num_controls; i++) {
2872 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2873 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2876 sensor->info_priv.flash = 0xff;
2877 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2885 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2894 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2895 enum v4l2_mbus_pixelcode *code)
2897 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2900 *code = sensor_colour_fmts[index].code;
2903 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2904 .init = sensor_init,
2905 .g_ctrl = sensor_g_control,
2906 .s_ctrl = sensor_s_control,
2907 .g_ext_ctrls = sensor_g_ext_controls,
2908 .s_ext_ctrls = sensor_s_ext_controls,
2909 .g_chip_ident = sensor_g_chip_ident,
2910 .ioctl = sensor_ioctl,
2913 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2914 .s_mbus_fmt = sensor_s_fmt,
2915 .g_mbus_fmt = sensor_g_fmt,
2916 .try_mbus_fmt = sensor_try_fmt,
2917 .enum_mbus_fmt = sensor_enum_fmt,
2920 static struct v4l2_subdev_ops sensor_subdev_ops = {
2921 .core = &sensor_subdev_core_ops,
2922 .video = &sensor_subdev_video_ops,
2925 static int sensor_probe(struct i2c_client *client,
2926 const struct i2c_device_id *did)
2928 struct sensor *sensor;
2929 struct soc_camera_device *icd = client->dev.platform_data;
2930 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2931 struct soc_camera_link *icl;
2934 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2936 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2940 icl = to_soc_camera_link(icd);
2942 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2946 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2947 dev_warn(&adapter->dev,
2948 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2952 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2956 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2958 /* Second stage probe - when a capture adapter is there */
2959 icd->ops = &sensor_ops;
2960 sensor->info_priv.fmt = sensor_colour_fmts[0];
2961 #if CONFIG_SENSOR_I2C_NOSCHED
2962 atomic_set(&sensor->tasklock_cnt,0);
2965 ret = sensor_video_probe(icd, client);
2968 i2c_set_clientdata(client, NULL);
2972 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2976 static int sensor_remove(struct i2c_client *client)
2978 struct sensor *sensor = to_sensor(client);
2979 struct soc_camera_device *icd = client->dev.platform_data;
2982 i2c_set_clientdata(client, NULL);
2983 client->driver = NULL;
2989 static const struct i2c_device_id sensor_id[] = {
2990 {SENSOR_NAME_STRING(), 0 },
2993 MODULE_DEVICE_TABLE(i2c, sensor_id);
2995 static struct i2c_driver sensor_i2c_driver = {
2997 .name = SENSOR_NAME_STRING(),
2999 .probe = sensor_probe,
3000 .remove = sensor_remove,
3001 .id_table = sensor_id,
3004 static int __init sensor_mod_init(void)
3006 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3007 return i2c_add_driver(&sensor_i2c_driver);
3010 static void __exit sensor_mod_exit(void)
3012 i2c_del_driver(&sensor_i2c_driver);
3015 device_initcall_sync(sensor_mod_init);
3016 module_exit(sensor_mod_exit);
3018 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3019 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3020 MODULE_LICENSE("GPL");