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>
24 #include <linux/vmalloc.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 sensor_init_width /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT sensor_init_height
56 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
57 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
58 #define SENSOR_BUS_PARAM sensor_init_busparam
60 #define CONFIG_SENSOR_WhiteBalance 0
61 #define CONFIG_SENSOR_Brightness 0
62 #define CONFIG_SENSOR_Contrast 0
63 #define CONFIG_SENSOR_Saturation 0
64 #define CONFIG_SENSOR_Effect 1
65 #define CONFIG_SENSOR_Scene 0
66 #define CONFIG_SENSOR_DigitalZoom 0
67 #define CONFIG_SENSOR_Focus 0
68 #define CONFIG_SENSOR_Exposure 0
69 #define CONFIG_SENSOR_Flash 0
70 #define CONFIG_SENSOR_Mirror 0
71 #define CONFIG_SENSOR_Flip 0
73 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
74 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
75 #define CONFIG_SENSOR_I2C_NOSCHED 0
76 #define CONFIG_SENSOR_I2C_RDWRCHK 0
78 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
79 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
80 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
81 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
82 #define COLOR_TEMPERATURE_OFFICE_DN 3500
83 #define COLOR_TEMPERATURE_OFFICE_UP 5000
84 #define COLOR_TEMPERATURE_HOME_DN 2500
85 #define COLOR_TEMPERATURE_HOME_UP 3500
87 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
88 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
90 #define SENSOR_AF_IS_ERR (0x00<<0)
91 #define SENSOR_AF_IS_OK (0x01<<0)
92 #define SENSOR_INIT_IS_ERR (0x00<<28)
93 #define SENSOR_INIT_IS_OK (0x01<<28)
100 /* init 640X480 VGA */
101 static struct reginfo sensor_init_data[] =
106 {0x13,0x17}, // #anti_black sun
107 {0x16,0xcf}, // #0xb6
109 {0x20,0x00}, // #P_BNKT
110 {0x21,0x01}, // #P_HBNKT
111 {0x22,0x01}, // #P_ROWFIL
112 {0x23,0x01}, // #P_VBNKT
114 {0x40,0x00}, // #0x8b
115 {0x41,0x00}, // #0x96
116 {0x42,0x00}, // #0xda
117 {0x43,0x00}, // #0x83
121 {0x11,0x14}, // # 6fps at lowlux
122 {0x12,0x78}, // # D65 target 0x74
123 {0x13,0x78}, // # CWF target 0x74
124 {0x14,0x78}, // # A target 0x74
127 {0x40,0x50}, // # Max x8
129 {0x41,0x20}, // #AG_TOP1 0x28
130 {0x42,0x20}, // #AG_TOP0 0x28
131 {0x43,0x00}, // #AG_MIN1 0x08
132 {0x44,0x00}, // #AG_MIN0 0x08
133 {0x45,0x00}, // #G50_dec 0x09
134 {0x46,0x0a}, // #G33_dec 0x17
135 {0x47,0x10}, // #G25_dec 0x1d
136 {0x48,0x13}, // #G20_dec 0x21
137 {0x49,0x15}, // #G12_dec 0x23
138 {0x4a,0x18}, // #G09_dec 0x24
139 {0x4b,0x1a}, // #G06_dec 0x26
140 {0x4c,0x1d}, // #G03_dec 0x27
141 {0x4d,0x20}, // #G100_inc 0x27
142 {0x4e,0x10}, // #G50_inc 0x1a
143 {0x4f,0x0a}, // #G33_inc 0x14
144 {0x50,0x08}, // #G25_inc 0x11
145 {0x51,0x06}, // #G20_inc 0x0f
146 {0x52,0x05}, // #G12_inc 0x0d
147 {0x53,0x04}, // #G09_inc 0x0c
148 {0x54,0x02}, // #G06_inc 0x0a
149 {0x55,0x01}, // #G03_inc 0x09
158 {0x15,0xfe}, // # R gain Top
159 {0x16,0x70}, // # R gain bottom 0x80
160 {0x17,0xea}, // # B gain Top
161 {0x18,0x80}, // # B gain bottom
162 {0x19,0xa0}, // # Cr top value
163 {0x1a,0x60}, // # Cr bottom value
164 {0x1b,0xa0}, // # Cb top value
165 {0x1c,0x60}, // # Cb bottom value
168 {0x20,0xe8}, // # AWB luminous top value
169 {0x21,0x20}, // # AWB luminous bottom value
174 {0x27,0x10}, // # ST for outdoor enable
175 {0x28,0x1a}, // # ST for outdoor disable
176 {0x29,0xb8}, // # AWB R gain at outdoor
177 {0x2a,0x94}, // # AWB B gain at outdoor
205 {0x63,0x98}, // # R D30 to D20
206 {0x64,0xa8}, // # B D30 to D20
207 {0x65,0x98}, // # R D20 to D30
208 {0x66,0xa8}, // # B D20 to D30
209 {0x67,0xc8}, // # R D65 to D30
210 {0x68,0x9f}, // # B D65 to D30
211 {0x69,0xc8}, // # R D30 to D65
212 {0x6a,0x9f}, // # B D30 to D65
221 //ading Register Setting
228 {0x46,0x11}, // # left R gain[7:4], right R gain[3:0]
229 {0x47,0x23}, // # top R gain[7:4], bottom R gain[3:0]
230 {0x48,0x10}, // # left Gr gain[7:4], right Gr gain[3:0]
231 {0x49,0x12}, // # top Gr gain[7:4], bottom Gr gain[3:0]
232 {0x4a,0x01}, // # left Gb gain[7:4], right Gb gain[3:0]
233 {0x4b,0x12}, // # top Gb gain[7:4], bottom Gb gain[3:0]
234 {0x4c,0x00}, // # left B gain[7:4], right B gain[3:0]
235 {0x4d,0x11}, // # top B gain[7:4], bottom B gain[3:0]
236 {0x4e,0x04}, // # X-axis center high[3:2], Y-axis center high[1:0]
237 {0x4f,0x50}, // # X-axis center low[7:0]
238 {0x50,0xf6}, // # Y-axis center low[7:0]
239 {0x51,0x80}, // # Shading Center Gain
240 {0x52,0x00}, // # Shading R Offset
241 {0x53,0x00}, // # Shading Gr Offset
242 {0x54,0x00}, // # Shading Gb Offset
243 {0x55,0x00}, // # Shading B Offset
248 {0x32,0xA }, // #0x10
249 {0x33,0x1E}, // #0x27
250 {0x34,0x42}, // #0x48
251 {0x35,0x5E}, // #0x62
252 {0x36,0x74}, // #0x77
253 {0x37,0x86}, // #0x88
254 {0x38,0x96}, // #0x97
255 {0x39,0xA4}, // #0xA5
256 {0x3a,0xB1}, // #0xB2
257 {0x3b,0xC8}, // #0xC9
258 {0x3c,0xDC}, // #0xDB
259 {0x3d,0xEF}, // #0xED
260 {0x3e,0xF8}, // #0xF7
261 {0x3f,0xFF}, // #0xFF
263 //lor matrix (D65) - Daylight
264 {0x71,0x3b}, // #0x3a
265 {0x72,0xca}, // #0xc9
266 {0x73,0xfb}, // #0xfe
267 {0x74,0x0f}, // #0x10
268 {0x75,0x22}, // #0x23
269 {0x76,0x0f}, // #0x0b
270 {0x77,0xf7}, // #0xfb
271 {0x78,0xc7}, // #0xce
272 {0x79,0x42}, // #0x38
274 //lor matrix (D30) - CWF
275 {0x7a,0x3b}, // #0x39
276 {0x7b,0xcb}, // #0xcd
277 {0x7c,0xfa}, // #0xfa
278 {0x7d,0x0e}, // #0x0a
279 {0x7e,0x21}, // #0x29
280 {0x7f,0x11}, // #0x0c
281 {0x80,0xf4}, // #0xf5
282 {0x81,0xc4}, // #0xc7
283 {0x82,0x48}, // #0x44
285 //lor matrix (D20) - A
286 {0x83,0x3a}, // #0x3a
287 {0x84,0xcd}, // #0xcc
288 {0x85,0xf9}, // #0xfa
289 {0x86,0x15}, // #0xfe
290 {0x87,0x26}, // #0x3a
291 {0x88,0x05}, // #0x08
292 {0x89,0xed}, // #0xf9
293 {0x8a,0xbb}, // #0xc3
294 {0x8b,0x57}, // #0x44
297 {0x17,0xC8}, // # DPCNRCTRL
298 {0x18,0x18}, // # DPTHR
299 {0x19,0x48}, // # [7:6] G DP Number Thr @ Dark | [5:0] DPTHRMIN
300 {0x1A,0x48}, // # [7:6] G DP Number Thr @ Normal | [5:0] DPTHRMAX
301 {0x1B,0x24}, // # DPTHRSLP( [7:4] @ Normal | [3:0] @ Dark )
302 {0x1C,0x00}, // # NRTHR
303 {0x1D,0x48}, // # [7:6] C DP Number Thr @ Dark | [5:0] NRTHRMIN 0x48
304 {0x1E,0x48}, // # [7:6] C DP Number Thr @ Normal | [5:0] NRTHRMAX
305 {0x1F,0x68}, // # NRTHRSLP( [7:4] @ Normal | [3:0] @ Dark ) 0x20
306 {0x20,0x04}, // # IllumiInfo STRTNOR
307 {0x21,0x0f}, // # IllumiInfo STRTDRK
309 {0x56,0x10}, // # lowlux shading enable
310 {0x57,0x92}, // # lowlux shading
311 {0x58,0x00}, // # lowlux shading on
314 {0x90,0x18}, // # upper gain
315 {0x91,0x18}, // # down gain
316 {0x92,0x04}, // # upper coring value
317 {0x96,0x04}, // # down coring value
319 {0x9f,0x10}, // # Yeugain
320 {0xa0,0x10}, // # Yedgain9
321 {0xa9,0x12}, // # Cr saturation
322 {0xaa,0x12}, // # Cb saturation
323 {0xb9,0x10}, // # 0x13 lowlux color
324 {0xba,0x20}, // # 0x10 lowlux color
326 {0xdd,0x4f}, // # ENHCTRL5
327 {0xde,0xba}, // # NOIZCTRL
360 /* 640X480 VGA @30fps for both preview & capture. */
361 static struct reginfo sensor_vga[] =
379 static struct reginfo sensor_cif[] =
385 static struct reginfo sensor_qvga[] =
391 static struct reginfo sensor_qcif[] =
396 static struct reginfo sensor_ClrFmt_YUYV[]=
402 static struct reginfo sensor_ClrFmt_UYVY[]=
409 #if CONFIG_SENSOR_WhiteBalance
410 static struct reginfo sensor_WhiteB_Auto[]=
412 {0x84, 0x6C}, //Contrast 4
436 {0x0f, 0x4a}, //Saturation 3
448 {0x4f, 0x2e}, //Brightness 3
462 /* Cloudy Colour Temperature : 6500K - 8000K */
463 static struct reginfo sensor_WhiteB_Cloudy[]=
465 {0x7C,0x04}, //Contrast 5
499 {0x4f,0x3a}, //Saturation 4
505 {0x4f, 0x2e}, //Brightness 3
518 /* ClearDay Colour Temperature : 5000K - 6500K */
519 static struct reginfo sensor_WhiteB_ClearDay[]=
522 {0x7C,0x04}, //Contrast 5
556 {0x4f,0x3a}, //Saturation 4
562 {0x4f, 0x2e}, //Brightness 3
575 /* Office Colour Temperature : 3500K - 5000K */
576 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
579 {0x84, 0x6C}, //Contrast 4
603 {0x0f, 0x4a}, //Saturation 3
615 {0x4f, 0x2e}, //Brightness 3
631 /* Home Colour Temperature : 2500K - 3500K */
632 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
635 {0x84, 0x6C}, //Contrast 4
659 {0x0f, 0x4a}, //Saturation 3
671 {0x4f, 0x2e}, //Brightness 3
684 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
685 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
689 #if CONFIG_SENSOR_Brightness
690 static struct reginfo sensor_Brightness0[]=
693 {0x3301, 0xff},//bit[7]:1, enable SDE
700 static struct reginfo sensor_Brightness1[]=
703 {0x3301, 0xff},//bit[7]:1, enable SDE
710 static struct reginfo sensor_Brightness2[]=
713 {0x3301, 0xff},//bit[7]:1, enable SDE
720 static struct reginfo sensor_Brightness3[]=
723 {0x3301, 0xff},//bit[7]:1, enable SDE
730 static struct reginfo sensor_Brightness4[]=
733 {0x3301, 0xff},//bit[7]:1, enable SDE
740 static struct reginfo sensor_Brightness5[]=
743 {0x3301, 0xff},//bit[7]:1, enable SDE
744 {0x3391, 0x04}, //bit[2] enable
745 {0x3390, 0x41}, //bit[3] sign of brightness
749 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
750 sensor_Brightness4, sensor_Brightness5,NULL,
755 #if CONFIG_SENSOR_Effect
756 static struct reginfo sensor_Effect_Normal[] =
765 static struct reginfo sensor_Effect_WandB[] =
775 static struct reginfo sensor_Effect_Sepia[] =
784 static struct reginfo sensor_Effect_Negative[] =
794 static struct reginfo sensor_Effect_Bluish[] =
804 static struct reginfo sensor_Effect_Green[] =
813 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
814 /*sensor_Effect_Bluish,*/ sensor_Effect_Green,NULL,
817 #if CONFIG_SENSOR_Exposure
818 static struct reginfo sensor_Exposure0[]=
823 static struct reginfo sensor_Exposure1[]=
828 static struct reginfo sensor_Exposure2[]=
833 static struct reginfo sensor_Exposure3[]=
838 static struct reginfo sensor_Exposure4[]=
843 static struct reginfo sensor_Exposure5[]=
848 static struct reginfo sensor_Exposure6[]=
853 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
854 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
857 #if CONFIG_SENSOR_Saturation
858 static struct reginfo sensor_Saturation0[]=
863 static struct reginfo sensor_Saturation1[]=
868 static struct reginfo sensor_Saturation2[]=
872 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
875 #if CONFIG_SENSOR_Contrast
876 static struct reginfo sensor_Contrast0[]=
881 static struct reginfo sensor_Contrast1[]=
886 static struct reginfo sensor_Contrast2[]=
891 static struct reginfo sensor_Contrast3[]=
896 static struct reginfo sensor_Contrast4[]=
902 static struct reginfo sensor_Contrast5[]=
907 static struct reginfo sensor_Contrast6[]=
911 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
912 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
916 #if CONFIG_SENSOR_Mirror
917 static struct reginfo sensor_MirrorOn[]=
922 static struct reginfo sensor_MirrorOff[]=
926 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
928 #if CONFIG_SENSOR_Flip
929 static struct reginfo sensor_FlipOn[]=
934 static struct reginfo sensor_FlipOff[]=
938 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
941 #if CONFIG_SENSOR_Scene
942 static struct reginfo sensor_SceneAuto[] =
947 static struct reginfo sensor_SceneNight[] =
951 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
954 #if CONFIG_SENSOR_DigitalZoom
955 static struct reginfo sensor_Zoom0[] =
960 static struct reginfo sensor_Zoom1[] =
965 static struct reginfo sensor_Zoom2[] =
971 static struct reginfo sensor_Zoom3[] =
975 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
977 static const struct v4l2_querymenu sensor_menus[] =
979 #if CONFIG_SENSOR_WhiteBalance
980 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
981 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
982 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
985 #if CONFIG_SENSOR_Effect
986 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
987 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
988 /* { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,*/{ .id = V4L2_CID_EFFECT, .index = 4, .name = "aqua", .reserved = 0,},
991 #if CONFIG_SENSOR_Scene
992 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
995 #if CONFIG_SENSOR_Flash
996 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
997 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1001 static const struct v4l2_queryctrl sensor_controls[] =
1003 #if CONFIG_SENSOR_WhiteBalance
1005 .id = V4L2_CID_DO_WHITE_BALANCE,
1006 .type = V4L2_CTRL_TYPE_MENU,
1007 .name = "White Balance Control",
1015 #if CONFIG_SENSOR_Brightness
1017 .id = V4L2_CID_BRIGHTNESS,
1018 .type = V4L2_CTRL_TYPE_INTEGER,
1019 .name = "Brightness Control",
1027 #if CONFIG_SENSOR_Effect
1029 .id = V4L2_CID_EFFECT,
1030 .type = V4L2_CTRL_TYPE_MENU,
1031 .name = "Effect Control",
1039 #if CONFIG_SENSOR_Exposure
1041 .id = V4L2_CID_EXPOSURE,
1042 .type = V4L2_CTRL_TYPE_INTEGER,
1043 .name = "Exposure Control",
1051 #if CONFIG_SENSOR_Saturation
1053 .id = V4L2_CID_SATURATION,
1054 .type = V4L2_CTRL_TYPE_INTEGER,
1055 .name = "Saturation Control",
1063 #if CONFIG_SENSOR_Contrast
1065 .id = V4L2_CID_CONTRAST,
1066 .type = V4L2_CTRL_TYPE_INTEGER,
1067 .name = "Contrast Control",
1075 #if CONFIG_SENSOR_Mirror
1077 .id = V4L2_CID_HFLIP,
1078 .type = V4L2_CTRL_TYPE_BOOLEAN,
1079 .name = "Mirror Control",
1087 #if CONFIG_SENSOR_Flip
1089 .id = V4L2_CID_VFLIP,
1090 .type = V4L2_CTRL_TYPE_BOOLEAN,
1091 .name = "Flip Control",
1099 #if CONFIG_SENSOR_Scene
1101 .id = V4L2_CID_SCENE,
1102 .type = V4L2_CTRL_TYPE_MENU,
1103 .name = "Scene Control",
1111 #if CONFIG_SENSOR_DigitalZoom
1113 .id = V4L2_CID_ZOOM_RELATIVE,
1114 .type = V4L2_CTRL_TYPE_INTEGER,
1115 .name = "DigitalZoom Control",
1121 .id = V4L2_CID_ZOOM_ABSOLUTE,
1122 .type = V4L2_CTRL_TYPE_INTEGER,
1123 .name = "DigitalZoom Control",
1131 #if CONFIG_SENSOR_Focus
1133 .id = V4L2_CID_FOCUS_RELATIVE,
1134 .type = V4L2_CTRL_TYPE_INTEGER,
1135 .name = "Focus Control",
1141 .id = V4L2_CID_FOCUS_ABSOLUTE,
1142 .type = V4L2_CTRL_TYPE_INTEGER,
1143 .name = "Focus Control",
1147 .default_value = 125,
1151 #if CONFIG_SENSOR_Flash
1153 .id = V4L2_CID_FLASH,
1154 .type = V4L2_CTRL_TYPE_MENU,
1155 .name = "Flash Control",
1164 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1165 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1166 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1167 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1168 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1169 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1170 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1171 static int sensor_resume(struct soc_camera_device *icd);
1172 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1173 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1174 #if CONFIG_SENSOR_Effect
1175 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1177 #if CONFIG_SENSOR_WhiteBalance
1178 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1180 static int sensor_deactivate(struct i2c_client *client);
1182 static struct soc_camera_ops sensor_ops =
1184 .suspend = sensor_suspend,
1185 .resume = sensor_resume,
1186 .set_bus_param = sensor_set_bus_param,
1187 .query_bus_param = sensor_query_bus_param,
1188 .controls = sensor_controls,
1189 .menus = sensor_menus,
1190 .num_controls = ARRAY_SIZE(sensor_controls),
1191 .num_menus = ARRAY_SIZE(sensor_menus),
1194 /* only one fixed colorspace per pixelcode */
1195 struct sensor_datafmt {
1196 enum v4l2_mbus_pixelcode code;
1197 enum v4l2_colorspace colorspace;
1200 /* Find a data format by a pixel code in an array */
1201 static const struct sensor_datafmt *sensor_find_datafmt(
1202 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1206 for (i = 0; i < n; i++)
1207 if (fmt[i].code == code)
1213 static const struct sensor_datafmt sensor_colour_fmts[] = {
1214 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1215 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1218 typedef struct sensor_info_priv_s
1232 unsigned char mirror; /* HFLIP */
1233 unsigned char flip; /* VFLIP */
1234 unsigned int winseqe_cur_addr;
1235 struct sensor_datafmt fmt;
1236 unsigned int funmodule_state;
1238 } sensor_info_priv_t;
1242 struct v4l2_subdev subdev;
1243 struct i2c_client *client;
1244 sensor_info_priv_t info_priv;
1245 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1246 #if CONFIG_SENSOR_I2C_NOSCHED
1247 atomic_t tasklock_cnt;
1249 struct rk29camera_platform_data *sensor_io_request;
1250 struct rk29camera_gpio_res *sensor_gpio_res;
1253 static struct sensor* to_sensor(const struct i2c_client *client)
1255 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1258 static int sensor_task_lock(struct i2c_client *client, int lock)
1260 #if CONFIG_SENSOR_I2C_NOSCHED
1262 struct sensor *sensor = to_sensor(client);
1265 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1266 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1267 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1271 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1272 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1273 goto sensor_task_lock_err;
1278 atomic_add(1, &sensor->tasklock_cnt);
1280 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1281 atomic_sub(1, &sensor->tasklock_cnt);
1283 if (atomic_read(&sensor->tasklock_cnt) == 0)
1288 sensor_task_lock_err:
1296 /* sensor register write */
1297 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1301 struct i2c_msg msg[1];
1303 buf[0] = reg & 0xFF;
1306 msg->addr = client->addr;
1307 msg->flags = client->flags;
1309 msg->len = sizeof(buf);
1310 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1311 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1316 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1317 err = i2c_transfer(client->adapter, msg, 1);
1322 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1330 /* sensor register read */
1331 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1336 struct i2c_msg msg[2];
1338 //buf[0] = reg >> 8;
1340 buf[1] = reg & 0xFF;
1342 msg[0].addr = client->addr;
1343 msg[0].flags = client->flags;
1345 msg[0].len = sizeof(buf);
1346 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1347 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1349 msg[1].addr = client->addr;
1350 msg[1].flags = client->flags|I2C_M_RD;
1353 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1354 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1358 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1359 err = i2c_transfer(client->adapter, msg, 2);
1365 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1373 /* write a array of registers */
1375 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1380 while (regarray[i].reg != 0)
1382 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1385 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1393 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1398 while (regarray[i].reg != 0)
1400 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1403 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1406 err = sensor_read(client, regarray[i].reg, &val_read);
1407 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1413 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1415 struct soc_camera_link *icl = to_soc_camera_link(icd);
1418 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1421 case Sensor_PowerDown:
1423 if (icl->powerdown) {
1424 ret = icl->powerdown(icd->pdev, on);
1425 if (ret == RK29_CAM_IO_SUCCESS) {
1429 icl->reset(icd->pdev);
1431 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1433 goto sensor_power_end;
1440 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1441 struct sensor *sensor = to_sensor(client);
1443 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1444 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1450 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1457 static s32 sensor_init_width = 640;
1458 static s32 sensor_init_height = 480;
1459 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
1460 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1461 static struct reginfo* sensor_init_data_p = NULL;
1462 static struct reginfo* sensor_init_winseq_p = NULL;
1463 static struct reginfo* sensor_init_winseq_board = NULL;
1464 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1466 struct i2c_client *client = v4l2_get_subdevdata(sd);
1467 struct soc_camera_device *icd = client->dev.platform_data;
1468 struct sensor *sensor = to_sensor(client);
1469 const struct v4l2_queryctrl *qctrl;
1470 const struct sensor_datafmt *fmt;
1472 int ret,pid = 0,i = 0,j=0;
1473 struct rk29camera_platform_data* tmp_plat_data =(struct rk29camera_platform_data*)val;
1474 sensor_init_data_p = sensor_init_data;
1475 sensor_init_winseq_p = sensor_vga;
1476 sensor_init_width = 640;
1477 sensor_init_height = 480;
1478 if (tmp_plat_data != NULL && (u32)tmp_plat_data != 1) {
1479 for(i = 0;i < RK_CAM_NUM;i++){
1480 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1481 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1485 if(tmp_plat_data && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1486 //user has defined the init data
1488 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1489 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1490 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1491 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1493 sensor_init_data_p = sensor_init_data;
1495 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1496 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1499 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1500 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1501 if(sensor_init_winseq_board)
1503 vfree(sensor_init_winseq_board);
1504 sensor_init_winseq_board = NULL;
1506 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1507 if(!sensor_init_winseq_board)
1508 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1509 for(j = 0;j< tmp_winseq_size;j++){
1510 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1511 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1513 sensor_init_winseq_p = sensor_init_winseq_board;
1515 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1516 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1518 //init width,height,bus,pixelcode
1519 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1520 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1521 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1522 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1523 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1524 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1525 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1526 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1528 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1530 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1532 goto sensor_INIT_ERR;
1536 if (sensor_task_lock(client,1)<0)
1537 goto sensor_INIT_ERR;
1538 // ret = sensor_write(client, 0x12, 0x80);
1541 // SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1543 // goto sensor_INIT_ERR;
1546 // mdelay(5); //delay 5 microseconds
1548 for(i = 0; i < sizeof(sensor_init_data)/2;i++){
1550 // ret = sensor_write(client, sensor_init_data + i*2, sensor_init_data + i*2 + 1);
1551 // printk("write to reg[0x%x] 0x%x\n",sensor_init_data[i].reg,sensor_init_data[i].val);
1552 ret = sensor_write(client, sensor_init_data_p[i].reg, sensor_init_data_p[i].val);
1553 //ret = sensor_write_array(client, sensor_init_data);
1556 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1557 goto sensor_INIT_ERR;
1559 // sensor_read(client,sensor_init_data[i].reg,&tmp);
1560 // printk("read from reg[0x%x] 0x%x\n",sensor_init_data[i].reg,tmp);
1562 sensor_task_lock(client,0);
1564 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1565 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1567 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1569 goto sensor_INIT_ERR;
1571 sensor->info_priv.fmt = *fmt;
1573 /* sensor sensor information for initialization */
1574 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1576 sensor->info_priv.whiteBalance = qctrl->default_value;
1577 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1579 sensor->info_priv.brightness = qctrl->default_value;
1580 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1582 sensor->info_priv.effect = qctrl->default_value;
1583 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1585 sensor->info_priv.exposure = qctrl->default_value;
1587 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1589 sensor->info_priv.saturation = qctrl->default_value;
1590 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1592 sensor->info_priv.contrast = qctrl->default_value;
1593 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1595 sensor->info_priv.mirror = qctrl->default_value;
1596 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1598 sensor->info_priv.flip = qctrl->default_value;
1599 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1601 sensor->info_priv.scene = qctrl->default_value;
1602 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1604 sensor->info_priv.digitalzoom = qctrl->default_value;
1606 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1607 #if CONFIG_SENSOR_Focus
1609 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1611 sensor->info_priv.focus = qctrl->default_value;
1614 #if CONFIG_SENSOR_Flash
1615 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1617 sensor->info_priv.flash = qctrl->default_value;
1620 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);
1621 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1624 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1625 sensor_task_lock(client,0);
1626 sensor_deactivate(client);
1630 static int sensor_deactivate(struct i2c_client *client)
1632 struct soc_camera_device *icd = client->dev.platform_data;
1633 struct sensor *sensor = to_sensor(client);
1635 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1637 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1638 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1640 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1641 icd->user_width = SENSOR_INIT_WIDTH;
1642 icd->user_height = SENSOR_INIT_HEIGHT;
1644 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1647 static struct reginfo sensor_power_down_sequence[]=
1651 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1654 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1657 if (pm_msg.event == PM_EVENT_SUSPEND) {
1658 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1659 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1661 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1664 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1666 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1671 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1677 static int sensor_resume(struct soc_camera_device *icd)
1681 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1683 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1687 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1693 static int sensor_set_bus_param(struct soc_camera_device *icd,
1694 unsigned long flags)
1700 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1702 struct soc_camera_link *icl = to_soc_camera_link(icd);
1703 unsigned long flags = SENSOR_BUS_PARAM;
1705 return soc_camera_apply_sensor_flags(icl, flags);
1708 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1710 struct i2c_client *client = v4l2_get_subdevdata(sd);
1711 struct soc_camera_device *icd = client->dev.platform_data;
1712 struct sensor *sensor = to_sensor(client);
1714 mf->width = icd->user_width;
1715 mf->height = icd->user_height;
1716 mf->code = sensor->info_priv.fmt.code;
1717 mf->colorspace = sensor->info_priv.fmt.colorspace;
1718 mf->field = V4L2_FIELD_NONE;
1722 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1726 if ((mf->width == 1024) && (mf->height == 768)) {
1728 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1730 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1732 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1734 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1739 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1743 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1747 if ((mf->width == 1280) && (mf->height == 720)) {
1749 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1754 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1757 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1759 struct i2c_client *client = v4l2_get_subdevdata(sd);
1760 struct sensor *sensor = to_sensor(client);
1761 const struct sensor_datafmt *fmt;
1762 struct reginfo *winseqe_set_addr=NULL;
1764 int ret=0, set_w,set_h,i;
1766 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1767 ARRAY_SIZE(sensor_colour_fmts));
1770 goto sensor_s_fmt_end;
1773 if (sensor->info_priv.fmt.code != mf->code) {
1776 case V4L2_MBUS_FMT_YUYV8_2X8:
1778 winseqe_set_addr = sensor_ClrFmt_YUYV;
1779 sensor_read(client, 0x3a, &readval);
1780 sensor_write(client,0x3a, readval&0xf7);
1781 sensor_read(client,0x3d,&readval);
1782 sensor_write(client,0x3d,readval&0xfe);
1785 case V4L2_MBUS_FMT_UYVY8_2X8:
1787 winseqe_set_addr = sensor_ClrFmt_UYVY;
1788 sensor_read(client, 0x3a, &readval);
1789 sensor_write(client,0x3a, readval|0x08);
1790 sensor_read(client,0x3d,&readval);
1791 sensor_write(client,0x3d,readval&0xfe);
1797 if (winseqe_set_addr != NULL) {
1798 sensor_write_array(client, winseqe_set_addr);
1799 sensor->info_priv.fmt.code = mf->code;
1800 sensor->info_priv.fmt.colorspace= mf->colorspace;
1801 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1803 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1810 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1812 winseqe_set_addr = sensor_qcif;
1816 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1818 winseqe_set_addr = sensor_qvga;
1822 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1824 winseqe_set_addr = sensor_cif;
1828 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1830 winseqe_set_addr = sensor_vga;
1836 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1837 set_w = SENSOR_INIT_WIDTH;
1838 set_h = SENSOR_INIT_HEIGHT;
1839 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1842 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
1844 printk("sizeof(winseqe_set_addr) %d\n",sizeof(winseqe_set_addr));
1845 for(i = 0; i < sizeof(winseqe_set_addr)/2;i++){
1846 ret |= sensor_write(client, winseqe_set_addr[i].reg, winseqe_set_addr[i].val);
1847 //ret |= sensor_write_array(client, winseqe_set_addr);
1849 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1850 goto sensor_s_fmt_end;
1853 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1856 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1860 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1870 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1872 struct i2c_client *client = v4l2_get_subdevdata(sd);
1873 struct sensor *sensor = to_sensor(client);
1874 const struct sensor_datafmt *fmt;
1877 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1878 ARRAY_SIZE(sensor_colour_fmts));
1880 fmt = &sensor->info_priv.fmt;
1881 mf->code = fmt->code;
1884 if (mf->height > SENSOR_MAX_HEIGHT)
1885 mf->height = SENSOR_MAX_HEIGHT;
1886 else if (mf->height < SENSOR_MIN_HEIGHT)
1887 mf->height = SENSOR_MIN_HEIGHT;
1889 if (mf->width > SENSOR_MAX_WIDTH)
1890 mf->width = SENSOR_MAX_WIDTH;
1891 else if (mf->width < SENSOR_MIN_WIDTH)
1892 mf->width = SENSOR_MIN_WIDTH;
1894 mf->colorspace = fmt->colorspace;
1898 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1900 struct i2c_client *client = v4l2_get_subdevdata(sd);
1902 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1905 if (id->match.addr != client->addr)
1908 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1913 #if CONFIG_SENSOR_Brightness
1914 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1916 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1918 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1920 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1922 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1924 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1927 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1931 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1935 #if CONFIG_SENSOR_Effect
1936 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1938 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1940 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1942 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1945 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1947 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1951 printk("value %d qctrl->minimum %d ",value, qctrl->minimum);
1952 printk("sizeof(sensor_EffectSeqe) %d\n",sizeof(sensor_EffectSeqe));
1953 printk("sizeof(sensor_EffectSeqe[%d]) %d\n",value - qctrl->minimum,sizeof(sensor_EffectSeqe[value - qctrl->minimum]));
1954 for(i = 0; i < 4; i++) {
1955 printk("sensor_EffectSeqe[%d][%d].reg 0x%x sensor_EffectSeqe[%d][%d].val 0x%x \n",
1956 value - qctrl->minimum, i, sensor_EffectSeqe[value - qctrl->minimum][i].reg,value - qctrl->minimum, i,sensor_EffectSeqe[value - qctrl->minimum][i].val);
1957 sensor_write(client, sensor_EffectSeqe[value - qctrl->minimum][i].reg, sensor_EffectSeqe[value - qctrl->minimum][i].val);
1962 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1966 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1970 #if CONFIG_SENSOR_Exposure
1971 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1973 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1975 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1977 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1979 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1981 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1984 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1988 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1992 #if CONFIG_SENSOR_Saturation
1993 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1995 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1997 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1999 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2001 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2003 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2006 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2010 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2014 #if CONFIG_SENSOR_Contrast
2015 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2017 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2019 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2021 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2023 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2025 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2028 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2032 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2036 #if CONFIG_SENSOR_Mirror
2037 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2039 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2041 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2043 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2045 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2047 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2050 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2054 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2058 #if CONFIG_SENSOR_Flip
2059 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2061 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2063 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2065 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2067 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2069 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2072 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2076 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2080 #if CONFIG_SENSOR_Scene
2081 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2083 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2085 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2087 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2089 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2091 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2094 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2098 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2102 #if CONFIG_SENSOR_WhiteBalance
2103 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2105 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2107 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2109 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2111 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2113 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2116 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2120 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2124 #if CONFIG_SENSOR_DigitalZoom
2125 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2127 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2128 struct sensor *sensor = to_sensor(client);
2129 const struct v4l2_queryctrl *qctrl_info;
2130 int digitalzoom_cur, digitalzoom_total;
2132 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2136 digitalzoom_cur = sensor->info_priv.digitalzoom;
2137 digitalzoom_total = qctrl_info->maximum;
2139 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2141 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2145 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2147 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2151 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2153 value = digitalzoom_total - digitalzoom_cur;
2156 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2158 value = 0 - digitalzoom_cur;
2161 digitalzoom_cur += value;
2163 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2165 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2167 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2170 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2177 #if CONFIG_SENSOR_Flash
2178 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2180 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2181 if (value == 3) { /* ddl@rock-chips.com: torch */
2182 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2184 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2186 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2190 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2195 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2197 struct i2c_client *client = v4l2_get_subdevdata(sd);
2198 struct sensor *sensor = to_sensor(client);
2199 const struct v4l2_queryctrl *qctrl;
2201 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2205 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2211 case V4L2_CID_BRIGHTNESS:
2213 ctrl->value = sensor->info_priv.brightness;
2216 case V4L2_CID_SATURATION:
2218 ctrl->value = sensor->info_priv.saturation;
2221 case V4L2_CID_CONTRAST:
2223 ctrl->value = sensor->info_priv.contrast;
2226 case V4L2_CID_DO_WHITE_BALANCE:
2228 ctrl->value = sensor->info_priv.whiteBalance;
2231 case V4L2_CID_EXPOSURE:
2233 ctrl->value = sensor->info_priv.exposure;
2236 case V4L2_CID_HFLIP:
2238 ctrl->value = sensor->info_priv.mirror;
2241 case V4L2_CID_VFLIP:
2243 ctrl->value = sensor->info_priv.flip;
2254 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2256 struct i2c_client *client = v4l2_get_subdevdata(sd);
2257 struct sensor *sensor = to_sensor(client);
2258 struct soc_camera_device *icd = client->dev.platform_data;
2259 const struct v4l2_queryctrl *qctrl;
2262 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2266 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2272 #if CONFIG_SENSOR_Brightness
2273 case V4L2_CID_BRIGHTNESS:
2275 if (ctrl->value != sensor->info_priv.brightness)
2277 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2281 sensor->info_priv.brightness = ctrl->value;
2286 #if CONFIG_SENSOR_Exposure
2287 case V4L2_CID_EXPOSURE:
2289 if (ctrl->value != sensor->info_priv.exposure)
2291 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2295 sensor->info_priv.exposure = ctrl->value;
2300 #if CONFIG_SENSOR_Saturation
2301 case V4L2_CID_SATURATION:
2303 if (ctrl->value != sensor->info_priv.saturation)
2305 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2309 sensor->info_priv.saturation = ctrl->value;
2314 #if CONFIG_SENSOR_Contrast
2315 case V4L2_CID_CONTRAST:
2317 if (ctrl->value != sensor->info_priv.contrast)
2319 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2323 sensor->info_priv.contrast = ctrl->value;
2328 #if CONFIG_SENSOR_WhiteBalance
2329 case V4L2_CID_DO_WHITE_BALANCE:
2331 if (ctrl->value != sensor->info_priv.whiteBalance)
2333 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2337 sensor->info_priv.whiteBalance = ctrl->value;
2342 #if CONFIG_SENSOR_Mirror
2343 case V4L2_CID_HFLIP:
2345 if (ctrl->value != sensor->info_priv.mirror)
2347 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2349 sensor->info_priv.mirror = ctrl->value;
2354 #if CONFIG_SENSOR_Flip
2355 case V4L2_CID_VFLIP:
2357 if (ctrl->value != sensor->info_priv.flip)
2359 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2361 sensor->info_priv.flip = ctrl->value;
2372 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2374 const struct v4l2_queryctrl *qctrl;
2375 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2376 struct sensor *sensor = to_sensor(client);
2378 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2382 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2386 switch (ext_ctrl->id)
2388 case V4L2_CID_SCENE:
2390 ext_ctrl->value = sensor->info_priv.scene;
2393 case V4L2_CID_EFFECT:
2395 ext_ctrl->value = sensor->info_priv.effect;
2398 case V4L2_CID_ZOOM_ABSOLUTE:
2400 ext_ctrl->value = sensor->info_priv.digitalzoom;
2403 case V4L2_CID_ZOOM_RELATIVE:
2407 case V4L2_CID_FOCUS_ABSOLUTE:
2409 ext_ctrl->value = sensor->info_priv.focus;
2412 case V4L2_CID_FOCUS_RELATIVE:
2416 case V4L2_CID_FLASH:
2418 ext_ctrl->value = sensor->info_priv.flash;
2426 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2428 const struct v4l2_queryctrl *qctrl;
2429 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2430 struct sensor *sensor = to_sensor(client);
2433 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2437 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2442 switch (ext_ctrl->id)
2444 #if CONFIG_SENSOR_Scene
2445 case V4L2_CID_SCENE:
2447 if (ext_ctrl->value != sensor->info_priv.scene)
2449 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2451 sensor->info_priv.scene = ext_ctrl->value;
2456 #if CONFIG_SENSOR_Effect
2457 case V4L2_CID_EFFECT:
2459 if (ext_ctrl->value != sensor->info_priv.effect)
2461 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2463 sensor->info_priv.effect= ext_ctrl->value;
2468 #if CONFIG_SENSOR_DigitalZoom
2469 case V4L2_CID_ZOOM_ABSOLUTE:
2471 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2474 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2476 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2478 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2480 sensor->info_priv.digitalzoom += val_offset;
2482 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2487 case V4L2_CID_ZOOM_RELATIVE:
2489 if (ext_ctrl->value)
2491 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2493 sensor->info_priv.digitalzoom += ext_ctrl->value;
2495 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2500 #if CONFIG_SENSOR_Focus
2501 case V4L2_CID_FOCUS_ABSOLUTE:
2503 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2506 if (ext_ctrl->value != sensor->info_priv.focus)
2508 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2510 sensor->info_priv.focus += val_offset;
2515 case V4L2_CID_FOCUS_RELATIVE:
2517 if (ext_ctrl->value)
2519 sensor->info_priv.focus += ext_ctrl->value;
2521 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2526 #if CONFIG_SENSOR_Flash
2527 case V4L2_CID_FLASH:
2529 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2531 sensor->info_priv.flash = ext_ctrl->value;
2533 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2544 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2546 struct i2c_client *client = v4l2_get_subdevdata(sd);
2547 struct soc_camera_device *icd = client->dev.platform_data;
2548 int i, error_cnt=0, error_idx=-1;
2551 for (i=0; i<ext_ctrl->count; i++) {
2552 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2559 error_idx = ext_ctrl->count;
2561 if (error_idx != -1) {
2562 ext_ctrl->error_idx = error_idx;
2569 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2571 struct i2c_client *client = v4l2_get_subdevdata(sd);
2572 struct soc_camera_device *icd = client->dev.platform_data;
2573 int i, error_cnt=0, error_idx=-1;
2576 for (i=0; i<ext_ctrl->count; i++) {
2577 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2584 error_idx = ext_ctrl->count;
2586 if (error_idx != -1) {
2587 ext_ctrl->error_idx = error_idx;
2594 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2595 * this wasn't our capture interface, so, we wait for the right one */
2596 static int sensor_video_probe(struct soc_camera_device *icd,
2597 struct i2c_client *client)
2601 struct sensor *sensor = to_sensor(client);
2603 /* We must have a parent by now. And it cannot be a wrong one.
2604 * So this entire test is completely redundant. */
2605 if (!icd->dev.parent ||
2606 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2609 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2611 goto sensor_video_probe_err;
2615 // ret = sensor_write(client, 0x12, 0x80);
2618 // SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2621 mdelay(50); //delay 5 microseconds
2623 /* check if it is an sensor sensor */
2624 ret = sensor_read(client, 0x01, &pid);
2626 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2628 goto sensor_video_probe_err;
2631 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2632 if (pid == SENSOR_ID) {
2633 sensor->model = SENSOR_V4L2_IDENT;
2635 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2637 goto sensor_video_probe_err;
2642 sensor_video_probe_err:
2647 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2649 struct i2c_client *client = v4l2_get_subdevdata(sd);
2650 struct soc_camera_device *icd = client->dev.platform_data;
2651 struct sensor *sensor = to_sensor(client);
2653 #if CONFIG_SENSOR_Flash
2657 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2660 case RK29_CAM_SUBDEV_DEACTIVATE:
2662 sensor_deactivate(client);
2666 case RK29_CAM_SUBDEV_IOREQUEST:
2668 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2669 if (sensor->sensor_io_request != NULL) {
2671 for(j = 0;j < RK_CAM_NUM;j++){
2672 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
2673 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
2674 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
2678 if(j == RK_CAM_NUM){
2679 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2681 goto sensor_ioctl_end;
2685 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2687 #if CONFIG_SENSOR_Flash
2688 if (sensor->sensor_gpio_res) {
2689 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2690 for (i = 0; i < icd->ops->num_controls; i++) {
2691 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2692 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2695 sensor->info_priv.flash = 0xff;
2696 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2704 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2712 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2713 enum v4l2_mbus_pixelcode *code)
2715 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2718 *code = sensor_colour_fmts[index].code;
2721 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2722 .init = sensor_init,
2723 .g_ctrl = sensor_g_control,
2724 .s_ctrl = sensor_s_control,
2725 .g_ext_ctrls = sensor_g_ext_controls,
2726 .s_ext_ctrls = sensor_s_ext_controls,
2727 .g_chip_ident = sensor_g_chip_ident,
2728 .ioctl = sensor_ioctl,
2731 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2732 .s_mbus_fmt = sensor_s_fmt,
2733 .g_mbus_fmt = sensor_g_fmt,
2734 .try_mbus_fmt = sensor_try_fmt,
2735 .enum_mbus_fmt = sensor_enum_fmt,
2738 static struct v4l2_subdev_ops sensor_subdev_ops = {
2739 .core = &sensor_subdev_core_ops,
2740 .video = &sensor_subdev_video_ops,
2743 static int sensor_probe(struct i2c_client *client,
2744 const struct i2c_device_id *did)
2746 struct sensor *sensor;
2747 struct soc_camera_device *icd = client->dev.platform_data;
2748 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2749 struct soc_camera_link *icl;
2752 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2754 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2758 icl = to_soc_camera_link(icd);
2760 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2764 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2765 dev_warn(&adapter->dev,
2766 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2770 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2774 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2776 /* Second stage probe - when a capture adapter is there */
2777 icd->ops = &sensor_ops;
2778 sensor->info_priv.fmt = sensor_colour_fmts[0];
2779 #if CONFIG_SENSOR_I2C_NOSCHED
2780 atomic_set(&sensor->tasklock_cnt,0);
2783 ret = sensor_video_probe(icd, client);
2786 i2c_set_clientdata(client, NULL);
2790 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2794 static int sensor_remove(struct i2c_client *client)
2796 struct sensor *sensor = to_sensor(client);
2797 struct soc_camera_device *icd = client->dev.platform_data;
2800 i2c_set_clientdata(client, NULL);
2801 client->driver = NULL;
2807 static const struct i2c_device_id sensor_id[] = {
2808 {SENSOR_NAME_STRING(), 0 },
2811 MODULE_DEVICE_TABLE(i2c, sensor_id);
2813 static struct i2c_driver sensor_i2c_driver = {
2815 .name = SENSOR_NAME_STRING(),
2817 .probe = sensor_probe,
2818 .remove = sensor_remove,
2819 .id_table = sensor_id,
2822 static int __init sensor_mod_init(void)
2824 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2825 return i2c_add_driver(&sensor_i2c_driver);
2828 static void __exit sensor_mod_exit(void)
2830 i2c_del_driver(&sensor_i2c_driver);
2833 device_initcall_sync(sensor_mod_init);
2834 module_exit(sensor_mod_exit);
2836 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2837 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2838 MODULE_LICENSE("GPL");