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_HI253
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_HI253
48 #define SENSOR_ID 0x92
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
51 #define SENSOR_MAX_WIDTH_REAL 1600
52 #define SENSOR_MAX_HEIGHT_REAL 1200
53 #if defined(CONFIG_SOC_CAMERA_HI253_INTERPOLATION_5M)
54 #define SENSOR_MAX_WIDTH 2592
55 #define SENSOR_MAX_HEIGHT 1944
56 #elif defined(CONFIG_SOC_CAMERA_HI253_INTERPOLATION_3M)
57 #define SENSOR_MAX_WIDTH 2048
58 #define SENSOR_MAX_HEIGHT 1536
60 #define SENSOR_MAX_WIDTH SENSOR_MAX_WIDTH_REAL
61 #define SENSOR_MAX_HEIGHT SENSOR_MAX_HEIGHT_REAL
64 #define SENSOR_INIT_WIDTH 1600 /* Sensor pixel size for sensor_init_data array */
65 #define SENSOR_INIT_HEIGHT 1200
66 #define SENSOR_INIT_WINSEQADR sensor_uxga
67 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
69 #define CONFIG_SENSOR_WhiteBalance 1
70 #define CONFIG_SENSOR_Brightness 0
71 #define CONFIG_SENSOR_Contrast 0
72 #define CONFIG_SENSOR_Saturation 0
73 #define CONFIG_SENSOR_Effect 1
74 #define CONFIG_SENSOR_Scene 1
75 #define CONFIG_SENSOR_DigitalZoom 0
76 #define CONFIG_SENSOR_Focus 0
77 #define CONFIG_SENSOR_Exposure 0
78 #define CONFIG_SENSOR_Flash 0
79 #define CONFIG_SENSOR_Mirror 0
80 #define CONFIG_SENSOR_Flip 0
82 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
83 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
84 #define CONFIG_SENSOR_I2C_NOSCHED 0
85 #define CONFIG_SENSOR_I2C_RDWRCHK 0
87 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|\
88 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
89 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
91 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
92 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
93 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
94 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
95 #define COLOR_TEMPERATURE_OFFICE_DN 3500
96 #define COLOR_TEMPERATURE_OFFICE_UP 5000
97 #define COLOR_TEMPERATURE_HOME_DN 2500
98 #define COLOR_TEMPERATURE_HOME_UP 3500
100 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
101 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
103 #define SENSOR_AF_IS_ERR (0x00<<0)
104 #define SENSOR_AF_IS_OK (0x01<<0)
105 #define SENSOR_INIT_IS_ERR (0x00<<28)
106 #define SENSOR_INIT_IS_OK (0x01<<28)
115 //flash off in fixed time to prevent from too hot , zyc
117 struct soc_camera_device *icd;
118 struct hrtimer timer;
120 #if CONFIG_SENSOR_Flash
121 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
123 static struct flash_timer flash_off_timer;
124 //for user defined if user want to customize the series , zyc
125 #ifdef CONFIG_HI253_USER_DEFINED_SERIES
126 #include "hi253_user_series.c"
128 /* init SVGA preview */
129 static struct reginfo sensor_init_data[] =
360 {0x11, 0x03}, //lxh,normal
402 {0x10, 0x7f},//lxh,3f
1168 /* 1600X1200 UXGA capture */
1169 static struct reginfo sensor_uxga[] =
1199 /* 1280X1024 SXGA */
1200 static struct reginfo sensor_sxga[] =
1204 static struct reginfo sensor_xga[] =
1209 /* 800X600 SVGA,30fps*/
1210 static struct reginfo sensor_svga[] =
1218 {0x03, 0x12}, //Function
1224 {0x03, 0x13}, //Function
1225 {0x80, 0xfd}, //Function
1252 static struct reginfo sensor_vga[] =
1258 static struct reginfo sensor_cif[] =
1264 static struct reginfo sensor_qvga[] =
1270 static struct reginfo sensor_qcif[] =
1276 static struct reginfo sensor_ClrFmt_YUYV[]=
1283 static struct reginfo sensor_ClrFmt_UYVY[]=
1290 #if CONFIG_SENSOR_WhiteBalance
1291 static struct reginfo sensor_WhiteB_Auto[]=
1305 /* Cloudy Colour Temperature : 6500K - 8000K */
1306 static struct reginfo sensor_WhiteB_Cloudy[]=
1320 /* ClearDay Colour Temperature : 5000K - 6500K */
1321 static struct reginfo sensor_WhiteB_ClearDay[]=
1335 /* Office Colour Temperature : 3500K - 5000K */
1336 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
1351 /* Home Colour Temperature : 2500K - 3500K */
1352 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
1366 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1367 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1371 #if CONFIG_SENSOR_Brightness
1372 static struct reginfo sensor_Brightness0[]=
1380 static struct reginfo sensor_Brightness1[]=
1388 static struct reginfo sensor_Brightness2[]=
1396 static struct reginfo sensor_Brightness3[]=
1404 static struct reginfo sensor_Brightness4[]=
1412 static struct reginfo sensor_Brightness5[]=
1419 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1420 sensor_Brightness4, sensor_Brightness5,NULL,
1425 #if CONFIG_SENSOR_Effect
1426 static struct reginfo sensor_Effect_Normal[] =
1435 static struct reginfo sensor_Effect_WandB[] =
1447 static struct reginfo sensor_Effect_Sepia[] =
1459 static struct reginfo sensor_Effect_Negative[] =
1472 static struct reginfo sensor_Effect_Bluish[] =
1485 static struct reginfo sensor_Effect_Green[] =
1497 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1498 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1501 #if CONFIG_SENSOR_Exposure
1502 static struct reginfo sensor_Exposure0[]=
1508 static struct reginfo sensor_Exposure1[]=
1515 static struct reginfo sensor_Exposure2[]=
1521 static struct reginfo sensor_Exposure3[]=
1527 static struct reginfo sensor_Exposure4[]=
1534 static struct reginfo sensor_Exposure5[]=
1540 static struct reginfo sensor_Exposure6[]=
1547 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1548 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1551 #if CONFIG_SENSOR_Saturation
1552 static struct reginfo sensor_Saturation0[]=
1558 static struct reginfo sensor_Saturation1[]=
1564 static struct reginfo sensor_Saturation2[]=
1568 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1571 #if CONFIG_SENSOR_Contrast
1572 static struct reginfo sensor_Contrast0[]=
1579 static struct reginfo sensor_Contrast1[]=
1586 static struct reginfo sensor_Contrast2[]=
1593 static struct reginfo sensor_Contrast3[]=
1600 static struct reginfo sensor_Contrast4[]=
1608 static struct reginfo sensor_Contrast5[]=
1615 static struct reginfo sensor_Contrast6[]=
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[]=
1633 static struct reginfo sensor_MirrorOff[]=
1638 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1640 #if CONFIG_SENSOR_Flip
1641 static struct reginfo sensor_FlipOn[]=
1647 static struct reginfo sensor_FlipOff[]=
1652 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1655 #if CONFIG_SENSOR_Scene
1656 static struct reginfo sensor_SceneAuto[] =
1662 static struct reginfo sensor_SceneNight[] =
1667 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1670 #if CONFIG_SENSOR_DigitalZoom
1671 static struct reginfo sensor_Zoom0[] =
1676 static struct reginfo sensor_Zoom1[] =
1681 static struct reginfo sensor_Zoom2[] =
1687 static struct reginfo sensor_Zoom3[] =
1691 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1693 static struct v4l2_querymenu sensor_menus[] =
1695 #if CONFIG_SENSOR_WhiteBalance
1696 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1697 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1698 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1701 #if CONFIG_SENSOR_Effect
1702 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1703 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1704 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1707 #if CONFIG_SENSOR_Scene
1708 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1711 #if CONFIG_SENSOR_Flash
1712 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1713 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1717 static struct v4l2_queryctrl sensor_controls[] =
1719 #if CONFIG_SENSOR_WhiteBalance
1721 .id = V4L2_CID_DO_WHITE_BALANCE,
1722 .type = V4L2_CTRL_TYPE_MENU,
1723 .name = "White Balance Control",
1731 #if CONFIG_SENSOR_Brightness
1733 .id = V4L2_CID_BRIGHTNESS,
1734 .type = V4L2_CTRL_TYPE_INTEGER,
1735 .name = "Brightness Control",
1743 #if CONFIG_SENSOR_Effect
1745 .id = V4L2_CID_EFFECT,
1746 .type = V4L2_CTRL_TYPE_MENU,
1747 .name = "Effect Control",
1755 #if CONFIG_SENSOR_Exposure
1757 .id = V4L2_CID_EXPOSURE,
1758 .type = V4L2_CTRL_TYPE_INTEGER,
1759 .name = "Exposure Control",
1767 #if CONFIG_SENSOR_Saturation
1769 .id = V4L2_CID_SATURATION,
1770 .type = V4L2_CTRL_TYPE_INTEGER,
1771 .name = "Saturation Control",
1779 #if CONFIG_SENSOR_Contrast
1781 .id = V4L2_CID_CONTRAST,
1782 .type = V4L2_CTRL_TYPE_INTEGER,
1783 .name = "Contrast Control",
1791 #if CONFIG_SENSOR_Mirror
1793 .id = V4L2_CID_HFLIP,
1794 .type = V4L2_CTRL_TYPE_BOOLEAN,
1795 .name = "Mirror Control",
1803 #if CONFIG_SENSOR_Flip
1805 .id = V4L2_CID_VFLIP,
1806 .type = V4L2_CTRL_TYPE_BOOLEAN,
1807 .name = "Flip Control",
1815 #if CONFIG_SENSOR_Scene
1817 .id = V4L2_CID_SCENE,
1818 .type = V4L2_CTRL_TYPE_MENU,
1819 .name = "Scene Control",
1827 #if CONFIG_SENSOR_DigitalZoom
1829 .id = V4L2_CID_ZOOM_RELATIVE,
1830 .type = V4L2_CTRL_TYPE_INTEGER,
1831 .name = "DigitalZoom Control",
1837 .id = V4L2_CID_ZOOM_ABSOLUTE,
1838 .type = V4L2_CTRL_TYPE_INTEGER,
1839 .name = "DigitalZoom Control",
1847 #if CONFIG_SENSOR_Focus
1849 .id = V4L2_CID_FOCUS_RELATIVE,
1850 .type = V4L2_CTRL_TYPE_INTEGER,
1851 .name = "Focus Control",
1857 .id = V4L2_CID_FOCUS_ABSOLUTE,
1858 .type = V4L2_CTRL_TYPE_INTEGER,
1859 .name = "Focus Control",
1863 .default_value = 125,
1867 #if CONFIG_SENSOR_Flash
1869 .id = V4L2_CID_FLASH,
1870 .type = V4L2_CTRL_TYPE_MENU,
1871 .name = "Flash Control",
1880 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1881 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1882 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1883 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1884 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1885 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1886 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1887 static int sensor_resume(struct soc_camera_device *icd);
1888 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1889 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1890 #if CONFIG_SENSOR_Effect
1891 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1893 #if CONFIG_SENSOR_WhiteBalance
1894 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1896 static int sensor_deactivate(struct i2c_client *client);
1898 static struct soc_camera_ops sensor_ops =
1900 .suspend = sensor_suspend,
1901 .resume = sensor_resume,
1902 .set_bus_param = sensor_set_bus_param,
1903 .query_bus_param = sensor_query_bus_param,
1904 .controls = sensor_controls,
1905 .menus = sensor_menus,
1906 .num_controls = ARRAY_SIZE(sensor_controls),
1907 .num_menus = ARRAY_SIZE(sensor_menus),
1910 /* only one fixed colorspace per pixelcode */
1911 struct sensor_datafmt {
1912 enum v4l2_mbus_pixelcode code;
1913 enum v4l2_colorspace colorspace;
1916 /* Find a data format by a pixel code in an array */
1917 static const struct sensor_datafmt *sensor_find_datafmt(
1918 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1922 for (i = 0; i < n; i++)
1923 if (fmt[i].code == code)
1929 static const struct sensor_datafmt sensor_colour_fmts[] = {
1930 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1931 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1934 typedef struct sensor_info_priv_s
1948 unsigned char mirror; /* HFLIP */
1949 unsigned char flip; /* VFLIP */
1950 unsigned int winseqe_cur_addr;
1951 struct sensor_datafmt fmt;
1952 unsigned int funmodule_state;
1954 } sensor_info_priv_t;
1958 struct v4l2_subdev subdev;
1959 struct i2c_client *client;
1960 sensor_info_priv_t info_priv;
1961 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1962 #if CONFIG_SENSOR_I2C_NOSCHED
1963 atomic_t tasklock_cnt;
1965 struct rk29camera_platform_data *sensor_io_request;
1966 struct rk29camera_gpio_res *sensor_gpio_res;
1969 static struct sensor* to_sensor(const struct i2c_client *client)
1971 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1974 static int sensor_task_lock(struct i2c_client *client, int lock)
1976 #if CONFIG_SENSOR_I2C_NOSCHED
1978 struct sensor *sensor = to_sensor(client);
1981 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1982 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1983 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1987 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1988 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1989 goto sensor_task_lock_err;
1994 atomic_add(1, &sensor->tasklock_cnt);
1996 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1997 atomic_sub(1, &sensor->tasklock_cnt);
1999 if (atomic_read(&sensor->tasklock_cnt) == 0)
2004 sensor_task_lock_err:
2011 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
2015 struct i2c_msg msg[1];
2020 msg->addr = client->addr;
2021 msg->flags = client->flags;
2023 msg->len = sizeof(buf);
2024 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2025 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2030 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2031 err = i2c_transfer(client->adapter, msg, 1);
2036 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2044 /* sensor register read */
2045 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
2049 struct i2c_msg msg[2];
2053 msg[0].addr = client->addr;
2054 msg[0].flags = client->flags;
2056 msg[0].len = sizeof(buf);
2057 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2058 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2060 msg[1].addr = client->addr;
2061 msg[1].flags = client->flags|I2C_M_RD;
2064 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2065 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2069 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2070 err = i2c_transfer(client->adapter, msg, 2);
2076 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2085 /* write a array of registers */
2086 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2090 #if CONFIG_SENSOR_I2C_RDWRCHK
2095 if (sensor_task_lock(client, 1) < 0)
2096 goto sensor_write_array_end;
2097 while (regarray[i].reg != END_REG)
2099 err = sensor_write(client, regarray[i].reg, regarray[i].val);
2103 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2107 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2109 goto sensor_write_array_end;
2112 #if CONFIG_SENSOR_I2C_RDWRCHK
2114 sensor_read(client, regarray[i].reg, &valchk);
2115 if (valchk != regarray[i].val)
2116 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2122 sensor_write_array_end:
2123 sensor_task_lock(client,0);
2126 #if CONFIG_SENSOR_I2C_RDWRCHK
2127 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
2135 while (regarray[i].reg != 0)
2137 sensor_read(client, regarray[i].reg, &valchk);
2138 if (valchk != regarray[i].val)
2139 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2146 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
2148 struct soc_camera_link *icl = to_soc_camera_link(icd);
2151 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2154 case Sensor_PowerDown:
2156 if (icl->powerdown) {
2157 ret = icl->powerdown(icd->pdev, on);
2158 if (ret == RK29_CAM_IO_SUCCESS) {
2162 icl->reset(icd->pdev);
2164 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
2166 goto sensor_power_end;
2173 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2174 struct sensor *sensor = to_sensor(client);
2176 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2177 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2179 //flash off after 2 secs
2180 hrtimer_cancel(&(flash_off_timer.timer));
2181 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
2188 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2195 #if CONFIG_SENSOR_Flash
2196 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
2197 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
2198 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
2199 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
2204 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2206 struct i2c_client *client = v4l2_get_subdevdata(sd);
2207 struct soc_camera_device *icd = client->dev.platform_data;
2208 struct sensor *sensor = to_sensor(client);
2209 const struct v4l2_queryctrl *qctrl;
2210 const struct sensor_datafmt *fmt;
2214 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2216 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2218 goto sensor_INIT_ERR;
2222 if (sensor_task_lock(client,1)<0)
2223 goto sensor_INIT_ERR;
2225 ret = sensor_write(client, 0x01, 0xF9);
2228 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2230 goto sensor_INIT_ERR;
2233 mdelay(5); //delay 5 microseconds
2234 /* check if it is an sensor sensor */
2235 ret = sensor_read(client, 0x04, &value);
2237 SENSOR_TR("read chip id high byte failed\n");
2239 goto sensor_INIT_ERR;
2243 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2244 if (value == SENSOR_ID) {
2245 sensor->model = SENSOR_V4L2_IDENT;
2247 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2249 goto sensor_INIT_ERR;
2252 ret = sensor_write_array(client, sensor_init_data);
2255 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2256 goto sensor_INIT_ERR;
2258 sensor_task_lock(client,0);
2259 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2260 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2262 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2264 goto sensor_INIT_ERR;
2266 sensor->info_priv.fmt = *fmt;
2268 /* sensor sensor information for initialization */
2269 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2271 sensor->info_priv.whiteBalance = qctrl->default_value;
2272 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2274 sensor->info_priv.brightness = qctrl->default_value;
2275 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2277 sensor->info_priv.effect = qctrl->default_value;
2278 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2280 sensor->info_priv.exposure = qctrl->default_value;
2282 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2284 sensor->info_priv.saturation = qctrl->default_value;
2285 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2287 sensor->info_priv.contrast = qctrl->default_value;
2288 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2290 sensor->info_priv.mirror = qctrl->default_value;
2291 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2293 sensor->info_priv.flip = qctrl->default_value;
2294 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2296 sensor->info_priv.scene = qctrl->default_value;
2297 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2299 sensor->info_priv.digitalzoom = qctrl->default_value;
2301 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2302 #if CONFIG_SENSOR_Focus
2304 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2306 sensor->info_priv.focus = qctrl->default_value;
2309 #if CONFIG_SENSOR_Flash
2310 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2312 sensor->info_priv.flash = qctrl->default_value;
2313 flash_off_timer.icd = icd;
2314 flash_off_timer.timer.function = flash_off_func;
2317 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);
2319 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2322 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2323 sensor_task_lock(client,0);
2324 sensor_deactivate(client);
2328 static int sensor_deactivate(struct i2c_client *client)
2330 struct soc_camera_device *icd = client->dev.platform_data;
2331 struct sensor *sensor = to_sensor(client);
2332 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2334 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2335 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2337 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2338 icd->user_width = SENSOR_INIT_WIDTH;
2339 icd->user_height = SENSOR_INIT_HEIGHT;
2341 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2345 static struct reginfo sensor_power_down_sequence[]=
2349 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2352 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2354 if (pm_msg.event == PM_EVENT_SUSPEND) {
2355 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2356 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2358 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2361 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2363 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2368 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2374 static int sensor_resume(struct soc_camera_device *icd)
2378 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2380 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2384 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2390 static int sensor_set_bus_param(struct soc_camera_device *icd,
2391 unsigned long flags)
2397 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2399 struct soc_camera_link *icl = to_soc_camera_link(icd);
2400 unsigned long flags = SENSOR_BUS_PARAM;
2402 return soc_camera_apply_sensor_flags(icl, flags);
2405 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2407 struct i2c_client *client = v4l2_get_subdevdata(sd);
2408 struct soc_camera_device *icd = client->dev.platform_data;
2409 struct sensor *sensor = to_sensor(client);
2411 mf->width = icd->user_width;
2412 mf->height = icd->user_height;
2413 mf->code = sensor->info_priv.fmt.code;
2414 mf->colorspace = sensor->info_priv.fmt.colorspace;
2415 mf->field = V4L2_FIELD_NONE;
2419 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2423 if ((mf->width == 1024) && (mf->height == 768)) {
2425 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2427 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2429 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2431 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2436 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2440 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2444 if ((mf->width == 1280) && (mf->height == 720)) {
2446 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2451 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2454 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2456 struct i2c_client *client = v4l2_get_subdevdata(sd);
2457 struct sensor *sensor = to_sensor(client);
2458 const struct sensor_datafmt *fmt;
2459 const struct v4l2_queryctrl *qctrl;
2460 struct soc_camera_device *icd = client->dev.platform_data;
2461 struct reginfo *winseqe_set_addr=NULL;
2462 int ret=0, set_w,set_h;
2464 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2465 ARRAY_SIZE(sensor_colour_fmts));
2468 goto sensor_s_fmt_end;
2471 if (sensor->info_priv.fmt.code != mf->code) {
2474 case V4L2_MBUS_FMT_YUYV8_2X8:
2476 winseqe_set_addr = sensor_ClrFmt_YUYV;
2479 case V4L2_MBUS_FMT_UYVY8_2X8:
2481 winseqe_set_addr = sensor_ClrFmt_UYVY;
2487 if (winseqe_set_addr != NULL) {
2488 sensor_write_array(client, winseqe_set_addr);
2489 sensor->info_priv.fmt.code = mf->code;
2490 sensor->info_priv.fmt.colorspace= mf->colorspace;
2491 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2493 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2500 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg != END_REG))
2502 winseqe_set_addr = sensor_qcif;
2506 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg != END_REG))
2508 winseqe_set_addr = sensor_qvga;
2512 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg != END_REG))
2514 winseqe_set_addr = sensor_cif;
2518 else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg != END_REG))
2520 winseqe_set_addr = sensor_vga;
2524 else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg != END_REG))
2526 winseqe_set_addr = sensor_svga;
2530 else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg != END_REG))
2532 winseqe_set_addr = sensor_xga;
2536 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg != END_REG))
2538 winseqe_set_addr = sensor_sxga;
2542 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg != END_REG))
2544 winseqe_set_addr = sensor_uxga;
2548 #if defined(CONFIG_SOC_CAMERA_HI253_INTERPOLATION)
2549 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
2551 winseqe_set_addr = sensor_uxga;
2552 set_w = SENSOR_MAX_WIDTH_REAL;
2553 set_h = SENSOR_MAX_HEIGHT_REAL;
2558 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2559 set_w = SENSOR_INIT_WIDTH;
2560 set_h = SENSOR_INIT_HEIGHT;
2562 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2565 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2566 #if CONFIG_SENSOR_Flash
2567 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2568 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2569 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2570 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2572 } else { /* ddl@rock-chips.com : Video */
2573 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2574 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2575 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2579 ret |= sensor_write_array(client, winseqe_set_addr);
2581 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2582 #if CONFIG_SENSOR_Flash
2583 if (sensor_fmt_capturechk(sd,f) == true) {
2584 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2585 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2586 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2590 goto sensor_s_fmt_end;
2593 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2595 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2596 #if CONFIG_SENSOR_Effect
2597 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2598 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2600 #if CONFIG_SENSOR_WhiteBalance
2601 if (sensor->info_priv.whiteBalance != 0) {
2602 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2603 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2606 sensor->info_priv.snap2preview = true;
2607 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2608 #if CONFIG_SENSOR_Effect
2609 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2610 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2612 #if CONFIG_SENSOR_WhiteBalance
2613 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2614 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2616 sensor->info_priv.video2preview = true;
2617 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2618 #if CONFIG_SENSOR_Effect
2619 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2620 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2622 #if CONFIG_SENSOR_WhiteBalance
2623 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2624 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2626 sensor->info_priv.video2preview = false;
2627 sensor->info_priv.snap2preview = false;
2630 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2634 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2644 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2646 struct i2c_client *client = v4l2_get_subdevdata(sd);
2647 struct sensor *sensor = to_sensor(client);
2648 const struct sensor_datafmt *fmt;
2649 int ret = 0,set_w,set_h;;
2651 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2652 ARRAY_SIZE(sensor_colour_fmts));
2654 fmt = &sensor->info_priv.fmt;
2655 mf->code = fmt->code;
2658 /* ddl@rock-chips.com : It is query max resolution only. */
2659 if (mf->reserved[6] == 0xfefe5a5a) {
2660 mf->height = SENSOR_MAX_HEIGHT;
2661 mf->width = SENSOR_MAX_WIDTH;
2663 goto sensor_try_fmt_end;
2666 if (mf->height > SENSOR_MAX_HEIGHT)
2667 mf->height = SENSOR_MAX_HEIGHT;
2668 else if (mf->height < SENSOR_MIN_HEIGHT)
2669 mf->height = SENSOR_MIN_HEIGHT;
2671 if (mf->width > SENSOR_MAX_WIDTH)
2672 mf->width = SENSOR_MAX_WIDTH;
2673 else if (mf->width < SENSOR_MIN_WIDTH)
2674 mf->width = SENSOR_MIN_WIDTH;
2679 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2684 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2689 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2694 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2699 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2704 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2709 #if defined(CONFIG_SOC_CAMERA_HI253_INTERPOLATION)
2710 else if (((set_w <= SENSOR_MAX_WIDTH) && (set_h <= SENSOR_MAX_HEIGHT)) )
2712 set_w = SENSOR_MAX_WIDTH_REAL;
2713 set_h = SENSOR_MAX_HEIGHT_REAL;
2719 set_w = SENSOR_INIT_WIDTH;
2720 set_h = SENSOR_INIT_HEIGHT;
2726 mf->colorspace = fmt->colorspace;
2731 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2733 struct i2c_client *client = v4l2_get_subdevdata(sd);
2735 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2738 if (id->match.addr != client->addr)
2741 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2746 #if CONFIG_SENSOR_Brightness
2747 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2749 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2751 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2753 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2755 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2757 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2760 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2764 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2768 #if CONFIG_SENSOR_Effect
2769 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2771 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2773 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2775 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2777 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2779 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2782 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2786 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2790 #if CONFIG_SENSOR_Exposure
2791 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2793 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2795 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2797 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2799 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2801 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2804 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2808 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2812 #if CONFIG_SENSOR_Saturation
2813 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2815 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2817 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2819 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2821 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2823 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2826 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2830 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2834 #if CONFIG_SENSOR_Contrast
2835 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2837 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2839 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2841 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2843 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2845 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2848 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2852 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2856 #if CONFIG_SENSOR_Mirror
2857 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2859 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2861 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2863 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2865 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2867 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2870 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2874 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2878 #if CONFIG_SENSOR_Flip
2879 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2881 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2883 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2885 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2887 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2889 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2892 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2896 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2900 #if CONFIG_SENSOR_Scene
2901 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2903 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2905 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2907 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2909 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2911 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2914 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2918 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2922 #if CONFIG_SENSOR_WhiteBalance
2923 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2925 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2927 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2929 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2931 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2933 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2936 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2940 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2944 #if CONFIG_SENSOR_DigitalZoom
2945 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2947 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2948 struct sensor *sensor = to_sensor(client);
2949 const struct v4l2_queryctrl *qctrl_info;
2950 int digitalzoom_cur, digitalzoom_total;
2952 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2956 digitalzoom_cur = sensor->info_priv.digitalzoom;
2957 digitalzoom_total = qctrl_info->maximum;
2959 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2961 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2965 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2967 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2971 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2973 *value = digitalzoom_total - digitalzoom_cur;
2976 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2978 value = 0 - digitalzoom_cur;
2981 digitalzoom_cur += value;
2983 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2985 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2987 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2990 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2997 #if CONFIG_SENSOR_Flash
2998 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3000 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3001 if (value == 3) { /* ddl@rock-chips.com: torch */
3002 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
3004 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3006 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3010 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3015 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3017 struct i2c_client *client = v4l2_get_subdevdata(sd);
3018 struct sensor *sensor = to_sensor(client);
3019 const struct v4l2_queryctrl *qctrl;
3021 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3025 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3031 case V4L2_CID_BRIGHTNESS:
3033 ctrl->value = sensor->info_priv.brightness;
3036 case V4L2_CID_SATURATION:
3038 ctrl->value = sensor->info_priv.saturation;
3041 case V4L2_CID_CONTRAST:
3043 ctrl->value = sensor->info_priv.contrast;
3046 case V4L2_CID_DO_WHITE_BALANCE:
3048 ctrl->value = sensor->info_priv.whiteBalance;
3051 case V4L2_CID_EXPOSURE:
3053 ctrl->value = sensor->info_priv.exposure;
3056 case V4L2_CID_HFLIP:
3058 ctrl->value = sensor->info_priv.mirror;
3061 case V4L2_CID_VFLIP:
3063 ctrl->value = sensor->info_priv.flip;
3074 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3076 struct i2c_client *client = v4l2_get_subdevdata(sd);
3077 struct sensor *sensor = to_sensor(client);
3078 struct soc_camera_device *icd = client->dev.platform_data;
3079 const struct v4l2_queryctrl *qctrl;
3082 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3086 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3092 #if CONFIG_SENSOR_Brightness
3093 case V4L2_CID_BRIGHTNESS:
3095 if (ctrl->value != sensor->info_priv.brightness)
3097 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3101 sensor->info_priv.brightness = ctrl->value;
3106 #if CONFIG_SENSOR_Exposure
3107 case V4L2_CID_EXPOSURE:
3109 if (ctrl->value != sensor->info_priv.exposure)
3111 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3115 sensor->info_priv.exposure = ctrl->value;
3120 #if CONFIG_SENSOR_Saturation
3121 case V4L2_CID_SATURATION:
3123 if (ctrl->value != sensor->info_priv.saturation)
3125 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3129 sensor->info_priv.saturation = ctrl->value;
3134 #if CONFIG_SENSOR_Contrast
3135 case V4L2_CID_CONTRAST:
3137 if (ctrl->value != sensor->info_priv.contrast)
3139 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3143 sensor->info_priv.contrast = ctrl->value;
3148 #if CONFIG_SENSOR_WhiteBalance
3149 case V4L2_CID_DO_WHITE_BALANCE:
3151 if (ctrl->value != sensor->info_priv.whiteBalance)
3153 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3157 sensor->info_priv.whiteBalance = ctrl->value;
3162 #if CONFIG_SENSOR_Mirror
3163 case V4L2_CID_HFLIP:
3165 if (ctrl->value != sensor->info_priv.mirror)
3167 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3169 sensor->info_priv.mirror = ctrl->value;
3174 #if CONFIG_SENSOR_Flip
3175 case V4L2_CID_VFLIP:
3177 if (ctrl->value != sensor->info_priv.flip)
3179 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3181 sensor->info_priv.flip = ctrl->value;
3192 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3194 const struct v4l2_queryctrl *qctrl;
3195 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3196 struct sensor *sensor = to_sensor(client);
3198 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3202 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3206 switch (ext_ctrl->id)
3208 case V4L2_CID_SCENE:
3210 ext_ctrl->value = sensor->info_priv.scene;
3213 case V4L2_CID_EFFECT:
3215 ext_ctrl->value = sensor->info_priv.effect;
3218 case V4L2_CID_ZOOM_ABSOLUTE:
3220 ext_ctrl->value = sensor->info_priv.digitalzoom;
3223 case V4L2_CID_ZOOM_RELATIVE:
3227 case V4L2_CID_FOCUS_ABSOLUTE:
3229 ext_ctrl->value = sensor->info_priv.focus;
3232 case V4L2_CID_FOCUS_RELATIVE:
3236 case V4L2_CID_FLASH:
3238 ext_ctrl->value = sensor->info_priv.flash;
3246 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3248 const struct v4l2_queryctrl *qctrl;
3249 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3250 struct sensor *sensor = to_sensor(client);
3253 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3257 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3262 switch (ext_ctrl->id)
3264 #if CONFIG_SENSOR_Scene
3265 case V4L2_CID_SCENE:
3267 if (ext_ctrl->value != sensor->info_priv.scene)
3269 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3271 sensor->info_priv.scene = ext_ctrl->value;
3276 #if CONFIG_SENSOR_Effect
3277 case V4L2_CID_EFFECT:
3279 if (ext_ctrl->value != sensor->info_priv.effect)
3281 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3283 sensor->info_priv.effect= ext_ctrl->value;
3288 #if CONFIG_SENSOR_DigitalZoom
3289 case V4L2_CID_ZOOM_ABSOLUTE:
3291 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3294 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3296 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3298 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3300 sensor->info_priv.digitalzoom += val_offset;
3302 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3307 case V4L2_CID_ZOOM_RELATIVE:
3309 if (ext_ctrl->value)
3311 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3313 sensor->info_priv.digitalzoom += ext_ctrl->value;
3315 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3320 #if CONFIG_SENSOR_Focus
3321 case V4L2_CID_FOCUS_ABSOLUTE:
3323 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3326 if (ext_ctrl->value != sensor->info_priv.focus)
3328 val_offset = ext_ctrl->value -sensor->info_priv.focus;
3330 sensor->info_priv.focus += val_offset;
3335 case V4L2_CID_FOCUS_RELATIVE:
3337 if (ext_ctrl->value)
3339 sensor->info_priv.focus += ext_ctrl->value;
3341 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
3346 #if CONFIG_SENSOR_Flash
3347 case V4L2_CID_FLASH:
3349 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3351 sensor->info_priv.flash = ext_ctrl->value;
3353 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3364 static int sensor_g_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_g_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 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3391 struct i2c_client *client = v4l2_get_subdevdata(sd);
3392 struct soc_camera_device *icd = client->dev.platform_data;
3393 int i, error_cnt=0, error_idx=-1;
3396 for (i=0; i<ext_ctrl->count; i++) {
3397 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3404 error_idx = ext_ctrl->count;
3406 if (error_idx != -1) {
3407 ext_ctrl->error_idx = error_idx;
3414 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3415 * this wasn't our capture interface, so, we wait for the right one */
3416 static int sensor_video_probe(struct soc_camera_device *icd,
3417 struct i2c_client *client)
3421 struct sensor *sensor = to_sensor(client);
3423 /* We must have a parent by now. And it cannot be a wrong one.
3424 * So this entire test is completely redundant. */
3425 if (!icd->dev.parent ||
3426 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3429 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3431 goto sensor_video_probe_err;
3435 ret = sensor_write(client, 0x01, 0xf9);
3438 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3441 mdelay(5); //delay 5 microseconds
3443 /* check if it is an sensor sensor */
3444 ret = sensor_read(client, 0x04, &value);
3446 SENSOR_TR("read chip id high byte failed\n");
3448 goto sensor_video_probe_err;
3451 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), value);
3452 if (value == SENSOR_ID) {
3453 sensor->model = SENSOR_V4L2_IDENT;
3455 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
3457 goto sensor_video_probe_err;
3462 sensor_video_probe_err:
3466 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3468 struct i2c_client *client = v4l2_get_subdevdata(sd);
3469 struct soc_camera_device *icd = client->dev.platform_data;
3470 struct sensor *sensor = to_sensor(client);
3472 #if CONFIG_SENSOR_Flash
3476 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3479 case RK29_CAM_SUBDEV_DEACTIVATE:
3481 sensor_deactivate(client);
3485 case RK29_CAM_SUBDEV_IOREQUEST:
3487 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3488 if (sensor->sensor_io_request != NULL) {
3489 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
3490 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
3491 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
3492 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
3493 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
3494 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
3497 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3499 goto sensor_ioctl_end;
3501 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3503 #if CONFIG_SENSOR_Flash
3504 if (sensor->sensor_gpio_res) {
3505 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3506 for (i = 0; i < icd->ops->num_controls; i++) {
3507 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3508 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3509 sensor_controls[i].id=0xffff;
3512 sensor->info_priv.flash = 0xff;
3513 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3514 }else{ //two cameras are the same,need to deal diffrently ,zyc
3515 for (i = 0; i < icd->ops->num_controls; i++) {
3516 if(0xffff == icd->ops->controls[i].id){
3517 sensor_controls[i].id=V4L2_CID_FLASH;
3527 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3535 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3536 enum v4l2_mbus_pixelcode *code)
3538 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3541 *code = sensor_colour_fmts[index].code;
3544 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3545 .init = sensor_init,
3546 .g_ctrl = sensor_g_control,
3547 .s_ctrl = sensor_s_control,
3548 .g_ext_ctrls = sensor_g_ext_controls,
3549 .s_ext_ctrls = sensor_s_ext_controls,
3550 .g_chip_ident = sensor_g_chip_ident,
3551 .ioctl = sensor_ioctl,
3555 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3556 .s_mbus_fmt = sensor_s_fmt,
3557 .g_mbus_fmt = sensor_g_fmt,
3558 .try_mbus_fmt = sensor_try_fmt,
3559 .enum_mbus_fmt = sensor_enum_fmt,
3562 static struct v4l2_subdev_ops sensor_subdev_ops = {
3563 .core = &sensor_subdev_core_ops,
3564 .video = &sensor_subdev_video_ops,
3567 static int sensor_probe(struct i2c_client *client,
3568 const struct i2c_device_id *did)
3570 struct sensor *sensor;
3571 struct soc_camera_device *icd = client->dev.platform_data;
3572 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3573 struct soc_camera_link *icl;
3576 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3578 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3582 icl = to_soc_camera_link(icd);
3584 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3588 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3589 dev_warn(&adapter->dev,
3590 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3594 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3598 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3600 /* Second stage probe - when a capture adapter is there */
3601 icd->ops = &sensor_ops;
3602 sensor->info_priv.fmt = sensor_colour_fmts[0];
3603 #if CONFIG_SENSOR_I2C_NOSCHED
3604 atomic_set(&sensor->tasklock_cnt,0);
3607 ret = sensor_video_probe(icd, client);
3610 i2c_set_clientdata(client, NULL);
3614 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3615 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3619 static int sensor_remove(struct i2c_client *client)
3621 struct sensor *sensor = to_sensor(client);
3622 struct soc_camera_device *icd = client->dev.platform_data;
3625 i2c_set_clientdata(client, NULL);
3626 client->driver = NULL;
3632 static const struct i2c_device_id sensor_id[] = {
3633 {SENSOR_NAME_STRING(), 0 },
3636 MODULE_DEVICE_TABLE(i2c, sensor_id);
3638 static struct i2c_driver sensor_i2c_driver = {
3640 .name = SENSOR_NAME_STRING(),
3642 .probe = sensor_probe,
3643 .remove = sensor_remove,
3644 .id_table = sensor_id,
3647 static int __init sensor_mod_init(void)
3649 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3650 return i2c_add_driver(&sensor_i2c_driver);
3653 static void __exit sensor_mod_exit(void)
3655 i2c_del_driver(&sensor_i2c_driver);
3658 device_initcall_sync(sensor_mod_init);
3659 module_exit(sensor_mod_exit);
3661 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3662 MODULE_AUTHOR("lxh@wisky.com.cn");
3663 MODULE_LICENSE("GPL");