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 <plat/rk_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 1
\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)
\r
93 #define SENSOR_AF_IS_OK (0x01<<0)
\r
94 #define SENSOR_INIT_IS_ERR (0x00<<28)
\r
95 #define SENSOR_INIT_IS_OK (0x01<<28)
\r
103 //flash off in fixed time to prevent from too hot , zyc
\r
104 struct flash_timer{
\r
105 struct soc_camera_device *icd;
\r
106 struct hrtimer timer;
\r
108 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
\r
110 static struct flash_timer flash_off_timer;
\r
111 //for user defined if user want to customize the series , zyc
\r
112 #if CONFIG_SID130B_USER_DEFINED_SERIES
\r
113 #include "sid130B_user_series.c"
\r
115 /* init 352X288 SVGA */
\r
116 static struct reginfo sensor_init_data[] =
\r
119 {0x04, 0x00}, //Group A 0x10
\r
120 {0x05, 0x0F}, //UXGA Output
\r
125 {0x08, 0xa2}, //PLL off
\r
145 //Flicker - 50Hz - Still mode ,
\r
149 {0x23, 0x29},//15},
\r
151 {0x35, 0x50},//3c},
\r
153 //Flicker - 50Hz - Preview mode 24MHz MCLK
\r
156 {0x25, 0xe6},//10},
\r
157 {0x27, 0x0d},//4b},
\r
159 {0x34, 0x80},//64},
\r
165 {0x11, 0x0a}, //.0c
\r
174 {0x40, 0x40}, //Max Again //anyuan
\r
211 {0x92, 0x0c}, //0bank 0x11 °ú µ¿ÀÏ
\r
212 {0x95, 0x40}, //0 bank 0x40 °ú µ¿ÀÏ
\r
258 //CMA change -D65~A
\r
259 {0x53, 0xa1}, //AWB R Gain for D30 to D20
\r
260 {0x54, 0xc0}, //AWB B Gain for D30 to D20
\r
261 {0x55, 0xa1}, //AWB R Gain for D20 to D30
\r
262 {0x56, 0xc0}, //AWB B Gain for D20 to D30
\r
263 {0x57, 0xc8}, //AWB R Gain for D65 to D30
\r
264 {0x58, 0xa0}, //AWB B Gain for D65 to D30
\r
265 {0x59, 0xc8}, //AWB R Gain for D30 to D65
\r
266 {0x5A, 0xa0}, //AWB B Gain for D30 to D65
\r
332 {0x30, 0x88}, //DPCNRCTRL
\r
333 {0x31, 0x14}, //DPTHR @ AGAIN = 00
\r
334 {0x32, 0x10}, //DPTHR @ AGAIN = 20
\r
335 {0x33, 0x0c}, //DPTHR @ AGAIN = 40
\r
336 {0x34, 0x08}, //DPTHR @ AGAIN = 60
\r
337 {0x35, 0x04}, //DPTHR @ AGAIN = 80
\r
338 {0x36, 0x44}, //DPTHVRNG
\r
339 {0x37, 0x66}, //DPNUMBER
\r
340 {0x38, 0x00}, //0x00 // NRTHR0 @ AGAIN = 00
\r
341 {0x39, 0x04}, //0x0C // NRTHR1 @ AGAIN = 20
\r
342 {0x3A, 0x04}, //0x18 // NRTHR2 @ AGAIN = 40
\r
343 {0x3B, 0x2c}, //0x30 // NRTHR3 @ AGAIN = 60
\r
344 {0x3C, 0x3c}, // NRTHR4 @ AGAIN = 80
\r
345 {0x3D, 0x04}, //NRTHVRNG0 @ AGAIN = 00
\r
346 {0x3E, 0x04}, //NRTHVRNG1 @ AGAIN = 20
\r
347 {0x3F, 0x04}, //NRTHVRNG2 @ AGAIN = 40
\r
348 {0x40, 0x2c}, //NRTHVRNG3 @ AGAIN = 60
\r
349 {0x41, 0x3c}, //NRTHVRNG4 @ AGAIN = 80
\r
350 {0x42, 0xff}, //NRTHVRNGMAX
\r
351 {0x43, 0x40}, //NRTHRWGT
\r
352 {0x44, 0x40}, //BASELVL
\r
353 {0x45, 0x06}, //SHUMAXH
\r
354 {0x46, 0x40}, //SHUMAXL
\r
355 {0x47, 0x30}, //ILLUMITHDRK
\r
358 {0x50, 0x0a}, //0x00
\r
359 {0x51, 0x20}, //0x45
\r
360 {0x52, 0x12}, //0x24
\r
361 {0x53, 0x12}, //0x24
\r
363 {0x54, 0x22}, //0x00
\r
364 {0x55, 0x18}, //0x40
\r
365 {0x56, 0x08}, //0x10
\r
366 {0x57, 0x10}, //0x20
\r
368 {0x58, 0x22}, //0x00
\r
369 {0x59, 0x18}, //0x40
\r
370 {0x5A, 0x08}, //0x10
\r
371 {0x5B, 0x10}, //0x20
\r
373 {0x5C, 0x25}, //0x04
\r
374 {0x5D, 0x1a}, //0x55
\r
375 {0x5E, 0x12}, //0x25
\r
376 {0x5F, 0x10}, //0x20
\r
378 {0x60, 0x32}, //0x32
\r
379 {0x61, 0x20}, //20//
\r
381 // {0x63, 0x89 //8c R Center start gain
\r
382 // {0x66, 0x79 //B Center start gain 73
\r
383 {0x6B, 0x00}, //01 //01
\r
384 {0x6C, 0x01}, //22
\r
385 {0x6D, 0x23}, //22
\r
386 {0x6E, 0x55}, //55
\r
387 {0x6F, 0x55}, //77
\r
388 {0x70, 0x55}, //65
\r
389 {0x71, 0x00}, //01 //AB (6)
\r
390 {0x72, 0x01}, //23 (5)
\r
391 {0x73, 0x23}, //33 (4)
\r
392 {0x74, 0x44}, //45 (3)
\r
393 {0x75, 0x45}, //55 (2)
\r
394 {0x76, 0x66}, //55 (1)
\r
395 {0x77, 0x00}, //01 //AB (6)
\r
396 {0x78, 0x01}, //23 (5)
\r
397 {0x79, 0x23}, //33 (4)
\r
398 {0x7A, 0x44}, //45 (3)
\r
399 {0x7B, 0x45}, //55 (2)
\r
400 {0x7C, 0x66}, //55 (1)
\r
401 {0x7D, 0x00}, //00 //00
\r
402 {0x7E, 0x00}, //00 //00
\r
403 {0x7F, 0x12}, //11 //12
\r
404 {0x80, 0x33}, //33 //33 //44
\r
405 {0x81, 0x44}, //33 //33 //44
\r
406 {0x82, 0x55}, //22 //44 //45
\r
435 //Color Matrix for D65
\r
437 {0xC0, 0x2F}, // CMASB D20 or D30 or Dark Condition Color Matrix Selection
\r
453 {0xC0, 0x2F}, // CMASB D20 or D30 or Dark Condition Color Matrix Selection
\r
470 //Color Matrix for CWF
\r
487 //Color Matrix for A
\r
579 {0x50, 0x00}, //DARK GAMMA on/off
\r
632 {0xA1, 0x08}, //@ 0
\r
633 {0xA2, 0x10}, //@ 20
\r
634 {0xA3, 0x16}, //@ 40
\r
635 {0xA4, 0x20}, //@ 60
\r
636 {0xA5, 0x30}, //@ 80
\r
649 {0xB2, 0x38}, //color suppression start
\r
685 {0x91, 0x81}, //knee function selection/knee point H
\r
686 {0x92, 0x00}, //knee point L
\r
687 {0x93, 0x50}, //Knee gain
\r
688 {0x94, 0x41}, //[6:4]knee start H/[2:0]Knee END H
\r
689 {0x95, 0x7e}, //knee start L
\r
690 {0x96, 0x48}, //knee END L
\r
712 {0xB0, 0xc0}, //YGMACTRL
\r
713 {0xB1, 0x04}, //YGMASLOP
\r
714 {0xB8, 0x0f}, //DRKTHR1
\r
715 {0xB9, 0x10}, //DRKTHR2
\r
716 //{0xBA, 0x38}, //DRKTHR3
\r
717 //{0xBB, 0x39}, //DRKTHR4
\r
736 // edge value adjustment
\r
757 /* 1600X1200 UXGA */
\r
758 static struct reginfo sensor_uxga[] =
\r
771 /* 1280X1024 SXGA */
\r
772 static struct reginfo sensor_sxga[] =
\r
784 static struct reginfo sensor_xga[] =
\r
789 static struct reginfo sensor_svga[] =
\r
800 static struct reginfo sensor_vga[] =
\r
806 {0x94,0x02}, //0x02
\r
807 {0x95,0x80}, //0x80
\r
809 {0x97,0xe0}, //0xe0
\r
814 static struct reginfo sensor_cif[] =
\r
825 static struct reginfo sensor_qvga[] =
\r
836 static struct reginfo sensor_qcif[] =
\r
846 static struct reginfo sensor_ClrFmt_YUYV[]=
\r
851 static struct reginfo sensor_ClrFmt_UYVY[]=
\r
856 #if CONFIG_SENSOR_WhiteBalance
\r
857 static struct reginfo sensor_WhiteB_Auto[]={
\r
862 /* Cloudy Colour Temperature : 6500K - 8000K */
\r
863 static struct reginfo sensor_WhiteB_Cloudy[]=
\r
871 /* ClearDay Colour Temperature : 5000K - 6500K */
\r
872 static struct reginfo sensor_WhiteB_ClearDay[]=
\r
881 /* Office Colour Temperature : 3500K - 5000K */
\r
882 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
\r
890 /* Home Colour Temperature : 2500K - 3500K */
\r
891 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
\r
899 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
\r
900 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
\r
904 #if CONFIG_SENSOR_Brightness
\r
905 static struct reginfo sensor_Brightness0[]=
\r
914 static struct reginfo sensor_Brightness1[]=
\r
923 static struct reginfo sensor_Brightness2[]=
\r
932 static struct reginfo sensor_Brightness3[]=
\r
941 static struct reginfo sensor_Brightness4[]=
\r
950 static struct reginfo sensor_Brightness5[]=
\r
956 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
\r
957 sensor_Brightness4, sensor_Brightness5,NULL,
\r
962 #if CONFIG_SENSOR_Effect
\r
963 static struct reginfo sensor_Effect_Normal[] =
\r
970 static struct reginfo sensor_Effect_WandB[] =
\r
978 static struct reginfo sensor_Effect_Sepia[] =
\r
987 static struct reginfo sensor_Effect_Negative[] =
\r
993 static struct reginfo sensor_Effect_Bluish[] =
\r
1003 static struct reginfo sensor_Effect_Green[] =
\r
1012 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
\r
1013 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
\r
1016 #if CONFIG_SENSOR_Exposure
\r
1017 static struct reginfo sensor_Exposure0[]=
\r
1023 static struct reginfo sensor_Exposure1[]=
\r
1029 static struct reginfo sensor_Exposure2[]=
\r
1035 static struct reginfo sensor_Exposure3[]=
\r
1041 static struct reginfo sensor_Exposure4[]=
\r
1047 static struct reginfo sensor_Exposure5[]=
\r
1053 static struct reginfo sensor_Exposure6[]=
\r
1059 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
\r
1060 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
\r
1063 #if CONFIG_SENSOR_Saturation
\r
1064 static struct reginfo sensor_Saturation0[]=
\r
1069 static struct reginfo sensor_Saturation1[]=
\r
1074 static struct reginfo sensor_Saturation2[]=
\r
1078 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
\r
1081 #if CONFIG_SENSOR_Contrast
\r
1082 static struct reginfo sensor_Contrast0[]=
\r
1087 static struct reginfo sensor_Contrast1[]=
\r
1092 static struct reginfo sensor_Contrast2[]=
\r
1097 static struct reginfo sensor_Contrast3[]=
\r
1102 static struct reginfo sensor_Contrast4[]=
\r
1108 static struct reginfo sensor_Contrast5[]=
\r
1113 static struct reginfo sensor_Contrast6[]=
\r
1117 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
\r
1118 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
\r
1122 #if CONFIG_SENSOR_Mirror
\r
1123 static struct reginfo sensor_MirrorOn[]=
\r
1128 static struct reginfo sensor_MirrorOff[]=
\r
1132 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
\r
1134 #if CONFIG_SENSOR_Flip
\r
1135 static struct reginfo sensor_FlipOn[]=
\r
1140 static struct reginfo sensor_FlipOff[]=
\r
1144 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
\r
1147 #if CONFIG_SENSOR_Scene
\r
1148 static struct reginfo sensor_SceneAuto[] =
\r
1157 static struct reginfo sensor_SceneNight[] =
\r
1165 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
\r
1168 #if CONFIG_SENSOR_DigitalZoom
\r
1169 static struct reginfo sensor_Zoom0[] =
\r
1174 static struct reginfo sensor_Zoom1[] =
\r
1179 static struct reginfo sensor_Zoom2[] =
\r
1185 static struct reginfo sensor_Zoom3[] =
\r
1189 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
\r
1191 static const struct v4l2_querymenu sensor_menus[] =
\r
1193 #if CONFIG_SENSOR_WhiteBalance
\r
1194 { .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
1195 { .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
1196 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
\r
1199 #if CONFIG_SENSOR_Effect
\r
1200 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
\r
1201 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
\r
1202 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
\r
1205 #if CONFIG_SENSOR_Scene
\r
1206 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
\r
1209 #if CONFIG_SENSOR_Flash
\r
1210 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
\r
1211 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
\r
1215 static struct v4l2_queryctrl sensor_controls[] =
\r
1217 #if CONFIG_SENSOR_WhiteBalance
\r
1219 .id = V4L2_CID_DO_WHITE_BALANCE,
\r
1220 .type = V4L2_CTRL_TYPE_MENU,
\r
1221 .name = "White Balance Control",
\r
1225 .default_value = 0,
\r
1229 #if CONFIG_SENSOR_Brightness
\r
1231 .id = V4L2_CID_BRIGHTNESS,
\r
1232 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1233 .name = "Brightness Control",
\r
1237 .default_value = 0,
\r
1241 #if CONFIG_SENSOR_Effect
\r
1243 .id = V4L2_CID_EFFECT,
\r
1244 .type = V4L2_CTRL_TYPE_MENU,
\r
1245 .name = "Effect Control",
\r
1249 .default_value = 0,
\r
1253 #if CONFIG_SENSOR_Exposure
\r
1255 .id = V4L2_CID_EXPOSURE,
\r
1256 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1257 .name = "Exposure Control",
\r
1261 .default_value = 0,
\r
1265 #if CONFIG_SENSOR_Saturation
\r
1267 .id = V4L2_CID_SATURATION,
\r
1268 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1269 .name = "Saturation Control",
\r
1273 .default_value = 0,
\r
1277 #if CONFIG_SENSOR_Contrast
\r
1279 .id = V4L2_CID_CONTRAST,
\r
1280 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1281 .name = "Contrast Control",
\r
1285 .default_value = 0,
\r
1289 #if CONFIG_SENSOR_Mirror
\r
1291 .id = V4L2_CID_HFLIP,
\r
1292 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
1293 .name = "Mirror Control",
\r
1297 .default_value = 1,
\r
1301 #if CONFIG_SENSOR_Flip
\r
1303 .id = V4L2_CID_VFLIP,
\r
1304 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
1305 .name = "Flip Control",
\r
1309 .default_value = 1,
\r
1313 #if CONFIG_SENSOR_Scene
\r
1315 .id = V4L2_CID_SCENE,
\r
1316 .type = V4L2_CTRL_TYPE_MENU,
\r
1317 .name = "Scene Control",
\r
1321 .default_value = 0,
\r
1325 #if CONFIG_SENSOR_DigitalZoom
\r
1327 .id = V4L2_CID_ZOOM_RELATIVE,
\r
1328 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1329 .name = "DigitalZoom Control",
\r
1333 .default_value = 0,
\r
1335 .id = V4L2_CID_ZOOM_ABSOLUTE,
\r
1336 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1337 .name = "DigitalZoom Control",
\r
1341 .default_value = 0,
\r
1345 #if CONFIG_SENSOR_Focus
\r
1347 .id = V4L2_CID_FOCUS_RELATIVE,
\r
1348 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1349 .name = "Focus Control",
\r
1353 .default_value = 0,
\r
1355 .id = V4L2_CID_FOCUS_ABSOLUTE,
\r
1356 .type = V4L2_CTRL_TYPE_INTEGER,
\r
1357 .name = "Focus Control",
\r
1361 .default_value = 125,
\r
1365 #if CONFIG_SENSOR_Flash
\r
1367 .id = V4L2_CID_FLASH,
\r
1368 .type = V4L2_CTRL_TYPE_MENU,
\r
1369 .name = "Flash Control",
\r
1373 .default_value = 0,
\r
1378 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
\r
1379 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
\r
1380 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
1381 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
1382 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
1383 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
1384 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
\r
1385 static int sensor_resume(struct soc_camera_device *icd);
\r
1386 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
\r
1387 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
\r
1388 #if CONFIG_SENSOR_Effect
\r
1389 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1391 #if CONFIG_SENSOR_WhiteBalance
\r
1392 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1394 static int sensor_deactivate(struct i2c_client *client);
\r
1396 static struct soc_camera_ops sensor_ops =
\r
1398 .suspend = sensor_suspend,
\r
1399 .resume = sensor_resume,
\r
1400 .set_bus_param = sensor_set_bus_param,
\r
1401 .query_bus_param = sensor_query_bus_param,
\r
1402 .controls = sensor_controls,
\r
1403 .menus = sensor_menus,
\r
1404 .num_controls = ARRAY_SIZE(sensor_controls),
\r
1405 .num_menus = ARRAY_SIZE(sensor_menus),
\r
1408 /* only one fixed colorspace per pixelcode */
\r
1409 struct sensor_datafmt {
\r
1410 enum v4l2_mbus_pixelcode code;
\r
1411 enum v4l2_colorspace colorspace;
\r
1414 /* Find a data format by a pixel code in an array */
\r
1415 static const struct sensor_datafmt *sensor_find_datafmt(
\r
1416 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
\r
1420 for (i = 0; i < n; i++)
\r
1421 if (fmt[i].code == code)
\r
1427 static const struct sensor_datafmt sensor_colour_fmts[] = {
\r
1428 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
\r
1429 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
\r
1432 typedef struct sensor_info_priv_s
\r
1444 bool snap2preview;
\r
1445 bool video2preview;
\r
1446 unsigned char mirror; /* HFLIP */
\r
1447 unsigned char flip; /* VFLIP */
\r
1448 unsigned int winseqe_cur_addr;
\r
1449 struct sensor_datafmt fmt;
\r
1450 unsigned int funmodule_state;
\r
1451 } sensor_info_priv_t;
\r
1455 struct v4l2_subdev subdev;
\r
1456 struct i2c_client *client;
\r
1457 sensor_info_priv_t info_priv;
\r
1458 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
\r
1459 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1460 atomic_t tasklock_cnt;
\r
1462 struct rk29camera_platform_data *sensor_io_request;
\r
1463 struct rk29camera_gpio_res *sensor_gpio_res;
\r
1466 static struct sensor* to_sensor(const struct i2c_client *client)
\r
1468 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
\r
1471 static int sensor_task_lock(struct i2c_client *client, int lock)
\r
1473 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1475 struct sensor *sensor = to_sensor(client);
\r
1478 if (atomic_read(&sensor->tasklock_cnt) == 0) {
\r
1479 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
\r
1480 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
\r
1484 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
\r
1485 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
\r
1486 goto sensor_task_lock_err;
\r
1488 preempt_disable();
\r
1491 atomic_add(1, &sensor->tasklock_cnt);
\r
1493 if (atomic_read(&sensor->tasklock_cnt) > 0) {
\r
1494 atomic_sub(1, &sensor->tasklock_cnt);
\r
1496 if (atomic_read(&sensor->tasklock_cnt) == 0)
\r
1501 sensor_task_lock_err:
\r
1509 /* sensor register write */
\r
1510 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
\r
1514 struct i2c_msg msg[1];
\r
1516 //buf[0] = reg >> 8;
\r
1517 buf[0] = reg & 0xFF;
\r
1520 msg->addr = client->addr;
\r
1521 msg->flags = client->flags;
\r
1523 msg->len = sizeof(buf);
\r
1524 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1525 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
\r
1530 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1531 err = i2c_transfer(client->adapter, msg, 1);
\r
1536 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
\r
1544 /* sensor register read */
\r
1545 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
\r
1549 struct i2c_msg msg[2];
\r
1551 // buf[0] = reg >> 8;
\r
1552 buf[0] = reg & 0xFF;
\r
1554 msg[0].addr = client->addr;
\r
1555 msg[0].flags = client->flags;
\r
1557 msg[0].len = sizeof(buf);
\r
1558 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1559 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
1561 msg[1].addr = client->addr;
\r
1562 msg[1].flags = client->flags|I2C_M_RD;
\r
1565 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1566 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
1570 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1571 err = i2c_transfer(client->adapter, msg, 2);
\r
1577 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
\r
1585 /* write a array of registers */
\r
1586 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
\r
1590 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1595 if (sensor_task_lock(client, 1) < 0)
\r
1596 goto sensor_write_array_end;
\r
1597 while (regarray[i].reg != 0xff)
\r
1599 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1603 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
\r
1607 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
\r
1609 goto sensor_write_array_end;
\r
1612 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1613 sensor_read(client, regarray[i].reg, &valchk);
\r
1614 if (valchk != regarray[i].val)
\r
1615 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
\r
1621 sensor_write_array_end:
\r
1622 sensor_task_lock(client,0);
\r
1625 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1626 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
\r
1634 while (regarray[i].reg != 0xff)
\r
1636 sensor_read(client, regarray[i].reg, &valchk);
\r
1637 if (valchk != regarray[i].val)
\r
1638 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
\r
1645 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
\r
1647 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1650 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
\r
1653 case Sensor_PowerDown:
\r
1655 if (icl->powerdown) {
\r
1656 ret = icl->powerdown(icd->pdev, on);
\r
1657 if (ret == RK29_CAM_IO_SUCCESS) {
\r
1661 icl->reset(icd->pdev);
\r
1663 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
\r
1665 goto sensor_power_end;
\r
1670 case Sensor_Flash:
\r
1672 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1673 struct sensor *sensor = to_sensor(client);
\r
1675 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
\r
1676 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
\r
1678 //flash off after 2 secs
\r
1679 hrtimer_cancel(&(flash_off_timer.timer));
\r
1680 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
\r
1687 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
1695 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
\r
1696 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
\r
1697 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
\r
1698 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1702 static int sensor_init(struct v4l2_subdev *sd, u32 val)
\r
1704 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1705 struct soc_camera_device *icd = client->dev.platform_data;
\r
1706 struct sensor *sensor = to_sensor(client);
\r
1707 const struct v4l2_queryctrl *qctrl;
\r
1708 const struct sensor_datafmt *fmt;
\r
1711 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1713 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
1715 goto sensor_INIT_ERR;
\r
1720 if (sensor_task_lock(client,1)<0)
\r
1721 goto sensor_INIT_ERR;
\r
1722 ret = sensor_write(client, 0x3012, 0x80);
\r
1725 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
\r
1727 goto sensor_INIT_ERR;
\r
1730 mdelay(5); //delay 5 microseconds
\r
1731 /* check if it is an sensor sensor */
\r
1732 ret = sensor_read(client, 0x300a, &value);
\r
1734 SENSOR_TR("read chip id high byte failed\n");
\r
1736 goto sensor_INIT_ERR;
\r
1739 pid |= (value << 8);
\r
1741 ret = sensor_read(client, 0x300b, &value);
\r
1743 SENSOR_TR("read chip id low byte failed\n");
\r
1745 goto sensor_INIT_ERR;
\r
1748 pid |= (value & 0xff);
\r
1749 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1750 if (pid == SENSOR_ID) {
\r
1751 sensor->model = SENSOR_V4L2_IDENT;
\r
1753 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1755 goto sensor_INIT_ERR;
\r
1759 sensor_read(client,0x01,&value);
\r
1760 pid = (value & 0xff);
\r
1761 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1762 if (pid == SENSOR_ID) {
\r
1763 sensor->model = SENSOR_V4L2_IDENT;
\r
1765 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
1767 goto sensor_INIT_ERR;
\r
1770 ret = sensor_write_array(client, sensor_init_data);
\r
1773 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
\r
1774 goto sensor_INIT_ERR;
\r
1776 sensor_task_lock(client,0);
\r
1777 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
\r
1778 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
\r
1780 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
\r
1782 goto sensor_INIT_ERR;
\r
1784 sensor->info_priv.fmt = *fmt;
\r
1786 /* sensor sensor information for initialization */
\r
1787 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1789 sensor->info_priv.whiteBalance = qctrl->default_value;
\r
1790 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
\r
1792 sensor->info_priv.brightness = qctrl->default_value;
\r
1793 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1795 sensor->info_priv.effect = qctrl->default_value;
\r
1796 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
\r
1798 sensor->info_priv.exposure = qctrl->default_value;
\r
1800 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
\r
1802 sensor->info_priv.saturation = qctrl->default_value;
\r
1803 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
\r
1805 sensor->info_priv.contrast = qctrl->default_value;
\r
1806 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
\r
1808 sensor->info_priv.mirror = qctrl->default_value;
\r
1809 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
\r
1811 sensor->info_priv.flip = qctrl->default_value;
\r
1812 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
\r
1814 sensor->info_priv.scene = qctrl->default_value;
\r
1815 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
1817 sensor->info_priv.digitalzoom = qctrl->default_value;
\r
1819 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
\r
1820 #if CONFIG_SENSOR_Focus
\r
1821 sensor_set_focus();
\r
1822 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
\r
1824 sensor->info_priv.focus = qctrl->default_value;
\r
1827 #if CONFIG_SENSOR_Flash
\r
1828 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
\r
1830 sensor->info_priv.flash = qctrl->default_value;
\r
1831 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
\r
1832 flash_off_timer.icd = icd;
\r
1833 flash_off_timer.timer.function = flash_off_func;
\r
1836 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
1837 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
\r
1840 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1841 sensor_task_lock(client,0);
\r
1842 sensor_deactivate(client);
\r
1846 static int sensor_deactivate(struct i2c_client *client)
\r
1848 struct soc_camera_device *icd = client->dev.platform_data;
\r
1849 struct sensor *sensor = to_sensor(client);
\r
1851 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1853 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
\r
1855 sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1857 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
\r
1858 icd->user_width = SENSOR_INIT_WIDTH;
\r
1859 icd->user_height = SENSOR_INIT_HEIGHT;
\r
1862 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1866 static struct reginfo sensor_power_down_sequence[]=
\r
1870 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
\r
1873 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1875 if (pm_msg.event == PM_EVENT_SUSPEND) {
\r
1876 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
\r
1877 ret = sensor_write_array(client, sensor_power_down_sequence) ;
\r
1879 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
\r
1882 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1884 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1889 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
\r
1895 static int sensor_resume(struct soc_camera_device *icd)
\r
1899 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
\r
1901 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1905 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
\r
1911 static int sensor_set_bus_param(struct soc_camera_device *icd,
\r
1912 unsigned long flags)
\r
1918 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
\r
1920 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1921 unsigned long flags = SENSOR_BUS_PARAM;
\r
1923 return soc_camera_apply_sensor_flags(icl, flags);
\r
1926 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1928 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1929 struct soc_camera_device *icd = client->dev.platform_data;
\r
1930 struct sensor *sensor = to_sensor(client);
\r
1932 mf->width = icd->user_width;
\r
1933 mf->height = icd->user_height;
\r
1934 mf->code = sensor->info_priv.fmt.code;
\r
1935 mf->colorspace = sensor->info_priv.fmt.colorspace;
\r
1936 mf->field = V4L2_FIELD_NONE;
\r
1940 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1944 if ((mf->width == 1024) && (mf->height == 768)) {
\r
1946 } else if ((mf->width == 1280) && (mf->height == 1024)) {
\r
1948 } else if ((mf->width == 1600) && (mf->height == 1200)) {
\r
1950 } else if ((mf->width == 2048) && (mf->height == 1536)) {
\r
1952 } else if ((mf->width == 2592) && (mf->height == 1944)) {
\r
1957 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
\r
1961 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1965 if ((mf->width == 1280) && (mf->height == 720)) {
\r
1967 } else if ((mf->width == 1920) && (mf->height == 1080)) {
\r
1972 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
\r
1975 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1977 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1978 struct sensor *sensor = to_sensor(client);
\r
1979 const struct sensor_datafmt *fmt;
\r
1980 const struct v4l2_queryctrl *qctrl;
\r
1981 struct soc_camera_device *icd = client->dev.platform_data;
\r
1982 struct reginfo *winseqe_set_addr=NULL;
\r
1983 int ret=0, set_w,set_h;
\r
1985 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
1986 ARRAY_SIZE(sensor_colour_fmts));
\r
1989 goto sensor_s_fmt_end;
\r
1992 if (sensor->info_priv.fmt.code != mf->code) {
\r
1995 case V4L2_MBUS_FMT_YUYV8_2X8:
\r
1997 winseqe_set_addr = sensor_ClrFmt_YUYV;
\r
2000 case V4L2_MBUS_FMT_UYVY8_2X8:
\r
2002 winseqe_set_addr = sensor_ClrFmt_UYVY;
\r
2008 if (winseqe_set_addr != NULL) {
\r
2009 sensor_write_array(client, winseqe_set_addr);
\r
2010 sensor->info_priv.fmt.code = mf->code;
\r
2011 sensor->info_priv.fmt.colorspace= mf->colorspace;
\r
2012 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
\r
2014 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
\r
2018 set_w = mf->width;
\r
2019 set_h = mf->height;
\r
2021 if (((set_w <= 176) && (set_h <= 144)) &&( sensor_qcif[0].reg!=0xff))
\r
2023 winseqe_set_addr = sensor_qcif;
\r
2027 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=0xff))
\r
2029 winseqe_set_addr = sensor_qvga;
\r
2033 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=0xff))
\r
2035 winseqe_set_addr = sensor_cif;
\r
2039 else if (((set_w <= 640) && (set_h <= 480)) &&( sensor_vga[0].reg!=0xff))
\r
2041 winseqe_set_addr = sensor_vga;
\r
2045 else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=0xff))
\r
2047 winseqe_set_addr = sensor_svga;
\r
2051 else if (((set_w <= 1024) && (set_h <= 768)) &&( sensor_xga[0].reg!=0xff))
\r
2053 winseqe_set_addr = sensor_xga;
\r
2057 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=0xff))
\r
2059 winseqe_set_addr = sensor_sxga;
\r
2063 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=0xff))
\r
2065 winseqe_set_addr = sensor_uxga;
\r
2071 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
\r
2072 set_w = SENSOR_INIT_WIDTH;
\r
2073 set_h = SENSOR_INIT_HEIGHT;
\r
2074 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
\r
2077 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
\r
2078 #if CONFIG_SENSOR_Flash
\r
2079 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
2080 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2081 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
\r
2082 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
\r
2084 } else { /* ddl@rock-chips.com : Video */
\r
2085 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2086 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2087 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
\r
2091 ret |= sensor_write_array(client, winseqe_set_addr);
\r
2093 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
\r
2094 #if CONFIG_SENSOR_Flash
\r
2095 if (sensor_fmt_capturechk(sd,mf) == true) {
\r
2096 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
2097 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2098 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
\r
2102 goto sensor_s_fmt_end;
\r
2105 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
\r
2107 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
2108 #if CONFIG_SENSOR_Effect
\r
2109 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2110 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2112 #if CONFIG_SENSOR_WhiteBalance
\r
2113 if (sensor->info_priv.whiteBalance != 0) {
\r
2114 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2115 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2118 sensor->info_priv.snap2preview = true;
\r
2119 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
\r
2120 #if CONFIG_SENSOR_Effect
\r
2121 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2122 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2124 #if CONFIG_SENSOR_WhiteBalance
\r
2125 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2126 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2128 sensor->info_priv.video2preview = true;
\r
2129 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
\r
2130 #if CONFIG_SENSOR_Effect
\r
2131 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
2132 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
2134 #if CONFIG_SENSOR_WhiteBalance
\r
2135 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
2136 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
2138 sensor->info_priv.video2preview = false;
\r
2139 sensor->info_priv.snap2preview = false;
\r
2141 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
\r
2145 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
\r
2148 mf->width = set_w;
\r
2149 mf->height = set_h;
\r
2155 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
2157 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2158 struct sensor *sensor = to_sensor(client);
\r
2159 const struct sensor_datafmt *fmt;
\r
2160 int ret = 0,set_w,set_h;
\r
2162 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
2163 ARRAY_SIZE(sensor_colour_fmts));
\r
2164 if (fmt == NULL) {
\r
2165 fmt = &sensor->info_priv.fmt;
\r
2166 mf->code = fmt->code;
\r
2169 if (mf->height > SENSOR_MAX_HEIGHT)
\r
2170 mf->height = SENSOR_MAX_HEIGHT;
\r
2171 else if (mf->height < SENSOR_MIN_HEIGHT)
\r
2172 mf->height = SENSOR_MIN_HEIGHT;
\r
2174 if (mf->width > SENSOR_MAX_WIDTH)
\r
2175 mf->width = SENSOR_MAX_WIDTH;
\r
2176 else if (mf->width < SENSOR_MIN_WIDTH)
\r
2177 mf->width = SENSOR_MIN_WIDTH;
\r
2179 set_w = mf->width;
\r
2180 set_h = mf->height;
\r
2182 if (((set_w <= 176) && (set_h <= 144)) &&( sensor_qcif[0].reg!=0xff))
\r
2187 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=0xff))
\r
2192 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=0xff))
\r
2197 else if (((set_w <= 640) && (set_h <= 480)) &&( sensor_vga[0].reg!=0xff))
\r
2202 else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=0xff))
\r
2207 else if (((set_w <= 1024) && (set_h <= 768)) &&( sensor_xga[0].reg!=0xff))
\r
2212 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=0xff))
\r
2217 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=0xff))
\r
2224 set_w = SENSOR_INIT_WIDTH;
\r
2225 set_h = SENSOR_INIT_HEIGHT;
\r
2227 mf->width = set_w;
\r
2228 mf->height = set_h;
\r
2229 mf->colorspace = fmt->colorspace;
\r
2234 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
\r
2236 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2238 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
\r
2241 if (id->match.addr != client->addr)
\r
2244 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
\r
2249 #if CONFIG_SENSOR_Brightness
\r
2250 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2252 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2254 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2256 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
\r
2258 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
\r
2260 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2263 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2267 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2271 #if CONFIG_SENSOR_Effect
\r
2272 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2274 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2276 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2278 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
\r
2280 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
\r
2282 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2285 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2289 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2293 #if CONFIG_SENSOR_Exposure
\r
2294 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2296 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2298 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2300 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
\r
2302 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
\r
2304 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2307 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2311 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2315 #if CONFIG_SENSOR_Saturation
\r
2316 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2318 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2320 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2322 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
\r
2324 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
\r
2326 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2329 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2333 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2337 #if CONFIG_SENSOR_Contrast
\r
2338 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2340 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2342 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2344 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
\r
2346 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
\r
2348 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2351 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2355 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2359 #if CONFIG_SENSOR_Mirror
\r
2360 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2362 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2364 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2366 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
\r
2368 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
\r
2370 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2373 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2377 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2381 #if CONFIG_SENSOR_Flip
\r
2382 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2384 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2386 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2388 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
\r
2390 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
\r
2392 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2395 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2399 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2403 #if CONFIG_SENSOR_Scene
\r
2404 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2406 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2408 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2410 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
\r
2412 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 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
2421 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2425 #if CONFIG_SENSOR_WhiteBalance
\r
2426 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2428 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2430 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
2432 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
\r
2434 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
\r
2436 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2439 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2443 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2447 #if CONFIG_SENSOR_DigitalZoom
\r
2448 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2450 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2451 struct sensor *sensor = to_sensor(client);
\r
2452 const struct v4l2_queryctrl *qctrl_info;
\r
2453 int digitalzoom_cur, digitalzoom_total;
\r
2455 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
2459 digitalzoom_cur = sensor->info_priv.digitalzoom;
\r
2460 digitalzoom_total = qctrl_info->maximum;
\r
2462 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
\r
2464 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2468 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
\r
2470 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2474 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
\r
2476 value = digitalzoom_total - digitalzoom_cur;
\r
2479 if ((value < 0) && ((digitalzoom_cur + value) < 0))
\r
2481 value = 0 - digitalzoom_cur;
\r
2484 digitalzoom_cur += value;
\r
2486 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
\r
2488 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
\r
2490 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2493 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2500 #if CONFIG_SENSOR_Flash
\r
2501 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2503 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
\r
2504 if (value == 3) { /* ddl@rock-chips.com: torch */
\r
2505 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
\r
2507 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2509 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2513 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2518 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2520 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2521 struct sensor *sensor = to_sensor(client);
\r
2522 const struct v4l2_queryctrl *qctrl;
\r
2524 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2528 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2534 case V4L2_CID_BRIGHTNESS:
\r
2536 ctrl->value = sensor->info_priv.brightness;
\r
2539 case V4L2_CID_SATURATION:
\r
2541 ctrl->value = sensor->info_priv.saturation;
\r
2544 case V4L2_CID_CONTRAST:
\r
2546 ctrl->value = sensor->info_priv.contrast;
\r
2549 case V4L2_CID_DO_WHITE_BALANCE:
\r
2551 ctrl->value = sensor->info_priv.whiteBalance;
\r
2554 case V4L2_CID_EXPOSURE:
\r
2556 ctrl->value = sensor->info_priv.exposure;
\r
2559 case V4L2_CID_HFLIP:
\r
2561 ctrl->value = sensor->info_priv.mirror;
\r
2564 case V4L2_CID_VFLIP:
\r
2566 ctrl->value = sensor->info_priv.flip;
\r
2577 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2579 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2580 struct sensor *sensor = to_sensor(client);
\r
2581 struct soc_camera_device *icd = client->dev.platform_data;
\r
2582 const struct v4l2_queryctrl *qctrl;
\r
2585 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2589 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2595 #if CONFIG_SENSOR_Brightness
\r
2596 case V4L2_CID_BRIGHTNESS:
\r
2598 if (ctrl->value != sensor->info_priv.brightness)
\r
2600 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
\r
2604 sensor->info_priv.brightness = ctrl->value;
\r
2609 #if CONFIG_SENSOR_Exposure
\r
2610 case V4L2_CID_EXPOSURE:
\r
2612 if (ctrl->value != sensor->info_priv.exposure)
\r
2614 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
\r
2618 sensor->info_priv.exposure = ctrl->value;
\r
2623 #if CONFIG_SENSOR_Saturation
\r
2624 case V4L2_CID_SATURATION:
\r
2626 if (ctrl->value != sensor->info_priv.saturation)
\r
2628 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
\r
2632 sensor->info_priv.saturation = ctrl->value;
\r
2637 #if CONFIG_SENSOR_Contrast
\r
2638 case V4L2_CID_CONTRAST:
\r
2640 if (ctrl->value != sensor->info_priv.contrast)
\r
2642 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
\r
2646 sensor->info_priv.contrast = ctrl->value;
\r
2651 #if CONFIG_SENSOR_WhiteBalance
\r
2652 case V4L2_CID_DO_WHITE_BALANCE:
\r
2654 if (ctrl->value != sensor->info_priv.whiteBalance)
\r
2656 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
\r
2660 sensor->info_priv.whiteBalance = ctrl->value;
\r
2665 #if CONFIG_SENSOR_Mirror
\r
2666 case V4L2_CID_HFLIP:
\r
2668 if (ctrl->value != sensor->info_priv.mirror)
\r
2670 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
\r
2672 sensor->info_priv.mirror = ctrl->value;
\r
2677 #if CONFIG_SENSOR_Flip
\r
2678 case V4L2_CID_VFLIP:
\r
2680 if (ctrl->value != sensor->info_priv.flip)
\r
2682 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
\r
2684 sensor->info_priv.flip = ctrl->value;
\r
2695 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
\r
2697 const struct v4l2_queryctrl *qctrl;
\r
2698 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2699 struct sensor *sensor = to_sensor(client);
\r
2701 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2705 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2709 switch (ext_ctrl->id)
\r
2711 case V4L2_CID_SCENE:
\r
2713 ext_ctrl->value = sensor->info_priv.scene;
\r
2716 case V4L2_CID_EFFECT:
\r
2718 ext_ctrl->value = sensor->info_priv.effect;
\r
2721 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2723 ext_ctrl->value = sensor->info_priv.digitalzoom;
\r
2726 case V4L2_CID_ZOOM_RELATIVE:
\r
2730 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2732 ext_ctrl->value = sensor->info_priv.focus;
\r
2735 case V4L2_CID_FOCUS_RELATIVE:
\r
2739 case V4L2_CID_FLASH:
\r
2741 ext_ctrl->value = sensor->info_priv.flash;
\r
2749 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
\r
2751 const struct v4l2_queryctrl *qctrl;
\r
2752 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2753 struct sensor *sensor = to_sensor(client);
\r
2756 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2760 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2765 switch (ext_ctrl->id)
\r
2767 #if CONFIG_SENSOR_Scene
\r
2768 case V4L2_CID_SCENE:
\r
2770 if (ext_ctrl->value != sensor->info_priv.scene)
\r
2772 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
\r
2774 sensor->info_priv.scene = ext_ctrl->value;
\r
2779 #if CONFIG_SENSOR_Effect
\r
2780 case V4L2_CID_EFFECT:
\r
2782 if (ext_ctrl->value != sensor->info_priv.effect)
\r
2784 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
\r
2786 sensor->info_priv.effect= ext_ctrl->value;
\r
2791 #if CONFIG_SENSOR_DigitalZoom
\r
2792 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2794 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2797 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
\r
2799 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
\r
2801 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
\r
2803 sensor->info_priv.digitalzoom += val_offset;
\r
2805 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2810 case V4L2_CID_ZOOM_RELATIVE:
\r
2812 if (ext_ctrl->value)
\r
2814 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
\r
2816 sensor->info_priv.digitalzoom += ext_ctrl->value;
\r
2818 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2823 #if CONFIG_SENSOR_Focus
\r
2824 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2826 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2829 if (ext_ctrl->value != sensor->info_priv.focus)
\r
2831 val_offset = ext_ctrl->value -sensor->info_priv.focus;
\r
2833 sensor->info_priv.focus += val_offset;
\r
2838 case V4L2_CID_FOCUS_RELATIVE:
\r
2840 if (ext_ctrl->value)
\r
2842 sensor->info_priv.focus += ext_ctrl->value;
\r
2844 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
\r
2849 #if CONFIG_SENSOR_Flash
\r
2850 case V4L2_CID_FLASH:
\r
2852 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
\r
2854 sensor->info_priv.flash = ext_ctrl->value;
\r
2856 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
\r
2867 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2869 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2870 struct soc_camera_device *icd = client->dev.platform_data;
\r
2871 int i, error_cnt=0, error_idx=-1;
\r
2874 for (i=0; i<ext_ctrl->count; i++) {
\r
2875 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2881 if (error_cnt > 1)
\r
2882 error_idx = ext_ctrl->count;
\r
2884 if (error_idx != -1) {
\r
2885 ext_ctrl->error_idx = error_idx;
\r
2892 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2894 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2895 struct soc_camera_device *icd = client->dev.platform_data;
\r
2896 int i, error_cnt=0, error_idx=-1;
\r
2899 for (i=0; i<ext_ctrl->count; i++) {
\r
2900 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2906 if (error_cnt > 1)
\r
2907 error_idx = ext_ctrl->count;
\r
2909 if (error_idx != -1) {
\r
2910 ext_ctrl->error_idx = error_idx;
\r
2917 /* Interface active, can use i2c. If it fails, it can indeed mean, that
\r
2918 * this wasn't our capture interface, so, we wait for the right one */
\r
2919 static int sensor_video_probe(struct soc_camera_device *icd,
\r
2920 struct i2c_client *client)
\r
2925 /* We must have a parent by now. And it cannot be a wrong one.
\r
2926 * So this entire test is completely redundant. */
\r
2927 if (!icd->dev.parent ||
\r
2928 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
\r
2931 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
2933 goto sensor_video_probe_err;
\r
2937 ret = sensor_write(client, 0x3012, 0x80);
\r
2940 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
\r
2943 mdelay(5); //delay 5 microseconds
\r
2945 /* check if it is an sensor sensor */
\r
2946 ret = sensor_read(client, 0x300a, &value);
\r
2948 SENSOR_TR("read chip id high byte failed\n");
\r
2950 goto sensor_video_probe_err;
\r
2954 ret = sensor_read(client, 0x01, &value);
\r
2956 SENSOR_TR("read chip id low byte failed\n");
\r
2958 goto sensor_video_probe_err;
\r
2961 pid = (value & 0xff);
\r
2962 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2963 if (pid == SENSOR_ID) {
\r
2964 sensor->model = SENSOR_V4L2_IDENT;
\r
2966 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2968 goto sensor_video_probe_err;
\r
2974 sensor_video_probe_err:
\r
2978 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
\r
2980 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2981 struct soc_camera_device *icd = client->dev.platform_data;
\r
2982 struct sensor *sensor = to_sensor(client);
\r
2984 #if CONFIG_SENSOR_Flash
\r
2988 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2991 case RK29_CAM_SUBDEV_DEACTIVATE:
\r
2993 sensor_deactivate(client);
\r
2997 case RK29_CAM_SUBDEV_IOREQUEST:
\r
2999 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
\r
3000 if (sensor->sensor_io_request != NULL) {
\r
3001 sensor->sensor_gpio_res = NULL;
\r
3002 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
\r
3003 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
\r
3004 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
\r
3005 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
\r
3008 if (sensor->sensor_gpio_res == NULL) {
\r
3009 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
3011 goto sensor_ioctl_end;
\r
3014 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
3016 goto sensor_ioctl_end;
\r
3018 /* 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
3019 for this project */
\r
3020 #if CONFIG_SENSOR_Flash
\r
3021 if (sensor->sensor_gpio_res) {
\r
3022 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
\r
3023 for (i = 0; i < icd->ops->num_controls; i++) {
\r
3024 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
\r
3025 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
\r
3026 sensor_controls[i].id=0xffff;
\r
3029 sensor->info_priv.flash = 0xff;
\r
3030 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
\r
3031 }else{ //two cameras are the same,need to deal diffrently ,zyc
\r
3032 for (i = 0; i < icd->ops->num_controls; i++) {
\r
3033 if(0xffff == icd->ops->controls[i].id){
\r
3034 sensor_controls[i].id=V4L2_CID_FLASH;
\r
3044 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
3052 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
\r
3053 enum v4l2_mbus_pixelcode *code)
\r
3055 if (index >= ARRAY_SIZE(sensor_colour_fmts))
\r
3058 *code = sensor_colour_fmts[index].code;
\r
3061 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
\r
3062 .init = sensor_init,
\r
3063 .g_ctrl = sensor_g_control,
\r
3064 .s_ctrl = sensor_s_control,
\r
3065 .g_ext_ctrls = sensor_g_ext_controls,
\r
3066 .s_ext_ctrls = sensor_s_ext_controls,
\r
3067 .g_chip_ident = sensor_g_chip_ident,
\r
3068 .ioctl = sensor_ioctl,
\r
3071 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
\r
3072 .s_mbus_fmt = sensor_s_fmt,
\r
3073 .g_mbus_fmt = sensor_g_fmt,
\r
3074 .try_mbus_fmt = sensor_try_fmt,
\r
3075 .enum_mbus_fmt = sensor_enum_fmt,
\r
3078 static struct v4l2_subdev_ops sensor_subdev_ops = {
\r
3079 .core = &sensor_subdev_core_ops,
\r
3080 .video = &sensor_subdev_video_ops,
\r
3083 static int sensor_probe(struct i2c_client *client,
\r
3084 const struct i2c_device_id *did)
\r
3086 struct sensor *sensor;
\r
3087 struct soc_camera_device *icd = client->dev.platform_data;
\r
3088 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
\r
3089 struct soc_camera_link *icl;
\r
3092 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
\r
3094 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
\r
3098 icl = to_soc_camera_link(icd);
\r
3100 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
\r
3104 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
\r
3105 dev_warn(&adapter->dev,
\r
3106 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
\r
3110 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
\r
3114 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
\r
3116 /* Second stage probe - when a capture adapter is there */
\r
3117 icd->ops = &sensor_ops;
\r
3118 sensor->info_priv.fmt = sensor_colour_fmts[0];
\r
3119 #if CONFIG_SENSOR_I2C_NOSCHED
\r
3120 atomic_set(&sensor->tasklock_cnt,0);
\r
3123 ret = sensor_video_probe(icd, client);
\r
3126 i2c_set_clientdata(client, NULL);
\r
3130 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
\r
3134 static int sensor_remove(struct i2c_client *client)
\r
3136 struct sensor *sensor = to_sensor(client);
\r
3137 struct soc_camera_device *icd = client->dev.platform_data;
\r
3140 i2c_set_clientdata(client, NULL);
\r
3141 client->driver = NULL;
\r
3147 static const struct i2c_device_id sensor_id[] = {
\r
3148 {SENSOR_NAME_STRING(), 0 },
\r
3151 MODULE_DEVICE_TABLE(i2c, sensor_id);
\r
3153 static struct i2c_driver sensor_i2c_driver = {
\r
3155 .name = SENSOR_NAME_STRING(),
\r
3157 .probe = sensor_probe,
\r
3158 .remove = sensor_remove,
\r
3159 .id_table = sensor_id,
\r
3162 static int __init sensor_mod_init(void)
\r
3164 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
\r
3165 return i2c_add_driver(&sensor_i2c_driver);
\r
3168 static void __exit sensor_mod_exit(void)
\r
3170 i2c_del_driver(&sensor_i2c_driver);
\r
3173 device_initcall_sync(sensor_mod_init);
\r
3174 module_exit(sensor_mod_exit);
\r
3176 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
\r
3177 MODULE_AUTHOR("ddl <kernel@rock-chips>");
\r
3178 MODULE_LICENSE("GPL");
\r