2 o* Driver for MT9M001 CMOS Image Sensor from Micron
\r
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
\r
6 * This program is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License version 2 as
\r
8 * published by the Free Software Foundation.
\r
11 #include <linux/videodev2.h>
\r
12 #include <linux/slab.h>
\r
13 #include <linux/i2c.h>
\r
14 #include <linux/log2.h>
\r
15 #include <linux/platform_device.h>
\r
16 #include <linux/delay.h>
\r
17 #include <linux/circ_buf.h>
\r
18 #include <linux/miscdevice.h>
\r
19 #include <media/v4l2-common.h>
\r
20 #include <media/v4l2-chip-ident.h>
\r
21 #include <media/soc_camera.h>
\r
22 #include <mach/rk29_camera.h>
\r
25 module_param(debug, int, S_IRUGO|S_IWUSR);
\r
27 #define dprintk(level, fmt, arg...) do { \
\r
28 if (debug >= level) \
\r
29 printk(KERN_WARNING fmt , ## arg); } while (0)
\r
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
\r
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
\r
35 #define _CONS(a,b) a##b
\r
36 #define CONS(a,b) _CONS(a,b)
\r
39 #define _STR(x) __STR(x)
\r
40 #define STR(x) _STR(x)
\r
42 #define MIN(x,y) ((x<y) ? x: y)
\r
43 #define MAX(x,y) ((x>y) ? x: y)
\r
45 /* Sensor Driver Configuration */
\r
46 #define SENSOR_NAME sid130B
\r
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_SID130B
\r
48 #define SENSOR_ID 0x1B
\r
49 #define SENSOR_MIN_WIDTH 176
\r
50 #define SENSOR_MIN_HEIGHT 144
\r
51 #define SENSOR_MAX_WIDTH 1600
\r
52 #define SENSOR_MAX_HEIGHT 1200
\r
53 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
\r
54 #define SENSOR_INIT_HEIGHT 480
\r
55 #define SENSOR_INIT_WINSEQADR sensor_vga
\r
56 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
\r
58 #define CONFIG_SENSOR_WhiteBalance 1
\r
59 #define CONFIG_SENSOR_Brightness 0
\r
60 #define CONFIG_SENSOR_Contrast 0
\r
61 #define CONFIG_SENSOR_Saturation 0
\r
62 #define CONFIG_SENSOR_Effect 1
\r
63 #define CONFIG_SENSOR_Scene 0
\r
64 #define CONFIG_SENSOR_DigitalZoom 0
\r
65 #define CONFIG_SENSOR_Focus 0
\r
66 #define CONFIG_SENSOR_Exposure 0
\r
67 #define CONFIG_SENSOR_Flash 0
\r
68 #define CONFIG_SENSOR_Mirror 0
\r
69 #define CONFIG_SENSOR_Flip 0
\r
71 #define CONFIG_SENSOR_I2C_SPEED 80000 /* Hz */
\r
72 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
\r
73 #define CONFIG_SENSOR_I2C_NOSCHED 0
\r
74 #define CONFIG_SENSOR_I2C_RDWRCHK 0
\r
76 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
\r
77 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW|\
\r
78 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
\r
80 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
\r
81 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
\r
82 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
\r
83 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
\r
84 #define COLOR_TEMPERATURE_OFFICE_DN 3500
\r
85 #define COLOR_TEMPERATURE_OFFICE_UP 5000
\r
86 #define COLOR_TEMPERATURE_HOME_DN 2500
\r
87 #define COLOR_TEMPERATURE_HOME_UP 3500
\r
89 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
\r
90 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
\r
92 #define SENSOR_AF_IS_ERR (0x00<<0)
93 #define SENSOR_AF_IS_OK (0x01<<0)
94 #define SENSOR_INIT_IS_ERR (0x00<<28)
95 #define SENSOR_INIT_IS_OK (0x01<<28)
\r
103 /* init 352X288 SVGA */
\r
104 static struct reginfo sensor_init_data[] =
\r
107 {0x04, 0x00}, //Group A 0x10
\r
108 {0x05, 0x0F}, //UXGA Output
\r
113 {0x08, 0xa2}, //PLL off
\r
133 //Flicker - 50Hz - Still mode ,
\r
137 {0x23, 0x29},//15},
\r
139 {0x35, 0x50},//3c},
\r
141 //Flicker - 50Hz - Preview mode 24MHz MCLK
\r
144 {0x25, 0xe6},//10},
\r
145 {0x27, 0x0d},//4b},
\r
147 {0x34, 0x80},//64},
\r
153 {0x11, 0x0a}, //.0c
\r
162 {0x40, 0x40}, //Max Again //anyuan
\r
199 {0x92, 0x0c}, //0bank 0x11 °ú µ¿ÀÏ
\r
200 {0x95, 0x40}, //0 bank 0x40 °ú µ¿ÀÏ
\r
246 //CMA change -D65~A
\r
247 {0x53, 0xa1}, //AWB R Gain for D30 to D20
\r
248 {0x54, 0xc0}, //AWB B Gain for D30 to D20
\r
249 {0x55, 0xa1}, //AWB R Gain for D20 to D30
\r
250 {0x56, 0xc0}, //AWB B Gain for D20 to D30
\r
251 {0x57, 0xc8}, //AWB R Gain for D65 to D30
\r
252 {0x58, 0xa0}, //AWB B Gain for D65 to D30
\r
253 {0x59, 0xc8}, //AWB R Gain for D30 to D65
\r
254 {0x5A, 0xa0}, //AWB B Gain for D30 to D65
\r
320 {0x30, 0x88}, //DPCNRCTRL
\r
321 {0x31, 0x14}, //DPTHR @ AGAIN = 00
\r
322 {0x32, 0x10}, //DPTHR @ AGAIN = 20
\r
323 {0x33, 0x0c}, //DPTHR @ AGAIN = 40
\r
324 {0x34, 0x08}, //DPTHR @ AGAIN = 60
\r
325 {0x35, 0x04}, //DPTHR @ AGAIN = 80
\r
326 {0x36, 0x44}, //DPTHVRNG
\r
327 {0x37, 0x66}, //DPNUMBER
\r
328 {0x38, 0x00}, //0x00 // NRTHR0 @ AGAIN = 00
\r
329 {0x39, 0x04}, //0x0C // NRTHR1 @ AGAIN = 20
\r
330 {0x3A, 0x04}, //0x18 // NRTHR2 @ AGAIN = 40
\r
331 {0x3B, 0x2c}, //0x30 // NRTHR3 @ AGAIN = 60
\r
332 {0x3C, 0x3c}, // NRTHR4 @ AGAIN = 80
\r
333 {0x3D, 0x04}, //NRTHVRNG0 @ AGAIN = 00
\r
334 {0x3E, 0x04}, //NRTHVRNG1 @ AGAIN = 20
\r
335 {0x3F, 0x04}, //NRTHVRNG2 @ AGAIN = 40
\r
336 {0x40, 0x2c}, //NRTHVRNG3 @ AGAIN = 60
\r
337 {0x41, 0x3c}, //NRTHVRNG4 @ AGAIN = 80
\r
338 {0x42, 0xff}, //NRTHVRNGMAX
\r
339 {0x43, 0x40}, //NRTHRWGT
\r
340 {0x44, 0x40}, //BASELVL
\r
341 {0x45, 0x06}, //SHUMAXH
\r
342 {0x46, 0x40}, //SHUMAXL
\r
343 {0x47, 0x30}, //ILLUMITHDRK
\r
346 {0x50, 0x0a}, //0x00
\r
347 {0x51, 0x20}, //0x45
\r
348 {0x52, 0x12}, //0x24
\r
349 {0x53, 0x12}, //0x24
\r
351 {0x54, 0x22}, //0x00
\r
352 {0x55, 0x18}, //0x40
\r
353 {0x56, 0x08}, //0x10
\r
354 {0x57, 0x10}, //0x20
\r
356 {0x58, 0x22}, //0x00
\r
357 {0x59, 0x18}, //0x40
\r
358 {0x5A, 0x08}, //0x10
\r
359 {0x5B, 0x10}, //0x20
\r
361 {0x5C, 0x25}, //0x04
\r
362 {0x5D, 0x1a}, //0x55
\r
363 {0x5E, 0x12}, //0x25
\r
364 {0x5F, 0x10}, //0x20
\r
366 {0x60, 0x32}, //0x32
\r
367 {0x61, 0x20}, //20//
\r
369 // {0x63, 0x89 //8c R Center start gain
\r
370 // {0x66, 0x79 //B Center start gain 73
\r
371 {0x6B, 0x00}, //01 //01
\r
372 {0x6C, 0x01}, //22
\r
373 {0x6D, 0x23}, //22
\r
374 {0x6E, 0x55}, //55
\r
375 {0x6F, 0x55}, //77
\r
376 {0x70, 0x55}, //65
\r
377 {0x71, 0x00}, //01 //AB (6)
\r
378 {0x72, 0x01}, //23 (5)
\r
379 {0x73, 0x23}, //33 (4)
\r
380 {0x74, 0x44}, //45 (3)
\r
381 {0x75, 0x45}, //55 (2)
\r
382 {0x76, 0x66}, //55 (1)
\r
383 {0x77, 0x00}, //01 //AB (6)
\r
384 {0x78, 0x01}, //23 (5)
\r
385 {0x79, 0x23}, //33 (4)
\r
386 {0x7A, 0x44}, //45 (3)
\r
387 {0x7B, 0x45}, //55 (2)
\r
388 {0x7C, 0x66}, //55 (1)
\r
389 {0x7D, 0x00}, //00 //00
\r
390 {0x7E, 0x00}, //00 //00
\r
391 {0x7F, 0x12}, //11 //12
\r
392 {0x80, 0x33}, //33 //33 //44
\r
393 {0x81, 0x44}, //33 //33 //44
\r
394 {0x82, 0x55}, //22 //44 //45
\r
423 //Color Matrix for D65
\r
425 {0xC0, 0x2F}, // CMASB D20 or D30 or Dark Condition Color Matrix Selection
\r
441 {0xC0, 0x2F}, // CMASB D20 or D30 or Dark Condition Color Matrix Selection
\r
458 //Color Matrix for CWF
\r
475 //Color Matrix for A
\r
567 {0x50, 0x00}, //DARK GAMMA on/off
\r
620 {0xA1, 0x08}, //@ 0
\r
621 {0xA2, 0x10}, //@ 20
\r
622 {0xA3, 0x16}, //@ 40
\r
623 {0xA4, 0x20}, //@ 60
\r
624 {0xA5, 0x30}, //@ 80
\r
637 {0xB2, 0x38}, //color suppression start
\r
673 {0x91, 0x81}, //knee function selection/knee point H
\r
674 {0x92, 0x00}, //knee point L
\r
675 {0x93, 0x50}, //Knee gain
\r
676 {0x94, 0x41}, //[6:4]knee start H/[2:0]Knee END H
\r
677 {0x95, 0x7e}, //knee start L
\r
678 {0x96, 0x48}, //knee END L
\r
700 {0xB0, 0xc0}, //YGMACTRL
\r
701 {0xB1, 0x04}, //YGMASLOP
\r
702 {0xB8, 0x0f}, //DRKTHR1
\r
703 {0xB9, 0x10}, //DRKTHR2
\r
704 //{0xBA, 0x38}, //DRKTHR3
\r
705 //{0xBB, 0x39}, //DRKTHR4
\r
724 // edge value adjustment
\r
745 /* 1600X1200 UXGA */
\r
746 static struct reginfo sensor_uxga[] =
\r
759 /* 1280X1024 SXGA */
\r
760 static struct reginfo sensor_sxga[] =
\r
772 static struct reginfo sensor_xga[] =
\r
777 static struct reginfo sensor_svga[] =
\r
788 static struct reginfo sensor_vga[] =
\r
794 {0x94,0x02}, //0x02
\r
795 {0x95,0x80}, //0x80
\r
797 {0x97,0xe0}, //0xe0
\r
802 static struct reginfo sensor_cif[] =
\r
813 static struct reginfo sensor_qvga[] =
\r
824 static struct reginfo sensor_qcif[] =
\r
834 static struct reginfo sensor_ClrFmt_YUYV[]=
\r
839 static struct reginfo sensor_ClrFmt_UYVY[]=
\r
844 #if CONFIG_SENSOR_WhiteBalance
\r
845 static struct reginfo sensor_WhiteB_Auto[]={
\r
850 /* Cloudy Colour Temperature : 6500K - 8000K */
\r
851 static struct reginfo sensor_WhiteB_Cloudy[]=
\r
859 /* ClearDay Colour Temperature : 5000K - 6500K */
\r
860 static struct reginfo sensor_WhiteB_ClearDay[]=
\r
869 /* Office Colour Temperature : 3500K - 5000K */
\r
870 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
\r
878 /* Home Colour Temperature : 2500K - 3500K */
\r
879 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
\r
887 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
\r
888 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
\r
892 #if CONFIG_SENSOR_Brightness
\r
893 static struct reginfo sensor_Brightness0[]=
\r
902 static struct reginfo sensor_Brightness1[]=
\r
911 static struct reginfo sensor_Brightness2[]=
\r
920 static struct reginfo sensor_Brightness3[]=
\r
929 static struct reginfo sensor_Brightness4[]=
\r
938 static struct reginfo sensor_Brightness5[]=
\r
944 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
\r
945 sensor_Brightness4, sensor_Brightness5,NULL,
\r
950 #if CONFIG_SENSOR_Effect
\r
951 static struct reginfo sensor_Effect_Normal[] =
\r
958 static struct reginfo sensor_Effect_WandB[] =
\r
966 static struct reginfo sensor_Effect_Sepia[] =
\r
975 static struct reginfo sensor_Effect_Negative[] =
\r
981 static struct reginfo sensor_Effect_Bluish[] =
\r
991 static struct reginfo sensor_Effect_Green[] =
\r
1000 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
\r
1001 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
\r
1004 #if CONFIG_SENSOR_Exposure
\r
1005 static struct reginfo sensor_Exposure0[]=
\r
1011 static struct reginfo sensor_Exposure1[]=
\r
1017 static struct reginfo sensor_Exposure2[]=
\r
1023 static struct reginfo sensor_Exposure3[]=
\r
1029 static struct reginfo sensor_Exposure4[]=
\r
1035 static struct reginfo sensor_Exposure5[]=
\r
1041 static struct reginfo sensor_Exposure6[]=
\r
1047 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
\r
1048 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
\r
1051 #if CONFIG_SENSOR_Saturation
\r
1052 static struct reginfo sensor_Saturation0[]=
\r
1057 static struct reginfo sensor_Saturation1[]=
\r
1062 static struct reginfo sensor_Saturation2[]=
\r
1066 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
\r
1069 #if CONFIG_SENSOR_Contrast
\r
1070 static struct reginfo sensor_Contrast0[]=
\r
1075 static struct reginfo sensor_Contrast1[]=
\r
1080 static struct reginfo sensor_Contrast2[]=
\r
1085 static struct reginfo sensor_Contrast3[]=
\r
1090 static struct reginfo sensor_Contrast4[]=
\r
1096 static struct reginfo sensor_Contrast5[]=
\r
1101 static struct reginfo sensor_Contrast6[]=
\r
1105 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
\r
1106 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
\r
1110 #if CONFIG_SENSOR_Mirror
\r
1111 static struct reginfo sensor_MirrorOn[]=
\r
1116 static struct reginfo sensor_MirrorOff[]=
\r
1120 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
\r
1122 #if CONFIG_SENSOR_Flip
\r
1123 static struct reginfo sensor_FlipOn[]=
\r
1128 static struct reginfo sensor_FlipOff[]=
\r
1132 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
\r
1135 #if CONFIG_SENSOR_Scene
\r
1136 static struct reginfo sensor_SceneAuto[] =
\r
1145 static struct reginfo sensor_SceneNight[] =
\r
1153 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
\r
1156 #if CONFIG_SENSOR_DigitalZoom
\r
1157 static struct reginfo sensor_Zoom0[] =
\r
1162 static struct reginfo sensor_Zoom1[] =
\r
1167 static struct reginfo sensor_Zoom2[] =
\r
1173 static struct reginfo sensor_Zoom3[] =
\r
1177 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
\r
1179 static const struct v4l2_querymenu sensor_menus[] =
\r
1181 #if CONFIG_SENSOR_WhiteBalance
\r
1182 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
\r
1183 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
\r
1184 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
\r
1187 #if CONFIG_SENSOR_Effect
\r
1188 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
\r
1189 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
\r
1190 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
\r
1193 #if CONFIG_SENSOR_Scene
\r
1194 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
\r
1197 #if CONFIG_SENSOR_Flash
\r
1198 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
\r
1199 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
\r
1203 static const struct v4l2_queryctrl sensor_controls[] =
\r
1205 #if CONFIG_SENSOR_WhiteBalance
\r
1207 .id = V4L2_CID_DO_WHITE_BALANCE,
\r
1208 .type = V4L2_CTRL_TYPE_MENU,
\r
1209 .name = "White Balance Control",
\r
1213 .default_value = 0,
\r
1217 #if CONFIG_SENSOR_Brightness
\r
1219 .id = V4L2_CID_BRIGHTNESS,
\r
1220 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1221 .name = "Brightness Control",
\r
1225 .default_value = 0,
\r
1229 #if CONFIG_SENSOR_Effect
\r
1231 .id = V4L2_CID_EFFECT,
\r
1232 .type = V4L2_CTRL_TYPE_MENU,
\r
1233 .name = "Effect Control",
\r
1237 .default_value = 0,
\r
1241 #if CONFIG_SENSOR_Exposure
\r
1243 .id = V4L2_CID_EXPOSURE,
\r
1244 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1245 .name = "Exposure Control",
\r
1249 .default_value = 0,
\r
1253 #if CONFIG_SENSOR_Saturation
\r
1255 .id = V4L2_CID_SATURATION,
\r
1256 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1257 .name = "Saturation Control",
\r
1261 .default_value = 0,
\r
1265 #if CONFIG_SENSOR_Contrast
\r
1267 .id = V4L2_CID_CONTRAST,
\r
1268 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1269 .name = "Contrast Control",
\r
1273 .default_value = 0,
\r
1277 #if CONFIG_SENSOR_Mirror
\r
1279 .id = V4L2_CID_HFLIP,
\r
1280 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
1281 .name = "Mirror Control",
\r
1285 .default_value = 1,
\r
1289 #if CONFIG_SENSOR_Flip
\r
1291 .id = V4L2_CID_VFLIP,
\r
1292 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
1293 .name = "Flip Control",
\r
1297 .default_value = 1,
\r
1301 #if CONFIG_SENSOR_Scene
\r
1303 .id = V4L2_CID_SCENE,
\r
1304 .type = V4L2_CTRL_TYPE_MENU,
\r
1305 .name = "Scene Control",
\r
1309 .default_value = 0,
\r
1313 #if CONFIG_SENSOR_DigitalZoom
\r
1315 .id = V4L2_CID_ZOOM_RELATIVE,
\r
1316 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1317 .name = "DigitalZoom Control",
\r
1321 .default_value = 0,
\r
1323 .id = V4L2_CID_ZOOM_ABSOLUTE,
\r
1324 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1325 .name = "DigitalZoom Control",
\r
1329 .default_value = 0,
\r
1333 #if CONFIG_SENSOR_Focus
\r
1335 .id = V4L2_CID_FOCUS_RELATIVE,
\r
1336 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1337 .name = "Focus Control",
\r
1341 .default_value = 0,
\r
1343 .id = V4L2_CID_FOCUS_ABSOLUTE,
\r
1344 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1345 .name = "Focus Control",
\r
1349 .default_value = 125,
\r
1353 #if CONFIG_SENSOR_Flash
\r
1355 .id = V4L2_CID_FLASH,
\r
1356 .type = V4L2_CTRL_TYPE_MENU,
\r
1357 .name = "Flash Control",
\r
1361 .default_value = 0,
\r
1366 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
\r
1367 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
\r
1368 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
1369 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
1370 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
1371 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
1372 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
\r
1373 static int sensor_resume(struct soc_camera_device *icd);
\r
1374 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
\r
1375 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
\r
1376 #if CONFIG_SENSOR_Effect
\r
1377 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1379 #if CONFIG_SENSOR_WhiteBalance
\r
1380 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1382 static int sensor_deactivate(struct i2c_client *client);
\r
1384 static struct soc_camera_ops sensor_ops =
\r
1386 .suspend = sensor_suspend,
\r
1387 .resume = sensor_resume,
\r
1388 .set_bus_param = sensor_set_bus_param,
\r
1389 .query_bus_param = sensor_query_bus_param,
\r
1390 .controls = sensor_controls,
\r
1391 .menus = sensor_menus,
\r
1392 .num_controls = ARRAY_SIZE(sensor_controls),
\r
1393 .num_menus = ARRAY_SIZE(sensor_menus),
\r
1396 /* only one fixed colorspace per pixelcode */
1397 struct sensor_datafmt {
1398 enum v4l2_mbus_pixelcode code;
1399 enum v4l2_colorspace colorspace;
1402 /* Find a data format by a pixel code in an array */
1403 static const struct sensor_datafmt *sensor_find_datafmt(
1404 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1408 for (i = 0; i < n; i++)
1409 if (fmt[i].code == code)
1415 static const struct sensor_datafmt sensor_colour_fmts[] = {
1416 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1417 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1420 typedef struct sensor_info_priv_s
\r
1432 bool snap2preview;
\r
1433 bool video2preview;
\r
1434 unsigned char mirror; /* HFLIP */
\r
1435 unsigned char flip; /* VFLIP */
\r
1436 unsigned int winseqe_cur_addr;
\r
1437 struct sensor_datafmt fmt;
\r
1438 unsigned int funmodule_state;
\r
1439 } sensor_info_priv_t;
\r
1443 struct v4l2_subdev subdev;
\r
1444 struct i2c_client *client;
\r
1445 sensor_info_priv_t info_priv;
\r
1446 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
\r
1447 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1448 atomic_t tasklock_cnt;
\r
1450 struct rk29camera_platform_data *sensor_io_request;
\r
1451 struct rk29camera_gpio_res *sensor_gpio_res;
\r
1454 static struct sensor* to_sensor(const struct i2c_client *client)
\r
1456 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
\r
1459 static int sensor_task_lock(struct i2c_client *client, int lock)
\r
1461 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1463 struct sensor *sensor = to_sensor(client);
\r
1466 if (atomic_read(&sensor->tasklock_cnt) == 0) {
\r
1467 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
\r
1468 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
\r
1472 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
\r
1473 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
\r
1474 goto sensor_task_lock_err;
\r
1476 preempt_disable();
\r
1479 atomic_add(1, &sensor->tasklock_cnt);
\r
1481 if (atomic_read(&sensor->tasklock_cnt) > 0) {
\r
1482 atomic_sub(1, &sensor->tasklock_cnt);
\r
1484 if (atomic_read(&sensor->tasklock_cnt) == 0)
\r
1489 sensor_task_lock_err:
\r
1497 /* sensor register write */
\r
1498 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
\r
1502 struct i2c_msg msg[1];
\r
1504 //buf[0] = reg >> 8;
\r
1505 buf[0] = reg & 0xFF;
\r
1508 msg->addr = client->addr;
\r
1509 msg->flags = client->flags;
\r
1511 msg->len = sizeof(buf);
\r
1512 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1513 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
\r
1518 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1519 err = i2c_transfer(client->adapter, msg, 1);
\r
1524 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
\r
1532 /* sensor register read */
\r
1533 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
\r
1537 struct i2c_msg msg[2];
\r
1539 // buf[0] = reg >> 8;
\r
1540 buf[0] = reg & 0xFF;
\r
1542 msg[0].addr = client->addr;
\r
1543 msg[0].flags = client->flags;
\r
1545 msg[0].len = sizeof(buf);
\r
1546 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1547 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
\r
1549 msg[1].addr = client->addr;
\r
1550 msg[1].flags = client->flags|I2C_M_RD;
\r
1553 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1554 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
\r
1558 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1559 err = i2c_transfer(client->adapter, msg, 2);
\r
1565 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
\r
1573 /* write a array of registers */
\r
1574 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
\r
1578 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1583 if (sensor_task_lock(client, 1) < 0)
\r
1584 goto sensor_write_array_end;
\r
1585 while (regarray[i].reg != 0xff)
\r
1587 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1591 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
\r
1595 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
\r
1597 goto sensor_write_array_end;
\r
1600 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1601 sensor_read(client, regarray[i].reg, &valchk);
\r
1602 if (valchk != regarray[i].val)
\r
1603 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
\r
1609 sensor_write_array_end:
\r
1610 sensor_task_lock(client,0);
\r
1613 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1614 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
\r
1622 while (regarray[i].reg != 0xff)
\r
1624 sensor_read(client, regarray[i].reg, &valchk);
\r
1625 if (valchk != regarray[i].val)
\r
1626 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
\r
1633 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
\r
1635 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1638 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
\r
1641 case Sensor_PowerDown:
\r
1643 if (icl->powerdown) {
\r
1644 ret = icl->powerdown(icd->pdev, on);
\r
1645 if (ret == RK29_CAM_IO_SUCCESS) {
\r
1649 icl->reset(icd->pdev);
\r
1651 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
\r
1653 goto sensor_power_end;
\r
1658 case Sensor_Flash:
\r
1660 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1661 struct sensor *sensor = to_sensor(client);
\r
1663 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
\r
1664 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
\r
1670 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
1677 static int sensor_init(struct v4l2_subdev *sd, u32 val)
\r
1679 struct i2c_client *client = sd->priv;
\r
1680 struct soc_camera_device *icd = client->dev.platform_data;
\r
1681 struct sensor *sensor = to_sensor(client);
\r
1682 const struct v4l2_queryctrl *qctrl;
\r
1683 const struct sensor_datafmt *fmt;
\r
1687 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1689 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
1691 goto sensor_INIT_ERR;
\r
1696 if (sensor_task_lock(client,1)<0)
\r
1697 goto sensor_INIT_ERR;
\r
1698 ret = sensor_write(client, 0x3012, 0x80);
\r
1701 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
\r
1703 goto sensor_INIT_ERR;
\r
1706 mdelay(5); //delay 5 microseconds
\r
1707 /* check if it is an sensor sensor */
\r
1708 ret = sensor_read(client, 0x300a, &value);
\r
1710 SENSOR_TR("read chip id high byte failed\n");
\r
1712 goto sensor_INIT_ERR;
\r
1715 pid |= (value << 8);
\r
1717 ret = sensor_read(client, 0x300b, &value);
\r
1719 SENSOR_TR("read chip id low byte failed\n");
\r
1721 goto sensor_INIT_ERR;
\r
1724 pid |= (value & 0xff);
\r
1725 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1726 if (pid == SENSOR_ID) {
\r
1727 sensor->model = SENSOR_V4L2_IDENT;
\r
1729 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1731 goto sensor_INIT_ERR;
\r
1735 sensor_read(client,0x01,&value);
\r
1736 pid = (value & 0xff);
\r
1737 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1738 if (pid == SENSOR_ID) {
\r
1739 sensor->model = SENSOR_V4L2_IDENT;
\r
1741 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1743 goto sensor_INIT_ERR;
\r
1746 ret = sensor_write_array(client, sensor_init_data);
\r
1749 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
\r
1750 goto sensor_INIT_ERR;
\r
1752 sensor_task_lock(client,0);
\r
1753 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
\r
1754 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
\r
1756 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1758 goto sensor_INIT_ERR;
1760 sensor->info_priv.fmt = *fmt;
\r
1762 /* sensor sensor information for initialization */
\r
1763 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1765 sensor->info_priv.whiteBalance = qctrl->default_value;
\r
1766 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
\r
1768 sensor->info_priv.brightness = qctrl->default_value;
\r
1769 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1771 sensor->info_priv.effect = qctrl->default_value;
\r
1772 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
\r
1774 sensor->info_priv.exposure = qctrl->default_value;
\r
1776 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
\r
1778 sensor->info_priv.saturation = qctrl->default_value;
\r
1779 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
\r
1781 sensor->info_priv.contrast = qctrl->default_value;
\r
1782 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
\r
1784 sensor->info_priv.mirror = qctrl->default_value;
\r
1785 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
\r
1787 sensor->info_priv.flip = qctrl->default_value;
\r
1788 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
\r
1790 sensor->info_priv.scene = qctrl->default_value;
\r
1791 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
1793 sensor->info_priv.digitalzoom = qctrl->default_value;
\r
1795 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
\r
1796 #if CONFIG_SENSOR_Focus
\r
1797 sensor_set_focus();
\r
1798 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
\r
1800 sensor->info_priv.focus = qctrl->default_value;
\r
1803 #if CONFIG_SENSOR_Flash
\r
1804 sensor_set_flash();
\r
1805 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
\r
1807 sensor->info_priv.flash = qctrl->default_value;
\r
1810 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);
\r
1811 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
\r
1814 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1815 sensor_task_lock(client,0);
\r
1816 sensor_deactivate(client);
\r
1820 static int sensor_deactivate(struct i2c_client *client)
\r
1822 struct soc_camera_device *icd = client->dev.platform_data;
\r
1823 struct sensor *sensor = to_sensor(client);
\r
1825 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1827 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
\r
1829 sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1831 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
\r
1832 icd->user_width = SENSOR_INIT_WIDTH;
\r
1833 icd->user_height = SENSOR_INIT_HEIGHT;
\r
1836 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1840 static struct reginfo sensor_power_down_sequence[]=
\r
1844 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
\r
1847 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1849 if (pm_msg.event == PM_EVENT_SUSPEND) {
\r
1850 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
\r
1851 ret = sensor_write_array(client, sensor_power_down_sequence) ;
\r
1853 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
\r
1856 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1858 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1863 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
\r
1869 static int sensor_resume(struct soc_camera_device *icd)
\r
1873 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
\r
1875 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1879 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
\r
1885 static int sensor_set_bus_param(struct soc_camera_device *icd,
\r
1886 unsigned long flags)
\r
1892 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
\r
1894 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1895 unsigned long flags = SENSOR_BUS_PARAM;
\r
1897 return soc_camera_apply_sensor_flags(icl, flags);
\r
1900 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1902 struct i2c_client *client = sd->priv;
1903 struct soc_camera_device *icd = client->dev.platform_data;
1904 struct sensor *sensor = to_sensor(client);
1906 mf->width = icd->user_width;
1907 mf->height = icd->user_height;
1908 mf->code = sensor->info_priv.fmt.code;
1909 mf->colorspace = sensor->info_priv.fmt.colorspace;
1910 mf->field = V4L2_FIELD_NONE;
1914 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1918 if ((mf->width == 1024) && (mf->height == 768)) {
1920 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1922 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1924 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1926 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1931 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1935 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1939 if ((mf->width == 1280) && (mf->height == 720)) {
1941 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1946 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1949 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1951 struct i2c_client *client = sd->priv;
\r
1952 struct sensor *sensor = to_sensor(client);
\r
1953 const struct sensor_datafmt *fmt;
\r
1954 const struct v4l2_queryctrl *qctrl;
\r
1955 struct soc_camera_device *icd = client->dev.platform_data;
\r
1956 struct reginfo *winseqe_set_addr=NULL;
\r
1957 int ret=0, set_w,set_h;
\r
1959 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1960 ARRAY_SIZE(sensor_colour_fmts));
1963 goto sensor_s_fmt_end;
1966 if (sensor->info_priv.fmt.code != mf->code) {
1969 case V4L2_MBUS_FMT_YUYV8_2X8:
1971 winseqe_set_addr = sensor_ClrFmt_YUYV;
1974 case V4L2_MBUS_FMT_UYVY8_2X8:
1976 winseqe_set_addr = sensor_ClrFmt_UYVY;
1982 if (winseqe_set_addr != NULL) {
1983 sensor_write_array(client, winseqe_set_addr);
1984 sensor->info_priv.fmt.code = mf->code;
1985 sensor->info_priv.fmt.colorspace= mf->colorspace;
1986 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1988 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1993 set_h = mf->height;
\r
1995 if (((set_w <= 176) && (set_h <= 144)) &&( sensor_qcif[0].reg!=0xff))
\r
1997 winseqe_set_addr = sensor_qcif;
\r
2001 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=0xff))
\r
2003 winseqe_set_addr = sensor_qvga;
\r
2007 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=0xff))
\r
2009 winseqe_set_addr = sensor_cif;
\r
2013 else if (((set_w <= 640) && (set_h <= 480)) &&( sensor_vga[0].reg!=0xff))
\r
2015 winseqe_set_addr = sensor_vga;
\r
2019 else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=0xff))
\r
2021 winseqe_set_addr = sensor_svga;
\r
2025 else if (((set_w <= 1024) && (set_h <= 768)) &&( sensor_xga[0].reg!=0xff))
\r
2027 winseqe_set_addr = sensor_xga;
\r
2031 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=0xff))
\r
2033 winseqe_set_addr = sensor_sxga;
\r
2037 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=0xff))
\r
2039 winseqe_set_addr = sensor_uxga;
\r
2045 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
\r
2046 set_w = SENSOR_INIT_WIDTH;
\r
2047 set_h = SENSOR_INIT_HEIGHT;
\r
2048 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
\r
2051 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
\r
2052 #if CONFIG_SENSOR_Flash
\r
2053 if (sensor_fmt_capturechk(sd,f) == true) { /* ddl@rock-chips.com : Capture */
\r
2054 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2055 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
\r
2056 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
\r
2058 } else { /* ddl@rock-chips.com : Video */
\r
2059 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2060 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2061 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
\r
2065 ret |= sensor_write_array(client, winseqe_set_addr);
\r
2067 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
\r
2068 #if CONFIG_SENSOR_Flash
\r
2069 if (sensor_fmt_capturechk(sd,f) == true) {
\r
2070 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2071 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2072 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
\r
2076 goto sensor_s_fmt_end;
\r
2079 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
\r
2081 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
2082 #if CONFIG_SENSOR_Effect
\r
2083 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2084 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2086 #if CONFIG_SENSOR_WhiteBalance
\r
2087 if (sensor->info_priv.whiteBalance != 0) {
\r
2088 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2089 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2092 sensor->info_priv.snap2preview = true;
\r
2093 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
\r
2094 #if CONFIG_SENSOR_Effect
\r
2095 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2096 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2098 #if CONFIG_SENSOR_WhiteBalance
\r
2099 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2100 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2102 sensor->info_priv.video2preview = true;
\r
2103 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
\r
2104 #if CONFIG_SENSOR_Effect
\r
2105 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2106 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2108 #if CONFIG_SENSOR_WhiteBalance
\r
2109 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2110 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2112 sensor->info_priv.video2preview = false;
\r
2113 sensor->info_priv.snap2preview = false;
\r
2115 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
\r
2119 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
\r
2122 mf->width = set_w;
\r
2123 mf->height = set_h;
\r
2129 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2131 struct i2c_client *client = sd->priv;
2132 struct sensor *sensor = to_sensor(client);
2133 const struct sensor_datafmt *fmt;
2136 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2137 ARRAY_SIZE(sensor_colour_fmts));
2139 fmt = &sensor->info_priv.fmt;
2140 mf->code = fmt->code;
2143 if (mf->height > SENSOR_MAX_HEIGHT)
2144 mf->height = SENSOR_MAX_HEIGHT;
2145 else if (mf->height < SENSOR_MIN_HEIGHT)
2146 mf->height = SENSOR_MIN_HEIGHT;
2148 if (mf->width > SENSOR_MAX_WIDTH)
2149 mf->width = SENSOR_MAX_WIDTH;
2150 else if (mf->width < SENSOR_MIN_WIDTH)
2151 mf->width = SENSOR_MIN_WIDTH;
2153 mf->colorspace = fmt->colorspace;
2158 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
\r
2160 struct i2c_client *client = sd->priv;
\r
2162 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
\r
2165 if (id->match.addr != client->addr)
\r
2168 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
\r
2173 #if CONFIG_SENSOR_Brightness
\r
2174 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2176 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2178 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2180 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
\r
2182 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
\r
2184 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2187 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2191 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2195 #if CONFIG_SENSOR_Effect
\r
2196 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2198 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2200 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2202 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
\r
2204 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
\r
2206 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2209 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2213 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2217 #if CONFIG_SENSOR_Exposure
\r
2218 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2220 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2222 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2224 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
\r
2226 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
\r
2228 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2231 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2235 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2239 #if CONFIG_SENSOR_Saturation
\r
2240 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2242 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2244 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2246 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
\r
2248 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
\r
2250 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2253 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2257 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2261 #if CONFIG_SENSOR_Contrast
\r
2262 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2264 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2266 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2268 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
\r
2270 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
\r
2272 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2275 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2279 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2283 #if CONFIG_SENSOR_Mirror
\r
2284 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2286 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2288 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2290 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
\r
2292 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
\r
2294 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2297 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2301 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2305 #if CONFIG_SENSOR_Flip
\r
2306 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2308 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2310 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2312 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
\r
2314 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
\r
2316 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2319 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2323 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2327 #if CONFIG_SENSOR_Scene
\r
2328 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2330 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2332 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2334 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
\r
2336 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
\r
2338 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2341 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2345 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2349 #if CONFIG_SENSOR_WhiteBalance
\r
2350 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2352 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2354 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2356 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
\r
2358 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
\r
2360 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2363 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2367 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2371 #if CONFIG_SENSOR_DigitalZoom
\r
2372 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2374 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2375 struct sensor *sensor = to_sensor(client);
\r
2376 const struct v4l2_queryctrl *qctrl_info;
\r
2377 int digitalzoom_cur, digitalzoom_total;
\r
2379 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
2383 digitalzoom_cur = sensor->info_priv.digitalzoom;
\r
2384 digitalzoom_total = qctrl_info->maximum;
\r
2386 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
\r
2388 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2392 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
\r
2394 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2398 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
\r
2400 value = digitalzoom_total - digitalzoom_cur;
\r
2403 if ((value < 0) && ((digitalzoom_cur + value) < 0))
\r
2405 value = 0 - digitalzoom_cur;
\r
2408 digitalzoom_cur += value;
\r
2410 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
\r
2412 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
\r
2414 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2417 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2424 #if CONFIG_SENSOR_Flash
\r
2425 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2427 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
\r
2428 if (value == 3) { /* ddl@rock-chips.com: torch */
\r
2429 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
\r
2431 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2433 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2437 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2442 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2444 struct i2c_client *client = sd->priv;
\r
2445 struct sensor *sensor = to_sensor(client);
\r
2446 const struct v4l2_queryctrl *qctrl;
\r
2448 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2452 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2458 case V4L2_CID_BRIGHTNESS:
\r
2460 ctrl->value = sensor->info_priv.brightness;
\r
2463 case V4L2_CID_SATURATION:
\r
2465 ctrl->value = sensor->info_priv.saturation;
\r
2468 case V4L2_CID_CONTRAST:
\r
2470 ctrl->value = sensor->info_priv.contrast;
\r
2473 case V4L2_CID_DO_WHITE_BALANCE:
\r
2475 ctrl->value = sensor->info_priv.whiteBalance;
\r
2478 case V4L2_CID_EXPOSURE:
\r
2480 ctrl->value = sensor->info_priv.exposure;
\r
2483 case V4L2_CID_HFLIP:
\r
2485 ctrl->value = sensor->info_priv.mirror;
\r
2488 case V4L2_CID_VFLIP:
\r
2490 ctrl->value = sensor->info_priv.flip;
\r
2501 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2503 struct i2c_client *client = sd->priv;
\r
2504 struct sensor *sensor = to_sensor(client);
\r
2505 struct soc_camera_device *icd = client->dev.platform_data;
\r
2506 const struct v4l2_queryctrl *qctrl;
\r
2509 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2513 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2519 #if CONFIG_SENSOR_Brightness
\r
2520 case V4L2_CID_BRIGHTNESS:
\r
2522 if (ctrl->value != sensor->info_priv.brightness)
\r
2524 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
\r
2528 sensor->info_priv.brightness = ctrl->value;
\r
2533 #if CONFIG_SENSOR_Exposure
\r
2534 case V4L2_CID_EXPOSURE:
\r
2536 if (ctrl->value != sensor->info_priv.exposure)
\r
2538 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
\r
2542 sensor->info_priv.exposure = ctrl->value;
\r
2547 #if CONFIG_SENSOR_Saturation
\r
2548 case V4L2_CID_SATURATION:
\r
2550 if (ctrl->value != sensor->info_priv.saturation)
\r
2552 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
\r
2556 sensor->info_priv.saturation = ctrl->value;
\r
2561 #if CONFIG_SENSOR_Contrast
\r
2562 case V4L2_CID_CONTRAST:
\r
2564 if (ctrl->value != sensor->info_priv.contrast)
\r
2566 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
\r
2570 sensor->info_priv.contrast = ctrl->value;
\r
2575 #if CONFIG_SENSOR_WhiteBalance
\r
2576 case V4L2_CID_DO_WHITE_BALANCE:
\r
2578 if (ctrl->value != sensor->info_priv.whiteBalance)
\r
2580 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
\r
2584 sensor->info_priv.whiteBalance = ctrl->value;
\r
2589 #if CONFIG_SENSOR_Mirror
\r
2590 case V4L2_CID_HFLIP:
\r
2592 if (ctrl->value != sensor->info_priv.mirror)
\r
2594 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
\r
2596 sensor->info_priv.mirror = ctrl->value;
\r
2601 #if CONFIG_SENSOR_Flip
\r
2602 case V4L2_CID_VFLIP:
\r
2604 if (ctrl->value != sensor->info_priv.flip)
\r
2606 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
\r
2608 sensor->info_priv.flip = ctrl->value;
\r
2619 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
\r
2621 const struct v4l2_queryctrl *qctrl;
\r
2622 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2623 struct sensor *sensor = to_sensor(client);
\r
2625 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2629 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2633 switch (ext_ctrl->id)
\r
2635 case V4L2_CID_SCENE:
\r
2637 ext_ctrl->value = sensor->info_priv.scene;
\r
2640 case V4L2_CID_EFFECT:
\r
2642 ext_ctrl->value = sensor->info_priv.effect;
\r
2645 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2647 ext_ctrl->value = sensor->info_priv.digitalzoom;
\r
2650 case V4L2_CID_ZOOM_RELATIVE:
\r
2654 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2656 ext_ctrl->value = sensor->info_priv.focus;
\r
2659 case V4L2_CID_FOCUS_RELATIVE:
\r
2663 case V4L2_CID_FLASH:
\r
2665 ext_ctrl->value = sensor->info_priv.flash;
\r
2673 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
\r
2675 const struct v4l2_queryctrl *qctrl;
\r
2676 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2677 struct sensor *sensor = to_sensor(client);
\r
2680 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2684 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2689 switch (ext_ctrl->id)
\r
2691 #if CONFIG_SENSOR_Scene
\r
2692 case V4L2_CID_SCENE:
\r
2694 if (ext_ctrl->value != sensor->info_priv.scene)
\r
2696 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
\r
2698 sensor->info_priv.scene = ext_ctrl->value;
\r
2703 #if CONFIG_SENSOR_Effect
\r
2704 case V4L2_CID_EFFECT:
\r
2706 if (ext_ctrl->value != sensor->info_priv.effect)
\r
2708 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
\r
2710 sensor->info_priv.effect= ext_ctrl->value;
\r
2715 #if CONFIG_SENSOR_DigitalZoom
\r
2716 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2718 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2721 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
\r
2723 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
\r
2725 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
\r
2727 sensor->info_priv.digitalzoom += val_offset;
\r
2729 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2734 case V4L2_CID_ZOOM_RELATIVE:
\r
2736 if (ext_ctrl->value)
\r
2738 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
\r
2740 sensor->info_priv.digitalzoom += ext_ctrl->value;
\r
2742 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2747 #if CONFIG_SENSOR_Focus
\r
2748 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2750 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2753 if (ext_ctrl->value != sensor->info_priv.focus)
\r
2755 val_offset = ext_ctrl->value -sensor->info_priv.focus;
\r
2757 sensor->info_priv.focus += val_offset;
\r
2762 case V4L2_CID_FOCUS_RELATIVE:
\r
2764 if (ext_ctrl->value)
\r
2766 sensor->info_priv.focus += ext_ctrl->value;
\r
2768 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
\r
2773 #if CONFIG_SENSOR_Flash
\r
2774 case V4L2_CID_FLASH:
\r
2776 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
\r
2778 sensor->info_priv.flash = ext_ctrl->value;
\r
2780 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
\r
2791 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2793 struct i2c_client *client = sd->priv;
\r
2794 struct soc_camera_device *icd = client->dev.platform_data;
\r
2795 int i, error_cnt=0, error_idx=-1;
\r
2798 for (i=0; i<ext_ctrl->count; i++) {
\r
2799 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2805 if (error_cnt > 1)
\r
2806 error_idx = ext_ctrl->count;
\r
2808 if (error_idx != -1) {
\r
2809 ext_ctrl->error_idx = error_idx;
\r
2816 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2818 struct i2c_client *client = sd->priv;
\r
2819 struct soc_camera_device *icd = client->dev.platform_data;
\r
2820 int i, error_cnt=0, error_idx=-1;
\r
2823 for (i=0; i<ext_ctrl->count; i++) {
\r
2824 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2830 if (error_cnt > 1)
\r
2831 error_idx = ext_ctrl->count;
\r
2833 if (error_idx != -1) {
\r
2834 ext_ctrl->error_idx = error_idx;
\r
2841 /* Interface active, can use i2c. If it fails, it can indeed mean, that
\r
2842 * this wasn't our capture interface, so, we wait for the right one */
\r
2843 static int sensor_video_probe(struct soc_camera_device *icd,
\r
2844 struct i2c_client *client)
\r
2848 struct sensor *sensor = to_sensor(client);
\r
2850 /* We must have a parent by now. And it cannot be a wrong one.
\r
2851 * So this entire test is completely redundant. */
\r
2852 if (!icd->dev.parent ||
\r
2853 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
\r
2856 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
2858 goto sensor_video_probe_err;
\r
2862 ret = sensor_write(client, 0x3012, 0x80);
\r
2865 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
\r
2868 mdelay(5); //delay 5 microseconds
\r
2870 /* check if it is an sensor sensor */
\r
2871 ret = sensor_read(client, 0x300a, &value);
\r
2873 SENSOR_TR("read chip id high byte failed\n");
\r
2875 goto sensor_video_probe_err;
\r
2879 ret = sensor_read(client, 0x01, &value);
\r
2881 SENSOR_TR("read chip id low byte failed\n");
\r
2883 goto sensor_video_probe_err;
\r
2886 pid = (value & 0xff);
\r
2887 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2888 if (pid == SENSOR_ID) {
\r
2889 sensor->model = SENSOR_V4L2_IDENT;
\r
2891 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2893 goto sensor_video_probe_err;
\r
2899 sensor_video_probe_err:
\r
2903 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
\r
2905 struct i2c_client *client = sd->priv;
\r
2906 struct soc_camera_device *icd = client->dev.platform_data;
\r
2907 struct sensor *sensor = to_sensor(client);
\r
2909 #if CONFIG_SENSOR_Flash
\r
2913 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2916 case RK29_CAM_SUBDEV_DEACTIVATE:
\r
2918 sensor_deactivate(client);
\r
2922 case RK29_CAM_SUBDEV_IOREQUEST:
\r
2924 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
\r
2925 if (sensor->sensor_io_request != NULL) {
\r
2926 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
\r
2927 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
\r
2928 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
\r
2929 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
\r
2930 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
\r
2931 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
\r
2934 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
2936 goto sensor_ioctl_end;
\r
2938 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
\r
2939 for this project */
\r
2940 #if CONFIG_SENSOR_Flash
\r
2941 if (sensor->sensor_gpio_res) {
\r
2942 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
\r
2943 for (i = 0; i < icd->ops->num_controls; i++) {
\r
2944 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
\r
2945 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
\r
2948 sensor->info_priv.flash = 0xff;
\r
2949 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
\r
2957 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2965 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2966 enum v4l2_mbus_pixelcode *code)
2968 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2971 *code = sensor_colour_fmts[index].code;
2974 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
\r
2975 .init = sensor_init,
\r
2976 .g_ctrl = sensor_g_control,
\r
2977 .s_ctrl = sensor_s_control,
\r
2978 .g_ext_ctrls = sensor_g_ext_controls,
\r
2979 .s_ext_ctrls = sensor_s_ext_controls,
\r
2980 .g_chip_ident = sensor_g_chip_ident,
\r
2981 .ioctl = sensor_ioctl,
\r
2984 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2985 .s_mbus_fmt = sensor_s_fmt,
2986 .g_mbus_fmt = sensor_g_fmt,
2987 .try_mbus_fmt = sensor_try_fmt,
2988 .enum_mbus_fmt = sensor_enum_fmt,
2991 static struct v4l2_subdev_ops sensor_subdev_ops = {
\r
2992 .core = &sensor_subdev_core_ops,
\r
2993 .video = &sensor_subdev_video_ops,
\r
2996 static int sensor_probe(struct i2c_client *client,
\r
2997 const struct i2c_device_id *did)
\r
2999 struct sensor *sensor;
\r
3000 struct soc_camera_device *icd = client->dev.platform_data;
\r
3001 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
\r
3002 struct soc_camera_link *icl;
\r
3005 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
\r
3007 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
\r
3011 icl = to_soc_camera_link(icd);
\r
3013 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
\r
3017 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
\r
3018 dev_warn(&adapter->dev,
\r
3019 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
\r
3023 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
\r
3027 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
\r
3029 /* Second stage probe - when a capture adapter is there */
\r
3030 icd->ops = &sensor_ops;
\r
3031 sensor->info_priv.fmt = sensor_colour_fmts[0];
\r
3032 #if CONFIG_SENSOR_I2C_NOSCHED
\r
3033 atomic_set(&sensor->tasklock_cnt,0);
\r
3036 ret = sensor_video_probe(icd, client);
\r
3039 i2c_set_clientdata(client, NULL);
\r
3043 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
\r
3047 static int sensor_remove(struct i2c_client *client)
\r
3049 struct sensor *sensor = to_sensor(client);
\r
3050 struct soc_camera_device *icd = client->dev.platform_data;
\r
3053 i2c_set_clientdata(client, NULL);
\r
3054 client->driver = NULL;
\r
3060 static const struct i2c_device_id sensor_id[] = {
\r
3061 {SENSOR_NAME_STRING(), 0 },
\r
3064 MODULE_DEVICE_TABLE(i2c, sensor_id);
\r
3066 static struct i2c_driver sensor_i2c_driver = {
\r
3068 .name = SENSOR_NAME_STRING(),
\r
3070 .probe = sensor_probe,
\r
3071 .remove = sensor_remove,
\r
3072 .id_table = sensor_id,
\r
3075 static int __init sensor_mod_init(void)
\r
3077 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
\r
3078 return i2c_add_driver(&sensor_i2c_driver);
\r
3081 static void __exit sensor_mod_exit(void)
\r
3083 i2c_del_driver(&sensor_i2c_driver);
\r
3086 device_initcall_sync(sensor_mod_init);
\r
3087 module_exit(sensor_mod_exit);
\r
3089 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
\r
3090 MODULE_AUTHOR("ddl <kernel@rock-chips>");
\r
3091 MODULE_LICENSE("GPL");