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 #if 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 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2390 flash_off_timer.icd = icd;
2391 flash_off_timer.timer.function = flash_off_func;
2394 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);
2395 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2398 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2399 sensor_task_lock(client,0);
2400 sensor_deactivate(client);
2404 static int sensor_deactivate(struct i2c_client *client)
2406 struct soc_camera_device *icd = client->dev.platform_data;
2408 struct sensor *sensor = to_sensor(client);
2409 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2411 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2412 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
2413 sensor_write(client, 0x30b0, 0x00);
2414 sensor_write(client, 0x30b1, 0x00);
2416 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2419 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2420 icd->user_width = SENSOR_INIT_WIDTH;
2421 icd->user_height = SENSOR_INIT_HEIGHT;
2422 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2427 static struct reginfo sensor_power_down_sequence[]=
2435 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2438 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2440 if (pm_msg.event == PM_EVENT_SUSPEND) {
2441 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2442 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2444 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2447 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2449 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2454 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2460 static int sensor_resume(struct soc_camera_device *icd)
2464 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2466 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2470 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2476 static int sensor_set_bus_param(struct soc_camera_device *icd,
2477 unsigned long flags)
2483 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2485 struct soc_camera_link *icl = to_soc_camera_link(icd);
2486 unsigned long flags = SENSOR_BUS_PARAM;
2488 return soc_camera_apply_sensor_flags(icl, flags);
2491 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2493 struct i2c_client *client = v4l2_get_subdevdata(sd);
2494 struct soc_camera_device *icd = client->dev.platform_data;
2495 struct sensor *sensor = to_sensor(client);
2497 mf->width = icd->user_width;
2498 mf->height = icd->user_height;
2499 mf->code = sensor->info_priv.fmt.code;
2500 mf->colorspace = sensor->info_priv.fmt.colorspace;
2501 mf->field = V4L2_FIELD_NONE;
2505 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2509 if ((mf->width == 1024) && (mf->height == 768)) {
2511 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2513 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2515 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2517 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2522 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2526 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2530 if ((mf->width == 1280) && (mf->height == 720)) {
2532 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2537 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2540 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2542 struct i2c_client *client = v4l2_get_subdevdata(sd);
2543 const struct sensor_datafmt *fmt;
2544 struct sensor *sensor = to_sensor(client);
2545 const struct v4l2_queryctrl *qctrl;
2546 struct soc_camera_device *icd = client->dev.platform_data;
2547 struct reginfo *winseqe_set_addr=NULL;
2548 int ret=0, set_w,set_h;
2550 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2551 ARRAY_SIZE(sensor_colour_fmts));
2554 goto sensor_s_fmt_end;
2557 if (sensor->info_priv.fmt.code != mf->code) {
2560 case V4L2_MBUS_FMT_YUYV8_2X8:
2562 winseqe_set_addr = sensor_ClrFmt_YUYV;
2565 case V4L2_MBUS_FMT_UYVY8_2X8:
2567 winseqe_set_addr = sensor_ClrFmt_UYVY;
2573 if (winseqe_set_addr != NULL) {
2574 sensor_write_array(client, winseqe_set_addr);
2575 sensor->info_priv.fmt.code = mf->code;
2576 sensor->info_priv.fmt.colorspace= mf->colorspace;
2577 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2579 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2586 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2588 winseqe_set_addr = sensor_qcif;
2592 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2594 winseqe_set_addr = sensor_qvga;
2598 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2600 winseqe_set_addr = sensor_cif;
2604 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2606 winseqe_set_addr = sensor_vga;
2610 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2612 winseqe_set_addr = sensor_svga;
2616 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2618 winseqe_set_addr = sensor_sxga;
2622 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2624 winseqe_set_addr = sensor_uxga;
2630 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2631 set_w = SENSOR_INIT_WIDTH;
2632 set_h = SENSOR_INIT_HEIGHT;
2633 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2636 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2637 #if CONFIG_SENSOR_Flash
2638 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2639 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2640 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2641 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2643 } else { /* ddl@rock-chips.com : Video */
2644 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2645 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2646 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2650 ret |= sensor_write_array(client, winseqe_set_addr);
2652 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2653 #if CONFIG_SENSOR_Flash
2654 if (sensor_fmt_capturechk(sd,mf) == true) {
2655 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2656 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2657 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2661 goto sensor_s_fmt_end;
2664 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2666 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2667 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2668 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2669 if (sensor->info_priv.whiteBalance != 0) {
2670 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2671 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2673 sensor->info_priv.snap2preview = true;
2674 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2675 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2676 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2677 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2678 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2679 sensor->info_priv.video2preview = true;
2680 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2681 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2682 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2683 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2684 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2686 sensor->info_priv.video2preview = false;
2687 sensor->info_priv.snap2preview = false;
2690 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2694 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2704 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2706 struct i2c_client *client = v4l2_get_subdevdata(sd);
2707 struct sensor *sensor = to_sensor(client);
2708 const struct sensor_datafmt *fmt;
2709 int ret = 0,set_w,set_h;
2711 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2712 ARRAY_SIZE(sensor_colour_fmts));
2714 fmt = &sensor->info_priv.fmt;
2715 mf->code = fmt->code;
2718 if (mf->height > SENSOR_MAX_HEIGHT)
2719 mf->height = SENSOR_MAX_HEIGHT;
2720 else if (mf->height < SENSOR_MIN_HEIGHT)
2721 mf->height = SENSOR_MIN_HEIGHT;
2723 if (mf->width > SENSOR_MAX_WIDTH)
2724 mf->width = SENSOR_MAX_WIDTH;
2725 else if (mf->width < SENSOR_MIN_WIDTH)
2726 mf->width = SENSOR_MIN_WIDTH;
2731 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2736 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2741 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2746 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2751 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2756 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2761 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2768 set_w = SENSOR_INIT_WIDTH;
2769 set_h = SENSOR_INIT_HEIGHT;
2774 mf->colorspace = fmt->colorspace;
2779 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2781 struct i2c_client *client = v4l2_get_subdevdata(sd);
2783 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2786 if (id->match.addr != client->addr)
2789 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return gt2005 identifier */
2794 #if CONFIG_SENSOR_Brightness
2795 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2797 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2799 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2801 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2803 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2805 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2808 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2812 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2816 #if CONFIG_SENSOR_Effect
2817 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2819 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2821 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2823 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2825 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2827 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2830 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2834 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2838 #if CONFIG_SENSOR_Exposure
2839 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2841 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2843 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2845 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2847 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2849 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2852 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2856 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2860 #if CONFIG_SENSOR_Saturation
2861 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2863 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2865 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2867 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2869 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2871 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2874 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2878 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2882 #if CONFIG_SENSOR_Contrast
2883 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2885 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2887 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2889 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2891 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2893 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2896 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2900 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2904 #if CONFIG_SENSOR_Mirror
2905 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2907 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2909 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2911 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2913 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2915 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2918 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2922 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2926 #if CONFIG_SENSOR_Flip
2927 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2929 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2931 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2933 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2935 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2937 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2940 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2944 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2948 #if CONFIG_SENSOR_Scene
2949 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2951 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2953 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2955 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2957 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2959 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2962 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2966 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2970 #if CONFIG_SENSOR_WhiteBalance
2971 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2973 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2975 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2977 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2979 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2981 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2984 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2988 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2992 #if CONFIG_SENSOR_DigitalZoom
2993 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2995 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2996 struct sensor *sensor = to_sensor(client);
2997 const struct v4l2_queryctrl *qctrl_info;
2998 int digitalzoom_cur, digitalzoom_total;
3000 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
3004 digitalzoom_cur = sensor->info_priv.digitalzoom;
3005 digitalzoom_total = qctrl_info->maximum;
3007 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
3009 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3013 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
3015 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3019 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
3021 value = digitalzoom_total - digitalzoom_cur;
3024 if ((value < 0) && ((digitalzoom_cur + value) < 0))
3026 value = 0 - digitalzoom_cur;
3029 digitalzoom_cur += value;
3031 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
3033 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
3035 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3038 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3045 #if CONFIG_SENSOR_Flash
3046 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3048 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3049 if (value == 3) { /* ddl@rock-chips.com: torch */
3050 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
3052 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3054 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3058 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3063 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3065 struct i2c_client *client = v4l2_get_subdevdata(sd);
3066 struct sensor *sensor = to_sensor(client);
3067 const struct v4l2_queryctrl *qctrl;
3069 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3073 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3079 case V4L2_CID_BRIGHTNESS:
3081 ctrl->value = sensor->info_priv.brightness;
3084 case V4L2_CID_SATURATION:
3086 ctrl->value = sensor->info_priv.saturation;
3089 case V4L2_CID_CONTRAST:
3091 ctrl->value = sensor->info_priv.contrast;
3094 case V4L2_CID_DO_WHITE_BALANCE:
3096 ctrl->value = sensor->info_priv.whiteBalance;
3099 case V4L2_CID_EXPOSURE:
3101 ctrl->value = sensor->info_priv.exposure;
3104 case V4L2_CID_HFLIP:
3106 ctrl->value = sensor->info_priv.mirror;
3109 case V4L2_CID_VFLIP:
3111 ctrl->value = sensor->info_priv.flip;
3122 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3124 struct i2c_client *client = v4l2_get_subdevdata(sd);
3125 struct sensor *sensor = to_sensor(client);
3126 struct soc_camera_device *icd = client->dev.platform_data;
3127 const struct v4l2_queryctrl *qctrl;
3130 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3134 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3140 #if CONFIG_SENSOR_Brightness
3141 case V4L2_CID_BRIGHTNESS:
3143 if (ctrl->value != sensor->info_priv.brightness)
3145 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3149 sensor->info_priv.brightness = ctrl->value;
3154 #if CONFIG_SENSOR_Exposure
3155 case V4L2_CID_EXPOSURE:
3157 if (ctrl->value != sensor->info_priv.exposure)
3159 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3163 sensor->info_priv.exposure = ctrl->value;
3168 #if CONFIG_SENSOR_Saturation
3169 case V4L2_CID_SATURATION:
3171 if (ctrl->value != sensor->info_priv.saturation)
3173 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3177 sensor->info_priv.saturation = ctrl->value;
3182 #if CONFIG_SENSOR_Contrast
3183 case V4L2_CID_CONTRAST:
3185 if (ctrl->value != sensor->info_priv.contrast)
3187 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3191 sensor->info_priv.contrast = ctrl->value;
3196 #if CONFIG_SENSOR_WhiteBalance
3197 case V4L2_CID_DO_WHITE_BALANCE:
3199 if (ctrl->value != sensor->info_priv.whiteBalance)
3201 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3205 sensor->info_priv.whiteBalance = ctrl->value;
3210 #if CONFIG_SENSOR_Mirror
3211 case V4L2_CID_HFLIP:
3213 if (ctrl->value != sensor->info_priv.mirror)
3215 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3217 sensor->info_priv.mirror = ctrl->value;
3222 #if CONFIG_SENSOR_Flip
3223 case V4L2_CID_VFLIP:
3225 if (ctrl->value != sensor->info_priv.flip)
3227 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3229 sensor->info_priv.flip = ctrl->value;
3240 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3242 const struct v4l2_queryctrl *qctrl;
3243 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3244 struct sensor *sensor = to_sensor(client);
3246 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3250 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3254 switch (ext_ctrl->id)
3256 case V4L2_CID_SCENE:
3258 ext_ctrl->value = sensor->info_priv.scene;
3261 case V4L2_CID_EFFECT:
3263 ext_ctrl->value = sensor->info_priv.effect;
3266 case V4L2_CID_ZOOM_ABSOLUTE:
3268 ext_ctrl->value = sensor->info_priv.digitalzoom;
3271 case V4L2_CID_ZOOM_RELATIVE:
3275 case V4L2_CID_FOCUS_ABSOLUTE:
3277 ext_ctrl->value = sensor->info_priv.focus;
3280 case V4L2_CID_FOCUS_RELATIVE:
3284 case V4L2_CID_FLASH:
3286 ext_ctrl->value = sensor->info_priv.flash;
3294 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3296 const struct v4l2_queryctrl *qctrl;
3297 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3298 struct sensor *sensor = to_sensor(client);
3301 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3305 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3310 switch (ext_ctrl->id)
3312 #if CONFIG_SENSOR_Scene
3313 case V4L2_CID_SCENE:
3315 if (ext_ctrl->value != sensor->info_priv.scene)
3317 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3319 sensor->info_priv.scene = ext_ctrl->value;
3324 #if CONFIG_SENSOR_Effect
3325 case V4L2_CID_EFFECT:
3327 if (ext_ctrl->value != sensor->info_priv.effect)
3329 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3331 sensor->info_priv.effect= ext_ctrl->value;
3336 #if CONFIG_SENSOR_DigitalZoom
3337 case V4L2_CID_ZOOM_ABSOLUTE:
3339 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3342 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3344 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3346 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3348 sensor->info_priv.digitalzoom += val_offset;
3350 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3355 case V4L2_CID_ZOOM_RELATIVE:
3357 if (ext_ctrl->value)
3359 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3361 sensor->info_priv.digitalzoom += ext_ctrl->value;
3363 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3368 #if CONFIG_SENSOR_Focus
3369 case V4L2_CID_FOCUS_ABSOLUTE:
3371 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3374 if (ext_ctrl->value != sensor->info_priv.focus)
3376 val_offset = ext_ctrl->value -sensor->info_priv.focus;
3378 sensor->info_priv.focus += val_offset;
3383 case V4L2_CID_FOCUS_RELATIVE:
3385 if (ext_ctrl->value)
3387 sensor->info_priv.focus += ext_ctrl->value;
3389 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
3394 #if CONFIG_SENSOR_Flash
3395 case V4L2_CID_FLASH:
3397 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3399 sensor->info_priv.flash = ext_ctrl->value;
3401 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3412 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3414 struct i2c_client *client = v4l2_get_subdevdata(sd);
3415 struct soc_camera_device *icd = client->dev.platform_data;
3416 int i, error_cnt=0, error_idx=-1;
3419 for (i=0; i<ext_ctrl->count; i++) {
3420 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3427 error_idx = ext_ctrl->count;
3429 if (error_idx != -1) {
3430 ext_ctrl->error_idx = error_idx;
3437 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3439 struct i2c_client *client = v4l2_get_subdevdata(sd);
3440 struct soc_camera_device *icd = client->dev.platform_data;
3441 int i, error_cnt=0, error_idx=-1;
3444 for (i=0; i<ext_ctrl->count; i++) {
3445 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3452 error_idx = ext_ctrl->count;
3454 if (error_idx != -1) {
3455 ext_ctrl->error_idx = error_idx;
3462 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3463 * this wasn't our capture interface, so, we wait for the right one */
3464 static int sensor_video_probe(struct soc_camera_device *icd,
3465 struct i2c_client *client)
3469 struct sensor *sensor = to_sensor(client);
3471 /* We must have a parent by now. And it cannot be a wrong one.
3472 * So this entire test is completely redundant. */
3473 if (!icd->dev.parent ||
3474 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3477 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3479 goto sensor_video_probe_err;
3483 /* ret = sensor_write(client, 0x3012, 0x80);
3486 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3489 mdelay(5); */ //delay 5 microseconds
3491 /* check if it is an sensor sensor */
3492 ret = sensor_read(client, 0x0000, &value);
3494 SENSOR_TR("read chip id high byte failed\n");
3496 goto sensor_video_probe_err;
3499 pid |= (value << 8);
3501 ret = sensor_read(client, 0x0001, &value);
3503 SENSOR_TR("read chip id low byte failed\n");
3505 goto sensor_video_probe_err;
3508 pid |= (value & 0xff);
3509 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3510 if (pid == SENSOR_ID) {
3511 sensor->model = SENSOR_V4L2_IDENT;
3513 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3515 goto sensor_video_probe_err;
3520 sensor_video_probe_err:
3524 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3526 struct i2c_client *client = v4l2_get_subdevdata(sd);
3527 struct soc_camera_device *icd = client->dev.platform_data;
3528 struct sensor *sensor = to_sensor(client);
3529 #if CONFIG_SENSOR_Flash
3534 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3537 case RK29_CAM_SUBDEV_DEACTIVATE:
3539 sensor_deactivate(client);
3543 case RK29_CAM_SUBDEV_IOREQUEST:
3545 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3546 if (sensor->sensor_io_request != NULL) {
3547 sensor->sensor_gpio_res = NULL;
3548 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
3549 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
3550 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
3551 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
3554 if (sensor->sensor_gpio_res == NULL) {
3555 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
3557 goto sensor_ioctl_end;
3560 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3562 goto sensor_ioctl_end;
3564 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3566 #if CONFIG_SENSOR_Flash
3567 if (sensor->sensor_gpio_res) {
3568 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3569 for (i = 0; i < icd->ops->num_controls; i++) {
3570 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3571 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3572 sensor_controls[i].id=0xffff;
3575 sensor->info_priv.flash = 0xff;
3576 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3577 }else{ //two cameras are the same,need to deal diffrently ,zyc
3578 for (i = 0; i < icd->ops->num_controls; i++) {
3579 if(0xffff == icd->ops->controls[i].id){
3580 sensor_controls[i].id=V4L2_CID_FLASH;
3590 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3598 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3599 enum v4l2_mbus_pixelcode *code)
3601 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3604 *code = sensor_colour_fmts[index].code;
3607 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3608 .init = sensor_init,
3609 .g_ctrl = sensor_g_control,
3610 .s_ctrl = sensor_s_control,
3611 .g_ext_ctrls = sensor_g_ext_controls,
3612 .s_ext_ctrls = sensor_s_ext_controls,
3613 .g_chip_ident = sensor_g_chip_ident,
3614 .ioctl = sensor_ioctl,
3617 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3618 .s_mbus_fmt = sensor_s_fmt,
3619 .g_mbus_fmt = sensor_g_fmt,
3620 .try_mbus_fmt = sensor_try_fmt,
3621 .enum_mbus_fmt = sensor_enum_fmt,
3624 static struct v4l2_subdev_ops sensor_subdev_ops = {
3625 .core = &sensor_subdev_core_ops,
3626 .video = &sensor_subdev_video_ops,
3629 static int sensor_probe(struct i2c_client *client,
3630 const struct i2c_device_id *did)
3632 struct sensor *sensor;
3633 struct soc_camera_device *icd = client->dev.platform_data;
3634 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3635 struct soc_camera_link *icl;
3638 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3640 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3644 icl = to_soc_camera_link(icd);
3646 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3650 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3651 dev_warn(&adapter->dev,
3652 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3656 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3660 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3662 /* Second stage probe - when a capture adapter is there */
3663 icd->ops = &sensor_ops;
3665 sensor->info_priv.fmt = sensor_colour_fmts[0];
3667 #if CONFIG_SENSOR_I2C_NOSCHED
3668 atomic_set(&sensor->tasklock_cnt,0);
3671 ret = sensor_video_probe(icd, client);
3674 i2c_set_clientdata(client, NULL);
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");