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(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_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_MBUS_FMT_YUYV8_2X8
58 #define CONFIG_SENSOR_WhiteBalance 1
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 1
63 #define CONFIG_SENSOR_Scene 1
64 #define CONFIG_SENSOR_DigitalZoom 0
65 #define CONFIG_SENSOR_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 /* only one fixed colorspace per pixelcode */
1968 struct sensor_datafmt {
1969 enum v4l2_mbus_pixelcode code;
1970 enum v4l2_colorspace colorspace;
1973 /* Find a data format by a pixel code in an array */
1974 static const struct sensor_datafmt *sensor_find_datafmt(
1975 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1979 for (i = 0; i < n; i++)
1980 if (fmt[i].code == code)
1986 static const struct sensor_datafmt sensor_colour_fmts[] = {
1987 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1988 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1990 enum sensor_work_state
1992 sensor_work_ready = 0,
1997 struct i2c_client *client;
1998 struct delayed_work dwork;
1999 enum sensor_work_state state;
2002 typedef struct sensor_info_priv_s
2018 unsigned char mirror; /* HFLIP */
2019 unsigned char flip; /* VFLIP */
2020 unsigned int winseqe_cur_addr;
2021 struct sensor_datafmt fmt;
2022 unsigned int enable;
2023 unsigned int funmodule_state;
2024 } sensor_info_priv_t;
2028 struct v4l2_subdev subdev;
2029 struct i2c_client *client;
2030 sensor_info_priv_t info_priv;
2031 struct workqueue_struct *sensor_wq;
2032 struct sensor_work sensor_wk;
2033 struct mutex wq_lock;
2034 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2035 #if CONFIG_SENSOR_I2C_NOSCHED
2036 atomic_t tasklock_cnt;
2038 struct rk29camera_platform_data *sensor_io_request;
2039 struct rk29camera_gpio_res *sensor_gpio_res;
2042 static struct sensor* to_sensor(const struct i2c_client *client)
2044 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2047 static int sensor_task_lock(struct i2c_client *client, int lock)
2049 #if CONFIG_SENSOR_I2C_NOSCHED
2051 struct sensor *sensor = to_sensor(client);
2054 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2055 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2056 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2060 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2061 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2062 goto sensor_task_lock_err;
2067 atomic_add(1, &sensor->tasklock_cnt);
2069 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2070 atomic_sub(1, &sensor->tasklock_cnt);
2072 if (atomic_read(&sensor->tasklock_cnt) == 0)
2077 sensor_task_lock_err:
2085 /* sensor register write */
2086 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2090 struct i2c_msg msg[1];
2093 buf[1] = reg & 0xFF;
2096 msg->addr = client->addr;
2097 msg->flags = client->flags;
2099 msg->len = sizeof(buf);
2100 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2101 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : 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, 1);
2112 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2120 /* sensor register read */
2121 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2125 struct i2c_msg msg[2];
2128 buf[1] = reg & 0xFF;
2130 msg[0].addr = client->addr;
2131 msg[0].flags = client->flags;
2133 msg[0].len = sizeof(buf);
2134 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2135 msg[0].read_type = 2; /* fpga i2c:2==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2137 msg[1].addr = client->addr;
2138 msg[1].flags = client->flags|I2C_M_RD;
2141 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
2142 msg[1].read_type = 2; /* fpga i2c:2==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2146 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
2147 err = i2c_transfer(client->adapter, msg, 2);
2153 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2161 /* write a array of registers */
2162 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2166 #if CONFIG_SENSOR_Focus
2167 struct sensor *sensor = to_sensor(client);
2169 #if CONFIG_SENSOR_I2C_RDWRCHK
2174 if (sensor_task_lock(client, 1) < 0)
2175 goto sensor_write_array_end;
2176 while (regarray[i].reg != 0)
2178 #if CONFIG_SENSOR_Focus
2179 if ((regarray == sensor_af_firmware) && (sensor->info_priv.enable == 0)) {
2180 SENSOR_DG("%s disable, Download af firmware terminated!\n",SENSOR_NAME_STRING());
2182 goto sensor_write_array_end;
2186 err = sensor_write(client, regarray[i].reg, regarray[i].val);
2190 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2194 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2197 goto sensor_write_array_end;
2200 #if CONFIG_SENSOR_I2C_RDWRCHK
2201 sensor_read(client, regarray[i].reg, &valchk);
2202 if (valchk != regarray[i].val)
2203 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2209 #if CONFIG_SENSOR_Focus
2210 if (((regarray->reg == SEQUENCE_PROPERTY) && (regarray->val == SEQUENCE_INIT))
2211 || (regarray == sensor_init_data)) {
2212 sensor->info_priv.affm_reinit = 1;
2216 sensor_write_array_end:
2217 sensor_task_lock(client,0);
2220 #if CONFIG_SENSOR_I2C_RDWRCHK
2221 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
2229 while (regarray[i].reg != 0)
2231 sensor_read(client, regarray[i].reg, &valchk);
2232 if (valchk != regarray[i].val)
2233 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2240 #if CONFIG_SENSOR_Focus
2247 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
2250 char read_tag=0xff,cnt;
2253 if (cmdinfo->validate_bit & 0x80) {
2254 if (sensor_write(client, CMD_TAG_Reg, cmdinfo->cmd_tag)) {
2255 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
2256 goto sensor_af_cmdset_err;
2258 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
2260 for (i=0; i<4; i++) {
2261 if (cmdinfo->validate_bit & (1<<i)) {
2262 if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
2263 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]);
2264 goto sensor_af_cmdset_err;
2266 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]);
2270 if (sensor_write(client, CMD_TAG_Reg, 0xff)) {
2271 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
2272 goto sensor_af_cmdset_err;
2274 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
2277 if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
2278 SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
2279 goto sensor_af_cmdset_err;
2286 if (sensor_read(client,CMD_TAG_Reg,&read_tag)){
2287 SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
2290 } while((read_tag != 0x00)&& (cnt++<100));
2292 SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
2294 sensor_af_cmdset_err:
2298 static int sensor_af_idlechk(struct i2c_client *client)
2306 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2308 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2310 goto sensor_af_idlechk_end;
2313 if (state != S_IDLE) {
2314 sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
2318 } while((state != S_IDLE)&& (cnt<100));
2320 ret = (state == S_IDLE) ? 0 : -1;
2322 sensor_af_idlechk_end:
2326 static int sensor_af_single(struct i2c_client *client)
2331 if (sensor_af_idlechk(client))
2332 goto sensor_af_single_end;
2334 if (sensor_af_cmdset(client, SingleFocus_Cmd, NULL)) {
2335 SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
2337 goto sensor_af_single_end;
2347 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2349 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2351 goto sensor_af_single_end;
2353 }while((state == S_FOCUSING) && (cnt<100));
2355 if (state != S_FOCUSED) {
2356 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
2358 goto sensor_af_single_end;
2361 //sensor_af_cmdset(client, ReturnIdle_Cmd, NULL); // by duanyp. fix af blur when taking pictures
2362 sensor_af_single_end:
2366 static int sensor_af_const(struct i2c_client *client)
2370 if (sensor_af_idlechk(client))
2371 goto sensor_af_const_end;
2373 if (sensor_af_cmdset(client, ConstFocus_Cmd, NULL)) {
2374 SENSOR_TR("%s const focus mode set error!\n",SENSOR_NAME_STRING());
2376 goto sensor_af_const_end;
2378 sensor_af_const_end:
2381 static int sensor_af_pause2capture(struct i2c_client *client)
2386 if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
2387 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
2389 goto sensor_af_pause_end;
2399 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2401 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2403 goto sensor_af_pause_end;
2405 }while((state != S_CAPTURE) && (cnt<100));
2407 if (state != S_CAPTURE) {
2408 SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
2410 goto sensor_af_pause_end;
2412 sensor_af_pause_end:
2415 static int sensor_af_zoneupdate(struct i2c_client *client)
2419 if (sensor_af_idlechk(client))
2420 goto sensor_af_zoneupdate_end;
2422 if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
2423 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
2425 goto sensor_af_zoneupdate_end;
2428 sensor_af_zoneupdate_end:
2431 static int sensor_af_init(struct i2c_client *client)
2436 ret = sensor_write_array(client, sensor_af_firmware);
2438 SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
2440 goto sensor_af_init_end;
2450 ret = sensor_read(client, STA_FOCUS_Reg, &state);
2452 SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
2454 goto sensor_af_init_end;
2456 }while((state == S_STARTUP) && (cnt<100));
2458 if (state != S_IDLE) {
2459 SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
2461 goto sensor_af_init_end;
2465 SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
2469 static int sensor_af_wq_function(struct i2c_client *client)
2471 struct sensor *sensor = to_sensor(client);
2472 struct af_cmdinfo cmdinfo;
2473 int ret=0, focus_pos = 0xfe;
2475 SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
2477 mutex_lock(&sensor->wq_lock);
2478 if (sensor_af_init(client)) {
2479 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
2482 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
2484 switch (sensor->info_priv.auto_focus)
2486 case SENSOR_AF_MODE_INFINITY:
2490 case SENSOR_AF_MODE_MACRO:
2492 if (focus_pos != 0x00)
2495 sensor_af_idlechk(client);
2496 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
2497 cmdinfo.cmd_para[0] = focus_pos;
2498 cmdinfo.validate_bit = 0x81;
2499 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
2502 case SENSOR_AF_MODE_AUTO:
2504 ret = sensor_af_single(client);
2507 case SENSOR_AF_MODE_CONTINUOUS:
2509 ret = sensor_af_const(client);
2512 case SENSOR_AF_MODE_CLOSE:
2519 SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
2520 goto sensor_af_wq_function_end;
2524 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);
2527 sensor_af_wq_function_end:
2528 sensor->sensor_wk.state = sensor_work_ready;
2529 mutex_unlock(&sensor->wq_lock);
2532 static void sensor_af_workqueue(struct work_struct *work)
2534 struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
2535 struct i2c_client *client = sensor_work->client;
2537 if (sensor_af_wq_function(client) < 0) {
2538 SENSOR_TR("%s af workqueue return false\n",SENSOR_NAME_STRING());
2543 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
2545 struct soc_camera_link *icl = to_soc_camera_link(icd);
2548 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2552 case Sensor_PowerDown:
2554 if (icl->powerdown) {
2555 ret = icl->powerdown(icd->pdev, on);
2556 if (ret == RK29_CAM_IO_SUCCESS) {
2560 icl->reset(icd->pdev);
2562 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
2564 goto sensor_power_end;
2571 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2572 struct sensor *sensor = to_sensor(client);
2574 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2575 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2581 SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
2589 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2591 struct i2c_client *client = sd->priv;
2592 struct soc_camera_device *icd = client->dev.platform_data;
2593 struct sensor *sensor = to_sensor(client);
2594 const struct v4l2_queryctrl *qctrl;
2595 const struct sensor_datafmt *fmt;
2599 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2601 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2603 goto sensor_INIT_ERR;
2605 /* ddl@rock-chips.com : ov3640_powerOn have hardware reset */
2608 if (sensor_task_lock(client,1)<0)
2609 goto sensor_INIT_ERR;
2610 ret = sensor_write(client, 0x3012, 0x80);
2613 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2615 goto sensor_INIT_ERR;
2618 mdelay(5); //delay 5 microseconds
2620 /* check if it is an sensor sensor */
2621 ret = sensor_read(client, 0x300a, &value);
2623 SENSOR_TR("read chip id high byte failed\n");
2625 goto sensor_INIT_ERR;
2628 pid |= (value << 8);
2630 ret = sensor_read(client, 0x300b, &value);
2632 SENSOR_TR("read chip id low byte failed\n");
2634 goto sensor_INIT_ERR;
2637 pid |= (value & 0xff);
2638 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2639 if (pid == SENSOR_ID) {
2640 sensor->model = SENSOR_V4L2_IDENT;
2642 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2644 goto sensor_INIT_ERR;
2647 ret = sensor_write_array(client, sensor_init_data);
2650 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2651 goto sensor_INIT_ERR;
2653 sensor_task_lock(client,0);
2655 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
2656 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2658 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2660 goto sensor_INIT_ERR;
2662 sensor->info_priv.fmt = *fmt;
2664 /* sensor sensor information for initialization */
2665 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2667 sensor->info_priv.whiteBalance = qctrl->default_value;
2668 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2670 sensor->info_priv.brightness = qctrl->default_value;
2671 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2673 sensor->info_priv.effect = qctrl->default_value;
2674 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2676 sensor->info_priv.exposure = qctrl->default_value;
2678 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2680 sensor->info_priv.saturation = qctrl->default_value;
2681 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2683 sensor->info_priv.contrast = qctrl->default_value;
2684 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2686 sensor->info_priv.mirror = qctrl->default_value;
2687 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2689 sensor->info_priv.flip = qctrl->default_value;
2690 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2692 sensor->info_priv.scene = qctrl->default_value;
2693 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2695 sensor->info_priv.digitalzoom = qctrl->default_value;
2697 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
2698 #if CONFIG_SENSOR_Focus
2699 // sensor_set_focus();
2700 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);//?,JYK
2702 sensor->info_priv.focus = qctrl->default_value;
2705 #if CONFIG_SENSOR_Flash
2706 //sensor_set_flash();
2707 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2709 sensor->info_priv.flash = qctrl->default_value;
2712 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);
2716 sensor_task_lock(client,0);
2717 sensor_deactivate(client);
2720 static int sensor_deactivate(struct i2c_client *client)
2722 struct soc_camera_device *icd = client->dev.platform_data;
2724 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2726 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2727 sensor_ioctrl(icd, Sensor_PowerDown, 1);
2728 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2729 icd->user_width = SENSOR_INIT_WIDTH;
2730 icd->user_height = SENSOR_INIT_HEIGHT;
2734 static struct reginfo sensor_power_down_sequence[]=
2743 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2746 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2748 if (pm_msg.event == PM_EVENT_SUSPEND) {
2749 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2750 ret = sensor_write_array(client, sensor_power_down_sequence) ;
2752 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2755 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2757 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2762 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2769 static int sensor_resume(struct soc_camera_device *icd)
2773 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2775 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2779 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2783 static int sensor_set_bus_param(struct soc_camera_device *icd,
2784 unsigned long flags)
2790 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2792 struct soc_camera_link *icl = to_soc_camera_link(icd);
2793 unsigned long flags = SENSOR_BUS_PARAM;
2795 return soc_camera_apply_sensor_flags(icl, flags);
2798 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2800 struct i2c_client *client = sd->priv;
2801 struct soc_camera_device *icd = client->dev.platform_data;
2802 struct sensor *sensor = to_sensor(client);
2804 mf->width = icd->user_width;
2805 mf->height = icd->user_height;
2806 mf->code = sensor->info_priv.fmt.code;
2807 mf->colorspace = sensor->info_priv.fmt.colorspace;
2808 mf->field = V4L2_FIELD_NONE;
2812 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2816 if ((mf->width == 1024) && (mf->height == 768)) {
2818 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2820 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2822 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2824 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2829 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2833 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2837 if ((mf->width == 1280) && (mf->height == 720)) {
2839 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2844 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2847 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2849 struct i2c_client *client = sd->priv;
2850 const struct sensor_datafmt *fmt;
2851 struct soc_camera_device *icd = client->dev.platform_data;
2852 struct sensor *sensor = to_sensor(client);
2853 const struct v4l2_queryctrl *qctrl;
2854 struct reginfo *winseqe_set_addr=NULL;
2855 int ret=0, set_w,set_h;
2858 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2859 ARRAY_SIZE(sensor_colour_fmts));
2862 goto sensor_s_fmt_end;
2865 if (sensor->info_priv.fmt.code != mf->code) {
2868 case V4L2_MBUS_FMT_YUYV8_2X8:
2870 winseqe_set_addr = sensor_ClrFmt_YUYV;
2873 case V4L2_MBUS_FMT_UYVY8_2X8:
2875 winseqe_set_addr = sensor_ClrFmt_UYVY;
2881 if (winseqe_set_addr != NULL) {
2882 sensor_write_array(client, winseqe_set_addr);
2883 sensor->info_priv.fmt.code = mf->code;
2884 sensor->info_priv.fmt.colorspace= mf->colorspace;
2885 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2887 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2893 isCapture = sensor_fmt_capturechk(sd, mf);
2895 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[isCapture][0].reg)
2897 winseqe_set_addr = sensor_qcif[isCapture];
2901 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[isCapture][0].reg)
2903 winseqe_set_addr = sensor_qvga[isCapture];
2907 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[isCapture][0].reg)
2909 winseqe_set_addr = sensor_cif[isCapture];
2913 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[isCapture][0].reg)
2915 winseqe_set_addr = sensor_vga[isCapture];
2919 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[isCapture][0].reg)
2921 winseqe_set_addr = sensor_svga[isCapture];
2925 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_sxga[isCapture][0].reg)
2927 winseqe_set_addr = sensor_xga[isCapture];
2931 else if (((set_w <= 1280) && (set_h <= 960)) && sensor_sxga[isCapture][0].reg)
2933 winseqe_set_addr = sensor_sxga[isCapture];
2937 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[isCapture][0].reg)
2939 winseqe_set_addr = sensor_uxga[isCapture];
2943 else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_uxga[isCapture][0].reg)
2945 winseqe_set_addr = sensor_qxga[isCapture];
2951 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2952 set_w = SENSOR_INIT_WIDTH;
2953 set_h = SENSOR_INIT_HEIGHT;
2954 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2957 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr){
2958 //srt --if capture,then should write sensor_qxga[1] first
2959 if((winseqe_set_addr != sensor_qxga[isCapture]) && isCapture) {
2960 SENSOR_DG("%s write sensor_qxga[1]\n", SENSOR_NAME_STRING());
2961 ret = sensor_write_array(client, sensor_qxga[isCapture]);
2963 SENSOR_TR("%s write sensor_qxga[1] failed\n", SENSOR_NAME_STRING());
2968 #if CONFIG_SENSOR_Focus
2969 //sensor_af_idlechk(client);
2970 if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS)
2972 sensor_af_idlechk(client); // by duanyp
2973 sensor_af_cmdset(client, PauseFocus_Cmd, NULL);
2977 #if CONFIG_SENSOR_Flash
2978 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2979 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2980 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2981 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2983 } else { /* ddl@rock-chips.com : Video */
2984 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2985 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2986 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2991 ret = sensor_write_array(client, winseqe_set_addr);
2993 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2994 #if CONFIG_SENSOR_Flash
2995 if (sensor_fmt_capturechk(sd,mf) == true) {
2996 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2997 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2998 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
3002 goto sensor_s_fmt_end;
3004 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
3005 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
3006 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3007 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
3008 if (sensor->info_priv.whiteBalance != 0) {
3009 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3010 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3012 sensor->info_priv.snap2preview = true;
3013 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
3014 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3015 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
3016 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3017 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3018 sensor->info_priv.video2preview = true;
3019 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
3020 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3021 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
3022 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3023 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
3024 sensor->info_priv.video2preview = false;
3025 sensor->info_priv.snap2preview = false;
3027 mdelay(100); // by FAE.
3029 SENSOR_DG("\n%s..%s.. icd->width=%d..icd->height=%d..isCapture=%d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h,isCapture);
3031 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);
3039 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
3041 struct i2c_client *client = sd->priv;
3042 struct sensor *sensor = to_sensor(client);
3043 const struct sensor_datafmt *fmt;
3046 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
3047 ARRAY_SIZE(sensor_colour_fmts));
3049 fmt = &sensor->info_priv.fmt;
3050 mf->code = fmt->code;
3053 if (mf->height > SENSOR_MAX_HEIGHT)
3054 mf->height = SENSOR_MAX_HEIGHT;
3055 else if (mf->height < SENSOR_MIN_HEIGHT)
3056 mf->height = SENSOR_MIN_HEIGHT;
3058 if (mf->width > SENSOR_MAX_WIDTH)
3059 mf->width = SENSOR_MAX_WIDTH;
3060 else if (mf->width < SENSOR_MIN_WIDTH)
3061 mf->width = SENSOR_MIN_WIDTH;
3063 mf->colorspace = fmt->colorspace;
3068 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
3070 struct i2c_client *client = sd->priv;
3072 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
3075 if (id->match.addr != client->addr)
3078 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV3640 identifier */
3083 #if CONFIG_SENSOR_Brightness
3084 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3086 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3088 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3090 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
3092 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
3094 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3097 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3101 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3105 #if CONFIG_SENSOR_Effect
3106 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3108 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3110 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3112 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
3114 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
3116 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3119 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3123 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3127 #if CONFIG_SENSOR_Exposure
3128 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3130 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3132 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3134 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
3136 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
3138 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3141 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3145 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3149 #if CONFIG_SENSOR_Saturation
3150 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3152 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3154 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3156 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
3158 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
3160 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3163 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3167 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3171 #if CONFIG_SENSOR_Contrast
3172 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3174 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3176 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3178 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
3180 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
3182 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3185 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3189 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3193 #if CONFIG_SENSOR_Mirror
3194 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3196 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3198 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3200 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
3202 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
3204 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3207 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3211 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3215 #if CONFIG_SENSOR_Flip
3216 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3218 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3220 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3222 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
3224 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
3226 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3229 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3233 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3237 #if CONFIG_SENSOR_Scene
3238 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3240 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3242 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3244 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
3246 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
3248 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3251 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3255 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3259 #if CONFIG_SENSOR_WhiteBalance
3260 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3262 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3264 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3266 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
3268 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
3270 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3273 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3277 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3281 #if CONFIG_SENSOR_DigitalZoom
3282 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
3284 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3285 struct sensor *sensor = to_sensor(client);
3286 const struct v4l2_queryctrl *qctrl_info;
3287 int digitalzoom_cur, digitalzoom_total;
3289 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
3293 digitalzoom_cur = sensor->info_priv.digitalzoom;
3294 digitalzoom_total = qctrl_info->maximum;
3296 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
3298 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3302 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
3304 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3308 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
3310 *value = digitalzoom_total - digitalzoom_cur;
3313 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
3315 *value = 0 - digitalzoom_cur;
3318 digitalzoom_cur += *value;
3320 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
3322 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
3324 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3327 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
3335 #if CONFIG_SENSOR_Focus
3336 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3338 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3339 struct sensor *sensor = to_sensor(client);
3340 const struct v4l2_queryctrl *qctrl_info;
3341 struct af_cmdinfo cmdinfo;
3344 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
3348 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3349 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
3351 if (sensor_af_idlechk(client))
3352 goto sensor_set_focus_absolute_end;
3354 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3355 cmdinfo.cmd_para[0] = value;
3356 cmdinfo.validate_bit = 0x81;
3357 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3358 //ret |= sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
3359 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3362 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3366 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3367 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3370 sensor_set_focus_absolute_end:
3373 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3375 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3376 struct sensor *sensor = to_sensor(client);
3377 const struct v4l2_queryctrl *qctrl_info;
3378 struct af_cmdinfo cmdinfo;
3381 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
3385 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3386 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
3388 if (sensor_af_idlechk(client))
3389 goto sensor_set_focus_relative_end;
3392 cmdinfo.cmd_tag = StepFocus_Near_Tag;
3393 } else if (value < 0) {
3394 cmdinfo.cmd_tag = StepFocus_Far_Tag;
3396 cmdinfo.validate_bit = 0x80;
3397 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3399 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3402 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3406 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3407 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3409 sensor_set_focus_relative_end:
3413 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3415 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3416 struct sensor *sensor = to_sensor(client);
3419 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
3422 case SENSOR_AF_MODE_AUTO:
3424 ret = sensor_af_single(client);
3428 case SENSOR_AF_MODE_MACRO:
3430 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
3434 case SENSOR_AF_MODE_INFINITY:
3436 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
3440 case SENSOR_AF_MODE_CONTINUOUS:
3442 ret = sensor_af_const(client);
3446 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3451 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
3454 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
3455 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
3461 #if CONFIG_SENSOR_Flash
3462 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3464 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3465 if (value == 3) { /* ddl@rock-chips.com: torch */
3466 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
3468 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3470 SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3474 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3478 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3480 struct i2c_client *client = sd->priv;
3481 struct sensor *sensor = to_sensor(client);
3482 const struct v4l2_queryctrl *qctrl;
3484 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3488 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3494 case V4L2_CID_BRIGHTNESS:
3496 ctrl->value = sensor->info_priv.brightness;
3499 case V4L2_CID_SATURATION:
3501 ctrl->value = sensor->info_priv.saturation;
3504 case V4L2_CID_CONTRAST:
3506 ctrl->value = sensor->info_priv.contrast;
3509 case V4L2_CID_DO_WHITE_BALANCE:
3511 ctrl->value = sensor->info_priv.whiteBalance;
3514 case V4L2_CID_EXPOSURE:
3516 ctrl->value = sensor->info_priv.exposure;
3519 case V4L2_CID_HFLIP:
3521 ctrl->value = sensor->info_priv.mirror;
3524 case V4L2_CID_VFLIP:
3526 ctrl->value = sensor->info_priv.flip;
3537 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3539 struct i2c_client *client = sd->priv;
3540 struct sensor *sensor = to_sensor(client);
3541 struct soc_camera_device *icd = client->dev.platform_data;
3542 const struct v4l2_queryctrl *qctrl;
3545 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3549 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3555 #if CONFIG_SENSOR_Brightness
3556 case V4L2_CID_BRIGHTNESS:
3558 if (ctrl->value != sensor->info_priv.brightness)
3560 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3564 sensor->info_priv.brightness = ctrl->value;
3569 #if CONFIG_SENSOR_Exposure
3570 case V4L2_CID_EXPOSURE:
3572 if (ctrl->value != sensor->info_priv.exposure)
3574 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3578 sensor->info_priv.exposure = ctrl->value;
3583 #if CONFIG_SENSOR_Saturation
3584 case V4L2_CID_SATURATION:
3586 if (ctrl->value != sensor->info_priv.saturation)
3588 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3592 sensor->info_priv.saturation = ctrl->value;
3597 #if CONFIG_SENSOR_Contrast
3598 case V4L2_CID_CONTRAST:
3600 if (ctrl->value != sensor->info_priv.contrast)
3602 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3606 sensor->info_priv.contrast = ctrl->value;
3611 #if CONFIG_SENSOR_WhiteBalance
3612 case V4L2_CID_DO_WHITE_BALANCE:
3614 if (ctrl->value != sensor->info_priv.whiteBalance)
3616 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3620 sensor->info_priv.whiteBalance = ctrl->value;
3625 #if CONFIG_SENSOR_Mirror
3626 case V4L2_CID_HFLIP:
3628 if (ctrl->value != sensor->info_priv.mirror)
3630 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3632 sensor->info_priv.mirror = ctrl->value;
3637 #if CONFIG_SENSOR_Flip
3638 case V4L2_CID_VFLIP:
3640 if (ctrl->value != sensor->info_priv.flip)
3642 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3644 sensor->info_priv.flip = ctrl->value;
3655 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3657 const struct v4l2_queryctrl *qctrl;
3658 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3659 struct sensor *sensor = to_sensor(client);
3661 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3665 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3669 switch (ext_ctrl->id)
3671 case V4L2_CID_SCENE:
3673 ext_ctrl->value = sensor->info_priv.scene;
3676 case V4L2_CID_EFFECT:
3678 ext_ctrl->value = sensor->info_priv.effect;
3681 case V4L2_CID_ZOOM_ABSOLUTE:
3683 ext_ctrl->value = sensor->info_priv.digitalzoom;
3686 case V4L2_CID_ZOOM_RELATIVE:
3690 case V4L2_CID_FOCUS_ABSOLUTE:
3692 ext_ctrl->value = sensor->info_priv.focus;
3695 case V4L2_CID_FOCUS_RELATIVE:
3699 case V4L2_CID_FLASH:
3701 ext_ctrl->value = sensor->info_priv.flash;
3709 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3711 const struct v4l2_queryctrl *qctrl;
3712 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3713 struct sensor *sensor = to_sensor(client);
3716 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3720 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3725 switch (ext_ctrl->id)
3727 #if CONFIG_SENSOR_Scene
3728 case V4L2_CID_SCENE:
3730 if (ext_ctrl->value != sensor->info_priv.scene)
3732 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3734 sensor->info_priv.scene = ext_ctrl->value;
3739 #if CONFIG_SENSOR_Effect
3740 case V4L2_CID_EFFECT:
3742 if (ext_ctrl->value != sensor->info_priv.effect)
3744 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3746 sensor->info_priv.effect= ext_ctrl->value;
3751 #if CONFIG_SENSOR_DigitalZoom
3752 case V4L2_CID_ZOOM_ABSOLUTE:
3754 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3757 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3759 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3761 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3763 sensor->info_priv.digitalzoom += val_offset;
3765 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3770 case V4L2_CID_ZOOM_RELATIVE:
3772 if (ext_ctrl->value)
3774 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3776 sensor->info_priv.digitalzoom += ext_ctrl->value;
3778 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3783 #if CONFIG_SENSOR_Focus
3784 case V4L2_CID_FOCUS_ABSOLUTE:
3786 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3789 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
3790 if (ext_ctrl->value == qctrl->minimum) {
3791 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
3792 } else if (ext_ctrl->value == qctrl->maximum) {
3793 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
3795 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
3801 case V4L2_CID_FOCUS_RELATIVE:
3803 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3806 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
3809 case V4L2_CID_FOCUS_AUTO:
3811 if (ext_ctrl->value == 1) {
3812 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
3814 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
3815 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
3816 if (ext_ctrl->value == 0)
3817 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3822 case V4L2_CID_FOCUS_CONTINUOUS:
3824 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
3825 if (ext_ctrl->value == 1) {
3826 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
3828 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
3831 if (ext_ctrl->value == 0)
3832 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3837 #if CONFIG_SENSOR_Flash
3838 case V4L2_CID_FLASH:
3840 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3842 sensor->info_priv.flash = ext_ctrl->value;
3844 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3855 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3857 struct i2c_client *client = sd->priv;
3858 struct soc_camera_device *icd = client->dev.platform_data;
3859 int i, error_cnt=0, error_idx=-1;
3862 for (i=0; i<ext_ctrl->count; i++) {
3863 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3870 error_idx = ext_ctrl->count;
3872 if (error_idx != -1) {
3873 ext_ctrl->error_idx = error_idx;
3880 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3882 struct i2c_client *client = sd->priv;
3883 struct soc_camera_device *icd = client->dev.platform_data;
3884 int i, error_cnt=0, error_idx=-1;
3887 for (i=0; i<ext_ctrl->count; i++) {
3888 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3895 error_idx = ext_ctrl->count;
3897 if (error_idx != -1) {
3898 ext_ctrl->error_idx = error_idx;
3905 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
3907 struct i2c_client *client = sd->priv;
3908 struct sensor *sensor = to_sensor(client);
3909 #if CONFIG_SENSOR_Focus
3910 struct soc_camera_device *icd = client->dev.platform_data;
3911 struct v4l2_mbus_framefmt mf;
3915 sensor->info_priv.enable = 1;
3916 #if CONFIG_SENSOR_Focus
3917 mf.width = icd->user_width;
3918 mf.height = icd->user_height;
3919 mf.code = sensor->info_priv.fmt.code;
3920 mf.colorspace = sensor->info_priv.fmt.colorspace;
3921 mf.field = V4L2_FIELD_NONE;
3922 /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
3923 if (sensor_fmt_capturechk(sd, &mf) == false) {
3924 if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {
3925 if (sensor->sensor_wq != NULL) {
3926 mutex_lock(&sensor->wq_lock);
3927 if (sensor->sensor_wk.state == sensor_working) {
3928 SENSOR_DG("%s sensor af firmware thread is runing, Ingore current work",SENSOR_NAME_STRING());
3929 mutex_unlock(&sensor->wq_lock);
3930 goto sensor_s_stream_end;
3932 sensor->sensor_wk.state = sensor_working;
3933 mutex_unlock(&sensor->wq_lock);
3934 sensor->sensor_wk.client = client;
3935 INIT_WORK(&(sensor->sensor_wk.dwork.work), sensor_af_workqueue);
3936 queue_delayed_work(sensor->sensor_wq,&(sensor->sensor_wk.dwork), 0);
3938 sensor->info_priv.affm_reinit = 0;
3942 } else if (enable == 0) {
3943 sensor->info_priv.enable = 0;
3944 #if CONFIG_SENSOR_Focus
3945 flush_work(&(sensor->sensor_wk.dwork.work));
3946 mutex_lock(&sensor->wq_lock);
3947 sensor->sensor_wk.state = sensor_work_ready;
3948 mutex_unlock(&sensor->wq_lock);
3952 sensor_s_stream_end:
3956 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3957 * this wasn't our capture interface, so, we wait for the right one */
3958 static int sensor_video_probe(struct soc_camera_device *icd,
3959 struct i2c_client *client)
3963 struct sensor *sensor = to_sensor(client);
3965 /* We must have a parent by now. And it cannot be a wrong one.
3966 * So this entire test is completely redundant. */
3967 if (!icd->dev.parent ||
3968 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3971 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3973 goto sensor_video_probe_err;
3976 ret = sensor_write(client, 0x3012, 0x80);
3978 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3980 goto sensor_video_probe_err;
3982 mdelay(5); //delay 5 microseconds
3984 /* check if it is an sensor sensor */
3985 ret = sensor_read(client, 0x300a, &value);
3987 SENSOR_TR("read chip id high byte failed\n");
3989 goto sensor_video_probe_err;
3992 pid |= (value << 8);
3994 ret = sensor_read(client, 0x300b, &value);
3996 SENSOR_TR("read chip id low byte failed\n");
3998 goto sensor_video_probe_err;
4001 pid |= (value & 0xff);
4002 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4003 if (pid == SENSOR_ID) {
4004 sensor->model = SENSOR_V4L2_IDENT;
4006 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4008 goto sensor_video_probe_err;
4012 sensor_video_probe_err:
4015 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
4017 struct i2c_client *client = sd->priv;
4018 struct soc_camera_device *icd = client->dev.platform_data;
4019 struct sensor *sensor = to_sensor(client);
4022 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4025 case RK29_CAM_SUBDEV_DEACTIVATE:
4027 sensor_deactivate(client);
4030 case RK29_CAM_SUBDEV_IOREQUEST:
4032 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
4033 if (sensor->sensor_io_request != NULL) {
4034 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
4035 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
4036 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
4037 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
4038 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
4039 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
4042 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
4044 goto sensor_ioctl_end;
4046 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
4048 #if CONFIG_SENSOR_Flash
4049 if (sensor->sensor_gpio_res) {
4050 printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
4051 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
4052 for (i = 0; i < icd->ops->num_controls; i++) {
4053 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
4054 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
4057 sensor->info_priv.flash = 0xff;
4058 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
4066 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4075 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
4076 enum v4l2_mbus_pixelcode *code)
4078 if (index >= ARRAY_SIZE(sensor_colour_fmts))
4081 *code = sensor_colour_fmts[index].code;
4084 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
4085 .init = sensor_init,
4086 .g_ctrl = sensor_g_control,
4087 .s_ctrl = sensor_s_control,
4088 .g_ext_ctrls = sensor_g_ext_controls,
4089 .s_ext_ctrls = sensor_s_ext_controls,
4090 .g_chip_ident = sensor_g_chip_ident,
4091 .ioctl = sensor_ioctl,
4094 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
4095 .s_mbus_fmt = sensor_s_fmt,
4096 .g_mbus_fmt = sensor_g_fmt,
4097 .try_mbus_fmt = sensor_try_fmt,
4098 .enum_mbus_fmt = sensor_enum_fmt,
4099 .s_stream = sensor_s_stream,
4102 static struct v4l2_subdev_ops sensor_subdev_ops = {
4103 .core = &sensor_subdev_core_ops,
4104 .video = &sensor_subdev_video_ops,
4107 static int sensor_probe(struct i2c_client *client,
4108 const struct i2c_device_id *did)
4110 struct sensor *sensor;
4111 struct soc_camera_device *icd = client->dev.platform_data;
4112 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
4113 struct soc_camera_link *icl;
4116 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
4118 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
4122 icl = to_soc_camera_link(icd);
4124 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
4128 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
4129 dev_warn(&adapter->dev,
4130 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
4134 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
4138 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
4140 /* Second stage probe - when a capture adapter is there */
4141 icd->ops = &sensor_ops;
4142 sensor->info_priv.fmt = sensor_colour_fmts[0];
4143 #if CONFIG_SENSOR_I2C_NOSCHED
4144 atomic_set(&sensor->tasklock_cnt,0);
4147 ret = sensor_video_probe(icd, client);
4150 i2c_set_clientdata(client, NULL);
4154 #if CONFIG_SENSOR_Focus
4155 sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING( wq));
4156 if (sensor->sensor_wq == NULL)
4157 SENSOR_TR("%s workqueue create fail!", SENSOR_NAME_STRING( wq));
4158 mutex_init(&sensor->wq_lock);
4159 sensor->sensor_wk.state = sensor_work_ready;
4162 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
4166 static int sensor_remove(struct i2c_client *client)
4168 struct sensor *sensor = to_sensor(client);
4169 struct soc_camera_device *icd = client->dev.platform_data;
4171 #if CONFIG_SENSOR_Focus
4172 if (sensor->sensor_wq) {
4173 destroy_workqueue(sensor->sensor_wq);
4174 sensor->sensor_wq = NULL;
4179 i2c_set_clientdata(client, NULL);
4180 client->driver = NULL;
4186 static const struct i2c_device_id sensor_id[] = {
4187 {SENSOR_NAME_STRING(), 0 },
4190 MODULE_DEVICE_TABLE(i2c, sensor_id);
4192 static struct i2c_driver sensor_i2c_driver = {
4194 .name = SENSOR_NAME_STRING(),
4196 .probe = sensor_probe,
4197 .remove = sensor_remove,
4198 .id_table = sensor_id,
4201 static int __init sensor_mod_init(void)
4203 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4204 return i2c_add_driver(&sensor_i2c_driver);
4207 static void __exit sensor_mod_exit(void)
4209 i2c_del_driver(&sensor_i2c_driver);
4212 device_initcall_sync(sensor_mod_init);
4213 module_exit(sensor_mod_exit);
4215 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
4216 MODULE_AUTHOR("ddl <kernel@rock-chips>");
4217 MODULE_LICENSE("GPL");