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 <mach/rk29_camera.h>
26 module_param(debug, int, S_IRUGO|S_IWUSR);
28 #define dprintk(level, fmt, arg...) do { \
30 printk(KERN_WARNING fmt , ## arg); } while (0)
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(0, format, ## __VA_ARGS__)
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_PIX_FMT_YUYV
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 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define 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)
99 /* init 640X480 VGA */
100 static struct reginfo sensor_init_data[] =
105 {0x13,0x17}, // #anti_black sun
106 {0x16,0xcf}, // #0xb6
108 {0x20,0x00}, // #P_BNKT
109 {0x21,0x01}, // #P_HBNKT
110 {0x22,0x01}, // #P_ROWFIL
111 {0x23,0x01}, // #P_VBNKT
113 {0x40,0x00}, // #0x8b
114 {0x41,0x00}, // #0x96
115 {0x42,0x00}, // #0xda
116 {0x43,0x00}, // #0x83
120 {0x11,0x14}, // # 6fps at lowlux
121 {0x12,0x78}, // # D65 target 0x74
122 {0x13,0x78}, // # CWF target 0x74
123 {0x14,0x78}, // # A target 0x74
126 {0x40,0x50}, // # Max x8
128 {0x41,0x20}, // #AG_TOP1 0x28
129 {0x42,0x20}, // #AG_TOP0 0x28
130 {0x43,0x00}, // #AG_MIN1 0x08
131 {0x44,0x00}, // #AG_MIN0 0x08
132 {0x45,0x00}, // #G50_dec 0x09
133 {0x46,0x0a}, // #G33_dec 0x17
134 {0x47,0x10}, // #G25_dec 0x1d
135 {0x48,0x13}, // #G20_dec 0x21
136 {0x49,0x15}, // #G12_dec 0x23
137 {0x4a,0x18}, // #G09_dec 0x24
138 {0x4b,0x1a}, // #G06_dec 0x26
139 {0x4c,0x1d}, // #G03_dec 0x27
140 {0x4d,0x20}, // #G100_inc 0x27
141 {0x4e,0x10}, // #G50_inc 0x1a
142 {0x4f,0x0a}, // #G33_inc 0x14
143 {0x50,0x08}, // #G25_inc 0x11
144 {0x51,0x06}, // #G20_inc 0x0f
145 {0x52,0x05}, // #G12_inc 0x0d
146 {0x53,0x04}, // #G09_inc 0x0c
147 {0x54,0x02}, // #G06_inc 0x0a
148 {0x55,0x01}, // #G03_inc 0x09
157 {0x15,0xfe}, // # R gain Top
158 {0x16,0x70}, // # R gain bottom 0x80
159 {0x17,0xea}, // # B gain Top
160 {0x18,0x80}, // # B gain bottom
161 {0x19,0xa0}, // # Cr top value
162 {0x1a,0x60}, // # Cr bottom value
163 {0x1b,0xa0}, // # Cb top value
164 {0x1c,0x60}, // # Cb bottom value
167 {0x20,0xe8}, // # AWB luminous top value
168 {0x21,0x20}, // # AWB luminous bottom value
173 {0x27,0x10}, // # ST for outdoor enable
174 {0x28,0x1a}, // # ST for outdoor disable
175 {0x29,0xb8}, // # AWB R gain at outdoor
176 {0x2a,0x94}, // # AWB B gain at outdoor
204 {0x63,0x98}, // # R D30 to D20
205 {0x64,0xa8}, // # B D30 to D20
206 {0x65,0x98}, // # R D20 to D30
207 {0x66,0xa8}, // # B D20 to D30
208 {0x67,0xc8}, // # R D65 to D30
209 {0x68,0x9f}, // # B D65 to D30
210 {0x69,0xc8}, // # R D30 to D65
211 {0x6a,0x9f}, // # B D30 to D65
220 //ading Register Setting
227 {0x46,0x11}, // # left R gain[7:4], right R gain[3:0]
228 {0x47,0x23}, // # top R gain[7:4], bottom R gain[3:0]
229 {0x48,0x10}, // # left Gr gain[7:4], right Gr gain[3:0]
230 {0x49,0x12}, // # top Gr gain[7:4], bottom Gr gain[3:0]
231 {0x4a,0x01}, // # left Gb gain[7:4], right Gb gain[3:0]
232 {0x4b,0x12}, // # top Gb gain[7:4], bottom Gb gain[3:0]
233 {0x4c,0x00}, // # left B gain[7:4], right B gain[3:0]
234 {0x4d,0x11}, // # top B gain[7:4], bottom B gain[3:0]
235 {0x4e,0x04}, // # X-axis center high[3:2], Y-axis center high[1:0]
236 {0x4f,0x50}, // # X-axis center low[7:0]
237 {0x50,0xf6}, // # Y-axis center low[7:0]
238 {0x51,0x80}, // # Shading Center Gain
239 {0x52,0x00}, // # Shading R Offset
240 {0x53,0x00}, // # Shading Gr Offset
241 {0x54,0x00}, // # Shading Gb Offset
242 {0x55,0x00}, // # Shading B Offset
247 {0x32,0xA }, // #0x10
248 {0x33,0x1E}, // #0x27
249 {0x34,0x42}, // #0x48
250 {0x35,0x5E}, // #0x62
251 {0x36,0x74}, // #0x77
252 {0x37,0x86}, // #0x88
253 {0x38,0x96}, // #0x97
254 {0x39,0xA4}, // #0xA5
255 {0x3a,0xB1}, // #0xB2
256 {0x3b,0xC8}, // #0xC9
257 {0x3c,0xDC}, // #0xDB
258 {0x3d,0xEF}, // #0xED
259 {0x3e,0xF8}, // #0xF7
260 {0x3f,0xFF}, // #0xFF
262 //lor matrix (D65) - Daylight
263 {0x71,0x3b}, // #0x3a
264 {0x72,0xca}, // #0xc9
265 {0x73,0xfb}, // #0xfe
266 {0x74,0x0f}, // #0x10
267 {0x75,0x22}, // #0x23
268 {0x76,0x0f}, // #0x0b
269 {0x77,0xf7}, // #0xfb
270 {0x78,0xc7}, // #0xce
271 {0x79,0x42}, // #0x38
273 //lor matrix (D30) - CWF
274 {0x7a,0x3b}, // #0x39
275 {0x7b,0xcb}, // #0xcd
276 {0x7c,0xfa}, // #0xfa
277 {0x7d,0x0e}, // #0x0a
278 {0x7e,0x21}, // #0x29
279 {0x7f,0x11}, // #0x0c
280 {0x80,0xf4}, // #0xf5
281 {0x81,0xc4}, // #0xc7
282 {0x82,0x48}, // #0x44
284 //lor matrix (D20) - A
285 {0x83,0x3a}, // #0x3a
286 {0x84,0xcd}, // #0xcc
287 {0x85,0xf9}, // #0xfa
288 {0x86,0x15}, // #0xfe
289 {0x87,0x26}, // #0x3a
290 {0x88,0x05}, // #0x08
291 {0x89,0xed}, // #0xf9
292 {0x8a,0xbb}, // #0xc3
293 {0x8b,0x57}, // #0x44
296 {0x17,0xC8}, // # DPCNRCTRL
297 {0x18,0x18}, // # DPTHR
298 {0x19,0x48}, // # [7:6] G DP Number Thr @ Dark | [5:0] DPTHRMIN
299 {0x1A,0x48}, // # [7:6] G DP Number Thr @ Normal | [5:0] DPTHRMAX
300 {0x1B,0x24}, // # DPTHRSLP( [7:4] @ Normal | [3:0] @ Dark )
301 {0x1C,0x00}, // # NRTHR
302 {0x1D,0x48}, // # [7:6] C DP Number Thr @ Dark | [5:0] NRTHRMIN 0x48
303 {0x1E,0x48}, // # [7:6] C DP Number Thr @ Normal | [5:0] NRTHRMAX
304 {0x1F,0x68}, // # NRTHRSLP( [7:4] @ Normal | [3:0] @ Dark ) 0x20
305 {0x20,0x04}, // # IllumiInfo STRTNOR
306 {0x21,0x0f}, // # IllumiInfo STRTDRK
308 {0x56,0x10}, // # lowlux shading enable
309 {0x57,0x92}, // # lowlux shading
310 {0x58,0x00}, // # lowlux shading on
313 {0x90,0x18}, // # upper gain
314 {0x91,0x18}, // # down gain
315 {0x92,0x04}, // # upper coring value
316 {0x96,0x04}, // # down coring value
318 {0x9f,0x10}, // # Yeugain
319 {0xa0,0x10}, // # Yedgain9
320 {0xa9,0x12}, // # Cr saturation
321 {0xaa,0x12}, // # Cb saturation
322 {0xb9,0x10}, // # 0x13 lowlux color
323 {0xba,0x20}, // # 0x10 lowlux color
325 {0xdd,0x4f}, // # ENHCTRL5
326 {0xde,0xba}, // # NOIZCTRL
359 /* 640X480 VGA @30fps for both preview & capture. */
360 static struct reginfo sensor_vga[] =
378 static struct reginfo sensor_cif[] =
384 static struct reginfo sensor_qvga[] =
390 static struct reginfo sensor_qcif[] =
395 static struct reginfo sensor_ClrFmt_YUYV[]=
400 static struct reginfo sensor_ClrFmt_UYVY[]=
406 #if CONFIG_SENSOR_WhiteBalance
407 static struct reginfo sensor_WhiteB_Auto[]=
409 {0x84, 0x6C}, //Contrast 4
433 {0x0f, 0x4a}, //Saturation 3
445 {0x4f, 0x2e}, //Brightness 3
459 /* Cloudy Colour Temperature : 6500K - 8000K */
460 static struct reginfo sensor_WhiteB_Cloudy[]=
462 {0x7C,0x04}, //Contrast 5
496 {0x4f,0x3a}, //Saturation 4
502 {0x4f, 0x2e}, //Brightness 3
515 /* ClearDay Colour Temperature : 5000K - 6500K */
516 static struct reginfo sensor_WhiteB_ClearDay[]=
519 {0x7C,0x04}, //Contrast 5
553 {0x4f,0x3a}, //Saturation 4
559 {0x4f, 0x2e}, //Brightness 3
572 /* Office Colour Temperature : 3500K - 5000K */
573 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
576 {0x84, 0x6C}, //Contrast 4
600 {0x0f, 0x4a}, //Saturation 3
612 {0x4f, 0x2e}, //Brightness 3
628 /* Home Colour Temperature : 2500K - 3500K */
629 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
632 {0x84, 0x6C}, //Contrast 4
656 {0x0f, 0x4a}, //Saturation 3
668 {0x4f, 0x2e}, //Brightness 3
681 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
682 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
686 #if CONFIG_SENSOR_Brightness
687 static struct reginfo sensor_Brightness0[]=
690 {0x3301, 0xff},//bit[7]:1, enable SDE
697 static struct reginfo sensor_Brightness1[]=
700 {0x3301, 0xff},//bit[7]:1, enable SDE
707 static struct reginfo sensor_Brightness2[]=
710 {0x3301, 0xff},//bit[7]:1, enable SDE
717 static struct reginfo sensor_Brightness3[]=
720 {0x3301, 0xff},//bit[7]:1, enable SDE
727 static struct reginfo sensor_Brightness4[]=
730 {0x3301, 0xff},//bit[7]:1, enable SDE
737 static struct reginfo sensor_Brightness5[]=
740 {0x3301, 0xff},//bit[7]:1, enable SDE
741 {0x3391, 0x04}, //bit[2] enable
742 {0x3390, 0x41}, //bit[3] sign of brightness
746 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
747 sensor_Brightness4, sensor_Brightness5,NULL,
752 #if CONFIG_SENSOR_Effect
753 static struct reginfo sensor_Effect_Normal[] =
762 static struct reginfo sensor_Effect_WandB[] =
772 static struct reginfo sensor_Effect_Sepia[] =
781 static struct reginfo sensor_Effect_Negative[] =
790 static struct reginfo sensor_Effect_Bluish[] =
800 static struct reginfo sensor_Effect_Green[] =
809 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
810 /*sensor_Effect_Bluish,*/ sensor_Effect_Green,NULL,
813 #if CONFIG_SENSOR_Exposure
814 static struct reginfo sensor_Exposure0[]=
819 static struct reginfo sensor_Exposure1[]=
824 static struct reginfo sensor_Exposure2[]=
829 static struct reginfo sensor_Exposure3[]=
834 static struct reginfo sensor_Exposure4[]=
839 static struct reginfo sensor_Exposure5[]=
844 static struct reginfo sensor_Exposure6[]=
849 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
850 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
853 #if CONFIG_SENSOR_Saturation
854 static struct reginfo sensor_Saturation0[]=
859 static struct reginfo sensor_Saturation1[]=
864 static struct reginfo sensor_Saturation2[]=
868 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
871 #if CONFIG_SENSOR_Contrast
872 static struct reginfo sensor_Contrast0[]=
877 static struct reginfo sensor_Contrast1[]=
882 static struct reginfo sensor_Contrast2[]=
887 static struct reginfo sensor_Contrast3[]=
892 static struct reginfo sensor_Contrast4[]=
898 static struct reginfo sensor_Contrast5[]=
903 static struct reginfo sensor_Contrast6[]=
907 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
908 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
912 #if CONFIG_SENSOR_Mirror
913 static struct reginfo sensor_MirrorOn[]=
918 static struct reginfo sensor_MirrorOff[]=
922 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
924 #if CONFIG_SENSOR_Flip
925 static struct reginfo sensor_FlipOn[]=
930 static struct reginfo sensor_FlipOff[]=
934 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
937 #if CONFIG_SENSOR_Scene
938 static struct reginfo sensor_SceneAuto[] =
943 static struct reginfo sensor_SceneNight[] =
947 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
950 #if CONFIG_SENSOR_DigitalZoom
951 static struct reginfo sensor_Zoom0[] =
956 static struct reginfo sensor_Zoom1[] =
961 static struct reginfo sensor_Zoom2[] =
967 static struct reginfo sensor_Zoom3[] =
971 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
973 static const struct v4l2_querymenu sensor_menus[] =
975 #if CONFIG_SENSOR_WhiteBalance
976 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
977 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
978 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
981 #if CONFIG_SENSOR_Effect
982 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
983 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
984 /* { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,*/{ .id = V4L2_CID_EFFECT, .index = 4, .name = "aqua", .reserved = 0,},
987 #if CONFIG_SENSOR_Scene
988 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
991 #if CONFIG_SENSOR_Flash
992 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
993 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
997 static const struct v4l2_queryctrl sensor_controls[] =
999 #if CONFIG_SENSOR_WhiteBalance
1001 .id = V4L2_CID_DO_WHITE_BALANCE,
1002 .type = V4L2_CTRL_TYPE_MENU,
1003 .name = "White Balance Control",
1011 #if CONFIG_SENSOR_Brightness
1013 .id = V4L2_CID_BRIGHTNESS,
1014 .type = V4L2_CTRL_TYPE_INTEGER,
1015 .name = "Brightness Control",
1023 #if CONFIG_SENSOR_Effect
1025 .id = V4L2_CID_EFFECT,
1026 .type = V4L2_CTRL_TYPE_MENU,
1027 .name = "Effect Control",
1035 #if CONFIG_SENSOR_Exposure
1037 .id = V4L2_CID_EXPOSURE,
1038 .type = V4L2_CTRL_TYPE_INTEGER,
1039 .name = "Exposure Control",
1047 #if CONFIG_SENSOR_Saturation
1049 .id = V4L2_CID_SATURATION,
1050 .type = V4L2_CTRL_TYPE_INTEGER,
1051 .name = "Saturation Control",
1059 #if CONFIG_SENSOR_Contrast
1061 .id = V4L2_CID_CONTRAST,
1062 .type = V4L2_CTRL_TYPE_INTEGER,
1063 .name = "Contrast Control",
1071 #if CONFIG_SENSOR_Mirror
1073 .id = V4L2_CID_HFLIP,
1074 .type = V4L2_CTRL_TYPE_BOOLEAN,
1075 .name = "Mirror Control",
1083 #if CONFIG_SENSOR_Flip
1085 .id = V4L2_CID_VFLIP,
1086 .type = V4L2_CTRL_TYPE_BOOLEAN,
1087 .name = "Flip Control",
1095 #if CONFIG_SENSOR_Scene
1097 .id = V4L2_CID_SCENE,
1098 .type = V4L2_CTRL_TYPE_MENU,
1099 .name = "Scene Control",
1107 #if CONFIG_SENSOR_DigitalZoom
1109 .id = V4L2_CID_ZOOM_RELATIVE,
1110 .type = V4L2_CTRL_TYPE_INTEGER,
1111 .name = "DigitalZoom Control",
1117 .id = V4L2_CID_ZOOM_ABSOLUTE,
1118 .type = V4L2_CTRL_TYPE_INTEGER,
1119 .name = "DigitalZoom Control",
1127 #if CONFIG_SENSOR_Focus
1129 .id = V4L2_CID_FOCUS_RELATIVE,
1130 .type = V4L2_CTRL_TYPE_INTEGER,
1131 .name = "Focus Control",
1137 .id = V4L2_CID_FOCUS_ABSOLUTE,
1138 .type = V4L2_CTRL_TYPE_INTEGER,
1139 .name = "Focus Control",
1143 .default_value = 125,
1147 #if CONFIG_SENSOR_Flash
1149 .id = V4L2_CID_FLASH,
1150 .type = V4L2_CTRL_TYPE_MENU,
1151 .name = "Flash Control",
1160 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1161 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1162 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1163 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1164 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1165 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1166 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1167 static int sensor_resume(struct soc_camera_device *icd);
1168 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1169 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1170 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1171 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1172 static int sensor_deactivate(struct i2c_client *client);
1174 static struct soc_camera_ops sensor_ops =
1176 .suspend = sensor_suspend,
1177 .resume = sensor_resume,
1178 .set_bus_param = sensor_set_bus_param,
1179 .query_bus_param = sensor_query_bus_param,
1180 .controls = sensor_controls,
1181 .menus = sensor_menus,
1182 .num_controls = ARRAY_SIZE(sensor_controls),
1183 .num_menus = ARRAY_SIZE(sensor_menus),
1186 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1187 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1188 .colorspace = _colorspace }
1190 #define JPG_FMT(_name, _depth, _fourcc) \
1191 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1193 static const struct soc_camera_data_format sensor_colour_formats[] = {
1194 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1195 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1198 typedef struct sensor_info_priv_s
1212 unsigned char mirror; /* HFLIP */
1213 unsigned char flip; /* VFLIP */
1214 unsigned int winseqe_cur_addr;
1215 unsigned int pixfmt;
1217 } sensor_info_priv_t;
1221 struct v4l2_subdev subdev;
1222 struct i2c_client *client;
1223 sensor_info_priv_t info_priv;
1224 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1225 #if CONFIG_SENSOR_I2C_NOSCHED
1226 atomic_t tasklock_cnt;
1228 struct rk29camera_platform_data *sensor_io_request;
1229 struct rk29camera_gpio_res *sensor_gpio_res;
1232 static struct sensor* to_sensor(const struct i2c_client *client)
1234 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1237 static int sensor_task_lock(struct i2c_client *client, int lock)
1239 #if CONFIG_SENSOR_I2C_NOSCHED
1241 struct sensor *sensor = to_sensor(client);
1244 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1245 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1246 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1250 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1251 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1252 goto sensor_task_lock_err;
1257 atomic_add(1, &sensor->tasklock_cnt);
1259 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1260 atomic_sub(1, &sensor->tasklock_cnt);
1262 if (atomic_read(&sensor->tasklock_cnt) == 0)
1267 sensor_task_lock_err:
1275 /* sensor register write */
1276 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1280 struct i2c_msg msg[1];
1282 buf[0] = reg & 0xFF;
1285 msg->addr = client->addr;
1286 msg->flags = client->flags;
1288 msg->len = sizeof(buf);
1289 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1290 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1295 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1296 err = i2c_transfer(client->adapter, msg, 1);
1301 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1309 /* sensor register read */
1310 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1315 struct i2c_msg msg[2];
1317 //buf[0] = reg >> 8;
1319 buf[1] = reg & 0xFF;
1321 msg[0].addr = client->addr;
1322 msg[0].flags = client->flags;
1324 msg[0].len = sizeof(buf);
1325 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1326 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1328 msg[1].addr = client->addr;
1329 msg[1].flags = client->flags|I2C_M_RD;
1332 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1333 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1337 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1338 err = i2c_transfer(client->adapter, msg, 2);
1344 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1352 /* write a array of registers */
1354 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1359 while (regarray[i].reg != 0)
1361 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1364 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1372 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1377 while (regarray[i].reg != 0)
1379 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1382 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1385 err = sensor_read(client, regarray[i].reg, &val_read);
1386 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1392 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1394 struct soc_camera_link *icl = to_soc_camera_link(icd);
1397 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1400 case Sensor_PowerDown:
1402 if (icl->powerdown) {
1403 ret = icl->powerdown(icd->pdev, on);
1404 if (ret == RK29_CAM_IO_SUCCESS) {
1408 icl->reset(icd->pdev);
1410 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1412 goto sensor_power_end;
1419 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1420 struct sensor *sensor = to_sensor(client);
1422 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1423 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1429 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1437 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1439 struct i2c_client *client = sd->priv;
1440 struct soc_camera_device *icd = client->dev.platform_data;
1441 struct sensor *sensor = to_sensor(client);
1442 const struct v4l2_queryctrl *qctrl;
1445 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1447 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1449 goto sensor_INIT_ERR;
1453 if (sensor_task_lock(client,1)<0)
1454 goto sensor_INIT_ERR;
1455 // ret = sensor_write(client, 0x12, 0x80);
1458 // SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1460 // goto sensor_INIT_ERR;
1463 mdelay(5); //delay 5 microseconds
1465 for(i = 0; i < sizeof(sensor_init_data)/2;i++){
1467 // ret = sensor_write(client, sensor_init_data + i*2, sensor_init_data + i*2 + 1);
1468 // printk("write to reg[0x%x] 0x%x\n",sensor_init_data[i].reg,sensor_init_data[i].val);
1469 ret = sensor_write(client, sensor_init_data[i].reg, sensor_init_data[i].val);
1470 //ret = sensor_write_array(client, sensor_init_data);
1473 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1474 goto sensor_INIT_ERR;
1476 // sensor_read(client,sensor_init_data[i].reg,&tmp);
1477 // printk("read from reg[0x%x] 0x%x\n",sensor_init_data[i].reg,tmp);
1479 sensor_task_lock(client,0);
1481 icd->user_width = SENSOR_INIT_WIDTH;
1482 icd->user_height = SENSOR_INIT_HEIGHT;
1483 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1484 sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
1486 /* sensor sensor information for initialization */
1487 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1489 sensor->info_priv.whiteBalance = qctrl->default_value;
1490 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1492 sensor->info_priv.brightness = qctrl->default_value;
1493 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1495 sensor->info_priv.effect = qctrl->default_value;
1496 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1498 sensor->info_priv.exposure = qctrl->default_value;
1500 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1502 sensor->info_priv.saturation = qctrl->default_value;
1503 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1505 sensor->info_priv.contrast = qctrl->default_value;
1506 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1508 sensor->info_priv.mirror = qctrl->default_value;
1509 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1511 sensor->info_priv.flip = qctrl->default_value;
1512 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1514 sensor->info_priv.scene = qctrl->default_value;
1515 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1517 sensor->info_priv.digitalzoom = qctrl->default_value;
1519 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1520 #if CONFIG_SENSOR_Focus
1522 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1524 sensor->info_priv.focus = qctrl->default_value;
1527 #if CONFIG_SENSOR_Flash
1528 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1530 sensor->info_priv.flash = qctrl->default_value;
1533 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);
1537 sensor_deactivate(client);
1541 static int sensor_deactivate(struct i2c_client *client)
1543 struct soc_camera_device *icd = client->dev.platform_data;
1545 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1547 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1548 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1550 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1551 icd->user_width = SENSOR_INIT_WIDTH;
1552 icd->user_height = SENSOR_INIT_HEIGHT;
1556 static struct reginfo sensor_power_down_sequence[]=
1560 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1563 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1566 if (pm_msg.event == PM_EVENT_SUSPEND) {
1567 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1568 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1570 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1573 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1575 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1580 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1586 static int sensor_resume(struct soc_camera_device *icd)
1590 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1592 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1596 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1602 static int sensor_set_bus_param(struct soc_camera_device *icd,
1603 unsigned long flags)
1609 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1611 struct soc_camera_link *icl = to_soc_camera_link(icd);
1612 unsigned long flags = SENSOR_BUS_PARAM;
1614 return soc_camera_apply_sensor_flags(icl, flags);
1617 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1619 struct i2c_client *client = sd->priv;
1620 struct soc_camera_device *icd = client->dev.platform_data;
1621 struct sensor *sensor = to_sensor(client);
1622 struct v4l2_pix_format *pix = &f->fmt.pix;
1624 pix->width = icd->user_width;
1625 pix->height = icd->user_height;
1626 pix->pixelformat = sensor->info_priv.pixfmt;
1627 pix->field = V4L2_FIELD_NONE;
1628 pix->colorspace = V4L2_COLORSPACE_JPEG;
1632 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_format *f)
1636 if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
1638 } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
1640 } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
1642 } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
1644 } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
1649 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1653 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_format *f)
1657 if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 720)) {
1659 } else if ((f->fmt.pix.width == 1920) && (f->fmt.pix.height == 1080)) {
1664 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1667 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1669 struct i2c_client *client = sd->priv;
1670 struct sensor *sensor = to_sensor(client);
1671 struct v4l2_pix_format *pix = &f->fmt.pix;
1672 struct reginfo *winseqe_set_addr=NULL;
1674 int ret=0, set_w,set_h,i;
1676 if (sensor->info_priv.pixfmt != pix->pixelformat) {
1677 switch (pix->pixelformat)
1679 case V4L2_PIX_FMT_YUYV:
1681 //winseqe_set_addr = sensor_ClrFmt_YUYV;
1682 sensor_read(client, 0x3a, &readval);
1683 sensor_write(client,0x3a, readval&0xf7);
1684 sensor_read(client,0x3d,&readval);
1685 sensor_write(client,0x3d,readval&0xfe);
1688 case V4L2_PIX_FMT_UYVY:
1690 //winseqe_set_addr = sensor_ClrFmt_UYVY;
1691 sensor_read(client, 0x3a, &readval);
1692 sensor_write(client,0x3a, readval|0x08);
1693 sensor_read(client,0x3d,&readval);
1694 sensor_write(client,0x3d,readval&0xfe);
1700 if (winseqe_set_addr != NULL) {
1701 sensor_write_array(client, winseqe_set_addr);
1702 sensor->info_priv.pixfmt = pix->pixelformat;
1704 SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1706 SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1707 // sensor->info_priv.pixfmt = pix->pixelformat;
1709 // SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1714 set_h = pix->height;
1716 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1718 winseqe_set_addr = sensor_qcif;
1722 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1724 winseqe_set_addr = sensor_qvga;
1728 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1730 winseqe_set_addr = sensor_cif;
1734 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1736 winseqe_set_addr = sensor_vga;
1742 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1743 set_w = SENSOR_INIT_WIDTH;
1744 set_h = SENSOR_INIT_HEIGHT;
1745 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1748 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
1750 printk("sizeof(winseqe_set_addr) %d\n",sizeof(winseqe_set_addr));
1751 for(i = 0; i < sizeof(winseqe_set_addr)/2;i++){
1752 ret |= sensor_write(client, winseqe_set_addr[i].reg, winseqe_set_addr[i].val);
1753 //ret |= sensor_write_array(client, winseqe_set_addr);
1755 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1756 goto sensor_s_fmt_end;
1759 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1762 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1766 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1770 pix->height = set_h;
1776 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1778 struct v4l2_pix_format *pix = &f->fmt.pix;
1779 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1780 pix->pixelformat == V4L2_PIX_FMT_YUYV;
1783 * With Bayer format enforce even side lengths, but let the user play
1784 * with the starting pixel
1787 if (pix->height > SENSOR_MAX_HEIGHT)
1788 pix->height = SENSOR_MAX_HEIGHT;
1789 else if (pix->height < SENSOR_MIN_HEIGHT)
1790 pix->height = SENSOR_MIN_HEIGHT;
1792 pix->height = ALIGN(pix->height, 2);
1794 if (pix->width > SENSOR_MAX_WIDTH)
1795 pix->width = SENSOR_MAX_WIDTH;
1796 else if (pix->width < SENSOR_MIN_WIDTH)
1797 pix->width = SENSOR_MIN_WIDTH;
1799 pix->width = ALIGN(pix->width, 2);
1804 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1806 struct i2c_client *client = sd->priv;
1808 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1811 if (id->match.addr != client->addr)
1814 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1819 #if CONFIG_SENSOR_Brightness
1820 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1822 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1824 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1826 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1828 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1830 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1833 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1837 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1841 #if CONFIG_SENSOR_Effect
1842 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1844 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1846 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1848 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1851 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1853 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1857 printk("value %d qctrl->minimum %d ",value, qctrl->minimum);
1858 printk("sizeof(sensor_EffectSeqe) %d\n",sizeof(sensor_EffectSeqe));
1859 printk("sizeof(sensor_EffectSeqe[%d]) %d\n",value - qctrl->minimum,sizeof(sensor_EffectSeqe[value - qctrl->minimum]));
1860 for(i = 0; i < 4; i++) {
1861 printk("sensor_EffectSeqe[%d][%d].reg 0x%x sensor_EffectSeqe[%d][%d].val 0x%x \n",
1862 value - qctrl->minimum, i, sensor_EffectSeqe[value - qctrl->minimum][i].reg,value - qctrl->minimum, i,sensor_EffectSeqe[value - qctrl->minimum][i].val);
1863 sensor_write(client, sensor_EffectSeqe[value - qctrl->minimum][i].reg, sensor_EffectSeqe[value - qctrl->minimum][i].val);
1868 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1872 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1876 #if CONFIG_SENSOR_Exposure
1877 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1879 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1881 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1883 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1885 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1887 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1890 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1894 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1898 #if CONFIG_SENSOR_Saturation
1899 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1901 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1903 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1905 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1907 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1909 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1912 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1916 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1920 #if CONFIG_SENSOR_Contrast
1921 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1923 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1925 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1927 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1929 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1931 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
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_Mirror
1943 static int sensor_set_mirror(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_MirrorSeqe[value - qctrl->minimum] != NULL)
1951 if (sensor_write_array(client, sensor_MirrorSeqe[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_Flip
1965 static int sensor_set_flip(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_FlipSeqe[value - qctrl->minimum] != NULL)
1973 if (sensor_write_array(client, sensor_FlipSeqe[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_Scene
1987 static int sensor_set_scene(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_SceneSeqe[value - qctrl->minimum] != NULL)
1995 if (sensor_write_array(client, sensor_SceneSeqe[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_WhiteBalance
2009 static int sensor_set_whiteBalance(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_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2017 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[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_DigitalZoom
2031 static int sensor_set_digitalzoom(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));
2034 struct sensor *sensor = to_sensor(client);
2035 const struct v4l2_queryctrl *qctrl_info;
2036 int digitalzoom_cur, digitalzoom_total;
2038 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2042 digitalzoom_cur = sensor->info_priv.digitalzoom;
2043 digitalzoom_total = qctrl_info->maximum;
2045 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2047 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2051 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2053 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2057 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2059 *value = digitalzoom_total - digitalzoom_cur;
2062 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2064 *value = 0 - digitalzoom_cur;
2067 digitalzoom_cur += *value;
2069 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2071 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2073 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2076 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2083 #if CONFIG_SENSOR_Flash
2084 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2086 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2087 if (value == 3) { /* ddl@rock-chips.com: torch */
2088 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2090 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2092 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2096 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2101 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2103 struct i2c_client *client = sd->priv;
2104 struct sensor *sensor = to_sensor(client);
2105 const struct v4l2_queryctrl *qctrl;
2107 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2111 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2117 case V4L2_CID_BRIGHTNESS:
2119 ctrl->value = sensor->info_priv.brightness;
2122 case V4L2_CID_SATURATION:
2124 ctrl->value = sensor->info_priv.saturation;
2127 case V4L2_CID_CONTRAST:
2129 ctrl->value = sensor->info_priv.contrast;
2132 case V4L2_CID_DO_WHITE_BALANCE:
2134 ctrl->value = sensor->info_priv.whiteBalance;
2137 case V4L2_CID_EXPOSURE:
2139 ctrl->value = sensor->info_priv.exposure;
2142 case V4L2_CID_HFLIP:
2144 ctrl->value = sensor->info_priv.mirror;
2147 case V4L2_CID_VFLIP:
2149 ctrl->value = sensor->info_priv.flip;
2160 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2162 struct i2c_client *client = sd->priv;
2163 struct sensor *sensor = to_sensor(client);
2164 struct soc_camera_device *icd = client->dev.platform_data;
2165 const struct v4l2_queryctrl *qctrl;
2168 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2172 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2178 #if CONFIG_SENSOR_Brightness
2179 case V4L2_CID_BRIGHTNESS:
2181 if (ctrl->value != sensor->info_priv.brightness)
2183 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2187 sensor->info_priv.brightness = ctrl->value;
2192 #if CONFIG_SENSOR_Exposure
2193 case V4L2_CID_EXPOSURE:
2195 if (ctrl->value != sensor->info_priv.exposure)
2197 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2201 sensor->info_priv.exposure = ctrl->value;
2206 #if CONFIG_SENSOR_Saturation
2207 case V4L2_CID_SATURATION:
2209 if (ctrl->value != sensor->info_priv.saturation)
2211 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2215 sensor->info_priv.saturation = ctrl->value;
2220 #if CONFIG_SENSOR_Contrast
2221 case V4L2_CID_CONTRAST:
2223 if (ctrl->value != sensor->info_priv.contrast)
2225 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2229 sensor->info_priv.contrast = ctrl->value;
2234 #if CONFIG_SENSOR_WhiteBalance
2235 case V4L2_CID_DO_WHITE_BALANCE:
2237 if (ctrl->value != sensor->info_priv.whiteBalance)
2239 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2243 sensor->info_priv.whiteBalance = ctrl->value;
2248 #if CONFIG_SENSOR_Mirror
2249 case V4L2_CID_HFLIP:
2251 if (ctrl->value != sensor->info_priv.mirror)
2253 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2255 sensor->info_priv.mirror = ctrl->value;
2260 #if CONFIG_SENSOR_Flip
2261 case V4L2_CID_VFLIP:
2263 if (ctrl->value != sensor->info_priv.flip)
2265 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2267 sensor->info_priv.flip = ctrl->value;
2278 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2280 const struct v4l2_queryctrl *qctrl;
2281 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2282 struct sensor *sensor = to_sensor(client);
2284 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2288 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2292 switch (ext_ctrl->id)
2294 case V4L2_CID_SCENE:
2296 ext_ctrl->value = sensor->info_priv.scene;
2299 case V4L2_CID_EFFECT:
2301 ext_ctrl->value = sensor->info_priv.effect;
2304 case V4L2_CID_ZOOM_ABSOLUTE:
2306 ext_ctrl->value = sensor->info_priv.digitalzoom;
2309 case V4L2_CID_ZOOM_RELATIVE:
2313 case V4L2_CID_FOCUS_ABSOLUTE:
2315 ext_ctrl->value = sensor->info_priv.focus;
2318 case V4L2_CID_FOCUS_RELATIVE:
2322 case V4L2_CID_FLASH:
2324 ext_ctrl->value = sensor->info_priv.flash;
2332 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2334 const struct v4l2_queryctrl *qctrl;
2335 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2336 struct sensor *sensor = to_sensor(client);
2339 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2343 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2348 switch (ext_ctrl->id)
2350 #if CONFIG_SENSOR_Scene
2351 case V4L2_CID_SCENE:
2353 if (ext_ctrl->value != sensor->info_priv.scene)
2355 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2357 sensor->info_priv.scene = ext_ctrl->value;
2362 #if CONFIG_SENSOR_Effect
2363 case V4L2_CID_EFFECT:
2365 if (ext_ctrl->value != sensor->info_priv.effect)
2367 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2369 sensor->info_priv.effect= ext_ctrl->value;
2374 #if CONFIG_SENSOR_DigitalZoom
2375 case V4L2_CID_ZOOM_ABSOLUTE:
2377 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2380 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2382 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2384 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2386 sensor->info_priv.digitalzoom += val_offset;
2388 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2393 case V4L2_CID_ZOOM_RELATIVE:
2395 if (ext_ctrl->value)
2397 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2399 sensor->info_priv.digitalzoom += ext_ctrl->value;
2401 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2406 #if CONFIG_SENSOR_Focus
2407 case V4L2_CID_FOCUS_ABSOLUTE:
2409 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2412 if (ext_ctrl->value != sensor->info_priv.focus)
2414 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2416 sensor->info_priv.focus += val_offset;
2421 case V4L2_CID_FOCUS_RELATIVE:
2423 if (ext_ctrl->value)
2425 sensor->info_priv.focus += ext_ctrl->value;
2427 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2432 #if CONFIG_SENSOR_Flash
2433 case V4L2_CID_FLASH:
2435 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2437 sensor->info_priv.flash = ext_ctrl->value;
2439 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2450 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2452 struct i2c_client *client = sd->priv;
2453 struct soc_camera_device *icd = client->dev.platform_data;
2454 int i, error_cnt=0, error_idx=-1;
2457 for (i=0; i<ext_ctrl->count; i++) {
2458 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2465 error_idx = ext_ctrl->count;
2467 if (error_idx != -1) {
2468 ext_ctrl->error_idx = error_idx;
2475 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2477 struct i2c_client *client = sd->priv;
2478 struct soc_camera_device *icd = client->dev.platform_data;
2479 int i, error_cnt=0, error_idx=-1;
2482 for (i=0; i<ext_ctrl->count; i++) {
2483 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2490 error_idx = ext_ctrl->count;
2492 if (error_idx != -1) {
2493 ext_ctrl->error_idx = error_idx;
2500 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2501 * this wasn't our capture interface, so, we wait for the right one */
2502 static int sensor_video_probe(struct soc_camera_device *icd,
2503 struct i2c_client *client)
2507 struct sensor *sensor = to_sensor(client);
2509 /* We must have a parent by now. And it cannot be a wrong one.
2510 * So this entire test is completely redundant. */
2511 if (!icd->dev.parent ||
2512 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2515 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2517 goto sensor_video_probe_err;
2521 // ret = sensor_write(client, 0x12, 0x80);
2524 // SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2527 mdelay(50); //delay 5 microseconds
2529 /* check if it is an sensor sensor */
2530 ret = sensor_read(client, 0x01, &pid);
2532 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2534 goto sensor_video_probe_err;
2537 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2538 if (pid == SENSOR_ID) {
2539 sensor->model = SENSOR_V4L2_IDENT;
2541 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2543 goto sensor_video_probe_err;
2546 icd->formats = sensor_colour_formats;
2547 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2551 sensor_video_probe_err:
2556 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2558 struct i2c_client *client = sd->priv;
2559 struct soc_camera_device *icd = client->dev.platform_data;
2560 struct sensor *sensor = to_sensor(client);
2562 #if CONFIG_SENSOR_Flash
2566 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2569 case RK29_CAM_SUBDEV_DEACTIVATE:
2571 sensor_deactivate(client);
2575 case RK29_CAM_SUBDEV_IOREQUEST:
2577 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2578 if (sensor->sensor_io_request != NULL) {
2579 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2580 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2581 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2582 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2583 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2584 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2587 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2589 goto sensor_ioctl_end;
2591 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2593 #if CONFIG_SENSOR_Flash
2594 if (sensor->sensor_gpio_res) {
2595 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2596 for (i = 0; i < icd->ops->num_controls; i++) {
2597 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2598 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2601 sensor->info_priv.flash = 0xff;
2602 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2610 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2618 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2619 .init = sensor_init,
2620 .g_ctrl = sensor_g_control,
2621 .s_ctrl = sensor_s_control,
2622 .g_ext_ctrls = sensor_g_ext_controls,
2623 .s_ext_ctrls = sensor_s_ext_controls,
2624 .g_chip_ident = sensor_g_chip_ident,
2625 .ioctl = sensor_ioctl,
2628 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2629 .s_fmt = sensor_s_fmt,
2630 .g_fmt = sensor_g_fmt,
2631 .try_fmt = sensor_try_fmt,
2634 static struct v4l2_subdev_ops sensor_subdev_ops = {
2635 .core = &sensor_subdev_core_ops,
2636 .video = &sensor_subdev_video_ops,
2639 static int sensor_probe(struct i2c_client *client,
2640 const struct i2c_device_id *did)
2642 struct sensor *sensor;
2643 struct soc_camera_device *icd = client->dev.platform_data;
2644 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2645 struct soc_camera_link *icl;
2648 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2650 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2654 icl = to_soc_camera_link(icd);
2656 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2660 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2661 dev_warn(&adapter->dev,
2662 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2666 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2670 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2672 /* Second stage probe - when a capture adapter is there */
2673 icd->ops = &sensor_ops;
2674 icd->y_skip_top = 0;
2675 #if CONFIG_SENSOR_I2C_NOSCHED
2676 atomic_set(&sensor->tasklock_cnt,0);
2679 ret = sensor_video_probe(icd, client);
2682 i2c_set_clientdata(client, NULL);
2686 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2690 static int sensor_remove(struct i2c_client *client)
2692 struct sensor *sensor = to_sensor(client);
2693 struct soc_camera_device *icd = client->dev.platform_data;
2696 i2c_set_clientdata(client, NULL);
2697 client->driver = NULL;
2703 static const struct i2c_device_id sensor_id[] = {
2704 {SENSOR_NAME_STRING(), 0 },
2707 MODULE_DEVICE_TABLE(i2c, sensor_id);
2709 static struct i2c_driver sensor_i2c_driver = {
2711 .name = SENSOR_NAME_STRING(),
2713 .probe = sensor_probe,
2714 .remove = sensor_remove,
2715 .id_table = sensor_id,
2718 static int __init sensor_mod_init(void)
2720 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2721 return i2c_add_driver(&sensor_i2c_driver);
2724 static void __exit sensor_mod_exit(void)
2726 i2c_del_driver(&sensor_i2c_driver);
2729 device_initcall_sync(sensor_mod_init);
2730 module_exit(sensor_mod_exit);
2732 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2733 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2734 MODULE_LICENSE("GPL");