2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_GT2005
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_GT2005
48 #define SENSOR_ID 0x5138
49 #define SENSOR_MIN_WIDTH 640
50 #define SENSOR_MIN_HEIGHT 480
51 #define SENSOR_MAX_WIDTH 1600
52 #define SENSOR_MAX_HEIGHT 1200
53 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT 480
55 #define SENSOR_INIT_WINSEQADR sensor_vga
56 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
58 #define CONFIG_SENSOR_WhiteBalance 1
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 1
63 #define CONFIG_SENSOR_Scene 1
64 #define CONFIG_SENSOR_DigitalZoom 0
65 #define CONFIG_SENSOR_Focus 0
66 #define CONFIG_SENSOR_Exposure 0
67 #define CONFIG_SENSOR_Flash 1
68 #define CONFIG_SENSOR_Mirror 0
69 #define CONFIG_SENSOR_Flip 0
71 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
72 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
73 #define CONFIG_SENSOR_I2C_NOSCHED 0
74 #define CONFIG_SENSOR_I2C_RDWRCHK 0
76 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
77 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
78 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
80 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
81 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
82 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
83 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
84 #define COLOR_TEMPERATURE_OFFICE_DN 3500
85 #define COLOR_TEMPERATURE_OFFICE_UP 5000
86 #define COLOR_TEMPERATURE_HOME_DN 2500
87 #define COLOR_TEMPERATURE_HOME_UP 3500
89 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
90 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
92 #define SENSOR_AF_IS_ERR (0x00<<0)
93 #define SENSOR_AF_IS_OK (0x01<<0)
94 #define SENSOR_INIT_IS_ERR (0x00<<28)
95 #define SENSOR_INIT_IS_OK (0x01<<28)
103 //flash off in fixed time to prevent from too hot , zyc
105 struct soc_camera_device *icd;
106 struct hrtimer timer;
108 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
110 static struct flash_timer flash_off_timer;
111 //for user defined if user want to customize the series , zyc
112 #ifdef CONFIG_GT2005_USER_DEFINED_SERIES
113 #include "gt2005_user_series.c"
115 /* init 352X288 SVGA */
116 static struct reginfo sensor_init_data[] =
571 ///////////////////////////
605 static struct reginfo sensor_uxga[] =
622 static struct reginfo sensor_sxga[] =
637 static struct reginfo sensor_svga[] =
1119 static struct reginfo sensor_vga[] =
1156 static struct reginfo sensor_cif[] =
1162 static struct reginfo sensor_qvga[] =
1170 static struct reginfo sensor_qcif[] =
1178 static struct reginfo gt2005_qqvga[] =
1222 static struct reginfo gt2005_Sharpness_auto[] =
1227 static struct reginfo gt2005_Sharpness1[] =
1233 static struct reginfo gt2005_Sharpness2[][3] =
1240 static struct reginfo gt2005_Sharpness3[] =
1246 static struct reginfo gt2005_Sharpness4[]=
1253 static struct reginfo gt2005_Sharpness5[] =
1261 static struct reginfo sensor_ClrFmt_YUYV[]=
1267 static struct reginfo sensor_ClrFmt_UYVY[]=
1273 #if CONFIG_SENSOR_WhiteBalance
1274 static struct reginfo sensor_WhiteB_Auto[]=
1276 {0x3306, 0x00}, //AWB auto, bit[1]:0,auto
1279 /* Cloudy Colour Temperature : 6500K - 8000K */
1280 static struct reginfo sensor_WhiteB_Cloudy[]=
1288 /* ClearDay Colour Temperature : 5000K - 6500K */
1289 static struct reginfo sensor_WhiteB_ClearDay[]=
1292 {0x3306, 0x02}, //AWB off
1298 /* Office Colour Temperature : 3500K - 5000K */
1299 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
1309 /* Home Colour Temperature : 2500K - 3500K */
1310 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
1319 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1320 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1324 #if CONFIG_SENSOR_Brightness
1325 static struct reginfo sensor_Brightness0[]=
1328 {0x3301, 0xff},//bit[7]:1, enable SDE
1335 static struct reginfo sensor_Brightness1[]=
1338 {0x3301, 0xff},//bit[7]:1, enable SDE
1345 static struct reginfo sensor_Brightness2[]=
1348 {0x3301, 0xff},//bit[7]:1, enable SDE
1355 static struct reginfo sensor_Brightness3[]=
1358 {0x3301, 0xff},//bit[7]:1, enable SDE
1365 static struct reginfo sensor_Brightness4[]=
1368 {0x3301, 0xff},//bit[7]:1, enable SDE
1375 static struct reginfo sensor_Brightness5[]=
1378 {0x3301, 0xff},//bit[7]:1, enable SDE
1379 {0x3391, 0x04}, //bit[2] enable
1380 {0x3390, 0x41}, //bit[3] sign of brightness
1384 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1385 sensor_Brightness4, sensor_Brightness5,NULL,
1390 #if CONFIG_SENSOR_Effect
1391 static struct reginfo sensor_Effect_Normal[] =
1397 static struct reginfo sensor_Effect_WandB[] =
1403 static struct reginfo sensor_Effect_Sepia[] =
1411 static struct reginfo sensor_Effect_Negative[] =
1414 {0x3391, 0x40}, //bit[6] negative
1417 static struct reginfo sensor_Effect_Bluish[] =
1426 static struct reginfo sensor_Effect_Green[] =
1434 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1435 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1438 #if CONFIG_SENSOR_Exposure
1439 static struct reginfo sensor_Exposure0[]=
1449 static struct reginfo sensor_Exposure1[]=
1459 static struct reginfo sensor_Exposure2[]=
1469 static struct reginfo sensor_Exposure3[]=
1479 static struct reginfo sensor_Exposure4[]=
1489 static struct reginfo sensor_Exposure5[]=
1499 static struct reginfo sensor_Exposure6[]=
1509 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1510 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1513 #if CONFIG_SENSOR_Saturation
1514 static struct reginfo sensor_Saturation0[]=
1516 {0x3301, 0xff},//bit[7]:1, enable SDE
1523 static struct reginfo sensor_Saturation1[]=
1525 {0x3301, 0xff},//bit[7]:1, enable SDE
1532 static struct reginfo sensor_Saturation2[]=
1534 {0x3301, 0xff},//bit[7]:1, enable SDE
1535 {0x3391, 0x02}, //enable color saturation
1540 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1543 #if CONFIG_SENSOR_Contrast
1544 static struct reginfo sensor_Contrast0[]=
1547 {0x3301, 0xff},//bit[7]:1, enable SDE
1555 static struct reginfo sensor_Contrast1[]=
1558 {0x3301, 0xff},//bit[7]:1, enable SDE
1566 static struct reginfo sensor_Contrast2[]=
1569 {0x3301, 0xff},//bit[7]:1, enable SDE
1577 static struct reginfo sensor_Contrast3[]=
1580 {0x3301, 0xff},//bit[7]:1, enable SDE
1588 static struct reginfo sensor_Contrast4[]=
1591 {0x3301, 0xff},//bit[7]:1, enable SDE
1600 static struct reginfo sensor_Contrast5[]=
1603 {0x3301, 0xff},//bit[7]:1, enable SDE
1611 static struct reginfo sensor_Contrast6[]=
1614 {0x3301, 0xff},//bit[7]:1, enable SDE
1615 {0x3391, 0x04}, //bit[2] enable contrast/brightness
1616 {0x3390, 0x45}, //bit[2] Yoffset sign
1621 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1622 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1626 #if CONFIG_SENSOR_Mirror
1627 static struct reginfo sensor_MirrorOn[]=
1635 static struct reginfo sensor_MirrorOff[]=
1642 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1644 #if CONFIG_SENSOR_Flip
1645 static struct reginfo sensor_FlipOn[]=
1658 static struct reginfo sensor_FlipOff[]=
1670 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1673 #if CONFIG_SENSOR_Scene
1674 static struct reginfo sensor_SceneAuto[] =
1676 #if 0 /* ddl@rock-chips.com : */
1691 static struct reginfo sensor_SceneNight[] =
1694 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1705 {0x3015, 0x50},//add 5 dummy frame
1710 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1726 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1729 #if CONFIG_SENSOR_DigitalZoom
1730 static struct reginfo sensor_Zoom0[] =
1735 static struct reginfo sensor_Zoom1[] =
1740 static struct reginfo sensor_Zoom2[] =
1746 static struct reginfo sensor_Zoom3[] =
1750 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1752 static const struct v4l2_querymenu sensor_menus[] =
1754 #if CONFIG_SENSOR_WhiteBalance
1755 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1756 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1757 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1760 #if CONFIG_SENSOR_Effect
1761 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1762 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1763 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1766 #if CONFIG_SENSOR_Scene
1767 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1770 #if CONFIG_SENSOR_Flash
1771 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1772 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1776 static struct v4l2_queryctrl sensor_controls[] =
1778 #if CONFIG_SENSOR_WhiteBalance
1780 .id = V4L2_CID_DO_WHITE_BALANCE,
1781 .type = V4L2_CTRL_TYPE_MENU,
1782 .name = "White Balance Control",
1790 #if CONFIG_SENSOR_Brightness
1792 .id = V4L2_CID_BRIGHTNESS,
1793 .type = V4L2_CTRL_TYPE_INTEGER,
1794 .name = "Brightness Control",
1802 #if CONFIG_SENSOR_Effect
1804 .id = V4L2_CID_EFFECT,
1805 .type = V4L2_CTRL_TYPE_MENU,
1806 .name = "Effect Control",
1814 #if CONFIG_SENSOR_Exposure
1816 .id = V4L2_CID_EXPOSURE,
1817 .type = V4L2_CTRL_TYPE_INTEGER,
1818 .name = "Exposure Control",
1826 #if CONFIG_SENSOR_Saturation
1828 .id = V4L2_CID_SATURATION,
1829 .type = V4L2_CTRL_TYPE_INTEGER,
1830 .name = "Saturation Control",
1838 #if CONFIG_SENSOR_Contrast
1840 .id = V4L2_CID_CONTRAST,
1841 .type = V4L2_CTRL_TYPE_INTEGER,
1842 .name = "Contrast Control",
1850 #if CONFIG_SENSOR_Mirror
1852 .id = V4L2_CID_HFLIP,
1853 .type = V4L2_CTRL_TYPE_BOOLEAN,
1854 .name = "Mirror Control",
1862 #if CONFIG_SENSOR_Flip
1864 .id = V4L2_CID_VFLIP,
1865 .type = V4L2_CTRL_TYPE_BOOLEAN,
1866 .name = "Flip Control",
1874 #if CONFIG_SENSOR_Scene
1876 .id = V4L2_CID_SCENE,
1877 .type = V4L2_CTRL_TYPE_MENU,
1878 .name = "Scene Control",
1886 #if CONFIG_SENSOR_DigitalZoom
1888 .id = V4L2_CID_ZOOM_RELATIVE,
1889 .type = V4L2_CTRL_TYPE_INTEGER,
1890 .name = "DigitalZoom Control",
1896 .id = V4L2_CID_ZOOM_ABSOLUTE,
1897 .type = V4L2_CTRL_TYPE_INTEGER,
1898 .name = "DigitalZoom Control",
1906 #if CONFIG_SENSOR_Focus
1908 .id = V4L2_CID_FOCUS_RELATIVE,
1909 .type = V4L2_CTRL_TYPE_INTEGER,
1910 .name = "Focus Control",
1916 .id = V4L2_CID_FOCUS_ABSOLUTE,
1917 .type = V4L2_CTRL_TYPE_INTEGER,
1918 .name = "Focus Control",
1922 .default_value = 125,
1926 #if CONFIG_SENSOR_Flash
1928 .id = V4L2_CID_FLASH,
1929 .type = V4L2_CTRL_TYPE_MENU,
1930 .name = "Flash Control",
1939 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1940 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1941 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1942 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1943 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1944 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1945 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1946 static int sensor_resume(struct soc_camera_device *icd);
1947 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1948 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1949 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1950 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1951 static int sensor_deactivate(struct i2c_client *client);
1953 static struct soc_camera_ops sensor_ops =
1955 .suspend = sensor_suspend,
1956 .resume = sensor_resume,
1957 .set_bus_param = sensor_set_bus_param,
1958 .query_bus_param = sensor_query_bus_param,
1959 .controls = sensor_controls,
1960 .menus = sensor_menus,
1961 .num_controls = ARRAY_SIZE(sensor_controls),
1962 .num_menus = ARRAY_SIZE(sensor_menus),
1965 /* only one fixed colorspace per pixelcode */
1966 struct sensor_datafmt {
1967 enum v4l2_mbus_pixelcode code;
1968 enum v4l2_colorspace colorspace;
1971 /* Find a data format by a pixel code in an array */
1972 static const struct sensor_datafmt *sensor_find_datafmt(
1973 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1977 for (i = 0; i < n; i++)
1978 if (fmt[i].code == code)
1984 static const struct sensor_datafmt sensor_colour_fmts[] = {
1985 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1986 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1989 typedef struct sensor_info_priv_s
2003 unsigned char mirror; /* HFLIP */
2004 unsigned char flip; /* VFLIP */
2005 unsigned int winseqe_cur_addr;
2006 struct sensor_datafmt fmt;
2007 unsigned int funmodule_state;
2008 } sensor_info_priv_t;
2012 struct v4l2_subdev subdev;
2013 struct i2c_client *client;
2014 sensor_info_priv_t info_priv;
2015 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2016 #if CONFIG_SENSOR_I2C_NOSCHED
2017 atomic_t tasklock_cnt;
2019 struct rk29camera_platform_data *sensor_io_request;
2020 struct rk29camera_gpio_res *sensor_gpio_res;
2023 static struct sensor* to_sensor(const struct i2c_client *client)
2025 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2028 static int sensor_task_lock(struct i2c_client *client, int lock)
2030 #if CONFIG_SENSOR_I2C_NOSCHED
2032 struct sensor *sensor = to_sensor(client);
2035 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2036 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2037 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2041 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2042 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2043 goto sensor_task_lock_err;
2048 atomic_add(1, &sensor->tasklock_cnt);
2050 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2051 atomic_sub(1, &sensor->tasklock_cnt);
2053 if (atomic_read(&sensor->tasklock_cnt) == 0)
2058 sensor_task_lock_err:
2066 /* sensor register write */
2067 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2071 struct i2c_msg msg[1];
2074 buf[1] = reg & 0xFF;
2077 msg->addr = client->addr;
2078 msg->flags = client->flags;
2080 msg->len = sizeof(buf);
2081 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2082 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2087 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2088 err = i2c_transfer(client->adapter, msg, 1);
2093 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2101 /* sensor register read */
2102 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2106 struct i2c_msg msg[2];
2109 buf[1] = reg & 0xFF;
2111 msg[0].addr = client->addr;
2112 msg[0].flags = client->flags;
2114 msg[0].len = sizeof(buf);
2115 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2116 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2118 msg[1].addr = client->addr;
2119 msg[1].flags = client->flags|I2C_M_RD;
2122 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2123 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2127 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2128 err = i2c_transfer(client->adapter, msg, 2);
2134 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2142 /* write a array of registers */
2143 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2147 #if CONFIG_SENSOR_I2C_RDWRCHK
2152 if (sensor_task_lock(client, 1) < 0)
2153 goto sensor_write_array_end;
2155 while (regarray[i].reg != 0)
2157 err = sensor_write(client, regarray[i].reg, regarray[i].val);
2161 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2165 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2167 goto sensor_write_array_end;
2170 #if CONFIG_SENSOR_I2C_RDWRCHK
2171 sensor_read(client, regarray[i].reg, &valchk);
2172 if (valchk != regarray[i].val)
2173 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2179 sensor_write_array_end:
2180 sensor_task_lock(client,0);
2184 #if CONFIG_SENSOR_I2C_RDWRCHK
2185 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
2191 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
2192 while(regarray[i].reg != 0)
2194 ret = sensor_read(client,regarray[i].reg,&value);
2197 SENSOR_TR("read value failed\n");
2200 if(regarray[i].val != value)
2202 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
2210 SENSOR_DG("%s check success\n",__FUNCTION__);
2215 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
2217 struct soc_camera_link *icl = to_soc_camera_link(icd);
2220 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2223 case Sensor_PowerDown:
2225 if (icl->powerdown) {
2226 ret = icl->powerdown(icd->pdev, on);
2227 if (ret == RK29_CAM_IO_SUCCESS) {
2231 icl->reset(icd->pdev);
2233 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
2235 goto sensor_power_end;
2242 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2243 struct sensor *sensor = to_sensor(client);
2245 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2246 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2248 //flash off after 2 secs
2249 hrtimer_cancel(&(flash_off_timer.timer));
2250 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
2257 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2264 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
2265 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
2266 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
2267 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
2271 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2273 struct i2c_client *client = v4l2_get_subdevdata(sd);
2274 struct soc_camera_device *icd = client->dev.platform_data;
2275 struct sensor *sensor = to_sensor(client);
2276 const struct v4l2_queryctrl *qctrl;
2277 const struct sensor_datafmt *fmt;
2281 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2283 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2285 goto sensor_INIT_ERR;
2289 if (sensor_task_lock(client,1)<0)
2290 goto sensor_INIT_ERR;
2291 /* ret = sensor_write(client, 0x3012, 0x80);
2294 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2296 goto sensor_INIT_ERR;
2299 mdelay(5); */ //delay 5 microseconds
2300 /* check if it is an sensor sensor */
2301 ret = sensor_read(client, 0x0000, &value);
2303 SENSOR_TR("read chip id high byte failed\n");
2305 goto sensor_INIT_ERR;
2308 pid |= (value << 8);
2310 ret = sensor_read(client, 0x0001, &value);
2312 SENSOR_TR("read chip id low byte failed\n");
2314 goto sensor_INIT_ERR;
2317 pid |= (value & 0xff);
2318 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2319 if (pid == SENSOR_ID) {
2320 sensor->model = SENSOR_V4L2_IDENT;
2322 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2324 goto sensor_INIT_ERR;
2327 ret = sensor_write_array(client, sensor_init_data);
2330 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2331 goto sensor_INIT_ERR;
2333 sensor_task_lock(client,0);
2335 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2336 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2338 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2340 goto sensor_INIT_ERR;
2342 sensor->info_priv.fmt = *fmt;
2344 /* sensor sensor information for initialization */
2345 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2347 sensor->info_priv.whiteBalance = qctrl->default_value;
2348 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2350 sensor->info_priv.brightness = qctrl->default_value;
2351 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2353 sensor->info_priv.effect = qctrl->default_value;
2354 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2356 sensor->info_priv.exposure = qctrl->default_value;
2358 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2360 sensor->info_priv.saturation = qctrl->default_value;
2361 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2363 sensor->info_priv.contrast = qctrl->default_value;
2364 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2366 sensor->info_priv.mirror = qctrl->default_value;
2367 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2369 sensor->info_priv.flip = qctrl->default_value;
2370 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2372 sensor->info_priv.scene = qctrl->default_value;
2373 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2375 sensor->info_priv.digitalzoom = qctrl->default_value;
2377 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2378 #if CONFIG_SENSOR_Focus
2380 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2382 sensor->info_priv.focus = qctrl->default_value;
2385 #if CONFIG_SENSOR_Flash
2386 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2388 sensor->info_priv.flash = qctrl->default_value;
2389 flash_off_timer.icd = icd;
2390 flash_off_timer.timer.function = flash_off_func;
2393 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);
2394 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2397 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2398 sensor_task_lock(client,0);
2399 sensor_deactivate(client);
2403 static int sensor_deactivate(struct i2c_client *client)
2405 struct soc_camera_device *icd = client->dev.platform_data;
2407 struct sensor *sensor = to_sensor(client);
2408 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2410 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2411 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
2412 sensor_write(client, 0x30b0, 0x00);
2413 sensor_write(client, 0x30b1, 0x00);
2415 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2418 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2419 icd->user_width = SENSOR_INIT_WIDTH;
2420 icd->user_height = SENSOR_INIT_HEIGHT;
2421 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2426 static struct reginfo sensor_power_down_sequence[]=
2434 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2437 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2439 if (pm_msg.event == PM_EVENT_SUSPEND) {
2440 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2441 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2443 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2446 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2448 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2453 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2459 static int sensor_resume(struct soc_camera_device *icd)
2463 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2465 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2469 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2475 static int sensor_set_bus_param(struct soc_camera_device *icd,
2476 unsigned long flags)
2482 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2484 struct soc_camera_link *icl = to_soc_camera_link(icd);
2485 unsigned long flags = SENSOR_BUS_PARAM;
2487 return soc_camera_apply_sensor_flags(icl, flags);
2490 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2492 struct i2c_client *client = v4l2_get_subdevdata(sd);
2493 struct soc_camera_device *icd = client->dev.platform_data;
2494 struct sensor *sensor = to_sensor(client);
2496 mf->width = icd->user_width;
2497 mf->height = icd->user_height;
2498 mf->code = sensor->info_priv.fmt.code;
2499 mf->colorspace = sensor->info_priv.fmt.colorspace;
2500 mf->field = V4L2_FIELD_NONE;
2504 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2508 if ((mf->width == 1024) && (mf->height == 768)) {
2510 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2512 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2514 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2516 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2521 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2525 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2529 if ((mf->width == 1280) && (mf->height == 720)) {
2531 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2536 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2539 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2541 struct i2c_client *client = v4l2_get_subdevdata(sd);
2542 const struct sensor_datafmt *fmt;
2543 struct sensor *sensor = to_sensor(client);
2544 const struct v4l2_queryctrl *qctrl;
2545 struct soc_camera_device *icd = client->dev.platform_data;
2546 struct reginfo *winseqe_set_addr=NULL;
2547 int ret=0, set_w,set_h;
2549 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2550 ARRAY_SIZE(sensor_colour_fmts));
2553 goto sensor_s_fmt_end;
2556 if (sensor->info_priv.fmt.code != mf->code) {
2559 case V4L2_MBUS_FMT_YUYV8_2X8:
2561 winseqe_set_addr = sensor_ClrFmt_YUYV;
2564 case V4L2_MBUS_FMT_UYVY8_2X8:
2566 winseqe_set_addr = sensor_ClrFmt_UYVY;
2572 if (winseqe_set_addr != NULL) {
2573 sensor_write_array(client, winseqe_set_addr);
2574 sensor->info_priv.fmt.code = mf->code;
2575 sensor->info_priv.fmt.colorspace= mf->colorspace;
2576 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2578 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2585 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2587 winseqe_set_addr = sensor_qcif;
2591 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2593 winseqe_set_addr = sensor_qvga;
2597 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2599 winseqe_set_addr = sensor_cif;
2603 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2605 winseqe_set_addr = sensor_vga;
2609 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2611 winseqe_set_addr = sensor_svga;
2615 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2617 winseqe_set_addr = sensor_sxga;
2621 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2623 winseqe_set_addr = sensor_uxga;
2629 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2630 set_w = SENSOR_INIT_WIDTH;
2631 set_h = SENSOR_INIT_HEIGHT;
2632 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2635 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2636 #if CONFIG_SENSOR_Flash
2637 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2638 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2639 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2640 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2642 } else { /* ddl@rock-chips.com : Video */
2643 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2644 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2645 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2649 ret |= sensor_write_array(client, winseqe_set_addr);
2651 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2652 #if CONFIG_SENSOR_Flash
2653 if (sensor_fmt_capturechk(sd,mf) == true) {
2654 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2655 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2656 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2660 goto sensor_s_fmt_end;
2663 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2665 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2666 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2667 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2668 if (sensor->info_priv.whiteBalance != 0) {
2669 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2670 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2672 sensor->info_priv.snap2preview = true;
2673 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2674 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2675 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2676 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2677 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2678 sensor->info_priv.video2preview = true;
2679 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2680 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2681 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2682 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2683 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2685 sensor->info_priv.video2preview = false;
2686 sensor->info_priv.snap2preview = false;
2689 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2693 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2703 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2705 struct i2c_client *client = v4l2_get_subdevdata(sd);
2706 struct sensor *sensor = to_sensor(client);
2707 const struct sensor_datafmt *fmt;
2708 int ret = 0,set_w,set_h;
2710 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2711 ARRAY_SIZE(sensor_colour_fmts));
2713 fmt = &sensor->info_priv.fmt;
2714 mf->code = fmt->code;
2717 if (mf->height > SENSOR_MAX_HEIGHT)
2718 mf->height = SENSOR_MAX_HEIGHT;
2719 else if (mf->height < SENSOR_MIN_HEIGHT)
2720 mf->height = SENSOR_MIN_HEIGHT;
2722 if (mf->width > SENSOR_MAX_WIDTH)
2723 mf->width = SENSOR_MAX_WIDTH;
2724 else if (mf->width < SENSOR_MIN_WIDTH)
2725 mf->width = SENSOR_MIN_WIDTH;
2730 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2735 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2740 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2745 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2750 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2755 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2760 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2767 set_w = SENSOR_INIT_WIDTH;
2768 set_h = SENSOR_INIT_HEIGHT;
2773 mf->colorspace = fmt->colorspace;
2778 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2780 struct i2c_client *client = v4l2_get_subdevdata(sd);
2782 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2785 if (id->match.addr != client->addr)
2788 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return gt2005 identifier */
2793 #if CONFIG_SENSOR_Brightness
2794 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2796 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2798 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2800 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2802 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2804 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2807 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2811 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2815 #if CONFIG_SENSOR_Effect
2816 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2818 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2820 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2822 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2824 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2826 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2829 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2833 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2837 #if CONFIG_SENSOR_Exposure
2838 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2840 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2842 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2844 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2846 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2848 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2851 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2855 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2859 #if CONFIG_SENSOR_Saturation
2860 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2862 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2864 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2866 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2868 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2870 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2873 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2877 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2881 #if CONFIG_SENSOR_Contrast
2882 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2884 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2886 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2888 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2890 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2892 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2895 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2899 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2903 #if CONFIG_SENSOR_Mirror
2904 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2906 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2908 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2910 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2912 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2914 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2917 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2921 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2925 #if CONFIG_SENSOR_Flip
2926 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2928 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2930 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2932 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2934 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2936 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2939 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2943 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2947 #if CONFIG_SENSOR_Scene
2948 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2950 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2952 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2954 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2956 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2958 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2961 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2965 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2969 #if CONFIG_SENSOR_WhiteBalance
2970 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2972 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2974 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2976 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2978 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2980 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2983 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2987 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2991 #if CONFIG_SENSOR_DigitalZoom
2992 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2994 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2995 struct sensor *sensor = to_sensor(client);
2996 const struct v4l2_queryctrl *qctrl_info;
2997 int digitalzoom_cur, digitalzoom_total;
2999 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
3003 digitalzoom_cur = sensor->info_priv.digitalzoom;
3004 digitalzoom_total = qctrl_info->maximum;
3006 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
3008 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3012 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
3014 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3018 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
3020 value = digitalzoom_total - digitalzoom_cur;
3023 if ((value < 0) && ((digitalzoom_cur + value) < 0))
3025 value = 0 - digitalzoom_cur;
3028 digitalzoom_cur += value;
3030 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
3032 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
3034 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3037 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3044 #if CONFIG_SENSOR_Flash
3045 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3047 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3048 if (value == 3) { /* ddl@rock-chips.com: torch */
3049 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
3051 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3053 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3057 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3062 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3064 struct i2c_client *client = v4l2_get_subdevdata(sd);
3065 struct sensor *sensor = to_sensor(client);
3066 const struct v4l2_queryctrl *qctrl;
3068 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3072 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3078 case V4L2_CID_BRIGHTNESS:
3080 ctrl->value = sensor->info_priv.brightness;
3083 case V4L2_CID_SATURATION:
3085 ctrl->value = sensor->info_priv.saturation;
3088 case V4L2_CID_CONTRAST:
3090 ctrl->value = sensor->info_priv.contrast;
3093 case V4L2_CID_DO_WHITE_BALANCE:
3095 ctrl->value = sensor->info_priv.whiteBalance;
3098 case V4L2_CID_EXPOSURE:
3100 ctrl->value = sensor->info_priv.exposure;
3103 case V4L2_CID_HFLIP:
3105 ctrl->value = sensor->info_priv.mirror;
3108 case V4L2_CID_VFLIP:
3110 ctrl->value = sensor->info_priv.flip;
3121 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3123 struct i2c_client *client = v4l2_get_subdevdata(sd);
3124 struct sensor *sensor = to_sensor(client);
3125 struct soc_camera_device *icd = client->dev.platform_data;
3126 const struct v4l2_queryctrl *qctrl;
3129 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3133 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3139 #if CONFIG_SENSOR_Brightness
3140 case V4L2_CID_BRIGHTNESS:
3142 if (ctrl->value != sensor->info_priv.brightness)
3144 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3148 sensor->info_priv.brightness = ctrl->value;
3153 #if CONFIG_SENSOR_Exposure
3154 case V4L2_CID_EXPOSURE:
3156 if (ctrl->value != sensor->info_priv.exposure)
3158 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3162 sensor->info_priv.exposure = ctrl->value;
3167 #if CONFIG_SENSOR_Saturation
3168 case V4L2_CID_SATURATION:
3170 if (ctrl->value != sensor->info_priv.saturation)
3172 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3176 sensor->info_priv.saturation = ctrl->value;
3181 #if CONFIG_SENSOR_Contrast
3182 case V4L2_CID_CONTRAST:
3184 if (ctrl->value != sensor->info_priv.contrast)
3186 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3190 sensor->info_priv.contrast = ctrl->value;
3195 #if CONFIG_SENSOR_WhiteBalance
3196 case V4L2_CID_DO_WHITE_BALANCE:
3198 if (ctrl->value != sensor->info_priv.whiteBalance)
3200 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3204 sensor->info_priv.whiteBalance = ctrl->value;
3209 #if CONFIG_SENSOR_Mirror
3210 case V4L2_CID_HFLIP:
3212 if (ctrl->value != sensor->info_priv.mirror)
3214 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3216 sensor->info_priv.mirror = ctrl->value;
3221 #if CONFIG_SENSOR_Flip
3222 case V4L2_CID_VFLIP:
3224 if (ctrl->value != sensor->info_priv.flip)
3226 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3228 sensor->info_priv.flip = ctrl->value;
3239 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3241 const struct v4l2_queryctrl *qctrl;
3242 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3243 struct sensor *sensor = to_sensor(client);
3245 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3249 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3253 switch (ext_ctrl->id)
3255 case V4L2_CID_SCENE:
3257 ext_ctrl->value = sensor->info_priv.scene;
3260 case V4L2_CID_EFFECT:
3262 ext_ctrl->value = sensor->info_priv.effect;
3265 case V4L2_CID_ZOOM_ABSOLUTE:
3267 ext_ctrl->value = sensor->info_priv.digitalzoom;
3270 case V4L2_CID_ZOOM_RELATIVE:
3274 case V4L2_CID_FOCUS_ABSOLUTE:
3276 ext_ctrl->value = sensor->info_priv.focus;
3279 case V4L2_CID_FOCUS_RELATIVE:
3283 case V4L2_CID_FLASH:
3285 ext_ctrl->value = sensor->info_priv.flash;
3293 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3295 const struct v4l2_queryctrl *qctrl;
3296 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3297 struct sensor *sensor = to_sensor(client);
3300 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3304 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3309 switch (ext_ctrl->id)
3311 #if CONFIG_SENSOR_Scene
3312 case V4L2_CID_SCENE:
3314 if (ext_ctrl->value != sensor->info_priv.scene)
3316 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3318 sensor->info_priv.scene = ext_ctrl->value;
3323 #if CONFIG_SENSOR_Effect
3324 case V4L2_CID_EFFECT:
3326 if (ext_ctrl->value != sensor->info_priv.effect)
3328 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3330 sensor->info_priv.effect= ext_ctrl->value;
3335 #if CONFIG_SENSOR_DigitalZoom
3336 case V4L2_CID_ZOOM_ABSOLUTE:
3338 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3341 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3343 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3345 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3347 sensor->info_priv.digitalzoom += val_offset;
3349 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3354 case V4L2_CID_ZOOM_RELATIVE:
3356 if (ext_ctrl->value)
3358 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3360 sensor->info_priv.digitalzoom += ext_ctrl->value;
3362 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3367 #if CONFIG_SENSOR_Focus
3368 case V4L2_CID_FOCUS_ABSOLUTE:
3370 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3373 if (ext_ctrl->value != sensor->info_priv.focus)
3375 val_offset = ext_ctrl->value -sensor->info_priv.focus;
3377 sensor->info_priv.focus += val_offset;
3382 case V4L2_CID_FOCUS_RELATIVE:
3384 if (ext_ctrl->value)
3386 sensor->info_priv.focus += ext_ctrl->value;
3388 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
3393 #if CONFIG_SENSOR_Flash
3394 case V4L2_CID_FLASH:
3396 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3398 sensor->info_priv.flash = ext_ctrl->value;
3400 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3411 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3413 struct i2c_client *client = v4l2_get_subdevdata(sd);
3414 struct soc_camera_device *icd = client->dev.platform_data;
3415 int i, error_cnt=0, error_idx=-1;
3418 for (i=0; i<ext_ctrl->count; i++) {
3419 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3426 error_idx = ext_ctrl->count;
3428 if (error_idx != -1) {
3429 ext_ctrl->error_idx = error_idx;
3436 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3438 struct i2c_client *client = v4l2_get_subdevdata(sd);
3439 struct soc_camera_device *icd = client->dev.platform_data;
3440 int i, error_cnt=0, error_idx=-1;
3443 for (i=0; i<ext_ctrl->count; i++) {
3444 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3451 error_idx = ext_ctrl->count;
3453 if (error_idx != -1) {
3454 ext_ctrl->error_idx = error_idx;
3461 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3462 * this wasn't our capture interface, so, we wait for the right one */
3463 static int sensor_video_probe(struct soc_camera_device *icd,
3464 struct i2c_client *client)
3468 struct sensor *sensor = to_sensor(client);
3470 /* We must have a parent by now. And it cannot be a wrong one.
3471 * So this entire test is completely redundant. */
3472 if (!icd->dev.parent ||
3473 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3476 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3478 goto sensor_video_probe_err;
3482 /* ret = sensor_write(client, 0x3012, 0x80);
3485 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3488 mdelay(5); */ //delay 5 microseconds
3490 /* check if it is an sensor sensor */
3491 ret = sensor_read(client, 0x0000, &value);
3493 SENSOR_TR("read chip id high byte failed\n");
3495 goto sensor_video_probe_err;
3498 pid |= (value << 8);
3500 ret = sensor_read(client, 0x0001, &value);
3502 SENSOR_TR("read chip id low byte failed\n");
3504 goto sensor_video_probe_err;
3507 pid |= (value & 0xff);
3508 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3509 if (pid == SENSOR_ID) {
3510 sensor->model = SENSOR_V4L2_IDENT;
3512 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3514 goto sensor_video_probe_err;
3519 sensor_video_probe_err:
3523 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3525 struct i2c_client *client = v4l2_get_subdevdata(sd);
3526 struct soc_camera_device *icd = client->dev.platform_data;
3527 struct sensor *sensor = to_sensor(client);
3528 #if CONFIG_SENSOR_Flash
3533 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3536 case RK29_CAM_SUBDEV_DEACTIVATE:
3538 sensor_deactivate(client);
3542 case RK29_CAM_SUBDEV_IOREQUEST:
3544 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3545 if (sensor->sensor_io_request != NULL) {
3546 sensor->sensor_gpio_res = NULL;
3547 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
3548 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
3549 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
3550 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
3553 if (sensor->sensor_gpio_res == NULL) {
3554 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
3556 goto sensor_ioctl_end;
3559 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3561 goto sensor_ioctl_end;
3563 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3565 #if CONFIG_SENSOR_Flash
3566 if (sensor->sensor_gpio_res) {
3567 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3568 for (i = 0; i < icd->ops->num_controls; i++) {
3569 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3570 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3571 sensor_controls[i].id=0xffff;
3574 sensor->info_priv.flash = 0xff;
3575 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3576 }else{ //two cameras are the same,need to deal diffrently ,zyc
3577 for (i = 0; i < icd->ops->num_controls; i++) {
3578 if(0xffff == icd->ops->controls[i].id){
3579 sensor_controls[i].id=V4L2_CID_FLASH;
3589 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3597 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3598 enum v4l2_mbus_pixelcode *code)
3600 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3603 *code = sensor_colour_fmts[index].code;
3606 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3607 .init = sensor_init,
3608 .g_ctrl = sensor_g_control,
3609 .s_ctrl = sensor_s_control,
3610 .g_ext_ctrls = sensor_g_ext_controls,
3611 .s_ext_ctrls = sensor_s_ext_controls,
3612 .g_chip_ident = sensor_g_chip_ident,
3613 .ioctl = sensor_ioctl,
3616 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3617 .s_mbus_fmt = sensor_s_fmt,
3618 .g_mbus_fmt = sensor_g_fmt,
3619 .try_mbus_fmt = sensor_try_fmt,
3620 .enum_mbus_fmt = sensor_enum_fmt,
3623 static struct v4l2_subdev_ops sensor_subdev_ops = {
3624 .core = &sensor_subdev_core_ops,
3625 .video = &sensor_subdev_video_ops,
3628 static int sensor_probe(struct i2c_client *client,
3629 const struct i2c_device_id *did)
3631 struct sensor *sensor;
3632 struct soc_camera_device *icd = client->dev.platform_data;
3633 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3634 struct soc_camera_link *icl;
3637 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3639 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3643 icl = to_soc_camera_link(icd);
3645 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3649 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3650 dev_warn(&adapter->dev,
3651 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3655 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3659 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3661 /* Second stage probe - when a capture adapter is there */
3662 icd->ops = &sensor_ops;
3664 sensor->info_priv.fmt = sensor_colour_fmts[0];
3666 #if CONFIG_SENSOR_I2C_NOSCHED
3667 atomic_set(&sensor->tasklock_cnt,0);
3670 ret = sensor_video_probe(icd, client);
3673 i2c_set_clientdata(client, NULL);
3677 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3678 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3682 static int sensor_remove(struct i2c_client *client)
3684 struct sensor *sensor = to_sensor(client);
3685 struct soc_camera_device *icd = client->dev.platform_data;
3688 i2c_set_clientdata(client, NULL);
3689 client->driver = NULL;
3695 static const struct i2c_device_id sensor_id[] = {
3696 {SENSOR_NAME_STRING(), 0 },
3699 MODULE_DEVICE_TABLE(i2c, sensor_id);
3701 static struct i2c_driver sensor_i2c_driver = {
3703 .name = SENSOR_NAME_STRING(),
3705 .probe = sensor_probe,
3706 .remove = sensor_remove,
3707 .id_table = sensor_id,
3710 static int __init sensor_mod_init(void)
3712 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3713 return i2c_add_driver(&sensor_i2c_driver);
3716 static void __exit sensor_mod_exit(void)
3718 i2c_del_driver(&sensor_i2c_driver);
3721 device_initcall_sync(sensor_mod_init);
3722 module_exit(sensor_mod_exit);
3724 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3725 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3726 MODULE_LICENSE("GPL");