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/rk_camera.h>
23 #include <linux/vmalloc.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 RK_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 sensor_init_width /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT sensor_init_height
55 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
56 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
57 #define SENSOR_BUS_PARAM sensor_init_busparam
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 1
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
78 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
79 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
80 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
81 #define COLOR_TEMPERATURE_OFFICE_DN 3500
82 #define COLOR_TEMPERATURE_OFFICE_UP 5000
83 #define COLOR_TEMPERATURE_HOME_DN 2500
84 #define COLOR_TEMPERATURE_HOME_UP 3500
86 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
87 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
89 #define SENSOR_AF_IS_ERR (0x00<<0)
90 #define SENSOR_AF_IS_OK (0x01<<0)
91 #define SENSOR_INIT_IS_ERR (0x00<<28)
92 #define SENSOR_INIT_IS_OK (0x01<<28)
100 static s32 sensor_init_width = 0;
101 static s32 sensor_init_height = 0;
102 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
103 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
104 static struct reginfo* sensor_init_data_p = NULL;
105 static struct reginfo* sensor_init_winseq_p = NULL;
106 static struct reginfo* sensor_init_winseq_board = NULL;
107 /* init 800*600 SVGA */
108 static struct reginfo sensor_init_data[] =
563 ///////////////////////////
597 static struct reginfo sensor_uxga[] =
614 static struct reginfo sensor_sxga[] =
629 static struct reginfo sensor_svga[] =
1111 static struct reginfo sensor_vga[] =
1148 static struct reginfo sensor_cif[] =
1154 static struct reginfo sensor_qvga[] =
1162 static struct reginfo sensor_qcif[] =
1169 static struct reginfo gt2005_qqvga[] =
1213 static struct reginfo gt2005_Sharpness_auto[] =
1218 static struct reginfo gt2005_Sharpness1[] =
1224 static struct reginfo gt2005_Sharpness2[][3] =
1231 static struct reginfo gt2005_Sharpness3[] =
1237 static struct reginfo gt2005_Sharpness4[]=
1244 static struct reginfo gt2005_Sharpness5[] =
1252 static struct reginfo sensor_ClrFmt_YUYV[]=
1258 static struct reginfo sensor_ClrFmt_UYVY[]=
1264 #if CONFIG_SENSOR_WhiteBalance
1265 static struct reginfo sensor_WhiteB_Auto[]=
1267 {0x3306, 0x00}, //AWB auto, bit[1]:0,auto
1270 /* Cloudy Colour Temperature : 6500K - 8000K */
1271 static struct reginfo sensor_WhiteB_Cloudy[]=
1279 /* ClearDay Colour Temperature : 5000K - 6500K */
1280 static struct reginfo sensor_WhiteB_ClearDay[]=
1283 {0x3306, 0x02}, //AWB off
1289 /* Office Colour Temperature : 3500K - 5000K */
1290 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
1300 /* Home Colour Temperature : 2500K - 3500K */
1301 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
1310 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1311 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1315 #if CONFIG_SENSOR_Brightness
1316 static struct reginfo sensor_Brightness0[]=
1319 {0x3301, 0xff},//bit[7]:1, enable SDE
1326 static struct reginfo sensor_Brightness1[]=
1329 {0x3301, 0xff},//bit[7]:1, enable SDE
1336 static struct reginfo sensor_Brightness2[]=
1339 {0x3301, 0xff},//bit[7]:1, enable SDE
1346 static struct reginfo sensor_Brightness3[]=
1349 {0x3301, 0xff},//bit[7]:1, enable SDE
1356 static struct reginfo sensor_Brightness4[]=
1359 {0x3301, 0xff},//bit[7]:1, enable SDE
1366 static struct reginfo sensor_Brightness5[]=
1369 {0x3301, 0xff},//bit[7]:1, enable SDE
1370 {0x3391, 0x04}, //bit[2] enable
1371 {0x3390, 0x41}, //bit[3] sign of brightness
1375 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1376 sensor_Brightness4, sensor_Brightness5,NULL,
1381 #if CONFIG_SENSOR_Effect
1382 static struct reginfo sensor_Effect_Normal[] =
1388 static struct reginfo sensor_Effect_WandB[] =
1394 static struct reginfo sensor_Effect_Sepia[] =
1402 static struct reginfo sensor_Effect_Negative[] =
1405 {0x3391, 0x40}, //bit[6] negative
1408 static struct reginfo sensor_Effect_Bluish[] =
1417 static struct reginfo sensor_Effect_Green[] =
1425 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1426 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1429 #if CONFIG_SENSOR_Exposure
1430 static struct reginfo sensor_Exposure0[]=
1440 static struct reginfo sensor_Exposure1[]=
1450 static struct reginfo sensor_Exposure2[]=
1460 static struct reginfo sensor_Exposure3[]=
1470 static struct reginfo sensor_Exposure4[]=
1480 static struct reginfo sensor_Exposure5[]=
1490 static struct reginfo sensor_Exposure6[]=
1500 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1501 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1504 #if CONFIG_SENSOR_Saturation
1505 static struct reginfo sensor_Saturation0[]=
1507 {0x3301, 0xff},//bit[7]:1, enable SDE
1514 static struct reginfo sensor_Saturation1[]=
1516 {0x3301, 0xff},//bit[7]:1, enable SDE
1523 static struct reginfo sensor_Saturation2[]=
1525 {0x3301, 0xff},//bit[7]:1, enable SDE
1526 {0x3391, 0x02}, //enable color saturation
1531 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1534 #if CONFIG_SENSOR_Contrast
1535 static struct reginfo sensor_Contrast0[]=
1538 {0x3301, 0xff},//bit[7]:1, enable SDE
1546 static struct reginfo sensor_Contrast1[]=
1549 {0x3301, 0xff},//bit[7]:1, enable SDE
1557 static struct reginfo sensor_Contrast2[]=
1560 {0x3301, 0xff},//bit[7]:1, enable SDE
1568 static struct reginfo sensor_Contrast3[]=
1571 {0x3301, 0xff},//bit[7]:1, enable SDE
1579 static struct reginfo sensor_Contrast4[]=
1582 {0x3301, 0xff},//bit[7]:1, enable SDE
1591 static struct reginfo sensor_Contrast5[]=
1594 {0x3301, 0xff},//bit[7]:1, enable SDE
1602 static struct reginfo sensor_Contrast6[]=
1605 {0x3301, 0xff},//bit[7]:1, enable SDE
1606 {0x3391, 0x04}, //bit[2] enable contrast/brightness
1607 {0x3390, 0x45}, //bit[2] Yoffset sign
1612 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1613 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1617 #if CONFIG_SENSOR_Mirror
1618 static struct reginfo sensor_MirrorOn[]=
1626 static struct reginfo sensor_MirrorOff[]=
1633 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1635 #if CONFIG_SENSOR_Flip
1636 static struct reginfo sensor_FlipOn[]=
1649 static struct reginfo sensor_FlipOff[]=
1661 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1664 #if CONFIG_SENSOR_Scene
1665 static struct reginfo sensor_SceneAuto[] =
1667 #if 0 /* ddl@rock-chips.com : */
1682 static struct reginfo sensor_SceneNight[] =
1685 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1696 {0x3015, 0x50},//add 5 dummy frame
1701 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1717 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1720 #if CONFIG_SENSOR_DigitalZoom
1721 static struct reginfo sensor_Zoom0[] =
1726 static struct reginfo sensor_Zoom1[] =
1731 static struct reginfo sensor_Zoom2[] =
1737 static struct reginfo sensor_Zoom3[] =
1741 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1743 static const struct v4l2_querymenu sensor_menus[] =
1745 #if CONFIG_SENSOR_WhiteBalance
1746 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1747 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1748 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1751 #if CONFIG_SENSOR_Effect
1752 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1753 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1754 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1757 #if CONFIG_SENSOR_Scene
1758 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1761 #if CONFIG_SENSOR_Flash
1762 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1763 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1767 static const struct v4l2_queryctrl sensor_controls[] =
1769 #if CONFIG_SENSOR_WhiteBalance
1771 .id = V4L2_CID_DO_WHITE_BALANCE,
1772 .type = V4L2_CTRL_TYPE_MENU,
1773 .name = "White Balance Control",
1781 #if CONFIG_SENSOR_Brightness
1783 .id = V4L2_CID_BRIGHTNESS,
1784 .type = V4L2_CTRL_TYPE_INTEGER,
1785 .name = "Brightness Control",
1793 #if CONFIG_SENSOR_Effect
1795 .id = V4L2_CID_EFFECT,
1796 .type = V4L2_CTRL_TYPE_MENU,
1797 .name = "Effect Control",
1805 #if CONFIG_SENSOR_Exposure
1807 .id = V4L2_CID_EXPOSURE,
1808 .type = V4L2_CTRL_TYPE_INTEGER,
1809 .name = "Exposure Control",
1817 #if CONFIG_SENSOR_Saturation
1819 .id = V4L2_CID_SATURATION,
1820 .type = V4L2_CTRL_TYPE_INTEGER,
1821 .name = "Saturation Control",
1829 #if CONFIG_SENSOR_Contrast
1831 .id = V4L2_CID_CONTRAST,
1832 .type = V4L2_CTRL_TYPE_INTEGER,
1833 .name = "Contrast Control",
1841 #if CONFIG_SENSOR_Mirror
1843 .id = V4L2_CID_HFLIP,
1844 .type = V4L2_CTRL_TYPE_BOOLEAN,
1845 .name = "Mirror Control",
1853 #if CONFIG_SENSOR_Flip
1855 .id = V4L2_CID_VFLIP,
1856 .type = V4L2_CTRL_TYPE_BOOLEAN,
1857 .name = "Flip Control",
1865 #if CONFIG_SENSOR_Scene
1867 .id = V4L2_CID_SCENE,
1868 .type = V4L2_CTRL_TYPE_MENU,
1869 .name = "Scene Control",
1877 #if CONFIG_SENSOR_DigitalZoom
1879 .id = V4L2_CID_ZOOM_RELATIVE,
1880 .type = V4L2_CTRL_TYPE_INTEGER,
1881 .name = "DigitalZoom Control",
1887 .id = V4L2_CID_ZOOM_ABSOLUTE,
1888 .type = V4L2_CTRL_TYPE_INTEGER,
1889 .name = "DigitalZoom Control",
1897 #if CONFIG_SENSOR_Focus
1899 .id = V4L2_CID_FOCUS_RELATIVE,
1900 .type = V4L2_CTRL_TYPE_INTEGER,
1901 .name = "Focus Control",
1907 .id = V4L2_CID_FOCUS_ABSOLUTE,
1908 .type = V4L2_CTRL_TYPE_INTEGER,
1909 .name = "Focus Control",
1913 .default_value = 125,
1917 #if CONFIG_SENSOR_Flash
1919 .id = V4L2_CID_FLASH,
1920 .type = V4L2_CTRL_TYPE_MENU,
1921 .name = "Flash Control",
1930 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1931 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1932 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1933 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1934 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1935 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1936 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1937 static int sensor_resume(struct soc_camera_device *icd);
1938 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1939 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1940 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1941 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1942 static int sensor_deactivate(struct i2c_client *client);
1944 static struct soc_camera_ops sensor_ops =
1946 .suspend = sensor_suspend,
1947 .resume = sensor_resume,
1948 .set_bus_param = sensor_set_bus_param,
1949 .query_bus_param = sensor_query_bus_param,
1950 .controls = sensor_controls,
1951 .menus = sensor_menus,
1952 .num_controls = ARRAY_SIZE(sensor_controls),
1953 .num_menus = ARRAY_SIZE(sensor_menus),
1956 /* only one fixed colorspace per pixelcode */
1957 struct sensor_datafmt {
1958 enum v4l2_mbus_pixelcode code;
1959 enum v4l2_colorspace colorspace;
1962 /* Find a data format by a pixel code in an array */
1963 static const struct sensor_datafmt *sensor_find_datafmt(
1964 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1968 for (i = 0; i < n; i++)
1969 if (fmt[i].code == code)
1975 static const struct sensor_datafmt sensor_colour_fmts[] = {
1976 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1977 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1980 typedef struct sensor_info_priv_s
1994 unsigned char mirror; /* HFLIP */
1995 unsigned char flip; /* VFLIP */
1996 unsigned int winseqe_cur_addr;
1997 struct sensor_datafmt fmt;
1998 unsigned int funmodule_state;
1999 } sensor_info_priv_t;
2003 struct v4l2_subdev subdev;
2004 struct i2c_client *client;
2005 sensor_info_priv_t info_priv;
2006 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2007 #if CONFIG_SENSOR_I2C_NOSCHED
2008 atomic_t tasklock_cnt;
2010 struct rkcamera_platform_data *sensor_io_request;
2011 struct rkcamera_gpio_res *sensor_gpio_res;
2014 static struct sensor* to_sensor(const struct i2c_client *client)
2016 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2019 static int sensor_task_lock(struct i2c_client *client, int lock)
2021 #if CONFIG_SENSOR_I2C_NOSCHED
2023 struct sensor *sensor = to_sensor(client);
2026 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2027 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2028 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2032 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2033 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2034 goto sensor_task_lock_err;
2039 atomic_add(1, &sensor->tasklock_cnt);
2041 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2042 atomic_sub(1, &sensor->tasklock_cnt);
2044 if (atomic_read(&sensor->tasklock_cnt) == 0)
2049 sensor_task_lock_err:
2057 /* sensor register write */
2058 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2062 struct i2c_msg msg[1];
2065 buf[1] = reg & 0xFF;
2068 msg->addr = client->addr;
2069 msg->flags = client->flags;
2071 msg->len = sizeof(buf);
2072 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2073 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2078 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2079 err = i2c_transfer(client->adapter, msg, 1);
2084 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2092 /* sensor register read */
2093 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2097 struct i2c_msg msg[2];
2100 buf[1] = reg & 0xFF;
2102 msg[0].addr = client->addr;
2103 msg[0].flags = client->flags;
2105 msg[0].len = sizeof(buf);
2106 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2107 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2109 msg[1].addr = client->addr;
2110 msg[1].flags = client->flags|I2C_M_RD;
2113 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2114 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2118 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2119 err = i2c_transfer(client->adapter, msg, 2);
2125 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2133 /* write a array of registers */
2134 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2138 #if CONFIG_SENSOR_I2C_RDWRCHK
2143 if (sensor_task_lock(client, 1) < 0)
2144 goto sensor_write_array_end;
2146 while (regarray[i].reg != 0)
2148 err = sensor_write(client, regarray[i].reg, regarray[i].val);
2152 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2156 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2158 goto sensor_write_array_end;
2161 #if CONFIG_SENSOR_I2C_RDWRCHK
2162 sensor_read(client, regarray[i].reg, &valchk);
2163 if (valchk != regarray[i].val)
2164 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2170 sensor_write_array_end:
2171 sensor_task_lock(client,0);
2175 #if CONFIG_SENSOR_I2C_RDWRCHK
2176 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
2182 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
2183 while(regarray[i].reg != 0)
2185 ret = sensor_read(client,regarray[i].reg,&value);
2188 SENSOR_TR("read value failed\n");
2191 if(regarray[i].val != value)
2193 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
2201 SENSOR_DG("%s check success\n",__FUNCTION__);
2206 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
2208 struct soc_camera_link *icl = to_soc_camera_link(icd);
2211 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2214 case Sensor_PowerDown:
2216 if (icl->powerdown) {
2217 ret = icl->powerdown(icd->pdev, on);
2218 if (ret == RK_CAM_IO_SUCCESS) {
2222 icl->reset(icd->pdev);
2224 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
2226 goto sensor_power_end;
2233 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2234 struct sensor *sensor = to_sensor(client);
2236 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2237 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2243 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2251 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2253 struct i2c_client *client = v4l2_get_subdevdata(sd);
2254 struct soc_camera_device *icd = client->dev.platform_data;
2255 struct sensor *sensor = to_sensor(client);
2256 const struct v4l2_queryctrl *qctrl;
2257 const struct sensor_datafmt *fmt;
2259 int ret,pid = 0,i = 0,j=0;
2260 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
2261 sensor_init_data_p = sensor_init_data;
2262 sensor_init_winseq_p = sensor_svga;
2263 sensor_init_width = 640;
2264 sensor_init_height = 480;
2265 if (tmp_plat_data != NULL) {
2266 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
2267 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
2268 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
2272 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
2273 //user has defined the init data
2275 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
2276 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
2277 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
2278 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
2280 sensor_init_data_p = sensor_init_data;
2282 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
2283 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
2286 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
2287 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
2288 if(sensor_init_winseq_board)
2290 vfree(sensor_init_winseq_board);
2291 sensor_init_winseq_board = NULL;
2293 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
2294 if(!sensor_init_winseq_board)
2295 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
2296 for(j = 0;j< tmp_winseq_size;j++){
2297 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
2298 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
2300 sensor_init_winseq_p = sensor_init_winseq_board;
2302 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
2303 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
2305 //init width,height,bus,pixelcode
2306 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
2307 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
2308 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
2309 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
2310 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
2311 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
2312 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
2313 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
2315 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2317 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2319 goto sensor_INIT_ERR;
2323 if (sensor_task_lock(client,1)<0)
2324 goto sensor_INIT_ERR;
2325 /* ret = sensor_write(client, 0x3012, 0x80);
2328 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2330 goto sensor_INIT_ERR;
2333 mdelay(5); */ //delay 5 microseconds
2334 /* check if it is an sensor sensor */
2335 ret = sensor_read(client, 0x0000, &value);
2337 SENSOR_TR("read chip id high byte failed\n");
2339 goto sensor_INIT_ERR;
2342 pid |= (value << 8);
2344 ret = sensor_read(client, 0x0001, &value);
2346 SENSOR_TR("read chip id low byte failed\n");
2348 goto sensor_INIT_ERR;
2351 pid |= (value & 0xff);
2352 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2353 if (pid == SENSOR_ID) {
2354 sensor->model = SENSOR_V4L2_IDENT;
2356 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2358 goto sensor_INIT_ERR;
2361 ret = sensor_write_array(client, sensor_init_data_p);
2364 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2365 goto sensor_INIT_ERR;
2367 sensor_task_lock(client,0);
2369 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2370 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2372 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2374 goto sensor_INIT_ERR;
2376 sensor->info_priv.fmt = *fmt;
2378 /* sensor sensor information for initialization */
2379 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2381 sensor->info_priv.whiteBalance = qctrl->default_value;
2382 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2384 sensor->info_priv.brightness = qctrl->default_value;
2385 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2387 sensor->info_priv.effect = qctrl->default_value;
2388 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2390 sensor->info_priv.exposure = qctrl->default_value;
2392 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2394 sensor->info_priv.saturation = qctrl->default_value;
2395 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2397 sensor->info_priv.contrast = qctrl->default_value;
2398 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2400 sensor->info_priv.mirror = qctrl->default_value;
2401 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2403 sensor->info_priv.flip = qctrl->default_value;
2404 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2406 sensor->info_priv.scene = qctrl->default_value;
2407 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2409 sensor->info_priv.digitalzoom = qctrl->default_value;
2411 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2412 #if CONFIG_SENSOR_Focus
2414 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2416 sensor->info_priv.focus = qctrl->default_value;
2419 #if CONFIG_SENSOR_Flash
2420 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2422 sensor->info_priv.flash = qctrl->default_value;
2425 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);
2426 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2429 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2430 sensor_task_lock(client,0);
2431 sensor_deactivate(client);
2435 static int sensor_deactivate(struct i2c_client *client)
2437 struct soc_camera_device *icd = client->dev.platform_data;
2439 struct sensor *sensor = to_sensor(client);
2440 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2442 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2443 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
2444 sensor_write(client, 0x30b0, 0x00);
2445 sensor_write(client, 0x30b1, 0x00);
2447 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2450 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2451 icd->user_width = SENSOR_INIT_WIDTH;
2452 icd->user_height = SENSOR_INIT_HEIGHT;
2453 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2458 static struct reginfo sensor_power_down_sequence[]=
2466 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2469 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2471 if (pm_msg.event == PM_EVENT_SUSPEND) {
2472 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2473 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2475 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2478 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2480 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2485 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2491 static int sensor_resume(struct soc_camera_device *icd)
2495 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2497 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2501 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2507 static int sensor_set_bus_param(struct soc_camera_device *icd,
2508 unsigned long flags)
2514 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2516 struct soc_camera_link *icl = to_soc_camera_link(icd);
2517 unsigned long flags = SENSOR_BUS_PARAM;
2519 return soc_camera_apply_sensor_flags(icl, flags);
2522 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2524 struct i2c_client *client = v4l2_get_subdevdata(sd);
2525 struct soc_camera_device *icd = client->dev.platform_data;
2526 struct sensor *sensor = to_sensor(client);
2528 mf->width = icd->user_width;
2529 mf->height = icd->user_height;
2530 mf->code = sensor->info_priv.fmt.code;
2531 mf->colorspace = sensor->info_priv.fmt.colorspace;
2532 mf->field = V4L2_FIELD_NONE;
2536 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2540 if ((mf->width == 1024) && (mf->height == 768)) {
2542 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2544 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2546 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2548 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2553 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2557 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2561 if ((mf->width == 1280) && (mf->height == 720)) {
2563 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2568 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2571 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2573 struct i2c_client *client = v4l2_get_subdevdata(sd);
2574 const struct sensor_datafmt *fmt;
2575 struct sensor *sensor = to_sensor(client);
2576 const struct v4l2_queryctrl *qctrl;
2577 struct soc_camera_device *icd = client->dev.platform_data;
2578 struct reginfo *winseqe_set_addr=NULL;
2579 int ret=0, set_w,set_h;
2581 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2582 ARRAY_SIZE(sensor_colour_fmts));
2585 goto sensor_s_fmt_end;
2588 if (sensor->info_priv.fmt.code != mf->code) {
2591 case V4L2_MBUS_FMT_YUYV8_2X8:
2593 winseqe_set_addr = sensor_ClrFmt_YUYV;
2596 case V4L2_MBUS_FMT_UYVY8_2X8:
2598 winseqe_set_addr = sensor_ClrFmt_UYVY;
2604 if (winseqe_set_addr != NULL) {
2605 sensor_write_array(client, winseqe_set_addr);
2606 sensor->info_priv.fmt.code = mf->code;
2607 sensor->info_priv.fmt.colorspace= mf->colorspace;
2608 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2610 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2617 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2619 winseqe_set_addr = sensor_qcif;
2623 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2625 winseqe_set_addr = sensor_qvga;
2629 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2631 winseqe_set_addr = sensor_cif;
2635 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2637 winseqe_set_addr = sensor_vga;
2641 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2643 winseqe_set_addr = sensor_svga;
2647 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2649 winseqe_set_addr = sensor_sxga;
2653 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2655 winseqe_set_addr = sensor_uxga;
2661 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2662 set_w = SENSOR_INIT_WIDTH;
2663 set_h = SENSOR_INIT_HEIGHT;
2664 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2667 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
2668 #if CONFIG_SENSOR_Flash
2669 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2670 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2671 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2672 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2674 } else { /* ddl@rock-chips.com : Video */
2675 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2676 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2677 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2681 ret |= sensor_write_array(client, winseqe_set_addr);
2683 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2684 #if CONFIG_SENSOR_Flash
2685 if (sensor_fmt_capturechk(sd,mf) == true) {
2686 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2687 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2688 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2692 goto sensor_s_fmt_end;
2695 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2697 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2698 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2699 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2700 if (sensor->info_priv.whiteBalance != 0) {
2701 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2702 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2704 sensor->info_priv.snap2preview = true;
2705 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2706 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2707 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2708 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2709 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2710 sensor->info_priv.video2preview = true;
2711 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2712 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2713 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2715 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2717 sensor->info_priv.video2preview = false;
2718 sensor->info_priv.snap2preview = false;
2721 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2725 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2735 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2737 struct i2c_client *client = v4l2_get_subdevdata(sd);
2738 struct sensor *sensor = to_sensor(client);
2739 const struct sensor_datafmt *fmt;
2742 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2743 ARRAY_SIZE(sensor_colour_fmts));
2745 fmt = &sensor->info_priv.fmt;
2746 mf->code = fmt->code;
2749 if (mf->height > SENSOR_MAX_HEIGHT)
2750 mf->height = SENSOR_MAX_HEIGHT;
2751 else if (mf->height < SENSOR_MIN_HEIGHT)
2752 mf->height = SENSOR_MIN_HEIGHT;
2754 if (mf->width > SENSOR_MAX_WIDTH)
2755 mf->width = SENSOR_MAX_WIDTH;
2756 else if (mf->width < SENSOR_MIN_WIDTH)
2757 mf->width = SENSOR_MIN_WIDTH;
2759 mf->colorspace = fmt->colorspace;
2764 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2766 struct i2c_client *client = v4l2_get_subdevdata(sd);
2768 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2771 if (id->match.addr != client->addr)
2774 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return gt2005 identifier */
2779 #if CONFIG_SENSOR_Brightness
2780 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2782 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2784 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2786 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2788 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2790 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2793 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2797 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2801 #if CONFIG_SENSOR_Effect
2802 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2804 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2806 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2808 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2810 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2812 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2815 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2819 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2823 #if CONFIG_SENSOR_Exposure
2824 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2826 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2828 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2830 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2832 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2834 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2837 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2841 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2845 #if CONFIG_SENSOR_Saturation
2846 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2848 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2850 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2852 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2854 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2856 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2859 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2863 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2867 #if CONFIG_SENSOR_Contrast
2868 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2870 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2872 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2874 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2876 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2878 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2881 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2885 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2889 #if CONFIG_SENSOR_Mirror
2890 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2892 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2894 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2896 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2898 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2900 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2903 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2907 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2911 #if CONFIG_SENSOR_Flip
2912 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2914 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2916 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2918 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2920 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2922 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2925 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2929 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2933 #if CONFIG_SENSOR_Scene
2934 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2936 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2938 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2940 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2942 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2944 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2947 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2951 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2955 #if CONFIG_SENSOR_WhiteBalance
2956 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2958 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2960 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2962 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2964 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2966 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2969 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2973 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2977 #if CONFIG_SENSOR_DigitalZoom
2978 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2980 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2981 struct sensor *sensor = to_sensor(client);
2982 const struct v4l2_queryctrl *qctrl_info;
2983 int digitalzoom_cur, digitalzoom_total;
2985 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2989 digitalzoom_cur = sensor->info_priv.digitalzoom;
2990 digitalzoom_total = qctrl_info->maximum;
2992 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2994 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2998 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
3000 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3004 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
3006 value = digitalzoom_total - digitalzoom_cur;
3009 if ((value < 0) && ((digitalzoom_cur + value) < 0))
3011 value = 0 - digitalzoom_cur;
3014 digitalzoom_cur += value;
3016 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
3018 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
3020 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3023 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3030 #if CONFIG_SENSOR_Flash
3031 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3033 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3034 if (value == 3) { /* ddl@rock-chips.com: torch */
3035 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
3037 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3039 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3043 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3048 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3050 struct i2c_client *client = v4l2_get_subdevdata(sd);
3051 struct sensor *sensor = to_sensor(client);
3052 const struct v4l2_queryctrl *qctrl;
3054 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3058 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3064 case V4L2_CID_BRIGHTNESS:
3066 ctrl->value = sensor->info_priv.brightness;
3069 case V4L2_CID_SATURATION:
3071 ctrl->value = sensor->info_priv.saturation;
3074 case V4L2_CID_CONTRAST:
3076 ctrl->value = sensor->info_priv.contrast;
3079 case V4L2_CID_DO_WHITE_BALANCE:
3081 ctrl->value = sensor->info_priv.whiteBalance;
3084 case V4L2_CID_EXPOSURE:
3086 ctrl->value = sensor->info_priv.exposure;
3089 case V4L2_CID_HFLIP:
3091 ctrl->value = sensor->info_priv.mirror;
3094 case V4L2_CID_VFLIP:
3096 ctrl->value = sensor->info_priv.flip;
3107 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3109 struct i2c_client *client = v4l2_get_subdevdata(sd);
3110 struct sensor *sensor = to_sensor(client);
3111 struct soc_camera_device *icd = client->dev.platform_data;
3112 const struct v4l2_queryctrl *qctrl;
3115 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3119 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3125 #if CONFIG_SENSOR_Brightness
3126 case V4L2_CID_BRIGHTNESS:
3128 if (ctrl->value != sensor->info_priv.brightness)
3130 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3134 sensor->info_priv.brightness = ctrl->value;
3139 #if CONFIG_SENSOR_Exposure
3140 case V4L2_CID_EXPOSURE:
3142 if (ctrl->value != sensor->info_priv.exposure)
3144 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3148 sensor->info_priv.exposure = ctrl->value;
3153 #if CONFIG_SENSOR_Saturation
3154 case V4L2_CID_SATURATION:
3156 if (ctrl->value != sensor->info_priv.saturation)
3158 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3162 sensor->info_priv.saturation = ctrl->value;
3167 #if CONFIG_SENSOR_Contrast
3168 case V4L2_CID_CONTRAST:
3170 if (ctrl->value != sensor->info_priv.contrast)
3172 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3176 sensor->info_priv.contrast = ctrl->value;
3181 #if CONFIG_SENSOR_WhiteBalance
3182 case V4L2_CID_DO_WHITE_BALANCE:
3184 if (ctrl->value != sensor->info_priv.whiteBalance)
3186 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3190 sensor->info_priv.whiteBalance = ctrl->value;
3195 #if CONFIG_SENSOR_Mirror
3196 case V4L2_CID_HFLIP:
3198 if (ctrl->value != sensor->info_priv.mirror)
3200 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3202 sensor->info_priv.mirror = ctrl->value;
3207 #if CONFIG_SENSOR_Flip
3208 case V4L2_CID_VFLIP:
3210 if (ctrl->value != sensor->info_priv.flip)
3212 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3214 sensor->info_priv.flip = ctrl->value;
3225 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3227 const struct v4l2_queryctrl *qctrl;
3228 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3229 struct sensor *sensor = to_sensor(client);
3231 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3235 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3239 switch (ext_ctrl->id)
3241 case V4L2_CID_SCENE:
3243 ext_ctrl->value = sensor->info_priv.scene;
3246 case V4L2_CID_EFFECT:
3248 ext_ctrl->value = sensor->info_priv.effect;
3251 case V4L2_CID_ZOOM_ABSOLUTE:
3253 ext_ctrl->value = sensor->info_priv.digitalzoom;
3256 case V4L2_CID_ZOOM_RELATIVE:
3260 case V4L2_CID_FOCUS_ABSOLUTE:
3262 ext_ctrl->value = sensor->info_priv.focus;
3265 case V4L2_CID_FOCUS_RELATIVE:
3269 case V4L2_CID_FLASH:
3271 ext_ctrl->value = sensor->info_priv.flash;
3279 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3281 const struct v4l2_queryctrl *qctrl;
3282 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3283 struct sensor *sensor = to_sensor(client);
3286 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3290 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3295 switch (ext_ctrl->id)
3297 #if CONFIG_SENSOR_Scene
3298 case V4L2_CID_SCENE:
3300 if (ext_ctrl->value != sensor->info_priv.scene)
3302 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3304 sensor->info_priv.scene = ext_ctrl->value;
3309 #if CONFIG_SENSOR_Effect
3310 case V4L2_CID_EFFECT:
3312 if (ext_ctrl->value != sensor->info_priv.effect)
3314 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3316 sensor->info_priv.effect= ext_ctrl->value;
3321 #if CONFIG_SENSOR_DigitalZoom
3322 case V4L2_CID_ZOOM_ABSOLUTE:
3324 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3327 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3329 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3331 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3333 sensor->info_priv.digitalzoom += val_offset;
3335 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3340 case V4L2_CID_ZOOM_RELATIVE:
3342 if (ext_ctrl->value)
3344 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3346 sensor->info_priv.digitalzoom += ext_ctrl->value;
3348 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3353 #if CONFIG_SENSOR_Focus
3354 case V4L2_CID_FOCUS_ABSOLUTE:
3356 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3359 if (ext_ctrl->value != sensor->info_priv.focus)
3361 val_offset = ext_ctrl->value -sensor->info_priv.focus;
3363 sensor->info_priv.focus += val_offset;
3368 case V4L2_CID_FOCUS_RELATIVE:
3370 if (ext_ctrl->value)
3372 sensor->info_priv.focus += ext_ctrl->value;
3374 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
3379 #if CONFIG_SENSOR_Flash
3380 case V4L2_CID_FLASH:
3382 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3384 sensor->info_priv.flash = ext_ctrl->value;
3386 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3397 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3399 struct i2c_client *client = v4l2_get_subdevdata(sd);
3400 struct soc_camera_device *icd = client->dev.platform_data;
3401 int i, error_cnt=0, error_idx=-1;
3404 for (i=0; i<ext_ctrl->count; i++) {
3405 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3412 error_idx = ext_ctrl->count;
3414 if (error_idx != -1) {
3415 ext_ctrl->error_idx = error_idx;
3422 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3424 struct i2c_client *client = v4l2_get_subdevdata(sd);
3425 struct soc_camera_device *icd = client->dev.platform_data;
3426 int i, error_cnt=0, error_idx=-1;
3429 for (i=0; i<ext_ctrl->count; i++) {
3430 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3437 error_idx = ext_ctrl->count;
3439 if (error_idx != -1) {
3440 ext_ctrl->error_idx = error_idx;
3447 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3448 * this wasn't our capture interface, so, we wait for the right one */
3449 static int sensor_video_probe(struct soc_camera_device *icd,
3450 struct i2c_client *client)
3454 struct sensor *sensor = to_sensor(client);
3456 /* We must have a parent by now. And it cannot be a wrong one.
3457 * So this entire test is completely redundant. */
3458 if (!icd->dev.parent ||
3459 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3462 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3464 goto sensor_video_probe_err;
3468 /* ret = sensor_write(client, 0x3012, 0x80);
3471 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3474 mdelay(5); */ //delay 5 microseconds
3476 /* check if it is an sensor sensor */
3477 ret = sensor_read(client, 0x0000, &value);
3479 SENSOR_TR("read chip id high byte failed\n");
3481 goto sensor_video_probe_err;
3484 pid |= (value << 8);
3486 ret = sensor_read(client, 0x0001, &value);
3488 SENSOR_TR("read chip id low byte failed\n");
3490 goto sensor_video_probe_err;
3493 pid |= (value & 0xff);
3494 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3495 if (pid == SENSOR_ID) {
3496 sensor->model = SENSOR_V4L2_IDENT;
3498 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3500 goto sensor_video_probe_err;
3505 sensor_video_probe_err:
3509 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3511 struct i2c_client *client = v4l2_get_subdevdata(sd);
3512 struct soc_camera_device *icd = client->dev.platform_data;
3513 struct sensor *sensor = to_sensor(client);
3514 #if CONFIG_SENSOR_Flash
3519 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3522 case RK_CAM_SUBDEV_DEACTIVATE:
3524 sensor_deactivate(client);
3528 case RK_CAM_SUBDEV_IOREQUEST:
3530 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
3531 if (sensor->sensor_io_request != NULL) {
3532 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
3533 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
3534 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
3535 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
3536 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
3537 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
3540 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3542 goto sensor_ioctl_end;
3544 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3546 #if CONFIG_SENSOR_Flash
3547 if (sensor->sensor_gpio_res) {
3548 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3549 for (i = 0; i < icd->ops->num_controls; i++) {
3550 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3551 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3554 sensor->info_priv.flash = 0xff;
3555 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3563 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3571 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3572 enum v4l2_mbus_pixelcode *code)
3574 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3577 *code = sensor_colour_fmts[index].code;
3580 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3581 .init = sensor_init,
3582 .g_ctrl = sensor_g_control,
3583 .s_ctrl = sensor_s_control,
3584 .g_ext_ctrls = sensor_g_ext_controls,
3585 .s_ext_ctrls = sensor_s_ext_controls,
3586 .g_chip_ident = sensor_g_chip_ident,
3587 .ioctl = sensor_ioctl,
3590 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3591 .s_mbus_fmt = sensor_s_fmt,
3592 .g_mbus_fmt = sensor_g_fmt,
3593 .try_mbus_fmt = sensor_try_fmt,
3594 .enum_mbus_fmt = sensor_enum_fmt,
3597 static struct v4l2_subdev_ops sensor_subdev_ops = {
3598 .core = &sensor_subdev_core_ops,
3599 .video = &sensor_subdev_video_ops,
3602 static int sensor_probe(struct i2c_client *client,
3603 const struct i2c_device_id *did)
3605 struct sensor *sensor;
3606 struct soc_camera_device *icd = client->dev.platform_data;
3607 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3608 struct soc_camera_link *icl;
3611 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3613 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3617 icl = to_soc_camera_link(icd);
3619 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3623 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3624 dev_warn(&adapter->dev,
3625 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3629 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3633 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3635 /* Second stage probe - when a capture adapter is there */
3636 icd->ops = &sensor_ops;
3638 sensor->info_priv.fmt = sensor_colour_fmts[0];
3640 #if CONFIG_SENSOR_I2C_NOSCHED
3641 atomic_set(&sensor->tasklock_cnt,0);
3644 ret = sensor_video_probe(icd, client);
3647 i2c_set_clientdata(client, NULL);
3651 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3655 static int sensor_remove(struct i2c_client *client)
3657 struct sensor *sensor = to_sensor(client);
3658 struct soc_camera_device *icd = client->dev.platform_data;
3661 i2c_set_clientdata(client, NULL);
3662 client->driver = NULL;
3668 static const struct i2c_device_id sensor_id[] = {
3669 {SENSOR_NAME_STRING(), 0 },
3672 MODULE_DEVICE_TABLE(i2c, sensor_id);
3674 static struct i2c_driver sensor_i2c_driver = {
3676 .name = SENSOR_NAME_STRING(),
3678 .probe = sensor_probe,
3679 .remove = sensor_remove,
3680 .id_table = sensor_id,
3683 static int __init sensor_mod_init(void)
3685 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3686 return i2c_add_driver(&sensor_i2c_driver);
3689 static void __exit sensor_mod_exit(void)
3691 i2c_del_driver(&sensor_i2c_driver);
3694 device_initcall_sync(sensor_mod_init);
3695 module_exit(sensor_mod_exit);
3697 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3698 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3699 MODULE_LICENSE("GPL");