2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <mach/rk29_camera.h>
26 module_param(debug, int, S_IRUGO|S_IWUSR);
28 #define dprintk(level, fmt, arg...) do { \
30 printk(KERN_WARNING fmt , ## arg); } while (0)
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(0, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_OV3640
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV3640
48 #define SENSOR_ID 0x364c
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
51 #define SENSOR_MAX_WIDTH 2048
52 #define SENSOR_MAX_HEIGHT 1536
53 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT 480
55 #define SENSOR_INIT_WINSEQADR sensor_init_data
56 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_YUYV
58 #define CONFIG_SENSOR_WhiteBalance 1
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 1
63 #define CONFIG_SENSOR_Scene 1
64 #define CONFIG_SENSOR_DigitalZoom 0
65 #define CONFIG_SENSOR_Exposure 0
66 #define CONFIG_SENSOR_Flash 1
67 #define CONFIG_SENSOR_Mirror 0
68 #define CONFIG_SENSOR_Flip 0
69 #ifdef CONFIG_OV3640_AUTOFOCUS
70 #define CONFIG_SENSOR_Focus 1
71 #include "ov3640_af_firmware.c"
73 #define CONFIG_SENSOR_Focus 0
76 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
77 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
78 #define CONFIG_SENSOR_I2C_NOSCHED 0
79 #define CONFIG_SENSOR_I2C_RDWRCHK 0
82 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
83 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
84 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
86 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
87 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
88 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
89 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
90 #define COLOR_TEMPERATURE_OFFICE_DN 3500
91 #define COLOR_TEMPERATURE_OFFICE_UP 5000
92 #define COLOR_TEMPERATURE_HOME_DN 2500
93 #define COLOR_TEMPERATURE_HOME_UP 3500
95 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
96 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
98 #define SENSOR_AF_IS_ERR (0x00<<0)
99 #define SENSOR_AF_IS_OK (0x01<<0)
101 #if CONFIG_SENSOR_Focus
102 #define SENSOR_AF_MODE_INFINITY 0
103 #define SENSOR_AF_MODE_MACRO 1
104 #define SENSOR_AF_MODE_FIXED 2
105 #define SENSOR_AF_MODE_AUTO 3
106 #define SENSOR_AF_MODE_CONTINUOUS 4
107 #define SENSOR_AF_MODE_CLOSE 5
111 #define VCM_FIRMWARE 1
113 #define VCM_STARTADDR 0x8000
116 #if (VCM_FIRMWARE==1)
117 #define S_FOCUSING 0x01
118 #define S_FOCUSED 0x02
119 #define S_CAPTURE 0x12
120 #define STA_FOCUS 0x3f07
121 #elif (VCM_FIRMWARE==2)
122 #define S_FOCUSING 0x01
123 #define S_FOCUSED 0x02
124 #define S_CAPTURE 0x12
125 #define STA_FOCUS 0x3f01
127 #define S_FOCUSING 0x65
128 #define S_FOCUSED 0x46
129 #define S_CAPTURE 0x47
130 #define STA_FOCUS 0x3f01
134 #if CONFIG_SENSOR_Focus
135 /* ov3640 VCM Command and Status Registers */
136 #define CMD_MAIN_Reg 0x3F00
137 #define CMD_TAG_Reg 0x3F01
138 #define CMD_PARA0_Reg 0x3F05
139 #define CMD_PARA1_Reg 0x3F04
140 #define CMD_PARA2_Reg 0x3F03
141 #define CMD_PARA3_Reg 0x3F02
142 #define STA_ZONE_Reg 0x3F06
143 #define STA_FOCUS_Reg 0x3F07
145 /* ov3640 VCM Command */
146 #define OverlayEn_Cmd 0x01
147 #define OverlayDis_Cmd 0x02
148 #define SingleFocus_Cmd 0x03
149 #define ConstFocus_Cmd 0x04
150 #define StepMode_Cmd 0x05
151 #define PauseFocus_Cmd 0x06
152 #define ReturnIdle_Cmd 0x08
153 #define SetZone_Cmd 0x10
154 #define UpdateZone_Cmd 0x12
155 #define SetMotor_Cmd 0x20
157 /* ov3640 Focus State */
158 #define S_FIRWRE 0xFF
159 #define S_STARTUP 0xFA
161 #define S_DRVICERR 0xEE
163 #define S_FOCUSING 0x01
164 #define S_FOCUSED 0x02
165 #define S_CAPTURE 0x12
168 /* ovxxxx Zone State */
169 #define Zone_Is_Focused(a, zone_val) (zone_val&(1<<(a-3)))
170 #define Zone_Get_ID(zone_val) (zone_val&0x03)
172 #define Zone_CenterMode 0x01
173 #define Zone_5xMode 0x02
174 #define Zone_5PlusMode 0x03
175 #define Zone_4fMode 0x04
177 #define ZoneSel_Auto 0x0b
178 #define ZoneSel_SemiAuto 0x0c
179 #define ZoneSel_Manual 0x0d
180 #define ZoneSel_Rotate 0x0e
182 /* ovxxxx Step Focus Commands */
183 #define StepFocus_Near_Tag 0x01
184 #define StepFocus_Far_Tag 0x02
185 #define StepFocus_Furthest_Tag 0x03
186 #define StepFocus_Nearest_Tag 0x04
187 #define StepFocus_Spec_Tag 0x10
190 /* init VGA 640*480 */
191 static struct reginfo sensor_init_data[] =
204 {0x30b2, 0x18}, // by FAE
217 {0x30a9, 0xbd},//disable internal DVDD, by FAE.
270 {0x3404, 0x00},//YUV, sequence
347 //{0x307c, 0x13}, // flip && mirror
348 {0x307c, 0x11}, // flip && mirror ,by FAE.
351 //640 480 ;XGA->XGA;;
401 static struct reginfo sensor_qxga_preview[] =
441 //{0x307c, 0x13}, // flip && mirror
442 {0x307c, 0x11}, // flip && mirror, by FAE.
446 //[Sensor.YUV.2048x1536] XGA->QXGA
484 static struct reginfo sensor_qxga_capture[] = {
498 //{0x307C, 0x13}, // by FAE.
524 //{0x307c, 0x13},// flip && mirror
525 {0x307c, 0x11},// flip && mirror , by FAE.
530 static struct reginfo *sensor_qxga[2] = {
536 static struct reginfo sensor_uxga_preview[] =
572 {0x304c, 0x81},//56Mhz PCLK output
573 //{0x307c, 0x13}, // flip && mirror
574 {0x307c, 0x11}, // flip && mirror, by FAE.
579 static struct reginfo sensor_uxga_capture[] =
593 {0x304c, 0x81},//56Mhz PCLK output
594 //{0x307c, 0x13}, // flip && mirror, by FAE.
600 static struct reginfo *sensor_uxga[2] = {
606 static struct reginfo sensor_sxga_preview[] =
642 {0x304c, 0x81},//56Mhz PCLK output
643 //{0x307c, 0x13}, // flip && mirror
644 {0x307c, 0x11}, // by FAE.
649 static struct reginfo sensor_sxga_capture[] =
663 {0x304c, 0x81},//56Mhz PCLK output
664 //{0x307c, 0x13}, // flip && mirror
665 {0x307c, 0x11}, // by FAE.
669 static struct reginfo *sensor_sxga[2] = {
675 static struct reginfo sensor_xga_preview[] =
707 {0x304c, 0x82},//28Mhz PCLK output
708 //{0x307c, 0x13}, // flip && mirror
709 {0x307c, 0x11},// by FAE.
714 static struct reginfo sensor_xga_capture[] =
728 {0x304c, 0x82},//28Mhz PCLK output
729 //{0x307c, 0x13}, // flip && mirror
730 {0x307c, 0x11}, // by FAE.
735 static struct reginfo *sensor_xga[2] = {
741 static struct reginfo sensor_svga_preview[] =
773 {0x304c, 0x83},//28Mhz PCLK output
775 //{0x307c, 0x13}, // flip && mirror
776 {0x307c, 0x11}, // flip && mirror, by FAE.
780 static struct reginfo sensor_svga_capture[] =
794 {0x304c, 0x82},//28Mhz PCLK output
796 //{0x307c, 0x13}, // flip && mirror
797 {0x307c, 0x11}, // flip && mirror, by FAE.
801 static struct reginfo * sensor_svga[2] = {
807 static struct reginfo sensor_vga_preview[] =
836 {0x3089, 0x88},// 0x80, by FAE.
838 {0x308b, 0xe4},// 0xe0, by FAE.
839 {0x304c, 0x84}, //0x83, by FAE.
840 //{0x307c, 0x13}, // flip && mirror
841 {0x307c, 0x11}, // flip && mirror, by FAE.
859 static struct reginfo sensor_vga_capture[] =
873 {0x304c, 0x82},//14Mhz PCLK output 84
874 //{0x307c, 0x13}, // flip && mirror
875 {0x307c, 0x11},// by FAE.
880 static struct reginfo *sensor_vga[2] = {
886 static struct reginfo sensor_cif_preview[] =
935 //{0x307c, 0x13}, // flip && mirror
936 {0x307c, 0x11}, // flip && mirror, by FAE.
941 static struct reginfo sensor_cif_capture[] =
955 {0x304c, 0x84},//14Mhz PCLK output
956 //{0x307c, 0x13}, // flip && mirror
957 {0x307c, 0x11},//by FAE.
962 static struct reginfo *sensor_cif[2] = {
968 static struct reginfo sensor_qvga_preview[] =
1000 {0x304c, 0x89},//14Mhz PCLK output
1001 //{0x307c, 0x13}, // flip && mirror
1002 {0x307c, 0x11}, // by FAE.
1007 static struct reginfo sensor_qvga_capture[] =
1021 {0x304c, 0x84},//14Mhz PCLK output
1023 //{0x307c, 0x13}, // flip && mirror
1024 {0x307c, 0x11},// by FAE.
1028 static struct reginfo *sensor_qvga[2] = {
1029 sensor_qvga_preview,
1030 sensor_qvga_capture,
1034 static struct reginfo sensor_qcif_preview[] =
1066 {0x304c, 0x82},//14Mhz PCLK output 89
1067 //{0x307c, 0x13}, // flip && mirror
1068 {0x307c, 0x11},// by FAE.
1072 static struct reginfo sensor_qcif_capture[] =
1086 {0x304c, 0x84},//14Mhz PCLK output
1088 //{0x307c, 0x13}, // flip && mirror
1089 {0x307c, 0x11}, // by FAE.
1093 static struct reginfo *sensor_qcif[2] = {
1094 sensor_qcif_preview,
1095 sensor_qcif_capture,
1100 static struct reginfo ov3640_Sharpness_auto[] =
1105 static struct reginfo ov3640_Sharpness1[] =
1111 static struct reginfo ov3640_Sharpness2[][3] =
1118 static struct reginfo ov3640_Sharpness3[] =
1124 static struct reginfo ov3640_Sharpness4[]=
1131 static struct reginfo ov3640_Sharpness5[] =
1139 static struct reginfo sensor_ClrFmt_YUYV[]=
1145 static struct reginfo sensor_ClrFmt_UYVY[]=
1151 #if CONFIG_SENSOR_WhiteBalance
1152 static struct reginfo sensor_WhiteB_Auto[]=
1154 {0x332b, 0x00},//AWB auto, bit[3]:0,auto
1158 /* Cloudy Colour Temperature : 6500K - 8000K */
1159 static struct reginfo sensor_WhiteB_Cloudy[]=
1168 /* ClearDay Colour Temperature : 5000K - 6500K */
1169 static struct reginfo sensor_WhiteB_ClearDay[]=
1172 {0x332b, 0x08}, //AWB off
1179 /* Office Colour Temperature : 3500K - 5000K */
1180 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
1190 /* Home Colour Temperature : 2500K - 3500K */
1191 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
1201 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1202 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1206 #if CONFIG_SENSOR_Brightness
1207 static struct reginfo sensor_Brightness0[]=
1218 static struct reginfo sensor_Brightness1[]=
1229 static struct reginfo sensor_Brightness2[]=
1240 static struct reginfo sensor_Brightness3[]=
1251 static struct reginfo sensor_Brightness4[]=
1262 static struct reginfo sensor_Brightness5[]=
1273 static struct reginfo sensor_Brightness6[]=
1277 {0x3355, 0x04}, //bit[2] enable
1278 {0x3354, 0x01}, //bit[3] sign of brightness
1284 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1285 sensor_Brightness4, sensor_Brightness5,sensor_Brightness6,NULL,
1290 #if CONFIG_SENSOR_Effect
1291 static struct reginfo sensor_Effect_Normal[] =
1300 static struct reginfo sensor_Effect_WandB[] =
1304 {0x3355, 0x18}, //bit[4]fix u enable, bit[3]fix v enable
1311 static struct reginfo sensor_Effect_Sepia[] =
1322 static struct reginfo sensor_Effect_Negative[] =
1326 {0x3355, 0x40}, //bit[6] negative
1330 static struct reginfo sensor_Effect_Bluish[] =
1341 static struct reginfo sensor_Effect_Green[] =
1352 static struct reginfo sensor_Effect_Red[] =
1362 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1363 sensor_Effect_Bluish, sensor_Effect_Green,sensor_Effect_Red,NULL,
1366 #if CONFIG_SENSOR_Exposure
1367 static struct reginfo sensor_Exposure0[]=
1378 static struct reginfo sensor_Exposure1[]=
1389 static struct reginfo sensor_Exposure2[]=
1400 static struct reginfo sensor_Exposure3[]=
1411 static struct reginfo sensor_Exposure4[]=
1422 static struct reginfo sensor_Exposure5[]=
1433 static struct reginfo sensor_Exposure6[]=
1444 static struct reginfo sensor_Exposure7[]=
1455 static struct reginfo sensor_Exposure8[]=
1466 static struct reginfo sensor_Exposure9[]=
1477 static struct reginfo sensor_Exposure10[]=
1488 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1489 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,sensor_Exposure7,sensor_Exposure8,sensor_Exposure9,
1490 sensor_Exposure10,NULL,
1493 #if CONFIG_SENSOR_Saturation
1494 static struct reginfo sensor_Saturation0[]=
1505 static struct reginfo sensor_Saturation1[]=
1516 static struct reginfo sensor_Saturation2[]=
1527 static struct reginfo sensor_Saturation3[]=
1538 static struct reginfo sensor_Saturation4[]=
1541 {0x3302, 0xef}, //bit[7]:1, enable SDE
1542 {0x3355, 0x02}, //enable color saturation
1549 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2,
1550 sensor_Saturation3, sensor_Saturation4, NULL,};
1553 #if CONFIG_SENSOR_Contrast
1554 static struct reginfo sensor_Contrast0[]=
1566 static struct reginfo sensor_Contrast1[]=
1578 static struct reginfo sensor_Contrast2[]=
1590 static struct reginfo sensor_Contrast3[]=
1602 static struct reginfo sensor_Contrast4[]=
1615 static struct reginfo sensor_Contrast5[]=
1627 static struct reginfo sensor_Contrast6[]=
1631 {0x3355, 0x04}, //bit[2] enable contrast/brightness
1632 {0x3354, 0x01}, //bit[2] Yoffset sign
1638 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1639 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1643 #if CONFIG_SENSOR_Mirror
1644 static struct reginfo sensor_MirrorOn[]=
1646 {0x307c, 0x12}, //mirror
1653 static struct reginfo sensor_MirrorOff[]=
1655 {0x307c, 0x10},// no mirror/flip
1662 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1664 #if CONFIG_SENSOR_Flip
1665 static struct reginfo sensor_FlipOn[]=
1667 {0x307c, 0x11}, //flip
1674 static struct reginfo sensor_FlipOff[]=
1676 {0x307c, 0x10}, // no mirror/flip
1682 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1685 #if CONFIG_SENSOR_Scene
1686 static struct reginfo sensor_SceneAuto[] =
1688 {0x3014, 0x84},//bit[3]=0 disable auto night mode
1689 {0x3015, 0x12},// or 0x02
1690 {0x302d, 0x00},//clear dummy frame
1691 {0x302e, 0x00},//clear dummy frame
1696 static struct reginfo sensor_SceneNight[] =
1698 {0x3014, 0x8c}, //bit[3] =1 enable auto night mode ¸ù¾Ý¹âÏßÇ¿Èõ×Ô¶¯½µÖ¡
1699 {0x3015, 0x22},//bit[6:4] ÉèÖò»Í¬,½µµÄÖ¡Âʲ»Ò»Ñù.¿ÉÒÔ¿´datasheet
1701 //000 no dummy frame
1708 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1711 #if CONFIG_SENSOR_DigitalZoom
1712 static struct reginfo sensor_Zoom0[] =
1717 static struct reginfo sensor_Zoom1[] =
1722 static struct reginfo sensor_Zoom2[] =
1728 static struct reginfo sensor_Zoom3[] =
1732 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1734 static const struct v4l2_querymenu sensor_menus[] =
1736 #if CONFIG_SENSOR_WhiteBalance
1737 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1738 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1739 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1742 #if CONFIG_SENSOR_Effect
1743 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1744 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1745 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1748 #if CONFIG_SENSOR_Scene
1749 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1752 #if CONFIG_SENSOR_Flash
1753 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1754 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1758 static const struct v4l2_queryctrl sensor_controls[] =
1760 #if CONFIG_SENSOR_WhiteBalance
1762 .id = V4L2_CID_DO_WHITE_BALANCE,
1763 .type = V4L2_CTRL_TYPE_MENU,
1764 .name = "White Balance Control",
1772 #if CONFIG_SENSOR_Brightness
1774 .id = V4L2_CID_BRIGHTNESS,
1775 .type = V4L2_CTRL_TYPE_INTEGER,
1776 .name = "Brightness Control",
1784 #if CONFIG_SENSOR_Effect
1786 .id = V4L2_CID_EFFECT,
1787 .type = V4L2_CTRL_TYPE_MENU,
1788 .name = "Effect Control",
1796 #if CONFIG_SENSOR_Exposure
1798 .id = V4L2_CID_EXPOSURE,
1799 .type = V4L2_CTRL_TYPE_INTEGER,
1800 .name = "Exposure Control",
1808 #if CONFIG_SENSOR_Saturation
1810 .id = V4L2_CID_SATURATION,
1811 .type = V4L2_CTRL_TYPE_INTEGER,
1812 .name = "Saturation Control",
1820 #if CONFIG_SENSOR_Contrast
1822 .id = V4L2_CID_CONTRAST,
1823 .type = V4L2_CTRL_TYPE_INTEGER,
1824 .name = "Contrast Control",
1832 #if CONFIG_SENSOR_Mirror
1834 .id = V4L2_CID_HFLIP,
1835 .type = V4L2_CTRL_TYPE_BOOLEAN,
1836 .name = "Mirror Control",
1844 #if CONFIG_SENSOR_Flip
1846 .id = V4L2_CID_VFLIP,
1847 .type = V4L2_CTRL_TYPE_BOOLEAN,
1848 .name = "Flip Control",
1856 #if CONFIG_SENSOR_Scene
1858 .id = V4L2_CID_SCENE,
1859 .type = V4L2_CTRL_TYPE_MENU,
1860 .name = "Scene Control",
1868 #if CONFIG_SENSOR_DigitalZoom
1870 .id = V4L2_CID_ZOOM_RELATIVE,
1871 .type = V4L2_CTRL_TYPE_INTEGER,
1872 .name = "DigitalZoom Control",
1878 .id = V4L2_CID_ZOOM_ABSOLUTE,
1879 .type = V4L2_CTRL_TYPE_INTEGER,
1880 .name = "DigitalZoom Control",
1888 #if CONFIG_SENSOR_Focus
1890 .id = V4L2_CID_FOCUS_RELATIVE,
1891 .type = V4L2_CTRL_TYPE_INTEGER,
1892 .name = "Focus Control",
1898 .id = V4L2_CID_FOCUS_ABSOLUTE,
1899 .type = V4L2_CTRL_TYPE_INTEGER,
1900 .name = "Focus Control",
1904 .default_value = 125,
1907 .id = V4L2_CID_FOCUS_AUTO,
1908 .type = V4L2_CTRL_TYPE_BOOLEAN,
1909 .name = "Focus Control",
1915 #if 0 //IF CONTINOUS IS SUPPORT, SET TO 1
1917 .id = V4L2_CID_FOCUS_CONTINUOUS,
1918 .type = V4L2_CTRL_TYPE_BOOLEAN,
1919 .name = "Focus Control",
1928 #if CONFIG_SENSOR_Flash
1930 .id = V4L2_CID_FLASH,
1931 .type = V4L2_CTRL_TYPE_MENU,
1932 .name = "Flash Control",
1941 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1942 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1943 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1944 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1945 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1946 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1947 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1948 static int sensor_resume(struct soc_camera_device *icd);
1949 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1950 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1951 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1952 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1953 static int sensor_deactivate(struct i2c_client *client);
1955 static struct soc_camera_ops sensor_ops =
1957 .suspend = sensor_suspend,
1958 .resume = sensor_resume,
1959 .set_bus_param = sensor_set_bus_param,
1960 .query_bus_param = sensor_query_bus_param,
1961 .controls = sensor_controls,
1962 .menus = sensor_menus,
1963 .num_controls = ARRAY_SIZE(sensor_controls),
1964 .num_menus = ARRAY_SIZE(sensor_menus),
1967 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1968 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1969 .colorspace = _colorspace }
1971 #define JPG_FMT(_name, _depth, _fourcc) \
1972 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1974 static const struct soc_camera_data_format sensor_colour_formats[] = {
1975 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1976 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1979 enum sensor_work_state
1981 sensor_work_ready = 0,
1986 struct i2c_client *client;
1987 struct delayed_work dwork;
1988 enum sensor_work_state state;
1991 typedef struct sensor_info_priv_s
2007 unsigned char mirror; /* HFLIP */
2008 unsigned char flip; /* VFLIP */
2009 unsigned int winseqe_cur_addr;
2010 unsigned int pixfmt;
2011 unsigned int enable;
2012 unsigned int funmodule_state;
2013 } sensor_info_priv_t;
2017 struct v4l2_subdev subdev;
2018 struct i2c_client *client;
2019 sensor_info_priv_t info_priv;
2020 struct workqueue_struct *sensor_wq;
2021 struct sensor_work sensor_wk;
2022 struct mutex wq_lock;
2023 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2024 #if CONFIG_SENSOR_I2C_NOSCHED
2025 atomic_t tasklock_cnt;
2027 struct rk29camera_platform_data *sensor_io_request;
2028 struct rk29camera_gpio_res *sensor_gpio_res;
2031 static struct sensor* to_sensor(const struct i2c_client *client)
2033 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2036 static int sensor_task_lock(struct i2c_client *client, int lock)
2038 #if CONFIG_SENSOR_I2C_NOSCHED
2040 struct sensor *sensor = to_sensor(client);
2043 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2044 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2045 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2049 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2050 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2051 goto sensor_task_lock_err;
2056 atomic_add(1, &sensor->tasklock_cnt);
2058 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2059 atomic_sub(1, &sensor->tasklock_cnt);
2061 if (atomic_read(&sensor->tasklock_cnt) == 0)
2066 sensor_task_lock_err:
2074 /* sensor register write */
2075 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2079 struct i2c_msg msg[1];
2082 buf[1] = reg & 0xFF;
2085 msg->addr = client->addr;
2086 msg->flags = client->flags;
2088 msg->len = sizeof(buf);
2089 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2090 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2095 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2096 err = i2c_transfer(client->adapter, msg, 1);
2101 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2109 /* sensor register read */
2110 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2114 struct i2c_msg msg[2];
2117 buf[1] = reg & 0xFF;
2119 msg[0].addr = client->addr;
2120 msg[0].flags = client->flags;
2122 msg[0].len = sizeof(buf);
2123 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2124 msg[0].read_type = 2; /* fpga i2c:2==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2126 msg[1].addr = client->addr;
2127 msg[1].flags = client->flags|I2C_M_RD;
2130 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2131 msg[1].read_type = 2; /* fpga i2c:2==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2135 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2136 err = i2c_transfer(client->adapter, msg, 2);
2142 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2150 /* write a array of registers */
2151 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2155 #if CONFIG_SENSOR_Focus
2156 struct sensor *sensor = to_sensor(client);
2158 #if CONFIG_SENSOR_I2C_RDWRCHK
2163 if (sensor_task_lock(client, 1) < 0)
2164 goto sensor_write_array_end;
2165 while (regarray[i].reg != 0)
2167 #if CONFIG_SENSOR_Focus
2168 if ((regarray == sensor_af_firmware) && (sensor->info_priv.enable == 0)) {
2169 SENSOR_DG("%s disable, Download af firmware terminated!\n",SENSOR_NAME_STRING());
2171 goto sensor_write_array_end;
2175 err = sensor_write(client, regarray[i].reg, regarray[i].val);
2179 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2183 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2186 goto sensor_write_array_end;
2189 #if CONFIG_SENSOR_I2C_RDWRCHK
2190 sensor_read(client, regarray[i].reg, &valchk);
2191 if (valchk != regarray[i].val)
2192 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2198 #if CONFIG_SENSOR_Focus
2199 if (((regarray->reg == SEQUENCE_PROPERTY) && (regarray->val == SEQUENCE_INIT))
2200 || (regarray == sensor_init_data)) {
2201 sensor->info_priv.affm_reinit = 1;
2205 sensor_write_array_end:
2206 sensor_task_lock(client,0);
2209 #if CONFIG_SENSOR_I2C_RDWRCHK
2210 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
2218 while (regarray[i].reg != 0)
2220 sensor_read(client, regarray[i].reg, &valchk);
2221 if (valchk != regarray[i].val)
2222 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2229 #if CONFIG_SENSOR_Focus
2236 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
2239 char read_tag=0xff,cnt;
2242 if (cmdinfo->validate_bit & 0x80) {
2243 if (sensor_write(client, CMD_TAG_Reg, cmdinfo->cmd_tag)) {
2244 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
2245 goto sensor_af_cmdset_err;
2247 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
2249 for (i=0; i<4; i++) {
2250 if (cmdinfo->validate_bit & (1<<i)) {
2251 if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
2252 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]);
2253 goto sensor_af_cmdset_err;
2255 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]);
2259 if (sensor_write(client, CMD_TAG_Reg, 0xff)) {
2260 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
2261 goto sensor_af_cmdset_err;
2263 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
2266 if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
2267 SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
2268 goto sensor_af_cmdset_err;
2275 if (sensor_read(client,CMD_TAG_Reg,&read_tag)){
2276 SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
2279 } while((read_tag != 0x00)&& (cnt++<100));
2281 SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
2283 sensor_af_cmdset_err:
2287 static int sensor_af_idlechk(struct i2c_client *client)
2295 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2297 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2299 goto sensor_af_idlechk_end;
2302 if (state != S_IDLE) {
2303 sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
2307 } while((state != S_IDLE)&& (cnt<100));
2309 ret = (state == S_IDLE) ? 0 : -1;
2311 sensor_af_idlechk_end:
2315 static int sensor_af_single(struct i2c_client *client)
2320 if (sensor_af_idlechk(client))
2321 goto sensor_af_single_end;
2323 if (sensor_af_cmdset(client, SingleFocus_Cmd, NULL)) {
2324 SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
2326 goto sensor_af_single_end;
2336 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2338 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2340 goto sensor_af_single_end;
2342 }while((state == S_FOCUSING) && (cnt<100));
2344 if (state != S_FOCUSED) {
2345 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
2347 goto sensor_af_single_end;
2350 //sensor_af_cmdset(client, ReturnIdle_Cmd, NULL); // by duanyp. fix af blur when taking pictures
2351 sensor_af_single_end:
2355 static int sensor_af_const(struct i2c_client *client)
2359 if (sensor_af_idlechk(client))
2360 goto sensor_af_const_end;
2362 if (sensor_af_cmdset(client, ConstFocus_Cmd, NULL)) {
2363 SENSOR_TR("%s const focus mode set error!\n",SENSOR_NAME_STRING());
2365 goto sensor_af_const_end;
2367 sensor_af_const_end:
2370 static int sensor_af_pause2capture(struct i2c_client *client)
2375 if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
2376 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
2378 goto sensor_af_pause_end;
2388 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2390 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2392 goto sensor_af_pause_end;
2394 }while((state != S_CAPTURE) && (cnt<100));
2396 if (state != S_CAPTURE) {
2397 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
2399 goto sensor_af_pause_end;
2401 sensor_af_pause_end:
2404 static int sensor_af_zoneupdate(struct i2c_client *client)
2408 if (sensor_af_idlechk(client))
2409 goto sensor_af_zoneupdate_end;
2411 if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
2412 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
2414 goto sensor_af_zoneupdate_end;
2417 sensor_af_zoneupdate_end:
2420 static int sensor_af_init(struct i2c_client *client)
2425 ret = sensor_write_array(client, sensor_af_firmware);
2427 SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
2429 goto sensor_af_init_end;
2439 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2441 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2443 goto sensor_af_init_end;
2445 }while((state == S_STARTUP) && (cnt<100));
2447 if (state != S_IDLE) {
2448 SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
2450 goto sensor_af_init_end;
2454 SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
2458 static int sensor_af_wq_function(struct i2c_client *client)
2460 struct sensor *sensor = to_sensor(client);
2461 struct af_cmdinfo cmdinfo;
2462 int ret=0, focus_pos = 0xfe;
2464 SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
2466 mutex_lock(&sensor->wq_lock);
2467 if (sensor_af_init(client)) {
2468 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
2471 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
2473 switch (sensor->info_priv.auto_focus)
2475 case SENSOR_AF_MODE_INFINITY:
2479 case SENSOR_AF_MODE_MACRO:
2481 if (focus_pos != 0x00)
2484 sensor_af_idlechk(client);
2485 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
2486 cmdinfo.cmd_para[0] = focus_pos;
2487 cmdinfo.validate_bit = 0x81;
2488 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
2491 case SENSOR_AF_MODE_AUTO:
2493 ret = sensor_af_single(client);
2496 case SENSOR_AF_MODE_CONTINUOUS:
2498 ret = sensor_af_const(client);
2501 case SENSOR_AF_MODE_CLOSE:
2508 SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
2509 goto sensor_af_wq_function_end;
2513 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);
2516 sensor_af_wq_function_end:
2517 sensor->sensor_wk.state = sensor_work_ready;
2518 mutex_unlock(&sensor->wq_lock);
2521 static void sensor_af_workqueue(struct work_struct *work)
2523 struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
2524 struct i2c_client *client = sensor_work->client;
2526 if (sensor_af_wq_function(client) < 0) {
2527 SENSOR_TR("%s af workqueue return false\n",SENSOR_NAME_STRING());
2532 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
2534 struct soc_camera_link *icl = to_soc_camera_link(icd);
2537 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2541 case Sensor_PowerDown:
2543 if (icl->powerdown) {
2544 ret = icl->powerdown(icd->pdev, on);
2545 if (ret == RK29_CAM_IO_SUCCESS) {
2549 icl->reset(icd->pdev);
2551 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
2553 goto sensor_power_end;
2560 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2561 struct sensor *sensor = to_sensor(client);
2563 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2564 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2570 SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
2578 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2580 struct i2c_client *client = sd->priv;
2581 struct soc_camera_device *icd = client->dev.platform_data;
2582 struct sensor *sensor = to_sensor(client);
2583 const struct v4l2_queryctrl *qctrl;
2587 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2589 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2591 goto sensor_INIT_ERR;
2593 /* ddl@rock-chips.com : ov3640_powerOn have hardware reset */
2596 if (sensor_task_lock(client,1)<0)
2597 goto sensor_INIT_ERR;
2598 ret = sensor_write(client, 0x3012, 0x80);
2601 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2603 goto sensor_INIT_ERR;
2606 mdelay(5); //delay 5 microseconds
2608 /* check if it is an sensor sensor */
2609 ret = sensor_read(client, 0x300a, &value);
2611 SENSOR_TR("read chip id high byte failed\n");
2613 goto sensor_INIT_ERR;
2616 pid |= (value << 8);
2618 ret = sensor_read(client, 0x300b, &value);
2620 SENSOR_TR("read chip id low byte failed\n");
2622 goto sensor_INIT_ERR;
2625 pid |= (value & 0xff);
2626 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2627 if (pid == SENSOR_ID) {
2628 sensor->model = SENSOR_V4L2_IDENT;
2630 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2632 goto sensor_INIT_ERR;
2635 ret = sensor_write_array(client, sensor_init_data);
2638 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2639 goto sensor_INIT_ERR;
2641 sensor_task_lock(client,0);
2642 //icd->user_width = SENSOR_INIT_WIDTH;
2643 //icd->user_height = SENSOR_INIT_HEIGHT;
2644 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2645 sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
2647 /* sensor sensor information for initialization */
2648 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2650 sensor->info_priv.whiteBalance = qctrl->default_value;
2651 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2653 sensor->info_priv.brightness = qctrl->default_value;
2654 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2656 sensor->info_priv.effect = qctrl->default_value;
2657 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2659 sensor->info_priv.exposure = qctrl->default_value;
2661 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2663 sensor->info_priv.saturation = qctrl->default_value;
2664 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2666 sensor->info_priv.contrast = qctrl->default_value;
2667 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2669 sensor->info_priv.mirror = qctrl->default_value;
2670 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2672 sensor->info_priv.flip = qctrl->default_value;
2673 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2675 sensor->info_priv.scene = qctrl->default_value;
2676 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2678 sensor->info_priv.digitalzoom = qctrl->default_value;
2680 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2681 #if CONFIG_SENSOR_Focus
2682 // sensor_set_focus();
2683 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);//?,JYK
2685 sensor->info_priv.focus = qctrl->default_value;
2688 #if CONFIG_SENSOR_Flash
2689 //sensor_set_flash();
2690 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2692 sensor->info_priv.flash = qctrl->default_value;
2695 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);
2699 sensor_task_lock(client,0);
2700 sensor_deactivate(client);
2703 static int sensor_deactivate(struct i2c_client *client)
2705 struct soc_camera_device *icd = client->dev.platform_data;
2707 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2709 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2710 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2711 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2712 icd->user_width = SENSOR_INIT_WIDTH;
2713 icd->user_height = SENSOR_INIT_HEIGHT;
2717 static struct reginfo sensor_power_down_sequence[]=
2726 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2729 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2731 if (pm_msg.event == PM_EVENT_SUSPEND) {
2732 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2733 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2735 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2738 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2740 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2745 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2752 static int sensor_resume(struct soc_camera_device *icd)
2756 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2758 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2762 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2766 static int sensor_set_bus_param(struct soc_camera_device *icd,
2767 unsigned long flags)
2773 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2775 struct soc_camera_link *icl = to_soc_camera_link(icd);
2776 unsigned long flags = SENSOR_BUS_PARAM;
2778 return soc_camera_apply_sensor_flags(icl, flags);
2781 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2783 struct i2c_client *client = sd->priv;
2784 struct soc_camera_device *icd = client->dev.platform_data;
2785 struct sensor *sensor = to_sensor(client);
2786 struct v4l2_pix_format *pix = &f->fmt.pix;
2788 pix->width = icd->user_width;
2789 pix->height = icd->user_height;
2790 pix->pixelformat = sensor->info_priv.pixfmt;
2791 pix->field = V4L2_FIELD_NONE;
2792 pix->colorspace = V4L2_COLORSPACE_JPEG;
2798 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_format *f)
2802 if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
2804 } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
2806 } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
2808 } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
2810 } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
2815 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
2818 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_format *f)
2822 if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 720)) {
2824 } else if ((f->fmt.pix.width == 1920) && (f->fmt.pix.height == 1080)) {
2829 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
2832 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2834 struct i2c_client *client = sd->priv;
2835 struct soc_camera_device *icd = client->dev.platform_data;
2836 struct sensor *sensor = to_sensor(client);
2837 struct v4l2_pix_format *pix = &f->fmt.pix;
2838 const struct v4l2_queryctrl *qctrl;
2839 struct reginfo *winseqe_set_addr=NULL;
2840 int ret=0, set_w,set_h;
2843 if (sensor->info_priv.pixfmt != pix->pixelformat) {
2844 switch (pix->pixelformat)
2846 case V4L2_PIX_FMT_YUYV:
2848 winseqe_set_addr = sensor_ClrFmt_YUYV;
2851 case V4L2_PIX_FMT_UYVY:
2853 winseqe_set_addr = sensor_ClrFmt_UYVY;
2859 if (winseqe_set_addr != NULL) {
2860 sensor_write_array(client, winseqe_set_addr);
2861 sensor->info_priv.pixfmt = pix->pixelformat;
2863 SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
2865 SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
2870 set_h = pix->height;
2871 isCapture = sensor_fmt_capturechk(sd, f);
2873 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[isCapture][0].reg)
2875 winseqe_set_addr = sensor_qcif[isCapture];
2879 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[isCapture][0].reg)
2881 winseqe_set_addr = sensor_qvga[isCapture];
2885 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[isCapture][0].reg)
2887 //printk("===> isCapture: %d!\n", isCapture);
2888 winseqe_set_addr = sensor_cif[isCapture];
2892 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[isCapture][0].reg)
2894 winseqe_set_addr = sensor_vga[isCapture];
2898 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[isCapture][0].reg)
2900 winseqe_set_addr = sensor_svga[isCapture];
2904 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_sxga[isCapture][0].reg)
2906 winseqe_set_addr = sensor_xga[isCapture];
2910 else if (((set_w <= 1280) && (set_h <= 960)) && sensor_sxga[isCapture][0].reg)
2912 winseqe_set_addr = sensor_sxga[isCapture];
2916 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[isCapture][0].reg)
2918 winseqe_set_addr = sensor_uxga[isCapture];
2922 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_uxga[isCapture][0].reg)
2924 winseqe_set_addr = sensor_qxga[isCapture];
2930 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2931 set_w = SENSOR_INIT_WIDTH;
2932 set_h = SENSOR_INIT_HEIGHT;
2933 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
2936 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
2938 //srt --if capture,then should write sensor_qxga[1] first
2940 if((winseqe_set_addr != sensor_qxga[isCapture]) && isCapture)
2942 SENSOR_DG("%s write sensor_qxga[1]\n", SENSOR_NAME_STRING());
2943 ret = sensor_write_array(client, sensor_qxga[isCapture]);
2946 SENSOR_TR("%s write sensor_qxga[1] failed\n", SENSOR_NAME_STRING());
2951 #if CONFIG_SENSOR_Focus
2952 //sensor_af_idlechk(client);
2953 if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS)
2955 sensor_af_idlechk(client); // by duanyp
2956 sensor_af_cmdset(client, PauseFocus_Cmd, NULL);
2960 #if CONFIG_SENSOR_Flash
2961 if (sensor_fmt_capturechk(sd,f) == true) { /* ddl@rock-chips.com : Capture */
2962 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2963 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2964 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2966 } else { /* ddl@rock-chips.com : Video */
2967 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2968 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2969 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2974 ret = sensor_write_array(client, winseqe_set_addr);
2976 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2977 #if CONFIG_SENSOR_Flash
2978 if (sensor_fmt_capturechk(sd,f) == true) {
2979 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2980 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2981 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2985 goto sensor_s_fmt_end;
2987 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2988 if (sensor_fmt_capturechk(sd,f) == true) { /* ddl@rock-chips.com : Capture */
2989 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2990 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2991 if (sensor->info_priv.whiteBalance != 0) {
2992 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2993 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2995 sensor->info_priv.snap2preview = true;
2996 } else if (sensor_fmt_videochk(sd,f) == true) { /* ddl@rock-chips.com : Video */
2997 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2998 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2999 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3000 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3001 sensor->info_priv.video2preview = true;
3002 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
3003 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3004 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
3005 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3006 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3007 sensor->info_priv.video2preview = false;
3008 sensor->info_priv.snap2preview = false;
3010 mdelay(100); // by FAE.
3012 SENSOR_DG("\n%s..%s.. icd->width=%d..icd->height=%d..isCapture=%d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h,isCapture);
3016 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);
3019 //add by duanyp. Improve the green phenomenon when startup camera every time.
3026 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
3028 struct v4l2_pix_format *pix = &f->fmt.pix;
3029 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
3030 pix->pixelformat == V4L2_PIX_FMT_YUYV;
3033 * With Bayer format enforce even side lengths, but let the user play
3034 * with the starting pixel
3037 if (pix->height > SENSOR_MAX_HEIGHT)
3038 pix->height = SENSOR_MAX_HEIGHT;
3039 else if (pix->height < SENSOR_MIN_HEIGHT)
3040 pix->height = SENSOR_MIN_HEIGHT;
3042 pix->height = ALIGN(pix->height, 2);
3044 if (pix->width > SENSOR_MAX_WIDTH)
3045 pix->width = SENSOR_MAX_WIDTH;
3046 else if (pix->width < SENSOR_MIN_WIDTH)
3047 pix->width = SENSOR_MIN_WIDTH;
3049 pix->width = ALIGN(pix->width, 2);
3054 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
3056 struct i2c_client *client = sd->priv;
3058 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
3061 if (id->match.addr != client->addr)
3064 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV3640 identifier */
3069 #if CONFIG_SENSOR_Brightness
3070 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3072 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3074 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3076 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
3078 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
3080 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3083 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3087 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3091 #if CONFIG_SENSOR_Effect
3092 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3094 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3096 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3098 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
3100 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
3102 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3105 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3109 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3113 #if CONFIG_SENSOR_Exposure
3114 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3116 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3118 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3120 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
3122 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
3124 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3127 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3131 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3135 #if CONFIG_SENSOR_Saturation
3136 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3138 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3140 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3142 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
3144 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
3146 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3149 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3153 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3157 #if CONFIG_SENSOR_Contrast
3158 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3160 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3162 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3164 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
3166 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
3168 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3171 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3175 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3179 #if CONFIG_SENSOR_Mirror
3180 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3182 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3184 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3186 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
3188 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
3190 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3193 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3197 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3201 #if CONFIG_SENSOR_Flip
3202 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3204 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3206 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3208 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
3210 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
3212 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3215 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3219 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3223 #if CONFIG_SENSOR_Scene
3224 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3226 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3228 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3230 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
3232 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
3234 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3237 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3241 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3245 #if CONFIG_SENSOR_WhiteBalance
3246 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3248 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3250 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3252 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
3254 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
3256 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3259 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3263 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3267 #if CONFIG_SENSOR_DigitalZoom
3268 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
3270 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3271 struct sensor *sensor = to_sensor(client);
3272 const struct v4l2_queryctrl *qctrl_info;
3273 int digitalzoom_cur, digitalzoom_total;
3275 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
3279 digitalzoom_cur = sensor->info_priv.digitalzoom;
3280 digitalzoom_total = qctrl_info->maximum;
3282 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
3284 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3288 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
3290 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3294 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
3296 *value = digitalzoom_total - digitalzoom_cur;
3299 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
3301 *value = 0 - digitalzoom_cur;
3304 digitalzoom_cur += *value;
3306 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
3308 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
3310 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3313 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
3321 #if CONFIG_SENSOR_Focus
3322 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3324 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3325 struct sensor *sensor = to_sensor(client);
3326 const struct v4l2_queryctrl *qctrl_info;
3327 struct af_cmdinfo cmdinfo;
3330 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
3334 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3335 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
3337 if (sensor_af_idlechk(client))
3338 goto sensor_set_focus_absolute_end;
3340 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3341 cmdinfo.cmd_para[0] = value;
3342 cmdinfo.validate_bit = 0x81;
3343 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3344 //ret |= sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
3345 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3348 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3352 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3353 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3356 sensor_set_focus_absolute_end:
3359 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3361 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3362 struct sensor *sensor = to_sensor(client);
3363 const struct v4l2_queryctrl *qctrl_info;
3364 struct af_cmdinfo cmdinfo;
3367 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
3371 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3372 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
3374 if (sensor_af_idlechk(client))
3375 goto sensor_set_focus_relative_end;
3378 cmdinfo.cmd_tag = StepFocus_Near_Tag;
3379 } else if (value < 0) {
3380 cmdinfo.cmd_tag = StepFocus_Far_Tag;
3382 cmdinfo.validate_bit = 0x80;
3383 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3385 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3388 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3392 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3393 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3395 sensor_set_focus_relative_end:
3399 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3401 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3402 struct sensor *sensor = to_sensor(client);
3405 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3408 case SENSOR_AF_MODE_AUTO:
3410 ret = sensor_af_single(client);
3414 case SENSOR_AF_MODE_MACRO:
3416 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
3420 case SENSOR_AF_MODE_INFINITY:
3422 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
3426 case SENSOR_AF_MODE_CONTINUOUS:
3428 ret = sensor_af_const(client);
3432 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3437 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3440 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3441 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3447 #if CONFIG_SENSOR_Flash
3448 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3450 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3451 if (value == 3) { /* ddl@rock-chips.com: torch */
3452 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
3454 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3456 SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3460 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3464 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3466 struct i2c_client *client = sd->priv;
3467 struct sensor *sensor = to_sensor(client);
3468 const struct v4l2_queryctrl *qctrl;
3470 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3474 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3480 case V4L2_CID_BRIGHTNESS:
3482 ctrl->value = sensor->info_priv.brightness;
3485 case V4L2_CID_SATURATION:
3487 ctrl->value = sensor->info_priv.saturation;
3490 case V4L2_CID_CONTRAST:
3492 ctrl->value = sensor->info_priv.contrast;
3495 case V4L2_CID_DO_WHITE_BALANCE:
3497 ctrl->value = sensor->info_priv.whiteBalance;
3500 case V4L2_CID_EXPOSURE:
3502 ctrl->value = sensor->info_priv.exposure;
3505 case V4L2_CID_HFLIP:
3507 ctrl->value = sensor->info_priv.mirror;
3510 case V4L2_CID_VFLIP:
3512 ctrl->value = sensor->info_priv.flip;
3523 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3525 struct i2c_client *client = sd->priv;
3526 struct sensor *sensor = to_sensor(client);
3527 struct soc_camera_device *icd = client->dev.platform_data;
3528 const struct v4l2_queryctrl *qctrl;
3531 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3535 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3541 #if CONFIG_SENSOR_Brightness
3542 case V4L2_CID_BRIGHTNESS:
3544 if (ctrl->value != sensor->info_priv.brightness)
3546 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3550 sensor->info_priv.brightness = ctrl->value;
3555 #if CONFIG_SENSOR_Exposure
3556 case V4L2_CID_EXPOSURE:
3558 if (ctrl->value != sensor->info_priv.exposure)
3560 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3564 sensor->info_priv.exposure = ctrl->value;
3569 #if CONFIG_SENSOR_Saturation
3570 case V4L2_CID_SATURATION:
3572 if (ctrl->value != sensor->info_priv.saturation)
3574 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3578 sensor->info_priv.saturation = ctrl->value;
3583 #if CONFIG_SENSOR_Contrast
3584 case V4L2_CID_CONTRAST:
3586 if (ctrl->value != sensor->info_priv.contrast)
3588 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3592 sensor->info_priv.contrast = ctrl->value;
3597 #if CONFIG_SENSOR_WhiteBalance
3598 case V4L2_CID_DO_WHITE_BALANCE:
3600 if (ctrl->value != sensor->info_priv.whiteBalance)
3602 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3606 sensor->info_priv.whiteBalance = ctrl->value;
3611 #if CONFIG_SENSOR_Mirror
3612 case V4L2_CID_HFLIP:
3614 if (ctrl->value != sensor->info_priv.mirror)
3616 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3618 sensor->info_priv.mirror = ctrl->value;
3623 #if CONFIG_SENSOR_Flip
3624 case V4L2_CID_VFLIP:
3626 if (ctrl->value != sensor->info_priv.flip)
3628 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3630 sensor->info_priv.flip = ctrl->value;
3641 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3643 const struct v4l2_queryctrl *qctrl;
3644 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3645 struct sensor *sensor = to_sensor(client);
3647 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3651 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3655 switch (ext_ctrl->id)
3657 case V4L2_CID_SCENE:
3659 ext_ctrl->value = sensor->info_priv.scene;
3662 case V4L2_CID_EFFECT:
3664 ext_ctrl->value = sensor->info_priv.effect;
3667 case V4L2_CID_ZOOM_ABSOLUTE:
3669 ext_ctrl->value = sensor->info_priv.digitalzoom;
3672 case V4L2_CID_ZOOM_RELATIVE:
3676 case V4L2_CID_FOCUS_ABSOLUTE:
3678 ext_ctrl->value = sensor->info_priv.focus;
3681 case V4L2_CID_FOCUS_RELATIVE:
3685 case V4L2_CID_FLASH:
3687 ext_ctrl->value = sensor->info_priv.flash;
3695 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3697 const struct v4l2_queryctrl *qctrl;
3698 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3699 struct sensor *sensor = to_sensor(client);
3702 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3706 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3711 switch (ext_ctrl->id)
3713 #if CONFIG_SENSOR_Scene
3714 case V4L2_CID_SCENE:
3716 if (ext_ctrl->value != sensor->info_priv.scene)
3718 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3720 sensor->info_priv.scene = ext_ctrl->value;
3725 #if CONFIG_SENSOR_Effect
3726 case V4L2_CID_EFFECT:
3728 if (ext_ctrl->value != sensor->info_priv.effect)
3730 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3732 sensor->info_priv.effect= ext_ctrl->value;
3737 #if CONFIG_SENSOR_DigitalZoom
3738 case V4L2_CID_ZOOM_ABSOLUTE:
3740 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3743 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3745 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3747 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3749 sensor->info_priv.digitalzoom += val_offset;
3751 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3756 case V4L2_CID_ZOOM_RELATIVE:
3758 if (ext_ctrl->value)
3760 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3762 sensor->info_priv.digitalzoom += ext_ctrl->value;
3764 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3769 #if CONFIG_SENSOR_Focus
3770 case V4L2_CID_FOCUS_ABSOLUTE:
3772 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3775 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
3776 if (ext_ctrl->value == qctrl->minimum) {
3777 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
3778 } else if (ext_ctrl->value == qctrl->maximum) {
3779 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
3781 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
3787 case V4L2_CID_FOCUS_RELATIVE:
3789 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3792 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
3795 case V4L2_CID_FOCUS_AUTO:
3797 if (ext_ctrl->value == 1) {
3798 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
3800 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
3801 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
3802 if (ext_ctrl->value == 0)
3803 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3808 case V4L2_CID_FOCUS_CONTINUOUS:
3810 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
3811 if (ext_ctrl->value == 1) {
3812 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
3814 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
3817 if (ext_ctrl->value == 0)
3818 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3823 #if CONFIG_SENSOR_Flash
3824 case V4L2_CID_FLASH:
3826 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3828 sensor->info_priv.flash = ext_ctrl->value;
3830 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3841 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3843 struct i2c_client *client = sd->priv;
3844 struct soc_camera_device *icd = client->dev.platform_data;
3845 int i, error_cnt=0, error_idx=-1;
3848 for (i=0; i<ext_ctrl->count; i++) {
3849 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3856 error_idx = ext_ctrl->count;
3858 if (error_idx != -1) {
3859 ext_ctrl->error_idx = error_idx;
3866 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3868 struct i2c_client *client = sd->priv;
3869 struct soc_camera_device *icd = client->dev.platform_data;
3870 int i, error_cnt=0, error_idx=-1;
3873 for (i=0; i<ext_ctrl->count; i++) {
3874 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3881 error_idx = ext_ctrl->count;
3883 if (error_idx != -1) {
3884 ext_ctrl->error_idx = error_idx;
3891 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
3893 struct i2c_client *client = sd->priv;
3894 struct sensor *sensor = to_sensor(client);
3895 #if CONFIG_SENSOR_Focus
3896 struct soc_camera_device *icd = client->dev.platform_data;
3897 struct v4l2_format fmt;
3901 sensor->info_priv.enable = 1;
3902 #if CONFIG_SENSOR_Focus
3903 fmt.fmt.pix.width = icd->user_width;
3904 fmt.fmt.pix.height = icd->user_height;
3905 /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
3906 if (sensor_fmt_capturechk(sd, &fmt) == false) {
3907 if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {
3908 if (sensor->sensor_wq != NULL) {
3909 mutex_lock(&sensor->wq_lock);
3910 if (sensor->sensor_wk.state == sensor_working) {
3911 SENSOR_DG("%s sensor af firmware thread is runing, Ingore current work",SENSOR_NAME_STRING());
3912 mutex_unlock(&sensor->wq_lock);
3913 goto sensor_s_stream_end;
3915 sensor->sensor_wk.state = sensor_working;
3916 mutex_unlock(&sensor->wq_lock);
3917 sensor->sensor_wk.client = client;
3918 INIT_WORK(&(sensor->sensor_wk.dwork.work), sensor_af_workqueue);
3919 queue_delayed_work(sensor->sensor_wq,&(sensor->sensor_wk.dwork), 0);
3921 sensor->info_priv.affm_reinit = 0;
3925 } else if (enable == 0) {
3926 sensor->info_priv.enable = 0;
3927 #if CONFIG_SENSOR_Focus
3928 flush_work(&(sensor->sensor_wk.dwork.work));
3929 mutex_lock(&sensor->wq_lock);
3930 sensor->sensor_wk.state = sensor_work_ready;
3931 mutex_unlock(&sensor->wq_lock);
3935 sensor_s_stream_end:
3939 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3940 * this wasn't our capture interface, so, we wait for the right one */
3941 static int sensor_video_probe(struct soc_camera_device *icd,
3942 struct i2c_client *client)
3946 struct sensor *sensor = to_sensor(client);
3948 /* We must have a parent by now. And it cannot be a wrong one.
3949 * So this entire test is completely redundant. */
3950 if (!icd->dev.parent ||
3951 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3954 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3956 goto sensor_video_probe_err;
3959 ret = sensor_write(client, 0x3012, 0x80);
3961 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3963 goto sensor_video_probe_err;
3965 mdelay(5); //delay 5 microseconds
3967 /* check if it is an sensor sensor */
3968 ret = sensor_read(client, 0x300a, &value);
3970 SENSOR_TR("read chip id high byte failed\n");
3972 goto sensor_video_probe_err;
3975 pid |= (value << 8);
3977 ret = sensor_read(client, 0x300b, &value);
3979 SENSOR_TR("read chip id low byte failed\n");
3981 goto sensor_video_probe_err;
3984 pid |= (value & 0xff);
3985 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3986 if (pid == SENSOR_ID) {
3987 sensor->model = SENSOR_V4L2_IDENT;
3989 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3991 goto sensor_video_probe_err;
3994 icd->formats = sensor_colour_formats;
3995 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
3999 sensor_video_probe_err:
4002 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
4004 struct i2c_client *client = sd->priv;
4005 struct soc_camera_device *icd = client->dev.platform_data;
4006 struct sensor *sensor = to_sensor(client);
4009 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4012 case RK29_CAM_SUBDEV_DEACTIVATE:
4014 sensor_deactivate(client);
4017 case RK29_CAM_SUBDEV_IOREQUEST:
4019 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
4020 if (sensor->sensor_io_request != NULL) {
4021 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
4022 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
4023 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
4024 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
4025 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
4026 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
4029 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
4031 goto sensor_ioctl_end;
4033 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
4035 #if CONFIG_SENSOR_Flash
4036 if (sensor->sensor_gpio_res) {
4037 printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
4038 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
4039 for (i = 0; i < icd->ops->num_controls; i++) {
4040 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
4041 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
4044 sensor->info_priv.flash = 0xff;
4045 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
4053 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4063 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
4064 .init = sensor_init,
4065 .g_ctrl = sensor_g_control,
4066 .s_ctrl = sensor_s_control,
4067 .g_ext_ctrls = sensor_g_ext_controls,
4068 .s_ext_ctrls = sensor_s_ext_controls,
4069 .g_chip_ident = sensor_g_chip_ident,
4070 .ioctl = sensor_ioctl,
4073 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
4074 .s_fmt = sensor_s_fmt,
4075 .g_fmt = sensor_g_fmt,
4076 .try_fmt = sensor_try_fmt,
4077 .s_stream = sensor_s_stream,
4080 static struct v4l2_subdev_ops sensor_subdev_ops = {
4081 .core = &sensor_subdev_core_ops,
4082 .video = &sensor_subdev_video_ops,
4085 static int sensor_probe(struct i2c_client *client,
4086 const struct i2c_device_id *did)
4088 struct sensor *sensor;
4089 struct soc_camera_device *icd = client->dev.platform_data;
4090 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
4091 struct soc_camera_link *icl;
4094 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
4096 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
4100 icl = to_soc_camera_link(icd);
4102 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
4106 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
4107 dev_warn(&adapter->dev,
4108 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
4112 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
4116 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
4118 /* Second stage probe - when a capture adapter is there */
4119 icd->ops = &sensor_ops;
4120 icd->y_skip_top = 0;
4121 #if CONFIG_SENSOR_I2C_NOSCHED
4122 atomic_set(&sensor->tasklock_cnt,0);
4125 ret = sensor_video_probe(icd, client);
4128 i2c_set_clientdata(client, NULL);
4132 #if CONFIG_SENSOR_Focus
4133 sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING( wq));
4134 if (sensor->sensor_wq == NULL)
4135 SENSOR_TR("%s workqueue create fail!", SENSOR_NAME_STRING( wq));
4136 mutex_init(&sensor->wq_lock);
4137 sensor->sensor_wk.state = sensor_work_ready;
4140 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
4144 static int sensor_remove(struct i2c_client *client)
4146 struct sensor *sensor = to_sensor(client);
4147 struct soc_camera_device *icd = client->dev.platform_data;
4149 #if CONFIG_SENSOR_Focus
4150 if (sensor->sensor_wq) {
4151 destroy_workqueue(sensor->sensor_wq);
4152 sensor->sensor_wq = NULL;
4157 i2c_set_clientdata(client, NULL);
4158 client->driver = NULL;
4164 static const struct i2c_device_id sensor_id[] = {
4165 {SENSOR_NAME_STRING(), 0 },
4168 MODULE_DEVICE_TABLE(i2c, sensor_id);
4170 static struct i2c_driver sensor_i2c_driver = {
4172 .name = SENSOR_NAME_STRING(),
4174 .probe = sensor_probe,
4175 .remove = sensor_remove,
4176 .id_table = sensor_id,
4179 static int __init sensor_mod_init(void)
4181 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4182 return i2c_add_driver(&sensor_i2c_driver);
4185 static void __exit sensor_mod_exit(void)
4187 i2c_del_driver(&sensor_i2c_driver);
4190 device_initcall_sync(sensor_mod_init);
4191 module_exit(sensor_mod_exit);
4193 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
4194 MODULE_AUTHOR("ddl <kernel@rock-chips>");
4195 MODULE_LICENSE("GPL");