2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
23 #include <linux/vmalloc.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_OV2655
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2655
48 #define SENSOR_ID 0x2656
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
51 #define SENSOR_MAX_WIDTH 1600
52 #define SENSOR_MAX_HEIGHT 1200
53 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT sensor_init_height
55 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
56 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
57 #define SENSOR_BUS_PARAM sensor_init_busparam
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 1
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 1
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 350000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
78 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
79 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
80 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
81 #define COLOR_TEMPERATURE_OFFICE_DN 3500
82 #define COLOR_TEMPERATURE_OFFICE_UP 5000
83 #define COLOR_TEMPERATURE_HOME_DN 2500
84 #define COLOR_TEMPERATURE_HOME_UP 3500
86 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
87 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
89 #define SENSOR_AF_IS_ERR (0x00<<0)
90 #define SENSOR_AF_IS_OK (0x01<<0)
91 #define SENSOR_INIT_IS_ERR (0x00<<28)
92 #define SENSOR_INIT_IS_OK (0x01<<28)
100 //flash off in fixed time to prevent from too hot , zyc
102 struct soc_camera_device *icd;
103 struct hrtimer timer;
105 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
107 static struct flash_timer flash_off_timer;
108 //for user defined if user want to customize the series , zyc
109 #ifdef CONFIG_OV2655_USER_DEFINED_SERIES
110 #include "ov2655_user_series.c"
113 /* init 352X288 SVGA */
114 static struct reginfo sensor_init_data[] =
128 {0x3090, 0x33},//0x3b},
205 {0x3088, 0x02},//{0x3088, 0x01},
206 {0x3089, 0x88},//{0x3089, 0x68},
207 {0x308A, 0x01},//{0x308a, 0x01},
208 {0x308B, 0xe0},//{0x308b, 0x20},
215 {0x331A, 0x28},//{0x331a, 0x16},
216 {0x331B, 0x1e},//{0x331b, 0x12},
279 {0x3350, 0x37},//0x33},
280 {0x3351, 0x27},//0x28},
291 {0x335c, 0x37},//0x34},
320 {0x307c, 0x10},//0x13},
338 {0x0, 0x0} //end flag
341 static struct reginfo sensor_720p[]=
343 {0x0, 0x0} //end flag
346 static struct reginfo sensor_uxga[] =
388 static struct reginfo sensor_sxga[] =
391 // {0x3086,0x01}, //sleep on
426 // {0x3086,0x00}, //sleep off
430 static struct reginfo sensor_xga[] =
435 static struct reginfo sensor_svga[] =
437 // {0x3086,0x01}, //sleep on
472 // {0x3086,0x00}, //sleep off
477 static struct reginfo sensor_vga[] =
479 // {0x3086,0x00}, //sleep off
514 // {0x3086,0x01}, //sleep on
519 static struct reginfo sensor_cif[] =
559 static struct reginfo sensor_qvga[] =
600 static struct reginfo sensor_qcif[] =
641 static struct reginfo ov2655_qqvga[] =
685 static struct reginfo ov2655_Sharpness_auto[] =
690 static struct reginfo ov2655_Sharpness1[] =
696 static struct reginfo ov2655_Sharpness2[][3] =
703 static struct reginfo ov2655_Sharpness3[] =
709 static struct reginfo ov2655_Sharpness4[]=
716 static struct reginfo ov2655_Sharpness5[] =
724 static struct reginfo sensor_ClrFmt_YUYV[]=
730 static struct reginfo sensor_ClrFmt_UYVY[]=
736 #if CONFIG_SENSOR_WhiteBalance
737 static struct reginfo sensor_WhiteB_Auto[]=
739 {0x3306, 0x00}, //AWB auto, bit[1]:0,auto
742 /* Cloudy Colour Temperature : 6500K - 8000K */
743 static struct reginfo sensor_WhiteB_Cloudy[]=
751 /* ClearDay Colour Temperature : 5000K - 6500K */
752 static struct reginfo sensor_WhiteB_ClearDay[]=
755 {0x3306, 0x02}, //AWB off
761 /* Office Colour Temperature : 3500K - 5000K */
762 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
772 /* Home Colour Temperature : 2500K - 3500K */
773 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
782 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
783 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
787 #if CONFIG_SENSOR_Brightness
788 static struct reginfo sensor_Brightness0[]=
791 {0x3301, 0xff},//bit[7]:1, enable SDE
798 static struct reginfo sensor_Brightness1[]=
801 {0x3301, 0xff},//bit[7]:1, enable SDE
808 static struct reginfo sensor_Brightness2[]=
811 {0x3301, 0xff},//bit[7]:1, enable SDE
818 static struct reginfo sensor_Brightness3[]=
821 {0x3301, 0xff},//bit[7]:1, enable SDE
828 static struct reginfo sensor_Brightness4[]=
831 {0x3301, 0xff},//bit[7]:1, enable SDE
838 static struct reginfo sensor_Brightness5[]=
841 {0x3301, 0xff},//bit[7]:1, enable SDE
842 {0x3391, 0x04}, //bit[2] enable
843 {0x3390, 0x41}, //bit[3] sign of brightness
847 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
848 sensor_Brightness4, sensor_Brightness5,NULL,
853 #if CONFIG_SENSOR_Effect
854 static struct reginfo sensor_Effect_Normal[] =
860 static struct reginfo sensor_Effect_WandB[] =
866 static struct reginfo sensor_Effect_Sepia[] =
874 static struct reginfo sensor_Effect_Negative[] =
877 {0x3391, 0x40}, //bit[6] negative
880 static struct reginfo sensor_Effect_Bluish[] =
889 static struct reginfo sensor_Effect_Green[] =
897 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
898 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
901 #if CONFIG_SENSOR_Exposure
902 static struct reginfo sensor_Exposure0[]=
912 static struct reginfo sensor_Exposure1[]=
922 static struct reginfo sensor_Exposure2[]=
932 static struct reginfo sensor_Exposure3[]=
942 static struct reginfo sensor_Exposure4[]=
952 static struct reginfo sensor_Exposure5[]=
962 static struct reginfo sensor_Exposure6[]=
972 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
973 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
976 #if CONFIG_SENSOR_Saturation
977 static struct reginfo sensor_Saturation0[]=
979 {0x3301, 0xff},//bit[7]:1, enable SDE
986 static struct reginfo sensor_Saturation1[]=
988 {0x3301, 0xff},//bit[7]:1, enable SDE
995 static struct reginfo sensor_Saturation2[]=
997 {0x3301, 0xff},//bit[7]:1, enable SDE
998 {0x3391, 0x02}, //enable color saturation
1003 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1006 #if CONFIG_SENSOR_Contrast
1007 static struct reginfo sensor_Contrast0[]=
1010 {0x3301, 0xff},//bit[7]:1, enable SDE
1018 static struct reginfo sensor_Contrast1[]=
1021 {0x3301, 0xff},//bit[7]:1, enable SDE
1029 static struct reginfo sensor_Contrast2[]=
1032 {0x3301, 0xff},//bit[7]:1, enable SDE
1040 static struct reginfo sensor_Contrast3[]=
1043 {0x3301, 0xff},//bit[7]:1, enable SDE
1051 static struct reginfo sensor_Contrast4[]=
1054 {0x3301, 0xff},//bit[7]:1, enable SDE
1063 static struct reginfo sensor_Contrast5[]=
1066 {0x3301, 0xff},//bit[7]:1, enable SDE
1074 static struct reginfo sensor_Contrast6[]=
1077 {0x3301, 0xff},//bit[7]:1, enable SDE
1078 {0x3391, 0x04}, //bit[2] enable contrast/brightness
1079 {0x3390, 0x45}, //bit[2] Yoffset sign
1084 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1085 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1089 #if CONFIG_SENSOR_Mirror
1090 static struct reginfo sensor_MirrorOn[]=
1098 static struct reginfo sensor_MirrorOff[]=
1105 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1107 #if CONFIG_SENSOR_Flip
1108 static struct reginfo sensor_FlipOn[]=
1121 static struct reginfo sensor_FlipOff[]=
1133 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1136 #if CONFIG_SENSOR_Scene
1137 static struct reginfo sensor_SceneAuto[] =
1139 #if 0 /* ddl@rock-chips.com : */
1154 static struct reginfo sensor_SceneNight[] =
1157 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1168 {0x3015, 0x50},//add 5 dummy frame
1173 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1188 // the fixed fps, RK30 CIF can't receive data correctly when taking pic frequently in scene night mode of
1189 // auto fps . Now use this series temporarily until fix the cif bug,zyc
1201 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1204 #if CONFIG_SENSOR_DigitalZoom
1205 static struct reginfo sensor_Zoom0[] =
1210 static struct reginfo sensor_Zoom1[] =
1215 static struct reginfo sensor_Zoom2[] =
1221 static struct reginfo sensor_Zoom3[] =
1225 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1227 static struct v4l2_querymenu sensor_menus[] =
1229 #if CONFIG_SENSOR_WhiteBalance
1230 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1231 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1232 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1235 #if CONFIG_SENSOR_Effect
1236 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1237 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1238 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1241 #if CONFIG_SENSOR_Scene
1242 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1245 #if CONFIG_SENSOR_Flash
1246 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1247 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1251 static struct v4l2_queryctrl sensor_controls[] =
1253 #if CONFIG_SENSOR_WhiteBalance
1255 .id = V4L2_CID_DO_WHITE_BALANCE,
1256 .type = V4L2_CTRL_TYPE_MENU,
1257 .name = "White Balance Control",
1265 #if CONFIG_SENSOR_Brightness
1267 .id = V4L2_CID_BRIGHTNESS,
1268 .type = V4L2_CTRL_TYPE_INTEGER,
1269 .name = "Brightness Control",
1277 #if CONFIG_SENSOR_Effect
1279 .id = V4L2_CID_EFFECT,
1280 .type = V4L2_CTRL_TYPE_MENU,
1281 .name = "Effect Control",
1289 #if CONFIG_SENSOR_Exposure
1291 .id = V4L2_CID_EXPOSURE,
1292 .type = V4L2_CTRL_TYPE_INTEGER,
1293 .name = "Exposure Control",
1301 #if CONFIG_SENSOR_Saturation
1303 .id = V4L2_CID_SATURATION,
1304 .type = V4L2_CTRL_TYPE_INTEGER,
1305 .name = "Saturation Control",
1313 #if CONFIG_SENSOR_Contrast
1315 .id = V4L2_CID_CONTRAST,
1316 .type = V4L2_CTRL_TYPE_INTEGER,
1317 .name = "Contrast Control",
1325 #if CONFIG_SENSOR_Mirror
1327 .id = V4L2_CID_HFLIP,
1328 .type = V4L2_CTRL_TYPE_BOOLEAN,
1329 .name = "Mirror Control",
1337 #if CONFIG_SENSOR_Flip
1339 .id = V4L2_CID_VFLIP,
1340 .type = V4L2_CTRL_TYPE_BOOLEAN,
1341 .name = "Flip Control",
1349 #if CONFIG_SENSOR_Scene
1351 .id = V4L2_CID_SCENE,
1352 .type = V4L2_CTRL_TYPE_MENU,
1353 .name = "Scene Control",
1361 #if CONFIG_SENSOR_DigitalZoom
1363 .id = V4L2_CID_ZOOM_RELATIVE,
1364 .type = V4L2_CTRL_TYPE_INTEGER,
1365 .name = "DigitalZoom Control",
1371 .id = V4L2_CID_ZOOM_ABSOLUTE,
1372 .type = V4L2_CTRL_TYPE_INTEGER,
1373 .name = "DigitalZoom Control",
1381 #if CONFIG_SENSOR_Focus
1383 .id = V4L2_CID_FOCUS_RELATIVE,
1384 .type = V4L2_CTRL_TYPE_INTEGER,
1385 .name = "Focus Control",
1391 .id = V4L2_CID_FOCUS_ABSOLUTE,
1392 .type = V4L2_CTRL_TYPE_INTEGER,
1393 .name = "Focus Control",
1397 .default_value = 125,
1401 #if CONFIG_SENSOR_Flash
1403 .id = V4L2_CID_FLASH,
1404 .type = V4L2_CTRL_TYPE_MENU,
1405 .name = "Flash Control",
1414 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1415 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1416 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1417 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1418 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1419 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1420 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1421 static int sensor_resume(struct soc_camera_device *icd);
1422 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1423 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1424 #if CONFIG_SENSOR_Effect
1425 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1427 #if CONFIG_SENSOR_WhiteBalance
1428 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1430 static int sensor_deactivate(struct i2c_client *client);
1432 static struct soc_camera_ops sensor_ops =
1434 .suspend = sensor_suspend,
1435 .resume = sensor_resume,
1436 .set_bus_param = sensor_set_bus_param,
1437 .query_bus_param = sensor_query_bus_param,
1438 .controls = sensor_controls,
1439 .menus = sensor_menus,
1440 .num_controls = ARRAY_SIZE(sensor_controls),
1441 .num_menus = ARRAY_SIZE(sensor_menus),
1443 /* only one fixed colorspace per pixelcode */
1444 struct sensor_datafmt {
1445 enum v4l2_mbus_pixelcode code;
1446 enum v4l2_colorspace colorspace;
1449 /* Find a data format by a pixel code in an array */
1450 static const struct sensor_datafmt *sensor_find_datafmt(
1451 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1455 for (i = 0; i < n; i++)
1456 if (fmt[i].code == code)
1462 static const struct sensor_datafmt sensor_colour_fmts[] = {
1463 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1464 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1467 typedef struct sensor_info_priv_s
1481 unsigned char mirror; /* HFLIP */
1482 unsigned char flip; /* VFLIP */
1483 unsigned int winseqe_cur_addr;
1484 struct sensor_datafmt fmt;
1485 unsigned int funmodule_state;
1486 } sensor_info_priv_t;
1490 struct v4l2_subdev subdev;
1491 struct i2c_client *client;
1492 sensor_info_priv_t info_priv;
1493 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1494 #if CONFIG_SENSOR_I2C_NOSCHED
1495 atomic_t tasklock_cnt;
1497 struct rk29camera_platform_data *sensor_io_request;
1498 struct rk29camera_gpio_res *sensor_gpio_res;
1501 static struct sensor* to_sensor(const struct i2c_client *client)
1503 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1506 static int sensor_task_lock(struct i2c_client *client, int lock)
1508 #if CONFIG_SENSOR_I2C_NOSCHED
1510 struct sensor *sensor = to_sensor(client);
1513 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1514 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1515 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1519 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1520 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1521 goto sensor_task_lock_err;
1526 atomic_add(1, &sensor->tasklock_cnt);
1528 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1529 atomic_sub(1, &sensor->tasklock_cnt);
1531 if (atomic_read(&sensor->tasklock_cnt) == 0)
1536 sensor_task_lock_err:
1544 /* sensor register write */
1545 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1549 struct i2c_msg msg[1];
1552 buf[1] = reg & 0xFF;
1555 msg->addr = client->addr;
1556 msg->flags = client->flags;
1558 msg->len = sizeof(buf);
1559 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1560 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1565 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1566 err = i2c_transfer(client->adapter, msg, 1);
1571 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1579 /* sensor register read */
1580 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1584 struct i2c_msg msg[2];
1587 buf[1] = reg & 0xFF;
1589 msg[0].addr = client->addr;
1590 msg[0].flags = client->flags;
1592 msg[0].len = sizeof(buf);
1593 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1594 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1596 msg[1].addr = client->addr;
1597 msg[1].flags = client->flags|I2C_M_RD;
1600 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1601 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1605 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1606 err = i2c_transfer(client->adapter, msg, 2);
1612 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1620 /* write a array of registers */
1621 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1625 #if CONFIG_SENSOR_I2C_RDWRCHK
1630 if (sensor_task_lock(client, 1) < 0)
1631 goto sensor_write_array_end;
1632 while (regarray[i].reg != 0)
1634 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1638 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1642 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1644 goto sensor_write_array_end;
1647 #if CONFIG_SENSOR_I2C_RDWRCHK
1648 sensor_read(client, regarray[i].reg, &valchk);
1649 if (valchk != regarray[i].val)
1650 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1656 sensor_write_array_end:
1657 sensor_task_lock(client,0);
1660 #if CONFIG_SENSOR_I2C_RDWRCHK
1661 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1669 while (regarray[i].reg != 0)
1671 sensor_read(client, regarray[i].reg, &valchk);
1672 if (valchk != regarray[i].val)
1673 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1681 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1683 struct soc_camera_link *icl = to_soc_camera_link(icd);
1686 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1690 case Sensor_PowerDown:
1692 if (icl->powerdown) {
1693 ret = icl->powerdown(icd->pdev, on);
1694 if (ret == RK29_CAM_IO_SUCCESS) {
1698 icl->reset(icd->pdev);
1700 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1702 goto sensor_power_end;
1709 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1710 struct sensor *sensor = to_sensor(client);
1712 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1713 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1715 //flash off after 2 secs
1716 hrtimer_cancel(&(flash_off_timer.timer));
1717 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1724 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1732 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1733 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1734 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1735 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1740 static s32 sensor_init_width = 640;
1741 static s32 sensor_init_height = 480;
1742 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);
1743 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1744 static struct reginfo* sensor_init_data_p = sensor_init_data;
1745 static struct reginfo* sensor_init_winseq_p = sensor_vga;
1746 static struct reginfo* sensor_init_winseq_board = NULL;
1747 static struct reginfo* sensor_init_data_board = NULL;
1748 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1750 struct i2c_client *client = v4l2_get_subdevdata(sd);
1751 struct soc_camera_device *icd = client->dev.platform_data;
1752 struct sensor *sensor = to_sensor(client);
1753 const struct v4l2_queryctrl *qctrl;
1754 const struct sensor_datafmt *fmt;
1756 int ret,pid = 0,i = 0,j=0,tmp_winseq_size;
1757 struct rk29camera_platform_data* tmp_plat_data =sensor->sensor_io_request;
1759 sensor_init_data_p = sensor_init_data;
1760 sensor_init_winseq_p = sensor_vga;
1761 sensor_init_width = 640;
1762 sensor_init_height = 480;
1764 if (tmp_plat_data != NULL) {
1765 for(i = 0;i < RK_CAM_NUM;i++){
1766 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1767 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0)) {
1773 if(tmp_plat_data &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1774 //user has defined the init data
1776 int tmp_init_data_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data_size;
1777 if(tmp_init_data_size > 2){//init data is valid
1778 if((sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1779 if(sensor_init_data_board) {
1780 vfree(sensor_init_data_board);
1781 sensor_init_data_board = NULL;
1783 sensor_init_data_board = (struct reginfo*)vmalloc(tmp_init_data_size);
1784 if(!sensor_init_data_board)
1785 SENSOR_TR("%s :vmalloc init data erro !",__FUNCTION__);
1786 for(j = 0;j< tmp_init_data_size;j++) {
1787 sensor_init_data_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1788 sensor_init_data_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1790 sensor_init_data_p = sensor_init_data_board;
1792 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1796 tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1797 if(tmp_winseq_size > 2){
1798 if(sizeof(struct reginfo) != sizeof(struct reginfo_t)){
1799 if(sensor_init_winseq_board) {
1800 vfree(sensor_init_winseq_board);
1801 sensor_init_winseq_board = NULL;
1803 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1804 if(!sensor_init_winseq_board)
1805 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1806 for(j = 0;j< tmp_winseq_size;j++){
1807 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1808 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1810 sensor_init_winseq_p = sensor_init_winseq_board;
1812 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1815 //init width,height,bus,pixelcode
1816 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1817 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1818 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1819 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1820 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1821 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1822 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1823 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1825 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1827 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1829 goto sensor_INIT_ERR;
1833 if (sensor_task_lock(client,1)<0)
1834 goto sensor_INIT_ERR;
1835 sensor_write(client, 0x300F, 0xAE);
1837 sensor_write(client, 0x300F, 0xAE);
1839 ret = sensor_write(client, 0x3012, 0x80);
1842 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1844 goto sensor_INIT_ERR;
1847 mdelay(5); //delay 5 microseconds
1848 /* check if it is an sensor sensor */
1849 ret = sensor_read(client, 0x300a, &value);
1851 SENSOR_TR("read chip id high byte failed\n");
1853 goto sensor_INIT_ERR;
1856 pid |= (value << 8);
1858 ret = sensor_read(client, 0x300b, &value);
1860 SENSOR_TR("read chip id low byte failed\n");
1862 goto sensor_INIT_ERR;
1865 pid |= (value & 0xff);
1866 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1867 if (pid == SENSOR_ID) {
1868 sensor->model = SENSOR_V4L2_IDENT;
1870 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1872 goto sensor_INIT_ERR;
1875 ret = sensor_write_array(client, sensor_init_data_p);
1878 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1879 goto sensor_INIT_ERR;
1881 sensor_task_lock(client,0);
1882 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1883 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1885 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1887 goto sensor_INIT_ERR;
1889 sensor->info_priv.fmt = *fmt;
1891 /* sensor sensor information for initialization */
1892 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1894 sensor->info_priv.whiteBalance = qctrl->default_value;
1895 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1897 sensor->info_priv.brightness = qctrl->default_value;
1898 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1900 sensor->info_priv.effect = qctrl->default_value;
1901 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1903 sensor->info_priv.exposure = qctrl->default_value;
1905 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1907 sensor->info_priv.saturation = qctrl->default_value;
1908 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1910 sensor->info_priv.contrast = qctrl->default_value;
1911 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1913 sensor->info_priv.mirror = qctrl->default_value;
1914 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1916 sensor->info_priv.flip = qctrl->default_value;
1917 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1919 sensor->info_priv.scene = qctrl->default_value;
1920 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1922 sensor->info_priv.digitalzoom = qctrl->default_value;
1924 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1925 #if CONFIG_SENSOR_Focus
1927 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1929 sensor->info_priv.focus = qctrl->default_value;
1932 #if CONFIG_SENSOR_Flash
1933 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1935 sensor->info_priv.flash = qctrl->default_value;
1937 flash_off_timer.icd = icd;
1938 flash_off_timer.timer.function = flash_off_func;
1941 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);
1942 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1945 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1946 sensor_task_lock(client,0);
1947 sensor_deactivate(client);
1951 static int sensor_deactivate(struct i2c_client *client)
1953 struct soc_camera_device *icd = client->dev.platform_data;
1954 struct sensor *sensor = to_sensor(client);
1955 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1957 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1958 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
1959 sensor_task_lock(client, 1);
1960 sensor_write(client, 0x30b0, 0x00);
1961 sensor_write(client, 0x30b1, 0x00);
1962 sensor_task_lock(client, 0);
1964 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1966 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1967 icd->user_width = SENSOR_INIT_WIDTH;
1968 icd->user_height = SENSOR_INIT_HEIGHT;
1969 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1974 static struct reginfo sensor_power_down_sequence[]=
1982 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1985 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1987 if (pm_msg.event == PM_EVENT_SUSPEND) {
1988 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1989 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1991 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1994 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1996 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2001 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2007 static int sensor_resume(struct soc_camera_device *icd)
2011 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2013 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2017 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2023 static int sensor_set_bus_param(struct soc_camera_device *icd,
2024 unsigned long flags)
2030 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2032 struct soc_camera_link *icl = to_soc_camera_link(icd);
2033 unsigned long flags = SENSOR_BUS_PARAM;
2035 return soc_camera_apply_sensor_flags(icl, flags);
2038 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2040 struct i2c_client *client = v4l2_get_subdevdata(sd);
2041 struct soc_camera_device *icd = client->dev.platform_data;
2042 struct sensor *sensor = to_sensor(client);
2044 mf->width = icd->user_width;
2045 mf->height = icd->user_height;
2046 mf->code = sensor->info_priv.fmt.code;
2047 mf->colorspace = sensor->info_priv.fmt.colorspace;
2048 mf->field = V4L2_FIELD_NONE;
2052 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2056 if ((mf->width == 1024) && (mf->height == 768)) {
2058 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2060 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2062 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2064 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2069 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2073 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2077 if ((mf->width == 1280) && (mf->height == 720)) {
2079 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2084 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2087 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2089 struct i2c_client *client = v4l2_get_subdevdata(sd);
2090 const struct sensor_datafmt *fmt;
2091 struct sensor *sensor = to_sensor(client);
2092 const struct v4l2_queryctrl *qctrl;
2093 struct soc_camera_device *icd = client->dev.platform_data;
2094 struct reginfo *winseqe_set_addr=NULL;
2095 int ret=0, set_w,set_h;
2097 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2098 ARRAY_SIZE(sensor_colour_fmts));
2101 goto sensor_s_fmt_end;
2104 if (sensor->info_priv.fmt.code != mf->code) {
2107 case V4L2_MBUS_FMT_YUYV8_2X8:
2109 winseqe_set_addr = sensor_ClrFmt_YUYV;
2112 case V4L2_MBUS_FMT_UYVY8_2X8:
2114 winseqe_set_addr = sensor_ClrFmt_UYVY;
2120 if (winseqe_set_addr != NULL) {
2121 sensor_write_array(client, winseqe_set_addr);
2122 sensor->info_priv.fmt.code = mf->code;
2123 sensor->info_priv.fmt.colorspace= mf->colorspace;
2124 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2126 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2133 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2135 winseqe_set_addr = sensor_qcif;
2139 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2141 winseqe_set_addr = sensor_qvga;
2145 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2147 winseqe_set_addr = sensor_cif;
2151 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2153 winseqe_set_addr = sensor_vga;
2157 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2159 winseqe_set_addr = sensor_svga;
2163 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
2165 winseqe_set_addr = sensor_720p;
2169 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
2171 winseqe_set_addr = sensor_xga;
2175 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2177 winseqe_set_addr = sensor_sxga;
2181 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2183 winseqe_set_addr = sensor_uxga;
2189 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2190 set_w = SENSOR_INIT_WIDTH;
2191 set_h = SENSOR_INIT_HEIGHT;
2192 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2195 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2196 #if CONFIG_SENSOR_Flash
2197 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2198 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2199 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2200 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2202 } else { /* ddl@rock-chips.com : Video */
2203 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2204 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2205 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2209 ret |= sensor_write_array(client, winseqe_set_addr);
2211 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2212 #if CONFIG_SENSOR_Flash
2213 if (sensor_fmt_capturechk(sd,mf) == true) {
2214 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2215 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2216 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2220 goto sensor_s_fmt_end;
2223 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2225 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2226 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2227 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2228 if (sensor->info_priv.whiteBalance != 0) {
2229 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2230 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2232 sensor->info_priv.snap2preview = true;
2233 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2234 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2235 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2236 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2237 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2238 sensor->info_priv.video2preview = true;
2239 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2240 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2241 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2242 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2243 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2245 sensor->info_priv.video2preview = false;
2246 sensor->info_priv.snap2preview = false;
2248 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2252 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2262 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2264 struct i2c_client *client = v4l2_get_subdevdata(sd);
2265 struct sensor *sensor = to_sensor(client);
2266 const struct sensor_datafmt *fmt;
2267 int ret = 0,set_w,set_h;
2269 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2270 ARRAY_SIZE(sensor_colour_fmts));
2272 fmt = &sensor->info_priv.fmt;
2273 mf->code = fmt->code;
2276 if (mf->height > SENSOR_MAX_HEIGHT)
2277 mf->height = SENSOR_MAX_HEIGHT;
2278 else if (mf->height < SENSOR_MIN_HEIGHT)
2279 mf->height = SENSOR_MIN_HEIGHT;
2281 if (mf->width > SENSOR_MAX_WIDTH)
2282 mf->width = SENSOR_MAX_WIDTH;
2283 else if (mf->width < SENSOR_MIN_WIDTH)
2284 mf->width = SENSOR_MIN_WIDTH;
2289 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2294 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2299 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2304 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2309 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2314 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
2319 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
2324 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2329 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2335 { /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2336 set_w = SENSOR_INIT_WIDTH;
2337 set_h = SENSOR_INIT_HEIGHT;
2342 mf->colorspace = fmt->colorspace;
2346 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2348 struct i2c_client *client = v4l2_get_subdevdata(sd);
2350 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2353 if (id->match.addr != client->addr)
2356 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2361 #if CONFIG_SENSOR_Brightness
2362 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2364 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2366 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2368 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2370 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2372 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2375 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2379 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2383 #if CONFIG_SENSOR_Effect
2384 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2386 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2388 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2390 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2392 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2394 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2397 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2401 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2405 #if CONFIG_SENSOR_Exposure
2406 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2408 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2410 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2412 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2414 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2416 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2419 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2423 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2427 #if CONFIG_SENSOR_Saturation
2428 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2430 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2432 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2434 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2436 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2438 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2441 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2445 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2449 #if CONFIG_SENSOR_Contrast
2450 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2452 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2454 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2456 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2458 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2460 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2463 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2467 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2471 #if CONFIG_SENSOR_Mirror
2472 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2474 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2476 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2478 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2480 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2482 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2485 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2489 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2493 #if CONFIG_SENSOR_Flip
2494 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2496 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2498 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2500 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2502 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2504 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2507 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2511 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2515 #if CONFIG_SENSOR_Scene
2516 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2518 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2520 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2522 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2524 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2526 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2529 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2533 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2537 #if CONFIG_SENSOR_WhiteBalance
2538 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2540 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2542 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2544 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2546 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2548 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2551 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2555 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2559 #if CONFIG_SENSOR_DigitalZoom
2560 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2562 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2563 struct sensor *sensor = to_sensor(client);
2564 const struct v4l2_queryctrl *qctrl_info;
2565 int digitalzoom_cur, digitalzoom_total;
2567 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2571 digitalzoom_cur = sensor->info_priv.digitalzoom;
2572 digitalzoom_total = qctrl_info->maximum;
2574 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2576 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2580 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2582 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2586 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2588 value = digitalzoom_total - digitalzoom_cur;
2591 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2593 value = 0 - digitalzoom_cur;
2596 digitalzoom_cur += value;
2598 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2600 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2602 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2605 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2612 #if CONFIG_SENSOR_Flash
2613 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2615 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2616 if (value == 3) { /* ddl@rock-chips.com: torch */
2617 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2619 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2621 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2625 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2630 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2632 struct i2c_client *client = v4l2_get_subdevdata(sd);
2633 struct sensor *sensor = to_sensor(client);
2634 const struct v4l2_queryctrl *qctrl;
2636 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2640 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2646 case V4L2_CID_BRIGHTNESS:
2648 ctrl->value = sensor->info_priv.brightness;
2651 case V4L2_CID_SATURATION:
2653 ctrl->value = sensor->info_priv.saturation;
2656 case V4L2_CID_CONTRAST:
2658 ctrl->value = sensor->info_priv.contrast;
2661 case V4L2_CID_DO_WHITE_BALANCE:
2663 ctrl->value = sensor->info_priv.whiteBalance;
2666 case V4L2_CID_EXPOSURE:
2668 ctrl->value = sensor->info_priv.exposure;
2671 case V4L2_CID_HFLIP:
2673 ctrl->value = sensor->info_priv.mirror;
2676 case V4L2_CID_VFLIP:
2678 ctrl->value = sensor->info_priv.flip;
2689 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2691 struct i2c_client *client = v4l2_get_subdevdata(sd);
2692 struct sensor *sensor = to_sensor(client);
2693 struct soc_camera_device *icd = client->dev.platform_data;
2694 const struct v4l2_queryctrl *qctrl;
2697 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2701 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2707 #if CONFIG_SENSOR_Brightness
2708 case V4L2_CID_BRIGHTNESS:
2710 if (ctrl->value != sensor->info_priv.brightness)
2712 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2716 sensor->info_priv.brightness = ctrl->value;
2721 #if CONFIG_SENSOR_Exposure
2722 case V4L2_CID_EXPOSURE:
2724 if (ctrl->value != sensor->info_priv.exposure)
2726 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2730 sensor->info_priv.exposure = ctrl->value;
2735 #if CONFIG_SENSOR_Saturation
2736 case V4L2_CID_SATURATION:
2738 if (ctrl->value != sensor->info_priv.saturation)
2740 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2744 sensor->info_priv.saturation = ctrl->value;
2749 #if CONFIG_SENSOR_Contrast
2750 case V4L2_CID_CONTRAST:
2752 if (ctrl->value != sensor->info_priv.contrast)
2754 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2758 sensor->info_priv.contrast = ctrl->value;
2763 #if CONFIG_SENSOR_WhiteBalance
2764 case V4L2_CID_DO_WHITE_BALANCE:
2766 if (ctrl->value != sensor->info_priv.whiteBalance)
2768 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2772 sensor->info_priv.whiteBalance = ctrl->value;
2777 #if CONFIG_SENSOR_Mirror
2778 case V4L2_CID_HFLIP:
2780 if (ctrl->value != sensor->info_priv.mirror)
2782 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2784 sensor->info_priv.mirror = ctrl->value;
2789 #if CONFIG_SENSOR_Flip
2790 case V4L2_CID_VFLIP:
2792 if (ctrl->value != sensor->info_priv.flip)
2794 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2796 sensor->info_priv.flip = ctrl->value;
2807 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2809 const struct v4l2_queryctrl *qctrl;
2810 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2811 struct sensor *sensor = to_sensor(client);
2813 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2817 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2821 switch (ext_ctrl->id)
2823 case V4L2_CID_SCENE:
2825 ext_ctrl->value = sensor->info_priv.scene;
2828 case V4L2_CID_EFFECT:
2830 ext_ctrl->value = sensor->info_priv.effect;
2833 case V4L2_CID_ZOOM_ABSOLUTE:
2835 ext_ctrl->value = sensor->info_priv.digitalzoom;
2838 case V4L2_CID_ZOOM_RELATIVE:
2842 case V4L2_CID_FOCUS_ABSOLUTE:
2844 ext_ctrl->value = sensor->info_priv.focus;
2847 case V4L2_CID_FOCUS_RELATIVE:
2851 case V4L2_CID_FLASH:
2853 ext_ctrl->value = sensor->info_priv.flash;
2861 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2863 const struct v4l2_queryctrl *qctrl;
2864 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2865 struct sensor *sensor = to_sensor(client);
2868 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2872 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2877 switch (ext_ctrl->id)
2879 #if CONFIG_SENSOR_Scene
2880 case V4L2_CID_SCENE:
2882 if (ext_ctrl->value != sensor->info_priv.scene)
2884 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2886 sensor->info_priv.scene = ext_ctrl->value;
2891 #if CONFIG_SENSOR_Effect
2892 case V4L2_CID_EFFECT:
2894 if (ext_ctrl->value != sensor->info_priv.effect)
2896 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2898 sensor->info_priv.effect= ext_ctrl->value;
2903 #if CONFIG_SENSOR_DigitalZoom
2904 case V4L2_CID_ZOOM_ABSOLUTE:
2906 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2909 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2911 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2913 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2915 sensor->info_priv.digitalzoom += val_offset;
2917 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2922 case V4L2_CID_ZOOM_RELATIVE:
2924 if (ext_ctrl->value)
2926 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2928 sensor->info_priv.digitalzoom += ext_ctrl->value;
2930 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2935 #if CONFIG_SENSOR_Focus
2936 case V4L2_CID_FOCUS_ABSOLUTE:
2938 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2941 if (ext_ctrl->value != sensor->info_priv.focus)
2943 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2945 sensor->info_priv.focus += val_offset;
2950 case V4L2_CID_FOCUS_RELATIVE:
2952 if (ext_ctrl->value)
2954 sensor->info_priv.focus += ext_ctrl->value;
2956 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2961 #if CONFIG_SENSOR_Flash
2962 case V4L2_CID_FLASH:
2964 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2966 sensor->info_priv.flash = ext_ctrl->value;
2968 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2979 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2981 struct i2c_client *client = v4l2_get_subdevdata(sd);
2982 struct soc_camera_device *icd = client->dev.platform_data;
2983 int i, error_cnt=0, error_idx=-1;
2986 for (i=0; i<ext_ctrl->count; i++) {
2987 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2994 error_idx = ext_ctrl->count;
2996 if (error_idx != -1) {
2997 ext_ctrl->error_idx = error_idx;
3004 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3006 struct i2c_client *client = v4l2_get_subdevdata(sd);
3007 struct soc_camera_device *icd = client->dev.platform_data;
3008 int i, error_cnt=0, error_idx=-1;
3011 for (i=0; i<ext_ctrl->count; i++) {
3012 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3019 error_idx = ext_ctrl->count;
3021 if (error_idx != -1) {
3022 ext_ctrl->error_idx = error_idx;
3029 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3030 * this wasn't our capture interface, so, we wait for the right one */
3031 static int sensor_video_probe(struct soc_camera_device *icd,
3032 struct i2c_client *client)
3036 struct sensor *sensor = to_sensor(client);
3038 /* We must have a parent by now. And it cannot be a wrong one.
3039 * So this entire test is completely redundant. */
3040 if (!icd->dev.parent ||
3041 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3044 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3046 goto sensor_video_probe_err;
3050 ret = sensor_write(client, 0x3012, 0x80);
3053 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3055 goto sensor_video_probe_err;
3057 mdelay(5); //delay 5 microseconds
3059 /* check if it is an sensor sensor */
3060 ret = sensor_read(client, 0x300a, &value);
3062 SENSOR_TR("read chip id high byte failed\n");
3064 goto sensor_video_probe_err;
3067 pid |= (value << 8);
3069 ret = sensor_read(client, 0x300b, &value);
3071 SENSOR_TR("read chip id low byte failed\n");
3073 goto sensor_video_probe_err;
3076 pid |= (value & 0xff);
3077 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3078 if (pid == SENSOR_ID) {
3079 sensor->model = SENSOR_V4L2_IDENT;
3081 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3083 goto sensor_video_probe_err;
3088 sensor_video_probe_err:
3091 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3093 struct i2c_client *client = v4l2_get_subdevdata(sd);
3094 struct soc_camera_device *icd = client->dev.platform_data;
3095 struct sensor *sensor = to_sensor(client);
3097 #if CONFIG_SENSOR_Flash
3101 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3104 case RK29_CAM_SUBDEV_DEACTIVATE:
3106 sensor_deactivate(client);
3110 case RK29_CAM_SUBDEV_IOREQUEST:
3112 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3113 if (sensor->sensor_io_request != NULL) {
3115 for(j = 0;j < RK_CAM_NUM;j++){
3116 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
3117 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
3118 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
3122 if(j == RK_CAM_NUM){
3123 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3125 goto sensor_ioctl_end;
3128 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3130 #if CONFIG_SENSOR_Flash
3131 if (sensor->sensor_gpio_res) {
3132 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3133 for (i = 0; i < icd->ops->num_controls; i++) {
3134 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3135 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3136 sensor_controls[i].id=0xffff;
3139 sensor->info_priv.flash = 0xff;
3140 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3141 }else{ //two cameras are the same,need to deal diffrently ,zyc
3142 for (i = 0; i < icd->ops->num_controls; i++) {
3143 if(0xffff == icd->ops->controls[i].id){
3144 sensor_controls[i].id=V4L2_CID_FLASH;
3154 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3163 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3164 enum v4l2_mbus_pixelcode *code)
3166 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3169 *code = sensor_colour_fmts[index].code;
3172 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3173 .init = sensor_init,
3174 .g_ctrl = sensor_g_control,
3175 .s_ctrl = sensor_s_control,
3176 .g_ext_ctrls = sensor_g_ext_controls,
3177 .s_ext_ctrls = sensor_s_ext_controls,
3178 .g_chip_ident = sensor_g_chip_ident,
3179 .ioctl = sensor_ioctl,
3181 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3182 .s_mbus_fmt = sensor_s_fmt,
3183 .g_mbus_fmt = sensor_g_fmt,
3184 .try_mbus_fmt = sensor_try_fmt,
3185 .enum_mbus_fmt = sensor_enum_fmt,
3188 static struct v4l2_subdev_ops sensor_subdev_ops = {
3189 .core = &sensor_subdev_core_ops,
3190 .video = &sensor_subdev_video_ops,
3193 static int sensor_probe(struct i2c_client *client,
3194 const struct i2c_device_id *did)
3196 struct sensor *sensor;
3197 struct soc_camera_device *icd = client->dev.platform_data;
3198 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3199 struct soc_camera_link *icl;
3202 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3204 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3208 icl = to_soc_camera_link(icd);
3210 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3214 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3215 dev_warn(&adapter->dev,
3216 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3220 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3224 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3226 /* Second stage probe - when a capture adapter is there */
3227 icd->ops = &sensor_ops;
3228 sensor->info_priv.fmt = sensor_colour_fmts[0];
3229 #if CONFIG_SENSOR_I2C_NOSCHED
3230 atomic_set(&sensor->tasklock_cnt,0);
3233 ret = sensor_video_probe(icd, client);
3236 i2c_set_clientdata(client, NULL);
3240 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3241 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3245 static int sensor_remove(struct i2c_client *client)
3247 struct sensor *sensor = to_sensor(client);
3248 struct soc_camera_device *icd = client->dev.platform_data;
3251 i2c_set_clientdata(client, NULL);
3252 client->driver = NULL;
3258 static const struct i2c_device_id sensor_id[] = {
3259 {SENSOR_NAME_STRING(), 0 },
3262 MODULE_DEVICE_TABLE(i2c, sensor_id);
3264 static struct i2c_driver sensor_i2c_driver = {
3266 .name = SENSOR_NAME_STRING(),
3268 .probe = sensor_probe,
3269 .remove = sensor_remove,
3270 .id_table = sensor_id,
3273 static int __init sensor_mod_init(void)
3275 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3276 return i2c_add_driver(&sensor_i2c_driver);
3279 static void __exit sensor_mod_exit(void)
3281 i2c_del_driver(&sensor_i2c_driver);
3284 device_initcall_sync(sensor_mod_init);
3285 module_exit(sensor_mod_exit);
3287 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3288 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3289 MODULE_LICENSE("GPL");