2 * 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>
24 #include <linux/vmalloc.h>
28 module_param(debug, int, S_IRUGO|S_IWUSR);
30 #define dprintk(level, fmt, arg...) do { \
32 printk(KERN_WARNING fmt , ## arg); } while (0)
34 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
35 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
37 #define _CONS(a,b) a##b
38 #define CONS(a,b) _CONS(a,b)
41 #define _STR(x) __STR(x)
42 #define STR(x) _STR(x)
44 #define MIN(x,y) ((x<y) ? x: y)
45 #define MAX(x,y) ((x>y) ? x: y)
47 /* Sensor Driver Configuration */
48 #define SENSOR_NAME RK_CAM_SENSOR_OV3640
49 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV3640
50 #define SENSOR_ID 0x364c
51 #define SENSOR_MIN_WIDTH 176
52 #define SENSOR_MIN_HEIGHT 144
53 #define SENSOR_MAX_WIDTH 2048
54 #define SENSOR_MAX_HEIGHT 1536
55 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
56 #define SENSOR_INIT_HEIGHT sensor_init_height
57 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
58 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
59 #define SENSOR_BUS_PARAM sensor_init_busparam
61 #define CONFIG_SENSOR_WhiteBalance 1
62 #define CONFIG_SENSOR_Brightness 0
63 #define CONFIG_SENSOR_Contrast 0
64 #define CONFIG_SENSOR_Saturation 0
65 #define CONFIG_SENSOR_Effect 1
66 #define CONFIG_SENSOR_Scene 1
67 #define CONFIG_SENSOR_DigitalZoom 0
68 #define CONFIG_SENSOR_Exposure 0
69 #define CONFIG_SENSOR_Flash 0
70 #define CONFIG_SENSOR_Mirror 0
71 #define CONFIG_SENSOR_Flip 0
72 #ifdef CONFIG_OV3640_AUTOFOCUS
73 #define CONFIG_SENSOR_Focus 1
74 #include "ov3640_af_firmware.c"
76 #define CONFIG_SENSOR_Focus 0
79 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
80 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
81 #define CONFIG_SENSOR_I2C_NOSCHED 0
82 #define CONFIG_SENSOR_I2C_RDWRCHK 0
84 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
85 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
86 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
87 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
88 #define COLOR_TEMPERATURE_OFFICE_DN 3500
89 #define COLOR_TEMPERATURE_OFFICE_UP 5000
90 #define COLOR_TEMPERATURE_HOME_DN 2500
91 #define COLOR_TEMPERATURE_HOME_UP 3500
93 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
94 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
96 #define SENSOR_AF_IS_ERR (0x00<<0)
97 #define SENSOR_AF_IS_OK (0x01<<0)
99 #if CONFIG_SENSOR_Focus
100 #define SENSOR_AF_MODE_INFINITY 0
101 #define SENSOR_AF_MODE_MACRO 1
102 #define SENSOR_AF_MODE_FIXED 2
103 #define SENSOR_AF_MODE_AUTO 3
104 #define SENSOR_AF_MODE_CONTINUOUS 4
105 #define SENSOR_AF_MODE_CLOSE 5
109 #define VCM_FIRMWARE 1
111 #define VCM_STARTADDR 0x8000
114 #if (VCM_FIRMWARE==1)
115 #define S_FOCUSING 0x01
116 #define S_FOCUSED 0x02
117 #define S_CAPTURE 0x12
118 #define STA_FOCUS 0x3f07
119 #elif (VCM_FIRMWARE==2)
120 #define S_FOCUSING 0x01
121 #define S_FOCUSED 0x02
122 #define S_CAPTURE 0x12
123 #define STA_FOCUS 0x3f01
125 #define S_FOCUSING 0x65
126 #define S_FOCUSED 0x46
127 #define S_CAPTURE 0x47
128 #define STA_FOCUS 0x3f01
132 #if CONFIG_SENSOR_Focus
133 /* ov3640 VCM Command and Status Registers */
134 #define CMD_MAIN_Reg 0x3F00
135 #define CMD_TAG_Reg 0x3F01
136 #define CMD_PARA0_Reg 0x3F05
137 #define CMD_PARA1_Reg 0x3F04
138 #define CMD_PARA2_Reg 0x3F03
139 #define CMD_PARA3_Reg 0x3F02
140 #define STA_ZONE_Reg 0x3F06
141 #define STA_FOCUS_Reg 0x3F07
143 /* ov3640 VCM Command */
144 #define OverlayEn_Cmd 0x01
145 #define OverlayDis_Cmd 0x02
146 #define SingleFocus_Cmd 0x03
147 #define ConstFocus_Cmd 0x04
148 #define StepMode_Cmd 0x05
149 #define PauseFocus_Cmd 0x06
150 #define ReturnIdle_Cmd 0x08
151 #define SetZone_Cmd 0x10
152 #define UpdateZone_Cmd 0x12
153 #define SetMotor_Cmd 0x20
155 /* ov3640 Focus State */
156 #define S_FIRWRE 0xFF
157 #define S_STARTUP 0xFA
159 #define S_DRVICERR 0xEE
161 #define S_FOCUSING 0x01
162 #define S_FOCUSED 0x02
163 #define S_CAPTURE 0x12
166 /* ovxxxx Zone State */
167 #define Zone_Is_Focused(a, zone_val) (zone_val&(1<<(a-3)))
168 #define Zone_Get_ID(zone_val) (zone_val&0x03)
170 #define Zone_CenterMode 0x01
171 #define Zone_5xMode 0x02
172 #define Zone_5PlusMode 0x03
173 #define Zone_4fMode 0x04
175 #define ZoneSel_Auto 0x0b
176 #define ZoneSel_SemiAuto 0x0c
177 #define ZoneSel_Manual 0x0d
178 #define ZoneSel_Rotate 0x0e
180 /* ovxxxx Step Focus Commands */
181 #define StepFocus_Near_Tag 0x01
182 #define StepFocus_Far_Tag 0x02
183 #define StepFocus_Furthest_Tag 0x03
184 #define StepFocus_Nearest_Tag 0x04
185 #define StepFocus_Spec_Tag 0x10
188 static s32 sensor_init_height = 0;
189 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);
190 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
191 static struct reginfo* sensor_init_data_p = NULL;
192 static struct reginfo* sensor_init_winseq_p = NULL;
193 static struct reginfo* sensor_init_winseq_board = NULL;
194 /* init VGA 640*480 */
195 static struct reginfo sensor_init_data[] =
208 {0x30b2, 0x18}, // by FAE
221 {0x30a9, 0xbd},//disable internal DVDD, by FAE.
274 {0x3404, 0x00},//YUV, sequence
351 #ifdef CONFIG_RK29_NEWTON
352 {0x307c, 0x10}, // flip && mirror ,for newton
356 //{0x307c, 0x13}, // flip && mirror
357 {0x307c, 0x11}, // flip && mirror ,by FAE.
362 //640 480 ;XGA->XGA;;
412 static struct reginfo sensor_qxga_preview[] =
454 //[Sensor.YUV.2048x1536] XGA->QXGA
492 static struct reginfo sensor_qxga_capture[] = {
534 static struct reginfo *sensor_qxga[2] = {
540 static struct reginfo sensor_uxga_preview[] =
576 {0x304c, 0x81},//56Mhz PCLK output
580 static struct reginfo sensor_uxga_capture[] =
594 {0x304c, 0x81},//56Mhz PCLK output
598 static struct reginfo *sensor_uxga[2] = {
604 static struct reginfo sensor_sxga_preview[] =
640 {0x304c, 0x81},//56Mhz PCLK output
644 static struct reginfo sensor_sxga_capture[] =
658 {0x304c, 0x81},//56Mhz PCLK output
662 static struct reginfo *sensor_sxga[2] = {
668 static struct reginfo sensor_xga_preview[] =
700 {0x304c, 0x82},//28Mhz PCLK output
705 static struct reginfo sensor_xga_capture[] =
719 {0x304c, 0x82},//28Mhz PCLK output
723 static struct reginfo *sensor_xga[2] = {
729 static struct reginfo sensor_svga_preview[] =
761 {0x304c, 0x83},//28Mhz PCLK output
765 static struct reginfo sensor_svga_capture[] =
779 {0x304c, 0x82},//28Mhz PCLK output
783 static struct reginfo * sensor_svga[2] = {
789 static struct reginfo sensor_vga_preview[] =
818 {0x3089, 0x88},// 0x80, by FAE.
820 {0x308b, 0xe4},// 0xe0, by FAE.
821 {0x304c, 0x84}, //0x83, by FAE.
839 static struct reginfo sensor_vga_capture[] =
853 {0x304c, 0x82},//14Mhz PCLK output 84
857 static struct reginfo *sensor_vga[2] = {
863 static struct reginfo sensor_cif_preview[] =
915 static struct reginfo sensor_cif_capture[] =
929 {0x304c, 0x84},//14Mhz PCLK output
933 static struct reginfo *sensor_cif[2] = {
939 static struct reginfo sensor_qvga_preview[] =
971 {0x304c, 0x89},//14Mhz PCLK output
975 static struct reginfo sensor_qvga_capture[] =
989 {0x304c, 0x84},//14Mhz PCLK output
993 static struct reginfo *sensor_qvga[2] = {
999 static struct reginfo sensor_qcif_preview[] =
1031 {0x304c, 0x82},//14Mhz PCLK output 89
1035 static struct reginfo sensor_qcif_capture[] =
1049 {0x304c, 0x84},//14Mhz PCLK output
1053 static struct reginfo *sensor_qcif[2] = {
1054 sensor_qcif_preview,
1055 sensor_qcif_capture,
1060 static struct reginfo ov3640_Sharpness_auto[] =
1065 static struct reginfo ov3640_Sharpness1[] =
1071 static struct reginfo ov3640_Sharpness2[][3] =
1078 static struct reginfo ov3640_Sharpness3[] =
1084 static struct reginfo ov3640_Sharpness4[]=
1091 static struct reginfo ov3640_Sharpness5[] =
1099 static struct reginfo sensor_ClrFmt_YUYV[]=
1105 static struct reginfo sensor_ClrFmt_UYVY[]=
1111 #if CONFIG_SENSOR_WhiteBalance
1112 static struct reginfo sensor_WhiteB_Auto[]=
1114 {0x332b, 0x00},//AWB auto, bit[3]:0,auto
1118 /* Cloudy Colour Temperature : 6500K - 8000K */
1119 static struct reginfo sensor_WhiteB_Cloudy[]=
1128 /* ClearDay Colour Temperature : 5000K - 6500K */
1129 static struct reginfo sensor_WhiteB_ClearDay[]=
1132 {0x332b, 0x08}, //AWB off
1139 /* Office Colour Temperature : 3500K - 5000K */
1140 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
1150 /* Home Colour Temperature : 2500K - 3500K */
1151 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
1161 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1162 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1166 #if CONFIG_SENSOR_Brightness
1167 static struct reginfo sensor_Brightness0[]=
1178 static struct reginfo sensor_Brightness1[]=
1189 static struct reginfo sensor_Brightness2[]=
1200 static struct reginfo sensor_Brightness3[]=
1211 static struct reginfo sensor_Brightness4[]=
1222 static struct reginfo sensor_Brightness5[]=
1233 static struct reginfo sensor_Brightness6[]=
1237 {0x3355, 0x04}, //bit[2] enable
1238 {0x3354, 0x01}, //bit[3] sign of brightness
1244 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1245 sensor_Brightness4, sensor_Brightness5,sensor_Brightness6,NULL,
1250 #if CONFIG_SENSOR_Effect
1251 static struct reginfo sensor_Effect_Normal[] =
1260 static struct reginfo sensor_Effect_WandB[] =
1264 {0x3355, 0x18}, //bit[4]fix u enable, bit[3]fix v enable
1271 static struct reginfo sensor_Effect_Sepia[] =
1282 static struct reginfo sensor_Effect_Negative[] =
1286 {0x3355, 0x40}, //bit[6] negative
1290 static struct reginfo sensor_Effect_Bluish[] =
1301 static struct reginfo sensor_Effect_Green[] =
1312 static struct reginfo sensor_Effect_Red[] =
1322 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1323 sensor_Effect_Bluish, sensor_Effect_Green,sensor_Effect_Red,NULL,
1326 #if CONFIG_SENSOR_Exposure
1327 static struct reginfo sensor_Exposure0[]=
1338 static struct reginfo sensor_Exposure1[]=
1349 static struct reginfo sensor_Exposure2[]=
1360 static struct reginfo sensor_Exposure3[]=
1371 static struct reginfo sensor_Exposure4[]=
1382 static struct reginfo sensor_Exposure5[]=
1393 static struct reginfo sensor_Exposure6[]=
1404 static struct reginfo sensor_Exposure7[]=
1415 static struct reginfo sensor_Exposure8[]=
1426 static struct reginfo sensor_Exposure9[]=
1437 static struct reginfo sensor_Exposure10[]=
1448 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1449 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,sensor_Exposure7,sensor_Exposure8,sensor_Exposure9,
1450 sensor_Exposure10,NULL,
1453 #if CONFIG_SENSOR_Saturation
1454 static struct reginfo sensor_Saturation0[]=
1465 static struct reginfo sensor_Saturation1[]=
1476 static struct reginfo sensor_Saturation2[]=
1487 static struct reginfo sensor_Saturation3[]=
1498 static struct reginfo sensor_Saturation4[]=
1501 {0x3302, 0xef}, //bit[7]:1, enable SDE
1502 {0x3355, 0x02}, //enable color saturation
1509 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2,
1510 sensor_Saturation3, sensor_Saturation4, NULL,};
1513 #if CONFIG_SENSOR_Contrast
1514 static struct reginfo sensor_Contrast0[]=
1526 static struct reginfo sensor_Contrast1[]=
1538 static struct reginfo sensor_Contrast2[]=
1550 static struct reginfo sensor_Contrast3[]=
1562 static struct reginfo sensor_Contrast4[]=
1575 static struct reginfo sensor_Contrast5[]=
1587 static struct reginfo sensor_Contrast6[]=
1591 {0x3355, 0x04}, //bit[2] enable contrast/brightness
1592 {0x3354, 0x01}, //bit[2] Yoffset sign
1598 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1599 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1603 #if CONFIG_SENSOR_Mirror
1604 static struct reginfo sensor_MirrorOn[]=
1606 {0x307c, 0x12}, //mirror
1613 static struct reginfo sensor_MirrorOff[]=
1615 {0x307c, 0x10},// no mirror/flip
1622 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1624 #if CONFIG_SENSOR_Flip
1625 static struct reginfo sensor_FlipOn[]=
1627 {0x307c, 0x11}, //flip
1634 static struct reginfo sensor_FlipOff[]=
1636 {0x307c, 0x10}, // no mirror/flip
1642 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1645 #if CONFIG_SENSOR_Scene
1646 static struct reginfo sensor_SceneAuto[] =
1648 {0x3014, 0x84},//bit[3]=0 disable auto night mode
1649 {0x3015, 0x12},// or 0x02
1650 {0x302d, 0x00},//clear dummy frame
1651 {0x302e, 0x00},//clear dummy frame
1656 static struct reginfo sensor_SceneNight[] =
1658 {0x3014, 0x8c}, //bit[3] =1 enable auto night mode ¸ù¾Ý¹âÏßÇ¿Èõ×Ô¶¯½µÖ¡
1659 {0x3015, 0x22},//bit[6:4] ÉèÖò»Í¬,½µµÄÖ¡Âʲ»Ò»Ñù.¿ÉÒÔ¿´datasheet
1661 //000 no dummy frame
1668 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1671 #if CONFIG_SENSOR_DigitalZoom
1672 static struct reginfo sensor_Zoom0[] =
1677 static struct reginfo sensor_Zoom1[] =
1682 static struct reginfo sensor_Zoom2[] =
1688 static struct reginfo sensor_Zoom3[] =
1692 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1694 static const struct v4l2_querymenu sensor_menus[] =
1696 #if CONFIG_SENSOR_WhiteBalance
1697 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1698 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1699 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1702 #if CONFIG_SENSOR_Effect
1703 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1704 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1705 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1708 #if CONFIG_SENSOR_Scene
1709 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1712 #if CONFIG_SENSOR_Flash
1713 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1714 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1718 static const struct v4l2_queryctrl sensor_controls[] =
1720 #if CONFIG_SENSOR_WhiteBalance
1722 .id = V4L2_CID_DO_WHITE_BALANCE,
1723 .type = V4L2_CTRL_TYPE_MENU,
1724 .name = "White Balance Control",
1732 #if CONFIG_SENSOR_Brightness
1734 .id = V4L2_CID_BRIGHTNESS,
1735 .type = V4L2_CTRL_TYPE_INTEGER,
1736 .name = "Brightness Control",
1744 #if CONFIG_SENSOR_Effect
1746 .id = V4L2_CID_EFFECT,
1747 .type = V4L2_CTRL_TYPE_MENU,
1748 .name = "Effect Control",
1756 #if CONFIG_SENSOR_Exposure
1758 .id = V4L2_CID_EXPOSURE,
1759 .type = V4L2_CTRL_TYPE_INTEGER,
1760 .name = "Exposure Control",
1768 #if CONFIG_SENSOR_Saturation
1770 .id = V4L2_CID_SATURATION,
1771 .type = V4L2_CTRL_TYPE_INTEGER,
1772 .name = "Saturation Control",
1780 #if CONFIG_SENSOR_Contrast
1782 .id = V4L2_CID_CONTRAST,
1783 .type = V4L2_CTRL_TYPE_INTEGER,
1784 .name = "Contrast Control",
1792 #if CONFIG_SENSOR_Mirror
1794 .id = V4L2_CID_HFLIP,
1795 .type = V4L2_CTRL_TYPE_BOOLEAN,
1796 .name = "Mirror Control",
1804 #if CONFIG_SENSOR_Flip
1806 .id = V4L2_CID_VFLIP,
1807 .type = V4L2_CTRL_TYPE_BOOLEAN,
1808 .name = "Flip Control",
1816 #if CONFIG_SENSOR_Scene
1818 .id = V4L2_CID_SCENE,
1819 .type = V4L2_CTRL_TYPE_MENU,
1820 .name = "Scene Control",
1828 #if CONFIG_SENSOR_DigitalZoom
1830 .id = V4L2_CID_ZOOM_RELATIVE,
1831 .type = V4L2_CTRL_TYPE_INTEGER,
1832 .name = "DigitalZoom Control",
1838 .id = V4L2_CID_ZOOM_ABSOLUTE,
1839 .type = V4L2_CTRL_TYPE_INTEGER,
1840 .name = "DigitalZoom Control",
1848 #if CONFIG_SENSOR_Focus
1850 .id = V4L2_CID_FOCUS_RELATIVE,
1851 .type = V4L2_CTRL_TYPE_INTEGER,
1852 .name = "Focus Control",
1858 .id = V4L2_CID_FOCUS_ABSOLUTE,
1859 .type = V4L2_CTRL_TYPE_INTEGER,
1860 .name = "Focus Control",
1864 .default_value = 125,
1867 .id = V4L2_CID_FOCUS_AUTO,
1868 .type = V4L2_CTRL_TYPE_BOOLEAN,
1869 .name = "Focus Control",
1875 #if 0 //IF CONTINOUS IS SUPPORT, SET TO 1
1877 .id = V4L2_CID_FOCUS_CONTINUOUS,
1878 .type = V4L2_CTRL_TYPE_BOOLEAN,
1879 .name = "Focus Control",
1888 #if CONFIG_SENSOR_Flash
1890 .id = V4L2_CID_FLASH,
1891 .type = V4L2_CTRL_TYPE_MENU,
1892 .name = "Flash Control",
1901 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1902 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1903 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1904 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1905 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1906 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1907 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1908 static int sensor_resume(struct soc_camera_device *icd);
1909 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1910 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1911 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1912 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1913 static int sensor_deactivate(struct i2c_client *client);
1915 static struct soc_camera_ops sensor_ops =
1917 .suspend = sensor_suspend,
1918 .resume = sensor_resume,
1919 .set_bus_param = sensor_set_bus_param,
1920 .query_bus_param = sensor_query_bus_param,
1921 .controls = sensor_controls,
1922 .menus = sensor_menus,
1923 .num_controls = ARRAY_SIZE(sensor_controls),
1924 .num_menus = ARRAY_SIZE(sensor_menus),
1927 /* only one fixed colorspace per pixelcode */
1928 struct sensor_datafmt {
1929 enum v4l2_mbus_pixelcode code;
1930 enum v4l2_colorspace colorspace;
1933 /* Find a data format by a pixel code in an array */
1934 static const struct sensor_datafmt *sensor_find_datafmt(
1935 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1939 for (i = 0; i < n; i++)
1940 if (fmt[i].code == code)
1946 static const struct sensor_datafmt sensor_colour_fmts[] = {
1947 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1948 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1950 enum sensor_work_state
1952 sensor_work_ready = 0,
1957 struct i2c_client *client;
1958 struct delayed_work dwork;
1959 enum sensor_work_state state;
1962 typedef struct sensor_info_priv_s
1978 unsigned char mirror; /* HFLIP */
1979 unsigned char flip; /* VFLIP */
1980 unsigned int winseqe_cur_addr;
1981 struct sensor_datafmt fmt;
1982 unsigned int enable;
1983 unsigned int funmodule_state;
1984 } sensor_info_priv_t;
1988 struct v4l2_subdev subdev;
1989 struct i2c_client *client;
1990 sensor_info_priv_t info_priv;
1991 struct workqueue_struct *sensor_wq;
1992 struct sensor_work sensor_wk;
1993 struct mutex wq_lock;
1994 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1995 #if CONFIG_SENSOR_I2C_NOSCHED
1996 atomic_t tasklock_cnt;
1998 struct rkcamera_platform_data *sensor_io_request;
1999 struct rkcamera_gpio_res *sensor_gpio_res;
2002 static struct sensor* to_sensor(const struct i2c_client *client)
2004 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2007 static int sensor_task_lock(struct i2c_client *client, int lock)
2009 #if CONFIG_SENSOR_I2C_NOSCHED
2011 struct sensor *sensor = to_sensor(client);
2014 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2015 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2016 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2020 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2021 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2022 goto sensor_task_lock_err;
2027 atomic_add(1, &sensor->tasklock_cnt);
2029 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2030 atomic_sub(1, &sensor->tasklock_cnt);
2032 if (atomic_read(&sensor->tasklock_cnt) == 0)
2037 sensor_task_lock_err:
2045 /* sensor register write */
2046 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2050 struct i2c_msg msg[1];
2053 buf[1] = reg & 0xFF;
2056 msg->addr = client->addr;
2057 msg->flags = client->flags;
2059 msg->len = sizeof(buf);
2060 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2061 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2066 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2067 err = i2c_transfer(client->adapter, msg, 1);
2072 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2080 /* sensor register read */
2081 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2085 struct i2c_msg msg[2];
2088 buf[1] = reg & 0xFF;
2090 msg[0].addr = client->addr;
2091 msg[0].flags = client->flags;
2093 msg[0].len = sizeof(buf);
2094 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2095 msg[0].read_type = 2; /* fpga i2c:2==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2097 msg[1].addr = client->addr;
2098 msg[1].flags = client->flags|I2C_M_RD;
2101 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2102 msg[1].read_type = 2; /* fpga i2c:2==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2106 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2107 err = i2c_transfer(client->adapter, msg, 2);
2113 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2121 /* write a array of registers */
2122 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2126 #if CONFIG_SENSOR_Focus
2127 struct sensor *sensor = to_sensor(client);
2129 #if CONFIG_SENSOR_I2C_RDWRCHK
2134 if (sensor_task_lock(client, 1) < 0)
2135 goto sensor_write_array_end;
2136 while (regarray[i].reg != 0)
2138 #if CONFIG_SENSOR_Focus
2139 if ((regarray == sensor_af_firmware) && (sensor->info_priv.enable == 0)) {
2140 SENSOR_DG("%s disable, Download af firmware terminated!\n",SENSOR_NAME_STRING());
2142 goto sensor_write_array_end;
2146 err = sensor_write(client, regarray[i].reg, regarray[i].val);
2150 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2154 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2157 goto sensor_write_array_end;
2160 #if CONFIG_SENSOR_I2C_RDWRCHK
2161 sensor_read(client, regarray[i].reg, &valchk);
2162 if (valchk != regarray[i].val)
2163 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2169 #if CONFIG_SENSOR_Focus
2170 if (((regarray->reg == SEQUENCE_PROPERTY) && (regarray->val == SEQUENCE_INIT))
2171 || (regarray == sensor_init_data)) {
2172 sensor->info_priv.affm_reinit = 1;
2176 sensor_write_array_end:
2177 sensor_task_lock(client,0);
2180 #if CONFIG_SENSOR_I2C_RDWRCHK
2181 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
2189 while (regarray[i].reg != 0)
2191 sensor_read(client, regarray[i].reg, &valchk);
2192 if (valchk != regarray[i].val)
2193 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2200 #if CONFIG_SENSOR_Focus
2207 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
2210 char read_tag=0xff,cnt;
2213 if (cmdinfo->validate_bit & 0x80) {
2214 if (sensor_write(client, CMD_TAG_Reg, cmdinfo->cmd_tag)) {
2215 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
2216 goto sensor_af_cmdset_err;
2218 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
2220 for (i=0; i<4; i++) {
2221 if (cmdinfo->validate_bit & (1<<i)) {
2222 if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
2223 SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
2224 goto sensor_af_cmdset_err;
2226 SENSOR_DG("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
2230 if (sensor_write(client, CMD_TAG_Reg, 0xff)) {
2231 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
2232 goto sensor_af_cmdset_err;
2234 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
2237 if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
2238 SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
2239 goto sensor_af_cmdset_err;
2246 if (sensor_read(client,CMD_TAG_Reg,&read_tag)){
2247 SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
2250 } while((read_tag != 0x00)&& (cnt++<100));
2252 SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
2254 sensor_af_cmdset_err:
2258 static int sensor_af_idlechk(struct i2c_client *client)
2266 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2268 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2270 goto sensor_af_idlechk_end;
2273 if (state != S_IDLE) {
2274 sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
2278 } while((state != S_IDLE)&& (cnt<100));
2280 ret = (state == S_IDLE) ? 0 : -1;
2282 sensor_af_idlechk_end:
2286 static int sensor_af_single(struct i2c_client *client)
2291 if (sensor_af_idlechk(client))
2292 goto sensor_af_single_end;
2294 if (sensor_af_cmdset(client, SingleFocus_Cmd, NULL)) {
2295 SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
2297 goto sensor_af_single_end;
2307 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2309 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2311 goto sensor_af_single_end;
2313 }while((state == S_FOCUSING) && (cnt<100));
2315 if (state != S_FOCUSED) {
2316 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
2318 goto sensor_af_single_end;
2321 //sensor_af_cmdset(client, ReturnIdle_Cmd, NULL); // by duanyp. fix af blur when taking pictures
2322 sensor_af_single_end:
2326 static int sensor_af_const(struct i2c_client *client)
2330 if (sensor_af_idlechk(client))
2331 goto sensor_af_const_end;
2333 if (sensor_af_cmdset(client, ConstFocus_Cmd, NULL)) {
2334 SENSOR_TR("%s const focus mode set error!\n",SENSOR_NAME_STRING());
2336 goto sensor_af_const_end;
2338 sensor_af_const_end:
2341 static int sensor_af_pause2capture(struct i2c_client *client)
2346 if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
2347 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
2349 goto sensor_af_pause_end;
2359 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2361 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2363 goto sensor_af_pause_end;
2365 }while((state != S_CAPTURE) && (cnt<100));
2367 if (state != S_CAPTURE) {
2368 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
2370 goto sensor_af_pause_end;
2372 sensor_af_pause_end:
2375 static int sensor_af_zoneupdate(struct i2c_client *client)
2379 if (sensor_af_idlechk(client))
2380 goto sensor_af_zoneupdate_end;
2382 if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
2383 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
2385 goto sensor_af_zoneupdate_end;
2388 sensor_af_zoneupdate_end:
2391 static int sensor_af_init(struct i2c_client *client)
2396 ret = sensor_write_array(client, sensor_af_firmware);
2398 SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
2400 goto sensor_af_init_end;
2410 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2412 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2414 goto sensor_af_init_end;
2416 }while((state == S_STARTUP) && (cnt<100));
2418 if (state != S_IDLE) {
2419 SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
2421 goto sensor_af_init_end;
2425 SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
2429 static int sensor_af_wq_function(struct i2c_client *client)
2431 struct sensor *sensor = to_sensor(client);
2432 struct af_cmdinfo cmdinfo;
2433 int ret=0, focus_pos = 0xfe;
2435 SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
2437 mutex_lock(&sensor->wq_lock);
2438 if (sensor_af_init(client)) {
2439 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
2442 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
2444 switch (sensor->info_priv.auto_focus)
2446 case SENSOR_AF_MODE_INFINITY:
2450 case SENSOR_AF_MODE_MACRO:
2452 if (focus_pos != 0x00)
2455 sensor_af_idlechk(client);
2456 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
2457 cmdinfo.cmd_para[0] = focus_pos;
2458 cmdinfo.validate_bit = 0x81;
2459 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
2462 case SENSOR_AF_MODE_AUTO:
2464 ret = sensor_af_single(client);
2467 case SENSOR_AF_MODE_CONTINUOUS:
2469 ret = sensor_af_const(client);
2472 case SENSOR_AF_MODE_CLOSE:
2479 SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
2480 goto sensor_af_wq_function_end;
2484 SENSOR_DG("%s sensor_af_wq_function set focus mode(0x%x) ret:0x%x\n",SENSOR_NAME_STRING(), sensor->info_priv.auto_focus,ret);
2487 sensor_af_wq_function_end:
2488 sensor->sensor_wk.state = sensor_work_ready;
2489 mutex_unlock(&sensor->wq_lock);
2492 static void sensor_af_workqueue(struct work_struct *work)
2494 struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
2495 struct i2c_client *client = sensor_work->client;
2497 if (sensor_af_wq_function(client) < 0) {
2498 SENSOR_TR("%s af workqueue return false\n",SENSOR_NAME_STRING());
2503 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
2505 struct soc_camera_link *icl = to_soc_camera_link(icd);
2508 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2512 case Sensor_PowerDown:
2514 if (icl->powerdown) {
2515 ret = icl->powerdown(icd->pdev, on);
2516 if (ret == RK_CAM_IO_SUCCESS) {
2520 icl->reset(icd->pdev);
2522 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
2524 goto sensor_power_end;
2531 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2532 struct sensor *sensor = to_sensor(client);
2534 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2535 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2541 SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
2549 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2551 struct i2c_client *client = sd->priv;
2552 struct soc_camera_device *icd = client->dev.platform_data;
2553 struct sensor *sensor = to_sensor(client);
2554 const struct v4l2_queryctrl *qctrl;
2555 const struct sensor_datafmt *fmt;
2557 int ret,pid = 0,i = 0,j=0;
2558 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
2559 sensor_init_data_p = sensor_init_data;
2560 sensor_init_winseq_p = sensor_vga;
2561 sensor_init_width = 640;
2562 sensor_init_height = 480;
2563 if (tmp_plat_data != NULL) {
2564 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
2565 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
2566 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
2570 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
2571 //user has defined the init data
2573 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
2574 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
2575 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
2576 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
2578 sensor_init_data_p = sensor_init_data;
2580 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
2581 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
2584 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
2585 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
2586 if(sensor_init_winseq_board)
2588 vfree(sensor_init_winseq_board);
2589 sensor_init_winseq_board = NULL;
2591 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
2592 if(!sensor_init_winseq_board)
2593 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
2594 for(j = 0;j< tmp_winseq_size;j++){
2595 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
2596 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
2598 sensor_init_winseq_p = sensor_init_winseq_board;
2600 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
2601 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
2603 //init width,height,bus,pixelcode
2604 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
2605 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
2606 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
2607 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
2608 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
2609 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
2610 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
2611 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
2613 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2615 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2617 goto sensor_INIT_ERR;
2619 /* ddl@rock-chips.com : ov3640_powerOn have hardware reset */
2622 if (sensor_task_lock(client,1)<0)
2623 goto sensor_INIT_ERR;
2624 ret = sensor_write(client, 0x3012, 0x80);
2627 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2629 goto sensor_INIT_ERR;
2632 mdelay(5); //delay 5 microseconds
2634 /* check if it is an sensor sensor */
2635 ret = sensor_read(client, 0x300a, &value);
2637 SENSOR_TR("read chip id high byte failed\n");
2639 goto sensor_INIT_ERR;
2642 pid |= (value << 8);
2644 ret = sensor_read(client, 0x300b, &value);
2646 SENSOR_TR("read chip id low byte failed\n");
2648 goto sensor_INIT_ERR;
2651 pid |= (value & 0xff);
2652 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2653 if (pid == SENSOR_ID) {
2654 sensor->model = SENSOR_V4L2_IDENT;
2656 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2658 goto sensor_INIT_ERR;
2661 ret = sensor_write_array(client, sensor_init_data_p);
2664 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2665 goto sensor_INIT_ERR;
2667 sensor_task_lock(client,0);
2669 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2670 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2672 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2674 goto sensor_INIT_ERR;
2676 sensor->info_priv.fmt = *fmt;
2678 /* sensor sensor information for initialization */
2679 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2681 sensor->info_priv.whiteBalance = qctrl->default_value;
2682 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2684 sensor->info_priv.brightness = qctrl->default_value;
2685 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2687 sensor->info_priv.effect = qctrl->default_value;
2688 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2690 sensor->info_priv.exposure = qctrl->default_value;
2692 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2694 sensor->info_priv.saturation = qctrl->default_value;
2695 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2697 sensor->info_priv.contrast = qctrl->default_value;
2698 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2700 sensor->info_priv.mirror = qctrl->default_value;
2701 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2703 sensor->info_priv.flip = qctrl->default_value;
2704 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2706 sensor->info_priv.scene = qctrl->default_value;
2707 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2709 sensor->info_priv.digitalzoom = qctrl->default_value;
2711 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2712 #if CONFIG_SENSOR_Focus
2713 // sensor_set_focus();
2714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);//?,JYK
2716 sensor->info_priv.focus = qctrl->default_value;
2719 #if CONFIG_SENSOR_Flash
2720 //sensor_set_flash();
2721 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2723 sensor->info_priv.flash = qctrl->default_value;
2726 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);
2730 sensor_task_lock(client,0);
2731 sensor_deactivate(client);
2734 static int sensor_deactivate(struct i2c_client *client)
2736 struct soc_camera_device *icd = client->dev.platform_data;
2738 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2740 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2741 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2742 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2743 icd->user_width = SENSOR_INIT_WIDTH;
2744 icd->user_height = SENSOR_INIT_HEIGHT;
2748 static struct reginfo sensor_power_down_sequence[]=
2757 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2760 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2762 if (pm_msg.event == PM_EVENT_SUSPEND) {
2763 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2764 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2766 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2769 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2771 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2776 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2783 static int sensor_resume(struct soc_camera_device *icd)
2787 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2789 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2793 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2797 static int sensor_set_bus_param(struct soc_camera_device *icd,
2798 unsigned long flags)
2804 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2806 struct soc_camera_link *icl = to_soc_camera_link(icd);
2807 unsigned long flags = SENSOR_BUS_PARAM;
2809 return soc_camera_apply_sensor_flags(icl, flags);
2812 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2814 struct i2c_client *client = sd->priv;
2815 struct soc_camera_device *icd = client->dev.platform_data;
2816 struct sensor *sensor = to_sensor(client);
2818 mf->width = icd->user_width;
2819 mf->height = icd->user_height;
2820 mf->code = sensor->info_priv.fmt.code;
2821 mf->colorspace = sensor->info_priv.fmt.colorspace;
2822 mf->field = V4L2_FIELD_NONE;
2826 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2830 if ((mf->width == 1024) && (mf->height == 768)) {
2832 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2834 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2836 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2838 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2843 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2847 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2851 if ((mf->width == 1280) && (mf->height == 720)) {
2853 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2858 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2861 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2863 struct i2c_client *client = sd->priv;
2864 const struct sensor_datafmt *fmt;
2865 struct soc_camera_device *icd = client->dev.platform_data;
2866 struct sensor *sensor = to_sensor(client);
2867 const struct v4l2_queryctrl *qctrl;
2868 struct reginfo *winseqe_set_addr=NULL;
2869 int ret=0, set_w,set_h;
2872 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2873 ARRAY_SIZE(sensor_colour_fmts));
2876 goto sensor_s_fmt_end;
2879 if (sensor->info_priv.fmt.code != mf->code) {
2882 case V4L2_MBUS_FMT_YUYV8_2X8:
2884 winseqe_set_addr = sensor_ClrFmt_YUYV;
2887 case V4L2_MBUS_FMT_UYVY8_2X8:
2889 winseqe_set_addr = sensor_ClrFmt_UYVY;
2895 if (winseqe_set_addr != NULL) {
2896 sensor_write_array(client, winseqe_set_addr);
2897 sensor->info_priv.fmt.code = mf->code;
2898 sensor->info_priv.fmt.colorspace= mf->colorspace;
2899 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2901 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2907 isCapture = sensor_fmt_capturechk(sd, mf);
2909 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[isCapture][0].reg)
2911 winseqe_set_addr = sensor_qcif[isCapture];
2915 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[isCapture][0].reg)
2917 winseqe_set_addr = sensor_qvga[isCapture];
2921 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[isCapture][0].reg)
2923 winseqe_set_addr = sensor_cif[isCapture];
2927 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[isCapture][0].reg)
2929 winseqe_set_addr = sensor_vga[isCapture];
2933 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[isCapture][0].reg)
2935 winseqe_set_addr = sensor_svga[isCapture];
2939 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_sxga[isCapture][0].reg)
2941 winseqe_set_addr = sensor_xga[isCapture];
2945 else if (((set_w <= 1280) && (set_h <= 960)) && sensor_sxga[isCapture][0].reg)
2947 winseqe_set_addr = sensor_sxga[isCapture];
2951 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[isCapture][0].reg)
2953 winseqe_set_addr = sensor_uxga[isCapture];
2957 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_uxga[isCapture][0].reg)
2959 winseqe_set_addr = sensor_qxga[isCapture];
2965 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2966 set_w = SENSOR_INIT_WIDTH;
2967 set_h = SENSOR_INIT_HEIGHT;
2968 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2971 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr){
2972 //srt --if capture,then should write sensor_qxga[1] first
2973 if((winseqe_set_addr != sensor_qxga[isCapture]) && isCapture) {
2974 SENSOR_DG("%s write sensor_qxga[1]\n", SENSOR_NAME_STRING());
2975 ret = sensor_write_array(client, sensor_qxga[isCapture]);
2977 SENSOR_TR("%s write sensor_qxga[1] failed\n", SENSOR_NAME_STRING());
2982 #if CONFIG_SENSOR_Focus
2983 //sensor_af_idlechk(client);
2984 if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS)
2986 sensor_af_idlechk(client); // by duanyp
2987 sensor_af_cmdset(client, PauseFocus_Cmd, NULL);
2991 #if CONFIG_SENSOR_Flash
2992 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2993 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2994 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2995 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2997 } else { /* ddl@rock-chips.com : Video */
2998 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2999 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3000 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
3005 ret = sensor_write_array(client, winseqe_set_addr);
3007 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
3008 #if CONFIG_SENSOR_Flash
3009 if (sensor_fmt_capturechk(sd,mf) == true) {
3010 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
3011 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3012 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
3016 goto sensor_s_fmt_end;
3018 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
3019 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
3020 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3021 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
3022 if (sensor->info_priv.whiteBalance != 0) {
3023 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3024 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3026 sensor->info_priv.snap2preview = true;
3027 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
3028 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3029 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
3030 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3031 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3032 sensor->info_priv.video2preview = true;
3033 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
3034 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3035 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
3036 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3037 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3038 sensor->info_priv.video2preview = false;
3039 sensor->info_priv.snap2preview = false;
3041 mdelay(100); // by FAE.
3043 SENSOR_DG("\n%s..%s.. icd->width=%d..icd->height=%d..isCapture=%d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h,isCapture);
3045 SENSOR_TR("\n %s .. Current Format is validate. icd->width=%d..icd->height=%d..isCapture=%d\n",SENSOR_NAME_STRING(),set_w,set_h,isCapture);
3053 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
3055 struct i2c_client *client = sd->priv;
3056 struct sensor *sensor = to_sensor(client);
3057 const struct sensor_datafmt *fmt;
3060 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
3061 ARRAY_SIZE(sensor_colour_fmts));
3063 fmt = &sensor->info_priv.fmt;
3064 mf->code = fmt->code;
3067 if (mf->height > SENSOR_MAX_HEIGHT)
3068 mf->height = SENSOR_MAX_HEIGHT;
3069 else if (mf->height < SENSOR_MIN_HEIGHT)
3070 mf->height = SENSOR_MIN_HEIGHT;
3072 if (mf->width > SENSOR_MAX_WIDTH)
3073 mf->width = SENSOR_MAX_WIDTH;
3074 else if (mf->width < SENSOR_MIN_WIDTH)
3075 mf->width = SENSOR_MIN_WIDTH;
3077 mf->colorspace = fmt->colorspace;
3082 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
3084 struct i2c_client *client = sd->priv;
3086 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
3089 if (id->match.addr != client->addr)
3092 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV3640 identifier */
3097 #if CONFIG_SENSOR_Brightness
3098 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3100 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3102 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3104 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
3106 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
3108 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3111 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3115 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3119 #if CONFIG_SENSOR_Effect
3120 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3122 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3124 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3126 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
3128 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
3130 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3133 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3137 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3141 #if CONFIG_SENSOR_Exposure
3142 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3144 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3146 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3148 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
3150 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
3152 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3155 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3159 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3163 #if CONFIG_SENSOR_Saturation
3164 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3166 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3168 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3170 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
3172 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
3174 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3177 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3181 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3185 #if CONFIG_SENSOR_Contrast
3186 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3188 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3190 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3192 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
3194 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
3196 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3199 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3203 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3207 #if CONFIG_SENSOR_Mirror
3208 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3210 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3212 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3214 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
3216 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
3218 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3221 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3225 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3229 #if CONFIG_SENSOR_Flip
3230 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3232 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3234 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3236 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
3238 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
3240 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3243 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3247 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3251 #if CONFIG_SENSOR_Scene
3252 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3254 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3256 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3258 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
3260 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
3262 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3265 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3269 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3273 #if CONFIG_SENSOR_WhiteBalance
3274 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3276 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3278 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3280 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
3282 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
3284 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3287 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3291 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3295 #if CONFIG_SENSOR_DigitalZoom
3296 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
3298 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3299 struct sensor *sensor = to_sensor(client);
3300 const struct v4l2_queryctrl *qctrl_info;
3301 int digitalzoom_cur, digitalzoom_total;
3303 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
3307 digitalzoom_cur = sensor->info_priv.digitalzoom;
3308 digitalzoom_total = qctrl_info->maximum;
3310 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
3312 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3316 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
3318 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3322 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
3324 *value = digitalzoom_total - digitalzoom_cur;
3327 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
3329 *value = 0 - digitalzoom_cur;
3332 digitalzoom_cur += *value;
3334 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
3336 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
3338 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3341 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
3349 #if CONFIG_SENSOR_Focus
3350 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3352 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3353 struct sensor *sensor = to_sensor(client);
3354 const struct v4l2_queryctrl *qctrl_info;
3355 struct af_cmdinfo cmdinfo;
3358 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
3362 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3363 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
3365 if (sensor_af_idlechk(client))
3366 goto sensor_set_focus_absolute_end;
3368 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3369 cmdinfo.cmd_para[0] = value;
3370 cmdinfo.validate_bit = 0x81;
3371 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3372 //ret |= sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
3373 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3376 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3380 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3381 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3384 sensor_set_focus_absolute_end:
3387 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3389 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3390 struct sensor *sensor = to_sensor(client);
3391 const struct v4l2_queryctrl *qctrl_info;
3392 struct af_cmdinfo cmdinfo;
3395 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
3399 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3400 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
3402 if (sensor_af_idlechk(client))
3403 goto sensor_set_focus_relative_end;
3406 cmdinfo.cmd_tag = StepFocus_Near_Tag;
3407 } else if (value < 0) {
3408 cmdinfo.cmd_tag = StepFocus_Far_Tag;
3410 cmdinfo.validate_bit = 0x80;
3411 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3413 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3416 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3420 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3421 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3423 sensor_set_focus_relative_end:
3427 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3429 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3430 struct sensor *sensor = to_sensor(client);
3433 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3436 case SENSOR_AF_MODE_AUTO:
3438 ret = sensor_af_single(client);
3442 case SENSOR_AF_MODE_MACRO:
3444 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
3448 case SENSOR_AF_MODE_INFINITY:
3450 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
3454 case SENSOR_AF_MODE_CONTINUOUS:
3456 ret = sensor_af_const(client);
3460 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3465 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3468 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3469 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3475 #if CONFIG_SENSOR_Flash
3476 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3478 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3479 if (value == 3) { /* ddl@rock-chips.com: torch */
3480 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
3482 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3484 SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3488 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3492 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3494 struct i2c_client *client = sd->priv;
3495 struct sensor *sensor = to_sensor(client);
3496 const struct v4l2_queryctrl *qctrl;
3498 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3502 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3508 case V4L2_CID_BRIGHTNESS:
3510 ctrl->value = sensor->info_priv.brightness;
3513 case V4L2_CID_SATURATION:
3515 ctrl->value = sensor->info_priv.saturation;
3518 case V4L2_CID_CONTRAST:
3520 ctrl->value = sensor->info_priv.contrast;
3523 case V4L2_CID_DO_WHITE_BALANCE:
3525 ctrl->value = sensor->info_priv.whiteBalance;
3528 case V4L2_CID_EXPOSURE:
3530 ctrl->value = sensor->info_priv.exposure;
3533 case V4L2_CID_HFLIP:
3535 ctrl->value = sensor->info_priv.mirror;
3538 case V4L2_CID_VFLIP:
3540 ctrl->value = sensor->info_priv.flip;
3551 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3553 struct i2c_client *client = sd->priv;
3554 struct sensor *sensor = to_sensor(client);
3555 struct soc_camera_device *icd = client->dev.platform_data;
3556 const struct v4l2_queryctrl *qctrl;
3559 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3563 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3569 #if CONFIG_SENSOR_Brightness
3570 case V4L2_CID_BRIGHTNESS:
3572 if (ctrl->value != sensor->info_priv.brightness)
3574 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3578 sensor->info_priv.brightness = ctrl->value;
3583 #if CONFIG_SENSOR_Exposure
3584 case V4L2_CID_EXPOSURE:
3586 if (ctrl->value != sensor->info_priv.exposure)
3588 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3592 sensor->info_priv.exposure = ctrl->value;
3597 #if CONFIG_SENSOR_Saturation
3598 case V4L2_CID_SATURATION:
3600 if (ctrl->value != sensor->info_priv.saturation)
3602 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3606 sensor->info_priv.saturation = ctrl->value;
3611 #if CONFIG_SENSOR_Contrast
3612 case V4L2_CID_CONTRAST:
3614 if (ctrl->value != sensor->info_priv.contrast)
3616 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3620 sensor->info_priv.contrast = ctrl->value;
3625 #if CONFIG_SENSOR_WhiteBalance
3626 case V4L2_CID_DO_WHITE_BALANCE:
3628 if (ctrl->value != sensor->info_priv.whiteBalance)
3630 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3634 sensor->info_priv.whiteBalance = ctrl->value;
3639 #if CONFIG_SENSOR_Mirror
3640 case V4L2_CID_HFLIP:
3642 if (ctrl->value != sensor->info_priv.mirror)
3644 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3646 sensor->info_priv.mirror = ctrl->value;
3651 #if CONFIG_SENSOR_Flip
3652 case V4L2_CID_VFLIP:
3654 if (ctrl->value != sensor->info_priv.flip)
3656 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3658 sensor->info_priv.flip = ctrl->value;
3669 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3671 const struct v4l2_queryctrl *qctrl;
3672 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3673 struct sensor *sensor = to_sensor(client);
3675 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3679 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3683 switch (ext_ctrl->id)
3685 case V4L2_CID_SCENE:
3687 ext_ctrl->value = sensor->info_priv.scene;
3690 case V4L2_CID_EFFECT:
3692 ext_ctrl->value = sensor->info_priv.effect;
3695 case V4L2_CID_ZOOM_ABSOLUTE:
3697 ext_ctrl->value = sensor->info_priv.digitalzoom;
3700 case V4L2_CID_ZOOM_RELATIVE:
3704 case V4L2_CID_FOCUS_ABSOLUTE:
3706 ext_ctrl->value = sensor->info_priv.focus;
3709 case V4L2_CID_FOCUS_RELATIVE:
3713 case V4L2_CID_FLASH:
3715 ext_ctrl->value = sensor->info_priv.flash;
3723 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3725 const struct v4l2_queryctrl *qctrl;
3726 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3727 struct sensor *sensor = to_sensor(client);
3730 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3734 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3739 switch (ext_ctrl->id)
3741 #if CONFIG_SENSOR_Scene
3742 case V4L2_CID_SCENE:
3744 if (ext_ctrl->value != sensor->info_priv.scene)
3746 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3748 sensor->info_priv.scene = ext_ctrl->value;
3753 #if CONFIG_SENSOR_Effect
3754 case V4L2_CID_EFFECT:
3756 if (ext_ctrl->value != sensor->info_priv.effect)
3758 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3760 sensor->info_priv.effect= ext_ctrl->value;
3765 #if CONFIG_SENSOR_DigitalZoom
3766 case V4L2_CID_ZOOM_ABSOLUTE:
3768 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3771 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3773 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3775 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3777 sensor->info_priv.digitalzoom += val_offset;
3779 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3784 case V4L2_CID_ZOOM_RELATIVE:
3786 if (ext_ctrl->value)
3788 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3790 sensor->info_priv.digitalzoom += ext_ctrl->value;
3792 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3797 #if CONFIG_SENSOR_Focus
3798 case V4L2_CID_FOCUS_ABSOLUTE:
3800 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3803 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
3804 if (ext_ctrl->value == qctrl->minimum) {
3805 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
3806 } else if (ext_ctrl->value == qctrl->maximum) {
3807 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
3809 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
3815 case V4L2_CID_FOCUS_RELATIVE:
3817 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3820 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
3823 case V4L2_CID_FOCUS_AUTO:
3825 if (ext_ctrl->value == 1) {
3826 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
3828 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
3829 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
3830 if (ext_ctrl->value == 0)
3831 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3836 case V4L2_CID_FOCUS_CONTINUOUS:
3838 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
3839 if (ext_ctrl->value == 1) {
3840 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
3842 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
3845 if (ext_ctrl->value == 0)
3846 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3851 #if CONFIG_SENSOR_Flash
3852 case V4L2_CID_FLASH:
3854 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3856 sensor->info_priv.flash = ext_ctrl->value;
3858 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3869 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3871 struct i2c_client *client = sd->priv;
3872 struct soc_camera_device *icd = client->dev.platform_data;
3873 int i, error_cnt=0, error_idx=-1;
3876 for (i=0; i<ext_ctrl->count; i++) {
3877 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3884 error_idx = ext_ctrl->count;
3886 if (error_idx != -1) {
3887 ext_ctrl->error_idx = error_idx;
3894 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3896 struct i2c_client *client = sd->priv;
3897 struct soc_camera_device *icd = client->dev.platform_data;
3898 int i, error_cnt=0, error_idx=-1;
3901 for (i=0; i<ext_ctrl->count; i++) {
3902 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3909 error_idx = ext_ctrl->count;
3911 if (error_idx != -1) {
3912 ext_ctrl->error_idx = error_idx;
3919 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
3921 struct i2c_client *client = sd->priv;
3922 struct sensor *sensor = to_sensor(client);
3923 #if CONFIG_SENSOR_Focus
3924 struct soc_camera_device *icd = client->dev.platform_data;
3925 struct v4l2_mbus_framefmt mf;
3929 sensor->info_priv.enable = 1;
3930 #if CONFIG_SENSOR_Focus
3931 mf.width = icd->user_width;
3932 mf.height = icd->user_height;
3933 mf.code = sensor->info_priv.fmt.code;
3934 mf.colorspace = sensor->info_priv.fmt.colorspace;
3935 mf.field = V4L2_FIELD_NONE;
3936 /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
3937 if (sensor_fmt_capturechk(sd, &mf) == false) {
3938 if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {
3939 if (sensor->sensor_wq != NULL) {
3940 mutex_lock(&sensor->wq_lock);
3941 if (sensor->sensor_wk.state == sensor_working) {
3942 SENSOR_DG("%s sensor af firmware thread is runing, Ingore current work",SENSOR_NAME_STRING());
3943 mutex_unlock(&sensor->wq_lock);
3944 goto sensor_s_stream_end;
3946 sensor->sensor_wk.state = sensor_working;
3947 mutex_unlock(&sensor->wq_lock);
3948 sensor->sensor_wk.client = client;
3949 INIT_WORK(&(sensor->sensor_wk.dwork.work), sensor_af_workqueue);
3950 queue_delayed_work(sensor->sensor_wq,&(sensor->sensor_wk.dwork), 0);
3952 sensor->info_priv.affm_reinit = 0;
3956 } else if (enable == 0) {
3957 sensor->info_priv.enable = 0;
3958 #if CONFIG_SENSOR_Focus
3959 flush_work(&(sensor->sensor_wk.dwork.work));
3960 mutex_lock(&sensor->wq_lock);
3961 sensor->sensor_wk.state = sensor_work_ready;
3962 mutex_unlock(&sensor->wq_lock);
3966 sensor_s_stream_end:
3970 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3971 * this wasn't our capture interface, so, we wait for the right one */
3972 static int sensor_video_probe(struct soc_camera_device *icd,
3973 struct i2c_client *client)
3977 struct sensor *sensor = to_sensor(client);
3979 /* We must have a parent by now. And it cannot be a wrong one.
3980 * So this entire test is completely redundant. */
3981 if (!icd->dev.parent ||
3982 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3985 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3987 goto sensor_video_probe_err;
3990 ret = sensor_write(client, 0x3012, 0x80);
3992 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3994 goto sensor_video_probe_err;
3996 mdelay(5); //delay 5 microseconds
3998 /* check if it is an sensor sensor */
3999 ret = sensor_read(client, 0x300a, &value);
4001 SENSOR_TR("read chip id high byte failed\n");
4003 goto sensor_video_probe_err;
4006 pid |= (value << 8);
4008 ret = sensor_read(client, 0x300b, &value);
4010 SENSOR_TR("read chip id low byte failed\n");
4012 goto sensor_video_probe_err;
4015 pid |= (value & 0xff);
4016 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4017 if (pid == SENSOR_ID) {
4018 sensor->model = SENSOR_V4L2_IDENT;
4020 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4022 goto sensor_video_probe_err;
4026 sensor_video_probe_err:
4029 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
4031 struct i2c_client *client = sd->priv;
4032 struct soc_camera_device *icd = client->dev.platform_data;
4033 struct sensor *sensor = to_sensor(client);
4036 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4039 case RK_CAM_SUBDEV_DEACTIVATE:
4041 sensor_deactivate(client);
4044 case RK_CAM_SUBDEV_IOREQUEST:
4046 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
4047 if (sensor->sensor_io_request != NULL) {
4048 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
4049 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
4050 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
4051 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
4052 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
4053 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
4056 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
4058 goto sensor_ioctl_end;
4060 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
4062 #if CONFIG_SENSOR_Flash
4063 if (sensor->sensor_gpio_res) {
4064 printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
4065 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
4066 for (i = 0; i < icd->ops->num_controls; i++) {
4067 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
4068 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
4071 sensor->info_priv.flash = 0xff;
4072 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
4080 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4089 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
4090 enum v4l2_mbus_pixelcode *code)
4092 if (index >= ARRAY_SIZE(sensor_colour_fmts))
4095 *code = sensor_colour_fmts[index].code;
4098 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
4099 .init = sensor_init,
4100 .g_ctrl = sensor_g_control,
4101 .s_ctrl = sensor_s_control,
4102 .g_ext_ctrls = sensor_g_ext_controls,
4103 .s_ext_ctrls = sensor_s_ext_controls,
4104 .g_chip_ident = sensor_g_chip_ident,
4105 .ioctl = sensor_ioctl,
4108 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
4109 .s_mbus_fmt = sensor_s_fmt,
4110 .g_mbus_fmt = sensor_g_fmt,
4111 .try_mbus_fmt = sensor_try_fmt,
4112 .enum_mbus_fmt = sensor_enum_fmt,
4113 .s_stream = sensor_s_stream,
4116 static struct v4l2_subdev_ops sensor_subdev_ops = {
4117 .core = &sensor_subdev_core_ops,
4118 .video = &sensor_subdev_video_ops,
4121 static int sensor_probe(struct i2c_client *client,
4122 const struct i2c_device_id *did)
4124 struct sensor *sensor;
4125 struct soc_camera_device *icd = client->dev.platform_data;
4126 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
4127 struct soc_camera_link *icl;
4130 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
4132 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
4136 icl = to_soc_camera_link(icd);
4138 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
4142 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
4143 dev_warn(&adapter->dev,
4144 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
4148 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
4152 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
4154 /* Second stage probe - when a capture adapter is there */
4155 icd->ops = &sensor_ops;
4156 sensor->info_priv.fmt = sensor_colour_fmts[0];
4157 #if CONFIG_SENSOR_I2C_NOSCHED
4158 atomic_set(&sensor->tasklock_cnt,0);
4161 ret = sensor_video_probe(icd, client);
4164 i2c_set_clientdata(client, NULL);
4168 #if CONFIG_SENSOR_Focus
4169 sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING( wq));
4170 if (sensor->sensor_wq == NULL)
4171 SENSOR_TR("%s workqueue create fail!", SENSOR_NAME_STRING( wq));
4172 mutex_init(&sensor->wq_lock);
4173 sensor->sensor_wk.state = sensor_work_ready;
4176 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
4180 static int sensor_remove(struct i2c_client *client)
4182 struct sensor *sensor = to_sensor(client);
4183 struct soc_camera_device *icd = client->dev.platform_data;
4185 #if CONFIG_SENSOR_Focus
4186 if (sensor->sensor_wq) {
4187 destroy_workqueue(sensor->sensor_wq);
4188 sensor->sensor_wq = NULL;
4193 i2c_set_clientdata(client, NULL);
4194 client->driver = NULL;
4200 static const struct i2c_device_id sensor_id[] = {
4201 {SENSOR_NAME_STRING(), 0 },
4204 MODULE_DEVICE_TABLE(i2c, sensor_id);
4206 static struct i2c_driver sensor_i2c_driver = {
4208 .name = SENSOR_NAME_STRING(),
4210 .probe = sensor_probe,
4211 .remove = sensor_remove,
4212 .id_table = sensor_id,
4215 static int __init sensor_mod_init(void)
4217 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4218 return i2c_add_driver(&sensor_i2c_driver);
4221 static void __exit sensor_mod_exit(void)
4223 i2c_del_driver(&sensor_i2c_driver);
4226 device_initcall_sync(sensor_mod_init);
4227 module_exit(sensor_mod_exit);
4229 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
4230 MODULE_AUTHOR("ddl <kernel@rock-chips>");
4231 MODULE_LICENSE("GPL");