1 #include <linux/videodev2.h>
\r
2 #include <linux/slab.h>
4 #include <linux/log2.h>
5 #include <linux/platform_device.h>
6 #include <linux/delay.h>
7 #include <linux/circ_buf.h>
8 #include <linux/miscdevice.h>
9 #include <media/v4l2-common.h>
10 #include <media/v4l2-chip-ident.h>
11 #include <media/soc_camera.h>
12 #include <plat/rk_camera.h>
\r
15 module_param(debug, int, S_IRUGO|S_IWUSR);
17 #define dprintk(level, fmt, arg...) do { \
19 printk(KERN_WARNING fmt , ## arg); } while (0)
21 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
22 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
25 #define _CONS(a,b) a##b
26 #define CONS(a,b) _CONS(a,b)
29 #define _STR(x) __STR(x)
30 #define STR(x) _STR(x)
32 #define MIN(x,y) ((x<y) ? x: y)
33 #define MAX(x,y) ((x>y) ? x: y)
35 /* Sensor Driver Configuration */
36 #define SENSOR_NAME RK29_CAM_SENSOR_OV2640
37 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2640
38 #define SENSOR_ID 0x2642
39 #define SENSOR_ID1 0x2641
40 #define SENSOR_MIN_WIDTH 640
41 #define SENSOR_MIN_HEIGHT 480
42 #define SENSOR_MAX_WIDTH 1600
43 #define SENSOR_MAX_HEIGHT 1200
44 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
45 #define SENSOR_INIT_HEIGHT 480
46 #define SENSOR_INIT_WINSEQADR sensor_vga
47 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
49 #define CONFIG_SENSOR_WhiteBalance 1
50 #define CONFIG_SENSOR_Brightness 0
51 #define CONFIG_SENSOR_Contrast 0
52 #define CONFIG_SENSOR_Saturation 0
53 #define CONFIG_SENSOR_Effect 0
54 #define CONFIG_SENSOR_Scene 0
55 #define CONFIG_SENSOR_DigitalZoom 0
56 #define CONFIG_SENSOR_Focus 0
57 #define CONFIG_SENSOR_Exposure 0
58 #define CONFIG_SENSOR_Flash 1
\r
59 #define CONFIG_SENSOR_Mirror 0
60 #define CONFIG_SENSOR_Flip 0
62 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
63 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
64 #define CONFIG_SENSOR_I2C_NOSCHED 0
65 #define CONFIG_SENSOR_I2C_RDWRCHK 0
67 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
68 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
69 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
71 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
72 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
73 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
74 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
75 #define COLOR_TEMPERATURE_OFFICE_DN 3500
76 #define COLOR_TEMPERATURE_OFFICE_UP 5000
77 #define COLOR_TEMPERATURE_HOME_DN 2500
78 #define COLOR_TEMPERATURE_HOME_UP 3500
80 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
81 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
83 #define SENSOR_AF_IS_ERR (0x00<<0)
\r
84 #define SENSOR_AF_IS_OK (0x01<<0)
\r
85 #define SENSOR_INIT_IS_ERR (0x00<<28)
\r
86 #define SENSOR_INIT_IS_OK (0x01<<28)
\r
93 /* init 800*600 SVGA */
94 static struct reginfo sensor_init_data[] =
104 {0x03,0x4f},// 0x8f peak
111 {0x04,0x28},//b7,b6 directs
113 {0x14,0x28}, //0x48 peak
184 //{0xff,0x00}, //added by peak on 20120409
\r
186 {0x7d,0x02},//0x00 peak//0x07,È·±£ÔÚ±ðµÄÎļþÀïû±»¸²¸Ç
188 {0x7d,0x28},//0x48//0x40 Õâ¸öÖµÒѾºÜСÁË,³ý·ÇÄãÔÚ±ðµÄÎļþÀïÓÖдÁË
189 {0x7d,0x28},//0x48 peak//0x40 Õâ¸öÖµÒѾºÜСÁË,³ý·ÇÄãÔÚ±ðµÄÎļþÀïÓÖдÁË
191 // removed by peak on 20120409
\r
198 //contrast added by peak on 20120409
\r
200 //{0x7d,0x04},//0x48//0x40
\r
201 //{0x7c,0x07},//0x48 peak//0x40
\r
204 //{0x7d,0x0c},//0x10
\r
205 //{0x7d,0x06},//0x0e
\r
207 //{0xff, 0x01},// added by peak on 20120409
\r
308 //{0x5e, 0x7d},//0x3c
\r
309 //{0x5f, 0x7d},//0x28
\r
310 //{0x60, 0x55},//0x55
\r
343 {0x93,0x06}, //0x06 peak
390 {0x0, 0x0} //end flag
395 static struct reginfo sensor_uxga[] =
414 {0x0, 0x0} //end flag
418 static struct reginfo sensor_sxga[] =
437 {0x0, 0x0} //end flag
441 static struct reginfo sensor_xga[] =
460 {0x0, 0x0} //end flag
467 static struct reginfo sensor_svga[] =
469 {0x0, 0x0} //end flag
473 static struct reginfo sensor_vga[] =
475 {0x0, 0x0} //end flag
479 static struct reginfo sensor_cif[] =
481 {0x0, 0x0} //end flag
485 static struct reginfo sensor_qvga[] =
487 {0x0, 0x0} //end flag
491 static struct reginfo sensor_qcif[] =
493 {0x0, 0x0} //end flag
497 static struct reginfo ov2655_qqvga[] =
541 static struct reginfo ov2655_Sharpness_auto[] =
546 static struct reginfo ov2655_Sharpness1[] =
552 static struct reginfo ov2655_Sharpness2[][3] =
559 static struct reginfo ov2655_Sharpness3[] =
565 static struct reginfo ov2655_Sharpness4[]=
572 static struct reginfo ov2655_Sharpness5[] =
580 static struct reginfo sensor_ClrFmt_YUYV[]=
586 static struct reginfo sensor_ClrFmt_UYVY[]=
592 #if CONFIG_SENSOR_WhiteBalance
593 static struct reginfo sensor_WhiteB_Auto[]=
596 {0xff, 0x00}, //AWB auto, bit[1]:0,auto
600 /* Cloudy Colour Temperature : 6500K - 8000K */
601 static struct reginfo sensor_WhiteB_Cloudy[]=
610 /* ClearDay Colour Temperature : 5000K - 6500K */
611 static struct reginfo sensor_WhiteB_ClearDay[]=
622 /* Office Colour Temperature : 3500K - 5000K */
623 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
633 /* Home Colour Temperature : 2500K - 3500K */
634 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
644 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_ClearDay,sensor_WhiteB_Cloudy,sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
649 #if CONFIG_SENSOR_Brightness
650 static struct reginfo sensor_Brightness0[]=
657 {0x0, 0x0} //end flag
660 static struct reginfo sensor_Brightness1[]=
668 {0x0, 0x0} //end flag
671 static struct reginfo sensor_Brightness2[]=
679 {0x0, 0x0} //end flag
682 static struct reginfo sensor_Brightness3[]=
690 {0x0, 0x0} //end flag
693 static struct reginfo sensor_Brightness4[]=
701 {0x0, 0x0} //end flag
704 static struct reginfo sensor_Brightness5[]=
711 {0x0, 0x0} //end flag
713 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
714 sensor_Brightness4, sensor_Brightness5,NULL,
719 #if CONFIG_SENSOR_Effect
720 static struct reginfo sensor_Effect_Normal[] =
728 {0x0, 0x0} //end flag
731 static struct reginfo sensor_Effect_WandB[] =
739 {0x0, 0x0} //end flag
742 static struct reginfo sensor_Effect_Sepia[] =
750 {0x0, 0x0} //end flag
753 static struct reginfo sensor_Effect_Negative[] =
761 {0x0, 0x0} //end flag
763 static struct reginfo sensor_Effect_Bluish[] =
771 {0x0, 0x0} //end flag
774 static struct reginfo sensor_Effect_Green[] =
782 {0x0, 0x0} //end flag
785 static struct reginfo sensor_Effect_Exp_Windows_Half[] =
792 {0x0, 0x0} //end flag
794 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
795 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
798 #if CONFIG_SENSOR_Exposure
799 static struct reginfo sensor_Exposure0[]=
804 static struct reginfo sensor_Exposure1[]=
809 static struct reginfo sensor_Exposure2[]=
814 static struct reginfo sensor_Exposure3[]=
819 static struct reginfo sensor_Exposure4[]=
824 static struct reginfo sensor_Exposure5[]=
829 static struct reginfo sensor_Exposure6[]=
834 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
835 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
838 #if CONFIG_SENSOR_Saturation
839 static struct reginfo sensor_Saturation0[]=
859 {0x0, 0x0} //end flag
862 static struct reginfo sensor_Saturation1[]=
882 {0x0, 0x0} //end flag
885 static struct reginfo sensor_Saturation2[]=
905 {0x0, 0x0} //end flag
907 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
911 #if CONFIG_SENSOR_Contrast
912 static struct reginfo sensor_Contrast0[]=
922 {0x0, 0x0} //end flag
926 static struct reginfo sensor_Contrast1[]=
936 {0x0, 0x0} //end flag
939 static struct reginfo sensor_Contrast2[]=
949 {0x0, 0x0} //end flag
952 static struct reginfo sensor_Contrast3[]=
962 {0x0, 0x0} //end flag
965 static struct reginfo sensor_Contrast4[]=
975 {0x0, 0x0} //end flag
979 static struct reginfo sensor_Contrast5[]=
989 {0x0, 0x0} //end flag
992 static struct reginfo sensor_Contrast6[]=
1002 {0x0, 0x0} //end flag
1006 static struct reginfo sensor_Contrast7[]=
1016 {0x0, 0x0} //end flag
1019 static struct reginfo sensor_Contrast8[]=
1029 {0x0, 0x0} //end flag
1032 static struct reginfo sensor_Contrast9[]=
1042 {0x0, 0x0} //end flag
1047 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1048 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1052 #if CONFIG_SENSOR_Mirror
1053 static struct reginfo sensor_MirrorOn[]=
1058 static struct reginfo sensor_MirrorOff[]=
1062 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1064 #if CONFIG_SENSOR_Flip
1065 static struct reginfo sensor_FlipOn[]=
1070 static struct reginfo sensor_FlipOff[]=
1074 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1077 #if CONFIG_SENSOR_Scene
1078 static struct reginfo sensor_SceneAuto[] =
1086 static struct reginfo sensor_SceneNight[] =
1108 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1111 #if CONFIG_SENSOR_DigitalZoom
1112 static struct reginfo sensor_Zoom0[] =
1117 static struct reginfo sensor_Zoom1[] =
1122 static struct reginfo sensor_Zoom2[] =
1128 static struct reginfo sensor_Zoom3[] =
1132 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1134 static const struct v4l2_querymenu sensor_menus[] =
1136 #if CONFIG_SENSOR_WhiteBalance
1137 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1138 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1139 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1142 #if CONFIG_SENSOR_Effect
1143 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1144 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1145 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1148 #if CONFIG_SENSOR_Scene
1149 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1152 #if CONFIG_SENSOR_Flash
1153 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1154 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1158 static const struct v4l2_queryctrl sensor_controls[] =
1160 #if CONFIG_SENSOR_WhiteBalance
1162 .id = V4L2_CID_DO_WHITE_BALANCE,
1163 .type = V4L2_CTRL_TYPE_MENU,
1164 .name = "White Balance Control",
1172 #if CONFIG_SENSOR_Brightness
1174 .id = V4L2_CID_BRIGHTNESS,
1175 .type = V4L2_CTRL_TYPE_INTEGER,
1176 .name = "Brightness Control",
1184 #if CONFIG_SENSOR_Effect
1186 .id = V4L2_CID_EFFECT,
1187 .type = V4L2_CTRL_TYPE_MENU,
1188 .name = "Effect Control",
1196 #if CONFIG_SENSOR_Exposure
1198 .id = V4L2_CID_EXPOSURE,
1199 .type = V4L2_CTRL_TYPE_INTEGER,
1200 .name = "Exposure Control",
1208 #if CONFIG_SENSOR_Saturation
1210 .id = V4L2_CID_SATURATION,
1211 .type = V4L2_CTRL_TYPE_INTEGER,
1212 .name = "Saturation Control",
1220 #if CONFIG_SENSOR_Contrast
1222 .id = V4L2_CID_CONTRAST,
1223 .type = V4L2_CTRL_TYPE_INTEGER,
1224 .name = "Contrast Control",
1232 #if CONFIG_SENSOR_Mirror
1234 .id = V4L2_CID_HFLIP,
1235 .type = V4L2_CTRL_TYPE_BOOLEAN,
1236 .name = "Mirror Control",
1244 #if CONFIG_SENSOR_Flip
1246 .id = V4L2_CID_VFLIP,
1247 .type = V4L2_CTRL_TYPE_BOOLEAN,
1248 .name = "Flip Control",
1256 #if CONFIG_SENSOR_Scene
1258 .id = V4L2_CID_SCENE,
1259 .type = V4L2_CTRL_TYPE_MENU,
1260 .name = "Scene Control",
1268 #if CONFIG_SENSOR_DigitalZoom
1270 .id = V4L2_CID_ZOOM_RELATIVE,
1271 .type = V4L2_CTRL_TYPE_INTEGER,
1272 .name = "DigitalZoom Control",
1278 .id = V4L2_CID_ZOOM_ABSOLUTE,
1279 .type = V4L2_CTRL_TYPE_INTEGER,
1280 .name = "DigitalZoom Control",
1288 #if CONFIG_SENSOR_Focus
1290 .id = V4L2_CID_FOCUS_RELATIVE,
1291 .type = V4L2_CTRL_TYPE_INTEGER,
1292 .name = "Focus Control",
1298 .id = V4L2_CID_FOCUS_ABSOLUTE,
1299 .type = V4L2_CTRL_TYPE_INTEGER,
1300 .name = "Focus Control",
1304 .default_value = 125,
1308 #if CONFIG_SENSOR_Flash
1310 .id = V4L2_CID_FLASH,
1311 .type = V4L2_CTRL_TYPE_MENU,
1312 .name = "Flash Control",
1321 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1322 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1323 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1324 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1325 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1326 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1327 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1328 static int sensor_resume(struct soc_camera_device *icd);
1329 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1330 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1331 #if CONFIG_SENSOR_Effect
1332 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1334 #if CONFIG_SENSOR_WhiteBalance
1335 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1337 static int sensor_deactivate(struct i2c_client *client);
1339 static struct soc_camera_ops sensor_ops =
1341 .suspend = sensor_suspend,
1342 .resume = sensor_resume,
1343 .set_bus_param = sensor_set_bus_param,
1344 .query_bus_param = sensor_query_bus_param,
1345 .controls = sensor_controls,
1346 .menus = sensor_menus,
1347 .num_controls = ARRAY_SIZE(sensor_controls),
1348 .num_menus = ARRAY_SIZE(sensor_menus),
1351 /* only one fixed colorspace per pixelcode */
1352 struct sensor_datafmt {
1353 enum v4l2_mbus_pixelcode code;
1354 enum v4l2_colorspace colorspace;
1357 /* Find a data format by a pixel code in an array */
1358 static const struct sensor_datafmt *sensor_find_datafmt(
1359 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1363 for (i = 0; i < n; i++)
1364 if (fmt[i].code == code)
1370 static const struct sensor_datafmt sensor_colour_fmts[] = {
1371 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1372 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1375 typedef struct sensor_info_priv_s
1389 unsigned char mirror; /* HFLIP */
1390 unsigned char flip; /* VFLIP */
1391 unsigned int winseqe_cur_addr;
1392 struct sensor_datafmt fmt;
1393 unsigned int funmodule_state;
1394 } sensor_info_priv_t;
1398 struct v4l2_subdev subdev;
1399 struct i2c_client *client;
1400 sensor_info_priv_t info_priv;
1401 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1402 #if CONFIG_SENSOR_I2C_NOSCHED
1403 atomic_t tasklock_cnt;
1405 struct rk29camera_platform_data *sensor_io_request;
1406 struct rk29camera_gpio_res *sensor_gpio_res;
1409 static struct sensor* to_sensor(const struct i2c_client *client)
1411 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1414 static int sensor_task_lock(struct i2c_client *client, int lock)
1416 #if CONFIG_SENSOR_I2C_NOSCHED
1418 struct sensor *sensor = to_sensor(client);
1421 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1422 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1423 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1427 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1428 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1429 goto sensor_task_lock_err;
1434 atomic_add(1, &sensor->tasklock_cnt);
1436 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1437 atomic_sub(1, &sensor->tasklock_cnt);
1439 if (atomic_read(&sensor->tasklock_cnt) == 0)
1444 sensor_task_lock_err:
1451 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1455 struct i2c_msg msg[1];
1457 buf[0] = reg & 0xFF;
1460 msg->addr = client->addr;
1461 msg->flags = client->flags;
1463 msg->len = sizeof(buf);
1464 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1465 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1470 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1471 err = i2c_transfer(client->adapter, msg, 1);
1476 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1484 /* sensor register read */
1485 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1489 struct i2c_msg msg[2];
1491 buf[0] = reg ;//>> 8;
1494 msg[0].addr = client->addr;
1495 msg[0].flags = client->flags;
1497 msg[0].len = sizeof(buf);
1498 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1499 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 */
1501 msg[1].addr = client->addr;
1502 msg[1].flags = client->flags|I2C_M_RD;
1505 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1506 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1510 while ((cnt-->0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1511 err = i2c_transfer(client->adapter, msg, 2);
1517 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1525 /* write a array of registers */
1526 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1530 #if CONFIG_SENSOR_I2C_RDWRCHK
1535 if (sensor_task_lock(client, 1) < 0)
1536 goto sensor_write_array_end;
1537 while (regarray[i].reg != 0)
1539 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1543 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1547 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1549 goto sensor_write_array_end;
1552 #if CONFIG_SENSOR_I2C_RDWRCHK
1553 sensor_read(client, regarray[i].reg, &valchk);
1554 if (valchk != regarray[i].val)
1555 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1561 sensor_write_array_end:
1562 sensor_task_lock(client,0);
1565 #if CONFIG_SENSOR_I2C_RDWRCHK
1566 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1574 while (regarray[i].reg != 0)
1576 sensor_read(client, regarray[i].reg, &valchk);
1577 if (valchk != regarray[i].val)
1578 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1585 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1587 struct soc_camera_link *icl = to_soc_camera_link(icd);
1590 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1594 case Sensor_PowerDown:
1596 if (icl->powerdown) {
1597 ret = icl->powerdown(icd->pdev, on);
1598 if (ret == RK29_CAM_IO_SUCCESS) {
1602 icl->reset(icd->pdev);
1604 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1606 goto sensor_power_end;
1613 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1614 struct sensor *sensor = to_sensor(client);
1616 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1617 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1623 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1630 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1632 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1633 struct soc_camera_device *icd = client->dev.platform_data;
1634 struct sensor *sensor = to_sensor(client);
1635 const struct v4l2_queryctrl *qctrl;
1636 const struct sensor_datafmt *fmt;
1640 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1642 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1644 goto sensor_INIT_ERR;
1648 if (sensor_task_lock(client,1)<0)
1649 goto sensor_INIT_ERR;
1650 ret = sensor_write(client, 0xff, 1);
1651 ret |= sensor_write(client, 0x12, 0x80);
1654 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1656 goto sensor_INIT_ERR;
1659 mdelay(5); //delay 5 microseconds
1660 /* check if it is an sensor sensor */
1661 ret = sensor_write(client, 0xff, 1);
1662 ret |= sensor_read(client, 0x0a, &value);
1664 SENSOR_TR("read chip id high byte failed\n");
1666 goto sensor_INIT_ERR;
1670 ret = sensor_read(client, 0x0b, &value);
1672 SENSOR_TR("read chip id low byte failed\n");
1674 goto sensor_INIT_ERR;
1677 pid |= (value & 0xff);
1679 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1680 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
1681 sensor->model = SENSOR_V4L2_IDENT;
1683 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1685 goto sensor_INIT_ERR;
1688 ret = sensor_write_array(client, sensor_init_data);
1691 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1692 goto sensor_INIT_ERR;
1694 sensor_task_lock(client,0);
1695 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1696 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1698 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1700 goto sensor_INIT_ERR;
1702 sensor->info_priv.fmt = *fmt;
1704 /* sensor sensor information for initialization */
1705 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1707 sensor->info_priv.whiteBalance = qctrl->default_value;
1708 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1710 sensor->info_priv.brightness = qctrl->default_value;
1711 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1713 sensor->info_priv.effect = qctrl->default_value;
1714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1716 sensor->info_priv.exposure = qctrl->default_value;
1718 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1720 sensor->info_priv.saturation = qctrl->default_value;
1721 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1723 sensor->info_priv.contrast = qctrl->default_value;
1724 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1726 sensor->info_priv.mirror = qctrl->default_value;
1727 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1729 sensor->info_priv.flip = qctrl->default_value;
1730 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1732 sensor->info_priv.scene = qctrl->default_value;
1733 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1735 sensor->info_priv.digitalzoom = qctrl->default_value;
1737 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1738 #if CONFIG_SENSOR_Focus
1740 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1742 sensor->info_priv.focus = qctrl->default_value;
1745 #if CONFIG_SENSOR_Flash
1746 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1748 sensor->info_priv.flash = qctrl->default_value;
1751 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);
1752 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1755 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1756 sensor_task_lock(client,0);
1757 sensor_deactivate(client);
1761 static int sensor_deactivate(struct i2c_client *client)
1763 struct soc_camera_device *icd = client->dev.platform_data;
1765 struct sensor *sensor = to_sensor(client);
\r
1766 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1768 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1770 sensor_task_lock(client, 1);
1771 sensor_write(client, 0x3000, reg_val&0xfc);
1772 sensor_write(client, 0x3001, 0x00);
1773 sensor_task_lock(client, 0);
1775 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1777 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1778 icd->user_width = SENSOR_INIT_WIDTH;
1779 icd->user_height = SENSOR_INIT_HEIGHT;
1780 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1785 static struct reginfo sensor_power_down_sequence[]=
1789 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1792 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1794 if (pm_msg.event == PM_EVENT_SUSPEND) {
1795 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1796 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1798 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1801 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1803 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1808 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1814 static int sensor_resume(struct soc_camera_device *icd)
1818 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1820 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1824 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1830 static int sensor_set_bus_param(struct soc_camera_device *icd,
1831 unsigned long flags)
1837 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1839 struct soc_camera_link *icl = to_soc_camera_link(icd);
1840 unsigned long flags = SENSOR_BUS_PARAM;
1842 return soc_camera_apply_sensor_flags(icl, flags);
1845 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1847 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1848 struct soc_camera_device *icd = client->dev.platform_data;
1849 struct sensor *sensor = to_sensor(client);
1851 mf->width = icd->user_width;
1852 mf->height = icd->user_height;
1853 mf->code = sensor->info_priv.fmt.code;
1854 mf->colorspace = sensor->info_priv.fmt.colorspace;
1855 mf->field = V4L2_FIELD_NONE;
1859 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1863 if ((mf->width == 1024) && (mf->height == 768)) {
1865 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1867 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1869 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1871 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1876 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1880 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1884 if ((mf->width == 1280) && (mf->height == 720)) {
1886 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1891 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1894 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1896 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1897 struct sensor *sensor = to_sensor(client);
1898 const struct sensor_datafmt *fmt;
1899 const struct v4l2_queryctrl *qctrl;
1900 struct soc_camera_device *icd = client->dev.platform_data;
1901 struct reginfo *winseqe_set_addr=NULL;
1902 int ret=0, set_w,set_h;
1904 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1905 ARRAY_SIZE(sensor_colour_fmts));
1908 goto sensor_s_fmt_end;
1911 if (sensor->info_priv.fmt.code != mf->code) {
1914 case V4L2_MBUS_FMT_YUYV8_2X8:
1916 winseqe_set_addr = sensor_ClrFmt_YUYV;
1919 case V4L2_MBUS_FMT_UYVY8_2X8:
1921 winseqe_set_addr = sensor_ClrFmt_UYVY;
1927 if (winseqe_set_addr != NULL) {
1928 sensor_write_array(client, winseqe_set_addr);
1929 sensor->info_priv.fmt.code = mf->code;
1930 sensor->info_priv.fmt.colorspace= mf->colorspace;
1931 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1933 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1940 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1942 winseqe_set_addr = sensor_qcif;
1946 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1948 winseqe_set_addr = sensor_qvga;
1952 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1954 winseqe_set_addr = sensor_cif;
1958 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1960 winseqe_set_addr = sensor_vga;
1964 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1966 winseqe_set_addr = sensor_svga;
1970 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1972 winseqe_set_addr = sensor_xga;
1976 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1978 winseqe_set_addr = sensor_sxga;
1982 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1984 winseqe_set_addr = sensor_uxga;
1990 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1991 set_w = SENSOR_INIT_WIDTH;
1992 set_h = SENSOR_INIT_HEIGHT;
1993 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1996 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1997 #if CONFIG_SENSOR_Flash
1998 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1999 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2000 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2001 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2003 } else { /* ddl@rock-chips.com : Video */
2004 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2005 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2006 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2010 ret |= sensor_write_array(client, winseqe_set_addr);
2012 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2013 #if CONFIG_SENSOR_Flash
2014 if (sensor_fmt_capturechk(sd,mf) == true) {
2015 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2016 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2017 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2021 goto sensor_s_fmt_end;
2024 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2026 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2027 #if CONFIG_SENSOR_Effect
2028 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2029 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2031 #if CONFIG_SENSOR_WhiteBalance
2032 if (sensor->info_priv.whiteBalance != 0) {
2033 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2034 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2037 sensor->info_priv.snap2preview = true;
2038 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2039 #if CONFIG_SENSOR_Effect
2040 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2041 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2043 #if CONFIG_SENSOR_WhiteBalance
2044 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2045 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2047 sensor->info_priv.video2preview = true;
2048 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2049 #if CONFIG_SENSOR_Effect
2050 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2051 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2053 #if CONFIG_SENSOR_WhiteBalance
2054 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2055 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2057 sensor->info_priv.video2preview = false;
2058 sensor->info_priv.snap2preview = false;
2060 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2064 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2074 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2076 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2077 struct sensor *sensor = to_sensor(client);
2078 const struct sensor_datafmt *fmt;
2079 int ret = 0,set_w,set_h;
\r
2081 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2082 ARRAY_SIZE(sensor_colour_fmts));
2084 fmt = &sensor->info_priv.fmt;
2085 mf->code = fmt->code;
2088 if (mf->height > SENSOR_MAX_HEIGHT)
2089 mf->height = SENSOR_MAX_HEIGHT;
2090 else if (mf->height < SENSOR_MIN_HEIGHT)
2091 mf->height = SENSOR_MIN_HEIGHT;
2093 if (mf->width > SENSOR_MAX_WIDTH)
2094 mf->width = SENSOR_MAX_WIDTH;
2095 else if (mf->width < SENSOR_MIN_WIDTH)
2096 mf->width = SENSOR_MIN_WIDTH;
2101 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2106 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2111 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2116 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2121 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2126 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
2131 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2136 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2143 set_w = SENSOR_INIT_WIDTH;
\r
2144 set_h = SENSOR_INIT_HEIGHT;
2148 mf->height = set_h;
\r
2150 mf->colorspace = fmt->colorspace;
2154 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2156 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2158 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2161 if (id->match.addr != client->addr)
2164 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2169 #if CONFIG_SENSOR_Brightness
2170 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2172 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2174 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2176 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2178 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2180 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2183 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2187 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2191 #if CONFIG_SENSOR_Effect
2192 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2194 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2196 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2198 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2200 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2202 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2205 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2209 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2213 #if CONFIG_SENSOR_Exposure
2214 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2216 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2218 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2220 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2222 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2224 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2227 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2231 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2235 #if CONFIG_SENSOR_Saturation
2236 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2238 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2240 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2242 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2244 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2246 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2249 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2253 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2257 #if CONFIG_SENSOR_Contrast
2258 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2260 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2262 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2264 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2266 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2268 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2271 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2275 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2279 #if CONFIG_SENSOR_Mirror
2280 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2282 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2284 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2286 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2288 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2290 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2293 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2297 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2301 #if CONFIG_SENSOR_Flip
2302 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2304 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2306 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2308 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2310 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2312 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2315 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2319 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2323 #if CONFIG_SENSOR_Scene
2324 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2326 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2328 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2330 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2332 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2334 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2337 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2341 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2345 #if CONFIG_SENSOR_WhiteBalance
2346 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2348 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2350 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2352 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2354 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2356 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2359 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2363 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2367 #if CONFIG_SENSOR_DigitalZoom
2368 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2370 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2371 struct sensor *sensor = to_sensor(client);
2372 const struct v4l2_queryctrl *qctrl_info;
2373 int digitalzoom_cur, digitalzoom_total;
2375 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2379 digitalzoom_cur = sensor->info_priv.digitalzoom;
2380 digitalzoom_total = qctrl_info->maximum;
2382 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2384 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2388 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2390 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2394 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2396 value = digitalzoom_total - digitalzoom_cur;
2399 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2401 value = 0 - digitalzoom_cur;
2404 digitalzoom_cur += value;
2406 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2408 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2410 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2413 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2420 #if CONFIG_SENSOR_Flash
2421 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2423 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2424 if (value == 3) { /* ddl@rock-chips.com: torch */
2425 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2427 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2429 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2433 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2438 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2440 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2441 struct sensor *sensor = to_sensor(client);
2442 const struct v4l2_queryctrl *qctrl;
2444 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2448 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2454 case V4L2_CID_BRIGHTNESS:
2456 ctrl->value = sensor->info_priv.brightness;
2459 case V4L2_CID_SATURATION:
2461 ctrl->value = sensor->info_priv.saturation;
2464 case V4L2_CID_CONTRAST:
2466 ctrl->value = sensor->info_priv.contrast;
2469 case V4L2_CID_DO_WHITE_BALANCE:
2471 ctrl->value = sensor->info_priv.whiteBalance;
2474 case V4L2_CID_EXPOSURE:
2476 ctrl->value = sensor->info_priv.exposure;
2479 case V4L2_CID_HFLIP:
2481 ctrl->value = sensor->info_priv.mirror;
2484 case V4L2_CID_VFLIP:
2486 ctrl->value = sensor->info_priv.flip;
2497 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2499 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2500 struct sensor *sensor = to_sensor(client);
2501 struct soc_camera_device *icd = client->dev.platform_data;
2502 const struct v4l2_queryctrl *qctrl;
2505 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2509 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2515 #if CONFIG_SENSOR_Brightness
2516 case V4L2_CID_BRIGHTNESS:
2518 if (ctrl->value != sensor->info_priv.brightness)
2520 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2524 sensor->info_priv.brightness = ctrl->value;
2529 #if CONFIG_SENSOR_Exposure
2530 case V4L2_CID_EXPOSURE:
2532 if (ctrl->value != sensor->info_priv.exposure)
2534 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2538 sensor->info_priv.exposure = ctrl->value;
2543 #if CONFIG_SENSOR_Saturation
2544 case V4L2_CID_SATURATION:
2546 if (ctrl->value != sensor->info_priv.saturation)
2548 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2552 sensor->info_priv.saturation = ctrl->value;
2557 #if CONFIG_SENSOR_Contrast
2558 case V4L2_CID_CONTRAST:
2560 if (ctrl->value != sensor->info_priv.contrast)
2562 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2566 sensor->info_priv.contrast = ctrl->value;
2571 #if CONFIG_SENSOR_WhiteBalance
2572 case V4L2_CID_DO_WHITE_BALANCE:
2574 if (ctrl->value != sensor->info_priv.whiteBalance)
2576 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2580 sensor->info_priv.whiteBalance = ctrl->value;
2585 #if CONFIG_SENSOR_Mirror
2586 case V4L2_CID_HFLIP:
2588 if (ctrl->value != sensor->info_priv.mirror)
2590 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2592 sensor->info_priv.mirror = ctrl->value;
2597 #if CONFIG_SENSOR_Flip
2598 case V4L2_CID_VFLIP:
2600 if (ctrl->value != sensor->info_priv.flip)
2602 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2604 sensor->info_priv.flip = ctrl->value;
2615 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2617 const struct v4l2_queryctrl *qctrl;
2618 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2619 struct sensor *sensor = to_sensor(client);
2621 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2625 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2629 switch (ext_ctrl->id)
2631 case V4L2_CID_SCENE:
2633 ext_ctrl->value = sensor->info_priv.scene;
2636 case V4L2_CID_EFFECT:
2638 ext_ctrl->value = sensor->info_priv.effect;
2641 case V4L2_CID_ZOOM_ABSOLUTE:
2643 ext_ctrl->value = sensor->info_priv.digitalzoom;
2646 case V4L2_CID_ZOOM_RELATIVE:
2650 case V4L2_CID_FOCUS_ABSOLUTE:
2652 ext_ctrl->value = sensor->info_priv.focus;
2655 case V4L2_CID_FOCUS_RELATIVE:
2659 case V4L2_CID_FLASH:
2661 ext_ctrl->value = sensor->info_priv.flash;
2669 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2671 const struct v4l2_queryctrl *qctrl;
2672 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2673 struct sensor *sensor = to_sensor(client);
2676 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2680 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2685 switch (ext_ctrl->id)
2687 #if CONFIG_SENSOR_Scene
2688 case V4L2_CID_SCENE:
2690 if (ext_ctrl->value != sensor->info_priv.scene)
2692 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2694 sensor->info_priv.scene = ext_ctrl->value;
2699 #if CONFIG_SENSOR_Effect
2700 case V4L2_CID_EFFECT:
2702 if (ext_ctrl->value != sensor->info_priv.effect)
2704 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2706 sensor->info_priv.effect= ext_ctrl->value;
2711 #if CONFIG_SENSOR_DigitalZoom
2712 case V4L2_CID_ZOOM_ABSOLUTE:
2714 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2717 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2719 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2721 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2723 sensor->info_priv.digitalzoom += val_offset;
2725 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2730 case V4L2_CID_ZOOM_RELATIVE:
2732 if (ext_ctrl->value)
2734 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2736 sensor->info_priv.digitalzoom += ext_ctrl->value;
2738 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2743 #if CONFIG_SENSOR_Focus
2744 case V4L2_CID_FOCUS_ABSOLUTE:
2746 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2749 if (ext_ctrl->value != sensor->info_priv.focus)
2751 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2753 sensor->info_priv.focus += val_offset;
2758 case V4L2_CID_FOCUS_RELATIVE:
2760 if (ext_ctrl->value)
2762 sensor->info_priv.focus += ext_ctrl->value;
2764 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2769 #if CONFIG_SENSOR_Flash
2770 case V4L2_CID_FLASH:
2772 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2774 sensor->info_priv.flash = ext_ctrl->value;
2776 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2787 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2789 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2790 struct soc_camera_device *icd = client->dev.platform_data;
2791 int i, error_cnt=0, error_idx=-1;
2794 for (i=0; i<ext_ctrl->count; i++) {
2795 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2802 error_idx = ext_ctrl->count;
2804 if (error_idx != -1) {
2805 ext_ctrl->error_idx = error_idx;
2812 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2814 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2815 struct soc_camera_device *icd = client->dev.platform_data;
2816 int i, error_cnt=0, error_idx=-1;
2819 for (i=0; i<ext_ctrl->count; i++) {
2820 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2827 error_idx = ext_ctrl->count;
2829 if (error_idx != -1) {
2830 ext_ctrl->error_idx = error_idx;
2837 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2838 * this wasn't our capture interface, so, we wait for the right one */
2839 static int sensor_video_probe(struct soc_camera_device *icd,
2840 struct i2c_client *client)
2844 struct sensor *sensor = to_sensor(client);
2846 /* We must have a parent by now. And it cannot be a wrong one.
2847 * So this entire test is completely redundant. */
2848 if (!icd->dev.parent ||
2849 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2852 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2854 goto sensor_video_probe_err;
2858 ret = sensor_write(client, 0xff, 0x1);
2860 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2862 goto sensor_video_probe_err;
2864 mdelay(5); //delay 5 microseconds
2866 /* check if it is an sensor sensor */
2867 ret = sensor_read(client, 0x0a, &value);
2869 SENSOR_TR("read chip id high byte failed\n");
2871 goto sensor_video_probe_err;
2875 ret = sensor_read(client, 0x0b, &value);
2877 SENSOR_TR("read chip id low byte failed\n");
2879 goto sensor_video_probe_err;
2882 pid |= (value & 0xff);
2883 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2885 if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {
2886 sensor->model = SENSOR_V4L2_IDENT;
2888 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2890 goto sensor_video_probe_err;
2895 sensor_video_probe_err:
2900 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2902 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2903 struct soc_camera_device *icd = client->dev.platform_data;
2904 struct sensor *sensor = to_sensor(client);
2907 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2910 case RK29_CAM_SUBDEV_DEACTIVATE:
2912 sensor_deactivate(client);
2916 case RK29_CAM_SUBDEV_IOREQUEST:
2918 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
\r
2919 if (sensor->sensor_io_request != NULL) {
2920 sensor->sensor_gpio_res = NULL;
2921 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2922 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2923 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2924 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2927 if (sensor->sensor_gpio_res == NULL) {
2928 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2930 goto sensor_ioctl_end;
2933 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2935 goto sensor_ioctl_end;
2937 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2939 #if CONFIG_SENSOR_Flash
2940 if (sensor->sensor_gpio_res) {
2941 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2942 for (i = 0; i < icd->ops->num_controls; i++) {
2943 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2944 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2947 sensor->info_priv.flash = 0xff;
2948 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2956 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2965 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2966 enum v4l2_mbus_pixelcode *code)
2968 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2971 *code = sensor_colour_fmts[index].code;
2974 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2975 .init = sensor_init,
2976 .g_ctrl = sensor_g_control,
2977 .s_ctrl = sensor_s_control,
2978 .g_ext_ctrls = sensor_g_ext_controls,
2979 .s_ext_ctrls = sensor_s_ext_controls,
2980 .g_chip_ident = sensor_g_chip_ident,
2981 .ioctl = sensor_ioctl,
2984 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2985 .s_mbus_fmt = sensor_s_fmt,
2986 .g_mbus_fmt = sensor_g_fmt,
2987 .try_mbus_fmt = sensor_try_fmt,
2988 .enum_mbus_fmt = sensor_enum_fmt,
2991 static struct v4l2_subdev_ops sensor_subdev_ops = {
2992 .core = &sensor_subdev_core_ops,
2993 .video = &sensor_subdev_video_ops,
2996 static int sensor_probe(struct i2c_client *client,
2997 const struct i2c_device_id *did)
2999 struct sensor *sensor;
3000 struct soc_camera_device *icd = client->dev.platform_data;
3001 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3002 struct soc_camera_link *icl;
3005 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3007 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3011 icl = to_soc_camera_link(icd);
3013 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3017 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3018 dev_warn(&adapter->dev,
3019 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3023 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3027 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3029 /* Second stage probe - when a capture adapter is there */
3030 icd->ops = &sensor_ops;
3031 sensor->info_priv.fmt = sensor_colour_fmts[0];
3032 #if CONFIG_SENSOR_I2C_NOSCHED
3033 atomic_set(&sensor->tasklock_cnt,0);
3036 ret = sensor_video_probe(icd, client);
3039 i2c_set_clientdata(client, NULL);
3043 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3047 static int sensor_remove(struct i2c_client *client)
3049 struct sensor *sensor = to_sensor(client);
3050 struct soc_camera_device *icd = client->dev.platform_data;
3053 i2c_set_clientdata(client, NULL);
3054 client->driver = NULL;
3060 static const struct i2c_device_id sensor_id[] = {
3061 {SENSOR_NAME_STRING(), 0 },
3064 MODULE_DEVICE_TABLE(i2c, sensor_id);
3066 static struct i2c_driver sensor_i2c_driver = {
3068 .name = SENSOR_NAME_STRING(),
3070 .probe = sensor_probe,
3071 .remove = sensor_remove,
3072 .id_table = sensor_id,
3075 static int __init sensor_mod_init(void)
3077 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3078 return i2c_add_driver(&sensor_i2c_driver);
3081 static void __exit sensor_mod_exit(void)
3083 i2c_del_driver(&sensor_i2c_driver);
3086 device_initcall_sync(sensor_mod_init);
3087 module_exit(sensor_mod_exit);
3089 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3090 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3091 MODULE_LICENSE("GPL");
\r