3 o* Driver for MT9M001 CMOS Image Sensor from Micron
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/videodev2.h>
13 #include <linux/slab.h>
14 #include <linux/i2c.h>
15 #include <linux/log2.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/circ_buf.h>
19 #include <linux/miscdevice.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-chip-ident.h>
22 #include <media/soc_camera.h>
23 #include <plat/rk_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__)
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
43 #define MIN(x,y) ((x<y) ? x: y)
44 #define MAX(x,y) ((x>y) ? x: y)
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME RK29_CAM_SENSOR_SIV120B
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_SIV120B
49 #define SENSOR_ID 0x12
50 #define SENSOR_MIN_WIDTH 640//176
51 #define SENSOR_MIN_HEIGHT 480//144
52 #define SENSOR_MAX_WIDTH 640
53 #define SENSOR_MAX_HEIGHT 480
54 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT 480
56 #define SENSOR_INIT_WINSEQADR sensor_vga
57 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
59 #define CONFIG_SENSOR_WhiteBalance 0
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 0
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 1
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
78 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
79 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
81 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
82 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
83 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
84 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
85 #define COLOR_TEMPERATURE_OFFICE_DN 3500
86 #define COLOR_TEMPERATURE_OFFICE_UP 5000
87 #define COLOR_TEMPERATURE_HOME_DN 2500
88 #define COLOR_TEMPERATURE_HOME_UP 3500
90 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
91 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
93 #define SENSOR_AF_IS_ERR (0x00<<0)
94 #define SENSOR_AF_IS_OK (0x01<<0)
95 #define SENSOR_INIT_IS_ERR (0x00<<28)
96 #define SENSOR_INIT_IS_OK (0x01<<28)
103 /* init 640X480 VGA */
104 static struct reginfo sensor_init_data[] =
109 {0x13,0x17}, // #anti_black sun
110 {0x16,0xcf}, // #0xb6
112 {0x20,0x00}, // #P_BNKT
113 {0x21,0x01}, // #P_HBNKT
114 {0x22,0x01}, // #P_ROWFIL
115 {0x23,0x01}, // #P_VBNKT
117 {0x40,0x00}, // #0x8b
118 {0x41,0x00}, // #0x96
119 {0x42,0x00}, // #0xda
120 {0x43,0x00}, // #0x83
124 {0x11,0x14}, // # 6fps at lowlux
125 {0x12,0x78}, // # D65 target 0x74
126 {0x13,0x78}, // # CWF target 0x74
127 {0x14,0x78}, // # A target 0x74
130 {0x40,0x50}, // # Max x8
132 {0x41,0x20}, // #AG_TOP1 0x28
133 {0x42,0x20}, // #AG_TOP0 0x28
134 {0x43,0x00}, // #AG_MIN1 0x08
135 {0x44,0x00}, // #AG_MIN0 0x08
136 {0x45,0x00}, // #G50_dec 0x09
137 {0x46,0x0a}, // #G33_dec 0x17
138 {0x47,0x10}, // #G25_dec 0x1d
139 {0x48,0x13}, // #G20_dec 0x21
140 {0x49,0x15}, // #G12_dec 0x23
141 {0x4a,0x18}, // #G09_dec 0x24
142 {0x4b,0x1a}, // #G06_dec 0x26
143 {0x4c,0x1d}, // #G03_dec 0x27
144 {0x4d,0x20}, // #G100_inc 0x27
145 {0x4e,0x10}, // #G50_inc 0x1a
146 {0x4f,0x0a}, // #G33_inc 0x14
147 {0x50,0x08}, // #G25_inc 0x11
148 {0x51,0x06}, // #G20_inc 0x0f
149 {0x52,0x05}, // #G12_inc 0x0d
150 {0x53,0x04}, // #G09_inc 0x0c
151 {0x54,0x02}, // #G06_inc 0x0a
152 {0x55,0x01}, // #G03_inc 0x09
161 {0x15,0xfe}, // # R gain Top
162 {0x16,0x70}, // # R gain bottom 0x80
163 {0x17,0xea}, // # B gain Top
164 {0x18,0x80}, // # B gain bottom
165 {0x19,0xa0}, // # Cr top value
166 {0x1a,0x60}, // # Cr bottom value
167 {0x1b,0xa0}, // # Cb top value
168 {0x1c,0x60}, // # Cb bottom value
171 {0x20,0xe8}, // # AWB luminous top value
172 {0x21,0x20}, // # AWB luminous bottom value
177 {0x27,0x10}, // # ST for outdoor enable
178 {0x28,0x1a}, // # ST for outdoor disable
179 {0x29,0xb8}, // # AWB R gain at outdoor
180 {0x2a,0x94}, // # AWB B gain at outdoor
208 {0x63,0x98}, // # R D30 to D20
209 {0x64,0xa8}, // # B D30 to D20
210 {0x65,0x98}, // # R D20 to D30
211 {0x66,0xa8}, // # B D20 to D30
212 {0x67,0xc8}, // # R D65 to D30
213 {0x68,0x9f}, // # B D65 to D30
214 {0x69,0xc8}, // # R D30 to D65
215 {0x6a,0x9f}, // # B D30 to D65
224 //ading Register Setting
231 {0x46,0x11}, // # left R gain[7:4], right R gain[3:0]
232 {0x47,0x23}, // # top R gain[7:4], bottom R gain[3:0]
233 {0x48,0x10}, // # left Gr gain[7:4], right Gr gain[3:0]
234 {0x49,0x12}, // # top Gr gain[7:4], bottom Gr gain[3:0]
235 {0x4a,0x01}, // # left Gb gain[7:4], right Gb gain[3:0]
236 {0x4b,0x12}, // # top Gb gain[7:4], bottom Gb gain[3:0]
237 {0x4c,0x00}, // # left B gain[7:4], right B gain[3:0]
238 {0x4d,0x11}, // # top B gain[7:4], bottom B gain[3:0]
239 {0x4e,0x04}, // # X-axis center high[3:2], Y-axis center high[1:0]
240 {0x4f,0x50}, // # X-axis center low[7:0]
241 {0x50,0xf6}, // # Y-axis center low[7:0]
242 {0x51,0x80}, // # Shading Center Gain
243 {0x52,0x00}, // # Shading R Offset
244 {0x53,0x00}, // # Shading Gr Offset
245 {0x54,0x00}, // # Shading Gb Offset
246 {0x55,0x00}, // # Shading B Offset
251 {0x32,0xA }, // #0x10
252 {0x33,0x1E}, // #0x27
253 {0x34,0x42}, // #0x48
254 {0x35,0x5E}, // #0x62
255 {0x36,0x74}, // #0x77
256 {0x37,0x86}, // #0x88
257 {0x38,0x96}, // #0x97
258 {0x39,0xA4}, // #0xA5
259 {0x3a,0xB1}, // #0xB2
260 {0x3b,0xC8}, // #0xC9
261 {0x3c,0xDC}, // #0xDB
262 {0x3d,0xEF}, // #0xED
263 {0x3e,0xF8}, // #0xF7
264 {0x3f,0xFF}, // #0xFF
266 //lor matrix (D65) - Daylight
267 {0x71,0x3b}, // #0x3a
268 {0x72,0xca}, // #0xc9
269 {0x73,0xfb}, // #0xfe
270 {0x74,0x0f}, // #0x10
271 {0x75,0x22}, // #0x23
272 {0x76,0x0f}, // #0x0b
273 {0x77,0xf7}, // #0xfb
274 {0x78,0xc7}, // #0xce
275 {0x79,0x42}, // #0x38
277 //lor matrix (D30) - CWF
278 {0x7a,0x3b}, // #0x39
279 {0x7b,0xcb}, // #0xcd
280 {0x7c,0xfa}, // #0xfa
281 {0x7d,0x0e}, // #0x0a
282 {0x7e,0x21}, // #0x29
283 {0x7f,0x11}, // #0x0c
284 {0x80,0xf4}, // #0xf5
285 {0x81,0xc4}, // #0xc7
286 {0x82,0x48}, // #0x44
288 //lor matrix (D20) - A
289 {0x83,0x3a}, // #0x3a
290 {0x84,0xcd}, // #0xcc
291 {0x85,0xf9}, // #0xfa
292 {0x86,0x15}, // #0xfe
293 {0x87,0x26}, // #0x3a
294 {0x88,0x05}, // #0x08
295 {0x89,0xed}, // #0xf9
296 {0x8a,0xbb}, // #0xc3
297 {0x8b,0x57}, // #0x44
300 {0x17,0xC8}, // # DPCNRCTRL
301 {0x18,0x18}, // # DPTHR
302 {0x19,0x48}, // # [7:6] G DP Number Thr @ Dark | [5:0] DPTHRMIN
303 {0x1A,0x48}, // # [7:6] G DP Number Thr @ Normal | [5:0] DPTHRMAX
304 {0x1B,0x24}, // # DPTHRSLP( [7:4] @ Normal | [3:0] @ Dark )
305 {0x1C,0x00}, // # NRTHR
306 {0x1D,0x48}, // # [7:6] C DP Number Thr @ Dark | [5:0] NRTHRMIN 0x48
307 {0x1E,0x48}, // # [7:6] C DP Number Thr @ Normal | [5:0] NRTHRMAX
308 {0x1F,0x68}, // # NRTHRSLP( [7:4] @ Normal | [3:0] @ Dark ) 0x20
309 {0x20,0x04}, // # IllumiInfo STRTNOR
310 {0x21,0x0f}, // # IllumiInfo STRTDRK
312 {0x56,0x10}, // # lowlux shading enable
313 {0x57,0x92}, // # lowlux shading
314 {0x58,0x00}, // # lowlux shading on
317 {0x90,0x18}, // # upper gain
318 {0x91,0x18}, // # down gain
319 {0x92,0x04}, // # upper coring value
320 {0x96,0x04}, // # down coring value
322 {0x9f,0x10}, // # Yeugain
323 {0xa0,0x10}, // # Yedgain9
324 {0xa9,0x12}, // # Cr saturation
325 {0xaa,0x12}, // # Cb saturation
326 {0xb9,0x10}, // # 0x13 lowlux color
327 {0xba,0x20}, // # 0x10 lowlux color
329 {0xdd,0x4f}, // # ENHCTRL5
330 {0xde,0xba}, // # NOIZCTRL
363 /* 640X480 VGA @30fps for both preview & capture. */
364 static struct reginfo sensor_vga[] =
382 static struct reginfo sensor_cif[] =
388 static struct reginfo sensor_qvga[] =
394 static struct reginfo sensor_qcif[] =
399 static struct reginfo sensor_ClrFmt_YUYV[]=
405 static struct reginfo sensor_ClrFmt_UYVY[]=
412 #if CONFIG_SENSOR_WhiteBalance
413 static struct reginfo sensor_WhiteB_Auto[]=
415 {0x84, 0x6C}, //Contrast 4
439 {0x0f, 0x4a}, //Saturation 3
451 {0x4f, 0x2e}, //Brightness 3
465 /* Cloudy Colour Temperature : 6500K - 8000K */
466 static struct reginfo sensor_WhiteB_Cloudy[]=
468 {0x7C,0x04}, //Contrast 5
502 {0x4f,0x3a}, //Saturation 4
508 {0x4f, 0x2e}, //Brightness 3
521 /* ClearDay Colour Temperature : 5000K - 6500K */
522 static struct reginfo sensor_WhiteB_ClearDay[]=
525 {0x7C,0x04}, //Contrast 5
559 {0x4f,0x3a}, //Saturation 4
565 {0x4f, 0x2e}, //Brightness 3
578 /* Office Colour Temperature : 3500K - 5000K */
579 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
582 {0x84, 0x6C}, //Contrast 4
606 {0x0f, 0x4a}, //Saturation 3
618 {0x4f, 0x2e}, //Brightness 3
634 /* Home Colour Temperature : 2500K - 3500K */
635 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
638 {0x84, 0x6C}, //Contrast 4
662 {0x0f, 0x4a}, //Saturation 3
674 {0x4f, 0x2e}, //Brightness 3
687 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
688 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
692 #if CONFIG_SENSOR_Brightness
693 static struct reginfo sensor_Brightness0[]=
696 {0x3301, 0xff},//bit[7]:1, enable SDE
703 static struct reginfo sensor_Brightness1[]=
706 {0x3301, 0xff},//bit[7]:1, enable SDE
713 static struct reginfo sensor_Brightness2[]=
716 {0x3301, 0xff},//bit[7]:1, enable SDE
723 static struct reginfo sensor_Brightness3[]=
726 {0x3301, 0xff},//bit[7]:1, enable SDE
733 static struct reginfo sensor_Brightness4[]=
736 {0x3301, 0xff},//bit[7]:1, enable SDE
743 static struct reginfo sensor_Brightness5[]=
746 {0x3301, 0xff},//bit[7]:1, enable SDE
747 {0x3391, 0x04}, //bit[2] enable
748 {0x3390, 0x41}, //bit[3] sign of brightness
752 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
753 sensor_Brightness4, sensor_Brightness5,NULL,
758 #if CONFIG_SENSOR_Effect
759 static struct reginfo sensor_Effect_Normal[] =
768 static struct reginfo sensor_Effect_WandB[] =
778 static struct reginfo sensor_Effect_Sepia[] =
787 static struct reginfo sensor_Effect_Negative[] =
797 static struct reginfo sensor_Effect_Bluish[] =
807 static struct reginfo sensor_Effect_Green[] =
816 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
817 /*sensor_Effect_Bluish,*/ sensor_Effect_Green,NULL,
820 #if CONFIG_SENSOR_Exposure
821 static struct reginfo sensor_Exposure0[]=
826 static struct reginfo sensor_Exposure1[]=
831 static struct reginfo sensor_Exposure2[]=
836 static struct reginfo sensor_Exposure3[]=
841 static struct reginfo sensor_Exposure4[]=
846 static struct reginfo sensor_Exposure5[]=
851 static struct reginfo sensor_Exposure6[]=
856 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
857 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
860 #if CONFIG_SENSOR_Saturation
861 static struct reginfo sensor_Saturation0[]=
866 static struct reginfo sensor_Saturation1[]=
871 static struct reginfo sensor_Saturation2[]=
875 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
878 #if CONFIG_SENSOR_Contrast
879 static struct reginfo sensor_Contrast0[]=
884 static struct reginfo sensor_Contrast1[]=
889 static struct reginfo sensor_Contrast2[]=
894 static struct reginfo sensor_Contrast3[]=
899 static struct reginfo sensor_Contrast4[]=
905 static struct reginfo sensor_Contrast5[]=
910 static struct reginfo sensor_Contrast6[]=
914 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
915 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
919 #if CONFIG_SENSOR_Mirror
920 static struct reginfo sensor_MirrorOn[]=
925 static struct reginfo sensor_MirrorOff[]=
929 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
931 #if CONFIG_SENSOR_Flip
932 static struct reginfo sensor_FlipOn[]=
937 static struct reginfo sensor_FlipOff[]=
941 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
944 #if CONFIG_SENSOR_Scene
945 static struct reginfo sensor_SceneAuto[] =
950 static struct reginfo sensor_SceneNight[] =
954 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
957 #if CONFIG_SENSOR_DigitalZoom
958 static struct reginfo sensor_Zoom0[] =
963 static struct reginfo sensor_Zoom1[] =
968 static struct reginfo sensor_Zoom2[] =
974 static struct reginfo sensor_Zoom3[] =
978 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
980 static const struct v4l2_querymenu sensor_menus[] =
982 #if CONFIG_SENSOR_WhiteBalance
983 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
984 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
985 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
988 #if CONFIG_SENSOR_Effect
989 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
990 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
991 /* { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,*/{ .id = V4L2_CID_EFFECT, .index = 4, .name = "aqua", .reserved = 0,},
994 #if CONFIG_SENSOR_Scene
995 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
998 #if CONFIG_SENSOR_Flash
999 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1000 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1004 static const struct v4l2_queryctrl sensor_controls[] =
1006 #if CONFIG_SENSOR_WhiteBalance
1008 .id = V4L2_CID_DO_WHITE_BALANCE,
1009 .type = V4L2_CTRL_TYPE_MENU,
1010 .name = "White Balance Control",
1018 #if CONFIG_SENSOR_Brightness
1020 .id = V4L2_CID_BRIGHTNESS,
1021 .type = V4L2_CTRL_TYPE_INTEGER,
1022 .name = "Brightness Control",
1030 #if CONFIG_SENSOR_Effect
1032 .id = V4L2_CID_EFFECT,
1033 .type = V4L2_CTRL_TYPE_MENU,
1034 .name = "Effect Control",
1042 #if CONFIG_SENSOR_Exposure
1044 .id = V4L2_CID_EXPOSURE,
1045 .type = V4L2_CTRL_TYPE_INTEGER,
1046 .name = "Exposure Control",
1054 #if CONFIG_SENSOR_Saturation
1056 .id = V4L2_CID_SATURATION,
1057 .type = V4L2_CTRL_TYPE_INTEGER,
1058 .name = "Saturation Control",
1066 #if CONFIG_SENSOR_Contrast
1068 .id = V4L2_CID_CONTRAST,
1069 .type = V4L2_CTRL_TYPE_INTEGER,
1070 .name = "Contrast Control",
1078 #if CONFIG_SENSOR_Mirror
1080 .id = V4L2_CID_HFLIP,
1081 .type = V4L2_CTRL_TYPE_BOOLEAN,
1082 .name = "Mirror Control",
1090 #if CONFIG_SENSOR_Flip
1092 .id = V4L2_CID_VFLIP,
1093 .type = V4L2_CTRL_TYPE_BOOLEAN,
1094 .name = "Flip Control",
1102 #if CONFIG_SENSOR_Scene
1104 .id = V4L2_CID_SCENE,
1105 .type = V4L2_CTRL_TYPE_MENU,
1106 .name = "Scene Control",
1114 #if CONFIG_SENSOR_DigitalZoom
1116 .id = V4L2_CID_ZOOM_RELATIVE,
1117 .type = V4L2_CTRL_TYPE_INTEGER,
1118 .name = "DigitalZoom Control",
1124 .id = V4L2_CID_ZOOM_ABSOLUTE,
1125 .type = V4L2_CTRL_TYPE_INTEGER,
1126 .name = "DigitalZoom Control",
1134 #if CONFIG_SENSOR_Focus
1136 .id = V4L2_CID_FOCUS_RELATIVE,
1137 .type = V4L2_CTRL_TYPE_INTEGER,
1138 .name = "Focus Control",
1144 .id = V4L2_CID_FOCUS_ABSOLUTE,
1145 .type = V4L2_CTRL_TYPE_INTEGER,
1146 .name = "Focus Control",
1150 .default_value = 125,
1154 #if CONFIG_SENSOR_Flash
1156 .id = V4L2_CID_FLASH,
1157 .type = V4L2_CTRL_TYPE_MENU,
1158 .name = "Flash Control",
1167 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1168 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1169 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1170 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1171 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1172 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1173 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1174 static int sensor_resume(struct soc_camera_device *icd);
1175 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1176 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1177 #if CONFIG_SENSOR_Effect
1178 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1180 #if CONFIG_SENSOR_WhiteBalance
1181 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1183 static int sensor_deactivate(struct i2c_client *client);
1185 static struct soc_camera_ops sensor_ops =
1187 .suspend = sensor_suspend,
1188 .resume = sensor_resume,
1189 .set_bus_param = sensor_set_bus_param,
1190 .query_bus_param = sensor_query_bus_param,
1191 .controls = sensor_controls,
1192 .menus = sensor_menus,
1193 .num_controls = ARRAY_SIZE(sensor_controls),
1194 .num_menus = ARRAY_SIZE(sensor_menus),
1197 /* only one fixed colorspace per pixelcode */
1198 struct sensor_datafmt {
1199 enum v4l2_mbus_pixelcode code;
1200 enum v4l2_colorspace colorspace;
1203 /* Find a data format by a pixel code in an array */
1204 static const struct sensor_datafmt *sensor_find_datafmt(
1205 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1209 for (i = 0; i < n; i++)
1210 if (fmt[i].code == code)
1216 static const struct sensor_datafmt sensor_colour_fmts[] = {
1217 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1218 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1221 typedef struct sensor_info_priv_s
1235 unsigned char mirror; /* HFLIP */
1236 unsigned char flip; /* VFLIP */
1237 unsigned int winseqe_cur_addr;
1238 struct sensor_datafmt fmt;
1239 unsigned int funmodule_state;
1241 } sensor_info_priv_t;
1245 struct v4l2_subdev subdev;
1246 struct i2c_client *client;
1247 sensor_info_priv_t info_priv;
1248 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1249 #if CONFIG_SENSOR_I2C_NOSCHED
1250 atomic_t tasklock_cnt;
1252 struct rk29camera_platform_data *sensor_io_request;
1253 struct rk29camera_gpio_res *sensor_gpio_res;
1256 static struct sensor* to_sensor(const struct i2c_client *client)
1258 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1261 static int sensor_task_lock(struct i2c_client *client, int lock)
1263 #if CONFIG_SENSOR_I2C_NOSCHED
1265 struct sensor *sensor = to_sensor(client);
1268 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1269 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1270 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1274 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1275 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1276 goto sensor_task_lock_err;
1281 atomic_add(1, &sensor->tasklock_cnt);
1283 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1284 atomic_sub(1, &sensor->tasklock_cnt);
1286 if (atomic_read(&sensor->tasklock_cnt) == 0)
1291 sensor_task_lock_err:
1299 /* sensor register write */
1300 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1304 struct i2c_msg msg[1];
1306 buf[0] = reg & 0xFF;
1309 msg->addr = client->addr;
1310 msg->flags = client->flags;
1312 msg->len = sizeof(buf);
1313 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1314 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1319 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1320 err = i2c_transfer(client->adapter, msg, 1);
1325 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1333 /* sensor register read */
1334 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1339 struct i2c_msg msg[2];
1341 //buf[0] = reg >> 8;
1343 buf[1] = reg & 0xFF;
1345 msg[0].addr = client->addr;
1346 msg[0].flags = client->flags;
1348 msg[0].len = sizeof(buf);
1349 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1350 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1352 msg[1].addr = client->addr;
1353 msg[1].flags = client->flags|I2C_M_RD;
1356 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1357 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1361 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1362 err = i2c_transfer(client->adapter, msg, 2);
1368 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1376 /* write a array of registers */
1378 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1383 while (regarray[i].reg != 0)
1385 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1388 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1396 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1401 while (regarray[i].reg != 0)
1403 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1406 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1409 err = sensor_read(client, regarray[i].reg, &val_read);
1410 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1416 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1418 struct soc_camera_link *icl = to_soc_camera_link(icd);
1421 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1424 case Sensor_PowerDown:
1426 if (icl->powerdown) {
1427 ret = icl->powerdown(icd->pdev, on);
1428 if (ret == RK29_CAM_IO_SUCCESS) {
1432 icl->reset(icd->pdev);
1434 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1436 goto sensor_power_end;
1443 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1444 struct sensor *sensor = to_sensor(client);
1446 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1447 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1453 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1461 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1463 struct i2c_client *client = v4l2_get_subdevdata(sd);
1464 struct soc_camera_device *icd = client->dev.platform_data;
1465 struct sensor *sensor = to_sensor(client);
1466 const struct v4l2_queryctrl *qctrl;
1467 const struct sensor_datafmt *fmt;
1470 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1472 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1474 goto sensor_INIT_ERR;
1478 if (sensor_task_lock(client,1)<0)
1479 goto sensor_INIT_ERR;
1480 // ret = sensor_write(client, 0x12, 0x80);
1483 // SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1485 // goto sensor_INIT_ERR;
1488 // mdelay(5); //delay 5 microseconds
1490 for(i = 0; i < sizeof(sensor_init_data)/2;i++){
1492 // ret = sensor_write(client, sensor_init_data + i*2, sensor_init_data + i*2 + 1);
1493 // printk("write to reg[0x%x] 0x%x\n",sensor_init_data[i].reg,sensor_init_data[i].val);
1494 ret = sensor_write(client, sensor_init_data[i].reg, sensor_init_data[i].val);
1495 //ret = sensor_write_array(client, sensor_init_data);
1498 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1499 goto sensor_INIT_ERR;
1501 // sensor_read(client,sensor_init_data[i].reg,&tmp);
1502 // printk("read from reg[0x%x] 0x%x\n",sensor_init_data[i].reg,tmp);
1504 sensor_task_lock(client,0);
1506 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1507 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1509 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1511 goto sensor_INIT_ERR;
1513 sensor->info_priv.fmt = *fmt;
1515 /* sensor sensor information for initialization */
1516 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1518 sensor->info_priv.whiteBalance = qctrl->default_value;
1519 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1521 sensor->info_priv.brightness = qctrl->default_value;
1522 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1524 sensor->info_priv.effect = qctrl->default_value;
1525 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1527 sensor->info_priv.exposure = qctrl->default_value;
1529 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1531 sensor->info_priv.saturation = qctrl->default_value;
1532 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1534 sensor->info_priv.contrast = qctrl->default_value;
1535 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1537 sensor->info_priv.mirror = qctrl->default_value;
1538 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1540 sensor->info_priv.flip = qctrl->default_value;
1541 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1543 sensor->info_priv.scene = qctrl->default_value;
1544 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1546 sensor->info_priv.digitalzoom = qctrl->default_value;
1548 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1549 #if CONFIG_SENSOR_Focus
1551 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1553 sensor->info_priv.focus = qctrl->default_value;
1556 #if CONFIG_SENSOR_Flash
1557 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1559 sensor->info_priv.flash = qctrl->default_value;
1562 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);
1563 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1566 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1567 sensor_task_lock(client,0);
1568 sensor_deactivate(client);
1572 static int sensor_deactivate(struct i2c_client *client)
1574 struct soc_camera_device *icd = client->dev.platform_data;
1575 struct sensor *sensor = to_sensor(client);
1577 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1579 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1580 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1582 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1583 icd->user_width = SENSOR_INIT_WIDTH;
1584 icd->user_height = SENSOR_INIT_HEIGHT;
1586 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1589 static struct reginfo sensor_power_down_sequence[]=
1593 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1596 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1599 if (pm_msg.event == PM_EVENT_SUSPEND) {
1600 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1601 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1603 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1606 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1608 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1613 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1619 static int sensor_resume(struct soc_camera_device *icd)
1623 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1625 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1629 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1635 static int sensor_set_bus_param(struct soc_camera_device *icd,
1636 unsigned long flags)
1642 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1644 struct soc_camera_link *icl = to_soc_camera_link(icd);
1645 unsigned long flags = SENSOR_BUS_PARAM;
1647 return soc_camera_apply_sensor_flags(icl, flags);
1650 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1652 struct i2c_client *client = v4l2_get_subdevdata(sd);
1653 struct soc_camera_device *icd = client->dev.platform_data;
1654 struct sensor *sensor = to_sensor(client);
1656 mf->width = icd->user_width;
1657 mf->height = icd->user_height;
1658 mf->code = sensor->info_priv.fmt.code;
1659 mf->colorspace = sensor->info_priv.fmt.colorspace;
1660 mf->field = V4L2_FIELD_NONE;
1664 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1668 if ((mf->width == 1024) && (mf->height == 768)) {
1670 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1672 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1674 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1676 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1681 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1685 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1689 if ((mf->width == 1280) && (mf->height == 720)) {
1691 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1696 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1699 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1701 struct i2c_client *client = v4l2_get_subdevdata(sd);
1702 struct sensor *sensor = to_sensor(client);
1703 const struct sensor_datafmt *fmt;
1704 struct reginfo *winseqe_set_addr=NULL;
1706 int ret=0, set_w,set_h,i;
1708 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1709 ARRAY_SIZE(sensor_colour_fmts));
1712 goto sensor_s_fmt_end;
1715 if (sensor->info_priv.fmt.code != mf->code) {
1718 case V4L2_MBUS_FMT_YUYV8_2X8:
1720 winseqe_set_addr = sensor_ClrFmt_YUYV;
1721 sensor_read(client, 0x3a, &readval);
1722 sensor_write(client,0x3a, readval&0xf7);
1723 sensor_read(client,0x3d,&readval);
1724 sensor_write(client,0x3d,readval&0xfe);
1727 case V4L2_MBUS_FMT_UYVY8_2X8:
1729 winseqe_set_addr = sensor_ClrFmt_UYVY;
1730 sensor_read(client, 0x3a, &readval);
1731 sensor_write(client,0x3a, readval|0x08);
1732 sensor_read(client,0x3d,&readval);
1733 sensor_write(client,0x3d,readval&0xfe);
1739 if (winseqe_set_addr != NULL) {
1740 sensor_write_array(client, winseqe_set_addr);
1741 sensor->info_priv.fmt.code = mf->code;
1742 sensor->info_priv.fmt.colorspace= mf->colorspace;
1743 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1745 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1752 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1754 winseqe_set_addr = sensor_qcif;
1758 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1760 winseqe_set_addr = sensor_qvga;
1764 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1766 winseqe_set_addr = sensor_cif;
1770 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1772 winseqe_set_addr = sensor_vga;
1778 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1779 set_w = SENSOR_INIT_WIDTH;
1780 set_h = SENSOR_INIT_HEIGHT;
1781 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1784 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
1786 printk("sizeof(winseqe_set_addr) %d\n",sizeof(winseqe_set_addr));
1787 for(i = 0; i < sizeof(winseqe_set_addr)/2;i++){
1788 ret |= sensor_write(client, winseqe_set_addr[i].reg, winseqe_set_addr[i].val);
1789 //ret |= sensor_write_array(client, winseqe_set_addr);
1791 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1792 goto sensor_s_fmt_end;
1795 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1798 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1802 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1812 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1814 struct i2c_client *client = v4l2_get_subdevdata(sd);
1815 struct sensor *sensor = to_sensor(client);
1816 const struct sensor_datafmt *fmt;
1817 int ret = 0,set_w,set_h;
1819 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1820 ARRAY_SIZE(sensor_colour_fmts));
1822 fmt = &sensor->info_priv.fmt;
1823 mf->code = fmt->code;
1826 if (mf->height > SENSOR_MAX_HEIGHT)
1827 mf->height = SENSOR_MAX_HEIGHT;
1828 else if (mf->height < SENSOR_MIN_HEIGHT)
1829 mf->height = SENSOR_MIN_HEIGHT;
1831 if (mf->width > SENSOR_MAX_WIDTH)
1832 mf->width = SENSOR_MAX_WIDTH;
1833 else if (mf->width < SENSOR_MIN_WIDTH)
1834 mf->width = SENSOR_MIN_WIDTH;
1839 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1844 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1849 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1854 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1861 set_w = SENSOR_INIT_WIDTH;
1862 set_h = SENSOR_INIT_HEIGHT;
1866 mf->colorspace = fmt->colorspace;
1870 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1872 struct i2c_client *client = v4l2_get_subdevdata(sd);
1874 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1877 if (id->match.addr != client->addr)
1880 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1885 #if CONFIG_SENSOR_Brightness
1886 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1888 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1890 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1892 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1894 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1896 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1899 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1903 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1907 #if CONFIG_SENSOR_Effect
1908 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1910 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1912 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1914 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1917 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1919 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1923 printk("value %d qctrl->minimum %d ",value, qctrl->minimum);
1924 printk("sizeof(sensor_EffectSeqe) %d\n",sizeof(sensor_EffectSeqe));
1925 printk("sizeof(sensor_EffectSeqe[%d]) %d\n",value - qctrl->minimum,sizeof(sensor_EffectSeqe[value - qctrl->minimum]));
1926 for(i = 0; i < 4; i++) {
1927 printk("sensor_EffectSeqe[%d][%d].reg 0x%x sensor_EffectSeqe[%d][%d].val 0x%x \n",
1928 value - qctrl->minimum, i, sensor_EffectSeqe[value - qctrl->minimum][i].reg,value - qctrl->minimum, i,sensor_EffectSeqe[value - qctrl->minimum][i].val);
1929 sensor_write(client, sensor_EffectSeqe[value - qctrl->minimum][i].reg, sensor_EffectSeqe[value - qctrl->minimum][i].val);
1934 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1938 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1942 #if CONFIG_SENSOR_Exposure
1943 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1945 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1947 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1949 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1951 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1953 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1956 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1960 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1964 #if CONFIG_SENSOR_Saturation
1965 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1967 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1969 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1971 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1973 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1975 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1978 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1982 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1986 #if CONFIG_SENSOR_Contrast
1987 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1989 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1991 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1993 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1995 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1997 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2000 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2004 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2008 #if CONFIG_SENSOR_Mirror
2009 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2011 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2013 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2015 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2017 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2019 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2022 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2026 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2030 #if CONFIG_SENSOR_Flip
2031 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2033 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2035 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2037 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2039 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2041 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2044 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2048 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2052 #if CONFIG_SENSOR_Scene
2053 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2055 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2057 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2059 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2061 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2063 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2066 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2070 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2074 #if CONFIG_SENSOR_WhiteBalance
2075 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2077 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2079 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2081 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2083 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2085 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2088 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2092 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2096 #if CONFIG_SENSOR_DigitalZoom
2097 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2099 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2100 struct sensor *sensor = to_sensor(client);
2101 const struct v4l2_queryctrl *qctrl_info;
2102 int digitalzoom_cur, digitalzoom_total;
2104 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2108 digitalzoom_cur = sensor->info_priv.digitalzoom;
2109 digitalzoom_total = qctrl_info->maximum;
2111 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2113 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2117 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2119 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2123 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2125 value = digitalzoom_total - digitalzoom_cur;
2128 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2130 value = 0 - digitalzoom_cur;
2133 digitalzoom_cur += value;
2135 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2137 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2139 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2142 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2149 #if CONFIG_SENSOR_Flash
2150 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2152 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2153 if (value == 3) { /* ddl@rock-chips.com: torch */
2154 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2156 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2158 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2162 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2167 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2169 struct i2c_client *client = v4l2_get_subdevdata(sd);
2170 struct sensor *sensor = to_sensor(client);
2171 const struct v4l2_queryctrl *qctrl;
2173 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2177 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2183 case V4L2_CID_BRIGHTNESS:
2185 ctrl->value = sensor->info_priv.brightness;
2188 case V4L2_CID_SATURATION:
2190 ctrl->value = sensor->info_priv.saturation;
2193 case V4L2_CID_CONTRAST:
2195 ctrl->value = sensor->info_priv.contrast;
2198 case V4L2_CID_DO_WHITE_BALANCE:
2200 ctrl->value = sensor->info_priv.whiteBalance;
2203 case V4L2_CID_EXPOSURE:
2205 ctrl->value = sensor->info_priv.exposure;
2208 case V4L2_CID_HFLIP:
2210 ctrl->value = sensor->info_priv.mirror;
2213 case V4L2_CID_VFLIP:
2215 ctrl->value = sensor->info_priv.flip;
2226 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2228 struct i2c_client *client = v4l2_get_subdevdata(sd);
2229 struct sensor *sensor = to_sensor(client);
2230 struct soc_camera_device *icd = client->dev.platform_data;
2231 const struct v4l2_queryctrl *qctrl;
2234 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2238 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2244 #if CONFIG_SENSOR_Brightness
2245 case V4L2_CID_BRIGHTNESS:
2247 if (ctrl->value != sensor->info_priv.brightness)
2249 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2253 sensor->info_priv.brightness = ctrl->value;
2258 #if CONFIG_SENSOR_Exposure
2259 case V4L2_CID_EXPOSURE:
2261 if (ctrl->value != sensor->info_priv.exposure)
2263 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2267 sensor->info_priv.exposure = ctrl->value;
2272 #if CONFIG_SENSOR_Saturation
2273 case V4L2_CID_SATURATION:
2275 if (ctrl->value != sensor->info_priv.saturation)
2277 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2281 sensor->info_priv.saturation = ctrl->value;
2286 #if CONFIG_SENSOR_Contrast
2287 case V4L2_CID_CONTRAST:
2289 if (ctrl->value != sensor->info_priv.contrast)
2291 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2295 sensor->info_priv.contrast = ctrl->value;
2300 #if CONFIG_SENSOR_WhiteBalance
2301 case V4L2_CID_DO_WHITE_BALANCE:
2303 if (ctrl->value != sensor->info_priv.whiteBalance)
2305 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2309 sensor->info_priv.whiteBalance = ctrl->value;
2314 #if CONFIG_SENSOR_Mirror
2315 case V4L2_CID_HFLIP:
2317 if (ctrl->value != sensor->info_priv.mirror)
2319 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2321 sensor->info_priv.mirror = ctrl->value;
2326 #if CONFIG_SENSOR_Flip
2327 case V4L2_CID_VFLIP:
2329 if (ctrl->value != sensor->info_priv.flip)
2331 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2333 sensor->info_priv.flip = ctrl->value;
2344 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2346 const struct v4l2_queryctrl *qctrl;
2347 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2348 struct sensor *sensor = to_sensor(client);
2350 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2354 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2358 switch (ext_ctrl->id)
2360 case V4L2_CID_SCENE:
2362 ext_ctrl->value = sensor->info_priv.scene;
2365 case V4L2_CID_EFFECT:
2367 ext_ctrl->value = sensor->info_priv.effect;
2370 case V4L2_CID_ZOOM_ABSOLUTE:
2372 ext_ctrl->value = sensor->info_priv.digitalzoom;
2375 case V4L2_CID_ZOOM_RELATIVE:
2379 case V4L2_CID_FOCUS_ABSOLUTE:
2381 ext_ctrl->value = sensor->info_priv.focus;
2384 case V4L2_CID_FOCUS_RELATIVE:
2388 case V4L2_CID_FLASH:
2390 ext_ctrl->value = sensor->info_priv.flash;
2398 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2400 const struct v4l2_queryctrl *qctrl;
2401 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2402 struct sensor *sensor = to_sensor(client);
2405 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2409 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2414 switch (ext_ctrl->id)
2416 #if CONFIG_SENSOR_Scene
2417 case V4L2_CID_SCENE:
2419 if (ext_ctrl->value != sensor->info_priv.scene)
2421 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2423 sensor->info_priv.scene = ext_ctrl->value;
2428 #if CONFIG_SENSOR_Effect
2429 case V4L2_CID_EFFECT:
2431 if (ext_ctrl->value != sensor->info_priv.effect)
2433 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2435 sensor->info_priv.effect= ext_ctrl->value;
2440 #if CONFIG_SENSOR_DigitalZoom
2441 case V4L2_CID_ZOOM_ABSOLUTE:
2443 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2446 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2448 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2450 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2452 sensor->info_priv.digitalzoom += val_offset;
2454 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2459 case V4L2_CID_ZOOM_RELATIVE:
2461 if (ext_ctrl->value)
2463 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2465 sensor->info_priv.digitalzoom += ext_ctrl->value;
2467 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2472 #if CONFIG_SENSOR_Focus
2473 case V4L2_CID_FOCUS_ABSOLUTE:
2475 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2478 if (ext_ctrl->value != sensor->info_priv.focus)
2480 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2482 sensor->info_priv.focus += val_offset;
2487 case V4L2_CID_FOCUS_RELATIVE:
2489 if (ext_ctrl->value)
2491 sensor->info_priv.focus += ext_ctrl->value;
2493 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2498 #if CONFIG_SENSOR_Flash
2499 case V4L2_CID_FLASH:
2501 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2503 sensor->info_priv.flash = ext_ctrl->value;
2505 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2516 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2518 struct i2c_client *client = v4l2_get_subdevdata(sd);
2519 struct soc_camera_device *icd = client->dev.platform_data;
2520 int i, error_cnt=0, error_idx=-1;
2523 for (i=0; i<ext_ctrl->count; i++) {
2524 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2531 error_idx = ext_ctrl->count;
2533 if (error_idx != -1) {
2534 ext_ctrl->error_idx = error_idx;
2541 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2543 struct i2c_client *client = v4l2_get_subdevdata(sd);
2544 struct soc_camera_device *icd = client->dev.platform_data;
2545 int i, error_cnt=0, error_idx=-1;
2548 for (i=0; i<ext_ctrl->count; i++) {
2549 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2556 error_idx = ext_ctrl->count;
2558 if (error_idx != -1) {
2559 ext_ctrl->error_idx = error_idx;
2566 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2567 * this wasn't our capture interface, so, we wait for the right one */
2568 static int sensor_video_probe(struct soc_camera_device *icd,
2569 struct i2c_client *client)
2573 struct sensor *sensor = to_sensor(client);
2575 /* We must have a parent by now. And it cannot be a wrong one.
2576 * So this entire test is completely redundant. */
2577 if (!icd->dev.parent ||
2578 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2581 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2583 goto sensor_video_probe_err;
2587 // ret = sensor_write(client, 0x12, 0x80);
2590 // SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2593 mdelay(50); //delay 5 microseconds
2595 /* check if it is an sensor sensor */
2596 ret = sensor_read(client, 0x01, &pid);
2598 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2600 goto sensor_video_probe_err;
2603 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2604 if (pid == SENSOR_ID) {
2605 sensor->model = SENSOR_V4L2_IDENT;
2607 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2609 goto sensor_video_probe_err;
2614 sensor_video_probe_err:
2619 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2621 struct i2c_client *client = v4l2_get_subdevdata(sd);
2622 struct soc_camera_device *icd = client->dev.platform_data;
2623 struct sensor *sensor = to_sensor(client);
2625 #if CONFIG_SENSOR_Flash
2629 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2632 case RK29_CAM_SUBDEV_DEACTIVATE:
2634 sensor_deactivate(client);
2638 case RK29_CAM_SUBDEV_IOREQUEST:
2640 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2641 if (sensor->sensor_io_request != NULL) {
2642 sensor->sensor_gpio_res = NULL;
2643 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2644 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2645 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2646 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2649 if (sensor->sensor_gpio_res == NULL) {
2650 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2652 goto sensor_ioctl_end;
2655 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2657 goto sensor_ioctl_end;
2659 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2661 #if CONFIG_SENSOR_Flash
2662 if (sensor->sensor_gpio_res) {
2663 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2664 for (i = 0; i < icd->ops->num_controls; i++) {
2665 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2666 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2669 sensor->info_priv.flash = 0xff;
2670 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2678 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2686 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2687 enum v4l2_mbus_pixelcode *code)
2689 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2692 *code = sensor_colour_fmts[index].code;
2695 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2696 .init = sensor_init,
2697 .g_ctrl = sensor_g_control,
2698 .s_ctrl = sensor_s_control,
2699 .g_ext_ctrls = sensor_g_ext_controls,
2700 .s_ext_ctrls = sensor_s_ext_controls,
2701 .g_chip_ident = sensor_g_chip_ident,
2702 .ioctl = sensor_ioctl,
2705 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2706 .s_mbus_fmt = sensor_s_fmt,
2707 .g_mbus_fmt = sensor_g_fmt,
2708 .try_mbus_fmt = sensor_try_fmt,
2709 .enum_mbus_fmt = sensor_enum_fmt,
2712 static struct v4l2_subdev_ops sensor_subdev_ops = {
2713 .core = &sensor_subdev_core_ops,
2714 .video = &sensor_subdev_video_ops,
2717 static int sensor_probe(struct i2c_client *client,
2718 const struct i2c_device_id *did)
2720 struct sensor *sensor;
2721 struct soc_camera_device *icd = client->dev.platform_data;
2722 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2723 struct soc_camera_link *icl;
2726 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2728 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2732 icl = to_soc_camera_link(icd);
2734 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2738 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2739 dev_warn(&adapter->dev,
2740 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2744 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2748 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2750 /* Second stage probe - when a capture adapter is there */
2751 icd->ops = &sensor_ops;
2752 sensor->info_priv.fmt = sensor_colour_fmts[0];
2753 #if CONFIG_SENSOR_I2C_NOSCHED
2754 atomic_set(&sensor->tasklock_cnt,0);
2757 ret = sensor_video_probe(icd, client);
2760 i2c_set_clientdata(client, NULL);
2764 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2768 static int sensor_remove(struct i2c_client *client)
2770 struct sensor *sensor = to_sensor(client);
2771 struct soc_camera_device *icd = client->dev.platform_data;
2774 i2c_set_clientdata(client, NULL);
2775 client->driver = NULL;
2781 static const struct i2c_device_id sensor_id[] = {
2782 {SENSOR_NAME_STRING(), 0 },
2785 MODULE_DEVICE_TABLE(i2c, sensor_id);
2787 static struct i2c_driver sensor_i2c_driver = {
2789 .name = SENSOR_NAME_STRING(),
2791 .probe = sensor_probe,
2792 .remove = sensor_remove,
2793 .id_table = sensor_id,
2796 static int __init sensor_mod_init(void)
2798 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2799 return i2c_add_driver(&sensor_i2c_driver);
2802 static void __exit sensor_mod_exit(void)
2804 i2c_del_driver(&sensor_i2c_driver);
2807 device_initcall_sync(sensor_mod_init);
2808 module_exit(sensor_mod_exit);
2810 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2811 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2812 MODULE_LICENSE("GPL");