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 <mach/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_DEBUG 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 RK_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 100000 /* 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 1
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)
88 #define SENSOR_INIT_IS_ERR (0x00<<28)
89 #define SENSOR_INIT_IS_OK (0x01<<28)
97 static s32 sensor_init_width = 0;
98 static s32 sensor_init_height = 0;
99 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);
100 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
101 static struct reginfo* sensor_init_data_p = NULL;
102 static struct reginfo* sensor_init_winseq_p = NULL;
103 static struct reginfo* sensor_init_winseq_board = NULL;
104 /* init 800*600 SVGA */
105 static struct reginfo sensor_init_data[] =
119 {0x3090, 0x33},//0x3b},
196 {0x3088, 0x02},//{0x3088, 0x01},
197 {0x3089, 0x88},//{0x3089, 0x68},
198 {0x308A, 0x01},//{0x308a, 0x01},
199 {0x308B, 0xe0},//{0x308b, 0x20},
206 {0x331A, 0x28},//{0x331a, 0x16},
207 {0x331B, 0x1e},//{0x331b, 0x12},
270 {0x3350, 0x37},//0x33},
271 {0x3351, 0x27},//0x28},
282 {0x335c, 0x37},//0x34},
311 {0x307c, 0x10},//0x13},
329 {0x0, 0x0} //end flag
334 static struct reginfo sensor_uxga[] =
376 static struct reginfo sensor_sxga[] =
415 static struct reginfo sensor_xga[] =
420 static struct reginfo sensor_svga[] =
461 static struct reginfo sensor_vga[] =
502 static struct reginfo sensor_cif[] =
542 static struct reginfo sensor_qvga[] =
583 static struct reginfo sensor_qcif[] =
623 static struct reginfo ov2655_qqvga[] =
667 static struct reginfo ov2655_Sharpness_auto[] =
672 static struct reginfo ov2655_Sharpness1[] =
678 static struct reginfo ov2655_Sharpness2[][3] =
685 static struct reginfo ov2655_Sharpness3[] =
691 static struct reginfo ov2655_Sharpness4[]=
698 static struct reginfo ov2655_Sharpness5[] =
706 static struct reginfo sensor_ClrFmt_YUYV[]=
712 static struct reginfo sensor_ClrFmt_UYVY[]=
718 #if CONFIG_SENSOR_WhiteBalance
719 static struct reginfo sensor_WhiteB_Auto[]=
721 {0x3306, 0x00}, //AWB auto, bit[1]:0,auto
724 /* Cloudy Colour Temperature : 6500K - 8000K */
725 static struct reginfo sensor_WhiteB_Cloudy[]=
733 /* ClearDay Colour Temperature : 5000K - 6500K */
734 static struct reginfo sensor_WhiteB_ClearDay[]=
737 {0x3306, 0x02}, //AWB off
743 /* Office Colour Temperature : 3500K - 5000K */
744 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
754 /* Home Colour Temperature : 2500K - 3500K */
755 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
764 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
765 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
769 #if CONFIG_SENSOR_Brightness
770 static struct reginfo sensor_Brightness0[]=
773 {0x3301, 0xff},//bit[7]:1, enable SDE
780 static struct reginfo sensor_Brightness1[]=
783 {0x3301, 0xff},//bit[7]:1, enable SDE
790 static struct reginfo sensor_Brightness2[]=
793 {0x3301, 0xff},//bit[7]:1, enable SDE
800 static struct reginfo sensor_Brightness3[]=
803 {0x3301, 0xff},//bit[7]:1, enable SDE
810 static struct reginfo sensor_Brightness4[]=
813 {0x3301, 0xff},//bit[7]:1, enable SDE
820 static struct reginfo sensor_Brightness5[]=
823 {0x3301, 0xff},//bit[7]:1, enable SDE
824 {0x3391, 0x04}, //bit[2] enable
825 {0x3390, 0x41}, //bit[3] sign of brightness
829 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
830 sensor_Brightness4, sensor_Brightness5,NULL,
835 #if CONFIG_SENSOR_Effect
836 static struct reginfo sensor_Effect_Normal[] =
842 static struct reginfo sensor_Effect_WandB[] =
848 static struct reginfo sensor_Effect_Sepia[] =
856 static struct reginfo sensor_Effect_Negative[] =
859 {0x3391, 0x40}, //bit[6] negative
862 static struct reginfo sensor_Effect_Bluish[] =
871 static struct reginfo sensor_Effect_Green[] =
879 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
880 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
883 #if CONFIG_SENSOR_Exposure
884 static struct reginfo sensor_Exposure0[]=
894 static struct reginfo sensor_Exposure1[]=
904 static struct reginfo sensor_Exposure2[]=
914 static struct reginfo sensor_Exposure3[]=
924 static struct reginfo sensor_Exposure4[]=
934 static struct reginfo sensor_Exposure5[]=
944 static struct reginfo sensor_Exposure6[]=
954 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
955 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
958 #if CONFIG_SENSOR_Saturation
959 static struct reginfo sensor_Saturation0[]=
961 {0x3301, 0xff},//bit[7]:1, enable SDE
968 static struct reginfo sensor_Saturation1[]=
970 {0x3301, 0xff},//bit[7]:1, enable SDE
977 static struct reginfo sensor_Saturation2[]=
979 {0x3301, 0xff},//bit[7]:1, enable SDE
980 {0x3391, 0x02}, //enable color saturation
985 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
988 #if CONFIG_SENSOR_Contrast
989 static struct reginfo sensor_Contrast0[]=
992 {0x3301, 0xff},//bit[7]:1, enable SDE
1000 static struct reginfo sensor_Contrast1[]=
1003 {0x3301, 0xff},//bit[7]:1, enable SDE
1011 static struct reginfo sensor_Contrast2[]=
1014 {0x3301, 0xff},//bit[7]:1, enable SDE
1022 static struct reginfo sensor_Contrast3[]=
1025 {0x3301, 0xff},//bit[7]:1, enable SDE
1033 static struct reginfo sensor_Contrast4[]=
1036 {0x3301, 0xff},//bit[7]:1, enable SDE
1045 static struct reginfo sensor_Contrast5[]=
1048 {0x3301, 0xff},//bit[7]:1, enable SDE
1056 static struct reginfo sensor_Contrast6[]=
1059 {0x3301, 0xff},//bit[7]:1, enable SDE
1060 {0x3391, 0x04}, //bit[2] enable contrast/brightness
1061 {0x3390, 0x45}, //bit[2] Yoffset sign
1066 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1067 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1071 #if CONFIG_SENSOR_Mirror
1072 static struct reginfo sensor_MirrorOn[]=
1080 static struct reginfo sensor_MirrorOff[]=
1087 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1089 #if CONFIG_SENSOR_Flip
1090 static struct reginfo sensor_FlipOn[]=
1103 static struct reginfo sensor_FlipOff[]=
1115 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1118 #if CONFIG_SENSOR_Scene
1119 static struct reginfo sensor_SceneAuto[] =
1121 #if 0 /* ddl@rock-chips.com : */
1136 static struct reginfo sensor_SceneNight[] =
1139 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1150 {0x3015, 0x50},//add 5 dummy frame
1155 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1171 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1174 #if CONFIG_SENSOR_DigitalZoom
1175 static struct reginfo sensor_Zoom0[] =
1180 static struct reginfo sensor_Zoom1[] =
1185 static struct reginfo sensor_Zoom2[] =
1191 static struct reginfo sensor_Zoom3[] =
1195 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1197 static const struct v4l2_querymenu sensor_menus[] =
1199 #if CONFIG_SENSOR_WhiteBalance
1200 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1201 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1202 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1205 #if CONFIG_SENSOR_Effect
1206 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1207 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1208 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1211 #if CONFIG_SENSOR_Scene
1212 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1215 #if CONFIG_SENSOR_Flash
1216 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1217 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1221 static const struct v4l2_queryctrl sensor_controls[] =
1223 #if CONFIG_SENSOR_WhiteBalance
1225 .id = V4L2_CID_DO_WHITE_BALANCE,
1226 .type = V4L2_CTRL_TYPE_MENU,
1227 .name = "White Balance Control",
1235 #if CONFIG_SENSOR_Brightness
1237 .id = V4L2_CID_BRIGHTNESS,
1238 .type = V4L2_CTRL_TYPE_INTEGER,
1239 .name = "Brightness Control",
1247 #if CONFIG_SENSOR_Effect
1249 .id = V4L2_CID_EFFECT,
1250 .type = V4L2_CTRL_TYPE_MENU,
1251 .name = "Effect Control",
1259 #if CONFIG_SENSOR_Exposure
1261 .id = V4L2_CID_EXPOSURE,
1262 .type = V4L2_CTRL_TYPE_INTEGER,
1263 .name = "Exposure Control",
1271 #if CONFIG_SENSOR_Saturation
1273 .id = V4L2_CID_SATURATION,
1274 .type = V4L2_CTRL_TYPE_INTEGER,
1275 .name = "Saturation Control",
1283 #if CONFIG_SENSOR_Contrast
1285 .id = V4L2_CID_CONTRAST,
1286 .type = V4L2_CTRL_TYPE_INTEGER,
1287 .name = "Contrast Control",
1295 #if CONFIG_SENSOR_Mirror
1297 .id = V4L2_CID_HFLIP,
1298 .type = V4L2_CTRL_TYPE_BOOLEAN,
1299 .name = "Mirror Control",
1307 #if CONFIG_SENSOR_Flip
1309 .id = V4L2_CID_VFLIP,
1310 .type = V4L2_CTRL_TYPE_BOOLEAN,
1311 .name = "Flip Control",
1319 #if CONFIG_SENSOR_Scene
1321 .id = V4L2_CID_SCENE,
1322 .type = V4L2_CTRL_TYPE_MENU,
1323 .name = "Scene Control",
1331 #if CONFIG_SENSOR_DigitalZoom
1333 .id = V4L2_CID_ZOOM_RELATIVE,
1334 .type = V4L2_CTRL_TYPE_INTEGER,
1335 .name = "DigitalZoom Control",
1341 .id = V4L2_CID_ZOOM_ABSOLUTE,
1342 .type = V4L2_CTRL_TYPE_INTEGER,
1343 .name = "DigitalZoom Control",
1351 #if CONFIG_SENSOR_Focus
1353 .id = V4L2_CID_FOCUS_RELATIVE,
1354 .type = V4L2_CTRL_TYPE_INTEGER,
1355 .name = "Focus Control",
1361 .id = V4L2_CID_FOCUS_ABSOLUTE,
1362 .type = V4L2_CTRL_TYPE_INTEGER,
1363 .name = "Focus Control",
1367 .default_value = 125,
1371 #if CONFIG_SENSOR_Flash
1373 .id = V4L2_CID_FLASH,
1374 .type = V4L2_CTRL_TYPE_MENU,
1375 .name = "Flash Control",
1384 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1385 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1386 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1387 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1388 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1389 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1390 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1391 static int sensor_resume(struct soc_camera_device *icd);
1392 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1393 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1394 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1395 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1396 static int sensor_deactivate(struct i2c_client *client);
1398 static struct soc_camera_ops sensor_ops =
1400 .suspend = sensor_suspend,
1401 .resume = sensor_resume,
1402 .set_bus_param = sensor_set_bus_param,
1403 .query_bus_param = sensor_query_bus_param,
1404 .controls = sensor_controls,
1405 .menus = sensor_menus,
1406 .num_controls = ARRAY_SIZE(sensor_controls),
1407 .num_menus = ARRAY_SIZE(sensor_menus),
1409 /* only one fixed colorspace per pixelcode */
1410 struct sensor_datafmt {
1411 enum v4l2_mbus_pixelcode code;
1412 enum v4l2_colorspace colorspace;
1415 /* Find a data format by a pixel code in an array */
1416 static const struct sensor_datafmt *sensor_find_datafmt(
1417 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1421 for (i = 0; i < n; i++)
1422 if (fmt[i].code == code)
1428 static const struct sensor_datafmt sensor_colour_fmts[] = {
1429 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1430 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1433 typedef struct sensor_info_priv_s
1447 unsigned char mirror; /* HFLIP */
1448 unsigned char flip; /* VFLIP */
1449 unsigned int winseqe_cur_addr;
1450 struct sensor_datafmt fmt;
1451 unsigned int funmodule_state;
1452 } sensor_info_priv_t;
1456 struct v4l2_subdev subdev;
1457 struct i2c_client *client;
1458 sensor_info_priv_t info_priv;
1459 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1460 #if CONFIG_SENSOR_I2C_NOSCHED
1461 atomic_t tasklock_cnt;
1463 struct rkcamera_platform_data *sensor_io_request;
1464 struct rkcamera_gpio_res *sensor_gpio_res;
1467 static struct sensor* to_sensor(const struct i2c_client *client)
1469 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1472 static int sensor_task_lock(struct i2c_client *client, int lock)
1474 #if CONFIG_SENSOR_I2C_NOSCHED
1476 struct sensor *sensor = to_sensor(client);
1479 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1480 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1481 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1485 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1486 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1487 goto sensor_task_lock_err;
1492 atomic_add(1, &sensor->tasklock_cnt);
1494 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1495 atomic_sub(1, &sensor->tasklock_cnt);
1497 if (atomic_read(&sensor->tasklock_cnt) == 0)
1502 sensor_task_lock_err:
1510 /* sensor register write */
1511 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1515 struct i2c_msg msg[1];
1518 buf[1] = reg & 0xFF;
1521 msg->addr = client->addr;
1522 msg->flags = client->flags;
1524 msg->len = sizeof(buf);
1525 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1526 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1531 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1532 err = i2c_transfer(client->adapter, msg, 1);
1537 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1545 /* sensor register read */
1546 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1550 struct i2c_msg msg[2];
1553 buf[1] = reg & 0xFF;
1555 msg[0].addr = client->addr;
1556 msg[0].flags = client->flags;
1558 msg[0].len = sizeof(buf);
1559 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1560 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1562 msg[1].addr = client->addr;
1563 msg[1].flags = client->flags|I2C_M_RD;
1566 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1567 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1571 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1572 err = i2c_transfer(client->adapter, msg, 2);
1578 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1586 /* write a array of registers */
1587 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1591 #if CONFIG_SENSOR_I2C_RDWRCHK
1596 if (sensor_task_lock(client, 1) < 0)
1597 goto sensor_write_array_end;
1598 while (regarray[i].reg != 0)
1600 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1604 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1608 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1610 goto sensor_write_array_end;
1613 #if CONFIG_SENSOR_I2C_RDWRCHK
1614 sensor_read(client, regarray[i].reg, &valchk);
1615 if (valchk != regarray[i].val)
1616 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1622 sensor_write_array_end:
1623 sensor_task_lock(client,0);
1626 #if CONFIG_SENSOR_I2C_RDWRCHK
1627 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1635 while (regarray[i].reg != 0)
1637 sensor_read(client, regarray[i].reg, &valchk);
1638 if (valchk != regarray[i].val)
1639 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1646 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
1648 struct soc_camera_link *icl = to_soc_camera_link(icd);
1651 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1655 case Sensor_PowerDown:
1657 if (icl->powerdown) {
1658 ret = icl->powerdown(icd->pdev, on);
1659 if (ret == RK_CAM_IO_SUCCESS) {
1663 icl->reset(icd->pdev);
1665 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
1667 goto sensor_power_end;
1674 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1675 struct sensor *sensor = to_sensor(client);
1677 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1678 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1684 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1691 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1693 struct i2c_client *client = v4l2_get_subdevdata(sd);
1694 struct soc_camera_device *icd = client->dev.platform_data;
1695 struct sensor *sensor = to_sensor(client);
1696 const struct v4l2_queryctrl *qctrl;
1697 const struct sensor_datafmt *fmt;
1699 int ret,pid = 0,i = 0,j=0;
1700 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
1701 sensor_init_data_p = sensor_init_data;
1702 sensor_init_winseq_p = sensor_vga;
1703 sensor_init_width = 640;
1704 sensor_init_height = 480;
1705 if (tmp_plat_data != NULL) {
1706 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
1707 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1708 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1712 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
1713 //user has defined the init data
1715 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1716 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1717 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1718 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1720 sensor_init_data_p = sensor_init_data;
1722 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1723 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1726 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1727 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1728 if(sensor_init_winseq_board)
1730 vfree(sensor_init_winseq_board);
1731 sensor_init_winseq_board = NULL;
1733 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1734 if(!sensor_init_winseq_board)
1735 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1736 for(j = 0;j< tmp_winseq_size;j++){
1737 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1738 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1740 sensor_init_winseq_p = sensor_init_winseq_board;
1742 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1743 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1745 //init width,height,bus,pixelcode
1746 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1747 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1748 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1749 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1750 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1751 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1752 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1753 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1755 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1757 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1759 goto sensor_INIT_ERR;
1763 if (sensor_task_lock(client,1)<0)
1764 goto sensor_INIT_ERR;
1765 sensor_write(client, 0x300F, 0xAE);
1767 sensor_write(client, 0x300F, 0xAE);
1769 ret = sensor_write(client, 0x3012, 0x80);
1772 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1774 goto sensor_INIT_ERR;
1777 mdelay(5); //delay 5 microseconds
1778 /* check if it is an sensor sensor */
1779 ret = sensor_read(client, 0x300a, &value);
1781 SENSOR_TR("read chip id high byte failed\n");
1783 goto sensor_INIT_ERR;
1786 pid |= (value << 8);
1788 ret = sensor_read(client, 0x300b, &value);
1790 SENSOR_TR("read chip id low byte failed\n");
1792 goto sensor_INIT_ERR;
1795 pid |= (value & 0xff);
1796 printk("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1797 if (pid == SENSOR_ID) {
1798 sensor->model = SENSOR_V4L2_IDENT;
1800 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1802 goto sensor_INIT_ERR;
1805 ret = sensor_write_array(client, sensor_init_data_p);
1808 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1809 goto sensor_INIT_ERR;
1811 sensor_task_lock(client,0);
1812 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1813 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1815 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1817 goto sensor_INIT_ERR;
1819 sensor->info_priv.fmt = *fmt;
1821 /* sensor sensor information for initialization */
1822 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1824 sensor->info_priv.whiteBalance = qctrl->default_value;
1825 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1827 sensor->info_priv.brightness = qctrl->default_value;
1828 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1830 sensor->info_priv.effect = qctrl->default_value;
1831 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1833 sensor->info_priv.exposure = qctrl->default_value;
1835 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1837 sensor->info_priv.saturation = qctrl->default_value;
1838 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1840 sensor->info_priv.contrast = qctrl->default_value;
1841 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1843 sensor->info_priv.mirror = qctrl->default_value;
1844 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1846 sensor->info_priv.flip = qctrl->default_value;
1847 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1849 sensor->info_priv.scene = qctrl->default_value;
1850 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1852 sensor->info_priv.digitalzoom = qctrl->default_value;
1854 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1855 #if CONFIG_SENSOR_Focus
1857 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1859 sensor->info_priv.focus = qctrl->default_value;
1862 #if CONFIG_SENSOR_Flash
1863 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1865 sensor->info_priv.flash = qctrl->default_value;
1868 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);
1869 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1872 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1873 sensor_task_lock(client,0);
1874 sensor_deactivate(client);
1878 static int sensor_deactivate(struct i2c_client *client)
1880 struct soc_camera_device *icd = client->dev.platform_data;
1882 struct sensor *sensor = to_sensor(client);
1883 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1885 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1886 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
1887 sensor_task_lock(client, 1);
1888 sensor_write(client, 0x30b0, 0x00);
1889 sensor_write(client, 0x30b1, 0x00);
1890 sensor_task_lock(client, 0);
1892 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1895 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1896 icd->user_width = SENSOR_INIT_WIDTH;
1897 icd->user_height = SENSOR_INIT_HEIGHT;
1898 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1903 static struct reginfo sensor_power_down_sequence[]=
1911 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1914 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1916 if (pm_msg.event == PM_EVENT_SUSPEND) {
1917 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1918 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1920 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1923 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1925 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1930 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1936 static int sensor_resume(struct soc_camera_device *icd)
1940 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1942 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1946 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1952 static int sensor_set_bus_param(struct soc_camera_device *icd,
1953 unsigned long flags)
1959 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1961 struct soc_camera_link *icl = to_soc_camera_link(icd);
1962 unsigned long flags = SENSOR_BUS_PARAM;
1964 return soc_camera_apply_sensor_flags(icl, flags);
1967 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1969 struct i2c_client *client = v4l2_get_subdevdata(sd);
1970 struct soc_camera_device *icd = client->dev.platform_data;
1971 struct sensor *sensor = to_sensor(client);
1973 mf->width = icd->user_width;
1974 mf->height = icd->user_height;
1975 mf->code = sensor->info_priv.fmt.code;
1976 mf->colorspace = sensor->info_priv.fmt.colorspace;
1977 mf->field = V4L2_FIELD_NONE;
1981 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1985 if ((mf->width == 1024) && (mf->height == 768)) {
1987 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1989 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1991 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1993 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1998 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2002 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2006 if ((mf->width == 1280) && (mf->height == 720)) {
2008 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2013 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2016 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2018 struct i2c_client *client = v4l2_get_subdevdata(sd);
2019 const struct sensor_datafmt *fmt;
2020 struct sensor *sensor = to_sensor(client);
2021 const struct v4l2_queryctrl *qctrl;
2022 struct soc_camera_device *icd = client->dev.platform_data;
2023 struct reginfo *winseqe_set_addr=NULL;
2024 int ret=0, set_w,set_h;
2026 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2027 ARRAY_SIZE(sensor_colour_fmts));
2030 goto sensor_s_fmt_end;
2033 if (sensor->info_priv.fmt.code != mf->code) {
2036 case V4L2_MBUS_FMT_YUYV8_2X8:
2038 winseqe_set_addr = sensor_ClrFmt_YUYV;
2041 case V4L2_MBUS_FMT_UYVY8_2X8:
2043 winseqe_set_addr = sensor_ClrFmt_UYVY;
2049 if (winseqe_set_addr != NULL) {
2050 sensor_write_array(client, winseqe_set_addr);
2051 sensor->info_priv.fmt.code = mf->code;
2052 sensor->info_priv.fmt.colorspace= mf->colorspace;
2053 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2055 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2062 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2064 winseqe_set_addr = sensor_qcif;
2068 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2070 winseqe_set_addr = sensor_qvga;
2074 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2076 winseqe_set_addr = sensor_cif;
2080 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2082 winseqe_set_addr = sensor_vga;
2086 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2088 winseqe_set_addr = sensor_svga;
2092 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
2094 winseqe_set_addr = sensor_xga;
2098 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2100 winseqe_set_addr = sensor_sxga;
2104 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2106 winseqe_set_addr = sensor_uxga;
2112 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2113 set_w = SENSOR_INIT_WIDTH;
2114 set_h = SENSOR_INIT_HEIGHT;
2115 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2118 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2119 #if CONFIG_SENSOR_Flash
2120 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2121 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2122 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2123 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2125 } else { /* ddl@rock-chips.com : Video */
2126 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2127 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2128 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2132 ret |= sensor_write_array(client, winseqe_set_addr);
2134 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2135 #if CONFIG_SENSOR_Flash
2136 if (sensor_fmt_capturechk(sd,mf) == true) {
2137 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2138 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2139 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2143 goto sensor_s_fmt_end;
2146 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2148 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2149 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2150 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2151 if (sensor->info_priv.whiteBalance != 0) {
2152 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2153 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2155 sensor->info_priv.snap2preview = true;
2156 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2157 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2158 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2159 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2160 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2161 sensor->info_priv.video2preview = true;
2162 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2163 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2164 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2165 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2166 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2168 sensor->info_priv.video2preview = false;
2169 sensor->info_priv.snap2preview = false;
2171 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2175 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2185 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2187 struct i2c_client *client = v4l2_get_subdevdata(sd);
2188 struct sensor *sensor = to_sensor(client);
2189 const struct sensor_datafmt *fmt;
2192 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2193 ARRAY_SIZE(sensor_colour_fmts));
2195 fmt = &sensor->info_priv.fmt;
2196 mf->code = fmt->code;
2199 if (mf->height > SENSOR_MAX_HEIGHT)
2200 mf->height = SENSOR_MAX_HEIGHT;
2201 else if (mf->height < SENSOR_MIN_HEIGHT)
2202 mf->height = SENSOR_MIN_HEIGHT;
2204 if (mf->width > SENSOR_MAX_WIDTH)
2205 mf->width = SENSOR_MAX_WIDTH;
2206 else if (mf->width < SENSOR_MIN_WIDTH)
2207 mf->width = SENSOR_MIN_WIDTH;
2209 mf->colorspace = fmt->colorspace;
2213 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2215 struct i2c_client *client = v4l2_get_subdevdata(sd);
2217 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2220 if (id->match.addr != client->addr)
2223 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2228 #if CONFIG_SENSOR_Brightness
2229 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2231 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2233 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2235 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2237 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2239 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2242 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2246 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2250 #if CONFIG_SENSOR_Effect
2251 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2253 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2255 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2257 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2259 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2261 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2264 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2268 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2272 #if CONFIG_SENSOR_Exposure
2273 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2275 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2277 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2279 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2281 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2283 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2286 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2290 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2294 #if CONFIG_SENSOR_Saturation
2295 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2297 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2299 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2301 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2303 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2305 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2308 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2312 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2316 #if CONFIG_SENSOR_Contrast
2317 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2319 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2321 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2323 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2325 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2327 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2330 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2334 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2338 #if CONFIG_SENSOR_Mirror
2339 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2341 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2343 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2345 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2347 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2349 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2352 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2356 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2360 #if CONFIG_SENSOR_Flip
2361 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2363 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2365 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2367 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2369 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2371 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2374 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2378 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2382 #if CONFIG_SENSOR_Scene
2383 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2385 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2387 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2389 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2391 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2393 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2396 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2400 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2404 #if CONFIG_SENSOR_WhiteBalance
2405 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2407 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2409 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2411 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2413 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2415 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2418 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2422 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2426 #if CONFIG_SENSOR_DigitalZoom
2427 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2429 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2430 struct sensor *sensor = to_sensor(client);
2431 const struct v4l2_queryctrl *qctrl_info;
2432 int digitalzoom_cur, digitalzoom_total;
2434 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2438 digitalzoom_cur = sensor->info_priv.digitalzoom;
2439 digitalzoom_total = qctrl_info->maximum;
2441 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2443 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2447 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2449 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2453 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2455 *value = digitalzoom_total - digitalzoom_cur;
2458 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2460 *value = 0 - digitalzoom_cur;
2463 digitalzoom_cur += *value;
2465 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2467 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2469 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2472 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2479 #if CONFIG_SENSOR_Flash
2480 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2482 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2483 if (value == 3) { /* ddl@rock-chips.com: torch */
2484 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2486 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2488 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2492 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2497 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2499 struct i2c_client *client = v4l2_get_subdevdata(sd);
2500 struct sensor *sensor = to_sensor(client);
2501 const struct v4l2_queryctrl *qctrl;
2503 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2507 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2513 case V4L2_CID_BRIGHTNESS:
2515 ctrl->value = sensor->info_priv.brightness;
2518 case V4L2_CID_SATURATION:
2520 ctrl->value = sensor->info_priv.saturation;
2523 case V4L2_CID_CONTRAST:
2525 ctrl->value = sensor->info_priv.contrast;
2528 case V4L2_CID_DO_WHITE_BALANCE:
2530 ctrl->value = sensor->info_priv.whiteBalance;
2533 case V4L2_CID_EXPOSURE:
2535 ctrl->value = sensor->info_priv.exposure;
2538 case V4L2_CID_HFLIP:
2540 ctrl->value = sensor->info_priv.mirror;
2543 case V4L2_CID_VFLIP:
2545 ctrl->value = sensor->info_priv.flip;
2556 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2558 struct i2c_client *client = v4l2_get_subdevdata(sd);
2559 struct sensor *sensor = to_sensor(client);
2560 struct soc_camera_device *icd = client->dev.platform_data;
2561 const struct v4l2_queryctrl *qctrl;
2564 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2568 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2574 #if CONFIG_SENSOR_Brightness
2575 case V4L2_CID_BRIGHTNESS:
2577 if (ctrl->value != sensor->info_priv.brightness)
2579 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2583 sensor->info_priv.brightness = ctrl->value;
2588 #if CONFIG_SENSOR_Exposure
2589 case V4L2_CID_EXPOSURE:
2591 if (ctrl->value != sensor->info_priv.exposure)
2593 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2597 sensor->info_priv.exposure = ctrl->value;
2602 #if CONFIG_SENSOR_Saturation
2603 case V4L2_CID_SATURATION:
2605 if (ctrl->value != sensor->info_priv.saturation)
2607 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2611 sensor->info_priv.saturation = ctrl->value;
2616 #if CONFIG_SENSOR_Contrast
2617 case V4L2_CID_CONTRAST:
2619 if (ctrl->value != sensor->info_priv.contrast)
2621 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2625 sensor->info_priv.contrast = ctrl->value;
2630 #if CONFIG_SENSOR_WhiteBalance
2631 case V4L2_CID_DO_WHITE_BALANCE:
2633 if (ctrl->value != sensor->info_priv.whiteBalance)
2635 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2639 sensor->info_priv.whiteBalance = ctrl->value;
2644 #if CONFIG_SENSOR_Mirror
2645 case V4L2_CID_HFLIP:
2647 if (ctrl->value != sensor->info_priv.mirror)
2649 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2651 sensor->info_priv.mirror = ctrl->value;
2656 #if CONFIG_SENSOR_Flip
2657 case V4L2_CID_VFLIP:
2659 if (ctrl->value != sensor->info_priv.flip)
2661 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2663 sensor->info_priv.flip = ctrl->value;
2674 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2676 const struct v4l2_queryctrl *qctrl;
2677 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2678 struct sensor *sensor = to_sensor(client);
2680 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2684 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2688 switch (ext_ctrl->id)
2690 case V4L2_CID_SCENE:
2692 ext_ctrl->value = sensor->info_priv.scene;
2695 case V4L2_CID_EFFECT:
2697 ext_ctrl->value = sensor->info_priv.effect;
2700 case V4L2_CID_ZOOM_ABSOLUTE:
2702 ext_ctrl->value = sensor->info_priv.digitalzoom;
2705 case V4L2_CID_ZOOM_RELATIVE:
2709 case V4L2_CID_FOCUS_ABSOLUTE:
2711 ext_ctrl->value = sensor->info_priv.focus;
2714 case V4L2_CID_FOCUS_RELATIVE:
2718 case V4L2_CID_FLASH:
2720 ext_ctrl->value = sensor->info_priv.flash;
2728 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2730 const struct v4l2_queryctrl *qctrl;
2731 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2732 struct sensor *sensor = to_sensor(client);
2735 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2739 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2744 switch (ext_ctrl->id)
2746 #if CONFIG_SENSOR_Scene
2747 case V4L2_CID_SCENE:
2749 if (ext_ctrl->value != sensor->info_priv.scene)
2751 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2753 sensor->info_priv.scene = ext_ctrl->value;
2758 #if CONFIG_SENSOR_Effect
2759 case V4L2_CID_EFFECT:
2761 if (ext_ctrl->value != sensor->info_priv.effect)
2763 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2765 sensor->info_priv.effect= ext_ctrl->value;
2770 #if CONFIG_SENSOR_DigitalZoom
2771 case V4L2_CID_ZOOM_ABSOLUTE:
2773 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2776 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2778 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2780 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2782 sensor->info_priv.digitalzoom += val_offset;
2784 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2789 case V4L2_CID_ZOOM_RELATIVE:
2791 if (ext_ctrl->value)
2793 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2795 sensor->info_priv.digitalzoom += ext_ctrl->value;
2797 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2802 #if CONFIG_SENSOR_Focus
2803 case V4L2_CID_FOCUS_ABSOLUTE:
2805 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2808 if (ext_ctrl->value != sensor->info_priv.focus)
2810 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2812 sensor->info_priv.focus += val_offset;
2817 case V4L2_CID_FOCUS_RELATIVE:
2819 if (ext_ctrl->value)
2821 sensor->info_priv.focus += ext_ctrl->value;
2823 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2828 #if CONFIG_SENSOR_Flash
2829 case V4L2_CID_FLASH:
2831 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2833 sensor->info_priv.flash = ext_ctrl->value;
2835 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2846 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2848 struct i2c_client *client = v4l2_get_subdevdata(sd);
2849 struct soc_camera_device *icd = client->dev.platform_data;
2850 int i, error_cnt=0, error_idx=-1;
2853 for (i=0; i<ext_ctrl->count; i++) {
2854 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2861 error_idx = ext_ctrl->count;
2863 if (error_idx != -1) {
2864 ext_ctrl->error_idx = error_idx;
2871 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2873 struct i2c_client *client = v4l2_get_subdevdata(sd);
2874 struct soc_camera_device *icd = client->dev.platform_data;
2875 int i, error_cnt=0, error_idx=-1;
2878 for (i=0; i<ext_ctrl->count; i++) {
2879 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2886 error_idx = ext_ctrl->count;
2888 if (error_idx != -1) {
2889 ext_ctrl->error_idx = error_idx;
2896 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2897 * this wasn't our capture interface, so, we wait for the right one */
2898 static int sensor_video_probe(struct soc_camera_device *icd,
2899 struct i2c_client *client)
2903 struct sensor *sensor = to_sensor(client);
2905 /* We must have a parent by now. And it cannot be a wrong one.
2906 * So this entire test is completely redundant. */
2907 if (!icd->dev.parent ||
2908 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2911 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2913 goto sensor_video_probe_err;
2917 ret = sensor_write(client, 0x3012, 0x80);
2920 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2922 goto sensor_video_probe_err;
2924 mdelay(5); //delay 5 microseconds
2926 /* check if it is an sensor sensor */
2927 ret = sensor_read(client, 0x300a, &value);
2929 SENSOR_TR("read chip id high byte failed\n");
2931 goto sensor_video_probe_err;
2934 pid |= (value << 8);
2936 ret = sensor_read(client, 0x300b, &value);
2938 SENSOR_TR("read chip id low byte failed\n");
2940 goto sensor_video_probe_err;
2943 pid |= (value & 0xff);
2944 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2945 if (pid == SENSOR_ID) {
2946 sensor->model = SENSOR_V4L2_IDENT;
2948 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2950 goto sensor_video_probe_err;
2952 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2955 sensor_video_probe_err:
2958 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2960 struct i2c_client *client = v4l2_get_subdevdata(sd);
2961 struct soc_camera_device *icd = client->dev.platform_data;
2962 struct sensor *sensor = to_sensor(client);
2965 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2968 case RK_CAM_SUBDEV_DEACTIVATE:
2970 sensor_deactivate(client);
2974 case RK_CAM_SUBDEV_IOREQUEST:
2976 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
2977 if (sensor->sensor_io_request != NULL) {
2978 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2979 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2980 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2981 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2982 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2983 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2986 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2988 goto sensor_ioctl_end;
2990 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2992 #if CONFIG_SENSOR_Flash
2993 if (sensor->sensor_gpio_res) {
2994 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2995 for (i = 0; i < icd->ops->num_controls; i++) {
2996 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2997 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3000 sensor->info_priv.flash = 0xff;
3001 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3009 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3018 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3019 enum v4l2_mbus_pixelcode *code)
3021 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3024 *code = sensor_colour_fmts[index].code;
3027 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3028 .init = sensor_init,
3029 .g_ctrl = sensor_g_control,
3030 .s_ctrl = sensor_s_control,
3031 .g_ext_ctrls = sensor_g_ext_controls,
3032 .s_ext_ctrls = sensor_s_ext_controls,
3033 .g_chip_ident = sensor_g_chip_ident,
3034 .ioctl = sensor_ioctl,
3036 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3037 .s_mbus_fmt = sensor_s_fmt,
3038 .g_mbus_fmt = sensor_g_fmt,
3039 .try_mbus_fmt = sensor_try_fmt,
3040 .enum_mbus_fmt = sensor_enum_fmt,
3043 static struct v4l2_subdev_ops sensor_subdev_ops = {
3044 .core = &sensor_subdev_core_ops,
3045 .video = &sensor_subdev_video_ops,
3048 static int sensor_probe(struct i2c_client *client,
3049 const struct i2c_device_id *did)
3051 struct sensor *sensor;
3052 struct soc_camera_device *icd = client->dev.platform_data;
3053 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3054 struct soc_camera_link *icl;
3057 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3059 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3063 icl = to_soc_camera_link(icd);
3065 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3069 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3070 dev_warn(&adapter->dev,
3071 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3075 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3079 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3081 /* Second stage probe - when a capture adapter is there */
3082 icd->ops = &sensor_ops;
3083 sensor->info_priv.fmt = sensor_colour_fmts[0];
3084 #if CONFIG_SENSOR_I2C_NOSCHED
3085 atomic_set(&sensor->tasklock_cnt,0);
3088 ret = sensor_video_probe(icd, client);
3091 i2c_set_clientdata(client, NULL);
3095 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3099 static int sensor_remove(struct i2c_client *client)
3101 struct sensor *sensor = to_sensor(client);
3102 struct soc_camera_device *icd = client->dev.platform_data;
3105 i2c_set_clientdata(client, NULL);
3106 client->driver = NULL;
3112 static const struct i2c_device_id sensor_id[] = {
3113 {SENSOR_NAME_STRING(), 0 },
3116 MODULE_DEVICE_TABLE(i2c, sensor_id);
3118 static struct i2c_driver sensor_i2c_driver = {
3120 .name = SENSOR_NAME_STRING(),
3122 .probe = sensor_probe,
3123 .remove = sensor_remove,
3124 .id_table = sensor_id,
3127 static int __init sensor_mod_init(void)
3129 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3130 return i2c_add_driver(&sensor_i2c_driver);
3133 static void __exit sensor_mod_exit(void)
3135 i2c_del_driver(&sensor_i2c_driver);
3138 device_initcall_sync(sensor_mod_init);
3139 module_exit(sensor_mod_exit);
3141 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3142 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3143 MODULE_LICENSE("GPL");