2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <mach/rk29_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 0
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 /* init 352X288 SVGA */
104 static struct reginfo sensor_init_data[] =
559 ///////////////////////////
593 static struct reginfo sensor_uxga[] =
610 static struct reginfo sensor_sxga[] =
625 static struct reginfo sensor_svga[] =
1107 static struct reginfo sensor_vga[] =
1144 static struct reginfo sensor_cif[] =
1150 static struct reginfo sensor_qvga[] =
1158 static struct reginfo sensor_qcif[] =
1165 static struct reginfo gt2005_qqvga[] =
1209 static struct reginfo gt2005_Sharpness_auto[] =
1214 static struct reginfo gt2005_Sharpness1[] =
1220 static struct reginfo gt2005_Sharpness2[][3] =
1227 static struct reginfo gt2005_Sharpness3[] =
1233 static struct reginfo gt2005_Sharpness4[]=
1240 static struct reginfo gt2005_Sharpness5[] =
1248 static struct reginfo sensor_ClrFmt_YUYV[]=
1254 static struct reginfo sensor_ClrFmt_UYVY[]=
1260 #if CONFIG_SENSOR_WhiteBalance
1261 static struct reginfo sensor_WhiteB_Auto[]=
1263 {0x3306, 0x00}, //AWB auto, bit[1]:0,auto
1266 /* Cloudy Colour Temperature : 6500K - 8000K */
1267 static struct reginfo sensor_WhiteB_Cloudy[]=
1275 /* ClearDay Colour Temperature : 5000K - 6500K */
1276 static struct reginfo sensor_WhiteB_ClearDay[]=
1279 {0x3306, 0x02}, //AWB off
1285 /* Office Colour Temperature : 3500K - 5000K */
1286 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
1296 /* Home Colour Temperature : 2500K - 3500K */
1297 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
1306 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1307 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1311 #if CONFIG_SENSOR_Brightness
1312 static struct reginfo sensor_Brightness0[]=
1315 {0x3301, 0xff},//bit[7]:1, enable SDE
1322 static struct reginfo sensor_Brightness1[]=
1325 {0x3301, 0xff},//bit[7]:1, enable SDE
1332 static struct reginfo sensor_Brightness2[]=
1335 {0x3301, 0xff},//bit[7]:1, enable SDE
1342 static struct reginfo sensor_Brightness3[]=
1345 {0x3301, 0xff},//bit[7]:1, enable SDE
1352 static struct reginfo sensor_Brightness4[]=
1355 {0x3301, 0xff},//bit[7]:1, enable SDE
1362 static struct reginfo sensor_Brightness5[]=
1365 {0x3301, 0xff},//bit[7]:1, enable SDE
1366 {0x3391, 0x04}, //bit[2] enable
1367 {0x3390, 0x41}, //bit[3] sign of brightness
1371 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1372 sensor_Brightness4, sensor_Brightness5,NULL,
1377 #if CONFIG_SENSOR_Effect
1378 static struct reginfo sensor_Effect_Normal[] =
1384 static struct reginfo sensor_Effect_WandB[] =
1390 static struct reginfo sensor_Effect_Sepia[] =
1398 static struct reginfo sensor_Effect_Negative[] =
1401 {0x3391, 0x40}, //bit[6] negative
1404 static struct reginfo sensor_Effect_Bluish[] =
1413 static struct reginfo sensor_Effect_Green[] =
1421 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1422 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1425 #if CONFIG_SENSOR_Exposure
1426 static struct reginfo sensor_Exposure0[]=
1436 static struct reginfo sensor_Exposure1[]=
1446 static struct reginfo sensor_Exposure2[]=
1456 static struct reginfo sensor_Exposure3[]=
1466 static struct reginfo sensor_Exposure4[]=
1476 static struct reginfo sensor_Exposure5[]=
1486 static struct reginfo sensor_Exposure6[]=
1496 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1497 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1500 #if CONFIG_SENSOR_Saturation
1501 static struct reginfo sensor_Saturation0[]=
1503 {0x3301, 0xff},//bit[7]:1, enable SDE
1510 static struct reginfo sensor_Saturation1[]=
1512 {0x3301, 0xff},//bit[7]:1, enable SDE
1519 static struct reginfo sensor_Saturation2[]=
1521 {0x3301, 0xff},//bit[7]:1, enable SDE
1522 {0x3391, 0x02}, //enable color saturation
1527 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1530 #if CONFIG_SENSOR_Contrast
1531 static struct reginfo sensor_Contrast0[]=
1534 {0x3301, 0xff},//bit[7]:1, enable SDE
1542 static struct reginfo sensor_Contrast1[]=
1545 {0x3301, 0xff},//bit[7]:1, enable SDE
1553 static struct reginfo sensor_Contrast2[]=
1556 {0x3301, 0xff},//bit[7]:1, enable SDE
1564 static struct reginfo sensor_Contrast3[]=
1567 {0x3301, 0xff},//bit[7]:1, enable SDE
1575 static struct reginfo sensor_Contrast4[]=
1578 {0x3301, 0xff},//bit[7]:1, enable SDE
1587 static struct reginfo sensor_Contrast5[]=
1590 {0x3301, 0xff},//bit[7]:1, enable SDE
1598 static struct reginfo sensor_Contrast6[]=
1601 {0x3301, 0xff},//bit[7]:1, enable SDE
1602 {0x3391, 0x04}, //bit[2] enable contrast/brightness
1603 {0x3390, 0x45}, //bit[2] Yoffset sign
1608 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1609 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1613 #if CONFIG_SENSOR_Mirror
1614 static struct reginfo sensor_MirrorOn[]=
1622 static struct reginfo sensor_MirrorOff[]=
1629 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1631 #if CONFIG_SENSOR_Flip
1632 static struct reginfo sensor_FlipOn[]=
1645 static struct reginfo sensor_FlipOff[]=
1657 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1660 #if CONFIG_SENSOR_Scene
1661 static struct reginfo sensor_SceneAuto[] =
1663 #if 0 /* ddl@rock-chips.com : */
1678 static struct reginfo sensor_SceneNight[] =
1681 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1692 {0x3015, 0x50},//add 5 dummy frame
1697 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1713 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1716 #if CONFIG_SENSOR_DigitalZoom
1717 static struct reginfo sensor_Zoom0[] =
1722 static struct reginfo sensor_Zoom1[] =
1727 static struct reginfo sensor_Zoom2[] =
1733 static struct reginfo sensor_Zoom3[] =
1737 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1739 static const struct v4l2_querymenu sensor_menus[] =
1741 #if CONFIG_SENSOR_WhiteBalance
1742 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1743 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1744 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1747 #if CONFIG_SENSOR_Effect
1748 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1749 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1750 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1753 #if CONFIG_SENSOR_Scene
1754 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1757 #if CONFIG_SENSOR_Flash
1758 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1759 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1763 static const struct v4l2_queryctrl sensor_controls[] =
1765 #if CONFIG_SENSOR_WhiteBalance
1767 .id = V4L2_CID_DO_WHITE_BALANCE,
1768 .type = V4L2_CTRL_TYPE_MENU,
1769 .name = "White Balance Control",
1777 #if CONFIG_SENSOR_Brightness
1779 .id = V4L2_CID_BRIGHTNESS,
1780 .type = V4L2_CTRL_TYPE_INTEGER,
1781 .name = "Brightness Control",
1789 #if CONFIG_SENSOR_Effect
1791 .id = V4L2_CID_EFFECT,
1792 .type = V4L2_CTRL_TYPE_MENU,
1793 .name = "Effect Control",
1801 #if CONFIG_SENSOR_Exposure
1803 .id = V4L2_CID_EXPOSURE,
1804 .type = V4L2_CTRL_TYPE_INTEGER,
1805 .name = "Exposure Control",
1813 #if CONFIG_SENSOR_Saturation
1815 .id = V4L2_CID_SATURATION,
1816 .type = V4L2_CTRL_TYPE_INTEGER,
1817 .name = "Saturation Control",
1825 #if CONFIG_SENSOR_Contrast
1827 .id = V4L2_CID_CONTRAST,
1828 .type = V4L2_CTRL_TYPE_INTEGER,
1829 .name = "Contrast Control",
1837 #if CONFIG_SENSOR_Mirror
1839 .id = V4L2_CID_HFLIP,
1840 .type = V4L2_CTRL_TYPE_BOOLEAN,
1841 .name = "Mirror Control",
1849 #if CONFIG_SENSOR_Flip
1851 .id = V4L2_CID_VFLIP,
1852 .type = V4L2_CTRL_TYPE_BOOLEAN,
1853 .name = "Flip Control",
1861 #if CONFIG_SENSOR_Scene
1863 .id = V4L2_CID_SCENE,
1864 .type = V4L2_CTRL_TYPE_MENU,
1865 .name = "Scene Control",
1873 #if CONFIG_SENSOR_DigitalZoom
1875 .id = V4L2_CID_ZOOM_RELATIVE,
1876 .type = V4L2_CTRL_TYPE_INTEGER,
1877 .name = "DigitalZoom Control",
1883 .id = V4L2_CID_ZOOM_ABSOLUTE,
1884 .type = V4L2_CTRL_TYPE_INTEGER,
1885 .name = "DigitalZoom Control",
1893 #if CONFIG_SENSOR_Focus
1895 .id = V4L2_CID_FOCUS_RELATIVE,
1896 .type = V4L2_CTRL_TYPE_INTEGER,
1897 .name = "Focus Control",
1903 .id = V4L2_CID_FOCUS_ABSOLUTE,
1904 .type = V4L2_CTRL_TYPE_INTEGER,
1905 .name = "Focus Control",
1909 .default_value = 125,
1913 #if CONFIG_SENSOR_Flash
1915 .id = V4L2_CID_FLASH,
1916 .type = V4L2_CTRL_TYPE_MENU,
1917 .name = "Flash Control",
1926 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1927 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1928 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1929 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1930 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1931 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1932 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1933 static int sensor_resume(struct soc_camera_device *icd);
1934 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1935 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1936 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1937 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1938 static int sensor_deactivate(struct i2c_client *client);
1940 static struct soc_camera_ops sensor_ops =
1942 .suspend = sensor_suspend,
1943 .resume = sensor_resume,
1944 .set_bus_param = sensor_set_bus_param,
1945 .query_bus_param = sensor_query_bus_param,
1946 .controls = sensor_controls,
1947 .menus = sensor_menus,
1948 .num_controls = ARRAY_SIZE(sensor_controls),
1949 .num_menus = ARRAY_SIZE(sensor_menus),
1952 /* only one fixed colorspace per pixelcode */
1953 struct sensor_datafmt {
1954 enum v4l2_mbus_pixelcode code;
1955 enum v4l2_colorspace colorspace;
1958 /* Find a data format by a pixel code in an array */
1959 static const struct sensor_datafmt *sensor_find_datafmt(
1960 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1964 for (i = 0; i < n; i++)
1965 if (fmt[i].code == code)
1971 static const struct sensor_datafmt sensor_colour_fmts[] = {
1972 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1973 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1976 typedef struct sensor_info_priv_s
1990 unsigned char mirror; /* HFLIP */
1991 unsigned char flip; /* VFLIP */
1992 unsigned int winseqe_cur_addr;
1993 struct sensor_datafmt fmt;
1994 unsigned int funmodule_state;
1995 } sensor_info_priv_t;
1999 struct v4l2_subdev subdev;
2000 struct i2c_client *client;
2001 sensor_info_priv_t info_priv;
2002 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2003 #if CONFIG_SENSOR_I2C_NOSCHED
2004 atomic_t tasklock_cnt;
2006 struct rk29camera_platform_data *sensor_io_request;
2007 struct rk29camera_gpio_res *sensor_gpio_res;
2010 static struct sensor* to_sensor(const struct i2c_client *client)
2012 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2015 static int sensor_task_lock(struct i2c_client *client, int lock)
2017 #if CONFIG_SENSOR_I2C_NOSCHED
2019 struct sensor *sensor = to_sensor(client);
2022 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2023 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2024 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2028 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2029 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2030 goto sensor_task_lock_err;
2035 atomic_add(1, &sensor->tasklock_cnt);
2037 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2038 atomic_sub(1, &sensor->tasklock_cnt);
2040 if (atomic_read(&sensor->tasklock_cnt) == 0)
2045 sensor_task_lock_err:
2053 /* sensor register write */
2054 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2058 struct i2c_msg msg[1];
2061 buf[1] = reg & 0xFF;
2064 msg->addr = client->addr;
2065 msg->flags = client->flags;
2067 msg->len = sizeof(buf);
2068 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2069 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2074 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2075 err = i2c_transfer(client->adapter, msg, 1);
2080 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2088 /* sensor register read */
2089 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2093 struct i2c_msg msg[2];
2096 buf[1] = reg & 0xFF;
2098 msg[0].addr = client->addr;
2099 msg[0].flags = client->flags;
2101 msg[0].len = sizeof(buf);
2102 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2103 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2105 msg[1].addr = client->addr;
2106 msg[1].flags = client->flags|I2C_M_RD;
2109 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2110 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2114 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2115 err = i2c_transfer(client->adapter, msg, 2);
2121 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2129 /* write a array of registers */
2130 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2134 #if CONFIG_SENSOR_I2C_RDWRCHK
2139 if (sensor_task_lock(client, 1) < 0)
2140 goto sensor_write_array_end;
2142 while (regarray[i].reg != 0)
2144 err = sensor_write(client, regarray[i].reg, regarray[i].val);
2148 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2152 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2154 goto sensor_write_array_end;
2157 #if CONFIG_SENSOR_I2C_RDWRCHK
2158 sensor_read(client, regarray[i].reg, &valchk);
2159 if (valchk != regarray[i].val)
2160 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2166 sensor_write_array_end:
2167 sensor_task_lock(client,0);
2171 #if CONFIG_SENSOR_I2C_RDWRCHK
2172 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
2178 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
2179 while(regarray[i].reg != 0)
2181 ret = sensor_read(client,regarray[i].reg,&value);
2184 SENSOR_TR("read value failed\n");
2187 if(regarray[i].val != value)
2189 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
2197 SENSOR_DG("%s check success\n",__FUNCTION__);
2202 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
2204 struct soc_camera_link *icl = to_soc_camera_link(icd);
2207 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2210 case Sensor_PowerDown:
2212 if (icl->powerdown) {
2213 ret = icl->powerdown(icd->pdev, on);
2214 if (ret == RK29_CAM_IO_SUCCESS) {
2218 icl->reset(icd->pdev);
2220 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
2222 goto sensor_power_end;
2229 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2230 struct sensor *sensor = to_sensor(client);
2232 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2233 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2239 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2247 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2249 struct i2c_client *client = v4l2_get_subdevdata(sd);
2250 struct soc_camera_device *icd = client->dev.platform_data;
2251 struct sensor *sensor = to_sensor(client);
2252 const struct v4l2_queryctrl *qctrl;
2253 const struct sensor_datafmt *fmt;
2257 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2259 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2261 goto sensor_INIT_ERR;
2265 if (sensor_task_lock(client,1)<0)
2266 goto sensor_INIT_ERR;
2267 /* ret = sensor_write(client, 0x3012, 0x80);
2270 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2272 goto sensor_INIT_ERR;
2275 mdelay(5); */ //delay 5 microseconds
2276 /* check if it is an sensor sensor */
2277 ret = sensor_read(client, 0x0000, &value);
2279 SENSOR_TR("read chip id high byte failed\n");
2281 goto sensor_INIT_ERR;
2284 pid |= (value << 8);
2286 ret = sensor_read(client, 0x0001, &value);
2288 SENSOR_TR("read chip id low byte failed\n");
2290 goto sensor_INIT_ERR;
2293 pid |= (value & 0xff);
2294 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2295 if (pid == SENSOR_ID) {
2296 sensor->model = SENSOR_V4L2_IDENT;
2298 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2300 goto sensor_INIT_ERR;
2303 ret = sensor_write_array(client, sensor_init_data);
2306 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2307 goto sensor_INIT_ERR;
2309 sensor_task_lock(client,0);
2311 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2312 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2314 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2316 goto sensor_INIT_ERR;
2318 sensor->info_priv.fmt = *fmt;
2320 /* sensor sensor information for initialization */
2321 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2323 sensor->info_priv.whiteBalance = qctrl->default_value;
2324 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2326 sensor->info_priv.brightness = qctrl->default_value;
2327 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2329 sensor->info_priv.effect = qctrl->default_value;
2330 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2332 sensor->info_priv.exposure = qctrl->default_value;
2334 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2336 sensor->info_priv.saturation = qctrl->default_value;
2337 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2339 sensor->info_priv.contrast = qctrl->default_value;
2340 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2342 sensor->info_priv.mirror = qctrl->default_value;
2343 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2345 sensor->info_priv.flip = qctrl->default_value;
2346 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2348 sensor->info_priv.scene = qctrl->default_value;
2349 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2351 sensor->info_priv.digitalzoom = qctrl->default_value;
2353 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2354 #if CONFIG_SENSOR_Focus
2356 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2358 sensor->info_priv.focus = qctrl->default_value;
2361 #if CONFIG_SENSOR_Flash
2362 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2364 sensor->info_priv.flash = qctrl->default_value;
2367 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);
2368 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2371 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2372 sensor_task_lock(client,0);
2373 sensor_deactivate(client);
2377 static int sensor_deactivate(struct i2c_client *client)
2379 struct soc_camera_device *icd = client->dev.platform_data;
2381 struct sensor *sensor = to_sensor(client);
2382 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2384 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2385 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
2386 sensor_write(client, 0x30b0, 0x00);
2387 sensor_write(client, 0x30b1, 0x00);
2389 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2392 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2393 icd->user_width = SENSOR_INIT_WIDTH;
2394 icd->user_height = SENSOR_INIT_HEIGHT;
2395 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2400 static struct reginfo sensor_power_down_sequence[]=
2408 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2411 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2413 if (pm_msg.event == PM_EVENT_SUSPEND) {
2414 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2415 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2417 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2420 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2422 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2427 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2433 static int sensor_resume(struct soc_camera_device *icd)
2437 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2439 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2443 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2449 static int sensor_set_bus_param(struct soc_camera_device *icd,
2450 unsigned long flags)
2456 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2458 struct soc_camera_link *icl = to_soc_camera_link(icd);
2459 unsigned long flags = SENSOR_BUS_PARAM;
2461 return soc_camera_apply_sensor_flags(icl, flags);
2464 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2466 struct i2c_client *client = v4l2_get_subdevdata(sd);
2467 struct soc_camera_device *icd = client->dev.platform_data;
2468 struct sensor *sensor = to_sensor(client);
2470 mf->width = icd->user_width;
2471 mf->height = icd->user_height;
2472 mf->code = sensor->info_priv.fmt.code;
2473 mf->colorspace = sensor->info_priv.fmt.colorspace;
2474 mf->field = V4L2_FIELD_NONE;
2478 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2482 if ((mf->width == 1024) && (mf->height == 768)) {
2484 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2486 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2488 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2490 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2495 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2499 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2503 if ((mf->width == 1280) && (mf->height == 720)) {
2505 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2510 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2513 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2515 struct i2c_client *client = v4l2_get_subdevdata(sd);
2516 const struct sensor_datafmt *fmt;
2517 struct sensor *sensor = to_sensor(client);
2518 const struct v4l2_queryctrl *qctrl;
2519 struct soc_camera_device *icd = client->dev.platform_data;
2520 struct reginfo *winseqe_set_addr=NULL;
2521 int ret=0, set_w,set_h;
2523 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2524 ARRAY_SIZE(sensor_colour_fmts));
2527 goto sensor_s_fmt_end;
2530 if (sensor->info_priv.fmt.code != mf->code) {
2533 case V4L2_MBUS_FMT_YUYV8_2X8:
2535 winseqe_set_addr = sensor_ClrFmt_YUYV;
2538 case V4L2_MBUS_FMT_UYVY8_2X8:
2540 winseqe_set_addr = sensor_ClrFmt_UYVY;
2546 if (winseqe_set_addr != NULL) {
2547 sensor_write_array(client, winseqe_set_addr);
2548 sensor->info_priv.fmt.code = mf->code;
2549 sensor->info_priv.fmt.colorspace= mf->colorspace;
2550 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2552 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2559 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2561 winseqe_set_addr = sensor_qcif;
2565 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2567 winseqe_set_addr = sensor_qvga;
2571 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2573 winseqe_set_addr = sensor_cif;
2577 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2579 winseqe_set_addr = sensor_vga;
2583 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2585 winseqe_set_addr = sensor_svga;
2589 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2591 winseqe_set_addr = sensor_sxga;
2595 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2597 winseqe_set_addr = sensor_uxga;
2603 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2604 set_w = SENSOR_INIT_WIDTH;
2605 set_h = SENSOR_INIT_HEIGHT;
2606 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2609 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2610 #if CONFIG_SENSOR_Flash
2611 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2612 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2613 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2614 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2616 } else { /* ddl@rock-chips.com : Video */
2617 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2618 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2619 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2623 ret |= sensor_write_array(client, winseqe_set_addr);
2625 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2626 #if CONFIG_SENSOR_Flash
2627 if (sensor_fmt_capturechk(sd,mf) == true) {
2628 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2629 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2630 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2634 goto sensor_s_fmt_end;
2637 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2639 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2640 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2641 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2642 if (sensor->info_priv.whiteBalance != 0) {
2643 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2644 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2646 sensor->info_priv.snap2preview = true;
2647 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2648 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2649 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2650 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2651 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2652 sensor->info_priv.video2preview = true;
2653 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2654 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2655 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2656 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2657 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2659 sensor->info_priv.video2preview = false;
2660 sensor->info_priv.snap2preview = false;
2663 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2667 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2677 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2679 struct i2c_client *client = v4l2_get_subdevdata(sd);
2680 struct sensor *sensor = to_sensor(client);
2681 const struct sensor_datafmt *fmt;
2684 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2685 ARRAY_SIZE(sensor_colour_fmts));
2687 fmt = &sensor->info_priv.fmt;
2688 mf->code = fmt->code;
2691 if (mf->height > SENSOR_MAX_HEIGHT)
2692 mf->height = SENSOR_MAX_HEIGHT;
2693 else if (mf->height < SENSOR_MIN_HEIGHT)
2694 mf->height = SENSOR_MIN_HEIGHT;
2696 if (mf->width > SENSOR_MAX_WIDTH)
2697 mf->width = SENSOR_MAX_WIDTH;
2698 else if (mf->width < SENSOR_MIN_WIDTH)
2699 mf->width = SENSOR_MIN_WIDTH;
2701 mf->colorspace = fmt->colorspace;
2706 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2708 struct i2c_client *client = v4l2_get_subdevdata(sd);
2710 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2713 if (id->match.addr != client->addr)
2716 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return gt2005 identifier */
2721 #if CONFIG_SENSOR_Brightness
2722 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2724 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2726 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2728 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2730 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2732 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2735 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2739 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2743 #if CONFIG_SENSOR_Effect
2744 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2746 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2748 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2750 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2752 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2754 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2757 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2761 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2765 #if CONFIG_SENSOR_Exposure
2766 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2768 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2770 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2772 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2774 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2776 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2779 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2783 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2787 #if CONFIG_SENSOR_Saturation
2788 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2790 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2792 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2794 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2796 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2798 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2801 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2805 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2809 #if CONFIG_SENSOR_Contrast
2810 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2812 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2814 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2816 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2818 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2820 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2823 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2827 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2831 #if CONFIG_SENSOR_Mirror
2832 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2834 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2836 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2838 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2840 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2842 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2845 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2849 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2853 #if CONFIG_SENSOR_Flip
2854 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2856 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2858 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2860 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2862 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2864 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2867 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2871 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2875 #if CONFIG_SENSOR_Scene
2876 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2878 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2880 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2882 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2884 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2886 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2889 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2893 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2897 #if CONFIG_SENSOR_WhiteBalance
2898 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2900 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2902 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2904 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2906 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2908 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2911 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2915 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2919 #if CONFIG_SENSOR_DigitalZoom
2920 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2922 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2923 struct sensor *sensor = to_sensor(client);
2924 const struct v4l2_queryctrl *qctrl_info;
2925 int digitalzoom_cur, digitalzoom_total;
2927 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2931 digitalzoom_cur = sensor->info_priv.digitalzoom;
2932 digitalzoom_total = qctrl_info->maximum;
2934 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2936 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2940 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2942 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2946 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2948 value = digitalzoom_total - digitalzoom_cur;
2951 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2953 value = 0 - digitalzoom_cur;
2956 digitalzoom_cur += value;
2958 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2960 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2962 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2965 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2972 #if CONFIG_SENSOR_Flash
2973 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2975 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2976 if (value == 3) { /* ddl@rock-chips.com: torch */
2977 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2979 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2981 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2985 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2990 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2992 struct i2c_client *client = v4l2_get_subdevdata(sd);
2993 struct sensor *sensor = to_sensor(client);
2994 const struct v4l2_queryctrl *qctrl;
2996 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3000 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3006 case V4L2_CID_BRIGHTNESS:
3008 ctrl->value = sensor->info_priv.brightness;
3011 case V4L2_CID_SATURATION:
3013 ctrl->value = sensor->info_priv.saturation;
3016 case V4L2_CID_CONTRAST:
3018 ctrl->value = sensor->info_priv.contrast;
3021 case V4L2_CID_DO_WHITE_BALANCE:
3023 ctrl->value = sensor->info_priv.whiteBalance;
3026 case V4L2_CID_EXPOSURE:
3028 ctrl->value = sensor->info_priv.exposure;
3031 case V4L2_CID_HFLIP:
3033 ctrl->value = sensor->info_priv.mirror;
3036 case V4L2_CID_VFLIP:
3038 ctrl->value = sensor->info_priv.flip;
3049 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3051 struct i2c_client *client = v4l2_get_subdevdata(sd);
3052 struct sensor *sensor = to_sensor(client);
3053 struct soc_camera_device *icd = client->dev.platform_data;
3054 const struct v4l2_queryctrl *qctrl;
3057 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3061 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3067 #if CONFIG_SENSOR_Brightness
3068 case V4L2_CID_BRIGHTNESS:
3070 if (ctrl->value != sensor->info_priv.brightness)
3072 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3076 sensor->info_priv.brightness = ctrl->value;
3081 #if CONFIG_SENSOR_Exposure
3082 case V4L2_CID_EXPOSURE:
3084 if (ctrl->value != sensor->info_priv.exposure)
3086 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3090 sensor->info_priv.exposure = ctrl->value;
3095 #if CONFIG_SENSOR_Saturation
3096 case V4L2_CID_SATURATION:
3098 if (ctrl->value != sensor->info_priv.saturation)
3100 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3104 sensor->info_priv.saturation = ctrl->value;
3109 #if CONFIG_SENSOR_Contrast
3110 case V4L2_CID_CONTRAST:
3112 if (ctrl->value != sensor->info_priv.contrast)
3114 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3118 sensor->info_priv.contrast = ctrl->value;
3123 #if CONFIG_SENSOR_WhiteBalance
3124 case V4L2_CID_DO_WHITE_BALANCE:
3126 if (ctrl->value != sensor->info_priv.whiteBalance)
3128 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3132 sensor->info_priv.whiteBalance = ctrl->value;
3137 #if CONFIG_SENSOR_Mirror
3138 case V4L2_CID_HFLIP:
3140 if (ctrl->value != sensor->info_priv.mirror)
3142 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3144 sensor->info_priv.mirror = ctrl->value;
3149 #if CONFIG_SENSOR_Flip
3150 case V4L2_CID_VFLIP:
3152 if (ctrl->value != sensor->info_priv.flip)
3154 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3156 sensor->info_priv.flip = ctrl->value;
3167 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3169 const struct v4l2_queryctrl *qctrl;
3170 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3171 struct sensor *sensor = to_sensor(client);
3173 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3177 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3181 switch (ext_ctrl->id)
3183 case V4L2_CID_SCENE:
3185 ext_ctrl->value = sensor->info_priv.scene;
3188 case V4L2_CID_EFFECT:
3190 ext_ctrl->value = sensor->info_priv.effect;
3193 case V4L2_CID_ZOOM_ABSOLUTE:
3195 ext_ctrl->value = sensor->info_priv.digitalzoom;
3198 case V4L2_CID_ZOOM_RELATIVE:
3202 case V4L2_CID_FOCUS_ABSOLUTE:
3204 ext_ctrl->value = sensor->info_priv.focus;
3207 case V4L2_CID_FOCUS_RELATIVE:
3211 case V4L2_CID_FLASH:
3213 ext_ctrl->value = sensor->info_priv.flash;
3221 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3223 const struct v4l2_queryctrl *qctrl;
3224 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3225 struct sensor *sensor = to_sensor(client);
3228 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3232 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3237 switch (ext_ctrl->id)
3239 #if CONFIG_SENSOR_Scene
3240 case V4L2_CID_SCENE:
3242 if (ext_ctrl->value != sensor->info_priv.scene)
3244 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3246 sensor->info_priv.scene = ext_ctrl->value;
3251 #if CONFIG_SENSOR_Effect
3252 case V4L2_CID_EFFECT:
3254 if (ext_ctrl->value != sensor->info_priv.effect)
3256 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3258 sensor->info_priv.effect= ext_ctrl->value;
3263 #if CONFIG_SENSOR_DigitalZoom
3264 case V4L2_CID_ZOOM_ABSOLUTE:
3266 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3269 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3271 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3273 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3275 sensor->info_priv.digitalzoom += val_offset;
3277 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3282 case V4L2_CID_ZOOM_RELATIVE:
3284 if (ext_ctrl->value)
3286 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3288 sensor->info_priv.digitalzoom += ext_ctrl->value;
3290 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3295 #if CONFIG_SENSOR_Focus
3296 case V4L2_CID_FOCUS_ABSOLUTE:
3298 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3301 if (ext_ctrl->value != sensor->info_priv.focus)
3303 val_offset = ext_ctrl->value -sensor->info_priv.focus;
3305 sensor->info_priv.focus += val_offset;
3310 case V4L2_CID_FOCUS_RELATIVE:
3312 if (ext_ctrl->value)
3314 sensor->info_priv.focus += ext_ctrl->value;
3316 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
3321 #if CONFIG_SENSOR_Flash
3322 case V4L2_CID_FLASH:
3324 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3326 sensor->info_priv.flash = ext_ctrl->value;
3328 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3339 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3341 struct i2c_client *client = v4l2_get_subdevdata(sd);
3342 struct soc_camera_device *icd = client->dev.platform_data;
3343 int i, error_cnt=0, error_idx=-1;
3346 for (i=0; i<ext_ctrl->count; i++) {
3347 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3354 error_idx = ext_ctrl->count;
3356 if (error_idx != -1) {
3357 ext_ctrl->error_idx = error_idx;
3364 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3366 struct i2c_client *client = v4l2_get_subdevdata(sd);
3367 struct soc_camera_device *icd = client->dev.platform_data;
3368 int i, error_cnt=0, error_idx=-1;
3371 for (i=0; i<ext_ctrl->count; i++) {
3372 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3379 error_idx = ext_ctrl->count;
3381 if (error_idx != -1) {
3382 ext_ctrl->error_idx = error_idx;
3389 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3390 * this wasn't our capture interface, so, we wait for the right one */
3391 static int sensor_video_probe(struct soc_camera_device *icd,
3392 struct i2c_client *client)
3396 struct sensor *sensor = to_sensor(client);
3398 /* We must have a parent by now. And it cannot be a wrong one.
3399 * So this entire test is completely redundant. */
3400 if (!icd->dev.parent ||
3401 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3404 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3406 goto sensor_video_probe_err;
3410 /* ret = sensor_write(client, 0x3012, 0x80);
3413 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3416 mdelay(5); */ //delay 5 microseconds
3418 /* check if it is an sensor sensor */
3419 ret = sensor_read(client, 0x0000, &value);
3421 SENSOR_TR("read chip id high byte failed\n");
3423 goto sensor_video_probe_err;
3426 pid |= (value << 8);
3428 ret = sensor_read(client, 0x0001, &value);
3430 SENSOR_TR("read chip id low byte failed\n");
3432 goto sensor_video_probe_err;
3435 pid |= (value & 0xff);
3436 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3437 if (pid == SENSOR_ID) {
3438 sensor->model = SENSOR_V4L2_IDENT;
3440 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3442 goto sensor_video_probe_err;
3447 sensor_video_probe_err:
3451 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3453 struct i2c_client *client = v4l2_get_subdevdata(sd);
3454 struct soc_camera_device *icd = client->dev.platform_data;
3455 struct sensor *sensor = to_sensor(client);
3456 #if CONFIG_SENSOR_Flash
3461 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3464 case RK29_CAM_SUBDEV_DEACTIVATE:
3466 sensor_deactivate(client);
3470 case RK29_CAM_SUBDEV_IOREQUEST:
3472 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3473 if (sensor->sensor_io_request != NULL) {
3474 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
3475 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
3476 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
3477 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
3478 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
3479 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
3482 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3484 goto sensor_ioctl_end;
3486 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3488 #if CONFIG_SENSOR_Flash
3489 if (sensor->sensor_gpio_res) {
3490 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3491 for (i = 0; i < icd->ops->num_controls; i++) {
3492 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3493 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3496 sensor->info_priv.flash = 0xff;
3497 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3505 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3513 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3514 enum v4l2_mbus_pixelcode *code)
3516 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3519 *code = sensor_colour_fmts[index].code;
3522 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3523 .init = sensor_init,
3524 .g_ctrl = sensor_g_control,
3525 .s_ctrl = sensor_s_control,
3526 .g_ext_ctrls = sensor_g_ext_controls,
3527 .s_ext_ctrls = sensor_s_ext_controls,
3528 .g_chip_ident = sensor_g_chip_ident,
3529 .ioctl = sensor_ioctl,
3532 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3533 .s_mbus_fmt = sensor_s_fmt,
3534 .g_mbus_fmt = sensor_g_fmt,
3535 .try_mbus_fmt = sensor_try_fmt,
3536 .enum_mbus_fmt = sensor_enum_fmt,
3539 static struct v4l2_subdev_ops sensor_subdev_ops = {
3540 .core = &sensor_subdev_core_ops,
3541 .video = &sensor_subdev_video_ops,
3544 static int sensor_probe(struct i2c_client *client,
3545 const struct i2c_device_id *did)
3547 struct sensor *sensor;
3548 struct soc_camera_device *icd = client->dev.platform_data;
3549 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3550 struct soc_camera_link *icl;
3553 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3555 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3559 icl = to_soc_camera_link(icd);
3561 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3565 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3566 dev_warn(&adapter->dev,
3567 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3571 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3575 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3577 /* Second stage probe - when a capture adapter is there */
3578 icd->ops = &sensor_ops;
3580 sensor->info_priv.fmt = sensor_colour_fmts[0];
3582 #if CONFIG_SENSOR_I2C_NOSCHED
3583 atomic_set(&sensor->tasklock_cnt,0);
3586 ret = sensor_video_probe(icd, client);
3589 i2c_set_clientdata(client, NULL);
3593 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3597 static int sensor_remove(struct i2c_client *client)
3599 struct sensor *sensor = to_sensor(client);
3600 struct soc_camera_device *icd = client->dev.platform_data;
3603 i2c_set_clientdata(client, NULL);
3604 client->driver = NULL;
3610 static const struct i2c_device_id sensor_id[] = {
3611 {SENSOR_NAME_STRING(), 0 },
3614 MODULE_DEVICE_TABLE(i2c, sensor_id);
3616 static struct i2c_driver sensor_i2c_driver = {
3618 .name = SENSOR_NAME_STRING(),
3620 .probe = sensor_probe,
3621 .remove = sensor_remove,
3622 .id_table = sensor_id,
3625 static int __init sensor_mod_init(void)
3627 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3628 return i2c_add_driver(&sensor_i2c_driver);
3631 static void __exit sensor_mod_exit(void)
3633 i2c_del_driver(&sensor_i2c_driver);
3636 device_initcall_sync(sensor_mod_init);
3637 module_exit(sensor_mod_exit);
3639 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3640 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3641 MODULE_LICENSE("GPL");