2 * Driver for OV5642 CMOS Image Sensor from OmniVision
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/rk29_camera.h>
25 #define _CONS(a,b) a##b
26 #define CONS(a,b) _CONS(a,b)
29 #define _STR(x) __STR(x)
30 #define STR(x) _STR(x)
32 /* Sensor Driver Configuration */
33 #define SENSOR_NAME ov5642
34 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV5642
35 #define SENSOR_ID 0x5642
36 #define SENSOR_MIN_WIDTH 176
37 #define SENSOR_MIN_HEIGHT 144
38 #define SENSOR_MAX_WIDTH 2592
39 #define SENSOR_MAX_HEIGHT 1944
40 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
41 #define SENSOR_INIT_HEIGHT 480
42 #define SENSOR_INIT_WINSEQADR sensor_vga
43 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_UYVY
45 #define CONFIG_SENSOR_WhiteBalance 1
46 #define CONFIG_SENSOR_Brightness 0
47 #define CONFIG_SENSOR_Contrast 0
48 #define CONFIG_SENSOR_Saturation 0
49 #define CONFIG_SENSOR_Effect 1
50 #define CONFIG_SENSOR_Scene 1
51 #define CONFIG_SENSOR_DigitalZoom 0
52 #define CONFIG_SENSOR_Exposure 0
53 #define CONFIG_SENSOR_Flash 0
54 #define CONFIG_SENSOR_Mirror 0
55 #define CONFIG_SENSOR_Flip 0
56 #ifdef CONFIG_OV5642_AUTOFOCUS
57 #define CONFIG_SENSOR_Focus 1
58 #include "ov5642_af_firmware.c"
60 #define CONFIG_SENSOR_Focus 0
63 #define CONFIG_SENSOR_I2C_SPEED 300000 /* Hz */
65 #define CONFIG_SENSOR_TR 1
66 #define CONFIG_SENSOR_DEBUG 1
68 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
69 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
71 #define MIN(x,y) ((x<y) ? x: y)
72 #define MAX(x,y) ((x>y) ? x: y)
74 #if (CONFIG_SENSOR_TR)
75 #define SENSOR_TR(format, ...) printk(format, ## __VA_ARGS__)
76 #if (CONFIG_SENSOR_DEBUG)
77 #define SENSOR_DG(format, ...) printk(format, ## __VA_ARGS__)
79 #define SENSOR_DG(format, ...)
82 #define SENSOR_TR(format, ...)
85 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
86 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
87 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
89 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
90 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
91 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
92 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
93 #define COLOR_TEMPERATURE_OFFICE_DN 3500
94 #define COLOR_TEMPERATURE_OFFICE_UP 5000
95 #define COLOR_TEMPERATURE_HOME_DN 2500
96 #define COLOR_TEMPERATURE_HOME_UP 3500
98 #define SENSOR_AF_IS_ERR (0x00<<0)
99 #define SENSOR_AF_IS_OK (0x01<<0)
101 #if CONFIG_SENSOR_Focus
102 #define SENSOR_AF_MODE_INFINITY 0
103 #define SENSOR_AF_MODE_MACRO 1
104 #define SENSOR_AF_MODE_FIXED 2
105 #define SENSOR_AF_MODE_AUTO 3
106 #define SENSOR_AF_MODE_CONTINUOUS 4
107 #define SENSOR_AF_MODE_CLOSE 5
110 #if CONFIG_SENSOR_Focus
111 /* ov5642 VCM Command and Status Registers */
112 #define CMD_MAIN_Reg 0x3024
113 #define CMD_TAG_Reg 0x3025
114 #define CMD_PARA0_Reg 0x5085
115 #define CMD_PARA1_Reg 0x5084
116 #define CMD_PARA2_Reg 0x5083
117 #define CMD_PARA3_Reg 0x5082
118 #define STA_ZONE_Reg 0x3026
119 #define STA_FOCUS_Reg 0x3027
121 /* ov5642 VCM Command */
122 #define OverlayEn_Cmd 0x01
123 #define OverlayDis_Cmd 0x02
124 #define SingleFocus_Cmd 0x03
125 #define ConstFocus_Cmd 0x04
126 #define StepMode_Cmd 0x05
127 #define PauseFocus_Cmd 0x06
128 #define ReturnIdle_Cmd 0x08
129 #define SetZone_Cmd 0x10
130 #define UpdateZone_Cmd 0x12
131 #define SetMotor_Cmd 0x20
133 /* ov5642 Focus State */
134 #define S_FIRWRE 0xFF
135 #define S_STARTUP 0xfa
137 #define S_DRVICERR 0xee
139 #define S_FOCUSING 0x01
140 #define S_FOCUSED 0x02
141 #define S_CAPTURE 0x12
144 /* ov5642 Zone State */
145 #define Zone_Is_Focused(a, zone_val) (zone_val&(1<<(a-3)))
146 #define Zone_Get_ID(zone_val) (zone_val&0x03)
148 #define Zone_CenterMode 0x01
149 #define Zone_5xMode 0x02
150 #define Zone_5PlusMode 0x03
151 #define Zone_4fMode 0x04
153 #define ZoneSel_Auto 0x0b
154 #define ZoneSel_SemiAuto 0x0c
155 #define ZoneSel_Manual 0x0d
156 #define ZoneSel_Rotate 0x0e
158 /* ov5642 Step Focus Commands */
159 #define StepFocus_Near_Tag 0x01
160 #define StepFocus_Far_Tag 0x02
161 #define StepFocus_Furthest_Tag 0x03
162 #define StepFocus_Nearest_Tag 0x04
163 #define StepFocus_Spec_Tag 0x10
166 /* init 640X480 SVGA */
167 static struct reginfo sensor_init_data[] =
237 {0x4300 , 0x32}, //UYVY
809 /* 2592X1944 QSXGA */
810 static struct reginfo sensor_qsxga[] =
815 static struct reginfo sensor_qxga[] =
821 static struct reginfo sensor_uxga[] =
827 static struct reginfo sensor_sxga[] =
833 static struct reginfo sensor_svga[] =
866 static struct reginfo sensor_vga[] =
872 static struct reginfo sensor_cif[] =
903 static struct reginfo sensor_qvga[] =
909 static struct reginfo sensor_qcif[] =
940 static struct reginfo ov2655_qqvga[] =
984 static struct reginfo ov2655_Sharpness_auto[] =
989 static struct reginfo ov2655_Sharpness1[] =
995 static struct reginfo ov2655_Sharpness2[][3] =
1002 static struct reginfo ov2655_Sharpness3[] =
1008 static struct reginfo ov2655_Sharpness4[]=
1015 static struct reginfo ov2655_Sharpness5[] =
1023 static struct reginfo sensor_ClrFmt_YUYV[]=
1029 static struct reginfo sensor_ClrFmt_UYVY[]=
1036 #if CONFIG_SENSOR_WhiteBalance
1037 static struct reginfo sensor_WhiteB_Auto[]=
1045 /* Cloudy Colour Temperature : 6500K - 8000K */
1046 static struct reginfo sensor_WhiteB_Cloudy[]=
1057 /* ClearDay Colour Temperature : 5000K - 6500K */
1058 static struct reginfo sensor_WhiteB_ClearDay[]=
1070 /* Office Colour Temperature : 3500K - 5000K */
1071 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
1084 /* Home Colour Temperature : 2500K - 3500K */
1085 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
1097 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1098 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1102 #if CONFIG_SENSOR_Brightness
1103 static struct reginfo sensor_Brightness0[]=
1108 static struct reginfo sensor_Brightness1[]=
1113 static struct reginfo sensor_Brightness2[]=
1118 static struct reginfo sensor_Brightness3[]=
1123 static struct reginfo sensor_Brightness4[]=
1128 static struct reginfo sensor_Brightness5[]=
1132 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1133 sensor_Brightness4, sensor_Brightness5,NULL,
1138 #if CONFIG_SENSOR_Effect
1139 static struct reginfo sensor_Effect_Normal[] =
1146 static struct reginfo sensor_Effect_WandB[] =
1155 static struct reginfo sensor_Effect_Sepia[] =
1164 static struct reginfo sensor_Effect_Negative[] =
1171 static struct reginfo sensor_Effect_Bluish[] =
1181 static struct reginfo sensor_Effect_Green[] =
1190 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1191 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1194 #if CONFIG_SENSOR_Exposure
1195 static struct reginfo sensor_Exposure0[]=
1200 static struct reginfo sensor_Exposure1[]=
1205 static struct reginfo sensor_Exposure2[]=
1210 static struct reginfo sensor_Exposure3[]=
1215 static struct reginfo sensor_Exposure4[]=
1220 static struct reginfo sensor_Exposure5[]=
1225 static struct reginfo sensor_Exposure6[]=
1230 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1231 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1234 #if CONFIG_SENSOR_Saturation
1235 static struct reginfo sensor_Saturation0[]=
1240 static struct reginfo sensor_Saturation1[]=
1245 static struct reginfo sensor_Saturation2[]=
1249 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1252 #if CONFIG_SENSOR_Contrast
1253 static struct reginfo sensor_Contrast0[]=
1258 static struct reginfo sensor_Contrast1[]=
1263 static struct reginfo sensor_Contrast2[]=
1268 static struct reginfo sensor_Contrast3[]=
1273 static struct reginfo sensor_Contrast4[]=
1279 static struct reginfo sensor_Contrast5[]=
1284 static struct reginfo sensor_Contrast6[]=
1288 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1289 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1293 #if CONFIG_SENSOR_Mirror
1294 static struct reginfo sensor_MirrorOn[]=
1299 static struct reginfo sensor_MirrorOff[]=
1303 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1305 #if CONFIG_SENSOR_Flip
1306 static struct reginfo sensor_FlipOn[]=
1311 static struct reginfo sensor_FlipOff[]=
1315 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1318 #if CONFIG_SENSOR_Scene
1319 static struct reginfo sensor_SceneAuto[] =
1326 static struct reginfo sensor_SceneNight[] =
1329 //15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mzh pclk
1347 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1350 #if CONFIG_SENSOR_DigitalZoom
1351 static struct reginfo sensor_Zoom0[] =
1356 static struct reginfo sensor_Zoom1[] =
1361 static struct reginfo sensor_Zoom2[] =
1367 static struct reginfo sensor_Zoom3[] =
1371 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
1373 static const struct v4l2_querymenu sensor_menus[] =
1375 #if CONFIG_SENSOR_WhiteBalance
1376 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1377 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1378 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1381 #if CONFIG_SENSOR_Effect
1382 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1383 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1384 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1387 #if CONFIG_SENSOR_Scene
1388 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1391 #if CONFIG_SENSOR_Flash
1392 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1393 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1397 static const struct v4l2_queryctrl sensor_controls[] =
1399 #if CONFIG_SENSOR_WhiteBalance
1401 .id = V4L2_CID_DO_WHITE_BALANCE,
1402 .type = V4L2_CTRL_TYPE_MENU,
1403 .name = "White Balance Control",
1411 #if CONFIG_SENSOR_Brightness
1413 .id = V4L2_CID_BRIGHTNESS,
1414 .type = V4L2_CTRL_TYPE_INTEGER,
1415 .name = "Brightness Control",
1423 #if CONFIG_SENSOR_Effect
1425 .id = V4L2_CID_EFFECT,
1426 .type = V4L2_CTRL_TYPE_MENU,
1427 .name = "Effect Control",
1435 #if CONFIG_SENSOR_Exposure
1437 .id = V4L2_CID_EXPOSURE,
1438 .type = V4L2_CTRL_TYPE_INTEGER,
1439 .name = "Exposure Control",
1447 #if CONFIG_SENSOR_Saturation
1449 .id = V4L2_CID_SATURATION,
1450 .type = V4L2_CTRL_TYPE_INTEGER,
1451 .name = "Saturation Control",
1459 #if CONFIG_SENSOR_Contrast
1461 .id = V4L2_CID_CONTRAST,
1462 .type = V4L2_CTRL_TYPE_INTEGER,
1463 .name = "Contrast Control",
1471 #if CONFIG_SENSOR_Mirror
1473 .id = V4L2_CID_HFLIP,
1474 .type = V4L2_CTRL_TYPE_BOOLEAN,
1475 .name = "Mirror Control",
1483 #if CONFIG_SENSOR_Flip
1485 .id = V4L2_CID_VFLIP,
1486 .type = V4L2_CTRL_TYPE_BOOLEAN,
1487 .name = "Flip Control",
1495 #if CONFIG_SENSOR_Scene
1497 .id = V4L2_CID_SCENE,
1498 .type = V4L2_CTRL_TYPE_MENU,
1499 .name = "Scene Control",
1507 #if CONFIG_SENSOR_DigitalZoom
1509 .id = V4L2_CID_ZOOM_RELATIVE,
1510 .type = V4L2_CTRL_TYPE_INTEGER,
1511 .name = "DigitalZoom Control",
1517 .id = V4L2_CID_ZOOM_ABSOLUTE,
1518 .type = V4L2_CTRL_TYPE_INTEGER,
1519 .name = "DigitalZoom Control",
1527 #ifdef CONFIG_SENSOR_Focus
1529 .id = V4L2_CID_FOCUS_RELATIVE,
1530 .type = V4L2_CTRL_TYPE_INTEGER,
1531 .name = "Focus Control",
1537 .id = V4L2_CID_FOCUS_ABSOLUTE,
1538 .type = V4L2_CTRL_TYPE_INTEGER,
1539 .name = "Focus Control",
1543 .default_value = 125,
1546 .id = V4L2_CID_FOCUS_AUTO,
1547 .type = V4L2_CTRL_TYPE_BOOLEAN,
1548 .name = "Focus Control",
1554 .id = V4L2_CID_FOCUS_CONTINUOUS,
1555 .type = V4L2_CTRL_TYPE_BOOLEAN,
1556 .name = "Focus Control",
1564 #if CONFIG_SENSOR_Flash
1566 .id = V4L2_CID_FLASH,
1567 .type = V4L2_CTRL_TYPE_MENU,
1568 .name = "Flash Control",
1577 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1578 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1579 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1580 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1581 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1582 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1583 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1584 static int sensor_resume(struct soc_camera_device *icd);
1585 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1586 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1588 static struct soc_camera_ops sensor_ops =
1590 .suspend = sensor_suspend,
1591 .resume = sensor_resume,
1592 .set_bus_param = sensor_set_bus_param,
1593 .query_bus_param = sensor_query_bus_param,
1594 .controls = sensor_controls,
1595 .menus = sensor_menus,
1596 .num_controls = ARRAY_SIZE(sensor_controls),
1597 .num_menus = ARRAY_SIZE(sensor_menus),
1600 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1601 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1602 .colorspace = _colorspace }
1604 #define JPG_FMT(_name, _depth, _fourcc) \
1605 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1607 static const struct soc_camera_data_format sensor_colour_formats[] = {
1608 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1609 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1612 typedef struct sensor_info_priv_s
1625 unsigned char mirror; /* HFLIP */
1626 unsigned char flip; /* VFLIP */
1627 unsigned int winseqe_cur_addr;
1628 unsigned int pixfmt;
1629 unsigned int funmodule_state;
1630 } sensor_info_priv_t;
1634 struct v4l2_subdev subdev;
1635 struct i2c_client *client;
1636 sensor_info_priv_t info_priv;
1637 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1640 static struct sensor* to_sensor(const struct i2c_client *client)
1642 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1645 /* sensor register write */
1646 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1650 struct i2c_msg msg[1];
1653 buf[1] = reg & 0xFF;
1656 msg->addr = client->addr;
1657 msg->flags = client->flags;
1659 msg->len = sizeof(buf);
1660 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1661 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1666 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1667 err = i2c_transfer(client->adapter, msg, 1);
1672 SENSOR_TR("\n %s write reg failed, try to write again!\n",SENSOR_NAME_STRING());
1680 /* sensor register read */
1681 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1685 struct i2c_msg msg[2];
1688 buf[1] = reg & 0xFF;
1690 msg[0].addr = client->addr;
1691 msg[0].flags = client->flags;
1693 msg[0].len = sizeof(buf);
1694 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1695 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1697 msg[1].addr = client->addr;
1698 msg[1].flags = client->flags|I2C_M_RD;
1701 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1702 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1706 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1707 err = i2c_transfer(client->adapter, msg, 2);
1713 SENSOR_TR("\n %s read reg failed, try to read again! reg:0x%x \n",SENSOR_NAME_STRING(),(unsigned int)val);
1721 /* write a array of registers */
1722 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1728 while (regarray[i].reg != 0)
1730 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1734 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1738 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1746 #if CONFIG_SENSOR_Focus
1753 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
1756 char read_tag=0xff,cnt;
1759 if (cmdinfo->validate_bit & 0x80) {
1760 if (sensor_write(client, CMD_TAG_Reg, cmdinfo->cmd_tag)) {
1761 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
1762 goto sensor_af_cmdset_err;
1764 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
1766 for (i=0; i<4; i++) {
1767 if (cmdinfo->validate_bit & (1<<i)) {
1768 if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
1769 SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
1770 goto sensor_af_cmdset_err;
1772 SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
1776 if (sensor_write(client, CMD_TAG_Reg, 0xff)) {
1777 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
1778 goto sensor_af_cmdset_err;
1780 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
1783 if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
1784 SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
1785 goto sensor_af_cmdset_err;
1792 if (sensor_read(client,CMD_TAG_Reg,&read_tag)){
1793 SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
1796 } while((read_tag != 0x00)&& (cnt++<100));
1798 SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
1800 sensor_af_cmdset_err:
1804 static int sensor_af_idlechk(struct i2c_client *client)
1812 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1814 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1816 goto sensor_af_idlechk_end;
1819 if (state != S_IDLE) {
1820 sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
1824 } while((state != S_IDLE)&& (cnt<100));
1826 ret = (state == S_IDLE) ? 0 : -1;
1828 sensor_af_idlechk_end:
1832 static int sensor_af_single(struct i2c_client *client)
1837 if (sensor_af_idlechk(client))
1838 goto sensor_af_single_end;
1840 if (sensor_af_cmdset(client, SingleFocus_Cmd, NULL)) {
1841 SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
1843 goto sensor_af_single_end;
1853 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1855 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1857 goto sensor_af_single_end;
1859 }while((state == S_FOCUSING) && (cnt<100));
1861 if (state != S_FOCUSED) {
1862 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
1864 goto sensor_af_single_end;
1867 sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
1868 sensor_af_single_end:
1872 static int sensor_af_const(struct i2c_client *client)
1876 if (sensor_af_idlechk(client))
1877 goto sensor_af_const_end;
1879 if (sensor_af_cmdset(client, ConstFocus_Cmd, NULL)) {
1880 SENSOR_TR("%s const focus mode set error!\n",SENSOR_NAME_STRING());
1882 goto sensor_af_const_end;
1884 sensor_af_const_end:
1887 static int sensor_af_pause2capture(struct i2c_client *client)
1892 if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
1893 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
1895 goto sensor_af_pause_end;
1905 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1907 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1909 goto sensor_af_pause_end;
1911 }while((state != S_CAPTURE) && (cnt<100));
1913 if (state != S_CAPTURE) {
1914 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
1916 goto sensor_af_pause_end;
1918 sensor_af_pause_end:
1921 static int sensor_af_zoneupdate(struct i2c_client *client)
1925 if (sensor_af_idlechk(client))
1926 goto sensor_af_zoneupdate_end;
1928 if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
1929 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
1931 goto sensor_af_zoneupdate_end;
1934 sensor_af_zoneupdate_end:
1937 static int sensor_af_init(struct i2c_client *client)
1942 ret = sensor_write_array(client, sensor_af_firmware);
1944 SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
1946 goto sensor_af_init_end;
1956 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1958 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1960 goto sensor_af_init_end;
1962 }while((state == S_STARTUP) && (cnt<100));
1964 if (state != S_IDLE) {
1965 SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
1967 goto sensor_af_init_end;
1970 if (sensor_af_single(client)) {
1972 goto sensor_af_init_end;
1976 SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
1980 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1982 struct i2c_client *client = sd->priv;
1983 struct soc_camera_device *icd = client->dev.platform_data;
1984 struct sensor *sensor = to_sensor(client);
1985 const struct v4l2_queryctrl *qctrl;
1989 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1992 ret = sensor_write(client, 0x3008, 0x80);
1994 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1996 goto sensor_INIT_ERR;
1999 mdelay(5); //delay 5 microseconds
2000 /* check if it is an sensor sensor */
2001 ret = sensor_read(client, 0x300a, &value);
2003 SENSOR_TR("read chip id high byte failed\n");
2005 goto sensor_INIT_ERR;
2008 pid |= (value << 8);
2010 ret = sensor_read(client, 0x300b, &value);
2012 SENSOR_TR("read chip id low byte failed\n");
2014 goto sensor_INIT_ERR;
2017 pid |= (value & 0xff);
2018 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2019 if (pid == SENSOR_ID) {
2020 sensor->model = SENSOR_V4L2_IDENT;
2022 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2024 goto sensor_INIT_ERR;
2027 ret = sensor_write_array(client, sensor_init_data);
2030 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2031 goto sensor_INIT_ERR;
2034 icd->user_width = SENSOR_INIT_WIDTH;
2035 icd->user_height = SENSOR_INIT_HEIGHT;
2036 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2037 sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
2039 /* sensor sensor information for initialization */
2040 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2042 sensor->info_priv.whiteBalance = qctrl->default_value;
2043 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2045 sensor->info_priv.brightness = qctrl->default_value;
2046 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2048 sensor->info_priv.effect = qctrl->default_value;
2049 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2051 sensor->info_priv.exposure = qctrl->default_value;
2053 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2055 sensor->info_priv.saturation = qctrl->default_value;
2056 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2058 sensor->info_priv.contrast = qctrl->default_value;
2059 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2061 sensor->info_priv.mirror = qctrl->default_value;
2062 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2064 sensor->info_priv.flip = qctrl->default_value;
2065 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2067 sensor->info_priv.scene = qctrl->default_value;
2068 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2070 sensor->info_priv.digitalzoom = qctrl->default_value;
2072 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2073 #if CONFIG_SENSOR_Focus
2074 if (sensor_af_init(client)) {
2075 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
2077 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
2078 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2080 sensor->info_priv.focus = qctrl->default_value;
2085 #if CONFIG_SENSOR_Flash
2086 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2088 sensor->info_priv.flash = qctrl->default_value;
2091 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,icd->user_width,icd->user_height);
2097 static int sensor_deactivate(struct v4l2_subdev *sd)
2099 struct i2c_client *client = sd->priv;
2101 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2103 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2104 sensor_write(client, 0x3017, 0x00); // FREX,VSYNC,HREF,PCLK,D9-D6
2105 sensor_write(client, 0x3018, 0x03); // D5-D0
2106 sensor_write(client,0x3019,0X00); // STROBE,SDA
2110 static struct reginfo sensor_power_down_sequence[]=
2114 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2117 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2118 struct soc_camera_link *icl;
2121 if (pm_msg.event == PM_EVENT_SUSPEND)
2123 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2124 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2127 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2132 icl = to_soc_camera_link(icd);
2134 ret = icl->power(icd->pdev, 0);
2136 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2144 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2150 static int sensor_resume(struct soc_camera_device *icd)
2152 struct soc_camera_link *icl;
2155 icl = to_soc_camera_link(icd);
2157 ret = icl->power(icd->pdev, 1);
2159 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2164 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2170 static int sensor_set_bus_param(struct soc_camera_device *icd,
2171 unsigned long flags)
2177 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2179 struct soc_camera_link *icl = to_soc_camera_link(icd);
2180 unsigned long flags = SENSOR_BUS_PARAM;
2182 return soc_camera_apply_sensor_flags(icl, flags);
2185 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2187 struct i2c_client *client = sd->priv;
2188 struct soc_camera_device *icd = client->dev.platform_data;
2189 struct sensor *sensor = to_sensor(client);
2190 struct v4l2_pix_format *pix = &f->fmt.pix;
2192 pix->width = icd->user_width;
2193 pix->height = icd->user_height;
2194 pix->pixelformat = sensor->info_priv.pixfmt;
2195 pix->field = V4L2_FIELD_NONE;
2196 pix->colorspace = V4L2_COLORSPACE_JPEG;
2200 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2202 struct i2c_client *client = sd->priv;
2203 struct sensor *sensor = to_sensor(client);
2204 struct v4l2_pix_format *pix = &f->fmt.pix;
2205 struct reginfo *winseqe_set_addr=NULL;
2206 int ret = 0, set_w,set_h;
2208 if (sensor->info_priv.pixfmt != pix->pixelformat) {
2209 switch (pix->pixelformat)
2211 case V4L2_PIX_FMT_YUYV:
2213 winseqe_set_addr = sensor_ClrFmt_YUYV;
2216 case V4L2_PIX_FMT_UYVY:
2218 winseqe_set_addr = sensor_ClrFmt_UYVY;
2224 if (winseqe_set_addr != NULL) {
2225 sensor_write_array(client, winseqe_set_addr);
2226 sensor->info_priv.pixfmt = pix->pixelformat;
2228 SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
2230 SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
2235 set_h = pix->height;
2237 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2239 winseqe_set_addr = sensor_qcif;
2243 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2245 winseqe_set_addr = sensor_qvga;
2249 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2251 winseqe_set_addr = sensor_cif;
2255 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2257 winseqe_set_addr = sensor_vga;
2261 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2263 winseqe_set_addr = sensor_svga;
2267 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2269 winseqe_set_addr = sensor_sxga;
2273 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2275 winseqe_set_addr = sensor_uxga;
2279 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_qxga[0].reg)
2281 winseqe_set_addr = sensor_qxga;
2285 else if (((set_w <= 2592) && (set_h <= 1944)) && sensor_qsxga[0].reg)
2287 winseqe_set_addr = sensor_qsxga;
2293 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2294 set_w = SENSOR_INIT_WIDTH;
2295 set_h = SENSOR_INIT_HEIGHT;
2297 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
2300 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
2302 ret |= sensor_write_array(client, winseqe_set_addr);
2304 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2305 goto sensor_s_fmt_end;
2308 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2309 //#if CONFIG_SENSOR_Focus
2310 //sensor_af_zoneupdate(client);
2314 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2318 SENSOR_TR("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2322 pix->height = set_h;
2327 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2329 struct v4l2_pix_format *pix = &f->fmt.pix;
2330 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
2331 pix->pixelformat == V4L2_PIX_FMT_YUYV;
2334 * With Bayer format enforce even side lengths, but let the user play
2335 * with the starting pixel
2338 if (pix->height > SENSOR_MAX_HEIGHT)
2339 pix->height = SENSOR_MAX_HEIGHT;
2340 else if (pix->height < SENSOR_MIN_HEIGHT)
2341 pix->height = SENSOR_MIN_HEIGHT;
2343 pix->height = ALIGN(pix->height, 2);
2345 if (pix->width > SENSOR_MAX_WIDTH)
2346 pix->width = SENSOR_MAX_WIDTH;
2347 else if (pix->width < SENSOR_MIN_WIDTH)
2348 pix->width = SENSOR_MIN_WIDTH;
2350 pix->width = ALIGN(pix->width, 2);
2355 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2357 struct i2c_client *client = sd->priv;
2359 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2362 if (id->match.addr != client->addr)
2365 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2370 #if CONFIG_SENSOR_Brightness
2371 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2373 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2375 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2377 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2379 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2381 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2384 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2388 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2392 #if CONFIG_SENSOR_Effect
2393 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2395 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2397 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2399 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2401 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2403 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2406 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2410 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2414 #if CONFIG_SENSOR_Exposure
2415 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2417 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2419 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2421 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2423 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2425 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2428 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2432 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2436 #if CONFIG_SENSOR_Saturation
2437 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2439 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2441 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2443 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2445 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2447 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2450 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2454 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2458 #if CONFIG_SENSOR_Contrast
2459 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2461 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2463 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2465 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2467 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 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);
2476 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2480 #if CONFIG_SENSOR_Mirror
2481 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2483 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2485 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2487 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2489 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2491 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2494 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2498 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2502 #if CONFIG_SENSOR_Flip
2503 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2505 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2507 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2509 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2511 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2513 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2516 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2520 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2524 #if CONFIG_SENSOR_Scene
2525 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2527 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2529 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2531 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2533 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2535 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2538 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2542 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2546 #if CONFIG_SENSOR_WhiteBalance
2547 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2549 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2551 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2553 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2555 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2557 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2560 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2564 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2568 #if CONFIG_SENSOR_DigitalZoom
2569 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2571 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2572 struct sensor *sensor = to_sensor(client);
2573 const struct v4l2_queryctrl *qctrl_info;
2574 int digitalzoom_cur, digitalzoom_total;
2576 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2580 digitalzoom_cur = sensor->info_priv.digitalzoom;
2581 digitalzoom_total = qctrl_info->maximum;
2583 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2585 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2589 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2591 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2595 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2597 *value = digitalzoom_total - digitalzoom_cur;
2600 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2602 *value = 0 - digitalzoom_cur;
2605 digitalzoom_cur += *value;
2607 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2609 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2611 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2614 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2621 #if CONFIG_SENSOR_Focus
2622 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2624 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2625 struct sensor *sensor = to_sensor(client);
2626 const struct v4l2_queryctrl *qctrl_info;
2627 struct af_cmdinfo cmdinfo;
2630 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2634 if (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) {
2635 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2637 if (sensor_af_idlechk(client))
2638 goto sensor_set_focus_absolute_end;
2640 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
2641 cmdinfo.cmd_para[0] = value;
2642 cmdinfo.validate_bit = 0x81;
2643 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
2644 //ret |= sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
2645 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2648 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2652 SENSOR_TR("\n %s..%s AF module state is error!\n",SENSOR_NAME_STRING(),__FUNCTION__);
2655 sensor_set_focus_absolute_end:
2658 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2660 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2661 struct sensor *sensor = to_sensor(client);
2662 const struct v4l2_queryctrl *qctrl_info;
2663 struct af_cmdinfo cmdinfo;
2666 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2670 if (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) {
2671 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2673 if (sensor_af_idlechk(client))
2674 goto sensor_set_focus_relative_end;
2677 cmdinfo.cmd_tag = StepFocus_Near_Tag;
2678 } else if (value < 0) {
2679 cmdinfo.cmd_tag = StepFocus_Far_Tag;
2681 cmdinfo.validate_bit = 0x80;
2682 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
2684 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2687 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2691 SENSOR_TR("\n %s..%s AF module state is error!\n",SENSOR_NAME_STRING(),__FUNCTION__);
2693 sensor_set_focus_relative_end:
2697 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2699 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2700 struct sensor *sensor = to_sensor(client);
2703 if (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) {
2706 case SENSOR_AF_MODE_AUTO:
2708 ret = sensor_af_single(client);
2712 case SENSOR_AF_MODE_MACRO:
2714 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2718 case SENSOR_AF_MODE_INFINITY:
2720 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2724 case SENSOR_AF_MODE_CONTINUOUS:
2726 ret = sensor_af_const(client);
2730 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2735 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2738 SENSOR_TR("\n %s..%s AF module state is error!\n",SENSOR_NAME_STRING(),__FUNCTION__);
2744 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2746 struct i2c_client *client = sd->priv;
2747 struct sensor *sensor = to_sensor(client);
2748 const struct v4l2_queryctrl *qctrl;
2750 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2754 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2760 case V4L2_CID_BRIGHTNESS:
2762 ctrl->value = sensor->info_priv.brightness;
2765 case V4L2_CID_SATURATION:
2767 ctrl->value = sensor->info_priv.saturation;
2770 case V4L2_CID_CONTRAST:
2772 ctrl->value = sensor->info_priv.contrast;
2775 case V4L2_CID_DO_WHITE_BALANCE:
2777 ctrl->value = sensor->info_priv.whiteBalance;
2780 case V4L2_CID_EXPOSURE:
2782 ctrl->value = sensor->info_priv.exposure;
2785 case V4L2_CID_HFLIP:
2787 ctrl->value = sensor->info_priv.mirror;
2790 case V4L2_CID_VFLIP:
2792 ctrl->value = sensor->info_priv.flip;
2803 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2805 struct i2c_client *client = sd->priv;
2806 struct sensor *sensor = to_sensor(client);
2807 struct soc_camera_device *icd = client->dev.platform_data;
2808 const struct v4l2_queryctrl *qctrl;
2811 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2815 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2821 #if CONFIG_SENSOR_Brightness
2822 case V4L2_CID_BRIGHTNESS:
2824 if (ctrl->value != sensor->info_priv.brightness)
2826 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2830 sensor->info_priv.brightness = ctrl->value;
2835 #if CONFIG_SENSOR_Exposure
2836 case V4L2_CID_EXPOSURE:
2838 if (ctrl->value != sensor->info_priv.exposure)
2840 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2844 sensor->info_priv.exposure = ctrl->value;
2849 #if CONFIG_SENSOR_Saturation
2850 case V4L2_CID_SATURATION:
2852 if (ctrl->value != sensor->info_priv.saturation)
2854 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2858 sensor->info_priv.saturation = ctrl->value;
2863 #if CONFIG_SENSOR_Contrast
2864 case V4L2_CID_CONTRAST:
2866 if (ctrl->value != sensor->info_priv.contrast)
2868 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2872 sensor->info_priv.contrast = ctrl->value;
2877 #if CONFIG_SENSOR_WhiteBalance
2878 case V4L2_CID_DO_WHITE_BALANCE:
2880 if (ctrl->value != sensor->info_priv.whiteBalance)
2882 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2886 sensor->info_priv.whiteBalance = ctrl->value;
2891 #if CONFIG_SENSOR_Mirror
2892 case V4L2_CID_HFLIP:
2894 if (ctrl->value != sensor->info_priv.mirror)
2896 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2898 sensor->info_priv.mirror = ctrl->value;
2903 #if CONFIG_SENSOR_Flip
2904 case V4L2_CID_VFLIP:
2906 if (ctrl->value != sensor->info_priv.flip)
2908 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2910 sensor->info_priv.flip = ctrl->value;
2921 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2923 const struct v4l2_queryctrl *qctrl;
2924 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2925 struct sensor *sensor = to_sensor(client);
2927 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2931 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2935 switch (ext_ctrl->id)
2937 case V4L2_CID_SCENE:
2939 ext_ctrl->value = sensor->info_priv.scene;
2942 case V4L2_CID_EFFECT:
2944 ext_ctrl->value = sensor->info_priv.effect;
2947 case V4L2_CID_ZOOM_ABSOLUTE:
2949 ext_ctrl->value = sensor->info_priv.digitalzoom;
2952 case V4L2_CID_ZOOM_RELATIVE:
2956 case V4L2_CID_FOCUS_ABSOLUTE:
2960 case V4L2_CID_FOCUS_RELATIVE:
2964 case V4L2_CID_FLASH:
2966 ext_ctrl->value = sensor->info_priv.flash;
2974 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2976 const struct v4l2_queryctrl *qctrl;
2977 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2978 struct sensor *sensor = to_sensor(client);
2981 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2985 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2990 switch (ext_ctrl->id)
2992 #if CONFIG_SENSOR_Scene
2993 case V4L2_CID_SCENE:
2995 if (ext_ctrl->value != sensor->info_priv.scene)
2997 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2999 sensor->info_priv.scene = ext_ctrl->value;
3004 #if CONFIG_SENSOR_Effect
3005 case V4L2_CID_EFFECT:
3007 if (ext_ctrl->value != sensor->info_priv.effect)
3009 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3011 sensor->info_priv.effect= ext_ctrl->value;
3016 #if CONFIG_SENSOR_DigitalZoom
3017 case V4L2_CID_ZOOM_ABSOLUTE:
3019 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3022 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3024 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3026 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3028 sensor->info_priv.digitalzoom += val_offset;
3030 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3035 case V4L2_CID_ZOOM_RELATIVE:
3037 if (ext_ctrl->value)
3039 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3041 sensor->info_priv.digitalzoom += ext_ctrl->value;
3043 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3048 #if CONFIG_SENSOR_Focus
3049 case V4L2_CID_FOCUS_ABSOLUTE:
3051 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3054 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
3055 if (ext_ctrl->value == qctrl->minimum) {
3056 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
3057 } else if (ext_ctrl->value == qctrl->maximum) {
3058 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
3060 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
3066 case V4L2_CID_FOCUS_RELATIVE:
3068 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3071 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
3074 case V4L2_CID_FOCUS_AUTO:
3076 if (ext_ctrl->value == 1) {
3077 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
3079 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
3080 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
3081 if (ext_ctrl->value == 0)
3082 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3086 case V4L2_CID_FOCUS_CONTINUOUS:
3088 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
3089 if (ext_ctrl->value == 1) {
3090 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
3092 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
3095 if (ext_ctrl->value == 0)
3096 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3101 #if CONFIG_SENSOR_Flash
3102 case V4L2_CID_FLASH:
3104 sensor->info_priv.flash = ext_ctrl->value;
3106 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3117 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3119 struct i2c_client *client = sd->priv;
3120 struct soc_camera_device *icd = client->dev.platform_data;
3121 int i, error_cnt=0, error_idx=-1;
3124 for (i=0; i<ext_ctrl->count; i++) {
3125 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3132 error_idx = ext_ctrl->count;
3134 if (error_idx != -1) {
3135 ext_ctrl->error_idx = error_idx;
3142 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3144 struct i2c_client *client = sd->priv;
3145 struct soc_camera_device *icd = client->dev.platform_data;
3146 int i, error_cnt=0, error_idx=-1;
3148 for (i=0; i<ext_ctrl->count; i++) {
3149 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3156 error_idx = ext_ctrl->count;
3158 if (error_idx != -1) {
3159 ext_ctrl->error_idx = error_idx;
3166 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3167 * this wasn't our capture interface, so, we wait for the right one */
3168 static int sensor_video_probe(struct soc_camera_device *icd,
3169 struct i2c_client *client)
3173 struct sensor *sensor = to_sensor(client);
3175 /* We must have a parent by now. And it cannot be a wrong one.
3176 * So this entire test is completely redundant. */
3177 if (!icd->dev.parent ||
3178 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3182 ret = sensor_write(client, 0x3012, 0x80);
3185 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3188 mdelay(5); //delay 5 microseconds
3190 /* check if it is an sensor sensor */
3191 ret = sensor_read(client, 0x300a, &value);
3193 SENSOR_TR("read chip id high byte failed\n");
3195 goto sensor_video_probe_err;
3198 pid |= (value << 8);
3200 ret = sensor_read(client, 0x300b, &value);
3202 SENSOR_TR("read chip id low byte failed\n");
3204 goto sensor_video_probe_err;
3207 pid |= (value & 0xff);
3208 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3209 if (pid == SENSOR_ID) {
3210 sensor->model = SENSOR_V4L2_IDENT;
3212 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3214 goto sensor_video_probe_err;
3217 icd->formats = sensor_colour_formats;
3218 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
3222 sensor_video_probe_err:
3226 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3228 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3231 case RK29_CAM_SUBDEV_DEACTIVATE:
3233 sensor_deactivate(sd);
3244 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3245 .init = sensor_init,
3246 .g_ctrl = sensor_g_control,
3247 .s_ctrl = sensor_s_control,
3248 .g_ext_ctrls = sensor_g_ext_controls,
3249 .s_ext_ctrls = sensor_s_ext_controls,
3250 .g_chip_ident = sensor_g_chip_ident,
3251 .ioctl = sensor_ioctl,
3254 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3255 .s_fmt = sensor_s_fmt,
3256 .g_fmt = sensor_g_fmt,
3257 .try_fmt = sensor_try_fmt,
3260 static struct v4l2_subdev_ops sensor_subdev_ops = {
3261 .core = &sensor_subdev_core_ops,
3262 .video = &sensor_subdev_video_ops,
3265 static int sensor_probe(struct i2c_client *client,
3266 const struct i2c_device_id *did)
3268 struct sensor *sensor;
3269 struct soc_camera_device *icd = client->dev.platform_data;
3270 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3271 struct soc_camera_link *icl;
3274 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3276 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3280 icl = to_soc_camera_link(icd);
3282 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3286 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3287 dev_warn(&adapter->dev,
3288 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3292 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3296 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3298 /* Second stage probe - when a capture adapter is there */
3299 icd->ops = &sensor_ops;
3300 icd->y_skip_top = 0;
3302 ret = sensor_video_probe(icd, client);
3305 i2c_set_clientdata(client, NULL);
3308 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3312 static int sensor_remove(struct i2c_client *client)
3314 struct sensor *sensor = to_sensor(client);
3315 struct soc_camera_device *icd = client->dev.platform_data;
3318 i2c_set_clientdata(client, NULL);
3319 client->driver = NULL;
3325 static const struct i2c_device_id sensor_id[] = {
3326 {SENSOR_NAME_STRING(), 0 },
3329 MODULE_DEVICE_TABLE(i2c, sensor_id);
3331 static struct i2c_driver sensor_i2c_driver = {
3333 .name = SENSOR_NAME_STRING(),
3335 .probe = sensor_probe,
3336 .remove = sensor_remove,
3337 .id_table = sensor_id,
3340 static int __init sensor_mod_init(void)
3342 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3343 return i2c_add_driver(&sensor_i2c_driver);
3346 static void __exit sensor_mod_exit(void)
3348 i2c_del_driver(&sensor_i2c_driver);
3351 device_initcall_sync(sensor_mod_init);
3352 module_exit(sensor_mod_exit);
3354 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3355 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3356 MODULE_LICENSE("GPL");